@@ -9,19 +9,19 @@ discard block |
||
| 9 | 9 | $ts_var_stat_update = strtotime(classSupernova::$config->db_loadItem('var_stat_update')); |
| 10 | 10 | $ts_scheduled_update = sys_schedule_get_prev_run(classSupernova::$config->db_loadItem('stats_schedule'), classSupernova::$config->var_stat_update); |
| 11 | 11 | |
| 12 | - if(sys_get_param_int('admin_update')) { |
|
| 12 | + if (sys_get_param_int('admin_update')) { |
|
| 13 | 13 | define('USER_LEVEL', isset($user['authlevel']) ? $user['authlevel'] : -1); |
| 14 | - if(USER_LEVEL > 0) { |
|
| 14 | + if (USER_LEVEL > 0) { |
|
| 15 | 15 | $is_admin_request = true; |
| 16 | 16 | $ts_scheduled_update = SN_TIME_NOW; |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if($ts_scheduled_update > $ts_var_stat_update) { |
|
| 20 | + if ($ts_scheduled_update > $ts_var_stat_update) { |
|
| 21 | 21 | lng_include('admin'); |
| 22 | 22 | sn_db_transaction_start(); |
| 23 | 23 | $ts_var_stat_update_end = strtotime(classSupernova::$config->db_loadItem('var_stat_update_end')); |
| 24 | - if(SN_TIME_NOW > $ts_var_stat_update_end) { |
|
| 24 | + if (SN_TIME_NOW > $ts_var_stat_update_end) { |
|
| 25 | 25 | $old_server_status = classSupernova::$config->db_loadItem('game_disable'); |
| 26 | 26 | classSupernova::$config->db_saveItem('game_disable', GAME_DISABLE_STAT); |
| 27 | 27 | |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $msg = $is_admin_request ? 'admin request' : 'scheduler'; |
| 33 | 33 | $next_run = date(FMT_DATE_TIME_SQL, sys_schedule_get_prev_run(classSupernova::$config->stats_schedule, classSupernova::$config->var_stat_update, true)); |
| 34 | - $msg = "Running stat updates: {$msg}. Config->var_stat_update = " . classSupernova::$config->var_stat_update . |
|
| 35 | - ', $ts_scheduled_update = ' . date(FMT_DATE_TIME_SQL, $ts_scheduled_update) . |
|
| 36 | - ', next_stat_update = ' . $next_run; |
|
| 34 | + $msg = "Running stat updates: {$msg}. Config->var_stat_update = ".classSupernova::$config->var_stat_update. |
|
| 35 | + ', $ts_scheduled_update = '.date(FMT_DATE_TIME_SQL, $ts_scheduled_update). |
|
| 36 | + ', next_stat_update = '.$next_run; |
|
| 37 | 37 | classSupernova::$debug->warning($msg, 'Stat update', LOG_INFO_STAT_PROCESS); |
| 38 | 38 | $total_time = microtime(true); |
| 39 | 39 | |
| 40 | 40 | // require_once('../includes/sys_stat.php'); |
| 41 | - require_once(SN_ROOT_PHYSICAL . 'includes/includes/sys_stat.php'); |
|
| 41 | + require_once(SN_ROOT_PHYSICAL.'includes/includes/sys_stat.php'); |
|
| 42 | 42 | sys_stat_calculate(); |
| 43 | 43 | |
| 44 | 44 | $total_time = microtime(true) - $total_time; |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | classSupernova::$config->db_saveItem('var_stat_update_end', SN_TIME_SQL); |
| 58 | 58 | |
| 59 | 59 | classSupernova::$config->db_saveItem('game_disable', $old_server_status); |
| 60 | - } elseif($ts_scheduled_update > $ts_var_stat_update) { |
|
| 60 | + } elseif ($ts_scheduled_update > $ts_var_stat_update) { |
|
| 61 | 61 | $timeout = strtotime(classSupernova::$config->db_loadItem('var_stat_update_end')) - SN_TIME_NOW; |
| 62 | 62 | $msg = classSupernova::$config->db_loadItem('var_stat_update_msg'); |
| 63 | 63 | $msg = "{$msg} ETA {$timeout} seconds. Please wait..."; |
| 64 | 64 | } |
| 65 | 65 | sn_db_transaction_rollback(); |
| 66 | - } elseif($is_admin_request) { |
|
| 66 | + } elseif ($is_admin_request) { |
|
| 67 | 67 | $msg = 'Stat is up to date'; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -29,32 +29,32 @@ discard block |
||
| 29 | 29 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = '', $already_changed = false) { |
| 30 | 30 | global $dm_change_legit, $user; |
| 31 | 31 | |
| 32 | - if(!$user_id) { |
|
| 32 | + if (!$user_id) { |
|
| 33 | 33 | return false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $dm_change_legit = true; |
| 37 | 37 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
| 38 | 38 | |
| 39 | - if($already_changed) { |
|
| 39 | + if ($already_changed) { |
|
| 40 | 40 | $rows_affected = 1; |
| 41 | 41 | } else { |
| 42 | 42 | $changeset = array(); |
| 43 | 43 | $a_user = db_user_by_id($user_id, true); |
| 44 | - if($dark_matter < 0) { |
|
| 44 | + if ($dark_matter < 0) { |
|
| 45 | 45 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
| 46 | 46 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
| 47 | 47 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
| 48 | - if($metamatter_to_reduce > 0) { |
|
| 48 | + if ($metamatter_to_reduce > 0) { |
|
| 49 | 49 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
| 50 | - if($metamatter_exists < $metamatter_to_reduce) { |
|
| 50 | + if ($metamatter_exists < $metamatter_to_reduce) { |
|
| 51 | 51 | classSupernova::$debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
| 52 | 52 | } |
| 53 | - if(is_array($comment)) { |
|
| 53 | + if (is_array($comment)) { |
|
| 54 | 54 | $comment = call_user_func_array('sprintf', $comment); |
| 55 | 55 | } |
| 56 | 56 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
| 57 | - classSupernova::$auth->account->metamatter_change($change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
|
| 57 | + classSupernova::$auth->account->metamatter_change($change_type, -$metamatter_to_reduce, 'ММ в ТМ: '.(-$dark_matter).' ТМ = '.$dark_matter_exists.' ТМ + '.$metamatter_to_reduce.' ММ. '.$comment); |
|
| 58 | 58 | $dark_matter = -$dark_matter_exists; |
| 59 | 59 | } |
| 60 | 60 | } else { |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | $rows_affected = classSupernova::$db->db_affected_rows(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if($rows_affected || !$dark_matter) { |
|
| 68 | + if ($rows_affected || !$dark_matter) { |
|
| 69 | 69 | $page_url = db_escape($_SERVER['SCRIPT_NAME']); |
| 70 | - if(is_array($comment)) { |
|
| 70 | + if (is_array($comment)) { |
|
| 71 | 71 | $comment = call_user_func_array('sprintf', $comment); |
| 72 | 72 | } |
| 73 | 73 | $comment = db_escape($comment); |
@@ -75,18 +75,18 @@ discard block |
||
| 75 | 75 | $row['username'] = db_escape($row['username']); |
| 76 | 76 | db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment, $row, $page_url); |
| 77 | 77 | |
| 78 | - if($user['id'] == $user_id) { |
|
| 78 | + if ($user['id'] == $user_id) { |
|
| 79 | 79 | $user['dark_matter'] += $dark_matter; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if($dark_matter > 0) { |
|
| 82 | + if ($dark_matter > 0) { |
|
| 83 | 83 | $old_referral = db_referral_get_by_id($user_id); |
| 84 | - if($old_referral['id']) { |
|
| 84 | + if ($old_referral['id']) { |
|
| 85 | 85 | db_referral_update_dm($user_id, $dark_matter); |
| 86 | 86 | $new_referral = db_referral_get_by_id($user_id); |
| 87 | 87 | |
| 88 | 88 | $partner_bonus = floor($new_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) : 0); |
| 89 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
| 89 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
| 90 | 90 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | function rpg_level_up(&$user, $type, $xp_to_add = 0) { |
| 104 | 104 | $q = 1.03; |
| 105 | 105 | |
| 106 | - switch($type) { |
|
| 106 | + switch ($type) { |
|
| 107 | 107 | case RPG_STRUCTURE: |
| 108 | 108 | $field_level = 'lvl_minier'; |
| 109 | 109 | $field_xp = 'xpminier'; |
@@ -140,17 +140,17 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $xp = &$user[$field_xp]; |
| 142 | 142 | |
| 143 | - if($xp_to_add) { |
|
| 143 | + if ($xp_to_add) { |
|
| 144 | 144 | $xp += $xp_to_add; |
| 145 | 145 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $level = $user[$field_level]; |
| 149 | - while($xp > rpg_xp_for_level($level + 1, $b1, $q)) { |
|
| 149 | + while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) { |
|
| 150 | 150 | $level++; |
| 151 | 151 | } |
| 152 | 152 | $level -= $user[$field_level]; |
| 153 | - if($level > 0) { |
|
| 153 | + if ($level > 0) { |
|
| 154 | 154 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
| 155 | 155 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
| 156 | 156 | $user[$field_level] += $level; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function geometry_progression_sum($n, $b1, $q) { |
| 4 | - return $q != 1 ? ($b1 * (pow($q, $n) - 1)/($q - 1)) : ($n * $b1); |
|
| 4 | + return $q != 1 ? ($b1 * (pow($q, $n) - 1) / ($q - 1)) : ($n * $b1); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function sn_floor($value) |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return float|int |
| 45 | 45 | */ |
| 46 | -function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
| 47 | - if($cut_extreme) { |
|
| 46 | +function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
| 47 | + if ($cut_extreme) { |
|
| 48 | 48 | $range_start--; |
| 49 | 49 | $range_end++; |
| 50 | 50 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $args = func_get_args(); |
| 62 | 62 | |
| 63 | - switch(func_num_args()) |
|
| 63 | + switch (func_num_args()) |
|
| 64 | 64 | { |
| 65 | 65 | case 0: |
| 66 | 66 | // trigger_error('median() requires at least one parameter',E_USER_WARNING); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | // fallthrough |
| 73 | 73 | |
| 74 | 74 | default: |
| 75 | - if(!is_array($args)) |
|
| 75 | + if (!is_array($args)) |
|
| 76 | 76 | { |
| 77 | 77 | // trigger_error('median() requires a list of numbers to operate on or an array of numbers', E_USER_NOTICE); |
| 78 | 78 | return false; |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | $n = count($args); |
| 84 | 84 | $h = intval($n / 2); |
| 85 | 85 | |
| 86 | - if($n % 2 == 0) |
|
| 86 | + if ($n % 2 == 0) |
|
| 87 | 87 | { |
| 88 | - $median = ($args[$h] + $args[$h-1]) / 2; |
|
| 88 | + $median = ($args[$h] + $args[$h - 1]) / 2; |
|
| 89 | 89 | } |
| 90 | 90 | else |
| 91 | 91 | { |
@@ -103,49 +103,49 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | function linear_calc(&$linear, $from = 0, $logProcess = false) |
| 105 | 105 | { |
| 106 | - for($i = $from; $i < count($linear); $i++) |
|
| 106 | + for ($i = $from; $i < count($linear); $i++) |
|
| 107 | 107 | { |
| 108 | 108 | $eq = &$linear[$i]; |
| 109 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
| 109 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
| 110 | 110 | { |
| 111 | 111 | $eq[$j] /= $eq[$from]; |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | - if($logProcess) pdump($linear, 'Нормализовано по х' . $from); |
|
| 114 | + if ($logProcess) pdump($linear, 'Нормализовано по х'.$from); |
|
| 115 | 115 | |
| 116 | - for($i = $from + 1; $i < count($linear); $i++) |
|
| 116 | + for ($i = $from + 1; $i < count($linear); $i++) |
|
| 117 | 117 | { |
| 118 | 118 | $eq = &$linear[$i]; |
| 119 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
| 119 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
| 120 | 120 | { |
| 121 | 121 | $eq[$j] -= $linear[$from][$j]; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | - if($logProcess) pdump($linear, 'Подставили х' . $from); |
|
| 124 | + if ($logProcess) pdump($linear, 'Подставили х'.$from); |
|
| 125 | 125 | |
| 126 | - if($from < count($linear) - 1) |
|
| 126 | + if ($from < count($linear) - 1) |
|
| 127 | 127 | { |
| 128 | 128 | linear_calc($linear, $from + 1, $logProcess); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if($from) |
|
| 131 | + if ($from) |
|
| 132 | 132 | { |
| 133 | - for($i = 0; $i < $from; $i++) |
|
| 133 | + for ($i = 0; $i < $from; $i++) |
|
| 134 | 134 | { |
| 135 | 135 | $eq = &$linear[$i]; |
| 136 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
| 136 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
| 137 | 137 | { |
| 138 | 138 | $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j]; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | - if($logProcess) pdump($linear, 'Подставили обратно х' . $from); |
|
| 141 | + if ($logProcess) pdump($linear, 'Подставили обратно х'.$from); |
|
| 142 | 142 | } |
| 143 | 143 | else |
| 144 | 144 | { |
| 145 | - if($logProcess) pdump($linear, 'Результат' . $from); |
|
| 146 | - foreach($linear as $index => &$eq) |
|
| 145 | + if ($logProcess) pdump($linear, 'Результат'.$from); |
|
| 146 | + foreach ($linear as $index => &$eq) |
|
| 147 | 147 | { |
| 148 | - pdump($eq[count($linear)], 'x' . $index); |
|
| 148 | + pdump($eq[count($linear)], 'x'.$index); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -86,8 +86,7 @@ discard block |
||
| 86 | 86 | if($n % 2 == 0) |
| 87 | 87 | { |
| 88 | 88 | $median = ($args[$h] + $args[$h-1]) / 2; |
| 89 | - } |
|
| 90 | - else |
|
| 89 | + } else |
|
| 91 | 90 | { |
| 92 | 91 | $median = $args[$h]; |
| 93 | 92 | } |
@@ -111,7 +110,9 @@ discard block |
||
| 111 | 110 | $eq[$j] /= $eq[$from]; |
| 112 | 111 | } |
| 113 | 112 | } |
| 114 | - if($logProcess) pdump($linear, 'Нормализовано по х' . $from); |
|
| 113 | + if($logProcess) { |
|
| 114 | + pdump($linear, 'Нормализовано по х' . $from); |
|
| 115 | + } |
|
| 115 | 116 | |
| 116 | 117 | for($i = $from + 1; $i < count($linear); $i++) |
| 117 | 118 | { |
@@ -121,7 +122,9 @@ discard block |
||
| 121 | 122 | $eq[$j] -= $linear[$from][$j]; |
| 122 | 123 | } |
| 123 | 124 | } |
| 124 | - if($logProcess) pdump($linear, 'Подставили х' . $from); |
|
| 125 | + if($logProcess) { |
|
| 126 | + pdump($linear, 'Подставили х' . $from); |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | if($from < count($linear) - 1) |
| 127 | 130 | { |
@@ -138,11 +141,14 @@ discard block |
||
| 138 | 141 | $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j]; |
| 139 | 142 | } |
| 140 | 143 | } |
| 141 | - if($logProcess) pdump($linear, 'Подставили обратно х' . $from); |
|
| 142 | - } |
|
| 143 | - else |
|
| 144 | + if($logProcess) { |
|
| 145 | + pdump($linear, 'Подставили обратно х' . $from); |
|
| 146 | + } |
|
| 147 | + } else |
|
| 144 | 148 | { |
| 145 | - if($logProcess) pdump($linear, 'Результат' . $from); |
|
| 149 | + if($logProcess) { |
|
| 150 | + pdump($linear, 'Результат' . $from); |
|
| 151 | + } |
|
| 146 | 152 | foreach($linear as $index => &$eq) |
| 147 | 153 | { |
| 148 | 154 | pdump($eq[count($linear)], 'x' . $index); |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | public function compile_request($request) { |
| 451 | 451 | global $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 = classSupernova::$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(classLocale::$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(classLocale::$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(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -500,26 +500,26 @@ discard block |
||
| 500 | 500 | * @throws Exception |
| 501 | 501 | */ |
| 502 | 502 | protected function payment_request_process($options = array()) { |
| 503 | - if(!$this->manifest['active']) { |
|
| 503 | + if (!$this->manifest['active']) { |
|
| 504 | 504 | throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // Если есть payment_id - загружаем под него данные |
| 508 | - if(!empty($this->payment_params['payment_id'])) { |
|
| 508 | + if (!empty($this->payment_params['payment_id'])) { |
|
| 509 | 509 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); |
| 510 | - if(!$this->request_payment_id) { |
|
| 510 | + if (!$this->request_payment_id) { |
|
| 511 | 511 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if(!$this->db_get_by_id($this->request_payment_id)) { |
|
| 514 | + if (!$this->db_get_by_id($this->request_payment_id)) { |
|
| 515 | 515 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Проверяем - был ли этот платеж обработан? |
| 519 | 519 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed |
| 520 | - if($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 520 | + if ($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 521 | 521 | sn_db_transaction_rollback(); |
| 522 | - sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); |
|
| 522 | + sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id); |
|
| 523 | 523 | die(); |
| 524 | 524 | } |
| 525 | 525 | } |
@@ -527,89 +527,89 @@ discard block |
||
| 527 | 527 | // Пытаемся получить из запроса ИД аккаунта |
| 528 | 528 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; |
| 529 | 529 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id |
| 530 | - if(empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 530 | + if (empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 531 | 531 | $request_account_id = $this->payment_account_id; |
| 532 | 532 | } |
| 533 | 533 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать |
| 534 | - if(empty($request_account_id)) { |
|
| 534 | + if (empty($request_account_id)) { |
|
| 535 | 535 | // TODO - аккаунт |
| 536 | 536 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 537 | 537 | } |
| 538 | 538 | // Если нет записи в таблице - тогда берем payment_account_id из запроса |
| 539 | - if(empty($this->payment_account_id)) { |
|
| 539 | + if (empty($this->payment_account_id)) { |
|
| 540 | 540 | $this->payment_account_id = $request_account_id; |
| 541 | 541 | } |
| 542 | 542 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать |
| 543 | - if($this->payment_account_id != $request_account_id) { |
|
| 543 | + if ($this->payment_account_id != $request_account_id) { |
|
| 544 | 544 | // TODO - Поменять сообщение об ошибке |
| 545 | 545 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 546 | 546 | } |
| 547 | 547 | // Проверяем существование аккаунта с данным ИД |
| 548 | - if(!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 549 | - throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 548 | + if (!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 549 | + throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'].' ID '.$this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? |
| 553 | - if(!empty($this->payment_params['server_id'])) { |
|
| 553 | + if (!empty($this->payment_params['server_id'])) { |
|
| 554 | 554 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); |
| 555 | - if(SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 556 | - throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 555 | + if (SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 556 | + throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | // Сверка количества оплаченной ММ с учётом бонусов |
| 561 | - if(!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 561 | + if (!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 562 | 562 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); |
| 563 | - if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 564 | - throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 563 | + if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 564 | + throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid']." пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 565 | 565 | } |
| 566 | 566 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; |
| 567 | 567 | } |
| 568 | - if(empty($this->payment_dark_matter_paid)) { |
|
| 568 | + if (empty($this->payment_dark_matter_paid)) { |
|
| 569 | 569 | // TODO - обратный расчёт из gained |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // Проверка наличия внешнего ИД платежа |
| 573 | - if(!empty($this->payment_params['payment_external_id'])) { |
|
| 573 | + if (!empty($this->payment_params['payment_external_id'])) { |
|
| 574 | 574 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); |
| 575 | - if(empty($request_payment_external_id)) { |
|
| 575 | + if (empty($request_payment_external_id)) { |
|
| 576 | 576 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 577 | - } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 577 | + } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 578 | 578 | // TODO - Может быть поменять сообщение |
| 579 | 579 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 580 | 580 | } |
| 581 | 581 | $this->payment_external_id = $request_payment_external_id; |
| 582 | 582 | } |
| 583 | 583 | // Сверка суммы, запрошенной СН к оплате |
| 584 | - if(!empty($this->payment_params['payment_external_money'])) { |
|
| 584 | + if (!empty($this->payment_params['payment_external_money'])) { |
|
| 585 | 585 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); |
| 586 | - if($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 587 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 586 | + if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 587 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 588 | 588 | } |
| 589 | 589 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; |
| 590 | 590 | } |
| 591 | 591 | // Заполняем поле валюты платёжной системы |
| 592 | - if(!empty($this->payment_params['payment_external_currency'])) { |
|
| 592 | + if (!empty($this->payment_params['payment_external_currency'])) { |
|
| 593 | 593 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); |
| 594 | - if(empty($this->payment_external_currency)) { |
|
| 594 | + if (empty($this->payment_external_currency)) { |
|
| 595 | 595 | // TODO - поменять сообщение |
| 596 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 596 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | - if(empty($this->payment_external_currency)) { |
|
| 599 | + if (empty($this->payment_external_currency)) { |
|
| 600 | 600 | $this->payment_external_currency = $this->config['currency']; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | // Заполнение внутренней суммы и валюты из внешних данных |
| 604 | - if(empty($this->payment_currency)) { |
|
| 604 | + if (empty($this->payment_currency)) { |
|
| 605 | 605 | $this->payment_currency = classSupernova::$config->payment_currency_default; |
| 606 | 606 | } |
| 607 | - if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 607 | + if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 608 | 608 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // TODO - Тестовый режим |
| 612 | - if(!empty($this->payment_params['test'])) { |
|
| 612 | + if (!empty($this->payment_params['test'])) { |
|
| 613 | 613 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); |
| 614 | 614 | } |
| 615 | 615 | |
@@ -636,21 +636,21 @@ discard block |
||
| 636 | 636 | sn_db_transaction_start(); |
| 637 | 637 | try { |
| 638 | 638 | $response = $this->payment_request_process(); |
| 639 | - } catch(Exception $e) { |
|
| 639 | + } catch (Exception $e) { |
|
| 640 | 640 | $response['result'] = $e->getCode(); |
| 641 | 641 | $response['message'] = $e->getMessage(); |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - if($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 644 | + if ($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 645 | 645 | sn_db_transaction_commit(); |
| 646 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 646 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 647 | 647 | } else { |
| 648 | 648 | sn_db_transaction_rollback(); |
| 649 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 649 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | // Переводим код результата из СН в код платежной системы |
| 653 | - if(is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 653 | + if (is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 654 | 654 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | $currency_from = strtolower($currency_from); |
| 674 | 674 | $currency_to = strtolower($currency_to); |
| 675 | 675 | |
| 676 | - if($currency_from != $currency_to) { |
|
| 676 | + if ($currency_from != $currency_to) { |
|
| 677 | 677 | $exchange_from = get_exchange_rate($currency_from); |
| 678 | 678 | $exchange_to = get_exchange_rate($currency_to); |
| 679 | 679 | |
@@ -697,10 +697,10 @@ discard block |
||
| 697 | 697 | public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { |
| 698 | 698 | $bonus = 0; |
| 699 | 699 | $dark_matter_new = $dark_matter; |
| 700 | - if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 701 | - if($direct) { |
|
| 702 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 703 | - if($dm_for_bonus <= $dark_matter) { |
|
| 700 | + if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 701 | + if ($direct) { |
|
| 702 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 703 | + if ($dm_for_bonus <= $dark_matter) { |
|
| 704 | 704 | $dark_matter_new = $dark_matter * (1 + $multiplier); |
| 705 | 705 | $bonus = $multiplier; |
| 706 | 706 | } else { |
@@ -708,9 +708,9 @@ discard block |
||
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | } else { |
| 711 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 711 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 712 | 712 | $temp = $dm_for_bonus * (1 + $multiplier); |
| 713 | - if($dark_matter >= $temp) { |
|
| 713 | + if ($dark_matter >= $temp) { |
|
| 714 | 714 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); |
| 715 | 715 | $bonus = $multiplier; |
| 716 | 716 | } else { |
@@ -764,30 +764,30 @@ discard block |
||
| 764 | 764 | ); |
| 765 | 765 | |
| 766 | 766 | $replace = false; |
| 767 | - if($this->payment_id) { |
|
| 767 | + if ($this->payment_id) { |
|
| 768 | 768 | $payment['payment_id'] = $this->payment_id; |
| 769 | 769 | $replace = true; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | $query = array(); |
| 773 | - foreach($payment as $key => $value) { |
|
| 774 | - $value = is_string($value) ? '"' . db_escape($value) . '"' : $value; |
|
| 773 | + foreach ($payment as $key => $value) { |
|
| 774 | + $value = is_string($value) ? '"'.db_escape($value).'"' : $value; |
|
| 775 | 775 | $query[] = "`{$key}` = {$value}"; |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | - $this->db->doquery(($replace ? 'REPLACE' : 'INSERT') . ' INTO `{{payment}}` SET ' . implode(',', $query) . ';'); |
|
| 778 | + $this->db->doquery(($replace ? 'REPLACE' : 'INSERT').' INTO `{{payment}}` SET '.implode(',', $query).';'); |
|
| 779 | 779 | |
| 780 | 780 | return $this->db_get_by_id($this->db->db_insert_id()); |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | |
| 784 | 784 | function payment_adjust_mm_new() { |
| 785 | - if(!$this->payment_test) { |
|
| 785 | + if (!$this->payment_test) { |
|
| 786 | 786 | // Not a test payment. Adding DM to account |
| 787 | 787 | $this->account = new Account($this->db); |
| 788 | 788 | $this->account->db_get_by_id($this->payment_account_id); |
| 789 | 789 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); |
| 790 | - if(!$result) { |
|
| 790 | + if (!$result) { |
|
| 791 | 791 | throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 792 | 792 | } |
| 793 | 793 | } |
@@ -796,25 +796,25 @@ discard block |
||
| 796 | 796 | function payment_cancel(&$payment) { |
| 797 | 797 | die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); |
| 798 | 798 | |
| 799 | - if(!isset($payment['payment_status'])) { |
|
| 799 | + if (!isset($payment['payment_status'])) { |
|
| 800 | 800 | throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 804 | - $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); |
|
| 803 | + if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 804 | + $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']); |
|
| 805 | 805 | |
| 806 | - if(!$payment['payment_test']) { |
|
| 806 | + if (!$payment['payment_test']) { |
|
| 807 | 807 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); |
| 808 | - if(!$result) { |
|
| 808 | + if (!$result) { |
|
| 809 | 809 | throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; |
| 813 | 813 | db_payment_update($payment, $safe_comment); |
| 814 | 814 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); |
| 815 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 815 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 816 | 816 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); |
| 817 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 817 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 818 | 818 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); |
| 819 | 819 | } |
| 820 | 820 | } |
@@ -828,8 +828,8 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | protected function db_complete_payment() { |
| 830 | 830 | // TODO - поле payment_processed |
| 831 | - if($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 832 | - if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 831 | + if ($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 832 | + if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 833 | 833 | $this->payment_adjust_mm_new(); |
| 834 | 834 | $this->payment_status = PAYMENT_STATUS_COMPLETE; |
| 835 | 835 | } else { |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | protected function db_assign_payment($payment = null) { |
| 877 | 877 | $this->payment_reset(); |
| 878 | 878 | |
| 879 | - if(is_array($payment) && isset($payment['payment_id'])) { |
|
| 879 | + if (is_array($payment) && isset($payment['payment_id'])) { |
|
| 880 | 880 | $this->payment_id = $payment['payment_id']; |
| 881 | 881 | $this->payment_status = $payment['payment_status']; |
| 882 | 882 | $this->payment_date = $payment['payment_date']; |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | protected function generate_description() { |
| 919 | 919 | // TODO - системная локализация |
| 920 | 920 | $this->description_generated = array( |
| 921 | - PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100), |
|
| 922 | - PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250), |
|
| 923 | - PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') . |
|
| 924 | - "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL . |
|
| 925 | - " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" . |
|
| 921 | + PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100), |
|
| 922 | + PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250), |
|
| 923 | + PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : ''). |
|
| 924 | + "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL. |
|
| 925 | + " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)". |
|
| 926 | 926 | " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}", |
| 927 | 927 | ); |
| 928 | 928 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | !mysql_select_db($settings['name']) |
| 53 | 53 | ? classSupernova::$debug->error_fatal('DB error - cannot find DB on server', $this->mysql_error()) |
| 54 | 54 | : false; |
| 55 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
| 55 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
| 56 | 56 | ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level', $this->mysql_error()) |
| 57 | 57 | : false; |
| 58 | 58 | |
@@ -802,7 +802,7 @@ |
||
| 802 | 802 | * @return bool |
| 803 | 803 | */ |
| 804 | 804 | protected function checkCaptainNotRelocating() { |
| 805 | - if($this->fleet->mission_type == MT_RELOCATE) { |
|
| 805 | + if ($this->fleet->mission_type == MT_RELOCATE) { |
|
| 806 | 806 | $arriving_captain = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbTargetRow, UNIT_CAPTAIN, true); |
| 807 | 807 | } else { |
| 808 | 808 | $arriving_captain = false; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | |
| 205 | 205 | public static function log_file($message, $spaces = 0) { |
| 206 | - if(self::$debug) { |
|
| 206 | + if (self::$debug) { |
|
| 207 | 207 | self::$debug->log_file($message, $spaces); |
| 208 | 208 | } |
| 209 | 209 | } |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | // Перепаковывает массив на заданную глубину, убирая поля с null |
| 216 | 216 | public static function array_repack(&$array, $level = 0) { |
| 217 | 217 | // TODO $lock_table не нужна тут |
| 218 | - if(!is_array($array)) { |
|
| 218 | + if (!is_array($array)) { |
|
| 219 | 219 | return; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - foreach($array as $key => &$value) { |
|
| 223 | - if($value === null) { |
|
| 222 | + foreach ($array as $key => &$value) { |
|
| 223 | + if ($value === null) { |
|
| 224 | 224 | unset($array[$key]); |
| 225 | - } elseif($level > 0 && is_array($value)) { |
|
| 225 | + } elseif ($level > 0 && is_array($value)) { |
|
| 226 | 226 | static::array_repack($value, $level - 1); |
| 227 | - if(empty($value)) { |
|
| 227 | + if (empty($value)) { |
|
| 228 | 228 | unset($array[$key]); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | // TODO Вынести в отдельный объект |
| 236 | 236 | public static function cache_repack($location_type, $record_id = 0) { |
| 237 | 237 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
| 238 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
| 238 | + if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | public static function cache_clear($location_type, $hard = true) { |
| 248 | 248 | //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />"); |
| 249 | - if($hard && !empty(static::$data[$location_type])) { |
|
| 249 | + if ($hard && !empty(static::$data[$location_type])) { |
|
| 250 | 250 | // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях |
| 251 | - array_walk(static::$data[$location_type], function (&$item) { $item = null; }); |
|
| 251 | + array_walk(static::$data[$location_type], function(&$item) { $item = null; }); |
|
| 252 | 252 | } |
| 253 | 253 | static::$locator[$location_type] = array(); |
| 254 | 254 | static::$queries[$location_type] = array(); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | public static function cache_clear_all($hard = true) { |
| 259 | 259 | //print('<br />CACHE CLEAR ALL<br />'); |
| 260 | - if($hard) { |
|
| 260 | + if ($hard) { |
|
| 261 | 261 | static::$data = array(); |
| 262 | 262 | static::cache_lock_unset_all(); |
| 263 | 263 | } |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
| 288 | 288 | // нет идентификатора - выход |
| 289 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
| 289 | + if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
| 290 | 290 | return; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | $in_transaction = static::db_transaction_check(false); |
| 294 | - if( |
|
| 294 | + if ( |
|
| 295 | 295 | $force_overwrite |
| 296 | 296 | || |
| 297 | 297 | // Не заменяются заблокированные записи во время транзакции |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | !static::cache_isset($location_type, $record_id) |
| 302 | 302 | ) { |
| 303 | 303 | static::$data[$location_type][$record_id] = $record; |
| 304 | - if($in_transaction && !$skip_lock) { |
|
| 304 | + if ($in_transaction && !$skip_lock) { |
|
| 305 | 305 | static::cache_lock_set($location_type, $record_id); |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | public static function cache_unset($cache_id, $safe_record_id) { |
| 311 | 311 | // $record_id должен быть проверен заранее ! |
| 312 | - if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
| 312 | + if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
| 313 | 313 | // Выставляем запись в null |
| 314 | 314 | static::$data[$cache_id][$safe_record_id] = null; |
| 315 | 315 | // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | public static function cache_lock_unset($location_type, $record_id) { |
| 329 | - if(isset(static::$locks[$location_type][$record_id])) { |
|
| 329 | + if (isset(static::$locks[$location_type][$record_id])) { |
|
| 330 | 330 | unset(static::$locks[$location_type][$record_id]); |
| 331 | 331 | } |
| 332 | 332 | |
@@ -360,15 +360,15 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | public static function db_transaction_check($status = null) { |
| 362 | 362 | $error_msg = false; |
| 363 | - if($status && !static::$db_in_transaction) { |
|
| 363 | + if ($status && !static::$db_in_transaction) { |
|
| 364 | 364 | $error_msg = 'No transaction started for current operation'; |
| 365 | - } elseif($status === null && static::$db_in_transaction) { |
|
| 365 | + } elseif ($status === null && static::$db_in_transaction) { |
|
| 366 | 366 | $error_msg = 'Transaction is already started'; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if($error_msg) { |
|
| 369 | + if ($error_msg) { |
|
| 370 | 370 | // TODO - Убрать позже |
| 371 | - print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>'); |
|
| 371 | + print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - '.$error_msg.'</h1>'); |
|
| 372 | 372 | $backtrace = debug_backtrace(); |
| 373 | 373 | array_shift($backtrace); |
| 374 | 374 | pdump($backtrace); |
@@ -381,12 +381,12 @@ discard block |
||
| 381 | 381 | public static function db_transaction_start($level = '') { |
| 382 | 382 | static::db_transaction_check(null); |
| 383 | 383 | |
| 384 | - $level ? doquery('SET TRANSACTION ISOLATION LEVEL ' . $level) : false; |
|
| 384 | + $level ? doquery('SET TRANSACTION ISOLATION LEVEL '.$level) : false; |
|
| 385 | 385 | |
| 386 | 386 | static::$transaction_id++; |
| 387 | 387 | doquery('START TRANSACTION'); |
| 388 | 388 | |
| 389 | - if(classSupernova::$config->db_manual_lock_enabled) { |
|
| 389 | + if (classSupernova::$config->db_manual_lock_enabled) { |
|
| 390 | 390 | classSupernova::$config->db_loadItem('var_db_manually_locked'); |
| 391 | 391 | classSupernova::$config->db_saveItem('var_db_manually_locked', SN_TIME_SQL); |
| 392 | 392 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | public static function db_transaction_commit() { |
| 402 | 402 | static::db_transaction_check(true); |
| 403 | 403 | |
| 404 | - if(!empty(static::$delayed_changset)) { |
|
| 404 | + if (!empty(static::$delayed_changset)) { |
|
| 405 | 405 | static::db_changeset_apply(static::$delayed_changset, true); |
| 406 | 406 | // pdump(static::$delayed_changset); |
| 407 | 407 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | public static function db_transaction_rollback() { |
| 414 | 414 | // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция |
| 415 | 415 | |
| 416 | - if(!empty(static::$delayed_changset)) { |
|
| 416 | + if (!empty(static::$delayed_changset)) { |
|
| 417 | 417 | static::db_changeset_revert(); |
| 418 | 418 | } |
| 419 | 419 | doquery('ROLLBACK'); |
@@ -441,8 +441,8 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public static function db_lock_tables($tables) { |
| 443 | 443 | $tables = is_array($tables) ? $tables : array($tables => ''); |
| 444 | - foreach($tables as $table_name => $condition) { |
|
| 445 | - self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
|
| 444 | + foreach ($tables as $table_name => $condition) { |
|
| 445 | + self::$db->doquery("SELECT 1 FROM {{{$table_name}}}".($condition ? ' WHERE '.$condition : '')); |
|
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | |
@@ -484,17 +484,17 @@ discard block |
||
| 484 | 484 | //pdump($filter, 'Выбираем ' . $location_type); |
| 485 | 485 | $query_cache = &static::$queries[$location_type][$filter]; |
| 486 | 486 | |
| 487 | - if(!isset($query_cache) || $query_cache === null) { |
|
| 487 | + if (!isset($query_cache) || $query_cache === null) { |
|
| 488 | 488 | // pdump($filter, 'Кэш пустой, начинаем возню'); |
| 489 | 489 | $location_info = &static::$location_info[$location_type]; |
| 490 | 490 | $id_field = $location_info[P_ID]; |
| 491 | 491 | $query_cache = array(); |
| 492 | 492 | |
| 493 | - if(static::db_transaction_check(false)) { |
|
| 493 | + if (static::db_transaction_check(false)) { |
|
| 494 | 494 | //pdump($filter, 'Транзакция - блокируем ' . $location_type); |
| 495 | 495 | // Проходим по всем родителям данной записи |
| 496 | 496 | // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data) |
| 497 | - foreach($location_info[P_OWNER_INFO] as $owner_data) { |
|
| 497 | + foreach ($location_info[P_OWNER_INFO] as $owner_data) { |
|
| 498 | 498 | $owner_location_type = $owner_data[P_LOCATION]; |
| 499 | 499 | //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type); |
| 500 | 500 | $parent_id_list = array(); |
@@ -502,24 +502,24 @@ discard block |
||
| 502 | 502 | $query = static::db_query( |
| 503 | 503 | "SELECT |
| 504 | 504 | distinct({{{$location_info[P_TABLE_NAME]}}}.{$owner_data[P_OWNER_FIELD]}) AS parent_id |
| 505 | - FROM {{{$location_info[P_TABLE_NAME]}}}" . |
|
| 506 | - ($filter ? ' WHERE ' . $filter : '') . |
|
| 505 | + FROM {{{$location_info[P_TABLE_NAME]}}}". |
|
| 506 | + ($filter ? ' WHERE '.$filter : ''). |
|
| 507 | 507 | ($fetch ? ' LIMIT 1' : ''), false, true); |
| 508 | 508 | |
| 509 | 509 | //pdump($q, 'Запрос блокировки'); |
| 510 | - while($row = db_fetch($query)) { |
|
| 510 | + while ($row = db_fetch($query)) { |
|
| 511 | 511 | // Исключаем из списка родительских ИД уже заблокированные записи |
| 512 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
| 512 | + if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
| 513 | 513 | $parent_id_list[$row['parent_id']] = $row['parent_id']; |
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | //pdump($parent_id_list, 'Выбраны родители'); |
| 517 | 517 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
| 518 | - if($indexes_str = implode(',', $parent_id_list)) { |
|
| 518 | + if ($indexes_str = implode(',', $parent_id_list)) { |
|
| 519 | 519 | //pdump($indexes_str, '$indexes_str'); |
| 520 | 520 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
| 521 | 521 | static::db_get_record_list($owner_location_type, |
| 522 | - $parent_id_field . (count($parent_id_list) > 1 ? " IN ({$indexes_str})" : " = {$indexes_str}"), $fetch, true); |
|
| 522 | + $parent_id_field.(count($parent_id_list) > 1 ? " IN ({$indexes_str})" : " = {$indexes_str}"), $fetch, true); |
|
| 523 | 523 | } |
| 524 | 524 | //pdump($filter, 'Транзакция - родители заблокированы ' . $owner_location_type); |
| 525 | 525 | } |
@@ -527,10 +527,10 @@ discard block |
||
| 527 | 527 | |
| 528 | 528 | //pdump($filter, 'Выбираем записи и заносим их в кыш-память ' . $owner_location_type); |
| 529 | 529 | $query = static::db_query( |
| 530 | - "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . |
|
| 530 | + "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}". |
|
| 531 | 531 | (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
| 532 | 532 | ); |
| 533 | - while($row = db_fetch($query)) { |
|
| 533 | + while ($row = db_fetch($query)) { |
|
| 534 | 534 | // static::db_get_record_by_id($location_type, $row[$id_field]); |
| 535 | 535 | static::cache_set($location_type, $row[$id_field], $row); |
| 536 | 536 | $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]]; |
@@ -538,14 +538,14 @@ discard block |
||
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - if($no_return) { |
|
| 541 | + if ($no_return) { |
|
| 542 | 542 | return true; |
| 543 | 543 | } else { |
| 544 | 544 | $result = false; |
| 545 | - if(is_array($query_cache)) { |
|
| 546 | - foreach($query_cache as $key => $value) { |
|
| 545 | + if (is_array($query_cache)) { |
|
| 546 | + foreach ($query_cache as $key => $value) { |
|
| 547 | 547 | $result[$key] = $value; |
| 548 | - if($fetch) { |
|
| 548 | + if ($fetch) { |
|
| 549 | 549 | break; |
| 550 | 550 | } |
| 551 | 551 | } |
@@ -564,16 +564,16 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
| 566 | 566 | //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false; |
| 567 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
| 567 | + if (!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
| 568 | 568 | return false; |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | $location_info = &static::$location_info[$location_type]; |
| 572 | 572 | $id_field = $location_info[P_ID]; |
| 573 | 573 | $table_name = $location_info[P_TABLE_NAME]; |
| 574 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
| 574 | + if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
| 575 | 575 | { |
| 576 | - if(static::$db->db_affected_rows()) { |
|
| 576 | + if (static::$db->db_affected_rows()) { |
|
| 577 | 577 | // Обновляем данные только если ряд был затронут |
| 578 | 578 | // TODO - переделать под работу со структурированными $set |
| 579 | 579 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | public static function db_upd_record_list($location_type, $condition, $set) { |
| 592 | - if(!($set = trim($set))) { |
|
| 592 | + if (!($set = trim($set))) { |
|
| 593 | 593 | return false; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | |
| 599 | 599 | //static::db_get_record_list($location_type, $condition, false, true); |
| 600 | 600 | |
| 601 | - if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
| 601 | + if ($result = static::db_query("UPDATE {{{$table_name}}} SET ".$set.($condition ? ' WHERE '.$condition : ''))) { |
|
| 602 | 602 | |
| 603 | - if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
| 603 | + if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
| 604 | 604 | // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью |
| 605 | 605 | // TODO - когда будет структурированный $condition и $set - перепаковывать данные |
| 606 | 606 | static::cache_clear($location_type, true); |
@@ -619,8 +619,8 @@ discard block |
||
| 619 | 619 | public static function db_ins_record($location_type, $set) { |
| 620 | 620 | $set = trim($set); |
| 621 | 621 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
| 622 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
| 623 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 622 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
| 623 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 624 | 624 | { |
| 625 | 625 | $record_id = db_insert_id(); |
| 626 | 626 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -642,8 +642,8 @@ discard block |
||
| 642 | 642 | $fields = implode(',', array_keys($field_set)); |
| 643 | 643 | |
| 644 | 644 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
| 645 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
| 646 | - if(static::$db->db_affected_rows()) { |
|
| 645 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
| 646 | + if (static::$db->db_affected_rows()) { |
|
| 647 | 647 | // Обновляем данные только если ряд был затронут |
| 648 | 648 | $record_id = db_insert_id(); |
| 649 | 649 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -659,15 +659,15 @@ discard block |
||
| 659 | 659 | |
| 660 | 660 | public static function db_del_record_by_id($location_type, $safe_record_id) { |
| 661 | 661 | // if(!($safe_record_id = intval($safe_record_id))) return false; |
| 662 | - if(!($safe_record_id = idval($safe_record_id))) { |
|
| 662 | + if (!($safe_record_id = idval($safe_record_id))) { |
|
| 663 | 663 | return false; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | $location_info = &static::$location_info[$location_type]; |
| 667 | 667 | $id_field = $location_info[P_ID]; |
| 668 | 668 | $table_name = $location_info[P_TABLE_NAME]; |
| 669 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
| 670 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 669 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
| 670 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 671 | 671 | { |
| 672 | 672 | static::cache_unset($location_type, $safe_record_id); |
| 673 | 673 | } |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | public static function db_del_record_list($location_type, $condition) { |
| 680 | - if(!($condition = trim($condition))) { |
|
| 680 | + if (!($condition = trim($condition))) { |
|
| 681 | 681 | return false; |
| 682 | 682 | } |
| 683 | 683 | |
@@ -686,8 +686,8 @@ discard block |
||
| 686 | 686 | |
| 687 | 687 | //static::db_get_record_list($location_type, $condition, false, true); |
| 688 | 688 | |
| 689 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
| 690 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 689 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
| 690 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
| 691 | 691 | { |
| 692 | 692 | // Обнуление кэша, потому что непонятно, что поменялось |
| 693 | 693 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
@@ -734,20 +734,20 @@ discard block |
||
| 734 | 734 | |
| 735 | 735 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
| 736 | 736 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
| 737 | - if(!($username_unsafe = trim($username_unsafe))) { |
|
| 737 | + if (!($username_unsafe = trim($username_unsafe))) { |
|
| 738 | 738 | return false; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | $user = null; |
| 742 | - if(is_array(static::$data[LOC_USER])) { |
|
| 743 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
| 744 | - if(is_array($user_data) && isset($user_data['username'])) { |
|
| 742 | + if (is_array(static::$data[LOC_USER])) { |
|
| 743 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
| 744 | + if (is_array($user_data) && isset($user_data['username'])) { |
|
| 745 | 745 | // проверяем поле |
| 746 | 746 | // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить! |
| 747 | - if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
| 747 | + if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
| 748 | 748 | // $user_as_ally = intval($user_data['user_as_ally']); |
| 749 | 749 | $user_as_ally = idval($user_data['user_as_ally']); |
| 750 | - if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
| 750 | + if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
| 751 | 751 | $user = $user_data; |
| 752 | 752 | break; |
| 753 | 753 | } |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | } |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - if($user === null) { |
|
| 759 | + if ($user === null) { |
|
| 760 | 760 | // Вытаскиваем запись |
| 761 | 761 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
| 762 | 762 | |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | // self::db_get_record_list(LOC_USER, "`username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'"); |
| 765 | 765 | |
| 766 | 766 | $user = static::db_query( |
| 767 | - "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '=') . " '{$username_safe}'" |
|
| 767 | + "SELECT * FROM {{users}} WHERE `username` ".($like ? 'LIKE' : '=')." '{$username_safe}'" |
|
| 768 | 768 | , true); |
| 769 | 769 | static::cache_set(LOC_USER, $user['id'], $user); // В кэш-юзер так же заполнять индексы |
| 770 | 770 | } |
@@ -774,17 +774,17 @@ discard block |
||
| 774 | 774 | |
| 775 | 775 | // UNUSED |
| 776 | 776 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
| 777 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
| 777 | + if (!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
| 778 | 778 | return false; |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | $user = null; |
| 782 | 782 | // TODO переделать на индексы |
| 783 | - if(is_array(static::$data[LOC_USER])) { |
|
| 784 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
| 785 | - if(is_array($user_data) && isset($user_data['email_2'])) { |
|
| 783 | + if (is_array(static::$data[LOC_USER])) { |
|
| 784 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
| 785 | + if (is_array($user_data) && isset($user_data['email_2'])) { |
|
| 786 | 786 | // проверяем поле |
| 787 | - if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
| 787 | + if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
| 788 | 788 | $user = $user_data; |
| 789 | 789 | break; |
| 790 | 790 | } |
@@ -792,11 +792,11 @@ discard block |
||
| 792 | 792 | } |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - if($user === null) { |
|
| 795 | + if ($user === null) { |
|
| 796 | 796 | // Вытаскиваем запись |
| 797 | 797 | $email_safe = db_escape($email_unsafe); |
| 798 | 798 | $user = static::db_query( |
| 799 | - "SELECT * FROM {{users}} WHERE LOWER(`email_2`) = '{$email_safe}'" . |
|
| 799 | + "SELECT * FROM {{users}} WHERE LOWER(`email_2`) = '{$email_safe}'". |
|
| 800 | 800 | ($use_both ? " OR LOWER(`email`) = '{$email_safe}'" : '') |
| 801 | 801 | , true); |
| 802 | 802 | |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | $user = null; |
| 812 | 812 | // TODO переделать на индексы |
| 813 | 813 | |
| 814 | - if($user === null && !empty($where_safe)) { |
|
| 814 | + if ($user === null && !empty($where_safe)) { |
|
| 815 | 815 | // Вытаскиваем запись |
| 816 | 816 | $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true); |
| 817 | 817 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') { |
| 834 | 834 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
| 835 | 835 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
| 836 | - if(is_array($unit)) { |
|
| 836 | + if (is_array($unit)) { |
|
| 837 | 837 | static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
| 838 | 838 | } |
| 839 | 839 | |
@@ -849,15 +849,15 @@ discard block |
||
| 849 | 849 | */ |
| 850 | 850 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) { |
| 851 | 851 | //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false; |
| 852 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
| 852 | + if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
| 853 | 853 | return false; |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
| 857 | - if(!isset($query_cache)) { |
|
| 858 | - $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions()); |
|
| 859 | - if(is_array($got_data)) { |
|
| 860 | - foreach($got_data as $unit_id => $unit_data) { |
|
| 857 | + if (!isset($query_cache)) { |
|
| 858 | + $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND ".static::db_unit_time_restrictions()); |
|
| 859 | + if (is_array($got_data)) { |
|
| 860 | + foreach ($got_data as $unit_id => $unit_data) { |
|
| 861 | 861 | // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
| 862 | 862 | $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
| 863 | 863 | } |
@@ -865,8 +865,8 @@ discard block |
||
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | $result = false; |
| 868 | - if(is_array($query_cache)) { |
|
| 869 | - foreach($query_cache as $key => $value) { |
|
| 868 | + if (is_array($query_cache)) { |
|
| 869 | + foreach ($query_cache as $key => $value) { |
|
| 870 | 870 | $result[$key] = $value; |
| 871 | 871 | } |
| 872 | 872 | } |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | * |
| 902 | 902 | */ |
| 903 | 903 | public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) { |
| 904 | - if(!$user_id) { |
|
| 904 | + if (!$user_id) { |
|
| 905 | 905 | pdump(debug_backtrace()); |
| 906 | 906 | die('No user_id for que_get_que()'); |
| 907 | 907 | } |
@@ -911,16 +911,16 @@ discard block |
||
| 911 | 911 | $query = array(); |
| 912 | 912 | |
| 913 | 913 | // if($user_id = intval($user_id)) |
| 914 | - if($user_id = idval($user_id)) { |
|
| 914 | + if ($user_id = idval($user_id)) { |
|
| 915 | 915 | $query[] = "`que_player_id` = {$user_id}"; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - if($que_type == QUE_RESEARCH || $planet_id === null) { |
|
| 918 | + if ($que_type == QUE_RESEARCH || $planet_id === null) { |
|
| 919 | 919 | $query[] = "`que_planet_id` IS NULL"; |
| 920 | - } elseif($planet_id) { |
|
| 921 | - $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
|
| 920 | + } elseif ($planet_id) { |
|
| 921 | + $query[] = "(`que_planet_id` = {$planet_id}".($que_type ? '' : ' OR que_planet_id IS NULL').")"; |
|
| 922 | 922 | } |
| 923 | - if($que_type) { |
|
| 923 | + if ($que_type) { |
|
| 924 | 924 | $query[] = "`que_type` = {$que_type}"; |
| 925 | 925 | } |
| 926 | 926 | |
@@ -953,13 +953,13 @@ discard block |
||
| 953 | 953 | |
| 954 | 954 | |
| 955 | 955 | public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) { |
| 956 | - if(!is_array($user)) { |
|
| 956 | + if (!is_array($user)) { |
|
| 957 | 957 | // TODO - remove later |
| 958 | 958 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
| 959 | 959 | pdump(debug_backtrace()); |
| 960 | 960 | die('USER is not ARRAY'); |
| 961 | 961 | } |
| 962 | - if(!isset($user['id']) || !$user['id']) { |
|
| 962 | + if (!isset($user['id']) || !$user['id']) { |
|
| 963 | 963 | // TODO - remove later |
| 964 | 964 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
| 965 | 965 | pdump($user); |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | |
| 975 | 975 | $db_changeset = array(); |
| 976 | 976 | $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
| 977 | - if($temp['unit_id']) { |
|
| 977 | + if ($temp['unit_id']) { |
|
| 978 | 978 | $db_changeset = array( |
| 979 | 979 | 'action' => SQL_OP_UPDATE, |
| 980 | 980 | P_VERSION => 1, |
@@ -1043,9 +1043,9 @@ discard block |
||
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | public function db_changeset_condition_compile(&$conditions, &$table_name = '') { |
| 1046 | - if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
| 1046 | + if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
| 1047 | 1047 | $conditions[P_LOCATION] = LOC_NONE; |
| 1048 | - switch($table_name) { |
|
| 1048 | + switch ($table_name) { |
|
| 1049 | 1049 | case 'users': |
| 1050 | 1050 | case LOC_USER: |
| 1051 | 1051 | $conditions[P_TABLE_NAME] = $table_name = 'users'; |
@@ -1067,35 +1067,33 @@ discard block |
||
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | $conditions[P_FIELDS_STR] = ''; |
| 1070 | - if($conditions['fields']) { |
|
| 1070 | + if ($conditions['fields']) { |
|
| 1071 | 1071 | $fields = array(); |
| 1072 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
| 1072 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
| 1073 | 1073 | $condition = "`{$field_name}` = "; |
| 1074 | 1074 | $value = ''; |
| 1075 | - if($field_data['delta']) { |
|
| 1076 | - $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
|
| 1077 | - } elseif($field_data['set']) { |
|
| 1075 | + if ($field_data['delta']) { |
|
| 1076 | + $value = "`{$field_name}`".($field_data['delta'] >= 0 ? '+' : '').$field_data['delta']; |
|
| 1077 | + } elseif ($field_data['set']) { |
|
| 1078 | 1078 | $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | - if($value) { |
|
| 1082 | - $fields[] = $condition . $value; |
|
| 1081 | + if ($value) { |
|
| 1082 | + $fields[] = $condition.$value; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | } |
| 1085 | 1085 | $conditions[P_FIELDS_STR] = implode(',', $fields); |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | $conditions[P_WHERE_STR] = ''; |
| 1089 | - if(!empty($conditions['where'])) { |
|
| 1090 | - if($conditions[P_VERSION] == 1) { |
|
| 1089 | + if (!empty($conditions['where'])) { |
|
| 1090 | + if ($conditions[P_VERSION] == 1) { |
|
| 1091 | 1091 | $the_conditions = array(); |
| 1092 | - foreach($conditions['where'] as $field_id => $field_value) { |
|
| 1092 | + foreach ($conditions['where'] as $field_id => $field_value) { |
|
| 1093 | 1093 | // Простое условие - $field_id = $field_value |
| 1094 | - if(is_string($field_id)) { |
|
| 1094 | + if (is_string($field_id)) { |
|
| 1095 | 1095 | $field_value = |
| 1096 | - $field_value === null ? 'NULL' : |
|
| 1097 | - (is_string($field_value) ? "'" . db_escape($field_value) . "'" : |
|
| 1098 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
| 1096 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'".db_escape($field_value)."'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
| 1099 | 1097 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
| 1100 | 1098 | } else { |
| 1101 | 1099 | die('Неподдерживаемый тип условия'); |
@@ -1112,7 +1110,7 @@ discard block |
||
| 1112 | 1110 | $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions); |
| 1113 | 1111 | } |
| 1114 | 1112 | |
| 1115 | - switch($conditions['action']) { |
|
| 1113 | + switch ($conditions['action']) { |
|
| 1116 | 1114 | case SQL_OP_DELETE: |
| 1117 | 1115 | $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); |
| 1118 | 1116 | break; |
@@ -1127,16 +1125,16 @@ discard block |
||
| 1127 | 1125 | die('Неподдерживаемая операция в classSupernova::db_changeset_condition_compile'); |
| 1128 | 1126 | } |
| 1129 | 1127 | |
| 1130 | - $conditions[P_QUERY_STR] = $conditions[P_ACTION_STR] . ' ' . $conditions[P_FIELDS_STR] . (' WHERE ' . $conditions[P_WHERE_STR]); |
|
| 1128 | + $conditions[P_QUERY_STR] = $conditions[P_ACTION_STR].' '.$conditions[P_FIELDS_STR].(' WHERE '.$conditions[P_WHERE_STR]); |
|
| 1131 | 1129 | } |
| 1132 | 1130 | |
| 1133 | 1131 | public static function db_changeset_apply($db_changeset, $flush_delayed = false) { |
| 1134 | 1132 | $result = true; |
| 1135 | - if(!is_array($db_changeset) || empty($db_changeset)) { |
|
| 1133 | + if (!is_array($db_changeset) || empty($db_changeset)) { |
|
| 1136 | 1134 | return $result; |
| 1137 | 1135 | } |
| 1138 | 1136 | |
| 1139 | - foreach($db_changeset as $table_name => &$table_data) { |
|
| 1137 | + foreach ($db_changeset as $table_name => &$table_data) { |
|
| 1140 | 1138 | // TODO - delayed changeset |
| 1141 | 1139 | /* |
| 1142 | 1140 | if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit')) |
@@ -1145,19 +1143,19 @@ discard block |
||
| 1145 | 1143 | continue; |
| 1146 | 1144 | } |
| 1147 | 1145 | */ |
| 1148 | - foreach($table_data as $record_id => &$conditions) { |
|
| 1146 | + foreach ($table_data as $record_id => &$conditions) { |
|
| 1149 | 1147 | static::db_changeset_condition_compile($conditions, $table_name); |
| 1150 | 1148 | |
| 1151 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
| 1149 | + if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
| 1152 | 1150 | continue; |
| 1153 | 1151 | } |
| 1154 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
| 1152 | + if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
| 1155 | 1153 | continue; |
| 1156 | 1154 | } // Защита от случайного удаления всех данных в таблице |
| 1157 | 1155 | |
| 1158 | - if($conditions[P_LOCATION] != LOC_NONE) { |
|
| 1156 | + if ($conditions[P_LOCATION] != LOC_NONE) { |
|
| 1159 | 1157 | //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд'); |
| 1160 | - switch($conditions['action']) { |
|
| 1158 | + switch ($conditions['action']) { |
|
| 1161 | 1159 | case SQL_OP_DELETE: |
| 1162 | 1160 | $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; |
| 1163 | 1161 | break; |
@@ -1239,13 +1237,13 @@ discard block |
||
| 1239 | 1237 | public static function init_0_prepare() { |
| 1240 | 1238 | // Отключаем magic_quotes |
| 1241 | 1239 | ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false; |
| 1242 | - if(@get_magic_quotes_gpc()) { |
|
| 1240 | + if (@get_magic_quotes_gpc()) { |
|
| 1243 | 1241 | $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); |
| 1244 | - array_walk_recursive($gpcr, function (&$value, $key) { |
|
| 1242 | + array_walk_recursive($gpcr, function(&$value, $key) { |
|
| 1245 | 1243 | $value = stripslashes($value); |
| 1246 | 1244 | }); |
| 1247 | 1245 | } |
| 1248 | - if(function_exists('set_magic_quotes_runtime')) { |
|
| 1246 | + if (function_exists('set_magic_quotes_runtime')) { |
|
| 1249 | 1247 | @set_magic_quotes_runtime(0); |
| 1250 | 1248 | @ini_set('magic_quotes_runtime', 0); |
| 1251 | 1249 | @ini_set('magic_quotes_sybase', 0); |
@@ -1285,7 +1283,7 @@ discard block |
||
| 1285 | 1283 | public static function init_3_load_config_file() { |
| 1286 | 1284 | $dbsettings = array(); |
| 1287 | 1285 | |
| 1288 | - require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
|
| 1286 | + require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX); |
|
| 1289 | 1287 | //self::$db_prefix = $dbsettings['prefix']; |
| 1290 | 1288 | self::$cache_prefix = !empty($dbsettings['cache_prefix']) ? $dbsettings['cache_prefix'] : $dbsettings['prefix']; |
| 1291 | 1289 | self::$db_name = $dbsettings['name']; |
@@ -1317,7 +1315,7 @@ discard block |
||
| 1317 | 1315 | } |
| 1318 | 1316 | |
| 1319 | 1317 | public static function init_debug_state() { |
| 1320 | - if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
| 1318 | + if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
| 1321 | 1319 | define('BE_DEBUG', true); |
| 1322 | 1320 | } |
| 1323 | 1321 | // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение |
@@ -1329,7 +1327,7 @@ discard block |
||
| 1329 | 1327 | defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
| 1330 | 1328 | defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
| 1331 | 1329 | |
| 1332 | - if(defined('BE_DEBUG') || static::$config->debug) { |
|
| 1330 | + if (defined('BE_DEBUG') || static::$config->debug) { |
|
| 1333 | 1331 | @define('BE_DEBUG', true); |
| 1334 | 1332 | @ini_set('display_errors', 1); |
| 1335 | 1333 | @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | public function load_db_settings() { |
| 66 | 66 | $dbsettings = array(); |
| 67 | 67 | |
| 68 | - require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
|
| 68 | + require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX); |
|
| 69 | 69 | |
| 70 | 70 | $this->dbsettings = $dbsettings; |
| 71 | 71 | } |
@@ -73,23 +73,23 @@ discard block |
||
| 73 | 73 | public function sn_db_connect($external_db_settings = null) { |
| 74 | 74 | $this->db_disconnect(); |
| 75 | 75 | |
| 76 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 76 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 77 | 77 | $this->dbsettings = $external_db_settings; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if(empty($this->dbsettings)) { |
|
| 80 | + if (empty($this->dbsettings)) { |
|
| 81 | 81 | $this->load_db_settings(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
| 85 | - if(!empty($this->dbsettings)) { |
|
| 85 | + if (!empty($this->dbsettings)) { |
|
| 86 | 86 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
| 87 | 87 | $this->driver = new $driver_name(); |
| 88 | 88 | $this->db_prefix = $this->dbsettings['prefix']; |
| 89 | 89 | |
| 90 | 90 | $this->connected = $this->connected || $this->driver_connect(); |
| 91 | 91 | |
| 92 | - if($this->connected) { |
|
| 92 | + if ($this->connected) { |
|
| 93 | 93 | $this->table_list = $this->db_get_table_list(); |
| 94 | 94 | // TODO Проверка на пустоту |
| 95 | 95 | } |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | protected function driver_connect() { |
| 104 | - if(!is_object($this->driver)) { |
|
| 104 | + if (!is_object($this->driver)) { |
|
| 105 | 105 | classSupernova::$debug->error_fatal('DB Error - No driver for MySQL found!'); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
| 108 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
| 109 | 109 | classSupernova::$debug->error_fatal('DB Error - WRONG MySQL driver!'); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | public function db_disconnect() { |
| 116 | - if($this->connected) { |
|
| 116 | + if ($this->connected) { |
|
| 117 | 117 | $this->connected = !$this->driver_disconnect(); |
| 118 | 118 | $this->connected = false; |
| 119 | 119 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function replaceTablePlaceholders($query) { |
| 130 | 130 | $sql = $query; |
| 131 | - if(strpos($sql, '{{') !== false) { |
|
| 132 | - foreach($this->table_list as $tableName) { |
|
| 133 | - $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
|
| 131 | + if (strpos($sql, '{{') !== false) { |
|
| 132 | + foreach ($this->table_list as $tableName) { |
|
| 133 | + $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param $fetch |
| 143 | 143 | */ |
| 144 | 144 | protected function logQuery($query, $fetch) { |
| 145 | - if(!classSupernova::$config->debug) { |
|
| 145 | + if (!classSupernova::$config->debug) { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $arr = debug_backtrace(); |
| 151 | 151 | $file = end(explode('/', $arr[0]['file'])); |
| 152 | 152 | $line = $arr[0]['line']; |
| 153 | - classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th> </th><th> " . ($fetch ? '+' : ' ') . " </th></tr>"); |
|
| 153 | + classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th> </th><th> ".($fetch ? '+' : ' ')." </th></tr>"); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -160,18 +160,18 @@ discard block |
||
| 160 | 160 | * @return void |
| 161 | 161 | */ |
| 162 | 162 | protected function commentQuery(&$sql) { |
| 163 | - if(!defined('DEBUG_SQL_COMMENT')) { |
|
| 163 | + if (!defined('DEBUG_SQL_COMMENT')) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | $backtrace = debug_backtrace(); |
| 167 | 167 | $sql_comment = classSupernova::$debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
| 168 | 168 | |
| 169 | - $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
|
| 170 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
| 169 | + $sql_commented = '/* '.implode("<br />", $sql_comment).'<br /> */ '.preg_replace("/\s+/", ' ', $sql); |
|
| 170 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
| 171 | 171 | classSupernova::$debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if(defined('DEBUG_SQL_ERROR')) { |
|
| 174 | + if (defined('DEBUG_SQL_ERROR')) { |
|
| 175 | 175 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
| 176 | 176 | classSupernova::$debug->add_to_array($sql_comment); |
| 177 | 177 | } |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | public function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
| 183 | - if(!is_string($table)) { |
|
| 183 | + if (!is_string($table)) { |
|
| 184 | 184 | $fetch = $table; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if(!$this->connected) { |
|
| 187 | + if (!$this->connected) { |
|
| 188 | 188 | $this->sn_db_connect(); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $sql = $this->replaceTablePlaceholders($query); |
| 197 | 197 | $this->commentQuery($sql); |
| 198 | - !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error() . "<br />$sql<br />", 'SQL Error') : false; |
|
| 198 | + !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error()."<br />$sql<br />", 'SQL Error') : false; |
|
| 199 | 199 | |
| 200 | 200 | return $fetch ? $this->db_fetch($sqlquery) : $sqlquery; |
| 201 | 201 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | protected function security_watch_user_queries($query) { |
| 206 | 206 | global $user; |
| 207 | 207 | |
| 208 | - if( |
|
| 208 | + if ( |
|
| 209 | 209 | !$this->isWatching // Not already watching |
| 210 | 210 | && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist |
| 211 | 211 | && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist |
@@ -213,11 +213,11 @@ discard block |
||
| 213 | 213 | ) { |
| 214 | 214 | $this->isWatching = true; |
| 215 | 215 | $msg = "\$query = \"{$query}\"\n\r"; |
| 216 | - if(!empty($_POST)) { |
|
| 217 | - $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
| 216 | + if (!empty($_POST)) { |
|
| 217 | + $msg .= "\n\r".dump($_POST, '$_POST'); |
|
| 218 | 218 | } |
| 219 | - if(!empty($_GET)) { |
|
| 220 | - $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
| 219 | + if (!empty($_GET)) { |
|
| 220 | + $msg .= "\n\r".dump($_GET, '$_GET'); |
|
| 221 | 221 | } |
| 222 | 222 | classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
| 223 | 223 | $this->isWatching = false; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | public function security_query_check_bad_words($query) { |
| 229 | 229 | global $user, $dm_change_legit, $mm_change_legit; |
| 230 | 230 | |
| 231 | - switch(true) { |
|
| 231 | + switch (true) { |
|
| 232 | 232 | case stripos($query, 'RUNCATE TABL') != false: |
| 233 | 233 | case stripos($query, 'ROP TABL') != false: |
| 234 | 234 | case stripos($query, 'ENAME TABL') != false: |
@@ -239,37 +239,37 @@ discard block |
||
| 239 | 239 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
| 240 | 240 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
| 241 | 241 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
| 242 | - $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
| 242 | + $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
| 243 | 243 | $report .= ">Database Inforamation\n"; |
| 244 | - $report .= "\tID - " . $user['id'] . "\n"; |
|
| 245 | - $report .= "\tUser - " . $user['username'] . "\n"; |
|
| 246 | - $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
| 247 | - $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
| 248 | - $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
| 249 | - $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
| 250 | - $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
| 251 | - $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 252 | - $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
| 253 | - $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
| 244 | + $report .= "\tID - ".$user['id']."\n"; |
|
| 245 | + $report .= "\tUser - ".$user['username']."\n"; |
|
| 246 | + $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
| 247 | + $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
| 248 | + $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
| 249 | + $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
| 250 | + $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
| 251 | + $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 252 | + $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
| 253 | + $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
| 254 | 254 | $report .= "\n"; |
| 255 | 255 | |
| 256 | 256 | $report .= ">Query Information\n"; |
| 257 | - $report .= "\tQuery - " . $query . "\n"; |
|
| 257 | + $report .= "\tQuery - ".$query."\n"; |
|
| 258 | 258 | $report .= "\n"; |
| 259 | 259 | |
| 260 | 260 | $report .= ">\$_SERVER Information\n"; |
| 261 | - $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
| 262 | - $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
| 263 | - $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 264 | - $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
| 265 | - $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
| 266 | - $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
| 267 | - $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
| 268 | - $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
| 261 | + $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
| 262 | + $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
| 263 | + $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 264 | + $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
| 265 | + $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
| 266 | + $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
| 267 | + $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
| 268 | + $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
| 269 | 269 | |
| 270 | 270 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
| 271 | 271 | |
| 272 | - $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a'); |
|
| 272 | + $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a'); |
|
| 273 | 273 | fwrite($fp, $report); |
| 274 | 274 | fclose($fp); |
| 275 | 275 | |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | $prefix_length = strlen($this->db_prefix); |
| 291 | 291 | |
| 292 | 292 | $tl = array(); |
| 293 | - while($row = $this->db_fetch($query)) { |
|
| 294 | - foreach($row as $table_name) { |
|
| 295 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
| 293 | + while ($row = $this->db_fetch($query)) { |
|
| 294 | + foreach ($row as $table_name) { |
|
| 295 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
| 296 | 296 | $table_name = substr($table_name, $prefix_length); |
| 297 | - } elseif($prefixed_only) { |
|
| 297 | + } elseif ($prefixed_only) { |
|
| 298 | 298 | continue; |
| 299 | 299 | } |
| 300 | 300 | // $table_name = str_replace($db_prefix, '', $table_name); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | $result = array(); |
| 390 | 390 | |
| 391 | 391 | $status = explode(' ', $this->driver->mysql_stat()); |
| 392 | - foreach($status as $value) { |
|
| 392 | + foreach ($status as $value) { |
|
| 393 | 393 | $row = explode(': ', $value); |
| 394 | 394 | $result[$row[0]] = $row[1]; |
| 395 | 395 | } |
@@ -405,10 +405,10 @@ discard block |
||
| 405 | 405 | $result = array(); |
| 406 | 406 | |
| 407 | 407 | $query = $this->db_sql_query('SHOW STATUS;'); |
| 408 | - if(is_bool($query)) { |
|
| 408 | + if (is_bool($query)) { |
|
| 409 | 409 | throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?'); |
| 410 | 410 | } |
| 411 | - while($row = db_fetch($query)) { |
|
| 411 | + while ($row = db_fetch($query)) { |
|
| 412 | 412 | $result[$row['Variable_name']] = $row['Value']; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -39,19 +39,19 @@ |
||
| 39 | 39 | |
| 40 | 40 | @$this->link = mysqli_connect($settings['server'], $settings['user'], $settings['pass'], $settings['name']); |
| 41 | 41 | if (!is_object($this->link) || $this->link->connect_error) { |
| 42 | - classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #' . $this->link->connect_errno, $this->link->connect_error); |
|
| 42 | + classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #'.$this->link->connect_errno, $this->link->connect_error); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | !$this->mysql_query("/*!40101 SET NAMES 'utf8' */") |
| 47 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #' . $this->link->errno, $this->link->error) |
|
| 47 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #'.$this->link->errno, $this->link->error) |
|
| 48 | 48 | : false; |
| 49 | 49 | !$this->mysql_query("SET NAMES 'utf8';") |
| 50 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #' . $this->link->errno, $this->link->error) |
|
| 50 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #'.$this->link->errno, $this->link->error) |
|
| 51 | 51 | : false; |
| 52 | 52 | |
| 53 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
| 54 | - ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #' . $this->link->errno, $this->link->error) |
|
| 53 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
| 54 | + ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #'.$this->link->errno, $this->link->error) |
|
| 55 | 55 | : false; |
| 56 | 56 | |
| 57 | 57 | $this->connected = true; |