supernova-ws /
SuperNova
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Created by Gorlum 13.05.2020 13:02 |
||||||
| 4 | */ |
||||||
| 5 | |||||||
| 6 | namespace Chat; |
||||||
| 7 | |||||||
| 8 | |||||||
| 9 | use classCache; |
||||||
| 10 | use Common\Traits\TSingleton; |
||||||
| 11 | use SN; |
||||||
| 12 | use SnTemplate; |
||||||
| 13 | |||||||
| 14 | class Chat { |
||||||
| 15 | |||||||
| 16 | use TSingleton; |
||||||
| 17 | |||||||
| 18 | const CHAT_DEFAULT_LINES_PER_PAGE = 20; |
||||||
| 19 | |||||||
| 20 | protected $_chat_aliases = array( |
||||||
| 21 | 'h' => 'help', |
||||||
| 22 | '?' => 'help', |
||||||
| 23 | 'help' => 'help', |
||||||
| 24 | 'w' => 'whisper', |
||||||
| 25 | 'whisper' => 'whisper', |
||||||
| 26 | 'b' => 'ban', |
||||||
| 27 | 'ban' => 'ban', |
||||||
| 28 | 'ub' => 'unban', |
||||||
| 29 | 'unban' => 'unban', |
||||||
| 30 | 'm' => 'mute', |
||||||
| 31 | 'mute' => 'mute', |
||||||
| 32 | 'um' => 'unmute', |
||||||
| 33 | 'unmute' => 'unmute', |
||||||
| 34 | 'iv' => 'invisible', |
||||||
| 35 | 'invisible' => 'invisible', |
||||||
| 36 | // * /i /ignore |
||||||
| 37 | // * /ck /kick |
||||||
| 38 | // * /ci /invite |
||||||
| 39 | // * /cj /join |
||||||
| 40 | // * /cc /create |
||||||
| 41 | ); |
||||||
| 42 | |||||||
| 43 | protected $_chat_commands = array( |
||||||
| 44 | 'invisible' => array( |
||||||
| 45 | 'access' => array(0, 1, 2, 3, 4), |
||||||
| 46 | 'options' => array( |
||||||
| 47 | CHAT_OPTION_SWITCH => CHAT_OPTION_SWITCH, |
||||||
| 48 | ), |
||||||
| 49 | ), |
||||||
| 50 | 'whisper' => array( |
||||||
| 51 | 'access' => array(0, 1, 2, 3, 4), |
||||||
| 52 | 'options' => array(), |
||||||
| 53 | ), |
||||||
| 54 | 'mute' => array( |
||||||
| 55 | 'access' => array(1, 2, 3, 4), |
||||||
| 56 | 'options' => array(), |
||||||
| 57 | ), |
||||||
| 58 | 'unmute' => array( |
||||||
| 59 | 'access' => array(1, 2, 3, 4), |
||||||
| 60 | 'options' => array(), |
||||||
| 61 | ), |
||||||
| 62 | 'ban' => array( |
||||||
| 63 | 'access' => array(1, 2, 3, 4), |
||||||
| 64 | 'options' => array(), |
||||||
| 65 | ), |
||||||
| 66 | 'unban' => array( |
||||||
| 67 | 'access' => array(1, 2, 3, 4), |
||||||
| 68 | 'options' => array(), |
||||||
| 69 | ), |
||||||
| 70 | 'help' => array( |
||||||
| 71 | 'access' => array(0, 1, 2, 3, 4), |
||||||
| 72 | 'options' => array(), |
||||||
| 73 | ), |
||||||
| 74 | ); |
||||||
| 75 | |||||||
| 76 | |||||||
| 77 | public static function chatModel() { |
||||||
| 78 | static::me()->_chatModel(); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 79 | } |
||||||
| 80 | |||||||
| 81 | public static function chatAddModel() { |
||||||
| 82 | static::me()->_chatAddModel(); |
||||||
|
0 ignored issues
–
show
It seems like
_chatAddModel() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | public static function chatView($template = null) { |
||||||
| 86 | return static::me()->_chatView($template); |
||||||
|
0 ignored issues
–
show
It seems like
_chatView() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 87 | } |
||||||
| 88 | |||||||
| 89 | public static function chatMsgView($template = null) { |
||||||
| 90 | static::me()->_chatMsgView($template); |
||||||
|
0 ignored issues
–
show
It seems like
_chatMsgView() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 91 | } |
||||||
| 92 | |||||||
| 93 | public static function chatFrameView($template = null) { |
||||||
| 94 | static::me()->_chatFrameView($template); |
||||||
|
0 ignored issues
–
show
It seems like
_chatFrameView() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 95 | } |
||||||
| 96 | |||||||
| 97 | protected function _chatView($template = null) { |
||||||
| 98 | defined('IN_AJAX') or define('IN_AJAX', true); |
||||||
| 99 | |||||||
| 100 | global $config, $lang; |
||||||
| 101 | |||||||
| 102 | $iframe = sys_get_param_id('iframe'); |
||||||
| 103 | |||||||
| 104 | // $template = $this->addModuleTemplate('chat_body', $template); |
||||||
| 105 | $template = SnTemplate::gettemplate('chat/chat_body', $template); |
||||||
| 106 | $template->assign_var('CHAT_REFRESH_RATE', $config->chat_refresh_rate); |
||||||
| 107 | $template->assign_var('CHAT_MODE', $iframe); |
||||||
| 108 | $template->assign_var('MENU', !$iframe); |
||||||
| 109 | $template->assign_var('NAVBAR', !$iframe); |
||||||
| 110 | $template->assign_var('CHAT_IFRAME', $iframe); |
||||||
| 111 | foreach ($lang['chat_advanced_command_interval'] as $interval => $locale) { |
||||||
| 112 | $template->assign_block_vars('chat_advanced_command_interval', array( |
||||||
| 113 | 'INTERVAL' => $interval, |
||||||
| 114 | 'NAME' => $locale, |
||||||
| 115 | )); |
||||||
| 116 | } |
||||||
| 117 | |||||||
| 118 | return $template; |
||||||
| 119 | } |
||||||
| 120 | |||||||
| 121 | protected function _chatMsgView($template = null) { |
||||||
| 122 | defined('IN_AJAX') or define('IN_AJAX', true); |
||||||
| 123 | |||||||
| 124 | global $config, $user, $lang; |
||||||
| 125 | |||||||
| 126 | |||||||
| 127 | $history = sys_get_param_str('history'); |
||||||
| 128 | if (!$history) { |
||||||
| 129 | $config->array_set('users', $user['id'], 'chat_last_refresh', SN_TIME_MICRO); |
||||||
| 130 | // $chat_player_row = $this->sn_chat_advanced_get_chat_player_record($user['id']); |
||||||
| 131 | doquery("UPDATE {{chat_player}} SET `chat_player_refresh_last` = " . SN_TIME_NOW . " WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 132 | } |
||||||
| 133 | |||||||
| 134 | $page = 0; |
||||||
| 135 | $last_message = ''; |
||||||
| 136 | $alliance = 0; |
||||||
| 137 | $template_result['.']['chat'] = array(); |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 138 | if (!$history && $config->getMode() != classCache::CACHER_NO_CACHE && $config->chat_timeout && SN_TIME_MICRO - $config->array_get('users', $user['id'], 'chat_last_activity') > $config->chat_timeout) { |
||||||
| 139 | $result['disable'] = true; |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 140 | $template_result['.']['chat'][] = array( |
||||||
| 141 | 'TIME' => date(FMT_DATE_TIME, htmlentities(SN_TIME_NOW + SN_CLIENT_TIME_DIFF, ENT_QUOTES, 'utf-8')), |
||||||
|
0 ignored issues
–
show
htmlentities(Chat\SN_TIM...at\ENT_QUOTES, 'utf-8') of type string is incompatible with the type integer|null expected by parameter $timestamp of date().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 142 | 'DISABLE' => true, |
||||||
| 143 | ); |
||||||
| 144 | } else { |
||||||
| 145 | $alliance = sys_get_param_str('ally') && $user['ally_id'] ? $user['ally_id'] : 0; |
||||||
| 146 | |||||||
| 147 | $page_limit = sys_get_param_id('line_per_page', self::CHAT_DEFAULT_LINES_PER_PAGE); // Chat rows Limit |
||||||
| 148 | |||||||
| 149 | $where_add = ''; |
||||||
| 150 | $last_message = 0; |
||||||
| 151 | if ($history) { |
||||||
| 152 | $rows = doquery("SELECT count(1) AS CNT |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 153 | FROM {{chat}} |
||||||
| 154 | WHERE |
||||||
| 155 | ( |
||||||
| 156 | (ally_id = '{$alliance}' AND `chat_message_recipient_id` IS NULL) OR |
||||||
| 157 | (ally_id = 0 AND `chat_message_recipient_id` = {$user['id']}) OR |
||||||
| 158 | (ally_id = 0 AND `chat_message_sender_id` = {$user['id']} AND `chat_message_recipient_id` IS NOT NULL) OR |
||||||
| 159 | (ally_id = 0 AND `chat_message_sender_id` IS NULL AND `chat_message_recipient_id` IS NULL) |
||||||
| 160 | ) |
||||||
| 161 | ", true); |
||||||
|
0 ignored issues
–
show
true of type true is incompatible with the type string expected by parameter $table of doquery().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 162 | $page_count = ceil($rows['CNT'] / $page_limit); |
||||||
| 163 | |||||||
| 164 | for ($i = 1; $i <= $page_count; $i++) { |
||||||
| 165 | $template_result['.']['page'][] = array( |
||||||
| 166 | 'NUMBER' => $i |
||||||
| 167 | ); |
||||||
| 168 | } |
||||||
| 169 | |||||||
| 170 | $page = min($page_count, max(1, sys_get_param_int('sheet'))); |
||||||
| 171 | } else { |
||||||
| 172 | $last_message = sys_get_param_id('last_message'); |
||||||
| 173 | $where_add = $last_message ? "AND `messageid` > {$last_message}" : ''; |
||||||
| 174 | $page = 1; |
||||||
| 175 | } |
||||||
| 176 | |||||||
| 177 | $start_row = ($page - 1) * $page_limit;// OR `chat_message_recipient_id` = {$user['id']} |
||||||
| 178 | $start_row = $start_row < 0 ? 0 : $start_row; |
||||||
| 179 | $query = doquery( |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 180 | "SELECT c.*, u.authlevel |
||||||
| 181 | FROM |
||||||
| 182 | {{chat}} AS c |
||||||
| 183 | LEFT JOIN {{users}} AS u ON u.id = c.chat_message_sender_id |
||||||
| 184 | WHERE |
||||||
| 185 | ( |
||||||
| 186 | (c.ally_id = '{$alliance}' AND `chat_message_recipient_id` IS NULL) OR |
||||||
| 187 | (c.ally_id = 0 AND `chat_message_recipient_id` = {$user['id']}) OR |
||||||
| 188 | (c.ally_id = 0 AND `chat_message_sender_id` = {$user['id']} AND `chat_message_recipient_id` IS NOT NULL) OR |
||||||
| 189 | (c.ally_id = 0 AND `chat_message_sender_id` IS NULL AND `chat_message_recipient_id` IS NULL) |
||||||
| 190 | ) |
||||||
| 191 | {$where_add} |
||||||
| 192 | ORDER BY messageid DESC |
||||||
| 193 | LIMIT {$start_row}, {$page_limit}"); |
||||||
| 194 | while ($chat_row = db_fetch($query)) { |
||||||
|
0 ignored issues
–
show
The function
db_fetch() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 195 | $chat_row['user'] = player_nick_render_to_html($chat_row['user']); |
||||||
| 196 | $nick_stripped = htmlentities(strip_tags($chat_row['user']), ENT_QUOTES, 'utf-8'); |
||||||
| 197 | $template_result['.']['chat'][] = array( |
||||||
| 198 | 'TIME' => SN::$gc->bbCodeParser->expandBbCode(date(FMT_DATE_TIME, $chat_row['timestamp'] + SN_CLIENT_TIME_DIFF)), |
||||||
| 199 | 'NICK' => $chat_row['user'], |
||||||
| 200 | 'NICK_STRIPPED' => $nick_stripped, |
||||||
| 201 | 'TEXT' => SN::$gc->bbCodeParser->expandBbCode($chat_row['message'], $chat_row['authlevel']), |
||||||
| 202 | 'SENDER_ID' => $chat_row['chat_message_sender_id'], |
||||||
| 203 | 'SENDER_NAME' => $safe_name = sys_safe_output($chat_row['chat_message_sender_name']), |
||||||
| 204 | 'SENDER_NAME_SAFE' => $safe_name <> $chat_row['chat_message_sender_name'] || strpbrk($safe_name, ' /\\\'') ? '"' . $safe_name . '"' : $safe_name, |
||||||
| 205 | 'RECIPIENT_ID' => $chat_row['chat_message_recipient_id'], |
||||||
| 206 | 'RECIPIENT_NAME' => $safe_name_recipient = sys_safe_output($chat_row['chat_message_recipient_name']), |
||||||
| 207 | 'RECIPIENT_NAME_SAFE' => $safe_name_recipient <> $chat_row['chat_message_recipient_name'] || strpbrk($safe_name_recipient, ' /\\\'') ? '"' . $safe_name_recipient . '"' : $safe_name_recipient, |
||||||
| 208 | ); |
||||||
| 209 | |||||||
| 210 | $last_message = max($last_message, $chat_row['messageid']); |
||||||
| 211 | } |
||||||
| 212 | } |
||||||
| 213 | |||||||
| 214 | $template_result['.']['chat'] = array_reverse($template_result['.']['chat']); |
||||||
| 215 | |||||||
| 216 | $template_result += array( |
||||||
| 217 | 'PAGE' => $page, |
||||||
| 218 | 'PAGES_TOTAL' => $page_count, |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 219 | 'PAGE_NEXT' => $page < $page_count ? $page + 1 : $page, |
||||||
| 220 | 'PAGE_PREV' => $page > 1 ? $page - 1 : $page, |
||||||
| 221 | 'ALLY' => $alliance, |
||||||
| 222 | 'HISTORY' => $history, |
||||||
| 223 | 'USER_ID' => $user['id'], |
||||||
| 224 | ); |
||||||
| 225 | |||||||
| 226 | // $template = $this->addModuleTemplate('chat_messages', $template); |
||||||
| 227 | $template = SnTemplate::gettemplate('chat/chat_messages', $template); |
||||||
| 228 | $template->assign_recursive($template_result); |
||||||
| 229 | |||||||
| 230 | if ($history) { |
||||||
| 231 | $pageTitle = "{$lang['chat_history']} - {$lang[$alliance ? 'chat_ally' : 'chat_common']}"; |
||||||
| 232 | SnTemplate::display($template, $pageTitle); |
||||||
| 233 | } else { |
||||||
| 234 | $result['last_message'] = $last_message; |
||||||
| 235 | $result['html'] = SnTemplate::templateRenderToHtml($template); |
||||||
| 236 | |||||||
| 237 | // $template = $this->addModuleTemplate('chat_online', $template); |
||||||
| 238 | $template = SnTemplate::gettemplate('chat/chat_online', null); |
||||||
| 239 | // $template->assign_recursive($template_result); |
||||||
| 240 | $chat_online_players = 0; |
||||||
| 241 | $chat_online_invisibles = 0; |
||||||
| 242 | $chat_player_invisible = 0; |
||||||
| 243 | $template_result['.']['online_player'] = array(); |
||||||
| 244 | $ally_add = $alliance ? "AND u.ally_id = {$alliance}" : ''; |
||||||
| 245 | |||||||
| 246 | $chat_player_list = db_chat_player_list_online($config->chat_refresh_rate, $ally_add); |
||||||
| 247 | |||||||
| 248 | // TODO: Добавить ограничение по бану |
||||||
| 249 | while ($chat_player_row = db_fetch($chat_player_list)) { |
||||||
|
0 ignored issues
–
show
The function
db_fetch() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 250 | $chat_online_players++; |
||||||
| 251 | if ($chat_player_row['chat_player_invisible']) { |
||||||
| 252 | $chat_online_invisibles++; |
||||||
| 253 | } |
||||||
| 254 | |||||||
| 255 | if (!$chat_player_row['chat_player_invisible'] || $user['authlevel']) { |
||||||
| 256 | $safe_name = sys_safe_output($chat_player_row['username']); |
||||||
| 257 | $safe_name = $chat_player_row['username'] <> $safe_name || strpbrk($safe_name, ' /\\\'') !== false ? '"' . $safe_name . '"' : $safe_name; |
||||||
| 258 | $template_result['.']['online_player'][] = array( |
||||||
| 259 | 'ID' => $chat_player_row['id'], |
||||||
| 260 | 'NAME' => player_nick_render_to_html($chat_player_row, array( |
||||||
| 261 | 'color' => true, |
||||||
| 262 | 'icons' => true, |
||||||
| 263 | 'ally' => !$alliance, |
||||||
| 264 | 'class' => 'class="chat_nick_whisper" safe_name="' . $safe_name . '"', |
||||||
| 265 | )), |
||||||
| 266 | 'NAME_SAFE' => $safe_name, |
||||||
| 267 | 'MUTED' => $chat_player_row['chat_player_muted'] && $chat_player_row['chat_player_muted'] >= SN_TIME_NOW ? date(FMT_DATE_TIME, $chat_player_row['chat_player_muted']) : false, |
||||||
| 268 | 'MUTE_REASON' => htmlentities($chat_player_row['chat_player_mute_reason'], ENT_COMPAT, 'UTF-8'), |
||||||
| 269 | 'INVISIBLE' => $chat_player_row['chat_player_invisible'], |
||||||
| 270 | 'AUTH_LEVEL' => $chat_player_row['authlevel'], |
||||||
| 271 | ); |
||||||
| 272 | } |
||||||
| 273 | if ($user['id'] == $chat_player_row['id']) { |
||||||
| 274 | $chat_player_invisible = $chat_player_row['chat_player_invisible']; |
||||||
| 275 | } |
||||||
| 276 | } |
||||||
| 277 | |||||||
| 278 | $chat_commands = &$this->_chat_commands; |
||||||
| 279 | $template_result = array_merge($template_result, array( |
||||||
| 280 | 'USER_ID' => $user['id'], |
||||||
| 281 | 'USER_AUTHLEVEL' => $user['authlevel'], |
||||||
| 282 | 'USER_CAN_BAN' => in_array($user['authlevel'], $chat_commands['ban']['access']), |
||||||
| 283 | 'USER_CAN_MUTE' => in_array($user['authlevel'], $chat_commands['mute']['access']), |
||||||
| 284 | 'USER_CAN_UNMUTE' => in_array($user['authlevel'], $chat_commands['unmute']['access']), |
||||||
| 285 | )); |
||||||
| 286 | $template->assign_recursive($template_result); |
||||||
| 287 | $result['online'] = SnTemplate::templateRenderToHtml($template); |
||||||
| 288 | |||||||
| 289 | $result['online_players'] = $chat_online_players; |
||||||
| 290 | $result['online_invisibles'] = $chat_online_invisibles; |
||||||
| 291 | $result['chat_player_invisible'] = $chat_player_invisible; |
||||||
| 292 | $result['users_total'] = SN::$config->users_amount; |
||||||
| 293 | $result['users_online'] = SN::$config->var_online_user_count; |
||||||
| 294 | print(json_encode($result)); |
||||||
| 295 | } |
||||||
| 296 | die(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 297 | } |
||||||
| 298 | |||||||
| 299 | protected function _chatFrameView($template = null) { |
||||||
| 300 | defined('IN_AJAX') or define('IN_AJAX', true); |
||||||
| 301 | |||||||
| 302 | // $template = $this->addModuleTemplate('chat_frame', $template); |
||||||
| 303 | $template = SnTemplate::gettemplate('chat/chat_frame', $template); |
||||||
| 304 | require_once($template->files['chat_frame']); |
||||||
| 305 | die(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 306 | } |
||||||
| 307 | |||||||
| 308 | |||||||
| 309 | protected function _chatModel() { |
||||||
| 310 | global $user, $template_result, $lang; |
||||||
| 311 | |||||||
| 312 | $this->update_chat_activity(); |
||||||
| 313 | |||||||
| 314 | $mode = sys_get_param_int('mode'); |
||||||
| 315 | switch ($mode) { |
||||||
| 316 | case CHAT_MODE_ALLY: |
||||||
| 317 | $template_result['ALLY'] = intval($user['ally_id']); |
||||||
| 318 | $template_result['CHAT_MODE'] = CHAT_MODE_ALLY; |
||||||
| 319 | $page_title = $lang['chat_ally']; |
||||||
| 320 | break; |
||||||
| 321 | |||||||
| 322 | case CHAT_MODE_COMMON: |
||||||
| 323 | default: |
||||||
| 324 | $page_title = $lang['chat_common']; |
||||||
| 325 | $template_result['CHAT_MODE'] = CHAT_MODE_COMMON; |
||||||
| 326 | break; |
||||||
| 327 | } |
||||||
| 328 | |||||||
| 329 | $template_result['PAGE_HEADER'] = $page_title; |
||||||
| 330 | |||||||
| 331 | $template_result['.']['smiles'] = array(); |
||||||
| 332 | |||||||
| 333 | foreach (SN::$gc->design->getSmilesList() as $auth_level => $replaces) { |
||||||
| 334 | if ($auth_level > $user['authlevel']) { |
||||||
| 335 | continue; |
||||||
| 336 | } |
||||||
| 337 | |||||||
| 338 | foreach ($replaces as $bbcode => $filename) { |
||||||
| 339 | $template_result['.']['smiles'][] = array( |
||||||
| 340 | 'BBCODE' => htmlentities($bbcode, ENT_COMPAT, 'UTF-8'), |
||||||
| 341 | 'FILENAME' => $filename, |
||||||
| 342 | ); |
||||||
| 343 | } |
||||||
| 344 | } |
||||||
| 345 | } |
||||||
| 346 | |||||||
| 347 | protected function _chatAddModel() { |
||||||
| 348 | defined('IN_AJAX') or define('IN_AJAX', true); |
||||||
| 349 | |||||||
| 350 | global $config, $user, $lang; |
||||||
| 351 | // $chat_commands = get_unit_param(P_CHAT, P_CHAT_COMMANDS); |
||||||
| 352 | // $chat_aliases = get_unit_param(P_CHAT, P_CHAT_ALIASES); |
||||||
| 353 | $chat_commands = &$this->_chat_commands; |
||||||
| 354 | $chat_aliases = &$this->_chat_aliases; |
||||||
| 355 | |||||||
| 356 | if ($config->getMode() != classCache::CACHER_NO_CACHE && $config->chat_timeout && SN_TIME_MICRO - $config->array_get('users', $user['id'], 'chat_last_activity') > $config->chat_timeout) { |
||||||
| 357 | die(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 358 | } |
||||||
| 359 | |||||||
| 360 | if (($message = sys_get_param_str_unsafe('message')) && $user['username']) { |
||||||
| 361 | $this->update_chat_activity(); |
||||||
| 362 | |||||||
| 363 | $chat_message_sender_id = 'NULL'; |
||||||
| 364 | $chat_message_sender_name = ''; |
||||||
| 365 | $chat_message_recipient_id = $user['id']; |
||||||
| 366 | $chat_message_recipient_name = SN::$db->db_escape($user['username']); |
||||||
| 367 | $nick = ''; |
||||||
| 368 | $ally_id = 0; |
||||||
| 369 | $chat_command_issued = ''; |
||||||
| 370 | |||||||
| 371 | $chat_player_row = $this->sn_chat_advanced_get_chat_player_record($user['id']); |
||||||
| 372 | $chat_player_muted = $chat_player_row['chat_player_muted'] && $chat_player_row['chat_player_muted'] >= SN_TIME_NOW ? $chat_player_row['chat_player_muted'] : false; |
||||||
| 373 | if (preg_match("#^\/([\w\?]+)\s*({on|off|ID\s*[0-9]+|[а-яёА-ЯЁa-zA-Z0-9\_\-\[\]\(\)\+\{\}]+|\".+\"}*)*\s*(.*)#iu", $message, $chat_command_parsed)) { |
||||||
| 374 | $chat_command_exists = array_key_exists(strtolower($chat_command_parsed[1]), $chat_aliases) ? true : strtolower($chat_command_parsed[1]); |
||||||
| 375 | $chat_command_issued = $chat_command_exists === true ? $chat_aliases[$chat_command_parsed[1]] : 'help'; |
||||||
| 376 | if ($chat_command_accessible = in_array($user['authlevel'], $chat_commands[$chat_command_issued]['access'])) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 377 | switch ($chat_command_issued) { |
||||||
| 378 | case 'invisible': |
||||||
| 379 | //$chat_player_row = $this->sn_chat_advanced_get_chat_player_record($user['id'], '`chat_player_invisible`', true); |
||||||
| 380 | $chat_directive = strtolower($chat_command_parsed[2]) == 'on' || $chat_command_parsed[2] == 1 ? 1 : (strtolower($chat_command_parsed[2]) == 'off' || (string)$chat_command_parsed[2] === '0' ? 0 : ''); |
||||||
| 381 | if ($chat_directive !== '') { |
||||||
| 382 | doquery("UPDATE {{chat_player}} SET `chat_player_invisible` = {$chat_directive} WHERE `chat_player_player_id` = {$user['id']} LIMIT 1"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 383 | } else { |
||||||
| 384 | $chat_directive = $chat_player_row['chat_player_invisible']; |
||||||
| 385 | } |
||||||
| 386 | $message = "[c=lime]{$lang['chat_advanced_visible'][$chat_directive]}[/c]"; |
||||||
| 387 | break; |
||||||
| 388 | |||||||
| 389 | case 'whisper': |
||||||
| 390 | if ($chat_player_muted) { |
||||||
| 391 | $chat_command_issued = ''; |
||||||
| 392 | } elseif ($chat_command_parsed[3] && $chat_command_parsed[2]) { |
||||||
| 393 | $chat_command_parsed[2] = trim($chat_command_parsed[2], '"'); |
||||||
| 394 | $recipient_info = db_user_by_username($chat_command_parsed[2]); |
||||||
|
0 ignored issues
–
show
The function
db_user_by_username() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
Are you sure the assignment to
$recipient_info is correct as db_user_by_username($chat_command_parsed[2]) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||||
| 395 | $chat_command_parsed[2] = SN::$db->db_escape($chat_command_parsed[2]); |
||||||
| 396 | if ($recipient_info['id']) { |
||||||
| 397 | $message = $chat_command_parsed[3]; |
||||||
| 398 | $nick = SN::$db->db_escape(player_nick_compact(player_nick_render_current_to_array($user, array('color' => true, 'icons' => true, 'ally' => false)))); |
||||||
| 399 | $chat_message_recipient_id = $recipient_info['id']; |
||||||
| 400 | $chat_message_recipient_name = SN::$db->db_escape($recipient_info['username']); |
||||||
| 401 | $chat_message_sender_id = $user['id']; |
||||||
| 402 | $chat_message_sender_name = SN::$db->db_escape($user['username']); |
||||||
| 403 | } else { |
||||||
| 404 | $message = "[c=red]{$lang['chat_advanced_err_player_name_unknown']}[/c]"; |
||||||
| 405 | } |
||||||
| 406 | } elseif (!$chat_command_parsed[2]) { |
||||||
| 407 | $message = "[c=red]{$lang['chat_advanced_err_message_player_empty']}[/c]"; |
||||||
| 408 | } elseif (!$chat_command_parsed[3]) { |
||||||
| 409 | $message = "[c=red]{$lang['chat_advanced_err_message_empty']}[/c]"; |
||||||
| 410 | } |
||||||
| 411 | break; |
||||||
| 412 | |||||||
| 413 | case 'mute': |
||||||
| 414 | case 'ban': |
||||||
| 415 | case 'unmute': |
||||||
| 416 | case 'unban': |
||||||
| 417 | if ($chat_command_parsed[2] && ($chat_command_parsed[3] || $chat_command_issued == 'unmute' || $chat_command_issued == 'unban')) { |
||||||
| 418 | $chat_command_parsed[2] = strtolower($chat_command_parsed[2]); |
||||||
| 419 | if (strpos($chat_command_parsed[2], 'id ') !== false && is_id($player_id = substr($chat_command_parsed[2], 3))) { |
||||||
| 420 | $chat_player_subject = db_user_by_id($player_id, false); |
||||||
|
0 ignored issues
–
show
The function
db_user_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
$player_id of type string is incompatible with the type integer expected by parameter $user_id_unsafe of db_user_by_id().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 421 | if ($chat_player_subject) { |
||||||
| 422 | if ($chat_player_subject['id'] == $user['id']) { |
||||||
| 423 | $message = "[c=red]{$lang['chat_advanced_err_player_same']}[/c]"; |
||||||
| 424 | } elseif ($chat_player_subject['authlevel'] >= $user['authlevel']) { |
||||||
| 425 | $message = "[c=red]{$lang['chat_advanced_err_player_higher']}[/c]"; |
||||||
| 426 | } else { |
||||||
| 427 | $chat_message_recipient_id = 'NULL'; |
||||||
| 428 | $chat_message_recipient_name = ''; |
||||||
| 429 | if ($chat_command_issued == 'unmute' || $chat_command_issued == 'unban') { |
||||||
| 430 | $temp = SN::$db->db_escape($chat_command_parsed[3]); |
||||||
| 431 | if ($chat_command_issued == 'unban') { |
||||||
| 432 | sys_admin_player_ban_unset($user, $chat_player_subject, $temp); |
||||||
| 433 | $message = $lang['chat_advanced_command_unban']; |
||||||
| 434 | } elseif ($chat_command_issued == 'unmute') { |
||||||
| 435 | doquery("UPDATE {{chat_player}} SET `chat_player_muted` = 0, `chat_player_mute_reason` = '{$temp}' WHERE `chat_player_player_id` = {$chat_player_subject['id']} LIMIT 1"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 436 | $message = $lang['chat_advanced_command_unmute']; |
||||||
| 437 | } else { |
||||||
| 438 | $message = ''; |
||||||
| 439 | } |
||||||
| 440 | |||||||
| 441 | if ($message) { |
||||||
| 442 | $message = sprintf($message, $chat_player_subject['username']); |
||||||
| 443 | $message .= $chat_command_parsed[3] ? sprintf($lang['chat_advanced_command_reason'], $chat_command_parsed[3]) : ''; |
||||||
| 444 | $message = "[c=lime]{$message}[/c]"; |
||||||
| 445 | } |
||||||
| 446 | } elseif (preg_match("#(\d+)(y|m|w|d|h)(\!)?\s*(.*)#iu", $chat_command_parsed[3], $chat_command_parsed_two)) { |
||||||
| 447 | //TODO Localize [\s\pL\w]* |
||||||
| 448 | $date_to_timestamp = array( |
||||||
| 449 | 'y' => PERIOD_YEAR, |
||||||
| 450 | 'm' => PERIOD_MONTH, |
||||||
| 451 | 'w' => PERIOD_WEEK, |
||||||
| 452 | 'd' => PERIOD_DAY, |
||||||
| 453 | 'h' => PERIOD_HOUR, |
||||||
| 454 | ); |
||||||
| 455 | $this->sn_chat_advanced_get_chat_player_record($chat_player_subject['id'], '`chat_player_muted`', false); |
||||||
| 456 | |||||||
| 457 | $term = $date_to_timestamp[$chat_command_parsed_two[2]] * $chat_command_parsed_two[1]; |
||||||
| 458 | $date_compiled = $term + SN_TIME_NOW; |
||||||
| 459 | $chat_command_parsed_two[4] = SN::$db->db_escape($chat_command_parsed_two[4]); |
||||||
| 460 | |||||||
| 461 | doquery("UPDATE {{chat_player}} SET `chat_player_muted` = {$date_compiled}, `chat_player_mute_reason` = '{$chat_command_parsed_two[4]}' WHERE `chat_player_player_id` = {$chat_player_subject['id']} LIMIT 1"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 462 | if ($chat_command_issued == 'ban') { |
||||||
| 463 | sys_admin_player_ban($user, $chat_player_subject, $term, $chat_command_parsed_two[3] != '!', $chat_command_parsed_two[4]); |
||||||
| 464 | $message = $chat_command_parsed_two[3] == '!' ? $lang['chat_advanced_command_ban_no_vacancy'] : $lang['chat_advanced_command_ban']; |
||||||
| 465 | } else { |
||||||
| 466 | $message = $lang['chat_advanced_command_mute']; |
||||||
| 467 | } |
||||||
| 468 | // $message = sprintf($message, $chat_player_subject['username'], date(FMT_DATE_TIME, $date_compiled)); |
||||||
| 469 | // $message .= $chat_command_parsed_two[4] ? sprintf($lang['chat_advanced_command_reason'], $chat_command_parsed_two[4]) : ''; |
||||||
| 470 | $message = sprintf($message, $chat_player_subject['username'], date(FMT_DATE_TIME, $date_compiled), $chat_command_parsed_two[4] ? sprintf($lang['chat_advanced_command_reason'], $chat_command_parsed_two[4]) : ''); |
||||||
| 471 | $message = "[c=red]{$message}[/c]"; |
||||||
| 472 | } else { |
||||||
| 473 | $message = "[c=red]{$lang['chat_advanced_err_term_wrong']}[/c]"; |
||||||
| 474 | } |
||||||
| 475 | } |
||||||
| 476 | } else { |
||||||
| 477 | $message = "[c=red]{$lang['chat_advanced_err_player_id_unknown']}[/c]"; |
||||||
| 478 | } |
||||||
| 479 | } else { |
||||||
| 480 | $message = "[c=red]{$lang['chat_advanced_err_player_id_incorrect']}[/c]"; |
||||||
| 481 | } |
||||||
| 482 | } elseif (!$chat_command_parsed[2]) { |
||||||
| 483 | $message = "[c=red]{$lang['chat_advanced_err_player_id_need']}[/c]"; |
||||||
| 484 | } elseif (!$chat_command_parsed[3]) { |
||||||
| 485 | $message = "[c=red]{$lang['chat_advanced_err_term_need']}[/c]"; |
||||||
| 486 | } |
||||||
| 487 | break; |
||||||
| 488 | |||||||
| 489 | default: |
||||||
| 490 | $message = array(); |
||||||
| 491 | $chat_command_parsed[2] = strtolower($chat_command_parsed[2]); |
||||||
| 492 | |||||||
| 493 | $chat_directive = $chat_command_parsed[2] && array_key_exists($chat_command_parsed[2], $chat_aliases) ? $chat_aliases[$chat_command_parsed[2]] : ''; |
||||||
| 494 | |||||||
| 495 | if (!$chat_directive) { |
||||||
| 496 | $commands_available = array(); |
||||||
| 497 | $message[] = $lang['chat_advanced_help_description']; |
||||||
| 498 | foreach ($chat_commands as $chat_command_listed => $chat_command_info) { |
||||||
| 499 | if (in_array($user['authlevel'], $chat_command_info['access'])) { |
||||||
| 500 | $commands_available[] = $lang['chat_advanced_help_short'][$chat_command_listed]; |
||||||
| 501 | } |
||||||
| 502 | } |
||||||
| 503 | $message[] = $lang['chat_advanced_help_commands_accessible'] . ' ' . implode(', ', $commands_available); |
||||||
| 504 | } else { |
||||||
| 505 | $message[] = sprintf($lang['chat_advanced_help_command'], $chat_directive); |
||||||
| 506 | $message[] = $lang['chat_advanced_help'][$chat_directive]; |
||||||
| 507 | $aliases = array(); |
||||||
| 508 | foreach ($chat_aliases as $chat_command_alias => $chat_command_real) { |
||||||
| 509 | if ($chat_command_real == $chat_directive) { |
||||||
| 510 | $aliases[] = '/' . $chat_command_alias; |
||||||
| 511 | } |
||||||
| 512 | } |
||||||
| 513 | $message[] = $lang['chat_advanced_help_command_aliases'] . implode(', ', $aliases); |
||||||
| 514 | } |
||||||
| 515 | $message = implode(chr(13) . chr(10), $message); |
||||||
| 516 | $message = "[c=lime]{$message}[/c]"; |
||||||
| 517 | |||||||
| 518 | if ($chat_command_exists !== true) { |
||||||
| 519 | $message = "[c=red]{$lang['chat_advanced_err_command_unknown']} \"/{$chat_command_exists}\"[/c]" . chr(13) . chr(10) . $message; |
||||||
| 520 | } |
||||||
| 521 | break; |
||||||
| 522 | } |
||||||
| 523 | } else { |
||||||
| 524 | $message = "[c=red]{$lang['chat_advanced_err_command_inacessible']}[/c]"; |
||||||
| 525 | } |
||||||
| 526 | $message = "[b]{$message}[/b]"; |
||||||
| 527 | } |
||||||
| 528 | |||||||
| 529 | if (!$chat_command_issued && !$chat_player_muted) { |
||||||
| 530 | $chat_message_sender_id = $user['id']; |
||||||
| 531 | $chat_message_sender_name = SN::$db->db_escape($user['username']); |
||||||
| 532 | $chat_message_recipient_id = 'NULL'; |
||||||
| 533 | $chat_message_recipient_name = ''; |
||||||
| 534 | $ally_id = sys_get_param('ally') && $user['ally_id'] ? $user['ally_id'] : 0; |
||||||
| 535 | $nick = SN::$db->db_escape(player_nick_compact(player_nick_render_current_to_array($user, array('color' => true, 'icons' => true, 'ally' => !$ally_id, 'class' => 'class="chat_nick_msg"')))); |
||||||
| 536 | |||||||
| 537 | // Replacing news://xxx link with BBCode |
||||||
| 538 | $message = preg_replace("#news\:\/\/(\d+)#i", "[news=$1]", $message); |
||||||
| 539 | // Replacing news URL with BBCode |
||||||
| 540 | $message = preg_replace("#(?:https?\:\/\/(?:.+)?\/announce\.php\?id\=(\d+))#", "[news=$1]", $message); |
||||||
| 541 | $message = preg_replace("#(?:https?\:\/\/(?:.+)?\/index\.php\?page\=battle_report\&cypher\=([0-9a-zA-Z]{32}))#", "[ube=$1]", $message); |
||||||
| 542 | |||||||
| 543 | if ($color = sys_get_param_str('color')) { |
||||||
| 544 | $message = "[c={$color}]{$message}[/c]"; |
||||||
| 545 | } |
||||||
| 546 | } elseif (!$chat_command_issued && $chat_player_muted) { |
||||||
| 547 | $chat_message_recipient_id = $user['id']; |
||||||
| 548 | $chat_message_recipient_name = SN::$db->db_escape($user['username']); |
||||||
| 549 | $message = sprintf($lang['chat_advanced_command_mute'], $user['username'], date(FMT_DATE_TIME, $chat_player_muted)) . |
||||||
| 550 | ($chat_player_row['chat_player_muted_reason'] ? sprintf($lang['chat_advanced_command_mute_reason'], $chat_player_row['chat_player_muted_reason']) : ''); |
||||||
| 551 | $message = "[c=red]{$message}[/c]"; |
||||||
| 552 | } |
||||||
| 553 | $message = SN::$db->db_escape($message); |
||||||
| 554 | |||||||
| 555 | doquery( |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 556 | "INSERT INTO |
||||||
| 557 | {{chat}} |
||||||
| 558 | SET |
||||||
| 559 | `user` = '{$nick}', |
||||||
| 560 | `ally_id` = '{$ally_id}', |
||||||
| 561 | `message` = '{$message}', |
||||||
| 562 | `timestamp` = " . SN_TIME_NOW . ", |
||||||
| 563 | `chat_message_sender_id` = {$chat_message_sender_id}, |
||||||
| 564 | `chat_message_sender_name` = '{$chat_message_sender_name}', |
||||||
| 565 | `chat_message_recipient_id` = {$chat_message_recipient_id}, |
||||||
| 566 | `chat_message_recipient_name` = '{$chat_message_recipient_name}'" |
||||||
| 567 | ); |
||||||
| 568 | } |
||||||
| 569 | |||||||
| 570 | die(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 571 | } |
||||||
| 572 | |||||||
| 573 | |||||||
| 574 | protected function update_chat_activity($refresh = false) { |
||||||
| 575 | global $config, $user; |
||||||
| 576 | |||||||
| 577 | $config->array_set('users', $user['id'], 'chat_last_activity', SN_TIME_MICRO); |
||||||
| 578 | $config->array_set('users', $user['id'], 'chat_last_refresh', $refresh ? 0 : SN_TIME_MICRO); |
||||||
| 579 | |||||||
| 580 | $activity_row = doquery("SELECT `chat_player_id` FROM {{chat_player}} WHERE `chat_player_player_id` = {$user['id']} LIMIT 1", true); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
true of type true is incompatible with the type string expected by parameter $table of doquery().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 581 | if (!$activity_row) { |
||||||
| 582 | doquery("INSERT INTO {{chat_player}} SET `chat_player_player_id` = {$user['id']}"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 583 | } else { |
||||||
| 584 | doquery("UPDATE {{chat_player}} SET `chat_player_activity` = '" . SN::$db->db_escape(SN_TIME_SQL) . "' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 585 | } |
||||||
| 586 | } |
||||||
| 587 | |||||||
| 588 | protected function sn_chat_advanced_get_chat_player_record($player_id, $fields = '*', $return_data = true) { |
||||||
| 589 | $result = false; |
||||||
| 590 | if($player_id) { |
||||||
| 591 | if(!($result = doquery("SELECT {$fields} FROM {{chat_player}} WHERE `chat_player_player_id` = {$player_id} LIMIT 1", true))) { |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
true of type true is incompatible with the type string expected by parameter $table of doquery().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 592 | doquery("INSERT INTO {{chat_player}} SET `chat_player_player_id` = {$player_id}"); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 593 | if($return_data) { |
||||||
| 594 | $result = doquery("SELECT {$fields} FROM {{chat_player}} WHERE `chat_player_player_id` = {$player_id} LIMIT 1", true); |
||||||
|
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 595 | } |
||||||
| 596 | } |
||||||
| 597 | } |
||||||
| 598 | |||||||
| 599 | return $result; |
||||||
| 600 | } |
||||||
| 601 | |||||||
| 602 | |||||||
| 603 | } |
||||||
| 604 |