@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | // OK 4.9 |
37 | 37 | public function __construct($filename = __FILE__) { |
38 | - if($this->provider_id == ACCOUNT_PROVIDER_NONE) { |
|
38 | + if ($this->provider_id == ACCOUNT_PROVIDER_NONE) { |
|
39 | 39 | die('У всех провайдеров должен быть $provider_id!'); |
40 | 40 | } |
41 | 41 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | // OK 4.6 |
134 | 134 | public function player_name_suggest() { |
135 | 135 | $name = ''; |
136 | - if(is_object($this->account) && !empty($this->account->account_email)) { |
|
136 | + if (is_object($this->account) && !empty($this->account->account_email)) { |
|
137 | 137 | list($name) = explode('@', $this->account->account_email); |
138 | 138 | } |
139 | 139 |
@@ -41,7 +41,7 @@ |
||
41 | 41 | // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true); |
42 | 42 | // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем" |
43 | 43 | $query = $this->db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE", true); |
44 | - } while($query); |
|
44 | + } while ($query); |
|
45 | 45 | |
46 | 46 | $this->db->doquery( |
47 | 47 | "REPLACE INTO {{confirmations}} |
@@ -239,7 +239,7 @@ |
||
239 | 239 | |
240 | 240 | $factory = $this->values[$id]; |
241 | 241 | |
242 | - $extended = function ($c) use ($callable, $factory) { |
|
242 | + $extended = function($c) use ($callable, $factory) { |
|
243 | 243 | return $callable($factory($c), $c); |
244 | 244 | }; |
245 | 245 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected static $is_init = false; |
20 | 20 | |
21 | 21 | protected static function init() { |
22 | - if(!empty(static::$db)) { |
|
22 | + if (!empty(static::$db)) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | static::$db = classSupernova::$db; |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $provider_id_safe = intval($provider_id_unsafe); |
67 | 67 | !is_array($account_list) ? $account_list = array($account_list) : false; |
68 | 68 | |
69 | - foreach($account_list as $provider_account_id_unsafe) { |
|
69 | + foreach ($account_list as $provider_account_id_unsafe) { |
|
70 | 70 | $provider_account_id_safe = intval($provider_account_id_unsafe); |
71 | 71 | |
72 | 72 | // TODO - Здесь могут отсутствовать аккаунты - проверять провайдером |
73 | 73 | $query = static::$db->doquery("SELECT `user_id` FROM {{account_translate}} WHERE `provider_id` = {$provider_id_safe} AND `provider_account_id` = {$provider_account_id_safe} FOR UPDATE"); |
74 | - while($row = static::$db->db_fetch($query)) { |
|
74 | + while ($row = static::$db->db_fetch($query)) { |
|
75 | 75 | $account_translation[$row['user_id']][$provider_id_unsafe][$provider_account_id_unsafe] = true; |
76 | 76 | } |
77 | 77 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " . |
92 | 92 | ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') . |
93 | 93 | "ORDER BY `timestamp` FOR UPDATE"); |
94 | - while($row = static::$db->db_fetch($query)) { |
|
94 | + while ($row = static::$db->db_fetch($query)) { |
|
95 | 95 | $account_translation[$row['user_id']][$row['provider_id']][$row['provider_account_id']] = $row; |
96 | 96 | } |
97 | 97 |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | !is_array($offset) ? $offset = array($offset) : false; |
39 | 39 | |
40 | 40 | $current_leaf = $this->__get(reset($offset)); |
41 | - while(($leaf_index = next($offset)) !== false) { |
|
42 | - if(!isset($current_leaf) || !is_array($current_leaf) || !isset($current_leaf[$leaf_index])) { |
|
41 | + while (($leaf_index = next($offset)) !== false) { |
|
42 | + if (!isset($current_leaf) || !is_array($current_leaf) || !isset($current_leaf[$leaf_index])) { |
|
43 | 43 | unset($current_leaf); |
44 | 44 | break; |
45 | 45 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | |
65 | 65 | !is_array($offset) ? $offset = array($offset) : false; |
66 | 66 | |
67 | - if($this->offsetExists($offset)) { |
|
67 | + if ($this->offsetExists($offset)) { |
|
68 | 68 | $result = $this->__get(reset($offset)); |
69 | - while(($leaf_index = next($offset)) !== false) { |
|
69 | + while (($leaf_index = next($offset)) !== false) { |
|
70 | 70 | $result = $result[$leaf_index]; |
71 | 71 | } |
72 | 72 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function offsetSet($offset, $value = null) { |
93 | 93 | // Если нет никакого индекса - значит нечего записывать |
94 | - if(!isset($offset) || (is_array($offset) && empty($offset))) { |
|
94 | + if (!isset($offset) || (is_array($offset) && empty($offset))) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Если в массиве индекса только один элемент - значит это просто индекс |
99 | - if(is_array($offset) && count($offset) == 1) { |
|
99 | + if (is_array($offset) && count($offset) == 1) { |
|
100 | 100 | // Разворачиваем его в индекс |
101 | 101 | $offset = array(reset($offset) => $value); |
102 | 102 | unset($value); |
@@ -104,16 +104,16 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | // Адресация многомерного массива через массив индексов в $option |
107 | - if(is_array($offset) && isset($value)) { |
|
107 | + if (is_array($offset) && isset($value)) { |
|
108 | 108 | // TODO - а не переделать ли это всё на __isset() ?? |
109 | 109 | // Вытаскиваем корневой элемент |
110 | 110 | $root = $this->__get(reset($offset)); |
111 | 111 | $current_leaf = &$root; |
112 | - while(($leaf_index = next($offset)) !== false) { |
|
112 | + while (($leaf_index = next($offset)) !== false) { |
|
113 | 113 | !is_array($current_leaf[$leaf_index]) ? $current_leaf[$leaf_index] = array() : false; |
114 | 114 | $current_leaf = &$current_leaf[$leaf_index]; |
115 | 115 | } |
116 | - if($current_leaf != $value) { |
|
116 | + if ($current_leaf != $value) { |
|
117 | 117 | $current_leaf = $value; |
118 | 118 | // Сохраняем данные с корня |
119 | 119 | $this->__set(reset($offset), $root); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | // Пакетная запись из массива ключ -> значение |
123 | 123 | !is_array($offset) ? $offset = array($offset => $value) : false; |
124 | 124 | |
125 | - foreach($offset as $key => $value) { |
|
125 | + foreach ($offset as $key => $value) { |
|
126 | 126 | $this->__get($key) !== $value ? $this->__set($key, $value) : false; |
127 | 127 | } |
128 | 128 | } |
@@ -143,18 +143,18 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function offsetUnset($offset) { |
145 | 145 | // Если нет никакого индекса - значит нечего записывать |
146 | - if(!isset($offset) || (is_array($offset) && empty($offset))) { |
|
146 | + if (!isset($offset) || (is_array($offset) && empty($offset))) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | 150 | !is_array($offset) ? $offset = array($offset) : false; |
151 | 151 | |
152 | - if($this->offsetExists($offset)) { |
|
152 | + if ($this->offsetExists($offset)) { |
|
153 | 153 | // Перематываем массив в конец |
154 | 154 | $key_to_delete = end($offset); |
155 | 155 | $parent_offset = $offset; |
156 | 156 | array_pop($parent_offset); |
157 | - if(!count($parent_offset)) { |
|
157 | + if (!count($parent_offset)) { |
|
158 | 158 | // В массиве был один элемент - мы удаляем в корне. Просто удаляем элемент |
159 | 159 | $this->__unset($key_to_delete); |
160 | 160 | } else { |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | public function compile_request($request) { |
451 | 451 | global $config, $lang, $user; |
452 | 452 | |
453 | - if(!(classSupernova::$auth->account instanceof Account)) { |
|
453 | + if (!(classSupernova::$auth->account instanceof Account)) { |
|
454 | 454 | // TODO - throw new Exception($lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
455 | 455 | } |
456 | 456 | $this->account = classSupernova::$auth->account; |
@@ -471,15 +471,15 @@ discard block |
||
471 | 471 | $this->payment_currency = $config->payment_currency_default; |
472 | 472 | $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency); |
473 | 473 | |
474 | - if(empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
474 | + if (empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
475 | 475 | $this->payment_external_currency = $this->config['currency']; |
476 | 476 | } |
477 | - if(empty($this->payment_external_currency)) { |
|
477 | + if (empty($this->payment_external_currency)) { |
|
478 | 478 | throw new Exception($lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET); |
479 | 479 | } |
480 | 480 | |
481 | 481 | $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency); |
482 | - if($this->payment_external_amount < 0.01) { |
|
482 | + if ($this->payment_external_amount < 0.01) { |
|
483 | 483 | throw new Exception($lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
484 | 484 | } |
485 | 485 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $this->generate_description(); |
489 | 489 | |
490 | 490 | $this->db_insert(); |
491 | - if(!$this->is_exists) { |
|
491 | + if (!$this->is_exists) { |
|
492 | 492 | throw new Exception($lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); |
493 | 493 | } |
494 | 494 | } |
@@ -503,24 +503,24 @@ discard block |
||
503 | 503 | protected function payment_request_process($options = array()) { |
504 | 504 | global $lang, $config; |
505 | 505 | |
506 | - if(!$this->manifest['active']) { |
|
506 | + if (!$this->manifest['active']) { |
|
507 | 507 | throw new Exception($lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); |
508 | 508 | } |
509 | 509 | |
510 | 510 | // Если есть payment_id - загружаем под него данные |
511 | - if(!empty($this->payment_params['payment_id'])) { |
|
511 | + if (!empty($this->payment_params['payment_id'])) { |
|
512 | 512 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); |
513 | - if(!$this->request_payment_id) { |
|
513 | + if (!$this->request_payment_id) { |
|
514 | 514 | throw new Exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
515 | 515 | } |
516 | 516 | |
517 | - if(!$this->db_get_by_id($this->request_payment_id)) { |
|
517 | + if (!$this->db_get_by_id($this->request_payment_id)) { |
|
518 | 518 | throw new Exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Проверяем - был ли этот платеж обработан? |
522 | 522 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed |
523 | - if($this->payment_status != PAYMENT_STATUS_NONE) { |
|
523 | + if ($this->payment_status != PAYMENT_STATUS_NONE) { |
|
524 | 524 | sn_db_transaction_rollback(); |
525 | 525 | sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); |
526 | 526 | die(); |
@@ -530,89 +530,89 @@ discard block |
||
530 | 530 | // Пытаемся получить из запроса ИД аккаунта |
531 | 531 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; |
532 | 532 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id |
533 | - if(empty($request_account_id) && !empty($this->payment_account_id)) { |
|
533 | + if (empty($request_account_id) && !empty($this->payment_account_id)) { |
|
534 | 534 | $request_account_id = $this->payment_account_id; |
535 | 535 | } |
536 | 536 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать |
537 | - if(empty($request_account_id)) { |
|
537 | + if (empty($request_account_id)) { |
|
538 | 538 | // TODO - аккаунт |
539 | 539 | throw new Exception($lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
540 | 540 | } |
541 | 541 | // Если нет записи в таблице - тогда берем payment_account_id из запроса |
542 | - if(empty($this->payment_account_id)) { |
|
542 | + if (empty($this->payment_account_id)) { |
|
543 | 543 | $this->payment_account_id = $request_account_id; |
544 | 544 | } |
545 | 545 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать |
546 | - if($this->payment_account_id != $request_account_id) { |
|
546 | + if ($this->payment_account_id != $request_account_id) { |
|
547 | 547 | // TODO - Поменять сообщение об ошибке |
548 | 548 | throw new Exception($lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
549 | 549 | } |
550 | 550 | // Проверяем существование аккаунта с данным ИД |
551 | - if(!$this->account->db_get_by_id($this->payment_account_id)) { |
|
551 | + if (!$this->account->db_get_by_id($this->payment_account_id)) { |
|
552 | 552 | throw new Exception($lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
553 | 553 | } |
554 | 554 | |
555 | 555 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? |
556 | - if(!empty($this->payment_params['server_id'])) { |
|
556 | + if (!empty($this->payment_params['server_id'])) { |
|
557 | 557 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); |
558 | - if(SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
558 | + if (SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
559 | 559 | throw new Exception($lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Сверка количества оплаченной ММ с учётом бонусов |
564 | - if(!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
564 | + if (!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
565 | 565 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); |
566 | - if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
566 | + if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
567 | 567 | throw new Exception($lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
568 | 568 | } |
569 | 569 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; |
570 | 570 | } |
571 | - if(empty($this->payment_dark_matter_paid)) { |
|
571 | + if (empty($this->payment_dark_matter_paid)) { |
|
572 | 572 | // TODO - обратный расчёт из gained |
573 | 573 | } |
574 | 574 | |
575 | 575 | // Проверка наличия внешнего ИД платежа |
576 | - if(!empty($this->payment_params['payment_external_id'])) { |
|
576 | + if (!empty($this->payment_params['payment_external_id'])) { |
|
577 | 577 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); |
578 | - if(empty($request_payment_external_id)) { |
|
578 | + if (empty($request_payment_external_id)) { |
|
579 | 579 | throw new exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
580 | - } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
580 | + } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
581 | 581 | // TODO - Может быть поменять сообщение |
582 | 582 | throw new exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
583 | 583 | } |
584 | 584 | $this->payment_external_id = $request_payment_external_id; |
585 | 585 | } |
586 | 586 | // Сверка суммы, запрошенной СН к оплате |
587 | - if(!empty($this->payment_params['payment_external_money'])) { |
|
587 | + if (!empty($this->payment_params['payment_external_money'])) { |
|
588 | 588 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); |
589 | - if($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
589 | + if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
590 | 590 | throw new Exception($lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
591 | 591 | } |
592 | 592 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; |
593 | 593 | } |
594 | 594 | // Заполняем поле валюты платёжной системы |
595 | - if(!empty($this->payment_params['payment_external_currency'])) { |
|
595 | + if (!empty($this->payment_params['payment_external_currency'])) { |
|
596 | 596 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); |
597 | - if(empty($this->payment_external_currency)) { |
|
597 | + if (empty($this->payment_external_currency)) { |
|
598 | 598 | // TODO - поменять сообщение |
599 | 599 | throw new Exception($lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
600 | 600 | } |
601 | 601 | } |
602 | - if(empty($this->payment_external_currency)) { |
|
602 | + if (empty($this->payment_external_currency)) { |
|
603 | 603 | $this->payment_external_currency = $this->config['currency']; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // Заполнение внутренней суммы и валюты из внешних данных |
607 | - if(empty($this->payment_currency)) { |
|
607 | + if (empty($this->payment_currency)) { |
|
608 | 608 | $this->payment_currency = $config->payment_currency_default; |
609 | 609 | } |
610 | - if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
610 | + if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
611 | 611 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); |
612 | 612 | } |
613 | 613 | |
614 | 614 | // TODO - Тестовый режим |
615 | - if(!empty($this->payment_params['test'])) { |
|
615 | + if (!empty($this->payment_params['test'])) { |
|
616 | 616 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); |
617 | 617 | } |
618 | 618 | |
@@ -641,12 +641,12 @@ discard block |
||
641 | 641 | sn_db_transaction_start(); |
642 | 642 | try { |
643 | 643 | $response = $this->payment_request_process(); |
644 | - } catch(Exception $e) { |
|
644 | + } catch (Exception $e) { |
|
645 | 645 | $response['result'] = $e->getCode(); |
646 | 646 | $response['message'] = $e->getMessage(); |
647 | 647 | } |
648 | 648 | |
649 | - if($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
649 | + if ($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
650 | 650 | sn_db_transaction_commit(); |
651 | 651 | $debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); |
652 | 652 | } else { |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | // Переводим код результата из СН в код платежной системы |
658 | - if(is_array($this->result_translations) && !empty($this->result_translations)) { |
|
658 | + if (is_array($this->result_translations) && !empty($this->result_translations)) { |
|
659 | 659 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; |
660 | 660 | } |
661 | 661 | |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | $currency_from = strtolower($currency_from); |
681 | 681 | $currency_to = strtolower($currency_to); |
682 | 682 | |
683 | - if($currency_from != $currency_to) { |
|
683 | + if ($currency_from != $currency_to) { |
|
684 | 684 | // $config_currency_from_name = 'payment_currency_exchange_' . $currency_from; |
685 | 685 | // $config_currency_to_name = 'payment_currency_exchange_' . $currency_to; |
686 | 686 | |
@@ -710,10 +710,10 @@ discard block |
||
710 | 710 | public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { |
711 | 711 | $bonus = 0; |
712 | 712 | $dark_matter_new = $dark_matter; |
713 | - if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
714 | - if($direct) { |
|
715 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
716 | - if($dm_for_bonus <= $dark_matter) { |
|
713 | + if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
714 | + if ($direct) { |
|
715 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
716 | + if ($dm_for_bonus <= $dark_matter) { |
|
717 | 717 | $dark_matter_new = $dark_matter * (1 + $multiplier); |
718 | 718 | $bonus = $multiplier; |
719 | 719 | } else { |
@@ -721,9 +721,9 @@ discard block |
||
721 | 721 | } |
722 | 722 | } |
723 | 723 | } else { |
724 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
724 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
725 | 725 | $temp = $dm_for_bonus * (1 + $multiplier); |
726 | - if($dark_matter >= $temp) { |
|
726 | + if ($dark_matter >= $temp) { |
|
727 | 727 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); |
728 | 728 | $bonus = $multiplier; |
729 | 729 | } else { |
@@ -779,13 +779,13 @@ discard block |
||
779 | 779 | ); |
780 | 780 | |
781 | 781 | $replace = false; |
782 | - if($this->payment_id) { |
|
782 | + if ($this->payment_id) { |
|
783 | 783 | $payment['payment_id'] = $this->payment_id; |
784 | 784 | $replace = true; |
785 | 785 | } |
786 | 786 | |
787 | 787 | $query = array(); |
788 | - foreach($payment as $key => $value) { |
|
788 | + foreach ($payment as $key => $value) { |
|
789 | 789 | $value = is_string($value) ? '"' . db_escape($value) . '"' : $value; |
790 | 790 | $query[] = "`{$key}` = {$value}"; |
791 | 791 | } |
@@ -797,12 +797,12 @@ discard block |
||
797 | 797 | |
798 | 798 | |
799 | 799 | function payment_adjust_mm_new() { |
800 | - if(!$this->payment_test) { |
|
800 | + if (!$this->payment_test) { |
|
801 | 801 | // Not a test payment. Adding DM to account |
802 | 802 | $this->account = new Account($this->db); |
803 | 803 | $this->account->db_get_by_id($this->payment_account_id); |
804 | 804 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); |
805 | - if(!$result) { |
|
805 | + if (!$result) { |
|
806 | 806 | throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
807 | 807 | } |
808 | 808 | } |
@@ -812,25 +812,25 @@ discard block |
||
812 | 812 | die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); |
813 | 813 | global $lang; |
814 | 814 | |
815 | - if(!isset($payment['payment_status'])) { |
|
815 | + if (!isset($payment['payment_status'])) { |
|
816 | 816 | throw new exception($lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); |
817 | 817 | } |
818 | 818 | |
819 | - if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
820 | - $safe_comment = db_escape($payment['payment_comment'] = $lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); |
|
819 | + if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
820 | + $safe_comment = db_escape($payment['payment_comment'] = $lang['pay_msg_request_payment_cancelled'] . ' ' . $payment['payment_comment']); |
|
821 | 821 | |
822 | - if(!$payment['payment_test']) { |
|
822 | + if (!$payment['payment_test']) { |
|
823 | 823 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); |
824 | - if(!$result) { |
|
824 | + if (!$result) { |
|
825 | 825 | throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
826 | 826 | } |
827 | 827 | } |
828 | 828 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; |
829 | 829 | doquery("UPDATE {{payment}} SET payment_status = {$payment['payment_status']}, payment_comment = '{$safe_comment}' WHERE payment_id = {$payment['payment_id']};"); |
830 | 830 | throw new exception($lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); |
831 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
831 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
832 | 832 | throw new exception($lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); |
833 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
833 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
834 | 834 | throw new exception($lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); |
835 | 835 | } |
836 | 836 | } |
@@ -844,8 +844,8 @@ discard block |
||
844 | 844 | |
845 | 845 | protected function db_complete_payment() { |
846 | 846 | // TODO - поле payment_processed |
847 | - if($this->payment_status == PAYMENT_STATUS_NONE) { |
|
848 | - if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
847 | + if ($this->payment_status == PAYMENT_STATUS_NONE) { |
|
848 | + if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
849 | 849 | $this->payment_adjust_mm_new(); |
850 | 850 | $this->payment_status = PAYMENT_STATUS_COMPLETE; |
851 | 851 | } else { |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | protected function db_assign_payment($payment = null) { |
893 | 893 | $this->payment_reset(); |
894 | 894 | |
895 | - if(is_array($payment) && isset($payment['payment_id'])) { |
|
895 | + if (is_array($payment) && isset($payment['payment_id'])) { |
|
896 | 896 | $this->payment_id = $payment['payment_id']; |
897 | 897 | $this->payment_status = $payment['payment_status']; |
898 | 898 | $this->payment_date = $payment['payment_date']; |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | // Инфа об устройстве и браузере - общая для всех |
90 | 90 | sn_db_transaction_start(); |
91 | 91 | $this->device_cypher = $_COOKIE[SN_COOKIE_D]; |
92 | - if($this->device_cypher) { |
|
92 | + if ($this->device_cypher) { |
|
93 | 93 | $cypher_safe = db_escape($this->device_cypher); |
94 | 94 | $device_id = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
95 | - if(!empty($device_id['device_id'])) { |
|
95 | + if (!empty($device_id['device_id'])) { |
|
96 | 96 | $this->device_id = $device_id['device_id']; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if($this->device_id <= 0) { |
|
100 | + if ($this->device_id <= 0) { |
|
101 | 101 | do { |
102 | 102 | $cypher_safe = db_escape($this->device_cypher = sys_random_string()); |
103 | 103 | $row = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | $this->page_address_id = db_get_set_unique_id_value($this->page_address, 'url_id', 'security_url', 'url_string'); |
119 | 119 | sn_db_transaction_commit(); |
120 | 120 | |
121 | - if($this->write_full_url) { |
|
121 | + if ($this->write_full_url) { |
|
122 | 122 | sn_db_transaction_start(); |
123 | 123 | $this->page_url = substr($_SERVER['REQUEST_URI'], strlen(SN_ROOT_RELATIVE)); |
124 | - if(strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
124 | + if (strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
125 | 125 | $this->page_url = '/simulator.php'; |
126 | 126 | } |
127 | 127 | $this->page_url_id = db_get_set_unique_id_value($this->page_url, 'url_id', 'security_url', 'url_string'); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function db_security_entry_insert($user_id_unsafe) { |
146 | 146 | // TODO $user_id = !empty(self::$user['id']) ? self::$user['id'] : 'NULL'; |
147 | - if(empty($user_id_unsafe)) { |
|
147 | + if (empty($user_id_unsafe)) { |
|
148 | 148 | // self::flog('Нет ИД пользователя'); |
149 | 149 | return true; |
150 | 150 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | public function db_counter_insert($user_id_unsafe) { |
168 | 168 | global $config, $sys_stop_log_hit, $is_watching; |
169 | 169 | |
170 | - if($sys_stop_log_hit || !$config->game_counter) { |
|
170 | + if ($sys_stop_log_hit || !$config->game_counter) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | // $this->ip_v4_int . ", '{$proxy_safe}', " . $this->page_address_id . ", " . $this->page_url_id . ");"); |
184 | 184 | doquery( |
185 | 185 | "INSERT INTO {{counter}} SET |
186 | - `visit_time` = '" . SN_TIME_SQL. "', |
|
186 | + `visit_time` = '" . SN_TIME_SQL . "', |
|
187 | 187 | `user_id` = {$user_id_safe}, |
188 | 188 | `device_id` = {$this->device_id}, |
189 | 189 | `browser_id` = {$this->browser_id}, |
190 | 190 | `user_ip` = {$this->ip_v4_int}, |
191 | 191 | `user_proxy` = '{$proxy_safe}', |
192 | 192 | `page_url_id` = {$this->page_address_id}" . |
193 | - ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '' ). |
|
193 | + ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '') . |
|
194 | 194 | ";"); |
195 | 195 | |
196 | 196 | $is_watching = false; |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ |
206 | 206 | // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно |
207 | 207 | |
208 | - if(sys_get_param('login_player_register_logout')) { |
|
208 | + if (sys_get_param('login_player_register_logout')) { |
|
209 | 209 | $this->logout(); |
210 | 210 | } |
211 | 211 | |
212 | 212 | $original_suggest = ''; |
213 | 213 | // Смотрим - есть ли у нас данные от пользователя |
214 | - if(($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
214 | + if (($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
215 | 215 | // Попытка регистрации нового игрока из данных, введенных пользователем |
216 | 216 | $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name'); |
217 | 217 | } else { |
218 | - foreach($this->providers_authorised as $provider) { |
|
219 | - if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
218 | + foreach ($this->providers_authorised as $provider) { |
|
219 | + if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
220 | 220 | $original_suggest = $provider->player_name_suggest(); |
221 | 221 | break; |
222 | 222 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру |
227 | - if(!$this->player_suggested_name) { |
|
227 | + if (!$this->player_suggested_name) { |
|
228 | 228 | $max_user_id = db_player_get_max_id(); // 4.5 |
229 | 229 | // TODO - предлагать имя игрока по локали |
230 | 230 | |
@@ -233,15 +233,15 @@ discard block |
||
233 | 233 | sn_db_transaction_rollback(); |
234 | 234 | $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000); |
235 | 235 | sn_db_transaction_start(); |
236 | - } while(db_player_name_exists($this->player_suggested_name)); |
|
236 | + } while (db_player_name_exists($this->player_suggested_name)); |
|
237 | 237 | |
238 | 238 | } |
239 | 239 | |
240 | - if($player_name_submitted) { |
|
240 | + if ($player_name_submitted) { |
|
241 | 241 | $this->register_player_db_create($this->player_suggested_name); // OK 4.5 |
242 | - if($this->register_status == LOGIN_SUCCESS) { |
|
242 | + if ($this->register_status == LOGIN_SUCCESS) { |
|
243 | 243 | sys_redirect(SN_ROOT_VIRTUAL . 'overview.php'); |
244 | - } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
244 | + } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
245 | 245 | // self::$player_suggested_name .= ' ' . $this->account->account_id; |
246 | 246 | } |
247 | 247 | // if(self::$login_status != LOGIN_SUCCESS) { |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | : false |
266 | 266 | ); |
267 | 267 | |
268 | - if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
268 | + if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
269 | 269 | $prohibited_characters = array_map(function($value) { |
270 | 270 | return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'"; |
271 | 271 | }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED)); |
@@ -297,27 +297,27 @@ discard block |
||
297 | 297 | global $sn_module_list, $lang; |
298 | 298 | |
299 | 299 | // !self::$is_init ? self::init() : false; |
300 | - if(empty($sn_module_list['auth'])) { |
|
300 | + if (empty($sn_module_list['auth'])) { |
|
301 | 301 | die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}'); |
302 | 302 | } |
303 | 303 | |
304 | 304 | !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false; |
305 | 305 | !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false; |
306 | - !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false; |
|
306 | + !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false; |
|
307 | 307 | |
308 | 308 | $this->auth_reset(); // OK v4.5 |
309 | 309 | |
310 | 310 | $this->providers = array(); |
311 | - foreach($sn_module_list['auth'] as $module_name => $module) { |
|
311 | + foreach ($sn_module_list['auth'] as $module_name => $module) { |
|
312 | 312 | $this->providers[$module->provider_id] = $module; |
313 | 313 | } |
314 | 314 | |
315 | 315 | // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым! |
316 | 316 | //pdump($this->providers); |
317 | - foreach($this->providers as $provider_id => $provider) { |
|
317 | + foreach ($this->providers as $provider_id => $provider) { |
|
318 | 318 | $login_status = $provider->login(); // OK v4.5 |
319 | 319 | self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? $lang['sys_login_messages'][$provider->account_login_status] : dump($provider))); |
320 | - if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
320 | + if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
321 | 321 | $this->providers_authorised[$provider_id] = &$this->providers[$provider_id]; |
322 | 322 | |
323 | 323 | $this->user_id_to_provider = array_replace_recursive( |
@@ -325,20 +325,20 @@ discard block |
||
325 | 325 | // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
326 | 326 | PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
327 | 327 | ); |
328 | - } elseif($login_status != LOGIN_UNDEFINED) { |
|
328 | + } elseif ($login_status != LOGIN_UNDEFINED) { |
|
329 | 329 | $this->provider_error_list[$provider_id] = $login_status; |
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | - if(empty($this->providers_authorised)) { |
|
333 | + if (empty($this->providers_authorised)) { |
|
334 | 334 | // Ни один аккаунт не авторизирован |
335 | 335 | // Проверяем - есть ли у нас ошибки в аккаунтах? |
336 | - if(!empty($this->provider_error_list)) { |
|
336 | + if (!empty($this->provider_error_list)) { |
|
337 | 337 | // Если есть - выводим их |
338 | 338 | self::$login_status = reset($this->provider_error_list); |
339 | 339 | $providerError = $this->providers[key($this->provider_error_list)]->account_login_message; |
340 | 340 | |
341 | - if(!empty($providerError)) { |
|
341 | + if (!empty($providerError)) { |
|
342 | 342 | self::$login_message = $providerError; |
343 | 343 | } |
344 | 344 | } |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users` |
354 | 354 | |
355 | 355 | // Остались ли у нас в списке доступные игроки? |
356 | - if(empty($this->accessible_user_row_list)) { |
|
356 | + if (empty($this->accessible_user_row_list)) { |
|
357 | 357 | // Нет ни одного игрока ни на одном авторизированном аккаунте |
358 | 358 | // Надо регать нового игрока |
359 | 359 | |
360 | 360 | // Сейчас происходит процесс регистрации игрока? |
361 | - if(!$this->is_player_register) { |
|
361 | + if (!$this->is_player_register) { |
|
362 | 362 | // Нет - отправляем на процесс регистрации |
363 | 363 | $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id')); |
364 | 364 | sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : '')); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | // Да, есть доступные игроки, которые так же прописаны в базе |
368 | 368 | $this->get_active_user(); // 4.5 |
369 | 369 | |
370 | - if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
370 | + if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
371 | 371 | $a_user = db_user_by_id($this->is_impersonating); |
372 | 372 | $this->impersonator_username = $a_user['username']; |
373 | 373 | } |
@@ -375,9 +375,9 @@ discard block |
||
375 | 375 | |
376 | 376 | //Прописываем текущего игрока на все авторизированные аккаунты |
377 | 377 | // TODO - ИЛИ ВСЕХ ИГРОКОВ?? |
378 | - if(empty($this->is_impersonating)) { |
|
379 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
380 | - if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
378 | + if (empty($this->is_impersonating)) { |
|
379 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
380 | + if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
381 | 381 | // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
382 | 382 | PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
383 | 383 | $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true; |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
390 | - if(empty(self::$user['id'])) { |
|
390 | + if (empty(self::$user['id'])) { |
|
391 | 391 | self::cookie_set(''); // OK 4.5 |
392 | - } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
392 | + } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
393 | 393 | self::cookie_set(self::$user['id']); // OK 4.5 |
394 | 394 | } |
395 | 395 | |
@@ -408,21 +408,21 @@ discard block |
||
408 | 408 | */ |
409 | 409 | // OK v4.7 |
410 | 410 | public function logout($redirect = true) { |
411 | - if(!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
411 | + if (!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
412 | 412 | self::cookie_set($_COOKIE[SN_COOKIE_U_I]); |
413 | 413 | self::cookie_set(0, true); |
414 | 414 | self::$main_provider->logout(); |
415 | 415 | } else { |
416 | - foreach($this->providers as $provider_name => $provider) { |
|
416 | + foreach ($this->providers as $provider_name => $provider) { |
|
417 | 417 | $provider->logout(); |
418 | 418 | } |
419 | 419 | |
420 | 420 | self::cookie_set(0); |
421 | 421 | } |
422 | 422 | |
423 | - if($redirect === true) { |
|
423 | + if ($redirect === true) { |
|
424 | 424 | sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php')); |
425 | - } elseif($redirect !== false) { |
|
425 | + } elseif ($redirect !== false) { |
|
426 | 426 | sys_redirect($redirect); |
427 | 427 | } |
428 | 428 | } |
@@ -433,15 +433,15 @@ discard block |
||
433 | 433 | * @param $user_selected |
434 | 434 | */ |
435 | 435 | public function impersonate($user_selected) { |
436 | - if($_COOKIE[SN_COOKIE_U_I]) { |
|
436 | + if ($_COOKIE[SN_COOKIE_U_I]) { |
|
437 | 437 | die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it |
438 | 438 | } |
439 | 439 | |
440 | - if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
440 | + if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
441 | 441 | die('You can\'t impersonate - too low level'); // TODO: Log it |
442 | 442 | } |
443 | 443 | |
444 | - if($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
444 | + if ($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
445 | 445 | die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it |
446 | 446 | } |
447 | 447 | |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]); |
450 | 450 | $account_to_impersonate = new Account(self::$main_provider->db); |
451 | 451 | $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']); |
452 | - if(!$account_to_impersonate->is_exists) { |
|
452 | + if (!$account_to_impersonate->is_exists) { |
|
453 | 453 | die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it |
454 | 454 | } |
455 | 455 | self::$main_provider->impersonate($account_to_impersonate); |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | public function password_check($password_unsafe) { |
476 | 476 | $result = false; |
477 | 477 | |
478 | - if(empty($this->providers_authorised)) { |
|
478 | + if (empty($this->providers_authorised)) { |
|
479 | 479 | // TODO - такого быть не может! |
480 | 480 | self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
481 | 481 | } else { |
482 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
483 | - if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
482 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
483 | + if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
484 | 484 | $result = $result || $provider->password_check($password_unsafe); |
485 | 485 | } |
486 | 486 | } |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | public function password_change($old_password_unsafe, $new_password_unsafe) { |
502 | 502 | global $lang; |
503 | 503 | |
504 | - if(empty($this->providers_authorised)) { |
|
504 | + if (empty($this->providers_authorised)) { |
|
505 | 505 | // TODO - такого быть не может! |
506 | 506 | self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
507 | 507 | return false; |
@@ -514,8 +514,8 @@ discard block |
||
514 | 514 | $salt_unsafe = self::password_salt_generate(); |
515 | 515 | |
516 | 516 | $providers_changed_password = array(); |
517 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
518 | - if( |
|
517 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
518 | + if ( |
|
519 | 519 | !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE) |
520 | 520 | || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe) |
521 | 521 | ) { |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id); |
528 | 528 | |
529 | 529 | // Рассылаем уведомления о смене пароля в ЛС |
530 | - foreach($account_translation as $user_id => $provider_info) { |
|
530 | + foreach ($account_translation as $user_id => $provider_info) { |
|
531 | 531 | // TODO - УКазывать тип аккаунта, на котором сменён пароль |
532 | 532 | msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, |
533 | 533 | $lang['sys_administration'], $lang['sys_login_register_message_title'], |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | sn_db_transaction_start(); |
575 | 575 | // Проверить наличие такого имени в истории имён |
576 | 576 | |
577 | - if(db_player_name_exists($player_name_unsafe)) { |
|
577 | + if (db_player_name_exists($player_name_unsafe)) { |
|
578 | 578 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR); |
579 | 579 | } |
580 | 580 | |
@@ -582,11 +582,11 @@ discard block |
||
582 | 582 | $player_language = ''; |
583 | 583 | $player_email = ''; |
584 | 584 | // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
585 | - foreach($this->providers_authorised as $provider) { |
|
586 | - if(!$player_language && $provider->account->account_language) { |
|
585 | + foreach ($this->providers_authorised as $provider) { |
|
586 | + if (!$player_language && $provider->account->account_language) { |
|
587 | 587 | $player_language = $provider->account->account_language; |
588 | 588 | } |
589 | - if(!$player_email && $provider->account->account_email) { |
|
589 | + if (!$player_email && $provider->account->account_email) { |
|
590 | 590 | $player_email = $provider->account->account_email; |
591 | 591 | } |
592 | 592 | } |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | )); |
603 | 603 | // Зарегестрировать на него аккаунты из self::$accounts_authorised |
604 | 604 | $a_user = self::$user; |
605 | - foreach($this->providers_authorised as $provider) { |
|
605 | + foreach ($this->providers_authorised as $provider) { |
|
606 | 606 | // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор |
607 | 607 | // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
608 | 608 | // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']); |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | |
615 | 615 | sn_db_transaction_commit(); |
616 | 616 | $this->register_status = LOGIN_SUCCESS; |
617 | - } catch(Exception $e) { |
|
617 | + } catch (Exception $e) { |
|
618 | 618 | sn_db_transaction_rollback(); |
619 | 619 | |
620 | 620 | // Если старое имя занято |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | // Пробиваем все ИД игроков по базе - есть ли вообще такие записи |
634 | 634 | // Вообще-то это не особо нужно - у нас по определению стоят констраинты |
635 | 635 | // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров |
636 | - foreach($this->user_id_to_provider as $user_id => $cork) { |
|
636 | + foreach ($this->user_id_to_provider as $user_id => $cork) { |
|
637 | 637 | $user = db_user_by_id($user_id); |
638 | 638 | // Если записи игрока в БД не существует? |
639 | - if(empty($user['id'])) { |
|
639 | + if (empty($user['id'])) { |
|
640 | 640 | // Удаляем этого и переходим к следующему |
641 | 641 | unset($this->user_id_to_provider[$user_id]); |
642 | 642 | // Де-регистрируем игрока из таблицы трансляции игроков |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | // OK v4.5 |
658 | 658 | protected function get_active_user() { |
659 | 659 | // Проверяем куку "текущего игрока" из браузера |
660 | - if( |
|
660 | + if ( |
|
661 | 661 | // Кука не пустая |
662 | 662 | ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U]) |
663 | 663 | // И в куке находится ID |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | } |
683 | 683 | |
684 | 684 | // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов |
685 | - if(empty(self::$user['id'])) { |
|
685 | + if (empty(self::$user['id'])) { |
|
686 | 686 | // Берем первого из доступных |
687 | 687 | // TODO - default_user |
688 | 688 | self::$user = reset($this->accessible_user_row_list); |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | |
707 | 707 | $result = array(); |
708 | 708 | |
709 | - if($user_id && empty($this->is_impersonating)) { |
|
709 | + if ($user_id && empty($this->is_impersonating)) { |
|
710 | 710 | // self::db_counter_insert(); |
711 | 711 | self::$device->db_counter_insert($user_id); |
712 | 712 | |
@@ -714,12 +714,12 @@ discard block |
||
714 | 714 | |
715 | 715 | sys_user_options_unpack($user); |
716 | 716 | |
717 | - if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
717 | + if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
718 | 718 | $user['banaday'] = 0; |
719 | 719 | $user['vacation'] = SN_TIME_NOW; |
720 | 720 | } |
721 | 721 | |
722 | - $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip']; |
|
722 | + $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip']; |
|
723 | 723 | $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain']; |
724 | 724 | |
725 | 725 | $result[F_BANNED_STATUS] = $user['banaday']; |
@@ -733,13 +733,13 @@ discard block |
||
733 | 733 | ); |
734 | 734 | } |
735 | 735 | |
736 | - if($extra = $config->security_ban_extra) { |
|
736 | + if ($extra = $config->security_ban_extra) { |
|
737 | 737 | $extra = explode(',', $extra); |
738 | - array_walk($extra,'trim'); |
|
738 | + array_walk($extra, 'trim'); |
|
739 | 739 | in_array(self::$device->device_id, $extra) and die(); |
740 | 740 | } |
741 | 741 | |
742 | - if(self::$login_message) { |
|
742 | + if (self::$login_message) { |
|
743 | 743 | $result[F_LOGIN_MESSAGE] = self::$login_message; |
744 | 744 | } |
745 | 745 | |
@@ -775,21 +775,21 @@ discard block |
||
775 | 775 | protected function register_player_name_validate($player_name_unsafe) { |
776 | 776 | // TODO - переделать под RAW-строки |
777 | 777 | // Если имя игрока пустое - NO GO! |
778 | - if(trim($player_name_unsafe) == '') { |
|
778 | + if (trim($player_name_unsafe) == '') { |
|
779 | 779 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR); |
780 | 780 | } |
781 | 781 | // Проверяем, что бы в начале и конце не было пустых символов |
782 | - if($player_name_unsafe != trim($player_name_unsafe)) { |
|
782 | + if ($player_name_unsafe != trim($player_name_unsafe)) { |
|
783 | 783 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR); |
784 | 784 | } |
785 | 785 | // Если логин имеет запрещенные символы - NO GO! |
786 | - if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
786 | + if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
787 | 787 | // TODO - выдавать в сообщение об ошибке список запрещенных символов |
788 | 788 | // TODO - заранее извещать игрока, какие символы являются запрещенными |
789 | 789 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR); |
790 | 790 | } |
791 | 791 | // Если логин меньше минимальной длины - NO GO! |
792 | - if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
792 | + if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
793 | 793 | // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока |
794 | 794 | // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени |
795 | 795 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR); |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | } |
848 | 848 | |
849 | 849 | protected static function flog($message, $die = false) { |
850 | - if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
850 | + if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
851 | 851 | return; |
852 | 852 | } |
853 | 853 | list($called, $caller) = debug_backtrace(false); |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false; |
861 | 861 | |
862 | 862 | classSupernova::log_file("$message - $caller_name"); |
863 | - if($die) { |
|
863 | + if ($die) { |
|
864 | 864 | $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
865 | 865 | } |
866 | 866 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | function db_unit_records_sum($unit_id, $user_skip_list_unit) |
105 | 105 | { |
106 | - return doquery ( |
|
106 | + return doquery( |
|
107 | 107 | "SELECT unit_player_id, username, sum(unit_level) as unit_level |
108 | 108 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
109 | 109 | WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit} |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | function db_unit_records_plain($unit_id, $user_skip_list_unit) |
117 | 117 | { |
118 | - return doquery ( |
|
118 | + return doquery( |
|
119 | 119 | "SELECT unit_player_id, username, unit_level |
120 | 120 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
121 | 121 | WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit} |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | function db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source = false) { |
128 | - if(!$source) { |
|
128 | + if (!$source) { |
|
129 | 129 | $source = array( |
130 | 130 | 'statpoints' => 'statpoints', |
131 | 131 | 'users' => 'users', |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - if($who == 1) { |
|
150 | - if($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
149 | + if ($who == 1) { |
|
150 | + if ($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
151 | 151 | $query_str = |
152 | 152 | "SELECT |
153 | 153 | @rownum:=@rownum+1 rownum, subject.{$source['id']} as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.{$source['username']} as `name`, subject.* |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | ORDER BY |
162 | 162 | sp.`{$Rank}_rank`, subject.{$source['id']} |
163 | 163 | LIMIT |
164 | - ". $start .",100;"; |
|
164 | + " . $start . ",100;"; |
|
165 | 165 | } else { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
166 | 166 | $query_str = |
167 | 167 | "SELECT |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | ORDER BY |
175 | 175 | subject.{$Rank} DESC, subject.{$source['id']} |
176 | 176 | LIMIT |
177 | - ". $start .",100;"; |
|
177 | + " . $start . ",100;"; |
|
178 | 178 | } |
179 | 179 | } else { |
180 | 180 | // TODO |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | ORDER BY |
192 | 192 | sp.`{$Rank}_rank`, subject.id |
193 | 193 | LIMIT |
194 | - ". $start .",100;"; |
|
194 | + " . $start . ",100;"; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return doquery($query_str); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) { |
278 | 278 | $current_value_safe = db_escape($current_value_unsafe); |
279 | 279 | $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true); |
280 | - if(!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
280 | + if (!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
281 | 281 | doquery("INSERT INTO {{{$db_table_name}}} (`{$db_value_field_name}`) VALUES ('{$current_value_safe}');"); |
282 | 282 | $variable_id = db_insert_id(); |
283 | 283 | } else { |