@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | $this->prepare(); |
94 | 94 | |
95 | 95 | $this->manifest['active'] = false; |
96 | - if(!empty($this->config) && is_array($this->config['db'])) { |
|
96 | + if (!empty($this->config) && is_array($this->config['db'])) { |
|
97 | 97 | // БД, отличная от стандартной |
98 | 98 | $this->db = new db_mysql(); |
99 | 99 | |
100 | 100 | $this->db->sn_db_connect($this->config['db']); |
101 | - if($this->manifest['active'] = $this->db->connected) { |
|
101 | + if ($this->manifest['active'] = $this->db->connected) { |
|
102 | 102 | $this->provider_id = ACCOUNT_PROVIDER_CENTRAL; |
103 | 103 | |
104 | 104 | $this->domain = $this->config['domain']; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | // Fallback to local DB |
115 | - if(!$this->manifest['active']) { |
|
115 | + if (!$this->manifest['active']) { |
|
116 | 116 | $this->db = classSupernova::$db; |
117 | 117 | |
118 | 118 | $this->provider_id = ACCOUNT_PROVIDER_LOCAL; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $this->manifest['active'] = true; |
126 | 126 | } |
127 | 127 | |
128 | - $this->cookie_name_impersonate = $this->cookie_name . AUTH_COOKIE_IMPERSONATE_SUFFIX; |
|
128 | + $this->cookie_name_impersonate = $this->cookie_name.AUTH_COOKIE_IMPERSONATE_SUFFIX; |
|
129 | 129 | |
130 | 130 | $this->account = new Account($this->db); |
131 | 131 | $this->confirmation = new Confirmation($this->db); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | // OK v4.5 |
167 | 167 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
168 | 168 | $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe); |
169 | - if($result) { |
|
169 | + if ($result) { |
|
170 | 170 | $this->cookie_set(); |
171 | 171 | } |
172 | 172 | |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | */ |
195 | 195 | // OK v4.6 |
196 | 196 | protected function password_reset_send_code() { |
197 | - if(!$this->is_password_reset) { |
|
197 | + if (!$this->is_password_reset) { |
|
198 | 198 | return $this->account_login_status; |
199 | 199 | } |
200 | 200 | |
201 | 201 | // Проверяем поддержку сброса пароля |
202 | - if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
202 | + if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
203 | 203 | return $this->account_login_status; |
204 | 204 | } |
205 | 205 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | unset($this->account); |
210 | 210 | $this->account = new Account($this->db); |
211 | 211 | |
212 | - if(!$this->account->db_get_by_email($email_unsafe)) { |
|
212 | + if (!$this->account->db_get_by_email($email_unsafe)) { |
|
213 | 213 | throw new Exception(PASSWORD_RESTORE_ERROR_EMAIL_NOT_EXISTS, ERR_ERROR); |
214 | 214 | // return $this->account_login_status; |
215 | 215 | } |
@@ -219,14 +219,14 @@ discard block |
||
219 | 219 | |
220 | 220 | // TODO - Проверять уровень доступа аккаунта! |
221 | 221 | // Аккаунты с АУТЛЕВЕЛ больше 0 - НЕ СБРАСЫВАЮТ ПАРОЛИ! |
222 | - foreach($user_list as $user_id => $user_data) { |
|
223 | - if($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) { |
|
222 | + foreach ($user_list as $user_id => $user_data) { |
|
223 | + if ($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) { |
|
224 | 224 | throw new Exception(PASSWORD_RESTORE_ERROR_ADMIN_ACCOUNT, ERR_ERROR); |
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | 228 | $confirmation = $this->confirmation->db_confirmation_get_latest_by_type_and_email(CONFIRM_PASSWORD_RESET, $email_unsafe); // OK 4.5 |
229 | - if(isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) { |
|
229 | + if (isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) { |
|
230 | 230 | throw new Exception(PASSWORD_RESTORE_ERROR_TOO_OFTEN, ERR_ERROR); |
231 | 231 | } |
232 | 232 | |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | |
240 | 240 | @$result = mymail($email_unsafe, |
241 | 241 | sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name), |
242 | - sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL . 'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name) |
|
242 | + sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL.'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name) |
|
243 | 243 | ); |
244 | 244 | |
245 | 245 | $result = $result ? PASSWORD_RESTORE_SUCCESS_CODE_SENT : PASSWORD_RESTORE_ERROR_SENDING; |
246 | - } catch(Exception $e) { |
|
246 | + } catch (Exception $e) { |
|
247 | 247 | sn_db_transaction_rollback(); |
248 | 248 | $result = $e->getMessage(); |
249 | 249 | } |
@@ -256,46 +256,46 @@ discard block |
||
256 | 256 | * @return int|string |
257 | 257 | */ |
258 | 258 | protected function password_reset_confirm() { |
259 | - if(!$this->is_password_reset_confirm) { |
|
259 | + if (!$this->is_password_reset_confirm) { |
|
260 | 260 | return $this->account_login_status; |
261 | 261 | } |
262 | 262 | |
263 | - if($this->account_login_status != LOGIN_UNDEFINED) { |
|
263 | + if ($this->account_login_status != LOGIN_UNDEFINED) { |
|
264 | 264 | return $this->account_login_status; |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Проверяем поддержку сброса пароля |
268 | - if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
268 | + if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
269 | 269 | return $this->account_login_status; |
270 | 270 | } |
271 | 271 | |
272 | 272 | try { |
273 | 273 | $code_unsafe = sys_get_param_str_unsafe('password_reset_code'); |
274 | - if(empty($code_unsafe)) { |
|
274 | + if (empty($code_unsafe)) { |
|
275 | 275 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR); |
276 | 276 | } |
277 | 277 | |
278 | 278 | sn_db_transaction_start(); |
279 | 279 | $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe); // OK 4.5 |
280 | 280 | |
281 | - if(empty($confirmation)) { |
|
281 | + if (empty($confirmation)) { |
|
282 | 282 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR); |
283 | 283 | } |
284 | 284 | |
285 | - if(SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) { |
|
285 | + if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) { |
|
286 | 286 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR); |
287 | 287 | } |
288 | 288 | |
289 | 289 | unset($this->account); |
290 | 290 | $this->account = new Account($this->db); |
291 | 291 | |
292 | - if(!$this->account->db_get_by_email($confirmation['email'])) { |
|
292 | + if (!$this->account->db_get_by_email($confirmation['email'])) { |
|
293 | 293 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR); |
294 | 294 | } |
295 | 295 | |
296 | 296 | $new_password_unsafe = $this->make_random_password(); |
297 | 297 | $salt_unsafe = $this->password_salt_generate(); |
298 | - if(!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) { |
|
298 | + if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) { |
|
299 | 299 | // Ошибка смены пароля |
300 | 300 | throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR); |
301 | 301 | } |
@@ -305,14 +305,14 @@ discard block |
||
305 | 305 | $this->cookie_set(); |
306 | 306 | $this->login_cookie(); |
307 | 307 | |
308 | - if($this->account_login_status == LOGIN_SUCCESS) { |
|
308 | + if ($this->account_login_status == LOGIN_SUCCESS) { |
|
309 | 309 | // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!! |
310 | 310 | $message_header = sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name); |
311 | 311 | $message = sprintf(classLocale::$lang['log_lost_email_pass'], classSupernova::$config->game_name, $this->account->account_name, $new_password_unsafe); |
312 | 312 | @$operation_result = mymail($confirmation['email'], $message_header, htmlspecialchars($message)); |
313 | 313 | |
314 | 314 | $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5 |
315 | - if(!empty($users_translated)) { |
|
315 | + if (!empty($users_translated)) { |
|
316 | 316 | // Отправляем в лички письмо о сбросе пароля |
317 | 317 | |
318 | 318 | // ПО ОПРЕДЕЛЕНИЮ в $users_translated только |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | // - игроки, привязанные только к этим аккаунтам |
322 | 322 | // Значит им всем сразу скопом можно отправлять сообщения |
323 | 323 | $message = sprintf(classLocale::$lang['sys_password_reset_message_body'], $new_password_unsafe); |
324 | - $message = sys_bbcodeParse($message) . '<br><br>'; |
|
324 | + $message = sys_bbcodeParse($message).'<br><br>'; |
|
325 | 325 | |
326 | - foreach($users_translated as $user_id => $providers_list) { |
|
326 | + foreach ($users_translated as $user_id => $providers_list) { |
|
327 | 327 | msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, classLocale::$lang['sys_administration'], classLocale::$lang['sys_login_register_message_title'], $message); |
328 | 328 | } |
329 | 329 | } else { |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | // OK v4.5 |
376 | 376 | protected function register() { |
377 | 377 | // TODO РЕГИСТРАЦИЯ ВСЕГДА ДОЛЖНА ЛОГИНИТЬ ПОЛЬЗОВАТЕЛЯ! |
378 | - $this->flog('Регистрация: начинаем. Провайдер ' . $this->provider_id); |
|
378 | + $this->flog('Регистрация: начинаем. Провайдер '.$this->provider_id); |
|
379 | 379 | |
380 | 380 | try { |
381 | - if(!$this->is_register) { |
|
381 | + if (!$this->is_register) { |
|
382 | 382 | $this->flog('Регистрация: не выставлен флаг регистрации - пропускаем'); |
383 | 383 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
384 | 384 | } |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | sn_db_transaction_start(); |
389 | 389 | |
390 | 390 | $this->account->db_get_by_name_or_email($this->input_login_unsafe, $this->input_email_unsafe); |
391 | - if($this->account->is_exists) { |
|
392 | - if($this->account->account_email == $this->input_email_unsafe) { |
|
391 | + if ($this->account->is_exists) { |
|
392 | + if ($this->account->account_email == $this->input_email_unsafe) { |
|
393 | 393 | throw new Exception(REGISTER_ERROR_EMAIL_EXISTS, ERR_ERROR); |
394 | 394 | } else { |
395 | 395 | throw new Exception(REGISTER_ERROR_ACCOUNT_NAME_EXISTS, ERR_ERROR); |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | // А вот это пока не нужно. Трансляцией аккаунтов в юзеров и созданием новых юзеров для новозашедших аккаунтов занимается Auth |
412 | 412 | // $this->register_account(); |
413 | 413 | sn_db_transaction_commit(); |
414 | - } catch(Exception $e) { |
|
414 | + } catch (Exception $e) { |
|
415 | 415 | sn_db_transaction_rollback(); |
416 | 416 | $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false; |
417 | 417 | } |
@@ -427,19 +427,19 @@ discard block |
||
427 | 427 | */ |
428 | 428 | // OK v4.5 |
429 | 429 | protected function login_cookie() { |
430 | - if($this->account_login_status != LOGIN_UNDEFINED) { |
|
430 | + if ($this->account_login_status != LOGIN_UNDEFINED) { |
|
431 | 431 | return $this->account_login_status; |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Пытаемся войти по куке |
435 | - if(!empty($_COOKIE[$this->cookie_name])) { |
|
436 | - if(count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) { |
|
435 | + if (!empty($_COOKIE[$this->cookie_name])) { |
|
436 | + if (count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) { |
|
437 | 437 | list($account_id_unsafe, $cookie_password_hash_salted, $user_remember_me) = explode(AUTH_COOKIE_DELIMETER, $_COOKIE[$this->cookie_name]); |
438 | 438 | } else { |
439 | 439 | list($account_id_unsafe, $user_name, $cookie_password_hash_salted, $user_remember_me) = explode("/%/", $_COOKIE[$this->cookie_name]); |
440 | 440 | } |
441 | 441 | |
442 | - if( |
|
442 | + if ( |
|
443 | 443 | $this->account->db_get_by_id($account_id_unsafe) |
444 | 444 | && ($this->password_encode_for_cookie($this->account->account_password) == $cookie_password_hash_salted) |
445 | 445 | ) { |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if($this->account_login_status != LOGIN_SUCCESS) { |
|
451 | + if ($this->account_login_status != LOGIN_SUCCESS) { |
|
452 | 452 | // Невалидная кука - чистим |
453 | 453 | $this->cookie_clear(); |
454 | 454 | } |
@@ -466,29 +466,29 @@ discard block |
||
466 | 466 | protected function login_username() { |
467 | 467 | // TODO - Логин по старым именам |
468 | 468 | try { |
469 | - if(!$this->is_login) { |
|
469 | + if (!$this->is_login) { |
|
470 | 470 | $this->flog('Логин: не выставлен флаг входа в игру - это не логин'); |
471 | 471 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
472 | 472 | } |
473 | 473 | |
474 | 474 | // TODO Пустое имя аккаунта |
475 | - if(!$this->input_login_unsafe) { |
|
475 | + if (!$this->input_login_unsafe) { |
|
476 | 476 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
477 | 477 | } |
478 | 478 | |
479 | 479 | $this->login_validate_input(); |
480 | 480 | |
481 | - if(!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) { |
|
481 | + if (!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) { |
|
482 | 482 | throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR); |
483 | 483 | } |
484 | 484 | |
485 | - if(!$this->account->password_check($this->input_login_password_raw)) { |
|
485 | + if (!$this->account->password_check($this->input_login_password_raw)) { |
|
486 | 486 | throw new Exception(LOGIN_ERROR_PASSWORD, ERR_ERROR); |
487 | 487 | } |
488 | 488 | |
489 | 489 | $this->cookie_set(); |
490 | 490 | $this->account_login_status = LOGIN_SUCCESS; |
491 | - } catch(Exception $e) { |
|
491 | + } catch (Exception $e) { |
|
492 | 492 | $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false; |
493 | 493 | } |
494 | 494 | |
@@ -510,18 +510,18 @@ discard block |
||
510 | 510 | protected function cookie_set($account_to_impersonate = null) { |
511 | 511 | $this_account = is_object($account_to_impersonate) ? $account_to_impersonate : $this->account; |
512 | 512 | |
513 | - if(!is_object($this_account) || !$this_account->is_exists) { |
|
513 | + if (!is_object($this_account) || !$this_account->is_exists) { |
|
514 | 514 | throw new Exception(LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET, ERR_ERROR); |
515 | 515 | } |
516 | 516 | |
517 | - if(is_object($account_to_impersonate) && $account_to_impersonate->is_exists) { |
|
517 | + if (is_object($account_to_impersonate) && $account_to_impersonate->is_exists) { |
|
518 | 518 | sn_setcookie($this->cookie_name_impersonate, $_COOKIE[$this->cookie_name], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain); |
519 | 519 | } |
520 | 520 | |
521 | 521 | $expire_time = $this->remember_me ? SN_TIME_NOW + PERIOD_YEAR : 0; |
522 | 522 | |
523 | 523 | $password_encoded = $this->password_encode_for_cookie($this_account->account_password); |
524 | - $cookie = $this_account->account_id . AUTH_COOKIE_DELIMETER . $password_encoded . AUTH_COOKIE_DELIMETER . $this->remember_me; |
|
524 | + $cookie = $this_account->account_id.AUTH_COOKIE_DELIMETER.$password_encoded.AUTH_COOKIE_DELIMETER.$this->remember_me; |
|
525 | 525 | $this->flog("cookie_set() - Устанавливаем куку {$cookie}"); |
526 | 526 | return sn_setcookie($this->cookie_name, $cookie, $expire_time, $this->sn_root_path, $this->domain); |
527 | 527 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | // OK v4.1 |
533 | 533 | protected function cookie_clear() { |
534 | 534 | // Автоматически вообще-то - если установлена кука имперсонатора - то чистим обычную, а куку имперсонатора - копируем в неё |
535 | - if(!empty($_COOKIE[$this->cookie_name_impersonate])) { |
|
535 | + if (!empty($_COOKIE[$this->cookie_name_impersonate])) { |
|
536 | 536 | sn_setcookie($this->cookie_name, $_COOKIE[$this->cookie_name_impersonate], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain); |
537 | 537 | sn_setcookie($this->cookie_name_impersonate, '', SN_TIME_NOW - PERIOD_WEEK, $this->sn_root_path, $this->domain); |
538 | 538 | } else { |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | protected function login_validate_input() { |
552 | 552 | // Проверяем, что бы в начале и конце не было пустых символов |
553 | 553 | // TODO - при копировании Эксель -> Опера - в конце образуются пустые места. Это не должно быть проблемой! Вынести проверку пароля в регистрацию! |
554 | - if($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
554 | + if ($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
555 | 555 | throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR); |
556 | 556 | } |
557 | - if(!$this->input_login_password_raw) { |
|
557 | + if (!$this->input_login_password_raw) { |
|
558 | 558 | throw new Exception(LOGIN_ERROR_PASSWORD_EMPTY, ERR_ERROR); |
559 | 559 | } |
560 | 560 | } |
@@ -570,37 +570,37 @@ discard block |
||
570 | 570 | $this->login_validate_input(); |
571 | 571 | |
572 | 572 | // Если нет имени пользователя - NO GO! |
573 | - if(!$this->input_login_unsafe) { |
|
573 | + if (!$this->input_login_unsafe) { |
|
574 | 574 | throw new Exception(LOGIN_ERROR_USERNAME_EMPTY, ERR_ERROR); |
575 | 575 | } |
576 | 576 | // Если логин имеет запрещенные символы - NO GO! |
577 | - if(strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
577 | + if (strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
578 | 578 | throw new Exception(LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS, ERR_ERROR); |
579 | 579 | } |
580 | 580 | // Если логин меньше минимальной длины - NO GO! |
581 | - if(strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) { |
|
581 | + if (strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) { |
|
582 | 582 | throw new Exception(REGISTER_ERROR_USERNAME_SHORT, ERR_ERROR); |
583 | 583 | } |
584 | 584 | // Если пароль меньше минимальной длины - NO GO! |
585 | - if(strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) { |
|
585 | + if (strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) { |
|
586 | 586 | throw new Exception(REGISTER_ERROR_PASSWORD_INSECURE, ERR_ERROR); |
587 | 587 | } |
588 | 588 | // Если пароль имеет пробельные символы в начале или конце - NO GO! |
589 | - if($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
589 | + if ($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
590 | 590 | throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR); |
591 | 591 | } |
592 | 592 | // Если пароль не совпадает с подтверждением - NO GO! То, что у пароля нет пробельных символов в начале/конце - мы уже проверили выше |
593 | 593 | //Если они есть у повтора - значит пароль и повтор не совпадут |
594 | - if($this->input_login_password_raw <> $this->input_login_password_raw_repeat) { |
|
594 | + if ($this->input_login_password_raw <> $this->input_login_password_raw_repeat) { |
|
595 | 595 | throw new Exception(REGISTER_ERROR_PASSWORD_DIFFERENT, ERR_ERROR); |
596 | 596 | } |
597 | 597 | // Если нет емейла - NO GO! |
598 | 598 | // TODO - регистрация без емейла |
599 | - if(!$this->input_email_unsafe) { |
|
599 | + if (!$this->input_email_unsafe) { |
|
600 | 600 | throw new Exception(REGISTER_ERROR_EMAIL_EMPTY, ERR_ERROR); |
601 | 601 | } |
602 | 602 | // Если емейл не является емейлом - NO GO! |
603 | - if(!is_email($this->input_email_unsafe)) { |
|
603 | + if (!is_email($this->input_email_unsafe)) { |
|
604 | 604 | throw new Exception(REGISTER_ERROR_EMAIL_WRONG, ERR_ERROR); |
605 | 605 | } |
606 | 606 | } |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | |
610 | 610 | // OK v4 |
611 | 611 | protected function password_encode_for_cookie($password) { |
612 | - return md5("{$password}--" . $this->secret_word); |
|
612 | + return md5("{$password}--".$this->secret_word); |
|
613 | 613 | } |
614 | 614 | // OK v4 |
615 | 615 | protected function password_encode($password, $salt) { |
@@ -629,22 +629,22 @@ discard block |
||
629 | 629 | return core_auth::make_random_password(); |
630 | 630 | } |
631 | 631 | protected function flog($message, $die = false) { |
632 | - if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
632 | + if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
633 | 633 | return; |
634 | 634 | } |
635 | 635 | list($called, $caller) = debug_backtrace(false); |
636 | 636 | |
637 | 637 | $caller_name = |
638 | - ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')) . |
|
639 | - (!empty($caller['type']) ? $caller['type'] : '') . |
|
640 | - (!empty($caller['function']) ? $caller['function'] : '') . |
|
641 | - (!empty($called['line']) ? ':' . $called['line'] : ''); |
|
638 | + ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')). |
|
639 | + (!empty($caller['type']) ? $caller['type'] : ''). |
|
640 | + (!empty($caller['function']) ? $caller['function'] : ''). |
|
641 | + (!empty($called['line']) ? ':'.$called['line'] : ''); |
|
642 | 642 | |
643 | 643 | $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false; |
644 | 644 | |
645 | 645 | classSupernova::log_file("$message - $caller_name"); |
646 | - if($die) { |
|
647 | - $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
|
646 | + if ($die) { |
|
647 | + $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в ".get_called_class()." (располагается в ".get_class()."). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | |
36 | 36 | $this->container = array(); |
37 | 37 | |
38 | - if(classSupernova::$cache->getMode() != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
38 | + if (classSupernova::$cache->getMode() != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
39 | 39 | $this->cache = classSupernova::$cache; |
40 | 40 | classSupernova::log_file('locale.__constructor: Cache is present'); |
41 | 41 | //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug! |
42 | 42 | } |
43 | 43 | |
44 | - if($enable_stat_usage && empty($this->stat_usage)) { |
|
44 | + if ($enable_stat_usage && empty($this->stat_usage)) { |
|
45 | 45 | $this->enable_stat_usage = $enable_stat_usage; |
46 | 46 | $this->usage_stat_load(); |
47 | 47 | // TODO shutdown function |
@@ -67,18 +67,18 @@ discard block |
||
67 | 67 | unset($fallback[$this->active]); |
68 | 68 | |
69 | 69 | // Проходим по оставшимся локалям |
70 | - foreach($fallback as $try_language) { |
|
70 | + foreach ($fallback as $try_language) { |
|
71 | 71 | // Если нет такой строки - пытаемся вытащить из кэша |
72 | - if(!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
73 | - $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset); |
|
72 | + if (!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
73 | + $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix.$try_language.'_'.$offset); |
|
74 | 74 | // Записываем результат работы кэша |
75 | 75 | $locale_cache_statistic['queries']++; |
76 | 76 | isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['hits']++ : $locale_cache_statistic['misses']++; |
77 | -!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix . $try_language . '_' . $offset : false; |
|
77 | +!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix.$try_language.'_'.$offset : false; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Если мы как-то где-то нашли строку... |
81 | - if(isset($this->container[$try_language][$offset])) { |
|
81 | + if (isset($this->container[$try_language][$offset])) { |
|
82 | 82 | // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер |
83 | 83 | $this[$offset] = $this->container[$try_language][$offset]; |
84 | 84 | $locale_cache_statistic['fallbacks']++; |
@@ -94,16 +94,16 @@ discard block |
||
94 | 94 | $this->container[$this->active][] = $value; |
95 | 95 | } else { |
96 | 96 | $this->container[$this->active][$offset] = $value; |
97 | - if($this->cache) { |
|
98 | - $this->cache->__set($this->cache_prefix_lang . $offset, $value); |
|
97 | + if ($this->cache) { |
|
98 | + $this->cache->__set($this->cache_prefix_lang.$offset, $value); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | public function offsetExists($offset) { |
103 | 103 | // Шорткат если у нас уже есть строка в памяти PHP |
104 | - if(!isset($this->container[$this->active][$offset])) { |
|
104 | + if (!isset($this->container[$this->active][$offset])) { |
|
105 | 105 | // pdump($this->cache_prefix_lang . $offset); |
106 | - if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) { |
|
106 | + if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang.$offset))) { |
|
107 | 107 | // pdump($this->cache_prefix_lang . $offset); |
108 | 108 | // Если нету такой строки - делаем фоллбэк |
109 | 109 | $this->locale_string_fallback($offset); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | public function offsetGet($offset) { |
121 | 121 | $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null; |
122 | - if($this->enable_stat_usage) { |
|
122 | + if ($this->enable_stat_usage) { |
|
123 | 123 | $this->usage_stat_log($offset, $value); |
124 | 124 | } |
125 | 125 | return $value; |
@@ -134,23 +134,23 @@ discard block |
||
134 | 134 | |
135 | 135 | |
136 | 136 | public function usage_stat_load() { |
137 | - $this->stat_usage = classSupernova::$cache->lng_stat_usage = array(); |
|
138 | - if(empty($this->stat_usage)) { |
|
137 | + $this->stat_usage = classSupernova::$cache->lng_stat_usage = array(); |
|
138 | + if (empty($this->stat_usage)) { |
|
139 | 139 | $query = classSupernova::$db->doSelect("SELECT * FROM `{{lng_usage_stat}}`"); |
140 | - while($row = db_fetch($query)) { |
|
141 | - $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty']; |
|
140 | + while ($row = db_fetch($query)) { |
|
141 | + $this->stat_usage[$row['lang_code'].':'.$row['string_id'].':'.$row['file'].':'.$row['line']] = $row['is_empty']; |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | } |
145 | 145 | public function usage_stat_save() { |
146 | - if(!empty($this->stat_usage_new)) { |
|
146 | + if (!empty($this->stat_usage_new)) { |
|
147 | 147 | classSupernova::$cache->lng_stat_usage = $this->stat_usage; |
148 | 148 | classSupernova::$db->doSelect("SELECT 1 FROM `{{lng_usage_stat}}` LIMIT 1"); |
149 | - foreach($this->stat_usage_new as &$value) { |
|
150 | - foreach($value as &$value2) { |
|
151 | - $value2 = '"' . db_escape($value2) . '"'; |
|
149 | + foreach ($this->stat_usage_new as &$value) { |
|
150 | + foreach ($value as &$value2) { |
|
151 | + $value2 = '"'.db_escape($value2).'"'; |
|
152 | 152 | } |
153 | - $value = '(' . implode(',', $value) .')'; |
|
153 | + $value = '('.implode(',', $value).')'; |
|
154 | 154 | } |
155 | 155 | classSupernova::$gc->db->doReplaceValuesDeprecated( |
156 | 156 | 'lng_usage_stat', |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | |
174 | 174 | $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1)); |
175 | 175 | |
176 | - $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line']; |
|
177 | - if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) { |
|
176 | + $string_id = $this->active.':'.$offset.':'.$file.':'.$trace[1]['line']; |
|
177 | + if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) { |
|
178 | 178 | $this->stat_usage[$string_id] = empty($value); |
179 | 179 | $this->stat_usage_new[] = array( |
180 | 180 | 'lang_code' => $this->active, |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | 'file' => $file, |
183 | 183 | 'line' => $trace[1]['line'], |
184 | 184 | 'is_empty' => intval(empty($value)), |
185 | - 'locale' => '' . $value, |
|
185 | + 'locale' => ''.$value, |
|
186 | 186 | ); |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | |
191 | 191 | protected function lng_try_filepath($path, $file_path_relative) { |
192 | - $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative; |
|
192 | + $file_path = SN_ROOT_PHYSICAL.($path && file_exists(SN_ROOT_PHYSICAL.$path.$file_path_relative) ? $path : '').$file_path_relative; |
|
193 | 193 | return file_exists($file_path) ? $file_path : false; |
194 | 194 | } |
195 | 195 | |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | |
212 | 212 | classSupernova::log_file("locale.include: Loading data from domain '{$filename}'", 1); |
213 | 213 | |
214 | - $cache_file_key = $this->cache_prefix_lang . '__' . $filename; |
|
214 | + $cache_file_key = $this->cache_prefix_lang.'__'.$filename; |
|
215 | 215 | |
216 | 216 | // Подключен ли внешний кэш? |
217 | - if($this->cache) { |
|
217 | + if ($this->cache) { |
|
218 | 218 | // Загружен ли уже данный файл? |
219 | 219 | $cache_file_status = $this->cache->__get($cache_file_key); |
220 | - classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0); |
|
221 | - if($cache_file_status) { |
|
220 | + classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is ".($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0); |
|
221 | + if ($cache_file_status) { |
|
222 | 222 | // Если да - повторять загрузку нет смысла |
223 | 223 | return null; |
224 | 224 | } |
@@ -232,47 +232,47 @@ discard block |
||
232 | 232 | $this->make_fallback($language); |
233 | 233 | |
234 | 234 | $file_path = ''; |
235 | - foreach($this->fallback as $lang_try) { |
|
236 | - if(!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
235 | + foreach ($this->fallback as $lang_try) { |
|
236 | + if (!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
237 | 237 | continue; |
238 | 238 | } |
239 | 239 | |
240 | - if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
240 | + if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
241 | 241 | break; |
242 | 242 | } |
243 | 243 | |
244 | - if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
244 | + if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
245 | 245 | break; |
246 | 246 | } |
247 | 247 | |
248 | 248 | $file_path = ''; |
249 | 249 | } |
250 | 250 | |
251 | - if($file_path) { |
|
251 | + if ($file_path) { |
|
252 | 252 | $a_lang_array = array(); |
253 | 253 | include($file_path); |
254 | 254 | |
255 | - if(!empty($a_lang_array)) { |
|
255 | + if (!empty($a_lang_array)) { |
|
256 | 256 | $this->merge($a_lang_array); |
257 | 257 | |
258 | 258 | // Загрузка данных из файла в кэш |
259 | - if($this->cache) { |
|
259 | + if ($this->cache) { |
|
260 | 260 | classSupernova::log_file("Locale: loading '{$filename}' into cache"); |
261 | - foreach($a_lang_array as $key => $value) { |
|
262 | - $value_cache_key = $this->cache_prefix_lang . $key; |
|
263 | - if($this->cache->__isset($value_cache_key)) { |
|
264 | - if(is_array($value)) { |
|
261 | + foreach ($a_lang_array as $key => $value) { |
|
262 | + $value_cache_key = $this->cache_prefix_lang.$key; |
|
263 | + if ($this->cache->__isset($value_cache_key)) { |
|
264 | + if (is_array($value)) { |
|
265 | 265 | $alt_value = $this->cache->__get($value_cache_key); |
266 | 266 | $value = array_replace_recursive($alt_value, $value); |
267 | 267 | // pdump($alt_value, $alt_value); |
268 | 268 | } |
269 | 269 | } |
270 | - $this->cache->__set($this->cache_prefix_lang . $key, $value); |
|
270 | + $this->cache->__set($this->cache_prefix_lang.$key, $value); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - if($this->cache) { |
|
275 | + if ($this->cache) { |
|
276 | 276 | $this->cache->__set($cache_file_key, true); |
277 | 277 | } |
278 | 278 | |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | public function lng_load_i18n($i18n) { |
288 | - if(!isset($i18n)) { |
|
288 | + if (!isset($i18n)) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | - foreach($i18n as $i18n_data) { |
|
293 | - if(is_string($i18n_data)) { |
|
292 | + foreach ($i18n as $i18n_data) { |
|
293 | + if (is_string($i18n_data)) { |
|
294 | 294 | $this->lng_include($i18n_data); |
295 | - } elseif(is_array($i18n_data)) { |
|
295 | + } elseif (is_array($i18n_data)) { |
|
296 | 296 | $this->lng_include($i18n_data['file'], $i18n_data['path']); |
297 | 297 | } |
298 | 298 | } |
@@ -310,27 +310,27 @@ discard block |
||
310 | 310 | |
311 | 311 | classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'"); |
312 | 312 | |
313 | - if($language_new == $this->active) { |
|
313 | + if ($language_new == $this->active) { |
|
314 | 314 | classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1); |
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | 318 | $this->active = $language = $language_new; |
319 | - $this->cache_prefix_lang = $this->cache_prefix . $this->active . '_'; |
|
319 | + $this->cache_prefix_lang = $this->cache_prefix.$this->active.'_'; |
|
320 | 320 | |
321 | 321 | $this['LANG_INFO'] = $this->lng_get_info($this->active); |
322 | 322 | $this->make_fallback($this->active); |
323 | 323 | |
324 | - if($this->cache) { |
|
325 | - $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT'); |
|
326 | - classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0); |
|
327 | - if($cache_lang_init_status) { |
|
324 | + if ($this->cache) { |
|
325 | + $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang.'__INIT'); |
|
326 | + classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is ".($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0); |
|
327 | + if ($cache_lang_init_status) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
331 | 331 | // Чистим текущие локализации из кэша. Достаточно почистить только флаги инициализации языкового кэша и загрузки файлов - они начинаются с '__' |
332 | 332 | classSupernova::log_file("locale.switch: Cache - invalidating data"); |
333 | - $this->cache->unset_by_prefix($this->cache_prefix_lang . '__'); |
|
333 | + $this->cache->unset_by_prefix($this->cache_prefix_lang.'__'); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | $this->lng_include('system'); |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | // Loading global language files |
341 | 341 | $this->lng_load_i18n(classSupernova::$sn_mvc['i18n']['']); |
342 | 342 | |
343 | - if($this->cache) { |
|
344 | - classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT'); |
|
345 | - $this->cache->__set($this->cache_prefix_lang . '__INIT', true); |
|
343 | + if ($this->cache) { |
|
344 | + classSupernova::log_file("locale.switch: Cache - setting flag ".$this->cache_prefix_lang.'__INIT'); |
|
345 | + $this->cache->__set($this->cache_prefix_lang.'__INIT', true); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | classSupernova::log_file("locale.switch: Complete - EXIT"); |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | |
353 | 353 | |
354 | 354 | public function lng_get_info($entry) { |
355 | - $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php'; |
|
355 | + $file_name = SN_ROOT_PHYSICAL.'language/'.$entry.'/language.mo.php'; |
|
356 | 356 | $lang_info = array(); |
357 | - if(file_exists($file_name)) { |
|
357 | + if (file_exists($file_name)) { |
|
358 | 358 | include($file_name); |
359 | 359 | } |
360 | 360 | |
@@ -362,15 +362,15 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | public function lng_get_list() { |
365 | - if(empty($this->lang_list)) { |
|
365 | + if (empty($this->lang_list)) { |
|
366 | 366 | $this->lang_list = array(); |
367 | 367 | |
368 | - $path = SN_ROOT_PHYSICAL . 'language/'; |
|
368 | + $path = SN_ROOT_PHYSICAL.'language/'; |
|
369 | 369 | $dir = dir($path); |
370 | - while(false !== ($entry = $dir->read())) { |
|
371 | - if(is_dir($path . $entry) && $entry[0] != '.') { |
|
370 | + while (false !== ($entry = $dir->read())) { |
|
371 | + if (is_dir($path.$entry) && $entry[0] != '.') { |
|
372 | 372 | $lang_info = $this->lng_get_info($entry); |
373 | - if($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
373 | + if ($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
374 | 374 | $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info; |
375 | 375 | } |
376 | 376 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | UBE_PLAYER_IS_DEFENDER => array(), |
56 | 56 | ); |
57 | 57 | |
58 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
58 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
59 | 59 | $result[$UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER][$player_id] = $UBEPlayer->getDbRow(); |
60 | 60 | } |
61 | 61 | |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function get_first_player_on_side($side) { |
72 | 72 | $result = null; |
73 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
74 | - if($UBEPlayer->getSide() == $side) { |
|
73 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
74 | + if ($UBEPlayer->getSide() == $side) { |
|
75 | 75 | $result = $UBEPlayer; |
76 | 76 | break; |
77 | 77 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function get_player_sides() { |
90 | 90 | $result = array(); |
91 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
91 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
92 | 92 | $result[$player_id] = $UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER; |
93 | 93 | } |
94 | 94 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | public function ubeLoadPlayersAndSetSideFromFleetIdList(array $added_fleets, UBEFleetList $fleetList, $side = UBE_PLAYER_IS_DEFENDER) { |
99 | - foreach($added_fleets as $fleet_id) { |
|
99 | + foreach ($added_fleets as $fleet_id) { |
|
100 | 100 | $this->db_load_player_by_id($fleetList[$fleet_id]->owner_id, $side); |
101 | 101 | } |
102 | 102 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @version 41a6.49 |
12 | 12 | */ |
13 | 13 | public static function unit_dump_header() { |
14 | - if(!defined('DEBUG_UBE')) { |
|
14 | + if (!defined('DEBUG_UBE')) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @version 41a6.49 |
49 | 49 | */ |
50 | 50 | public static function unit_dump(UBEUnit $unit, $desc = '', UBEUnit $before = null) { |
51 | - if(!defined('DEBUG_UBE')) { |
|
51 | + if (!defined('DEBUG_UBE')) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | // print("<td>" . $this->units_lost . "</td>"); |
76 | 76 | // print("<td>" . $this->units_restored . "</td>"); |
77 | 77 | // print("<td>" . $this->capacity . "</td>"); |
78 | - print("<td>" . round($unit->share_of_side_armor, 4) . "</td>"); |
|
78 | + print("<td>".round($unit->share_of_side_armor, 4)."</td>"); |
|
79 | 79 | print('</tr>'); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @version 41a6.49 |
87 | 87 | */ |
88 | 88 | public static function unit_dump_footer() { |
89 | - if(!defined('DEBUG_UBE')) { |
|
89 | + if (!defined('DEBUG_UBE')) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @return UBEUnit |
102 | 102 | */ |
103 | 103 | public static function unit_dump_defender(UBEUnit $attacking_unit_pool, UBEUnit $defending_unit_pool, $defending_fleet_id) { |
104 | - if(!defined('DEBUG_UBE')) { |
|
104 | + if (!defined('DEBUG_UBE')) { |
|
105 | 105 | return null; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $classLocale = classLocale::$lang; |
109 | 109 | |
110 | - print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}" . |
|
111 | - ' attacks ' . |
|
112 | - $defending_fleet_id . '@' . "[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}" . |
|
113 | - ' with ' . pretty_number($defending_unit_pool->attack_income) . |
|
110 | + print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}". |
|
111 | + ' attacks '. |
|
112 | + $defending_fleet_id.'@'."[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}". |
|
113 | + ' with '.pretty_number($defending_unit_pool->attack_income). |
|
114 | 114 | '<br>' |
115 | 115 | ); |
116 | 116 | $before = clone $defending_unit_pool; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @version 41a6.49 |
128 | 128 | */ |
129 | 129 | public static function unit_dump_delta(UBEUnit $unit, $field, UBEUnit $before = null) { |
130 | - if(!defined('DEBUG_UBE')) { |
|
130 | + if (!defined('DEBUG_UBE')) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | print(pretty_number($unit->$field)); |
137 | 137 | print("</td>"); |
138 | 138 | print("<td>"); |
139 | - if(!empty($before)) { |
|
140 | - print('' . pretty_number($unit->$field - $before->$field) . ''); |
|
139 | + if (!empty($before)) { |
|
140 | + print(''.pretty_number($unit->$field - $before->$field).''); |
|
141 | 141 | } |
142 | 142 | print("</td>"); |
143 | 143 | } |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function ube_db_load_fleets_outcome($report_row) { |
84 | 84 | $query = doquery("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
85 | - while($row = db_fetch($query)) { |
|
85 | + while ($row = db_fetch($query)) { |
|
86 | 86 | $fleet_id = $row['ube_report_outcome_fleet_fleet_id']; |
87 | 87 | $this[$fleet_id]->load_outcome_from_report_row($row); |
88 | 88 | } |
89 | 89 | |
90 | 90 | $query = doquery("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`"); |
91 | - while($row = db_fetch($query)) { |
|
91 | + while ($row = db_fetch($query)) { |
|
92 | 92 | $fleet_id = $row['ube_report_outcome_unit_fleet_id']; |
93 | 93 | $this[$fleet_id]->load_unit_outcome_from_row($row); |
94 | 94 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | UBE_PLAYER_IS_DEFENDER => array(), |
109 | 109 | ); |
110 | 110 | |
111 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
111 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
112 | 112 | $result[$UBEFleet->is_attacker][] = array( |
113 | 113 | 'ID' => $fleet_id, |
114 | 114 | 'NAME' => $ube->players[$UBEFleet->owner_id]->name, |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function ube_analyze_fleets($is_simulator, UBEDebris $debris, array $resource_exchange_rates) { |
133 | 133 | // Генерируем результат боя |
134 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
134 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
135 | 135 | // Инициализируем массив результатов для флота |
136 | 136 | // $this->init_fleet_outcome_and_link_to_side($UBEFleet); |
137 | 137 | |
138 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
138 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
139 | 139 | $UBEUnit->ube_analyze_unit($is_simulator); |
140 | 140 | } |
141 | 141 | |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | $this->resources_lost_in_metal = array( |
153 | 153 | RES_METAL => 0, |
154 | 154 | ); |
155 | - foreach($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
155 | + foreach ($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
156 | 156 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
157 | 157 | } |
158 | - foreach($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
158 | + foreach ($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
159 | 159 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
160 | 160 | } |
161 | 161 | } |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function ube_get_groups() { |
168 | 168 | $result = array(); |
169 | - foreach($this->_container as $UBEFleet) { |
|
170 | - if($UBEFleet->group_id) { |
|
169 | + foreach ($this->_container as $UBEFleet) { |
|
170 | + if ($UBEFleet->group_id) { |
|
171 | 171 | $result[$UBEFleet->group_id] = $UBEFleet->group_id; |
172 | 172 | } |
173 | 173 | } |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function ube_get_capacity_attackers() { |
182 | 182 | $result = 0; |
183 | - foreach($this->_container as $UBEFleet) { |
|
184 | - if($UBEFleet->is_attacker) { |
|
183 | + foreach ($this->_container as $UBEFleet) { |
|
184 | + if ($UBEFleet->is_attacker) { |
|
185 | 185 | $result += $UBEFleet->fleet_capacity; |
186 | 186 | } |
187 | 187 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function ube_db_load_from_report_row(array $report_row, UBE $ube) { |
197 | 197 | $query = doquery("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
198 | - while($fleet_row = db_fetch($query)) { |
|
198 | + while ($fleet_row = db_fetch($query)) { |
|
199 | 199 | $objFleet = new UBEFleet(); |
200 | 200 | $objFleet->load_from_report($fleet_row, $ube); |
201 | 201 | $this[$objFleet->db_id] = $objFleet; |
@@ -209,20 +209,20 @@ discard block |
||
209 | 209 | * @version 2016-02-25 23:42:45 41a4.68 |
210 | 210 | */ |
211 | 211 | public function ube_prepare_for_next_round($is_simulator) { |
212 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
212 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
213 | 213 | $UBEFleet->prepare_for_next_round($is_simulator); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Суммируем данные по атакующим и защитникам |
217 | 217 | $this->ube_total[UBE_PLAYER_IS_ATTACKER]->_reset(); |
218 | 218 | $this->ube_total[UBE_PLAYER_IS_DEFENDER]->_reset(); |
219 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
219 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
220 | 220 | $this->ube_total[$UBEFleet->is_attacker]->add_unit_stats_array($UBEFleet->total_stats); |
221 | 221 | } |
222 | 222 | //pvar_dump($this->ube_total); |
223 | 223 | |
224 | 224 | // Высчитываем долю атаки, приходящейся на юнит равную отношению брони юнита к общей броне - крупные цели атакуют чаще |
225 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
225 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
226 | 226 | $UBEFleet->calculate_unit_partial_data($this->ube_total[$UBEFleet->is_attacker]); |
227 | 227 | } |
228 | 228 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function ube_calculate_attack_results(UBE $ube) { |
238 | 238 | // Каждый флот атакует все |
239 | - foreach($this->_container as $attack_fleet_data) { |
|
239 | + foreach ($this->_container as $attack_fleet_data) { |
|
240 | 240 | defined('DEBUG_UBE') ? print("Fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false; |
241 | 241 | |
242 | 242 | $attack_fleet_data->attack_fleets($this, $ube->is_simulator); |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @version 2016-02-25 23:42:45 41a4.68 |
252 | 252 | */ |
253 | 253 | public function ube_actualize_sides() { |
254 | - foreach($this->_container as $UBEFleet) { |
|
255 | - if($UBEFleet->get_unit_count() > 0) { |
|
254 | + foreach ($this->_container as $UBEFleet) { |
|
255 | + if ($UBEFleet->get_unit_count() > 0) { |
|
256 | 256 | $this->ube_side_present_at_round_start[$UBEFleet->is_attacker] = 1; |
257 | 257 | } |
258 | 258 | } |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function ube_calculate_attack_reapers() { |
267 | 267 | $reapers = 0; |
268 | - foreach($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
269 | - if($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
268 | + foreach ($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
269 | + if ($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
270 | 270 | $reapers += $UBERoundFleetCombat->unit_list->unitCountReapers(); |
271 | 271 | } |
272 | 272 | } |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | |
284 | 284 | $result = UBE_COMBAT_RESULT_DRAW; |
285 | 285 | // Проверяем результат боя |
286 | - if($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
286 | + if ($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
287 | 287 | // Если кого-то не осталось или не осталось обоих - заканчиваем цикл |
288 | 288 | $result = UBE_COMBAT_RESULT_DRAW_END; |
289 | - } elseif($this->ube_get_sides_count() == 1) { |
|
289 | + } elseif ($this->ube_get_sides_count() == 1) { |
|
290 | 290 | // Если осталась одна сторона - она и выиграла |
291 | 291 | $result = isset($this->ube_side_present_at_round_start[UBE_PLAYER_IS_ATTACKER]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS; |
292 | 292 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @version 41a6.16 |
304 | 304 | */ |
305 | 305 | public function ubeInitGetAttackers(Fleet $objFleet, UBEPlayerList $players) { |
306 | - if($objFleet->group_id) { |
|
306 | + if ($objFleet->group_id) { |
|
307 | 307 | $fleets_added = $this->dbLoadWhere("`fleet_group` = {$objFleet->group_id}"); |
308 | 308 | } else { |
309 | 309 | $this->ube_insert_from_Fleet($objFleet); |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * @version 2016-02-25 23:42:45 41a4.68 |
37 | 37 | */ |
38 | 38 | public function make_snapshot(UBEFleetList $UBEFleetList) { |
39 | - foreach($UBEFleetList->_container as $fleet_id => $UBEFleet) { |
|
40 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
39 | + foreach ($UBEFleetList->_container as $fleet_id => $UBEFleet) { |
|
40 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
41 | 41 | $this->snapshot[$fleet_id][$UBEUnit->unitId] = new UBESnapshotUnit(); |
42 | 42 | $this->snapshot[$fleet_id][$UBEUnit->unitId]->init_from_UBEUnit($UBEUnit); |
43 | 43 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @version 2016-02-25 23:42:45 41a4.68 |
54 | 54 | */ |
55 | 55 | public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, &$unit_sort_order, UBEFleetList $UBEFleetList, array $outer_prefix) { |
56 | - foreach($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
56 | + foreach ($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
57 | 57 | $inner_prefix = array( |
58 | 58 | $UBEFleetList[$fleet_id]->owner_id, |
59 | 59 | $fleet_id, |
60 | 60 | ); |
61 | - foreach($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
61 | + foreach ($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
62 | 62 | $sql_perform_ube_report_unit[] = array_merge( |
63 | 63 | $outer_prefix, |
64 | 64 | $inner_prefix, |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | UBE_PLAYER_IS_DEFENDER => array(), |
102 | 102 | ); |
103 | 103 | |
104 | - foreach($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
104 | + foreach ($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
105 | 105 | $fleet_owner_id = $ube->fleet_list[$fleet_id]->owner_id; |
106 | 106 | $planet_ube_row = $ube->fleet_list[$fleet_id]->UBE_PLANET; |
107 | 107 | |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | 'PLAYER_NAME' => htmlentities($ube->players[$fleet_owner_id]->name, ENT_COMPAT, 'UTF-8'), |
112 | 112 | ); |
113 | 113 | |
114 | - if(is_array($planet_ube_row)) { |
|
114 | + if (is_array($planet_ube_row)) { |
|
115 | 115 | $template_fleet += $planet_ube_row; |
116 | 116 | $template_fleet[PLANET_NAME] = $template_fleet[PLANET_NAME] ? htmlentities($template_fleet[PLANET_NAME], ENT_COMPAT, 'UTF-8') : ''; |
117 | 117 | $template_fleet['PLANET_TYPE_TEXT'] = $lang['sys_planet_type_sh'][$template_fleet['PLANET_TYPE']]; |
118 | 118 | } |
119 | 119 | |
120 | - foreach($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
120 | + foreach ($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
121 | 121 | $template_fleet['.']['ship'][] = $unit_snapshot->report_render_unit($prevSnapshot[$fleet_id][$unit_id]); |
122 | 122 | } |
123 | 123 |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | $debris_for_moon = $debris->debris_total(); |
72 | 72 | |
73 | - if(!$debris_for_moon) { |
|
73 | + if (!$debris_for_moon) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $moon_chance = min($debris_for_moon / UBE_MOON_DEBRIS_PER_PERCENT, UBE_MOON_PERCENT_MAX); // TODO Configure |
79 | 79 | $moon_chance = $moon_chance >= UBE_MOON_PERCENT_MIN ? $moon_chance : 0; |
80 | 80 | $this->create_chance = $moon_chance; |
81 | - if($moon_chance) { |
|
82 | - if($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
81 | + if ($moon_chance) { |
|
82 | + if ($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
83 | 83 | $this->status = UBE_MOON_CREATE_SUCCESS; |
84 | 84 | $this->moon_diameter = round($is_simulator ? $moon_chance * 150 + 1999 : mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999)); |
85 | 85 | |
86 | - if($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
86 | + if ($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
87 | 87 | $debris->_reset(); |
88 | 88 | } else { |
89 | 89 | $moon_debris_left_percent = ($debris_for_moon - UBE_MOON_DEBRIS_MAX_SPENT) / $debris_for_moon; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function moon_destroy_try($reapers) { |
104 | 104 | // TODO: $is_simulator |
105 | - if($reapers <= 0) { |
|
105 | + if ($reapers <= 0) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @version 2016-02-25 23:42:45 41a4.68 |
121 | 121 | */ |
122 | 122 | public function calculate_moon(UBE $ube) { |
123 | - if(UBE_MOON_EXISTS == $this->status) { |
|
124 | - if($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
123 | + if (UBE_MOON_EXISTS == $this->status) { |
|
124 | + if ($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
125 | 125 | $reapers = $ube->fleet_list->ube_calculate_attack_reapers(); |
126 | 126 | $this->moon_destroy_try($reapers); |
127 | 127 | } |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function report_generate_array() { |
137 | 137 | return array( |
138 | - 'ube_report_moon' => (int)$this->status, |
|
139 | - 'ube_report_moon_chance' => (int)$this->create_chance, |
|
140 | - 'ube_report_moon_size' => (float)$this->moon_diameter, |
|
141 | - 'ube_report_moon_reapers' => (int)$this->reapers_status, |
|
142 | - 'ube_report_moon_destroy_chance' => (int)$this->destroy_chance, |
|
143 | - 'ube_report_moon_reapers_die_chance' => (int)$this->reaper_die_chance, |
|
138 | + 'ube_report_moon' => (int) $this->status, |
|
139 | + 'ube_report_moon_chance' => (int) $this->create_chance, |
|
140 | + 'ube_report_moon_size' => (float) $this->moon_diameter, |
|
141 | + 'ube_report_moon_reapers' => (int) $this->reapers_status, |
|
142 | + 'ube_report_moon_destroy_chance' => (int) $this->destroy_chance, |
|
143 | + 'ube_report_moon_reapers_die_chance' => (int) $this->reaper_die_chance, |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param $planet_id |
172 | 172 | */ |
173 | 173 | public function db_apply_result($planet_info, $destination_user_id) { |
174 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
174 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
175 | 175 | $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $this->moon_diameter, '', false); |
176 | 176 | $this->moon_name = $moon_row['name']; |
177 | 177 | unset($moon_row); |
178 | - } elseif($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
178 | + } elseif ($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
179 | 179 | DBStaticPlanet::db_planet_delete_by_id($planet_info[PLANET_ID]); |
180 | 180 | } |
181 | 181 | } |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | $classLocale = classLocale::$lang; |
185 | 185 | |
186 | 186 | $text_defender = ''; |
187 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
187 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
188 | 188 | $text_defender .= "{$classLocale['ube_report_moon_created']} {$this->moon_diameter} {$classLocale['sys_kilometers_short']}<br /><br />"; |
189 | - } elseif($this->status == UBE_MOON_CREATE_FAILED) { |
|
189 | + } elseif ($this->status == UBE_MOON_CREATE_FAILED) { |
|
190 | 190 | $text_defender .= "{$classLocale['ube_report_moon_chance']} {$this->create_chance}%<br /><br />"; |
191 | 191 | } |
192 | 192 | |
193 | - if($ube->mission_type_id == MT_DESTROY) { |
|
194 | - if($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
193 | + if ($ube->mission_type_id == MT_DESTROY) { |
|
194 | + if ($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
195 | 195 | $text_defender .= classLocale::$lang['ube_report_moon_reapers_none']; |
196 | 196 | } else { |
197 | 197 | $text_defender .= "{$classLocale['ube_report_moon_reapers_wave']}. {$classLocale['ube_report_moon_reapers_chance']} {$this->destroy_chance}%. "; |
198 | - $text_defender .= classLocale::$lang[$this->status == UBE_MOON_DESTROY_SUCCESS ? 'ube_report_moon_reapers_success' : 'ube_report_moon_reapers_failure'] . "<br />"; |
|
198 | + $text_defender .= classLocale::$lang[$this->status == UBE_MOON_DESTROY_SUCCESS ? 'ube_report_moon_reapers_success' : 'ube_report_moon_reapers_failure']."<br />"; |
|
199 | 199 | |
200 | 200 | $text_defender .= "{$classLocale['ube_report_moon_reapers_outcome']} {$this->reaper_die_chance}%. "; |
201 | 201 | $text_defender .= classLocale::$lang[$this->reapers_status == UBE_MOON_REAPERS_RETURNED ? 'ube_report_moon_reapers_survive' : 'ube_report_moon_reapers_died']; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @version 2016-02-25 23:42:45 41a4.68 |
221 | 221 | */ |
222 | 222 | public function ubeInitLoadStatis($destination_planet) { |
223 | - if($destination_planet['planet_type'] == PT_MOON || is_array($moon = DBStaticPlanet::db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
223 | + if ($destination_planet['planet_type'] == PT_MOON || is_array($moon = DBStaticPlanet::db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
224 | 224 | $this->status = UBE_MOON_EXISTS; |
225 | 225 | $this->moon_diameter = !empty($moon['planet_type']) && $moon['planet_type'] == PT_MOON ? $moon['diameter'] : $destination_planet['diameter']; |
226 | 226 | $this->reapers_status = UBE_MOON_REAPERS_NONE; |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public function sn_ube_report_save($ube) { |
15 | 15 | // Если уже есть ИД репорта - значит репорт был взят из таблицы. С таким мы не работаем |
16 | - if($ube->get_cypher()) { |
|
16 | + if ($ube->get_cypher()) { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | |
20 | 20 | // Генерируем уникальный секретный ключ и проверяем наличие в базе |
21 | 21 | do { |
22 | 22 | $ube->report_cypher = sys_random_string(32); |
23 | - } while(classSupernova::$db->doSelectFetch("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE")); |
|
23 | + } while (classSupernova::$db->doSelectFetch("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE")); |
|
24 | 24 | |
25 | 25 | // Инициализация таблицы для пакетной вставки информации |
26 | 26 | $sql_perform = array( |
@@ -106,21 +106,21 @@ discard block |
||
106 | 106 | |
107 | 107 | // Сохраняем общую информацию о бое |
108 | 108 | classSupernova::$db->doInsertSet(TABLE_UBE_REPORT, array( |
109 | - 'ube_report_cypher' => (string)$ube->report_cypher, |
|
110 | - 'ube_report_time_combat' => (string)date(FMT_DATE_TIME_SQL, $ube->combat_timestamp), |
|
111 | - 'ube_report_time_spent' => (float)$ube->time_spent, |
|
112 | - 'ube_report_combat_admin' => (int)$ube->is_admin_in_combat, |
|
113 | - 'ube_report_mission_type' => (int)$ube->mission_type_id, |
|
114 | - 'ube_report_combat_result' => (int)$ube->combat_result, |
|
115 | - 'ube_report_combat_sfr' => (int)$ube->is_small_fleet_recce, |
|
116 | - 'ube_report_planet_id' => (int)$ube->ube_planet_info[PLANET_ID], |
|
117 | - 'ube_report_planet_name' => (string)$ube->ube_planet_info[PLANET_NAME], |
|
118 | - 'ube_report_planet_size' => (int)$ube->ube_planet_info[PLANET_SIZE], |
|
119 | - 'ube_report_planet_galaxy' => (int)$ube->ube_planet_info[PLANET_GALAXY], |
|
120 | - 'ube_report_planet_system' => (int)$ube->ube_planet_info[PLANET_SYSTEM], |
|
121 | - 'ube_report_planet_planet' => (int)$ube->ube_planet_info[PLANET_PLANET], |
|
122 | - 'ube_report_planet_planet_type' => (int)$ube->ube_planet_info[PLANET_TYPE], |
|
123 | - 'ube_report_capture_result' => (int)$ube->capture_result, |
|
109 | + 'ube_report_cypher' => (string) $ube->report_cypher, |
|
110 | + 'ube_report_time_combat' => (string) date(FMT_DATE_TIME_SQL, $ube->combat_timestamp), |
|
111 | + 'ube_report_time_spent' => (float) $ube->time_spent, |
|
112 | + 'ube_report_combat_admin' => (int) $ube->is_admin_in_combat, |
|
113 | + 'ube_report_mission_type' => (int) $ube->mission_type_id, |
|
114 | + 'ube_report_combat_result' => (int) $ube->combat_result, |
|
115 | + 'ube_report_combat_sfr' => (int) $ube->is_small_fleet_recce, |
|
116 | + 'ube_report_planet_id' => (int) $ube->ube_planet_info[PLANET_ID], |
|
117 | + 'ube_report_planet_name' => (string) $ube->ube_planet_info[PLANET_NAME], |
|
118 | + 'ube_report_planet_size' => (int) $ube->ube_planet_info[PLANET_SIZE], |
|
119 | + 'ube_report_planet_galaxy' => (int) $ube->ube_planet_info[PLANET_GALAXY], |
|
120 | + 'ube_report_planet_system' => (int) $ube->ube_planet_info[PLANET_SYSTEM], |
|
121 | + 'ube_report_planet_planet' => (int) $ube->ube_planet_info[PLANET_PLANET], |
|
122 | + 'ube_report_planet_planet_type' => (int) $ube->ube_planet_info[PLANET_TYPE], |
|
123 | + 'ube_report_capture_result' => (int) $ube->capture_result, |
|
124 | 124 | ) |
125 | 125 | + $ube->debris->report_generate_array() |
126 | 126 | + $ube->moon_calculator->report_generate_array() |
@@ -129,22 +129,22 @@ discard block |
||
129 | 129 | |
130 | 130 | // Сохраняем общую информацию по игрокам |
131 | 131 | $player_sides = $ube->players->get_player_sides(); |
132 | - foreach($player_sides as $player_id => $player_side) { |
|
132 | + foreach ($player_sides as $player_id => $player_side) { |
|
133 | 133 | $sql_perform['ube_report_player'][] = array( |
134 | 134 | $ube_report_id, |
135 | 135 | $player_id, |
136 | 136 | |
137 | - "'" . db_escape($ube->players[$player_id]->name) . "'", |
|
137 | + "'".db_escape($ube->players[$player_id]->name)."'", |
|
138 | 138 | $ube->players[$player_id]->getSide() == UBE_PLAYER_IS_ATTACKER ? 1 : 0, |
139 | 139 | |
140 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
141 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
142 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
140 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
141 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
142 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
143 | 143 | ); |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Всякая информация по флотам |
147 | - foreach($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
147 | + foreach ($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
148 | 148 | // Сохраняем общую информацию по флотам |
149 | 149 | $sql_perform['ube_report_fleet'][] = $UBEFleet->sql_generate_array($ube_report_id); |
150 | 150 | |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | $ube->rounds->sql_generate_unit_array($sql_perform['ube_report_unit'], $ube_report_id, $ube->fleet_list); |
160 | 160 | |
161 | 161 | // Пакетная вставка данных |
162 | - foreach($sql_perform as $table_name => $table_data) { |
|
163 | - if(count($table_data) < 2) { |
|
162 | + foreach ($sql_perform as $table_name => $table_data) { |
|
163 | + if (count($table_data) < 2) { |
|
164 | 164 | continue; |
165 | 165 | } |
166 | - foreach($table_data as &$record_data) { |
|
167 | - $record_data = '(' . implode(',', $record_data) . ')'; |
|
166 | + foreach ($table_data as &$record_data) { |
|
167 | + $record_data = '('.implode(',', $record_data).')'; |
|
168 | 168 | } |
169 | 169 | $fields = $table_data[0]; |
170 | 170 | unset($table_data[0]); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $report_cypher = db_escape($report_cypher); |
187 | 187 | |
188 | 188 | $report_row = classSupernova::$db->doSelectFetch("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1"); |
189 | - if(!$report_row) { |
|
189 | + if (!$report_row) { |
|
190 | 190 | return UBE_REPORT_NOT_FOUND; |
191 | 191 | } |
192 | 192 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @param $template_result |
203 | 203 | */ |
204 | 204 | public function sn_ube_report_generate(UBE $ube, &$template_result) { |
205 | - if(!is_object($ube)) { |
|
205 | + if (!is_object($ube)) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | |
218 | 218 | // Координаты, тип и название планеты - если есть |
219 | 219 | //R $planet_owner_id = $combat_data[UBE_FLEETS][0][UBE_OWNER]; |
220 | - if(isset($ube->ube_planet_info)) { |
|
220 | + if (isset($ube->ube_planet_info)) { |
|
221 | 221 | $template_result += $ube->ube_planet_info; |
222 | 222 | $template_result[PLANET_NAME] = str_replace(' ', ' ', htmlentities($template_result[PLANET_NAME], ENT_COMPAT, 'UTF-8')); |
223 | 223 | } |
224 | 224 | |
225 | 225 | // Обломки |
226 | 226 | $debris = array(); |
227 | - foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
228 | - if($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
227 | + foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
228 | + if ($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
229 | 229 | $debris[] = array( |
230 | 230 | 'NAME' => classLocale::$lang['tech'][$resource_id], |
231 | 231 | 'AMOUNT' => pretty_number($resource_amount), |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function report_render_rounds(&$template_result, UBE $ube) { |
27 | 27 | $round_count = $this->count(); |
28 | - for($round = 1; $round <= $round_count - 1; $round++) { |
|
28 | + for ($round = 1; $round <= $round_count - 1; $round++) { |
|
29 | 29 | $template_result['.']['round'][] = array( |
30 | 30 | 'NUMBER' => $round, |
31 | 31 | '.' => array( |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, $ube_report_id, UBEFleetList $UBEFleetList) { |
50 | 50 | $unit_sort_order = 1; |
51 | - foreach($this->_container as $round_number => $UBERound) { |
|
51 | + foreach ($this->_container as $round_number => $UBERound) { |
|
52 | 52 | $outer_prefix = array( |
53 | 53 | $ube_report_id, |
54 | 54 | $round_number, |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function db_load_round_list_from_report_row($report_row, UBE $ube) { |
68 | 68 | $query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_id`"); |
69 | - while($report_unit_row = db_fetch($query)) { |
|
69 | + while ($report_unit_row = db_fetch($query)) { |
|
70 | 70 | $round_number = $report_unit_row['ube_report_unit_round']; |
71 | - if(!isset($this[$round_number])) { |
|
71 | + if (!isset($this[$round_number])) { |
|
72 | 72 | $this[$round_number] = new UBERound(); |
73 | 73 | $this[$round_number]->init_round_from_report_unit_row($report_unit_row); |
74 | 74 | } |