@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +/** |
|
| 4 | + * @param double $planet_sectors |
|
| 5 | + */ |
|
| 3 | 6 | function uni_create_planet_get_density($position_data, $user_row, $planet_sectors) { |
| 4 | 7 | $density_list = sn_get_groups('planet_density'); |
| 5 | 8 | $density_min = reset($density_list); |
@@ -250,16 +250,17 @@ discard block |
||
| 250 | 250 | if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) |
| 251 | 251 | { |
| 252 | 252 | $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id'); |
| 253 | - } |
|
| 254 | - else |
|
| 253 | + } else |
|
| 255 | 254 | { |
| 256 | 255 | $planet_row = db_planet_by_id($planet_row['id']); |
| 257 | 256 | } |
| 258 | 257 | |
| 259 | 258 | // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету |
| 260 | - if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
| 259 | + if(!isset($planet_row['id'])) { |
|
| 260 | + // || $planet_row['id'] != $user['current_planet'] |
|
| 261 | 261 | { |
| 262 | 262 | $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id'); |
| 263 | + } |
|
| 263 | 264 | // Если текущей планеты не существует - выставляем Столицу |
| 264 | 265 | if(!isset($planet_row['id'])) |
| 265 | 266 | { |
@@ -301,8 +302,7 @@ discard block |
||
| 301 | 302 | if(!$from['id']) |
| 302 | 303 | { |
| 303 | 304 | $result = $lang['sys_planet_expedition']; |
| 304 | - } |
|
| 305 | - else |
|
| 305 | + } else |
|
| 306 | 306 | { |
| 307 | 307 | $from_planet_id = $include_id ? ( |
| 308 | 308 | 'ID {' . ($from['id'] ? $from['id'] : ($from[$prefix . 'planet_id'] ? $from[$prefix . 'planet_id'] : 0)) . '} ' |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $possible_cores = array(); |
| 9 | 9 | $probability = 0; |
| 10 | - foreach($density_list as $possible_core_id => $core_data) { |
|
| 11 | - if(!$core_data[UNIT_PLANET_DENSITY_RARITY]) { |
|
| 10 | + foreach ($density_list as $possible_core_id => $core_data) { |
|
| 11 | + if (!$core_data[UNIT_PLANET_DENSITY_RARITY]) { |
|
| 12 | 12 | continue; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - if( |
|
| 15 | + if ( |
|
| 16 | 16 | // Core type exists |
| 17 | 17 | in_array($possible_core_id, $position_data['core_types']) |
| 18 | 18 | // Limit core type with planet sector count |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $random = mt_rand(1, $probability); |
| 35 | 35 | $selected_core = null; |
| 36 | - foreach($possible_cores as $core_type => $core_info) { |
|
| 37 | - if($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) { |
|
| 36 | + foreach ($possible_cores as $core_type => $core_info) { |
|
| 37 | + if ($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) { |
|
| 38 | 38 | $selected_core = $core_info; |
| 39 | 39 | break; |
| 40 | 40 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $Position = intval($Position); |
| 61 | 61 | |
| 62 | - if(!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) { |
|
| 62 | + if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) { |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | $planet_generator = sn_get_groups('planet_generator'); |
| 70 | 70 | |
| 71 | - if($HomeWorld) { |
|
| 71 | + if ($HomeWorld) { |
|
| 72 | 72 | $position_data = $planet_generator[0]; |
| 73 | 73 | } else { |
| 74 | 74 | $position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position]; |
| 75 | - if($Position >= UNIVERSE_RANDOM_PLANET_START) { |
|
| 75 | + if ($Position >= UNIVERSE_RANDOM_PLANET_START) { |
|
| 76 | 76 | // Корректируем температуру для планеты-странника |
| 77 | 77 | $position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START); |
| 78 | 78 | } |
@@ -172,15 +172,15 @@ discard block |
||
| 172 | 172 | $moon_name = ''; |
| 173 | 173 | $moon_row = array(); |
| 174 | 174 | $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id'); |
| 175 | - if(!$moon['id']) { |
|
| 175 | + if (!$moon['id']) { |
|
| 176 | 176 | $moon_planet = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET, true, '`id`, `temp_min`, `temp_max`, `name`, `debris_metal`, `debris_crystal`'); |
| 177 | 177 | |
| 178 | - if($moon_planet['id']) { |
|
| 178 | + if ($moon_planet['id']) { |
|
| 179 | 179 | $base_storage_size = BASE_STORAGE_SIZE; |
| 180 | 180 | |
| 181 | - if(!$moon_chance) { |
|
| 181 | + if (!$moon_chance) { |
|
| 182 | 182 | $size = mt_rand(1100, 8999); |
| 183 | - } elseif($moon_chance <= 100) { |
|
| 183 | + } elseif ($moon_chance <= 100) { |
|
| 184 | 184 | $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999); |
| 185 | 185 | } else { |
| 186 | 186 | $size = $moon_chance; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | $field_max = ceil($size / 1000); |
| 198 | 198 | |
| 199 | - if(isset($options['image']) && $options['image']) { |
|
| 199 | + if (isset($options['image']) && $options['image']) { |
|
| 200 | 200 | $moon_image = $options['image']; |
| 201 | 201 | } else { |
| 202 | 202 | $moon_image = 'mond'; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'" |
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - if($update_debris) { |
|
| 214 | + if ($update_debris) { |
|
| 215 | 215 | $debris_spent = $moon_chance * 1000000; |
| 216 | 216 | $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100)); |
| 217 | 217 | $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $planet_row['id'] = $user['current_planet']; |
| 248 | 248 | |
| 249 | 249 | // Пытаемся переключить на новую планету |
| 250 | - if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) |
|
| 250 | + if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) |
|
| 251 | 251 | { |
| 252 | 252 | $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id'); |
| 253 | 253 | } |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету |
| 260 | - if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
| 260 | + if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
| 261 | 261 | { |
| 262 | 262 | $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id'); |
| 263 | 263 | // Если текущей планеты не существует - выставляем Столицу |
| 264 | - if(!isset($planet_row['id'])) |
|
| 264 | + if (!isset($planet_row['id'])) |
|
| 265 | 265 | { |
| 266 | 266 | $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id'); |
| 267 | 267 | // Если и столицы не существует - значит что-то очень не так с записью пользователя |
| 268 | - if(!isset($planet_row['id'])) |
|
| 268 | + if (!isset($planet_row['id'])) |
|
| 269 | 269 | { |
| 270 | 270 | global $debug; |
| 271 | 271 | $debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Если производилось переключение планеты - делаем запись в юзере |
| 277 | - if($user['current_planet'] != $planet_row['id']) |
|
| 277 | + if ($user['current_planet'] != $planet_row['id']) |
|
| 278 | 278 | { |
| 279 | 279 | db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'"); |
| 280 | 280 | $user['current_planet'] = $planet_row['id']; |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | { |
| 299 | 299 | global $lang; |
| 300 | 300 | |
| 301 | - if(!$from['id']) |
|
| 301 | + if (!$from['id']) |
|
| 302 | 302 | { |
| 303 | 303 | $result = $lang['sys_planet_expedition']; |
| 304 | 304 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | function uni_calculate_moon_chance($FleetDebris) |
| 338 | 338 | { |
| 339 | 339 | $MoonChance = $FleetDebris / 1000000; |
| 340 | - return ($MoonChance < 1) ? 0 : ($MoonChance>30 ? 30 : $MoonChance); |
|
| 340 | + return ($MoonChance < 1) ? 0 : ($MoonChance > 30 ? 30 : $MoonChance); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | function uni_coordinates_valid($coordinates, $prefix = '') |
@@ -359,23 +359,23 @@ discard block |
||
| 359 | 359 | global $lang, $config; |
| 360 | 360 | |
| 361 | 361 | try { |
| 362 | - if($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { |
|
| 362 | + if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { |
|
| 363 | 363 | throw new exception($lang['ov_teleport_err_cooldown'], ERR_ERROR); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - if(mrc_get_level($user, false, RES_DARK_MATTER) < $config->planet_teleport_cost) { |
|
| 366 | + if (mrc_get_level($user, false, RES_DARK_MATTER) < $config->planet_teleport_cost) { |
|
| 367 | 367 | throw new exception($lang['ov_teleport_err_no_dark_matter'], ERR_ERROR); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // TODO: Replace quick-check with using gathered flying fleet data |
| 371 | - if(FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) { |
|
| 371 | + if (FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) { |
|
| 372 | 372 | throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if(is_array($new_coordinates)) { |
|
| 375 | + if (is_array($new_coordinates)) { |
|
| 376 | 376 | $new_coordinates['planet_type'] = PT_PLANET; |
| 377 | 377 | $incoming = db_planet_by_vector($new_coordinates, '', true, 'id'); |
| 378 | - if($incoming['id']) { |
|
| 378 | + if ($incoming['id']) { |
|
| 379 | 379 | throw new exception($lang['ov_teleport_err_destination_busy'], ERR_ERROR); |
| 380 | 380 | } |
| 381 | 381 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | 'result' => ERR_NONE, |
| 385 | 385 | 'message' => '', |
| 386 | 386 | ); |
| 387 | - } catch(exception $e) { |
|
| 387 | + } catch (exception $e) { |
|
| 388 | 388 | $response = array( |
| 389 | 389 | 'result' => $e->getCode(), |
| 390 | 390 | 'message' => $e->getMessage(), |
@@ -11,6 +11,9 @@ discard block |
||
| 11 | 11 | require_once('general/math.php'); |
| 12 | 12 | require_once('general_pname.php'); |
| 13 | 13 | |
| 14 | +/** |
|
| 15 | + * @param string $func_name |
|
| 16 | + */ |
|
| 14 | 17 | function sn_function_call($func_name, $func_arg = array()) |
| 15 | 18 | { |
| 16 | 19 | global $functions; // All data in $functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
@@ -58,6 +61,9 @@ discard block |
||
| 58 | 61 | |
| 59 | 62 | // ---------------------------------------------------------------------------------------------------------------- |
| 60 | 63 | // Fonction de lecture / ecriture / exploitation de templates |
| 64 | +/** |
|
| 65 | + * @param string $filename |
|
| 66 | + */ |
|
| 61 | 67 | function sys_file_read($filename) |
| 62 | 68 | { |
| 63 | 69 | return @file_get_contents($filename); |
@@ -106,7 +112,7 @@ discard block |
||
| 106 | 112 | /** |
| 107 | 113 | * Получение курса обмены валюты в серверную валюту |
| 108 | 114 | * |
| 109 | - * @param $currency_symbol |
|
| 115 | + * @param string $currency_symbol |
|
| 110 | 116 | * |
| 111 | 117 | * @return float |
| 112 | 118 | */ |
@@ -143,6 +149,7 @@ discard block |
||
| 143 | 149 | null - standard result |
| 144 | 150 | true - return only style class for current params |
| 145 | 151 | false - return array('text' => $ret, 'class' => $class), where $ret - unstyled |
| 152 | + * @param boolean $style |
|
| 146 | 153 | */ |
| 147 | 154 | |
| 148 | 155 | function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) |
@@ -262,6 +269,9 @@ discard block |
||
| 262 | 269 | return preg_replace($ListCensure, '*', $String); |
| 263 | 270 | } |
| 264 | 271 | |
| 272 | +/** |
|
| 273 | + * @param string $email |
|
| 274 | + */ |
|
| 265 | 275 | function is_email($email) { |
| 266 | 276 | return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)); |
| 267 | 277 | } |
@@ -298,6 +308,9 @@ discard block |
||
| 298 | 308 | return floatval(sys_get_param($param_name, $default)); |
| 299 | 309 | } |
| 300 | 310 | |
| 311 | +/** |
|
| 312 | + * @param string $param_name |
|
| 313 | + */ |
|
| 301 | 314 | function sys_get_param_escaped($param_name, $default = '') |
| 302 | 315 | { |
| 303 | 316 | return db_escape(sys_get_param($param_name, $default)); |
@@ -542,6 +555,9 @@ discard block |
||
| 542 | 555 | } |
| 543 | 556 | |
| 544 | 557 | // Generates random string of $length symbols from $allowed_chars charset |
| 558 | +/** |
|
| 559 | + * @param string $allowed_chars |
|
| 560 | + */ |
|
| 545 | 561 | function sys_random_string($length = 16, $allowed_chars = SN_SYS_SEC_CHARS_ALLOWED) { |
| 546 | 562 | $allowed_length = strlen($allowed_chars); |
| 547 | 563 | |
@@ -667,6 +683,9 @@ discard block |
||
| 667 | 683 | return implode(';', $fleet_string); |
| 668 | 684 | } |
| 669 | 685 | |
| 686 | +/** |
|
| 687 | + * @param string $body |
|
| 688 | + */ |
|
| 670 | 689 | function mymail($email_unsafe, $title, $body, $from = '', $html = false) { |
| 671 | 690 | global $config, $lang; |
| 672 | 691 | |
@@ -954,6 +973,9 @@ discard block |
||
| 954 | 973 | return serialize($nick_array); |
| 955 | 974 | } |
| 956 | 975 | |
| 976 | +/** |
|
| 977 | + * @param string $nick_string |
|
| 978 | + */ |
|
| 957 | 979 | function player_nick_uncompact($nick_string) { |
| 958 | 980 | try { |
| 959 | 981 | $result = unserialize($nick_string); |
@@ -1237,6 +1259,9 @@ discard block |
||
| 1237 | 1259 | return $ranks; |
| 1238 | 1260 | } |
| 1239 | 1261 | |
| 1262 | +/** |
|
| 1263 | + * @param boolean $planet_id |
|
| 1264 | + */ |
|
| 1240 | 1265 | function sys_player_new_adjust($user_id, $planet_id){return sn_function_call('sys_player_new_adjust', array($user_id, $planet_id, &$result));} |
| 1241 | 1266 | function sn_sys_player_new_adjust($user_id, $planet_id, &$result) { |
| 1242 | 1267 | return $result; |
@@ -1589,6 +1614,9 @@ discard block |
||
| 1589 | 1614 | return version_compare(sn_version_compare_extra($ver1), sn_version_compare_extra($ver2)); |
| 1590 | 1615 | } |
| 1591 | 1616 | |
| 1617 | +/** |
|
| 1618 | + * @param string $name |
|
| 1619 | + */ |
|
| 1592 | 1620 | function sn_setcookie($name, $value = null, $expire = null, $path = SN_ROOT_RELATIVE, $domain = null, $secure = null, $httponly = null) { |
| 1593 | 1621 | $_COOKIE[$name] = $value; |
| 1594 | 1622 | return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); |
@@ -14,24 +14,24 @@ discard block |
||
| 14 | 14 | function sn_function_call($func_name, $func_arg = array()) { |
| 15 | 15 | global $functions; // All data in $functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
| 16 | 16 | |
| 17 | - if(is_array($functions[$func_name]) && !is_callable($functions[$func_name])) { |
|
| 17 | + if (is_array($functions[$func_name]) && !is_callable($functions[$func_name])) { |
|
| 18 | 18 | // Chain-callable functions should be made as following: |
| 19 | 19 | // 1. Never use incomplete calls with parameters "by default" |
| 20 | 20 | // 2. Reserve last parameter for cumulative result |
| 21 | 21 | // 3. Use same format for original value and cumulative result (if there is original value) |
| 22 | 22 | // 4. Honor cumulative result |
| 23 | 23 | // 5. Return cumulative result |
| 24 | - foreach($functions[$func_name] as $func_chain_name) { |
|
| 24 | + foreach ($functions[$func_name] as $func_chain_name) { |
|
| 25 | 25 | // По идее - это уже тут не нужно, потому что оно все должно быть callable к этому моменту |
| 26 | 26 | // Но для старых модулей... |
| 27 | - if(is_callable($func_chain_name)) { |
|
| 27 | + if (is_callable($func_chain_name)) { |
|
| 28 | 28 | $result = call_user_func_array($func_chain_name, $func_arg); |
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | } else { |
| 32 | 32 | // TODO: This is left for backward compatibility. Appropriate code should be rewrote! |
| 33 | 33 | $func_name = isset($functions[$func_name]) && is_callable($functions[$func_name]) ? $functions[$func_name] : ('sn_' . $func_name); |
| 34 | - if(is_callable($func_name)) { |
|
| 34 | + if (is_callable($func_name)) { |
|
| 35 | 35 | $result = call_user_func_array($func_name, $func_arg); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * @param string $page_name - имя страницы, для которого должен был быть выполнен хук |
| 47 | 47 | */ |
| 48 | 48 | function execute_hooks(&$hook_list, &$template, $hook_type = null, $page_name = null) { |
| 49 | - if(!empty($hook_list)) { |
|
| 50 | - foreach($hook_list as $hook) { |
|
| 51 | - if(is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
| 49 | + if (!empty($hook_list)) { |
|
| 50 | + foreach ($hook_list as $hook) { |
|
| 51 | + if (is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
| 52 | 52 | $template = call_user_func($hook_call, $template, $hook_type, $page_name); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) { |
| 150 | 150 | $n = floatval($n); |
| 151 | - if(is_int($floor)) { |
|
| 151 | + if (is_int($floor)) { |
|
| 152 | 152 | $n = round($n, $floor); // , PHP_ROUND_HALF_DOWN |
| 153 | - } elseif($floor === true) { |
|
| 153 | + } elseif ($floor === true) { |
|
| 154 | 154 | $n = floor($n); |
| 155 | 155 | $floor = 0; |
| 156 | 156 | } else { |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | $ret = $n; |
| 161 | 161 | |
| 162 | 162 | $suffix = ''; |
| 163 | - if($limit) { |
|
| 164 | - if($ret > 0) { |
|
| 165 | - while($ret > $limit) { |
|
| 163 | + if ($limit) { |
|
| 164 | + if ($ret > 0) { |
|
| 165 | + while ($ret > $limit) { |
|
| 166 | 166 | $suffix .= 'k'; |
| 167 | 167 | $ret = round($ret / 1000); |
| 168 | 168 | } |
| 169 | 169 | } else { |
| 170 | - while($ret < -$limit) { |
|
| 170 | + while ($ret < -$limit) { |
|
| 171 | 171 | $suffix .= 'k'; |
| 172 | 172 | $ret = round($ret / 1000); |
| 173 | 173 | } |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | $ret = number_format($ret, $floor, ',', '.'); |
| 178 | 178 | $ret .= $suffix; |
| 179 | 179 | |
| 180 | - if($color !== false) { |
|
| 181 | - if($color === true) { |
|
| 180 | + if ($color !== false) { |
|
| 181 | + if ($color === true) { |
|
| 182 | 182 | $class = $n == 0 ? 'zero' : ($n > 0 ? 'positive' : 'negative'); |
| 183 | - } elseif($color >= 0) { |
|
| 183 | + } elseif ($color >= 0) { |
|
| 184 | 184 | $class = $n == $color ? 'zero' : ($n < $color ? 'positive' : 'negative'); |
| 185 | 185 | } else { |
| 186 | 186 | $class = ($n == -$color) ? 'zero' : ($n < -$color ? 'negative' : 'positive'); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if(!isset($style)) { |
|
| 189 | + if (!isset($style)) { |
|
| 190 | 190 | $ret = "<span class='{$class}'>{$ret}</span>"; |
| 191 | 191 | } else { |
| 192 | 192 | $ret = $style ? $ret = $class : $ret = array('text' => $ret, 'class' => $class); |
@@ -311,11 +311,11 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | function sys_get_param_phone($param_name, $default = '') { |
| 313 | 313 | $phone_raw = sys_get_param_str_unsafe($param_name, $default = ''); |
| 314 | - if($phone_raw) { |
|
| 314 | + if ($phone_raw) { |
|
| 315 | 315 | $phone = $phone_raw[0] == '+' ? '+' : ''; |
| 316 | - for($i = 0; $i < strlen($phone_raw); $i++) { |
|
| 316 | + for ($i = 0; $i < strlen($phone_raw); $i++) { |
|
| 317 | 317 | $ord = ord($phone_raw[$i]); |
| 318 | - if($ord >= 48 && $ord <= 57) { |
|
| 318 | + if ($ord >= 48 && $ord <= 57) { |
|
| 319 | 319 | $phone .= $phone_raw[$i]; |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | function CheckAbandonPlanetState(&$planet) { |
| 335 | - if($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
| 335 | + if ($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
| 336 | 336 | db_planet_delete_by_id($planet['id']); |
| 337 | 337 | } |
| 338 | 338 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | global $config; |
| 342 | 342 | |
| 343 | 343 | static $rate, $sn_group_resources_all, $sn_group_resources_loot; |
| 344 | - if(!$rate) { |
|
| 344 | + if (!$rate) { |
|
| 345 | 345 | $sn_group_resources_all = sn_get_groups('resources_all'); |
| 346 | 346 | $sn_group_resources_loot = sn_get_groups('resources_loot'); |
| 347 | 347 | |
@@ -351,19 +351,19 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $unit_cost_data = get_unit_param($unit_id, 'cost'); |
| 354 | - if(!is_array($unit_cost_data)) { |
|
| 354 | + if (!is_array($unit_cost_data)) { |
|
| 355 | 355 | return array('total' => 0); |
| 356 | 356 | } |
| 357 | 357 | $factor = isset($unit_cost_data['factor']) ? $unit_cost_data['factor'] : 1; |
| 358 | 358 | $cost_array = array(BUILD_CREATE => array(), 'total' => 0); |
| 359 | 359 | $unit_level = $unit_level > 0 ? $unit_level : 0; |
| 360 | - foreach($unit_cost_data as $resource_id => $resource_amount) { |
|
| 361 | - if(!in_array($resource_id, $sn_group_resources_all)) { |
|
| 360 | + foreach ($unit_cost_data as $resource_id => $resource_amount) { |
|
| 361 | + if (!in_array($resource_id, $sn_group_resources_all)) { |
|
| 362 | 362 | continue; |
| 363 | 363 | } |
| 364 | 364 | // $cost_array[BUILD_CREATE][$resource_id] = $resource_amount * ($factor == 1 ? $unit_level : ((pow($factor, $unit_level) - $factor) / ($factor - 1))); |
| 365 | 365 | $cost_array[BUILD_CREATE][$resource_id] = round($resource_amount * ($factor == 1 ? $unit_level : ((1 - pow($factor, $unit_level)) / (1 - $factor)))); |
| 366 | - if(in_array($resource_id, $sn_group_resources_loot)) { |
|
| 366 | + if (in_array($resource_id, $sn_group_resources_loot)) { |
|
| 367 | 367 | $cost_array['total'] += $cost_array[BUILD_CREATE][$resource_id] * $rate[$resource_id]; |
| 368 | 368 | } |
| 369 | 369 | } |
@@ -438,19 +438,19 @@ discard block |
||
| 438 | 438 | $mercenary_level = 0; |
| 439 | 439 | $unit_db_name = pname_resource_name($unit_id); |
| 440 | 440 | |
| 441 | - if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
| 441 | + if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
| 442 | 442 | $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id); |
| 443 | 443 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
| 444 | - } elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
| 444 | + } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
| 445 | 445 | $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id); |
| 446 | 446 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
| 447 | - } elseif(in_array($unit_id, sn_get_groups('governors'))) { |
|
| 447 | + } elseif (in_array($unit_id, sn_get_groups('governors'))) { |
|
| 448 | 448 | $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0; |
| 449 | - } elseif($unit_id == RES_DARK_MATTER) { |
|
| 449 | + } elseif ($unit_id == RES_DARK_MATTER) { |
|
| 450 | 450 | $mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter); |
| 451 | - } elseif($unit_id == RES_METAMATTER) { |
|
| 451 | + } elseif ($unit_id == RES_METAMATTER) { |
|
| 452 | 452 | $mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name]; |
| 453 | - } elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
| 453 | + } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
| 454 | 454 | $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name]; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -460,19 +460,19 @@ discard block |
||
| 460 | 460 | function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) { return sn_function_call(__FUNCTION__, array(&$user, $planet, $mercenaries, $value)); } |
| 461 | 461 | |
| 462 | 462 | function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) { |
| 463 | - if(!is_array($mercenaries)) { |
|
| 463 | + if (!is_array($mercenaries)) { |
|
| 464 | 464 | $mercenaries = array($mercenaries); |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $base_value = isset($base_value) ? $base_value : $value; |
| 468 | 468 | |
| 469 | - foreach($mercenaries as $mercenary_id) { |
|
| 469 | + foreach ($mercenaries as $mercenary_id) { |
|
| 470 | 470 | $mercenary_level = mrc_get_level($user, $planet, $mercenary_id); |
| 471 | 471 | |
| 472 | 472 | $mercenary = get_unit_param($mercenary_id); |
| 473 | 473 | $mercenary_bonus = $mercenary['bonus']; |
| 474 | 474 | |
| 475 | - switch($mercenary['bonus_type']) { |
|
| 475 | + switch ($mercenary['bonus_type']) { |
|
| 476 | 476 | case BONUS_PERCENT_CUMULATIVE: |
| 477 | 477 | $value *= 1 + $mercenary_level * $mercenary_bonus / 100; |
| 478 | 478 | break; |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | $allowed_length = strlen($allowed_chars); |
| 504 | 504 | |
| 505 | 505 | $random_string = ''; |
| 506 | - for($i = 0; $i < $length; $i++) { |
|
| 506 | + for ($i = 0; $i < $length; $i++) { |
|
| 507 | 507 | $random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)]; |
| 508 | 508 | } |
| 509 | 509 | |
@@ -523,12 +523,12 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | $options = ''; |
| 525 | 525 | $option_list = array(); |
| 526 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
| 526 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
| 527 | 527 | $option_list[$option_group_id] = array(); |
| 528 | - foreach($option_group as $option_name => $option_value) { |
|
| 529 | - if(!isset($user[$option_name])) { |
|
| 528 | + foreach ($option_group as $option_name => $option_value) { |
|
| 529 | + if (!isset($user[$option_name])) { |
|
| 530 | 530 | $user[$option_name] = $option_value; |
| 531 | - } elseif($user[$option_name] == '') { |
|
| 531 | + } elseif ($user[$option_name] == '') { |
|
| 532 | 532 | $user[$option_name] = 0; |
| 533 | 533 | } |
| 534 | 534 | $options .= "{$option_name}^{$user[$option_name]}|"; |
@@ -548,16 +548,16 @@ discard block |
||
| 548 | 548 | $option_list = array(); |
| 549 | 549 | $option_string_list = explode('|', $user['options']); |
| 550 | 550 | |
| 551 | - foreach($option_string_list as $option_string) { |
|
| 551 | + foreach ($option_string_list as $option_string) { |
|
| 552 | 552 | list($option_name, $option_value) = explode('^', $option_string); |
| 553 | 553 | $option_list[$option_name] = $option_value; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | $final_list = array(); |
| 557 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
| 557 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
| 558 | 558 | $final_list[$option_group_id] = array(); |
| 559 | - foreach($option_group as $option_name => $option_value) { |
|
| 560 | - if(!isset($option_list[$option_name])) { |
|
| 559 | + foreach ($option_group as $option_name => $option_value) { |
|
| 560 | + if (!isset($option_list[$option_name])) { |
|
| 561 | 561 | $option_list[$option_name] = $option_value; |
| 562 | 562 | } |
| 563 | 563 | $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name]; |
@@ -571,12 +571,12 @@ discard block |
||
| 571 | 571 | |
| 572 | 572 | function sys_unit_str2arr($fleet_string) { |
| 573 | 573 | $fleet_array = array(); |
| 574 | - if(!empty($fleet_string)) { |
|
| 574 | + if (!empty($fleet_string)) { |
|
| 575 | 575 | $arrTemp = explode(';', $fleet_string); |
| 576 | - foreach($arrTemp as $temp) { |
|
| 577 | - if($temp) { |
|
| 576 | + foreach ($arrTemp as $temp) { |
|
| 577 | + if ($temp) { |
|
| 578 | 578 | $temp = explode(',', $temp); |
| 579 | - if(!empty($temp[0]) && !empty($temp[1])) { |
|
| 579 | + if (!empty($temp[0]) && !empty($temp[1])) { |
|
| 580 | 580 | $fleet_array[$temp[0]] += $temp[1]; |
| 581 | 581 | } |
| 582 | 582 | } |
@@ -588,13 +588,13 @@ discard block |
||
| 588 | 588 | |
| 589 | 589 | function sys_unit_arr2str($unit_list) { |
| 590 | 590 | $fleet_string = array(); |
| 591 | - if(isset($unit_list)) { |
|
| 592 | - if(!is_array($unit_list)) { |
|
| 591 | + if (isset($unit_list)) { |
|
| 592 | + if (!is_array($unit_list)) { |
|
| 593 | 593 | $unit_list = array($unit_list => 1); |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - foreach($unit_list as $unit_id => $unit_count) { |
|
| 597 | - if($unit_id && $unit_count) { |
|
| 596 | + foreach ($unit_list as $unit_id => $unit_count) { |
|
| 597 | + if ($unit_id && $unit_count) { |
|
| 598 | 598 | $fleet_string[] = "{$unit_id},{$unit_count}"; |
| 599 | 599 | } |
| 600 | 600 | } |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | $body = str_replace("\r\n", "\n", $body); |
| 622 | 622 | $body = str_replace("\n", "\r\n", $body); |
| 623 | 623 | |
| 624 | - if($html) { |
|
| 624 | + if ($html) { |
|
| 625 | 625 | $body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>'; |
| 626 | 626 | } |
| 627 | 627 | |
@@ -665,21 +665,21 @@ discard block |
||
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | function sn_ali_fill_user_ally(&$user) { |
| 668 | - if(!$user['ally_id']) { |
|
| 668 | + if (!$user['ally_id']) { |
|
| 669 | 669 | return; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if(!isset($user['ally'])) { |
|
| 672 | + if (!isset($user['ally'])) { |
|
| 673 | 673 | $user['ally'] = db_ally_get_by_id($user['ally_id']); |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - if(!isset($user['ally']['player'])) { |
|
| 676 | + if (!isset($user['ally']['player'])) { |
|
| 677 | 677 | $user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false); |
| 678 | 678 | } |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | function sn_get_url_contents($url) { |
| 682 | - if(function_exists('curl_init')) { |
|
| 682 | + if (function_exists('curl_init')) { |
|
| 683 | 683 | $crl = curl_init(); |
| 684 | 684 | $timeout = 5; |
| 685 | 685 | curl_setopt($crl, CURLOPT_URL, $url); |
@@ -714,10 +714,10 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | function get_ship_data($ship_id, $user) { |
| 716 | 716 | $ship_data = array(); |
| 717 | - if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
| 718 | - foreach(get_unit_param($ship_id, 'engine') as $engine_info) { |
|
| 717 | + if (in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
| 718 | + foreach (get_unit_param($ship_id, 'engine') as $engine_info) { |
|
| 719 | 719 | $tech_level = intval(mrc_get_level($user, false, $engine_info['tech'])); |
| 720 | - if(empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
| 720 | + if (empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
| 721 | 721 | $ship_data = $engine_info; |
| 722 | 722 | $ship_data['tech_level'] = $tech_level; |
| 723 | 723 | } |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | return $ship_data; |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | -if(!function_exists('strptime')) { |
|
| 732 | +if (!function_exists('strptime')) { |
|
| 733 | 733 | function strptime($date, $format) { |
| 734 | 734 | $masks = array( |
| 735 | 735 | '%d' => '(?P<d>[0-9]{2})', |
@@ -742,12 +742,12 @@ discard block |
||
| 742 | 742 | ); |
| 743 | 743 | |
| 744 | 744 | $rexep = "#" . strtr(preg_quote($format), $masks) . "#"; |
| 745 | - if(preg_match($rexep, $date, $out)) { |
|
| 745 | + if (preg_match($rexep, $date, $out)) { |
|
| 746 | 746 | $ret = array( |
| 747 | - "tm_sec" => (int)$out['S'], |
|
| 748 | - "tm_min" => (int)$out['M'], |
|
| 749 | - "tm_hour" => (int)$out['H'], |
|
| 750 | - "tm_mday" => (int)$out['d'], |
|
| 747 | + "tm_sec" => (int) $out['S'], |
|
| 748 | + "tm_min" => (int) $out['M'], |
|
| 749 | + "tm_hour" => (int) $out['H'], |
|
| 750 | + "tm_mday" => (int) $out['d'], |
|
| 751 | 751 | "tm_mon" => $out['m'] ? $out['m'] - 1 : 0, |
| 752 | 752 | "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0, |
| 753 | 753 | ); |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | function sn_sys_sector_buy($redirect = 'overview.php') { |
| 763 | 763 | global $lang, $user, $planetrow; |
| 764 | 764 | |
| 765 | - if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
| 765 | + if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
| 766 | 766 | return; |
| 767 | 767 | } |
| 768 | 768 | |
@@ -775,9 +775,9 @@ discard block |
||
| 775 | 775 | // $planetrow = $planetrow['planet']; |
| 776 | 776 | $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); |
| 777 | 777 | $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; |
| 778 | - if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
| 778 | + if ($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
| 779 | 779 | $planet_name_text = uni_render_planet($planetrow); |
| 780 | - if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf($lang['sys_sector_purchase_log'], |
|
| 780 | + if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf($lang['sys_sector_purchase_log'], |
|
| 781 | 781 | $user['username'], $user['id'], $planet_name_text, $lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost) |
| 782 | 782 | )) { |
| 783 | 783 | $sector_db_name = pname_resource_name(UNIT_SECTOR); |
@@ -792,30 +792,30 @@ discard block |
||
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') { |
| 795 | - if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
| 796 | - foreach($handler_list as $function_name => $function_data) { |
|
| 797 | - if(is_string($function_data)) { |
|
| 795 | + if (isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
| 796 | + foreach ($handler_list as $function_name => $function_data) { |
|
| 797 | + if (is_string($function_data)) { |
|
| 798 | 798 | $override_with = &$function_data; |
| 799 | - } elseif(isset($function_data['callable'])) { |
|
| 799 | + } elseif (isset($function_data['callable'])) { |
|
| 800 | 800 | $override_with = &$function_data['callable']; |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | $overwrite = $override_with[0] == '*'; |
| 804 | - if($overwrite) { |
|
| 804 | + if ($overwrite) { |
|
| 805 | 805 | $override_with = substr($override_with, 1); |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - if(($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
| 808 | + if (($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
| 809 | 809 | $override_with = array($class_module_name, $override_with); |
| 810 | - } elseif($point_position == 0) { |
|
| 810 | + } elseif ($point_position == 0) { |
|
| 811 | 811 | $override_with = substr($override_with, 1); |
| 812 | - } elseif($point_position > 0) { |
|
| 812 | + } elseif ($point_position > 0) { |
|
| 813 | 813 | $override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1)); |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | - if($overwrite) { |
|
| 816 | + if ($overwrite) { |
|
| 817 | 817 | $functions[$function_name] = array(); |
| 818 | - } elseif(!isset($functions[$function_name])) { |
|
| 818 | + } elseif (!isset($functions[$function_name])) { |
|
| 819 | 819 | $functions[$function_name] = array(); |
| 820 | 820 | $sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : ''); |
| 821 | 821 | //if(is_callable($sn_function_name)) |
@@ -834,15 +834,15 @@ discard block |
||
| 834 | 834 | function player_nick_render_to_html($result, $options = false) { |
| 835 | 835 | // TODO - обрабатывать разные случаи: $user, $render_nick_array, $string |
| 836 | 836 | |
| 837 | - if(is_string($result) && strpos($result, ':{i:')) { |
|
| 837 | + if (is_string($result) && strpos($result, ':{i:')) { |
|
| 838 | 838 | $result = player_nick_uncompact($result); |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - if(is_array($result)) { |
|
| 842 | - if(isset($result['id'])) { |
|
| 841 | + if (is_array($result)) { |
|
| 842 | + if (isset($result['id'])) { |
|
| 843 | 843 | $result = player_nick_render_current_to_array($result, $options); |
| 844 | 844 | } |
| 845 | - if(!isset($result[NICK_HTML])) { |
|
| 845 | + if (!isset($result[NICK_HTML])) { |
|
| 846 | 846 | $result = player_nick_render_array_to_html($result); |
| 847 | 847 | } |
| 848 | 848 | unset($result[NICK_HTML]); |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | try { |
| 866 | 866 | $result = unserialize($nick_string); |
| 867 | 867 | // ksort($result); // Всегда ksort-ый в player_nick_compact() |
| 868 | - } catch(exception $e) { |
|
| 868 | + } catch (exception $e) { |
|
| 869 | 869 | $result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example |
| 870 | 870 | } |
| 871 | 871 | |
@@ -878,20 +878,20 @@ discard block |
||
| 878 | 878 | global $config, $user; |
| 879 | 879 | |
| 880 | 880 | // ALL STRING ARE UNSAFE!!! |
| 881 | - if(isset($nick_array[NICK_BIRTHSDAY])) { |
|
| 881 | + if (isset($nick_array[NICK_BIRTHSDAY])) { |
|
| 882 | 882 | $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />'; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - if(isset($nick_array[NICK_VACATION])) { |
|
| 885 | + if (isset($nick_array[NICK_VACATION])) { |
|
| 886 | 886 | $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />'; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - if(isset($nick_array[NICK_GENDER])) { |
|
| 889 | + if (isset($nick_array[NICK_GENDER])) { |
|
| 890 | 890 | $result[NICK_GENDER] = '<img src="' . ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />'; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
| 894 | - switch($nick_array[NICK_AUTH_LEVEL]) { |
|
| 893 | + if (isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
| 894 | + switch ($nick_array[NICK_AUTH_LEVEL]) { |
|
| 895 | 895 | case 4: |
| 896 | 896 | $highlight = $config->chat_highlight_developer; |
| 897 | 897 | break; |
@@ -912,20 +912,20 @@ discard block |
||
| 912 | 912 | $highlight = isset($nick_array[NICK_PREMIUM]) ? $config->chat_highlight_premium : ''; |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - if($highlight) { |
|
| 915 | + if ($highlight) { |
|
| 916 | 916 | list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight); |
| 917 | 917 | } |
| 918 | 918 | // $result = preg_replace("#(.+)#", $highlight, $result); |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - if(isset($nick_array[NICK_CLASS])) { |
|
| 921 | + if (isset($nick_array[NICK_CLASS])) { |
|
| 922 | 922 | $result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>'; |
| 923 | 923 | $result[NICK_CLASS_END] = '</span>'; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | $result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]); |
| 927 | 927 | |
| 928 | - if(isset($nick_array[NICK_ALLY])) { |
|
| 928 | + if (isset($nick_array[NICK_ALLY])) { |
|
| 929 | 929 | $result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']'; |
| 930 | 930 | } |
| 931 | 931 | |
@@ -949,32 +949,32 @@ discard block |
||
| 949 | 949 | */ |
| 950 | 950 | |
| 951 | 951 | |
| 952 | - if($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
| 952 | + if ($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
| 953 | 953 | $result[NICK_BIRTHSDAY] = ''; |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | - if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
| 956 | + if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
| 957 | 957 | $result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male'); |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
| 960 | + if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
| 961 | 961 | $result[NICK_VACATION] = $render_user['vacation']; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | - if($options === true || (isset($options['color']) && $options['color'])) { |
|
| 965 | - if($user_auth_level = $render_user['authlevel']) { |
|
| 964 | + if ($options === true || (isset($options['color']) && $options['color'])) { |
|
| 965 | + if ($user_auth_level = $render_user['authlevel']) { |
|
| 966 | 966 | $result[NICK_AUTH_LEVEL] = $user_auth_level; |
| 967 | 967 | } |
| 968 | - if($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) { |
|
| 968 | + if ($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) { |
|
| 969 | 969 | $result[NICK_PREMIUM] = $user_premium; |
| 970 | 970 | } |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | - if((isset($options['class']) && $options['class'])) { |
|
| 973 | + if ((isset($options['class']) && $options['class'])) { |
|
| 974 | 974 | $result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class']; |
| 975 | 975 | } |
| 976 | 976 | |
| 977 | - if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
| 977 | + if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
| 978 | 978 | $result[NICK_ALLY] = $render_user['ally_tag']; |
| 979 | 979 | } |
| 980 | 980 | |
@@ -992,25 +992,25 @@ discard block |
||
| 992 | 992 | |
| 993 | 993 | $user_skip_list = array(); |
| 994 | 994 | |
| 995 | - if($config->stats_hide_admins) { |
|
| 995 | + if ($config->stats_hide_admins) { |
|
| 996 | 996 | $user_skip_list[] = '`authlevel` > 0'; |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | - if($config->stats_hide_player_list) { |
|
| 999 | + if ($config->stats_hide_player_list) { |
|
| 1000 | 1000 | $temp = explode(',', $config->stats_hide_player_list); |
| 1001 | - foreach($temp as $user_id) { |
|
| 1001 | + foreach ($temp as $user_id) { |
|
| 1002 | 1002 | $user_id = floatval($user_id); |
| 1003 | - if($user_id) { |
|
| 1003 | + if ($user_id) { |
|
| 1004 | 1004 | $user_skip_list[] = '`id` = ' . $user_id; |
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if(!empty($user_skip_list)) { |
|
| 1009 | + if (!empty($user_skip_list)) { |
|
| 1010 | 1010 | $user_skip_list = implode(' OR ', $user_skip_list); |
| 1011 | 1011 | $user_skip_query = db_user_list($user_skip_list); |
| 1012 | - if(!empty($user_skip_query)) { |
|
| 1013 | - foreach($user_skip_query as $user_skip_row) { |
|
| 1012 | + if (!empty($user_skip_query)) { |
|
| 1013 | + foreach ($user_skip_query as $user_skip_row) { |
|
| 1014 | 1014 | $result[$user_skip_row['id']] = $user_skip_row['id']; |
| 1015 | 1015 | } |
| 1016 | 1016 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | |
| 1042 | 1042 | function sn_sn_get_groups($groups, &$result) { |
| 1043 | 1043 | $result = is_array($result) ? $result : array(); |
| 1044 | - foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
| 1044 | + foreach ($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
| 1045 | 1045 | $result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array(); |
| 1046 | 1046 | } |
| 1047 | 1047 | |
@@ -1069,8 +1069,8 @@ discard block |
||
| 1069 | 1069 | $sn_data_unit = get_unit_param($unit_id); |
| 1070 | 1070 | |
| 1071 | 1071 | $result = is_array($result) ? $result : array(); |
| 1072 | - if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) { |
|
| 1073 | - foreach($sn_data_unit[$field] as $require_id => $require_level) { |
|
| 1072 | + if ($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) { |
|
| 1073 | + foreach ($sn_data_unit[$field] as $require_id => $require_level) { |
|
| 1074 | 1074 | $level_got = mrc_get_level($user, $planetrow, $require_id); |
| 1075 | 1075 | $level_basic = mrc_get_level($user, $planetrow, $require_id, false, true); |
| 1076 | 1076 | $result[] = array( |
@@ -1094,16 +1094,16 @@ discard block |
||
| 1094 | 1094 | |
| 1095 | 1095 | $ranks = array(); |
| 1096 | 1096 | |
| 1097 | - if($ally['ranklist']) { |
|
| 1097 | + if ($ally['ranklist']) { |
|
| 1098 | 1098 | $str_ranks = explode(';', $ally['ranklist']); |
| 1099 | - foreach($str_ranks as $str_rank) { |
|
| 1100 | - if(!$str_rank) { |
|
| 1099 | + foreach ($str_ranks as $str_rank) { |
|
| 1100 | + if (!$str_rank) { |
|
| 1101 | 1101 | continue; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | $tmp = explode(',', $str_rank); |
| 1105 | 1105 | $rank_id = count($ranks); |
| 1106 | - foreach($ally_rights as $key => $value) { |
|
| 1106 | + foreach ($ally_rights as $key => $value) { |
|
| 1107 | 1107 | $ranks[$rank_id][$value] = $tmp[$key]; |
| 1108 | 1108 | } |
| 1109 | 1109 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | function array_merge_recursive_numeric($array1, $array2) { |
| 1122 | - if(!empty($array2) && is_array($array2)) { |
|
| 1123 | - foreach($array2 as $key => $value) { |
|
| 1122 | + if (!empty($array2) && is_array($array2)) { |
|
| 1123 | + foreach ($array2 as $key => $value) { |
|
| 1124 | 1124 | // if(!isset($array1[$key]) || !is_array($array1[$key])) { |
| 1125 | 1125 | // $array1[$key] = $value; |
| 1126 | 1126 | // } else { |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | |
| 1136 | 1136 | function sn_sys_array_cumulative_sum(&$array) { |
| 1137 | 1137 | $accum = 0; |
| 1138 | - foreach($array as &$value) { |
|
| 1138 | + foreach ($array as &$value) { |
|
| 1139 | 1139 | $accum += $value; |
| 1140 | 1140 | $value = $accum; |
| 1141 | 1141 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | $sn_data_density = sn_get_groups('planet_density'); |
| 1146 | 1146 | $density_price_chart = array(); |
| 1147 | 1147 | |
| 1148 | - foreach($sn_data_density as $density_id => $density_data) { |
|
| 1148 | + foreach ($sn_data_density as $density_id => $density_data) { |
|
| 1149 | 1149 | // Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра |
| 1150 | 1150 | $density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false; |
| 1151 | 1151 | } |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | |
| 1154 | 1154 | $total_rarity = array_sum($density_price_chart); |
| 1155 | 1155 | |
| 1156 | - foreach($density_price_chart as &$density_data) { |
|
| 1156 | + foreach ($density_price_chart as &$density_data) { |
|
| 1157 | 1157 | $density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE); |
| 1158 | 1158 | } |
| 1159 | 1159 | |
@@ -1161,18 +1161,18 @@ discard block |
||
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | function sn_sys_planet_core_transmute(&$user, &$planetrow) { |
| 1164 | - if(!sys_get_param_str('transmute')) { |
|
| 1164 | + if (!sys_get_param_str('transmute')) { |
|
| 1165 | 1165 | return array(); |
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | global $lang; |
| 1169 | 1169 | |
| 1170 | 1170 | try { |
| 1171 | - if($planetrow['planet_type'] != PT_PLANET) { |
|
| 1171 | + if ($planetrow['planet_type'] != PT_PLANET) { |
|
| 1172 | 1172 | throw new exception($lang['ov_core_err_not_a_planet'], ERR_ERROR); |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | - if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
| 1175 | + if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
| 1176 | 1176 | throw new exception($lang['ov_core_err_same_density'], ERR_WARNING); |
| 1177 | 1177 | } |
| 1178 | 1178 | |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | $planet_density_index = $planetrow['density_index']; |
| 1187 | 1187 | |
| 1188 | 1188 | $density_price_chart = planet_density_price_chart($planetrow); |
| 1189 | - if(!isset($density_price_chart[$new_density_index])) { |
|
| 1189 | + if (!isset($density_price_chart[$new_density_index])) { |
|
| 1190 | 1190 | // Hack attempt |
| 1191 | 1191 | throw new exception($lang['ov_core_err_denisty_type_wrong'], ERR_ERROR); |
| 1192 | 1192 | } |
@@ -1195,13 +1195,13 @@ discard block |
||
| 1195 | 1195 | // $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost'); |
| 1196 | 1196 | // $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index]; |
| 1197 | 1197 | $transmute_cost = $density_price_chart[$new_density_index]; |
| 1198 | - if($user_dark_matter < $transmute_cost) { |
|
| 1198 | + if ($user_dark_matter < $transmute_cost) { |
|
| 1199 | 1199 | throw new exception($lang['ov_core_err_no_dark_matter'], ERR_ERROR); |
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | $sn_data_planet_density = sn_get_groups('planet_density'); |
| 1203 | - foreach($sn_data_planet_density as $key => $value) { |
|
| 1204 | - if($key == $new_density_index) { |
|
| 1203 | + foreach ($sn_data_planet_density as $key => $value) { |
|
| 1204 | + if ($key == $new_density_index) { |
|
| 1205 | 1205 | break; |
| 1206 | 1206 | } |
| 1207 | 1207 | $prev_density_index = $key; |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | 'STATUS' => ERR_NONE, |
| 1233 | 1233 | 'MESSAGE' => sprintf($lang['ov_core_err_none'], $lang['uni_planet_density_types'][$planet_density_index], $lang['uni_planet_density_types'][$new_density_index], $new_density), |
| 1234 | 1234 | ); |
| 1235 | - } catch(exception $e) { |
|
| 1235 | + } catch (exception $e) { |
|
| 1236 | 1236 | sn_db_transaction_rollback(); |
| 1237 | 1237 | $result = array( |
| 1238 | 1238 | 'STATUS' => $e->getCode(), |
@@ -1247,8 +1247,8 @@ discard block |
||
| 1247 | 1247 | global $sn_module_list; |
| 1248 | 1248 | |
| 1249 | 1249 | $active_modules = 0; |
| 1250 | - if(isset($sn_module_list[$group]) && is_array($sn_module_list[$group])) { |
|
| 1251 | - foreach($sn_module_list[$group] as $payment_module) { |
|
| 1250 | + if (isset($sn_module_list[$group]) && is_array($sn_module_list[$group])) { |
|
| 1251 | + foreach ($sn_module_list[$group] as $payment_module) { |
|
| 1252 | 1252 | $active_modules += $payment_module->manifest['active']; |
| 1253 | 1253 | } |
| 1254 | 1254 | } |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | function get_resource_exchange() { |
| 1260 | 1260 | static $rates; |
| 1261 | 1261 | |
| 1262 | - if(!$rates) { |
|
| 1262 | + if (!$rates) { |
|
| 1263 | 1263 | global $config; |
| 1264 | 1264 | |
| 1265 | 1265 | $rates = array( |
@@ -1269,7 +1269,7 @@ discard block |
||
| 1269 | 1269 | RES_DARK_MATTER => 'rpg_exchange_darkMatter', |
| 1270 | 1270 | ); |
| 1271 | 1271 | |
| 1272 | - foreach($rates as &$rate) { |
|
| 1272 | + foreach ($rates as &$rate) { |
|
| 1273 | 1273 | $rate = $config->$rate; |
| 1274 | 1274 | } |
| 1275 | 1275 | } |
@@ -1280,12 +1280,12 @@ discard block |
||
| 1280 | 1280 | function get_unit_cost_in(&$cost, $in_resource = RES_METAL) { |
| 1281 | 1281 | static $rates; |
| 1282 | 1282 | |
| 1283 | - if(!$rates) { |
|
| 1283 | + if (!$rates) { |
|
| 1284 | 1284 | $rates = get_resource_exchange(); |
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | 1287 | $metal_cost = 0; |
| 1288 | - foreach($cost as $resource_id => $resource_value) { |
|
| 1288 | + foreach ($cost as $resource_id => $resource_value) { |
|
| 1289 | 1289 | $metal_cost += $rates[$resource_id] * $resource_value; |
| 1290 | 1290 | } |
| 1291 | 1291 | |
@@ -1295,8 +1295,8 @@ discard block |
||
| 1295 | 1295 | function get_player_max_expeditons(&$user, $astrotech = -1) { return sn_function_call(__FUNCTION__, array(&$user, $astrotech, &$result)); } |
| 1296 | 1296 | |
| 1297 | 1297 | function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) { |
| 1298 | - if($astrotech == -1) { |
|
| 1299 | - if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
| 1298 | + if ($astrotech == -1) { |
|
| 1299 | + if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
| 1300 | 1300 | $astrotech = mrc_get_level($user, false, TECH_ASTROTECH); |
| 1301 | 1301 | $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0; |
| 1302 | 1302 | } |
@@ -1314,8 +1314,8 @@ discard block |
||
| 1314 | 1314 | function get_player_max_colonies(&$user, $astrotech = -1) { |
| 1315 | 1315 | global $config; |
| 1316 | 1316 | |
| 1317 | - if($astrotech == -1) { |
|
| 1318 | - if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
| 1317 | + if ($astrotech == -1) { |
|
| 1318 | + if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
| 1319 | 1319 | |
| 1320 | 1320 | $expeditions = get_player_max_expeditons($user); |
| 1321 | 1321 | $astrotech = mrc_get_level($user, false, TECH_ASTROTECH); |
@@ -1360,10 +1360,10 @@ discard block |
||
| 1360 | 1360 | |
| 1361 | 1361 | // pdump($powerup_unit, '$powerup_unit'); |
| 1362 | 1362 | $level_current = $term_original = $time_left = 0; |
| 1363 | - if($is_upgrade) { |
|
| 1363 | + if ($is_upgrade) { |
|
| 1364 | 1364 | $time_finish = strtotime($powerup_unit['unit_time_finish']); |
| 1365 | 1365 | $time_left = max(0, $time_finish - SN_TIME_NOW); |
| 1366 | - if($time_left > 0) { |
|
| 1366 | + if ($time_left > 0) { |
|
| 1367 | 1367 | $term_original = $time_finish - strtotime($powerup_unit['unit_time_start']); |
| 1368 | 1368 | $level_current = $powerup_unit['unit_level']; |
| 1369 | 1369 | } |
@@ -1371,22 +1371,22 @@ discard block |
||
| 1371 | 1371 | |
| 1372 | 1372 | $level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK]; |
| 1373 | 1373 | $original_cost = 0; |
| 1374 | - for($i = 1; $i <= $level_max; $i++) { |
|
| 1374 | + for ($i = 1; $i <= $level_max; $i++) { |
|
| 1375 | 1375 | $base_cost = eco_get_total_cost($powerup_id, $i); |
| 1376 | 1376 | $base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER]; |
| 1377 | - foreach($sn_powerup_buy_discounts as $period => $discount) { |
|
| 1377 | + foreach ($sn_powerup_buy_discounts as $period => $discount) { |
|
| 1378 | 1378 | $upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH); |
| 1379 | 1379 | $result[$i][$period] = $upgrade_price; |
| 1380 | 1380 | $original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost; |
| 1381 | 1381 | } |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if($is_upgrade && $time_left) { |
|
| 1384 | + if ($is_upgrade && $time_left) { |
|
| 1385 | 1385 | $term_original = round($term_original / PERIOD_DAY); |
| 1386 | 1386 | $time_left = min(floor($time_left / PERIOD_DAY), $term_original); |
| 1387 | 1387 | $cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0; |
| 1388 | 1388 | |
| 1389 | - array_walk_recursive($result, function (&$value) use ($cost_left) { |
|
| 1389 | + array_walk_recursive($result, function(&$value) use ($cost_left) { |
|
| 1390 | 1390 | $value -= $cost_left; |
| 1391 | 1391 | }); |
| 1392 | 1392 | } |
@@ -1444,7 +1444,7 @@ discard block |
||
| 1444 | 1444 | |
| 1445 | 1445 | function print_rr($var, $capture = false) { |
| 1446 | 1446 | $print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>'; |
| 1447 | - if($capture) { |
|
| 1447 | + if ($capture) { |
|
| 1448 | 1448 | return $print; |
| 1449 | 1449 | } else { |
| 1450 | 1450 | print($print); |
@@ -37,11 +37,11 @@ |
||
| 37 | 37 | /** |
| 38 | 38 | * @param float $range_start - Начало диапазона |
| 39 | 39 | * @param float $range_end - Конец диапазона |
| 40 | - * @param bool|int $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд |
|
| 40 | + * @param boolean $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд |
|
| 41 | 41 | * @param int $strict - В сколько сигм надо уложить результат |
| 42 | 42 | * @param bool|false $cut_extreme - надо ли обрезать крайние значения. Например, при $strict = 2 их слишком много |
| 43 | 43 | * |
| 44 | - * @return float|int |
|
| 44 | + * @return double |
|
| 45 | 45 | */ |
| 46 | 46 | function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
| 47 | 47 | if($cut_extreme) { |
@@ -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,47 +103,47 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | function linear_calc(&$linear, $from = 0, $debug = 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($debug) pdump($linear, 'Нормализовано по х' . $from); |
|
| 114 | + if ($debug) 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($debug) pdump($linear, 'Подставили х' . $from); |
|
| 124 | + if ($debug) 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, $debug); |
| 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($debug) pdump($linear, 'Подставили обратно х' . $from); |
|
| 141 | + if ($debug) pdump($linear, 'Подставили обратно х' . $from); |
|
| 142 | 142 | } |
| 143 | 143 | else |
| 144 | 144 | { |
| 145 | - if($debug) pdump($linear, 'Результат' . $from); |
|
| 146 | - foreach($linear as $index => &$eq) |
|
| 145 | + if ($debug) pdump($linear, 'Результат' . $from); |
|
| 146 | + foreach ($linear as $index => &$eq) |
|
| 147 | 147 | { |
| 148 | 148 | pdump($eq[count($linear)], 'x' . $index); |
| 149 | 149 | } |
@@ -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($debug) pdump($linear, 'Нормализовано по х' . $from); |
|
| 113 | + if($debug) { |
|
| 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($debug) pdump($linear, 'Подставили х' . $from); |
|
| 125 | + if($debug) { |
|
| 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($debug) pdump($linear, 'Подставили обратно х' . $from); |
|
| 142 | - } |
|
| 143 | - else |
|
| 144 | + if($debug) { |
|
| 145 | + pdump($linear, 'Подставили обратно х' . $from); |
|
| 146 | + } |
|
| 147 | + } else |
|
| 144 | 148 | { |
| 145 | - if($debug) pdump($linear, 'Результат' . $from); |
|
| 149 | + if($debug) { |
|
| 150 | + pdump($linear, 'Результат' . $from); |
|
| 151 | + } |
|
| 146 | 152 | foreach($linear as $index => &$eq) |
| 147 | 153 | { |
| 148 | 154 | pdump($eq[count($linear)], 'x' . $index); |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +/** |
|
| 4 | + * @return double |
|
| 5 | + */ |
|
| 3 | 6 | function flt_fleet_speed($user, $fleet) |
| 4 | 7 | { |
| 5 | 8 | if (!is_array($fleet)) |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function flt_fleet_speed($user, $fleet) { |
| 4 | - if(!is_array($fleet)) { |
|
| 4 | + if (!is_array($fleet)) { |
|
| 5 | 5 | $fleet = array($fleet => 1); |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | $speeds = array(); |
| 9 | - if(!empty($fleet)) { |
|
| 10 | - foreach($fleet as $ship_id => $amount) { |
|
| 11 | - if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
| 9 | + if (!empty($fleet)) { |
|
| 10 | + foreach ($fleet as $ship_id => $amount) { |
|
| 11 | + if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
| 12 | 12 | $single_ship_data = get_ship_data($ship_id, $user); |
| 13 | 13 | $speeds[] = $single_ship_data['speed']; |
| 14 | 14 | } |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | function flt_travel_distance($from, $to) { |
| 22 | 22 | global $config; |
| 23 | 23 | |
| 24 | - if($from['galaxy'] != $to['galaxy']) { |
|
| 24 | + if ($from['galaxy'] != $to['galaxy']) { |
|
| 25 | 25 | $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance; |
| 26 | - } elseif($from['system'] != $to['system']) { |
|
| 26 | + } elseif ($from['system'] != $to['system']) { |
|
| 27 | 27 | $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700; |
| 28 | - } elseif($from['planet'] != $to['planet']) { |
|
| 28 | + } elseif ($from['planet'] != $to['planet']) { |
|
| 29 | 29 | $distance = abs($from['planet'] - $to['planet']) * 5 + 1000; |
| 30 | 30 | } else { |
| 31 | 31 | $distance = 5; |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $game_fleet_speed = flt_server_flight_speed_multiplier(); |
| 54 | 54 | $fleet_speed = flt_fleet_speed($user_row, $fleet_array); |
| 55 | - if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { |
|
| 55 | + if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { |
|
| 56 | 56 | $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10; |
| 57 | 57 | $real_speed = $speed_percent * sqrt($fleet_speed); |
| 58 | 58 | |
| 59 | 59 | $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed)); |
| 60 | 60 | |
| 61 | - foreach($fleet_array as $ship_id => $ship_count) { |
|
| 62 | - if(!$ship_id || !$ship_count) { |
|
| 61 | + foreach ($fleet_array as $ship_id => $ship_count) { |
|
| 62 | + if (!$ship_id || !$ship_count) { |
|
| 63 | 63 | continue; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $config_bashing_attacks = $config->fleet_bashing_attacks; |
| 91 | 91 | $config_bashing_interval = $config->fleet_bashing_interval; |
| 92 | - if(!$config_bashing_attacks) { |
|
| 92 | + if (!$config_bashing_attacks) { |
|
| 93 | 93 | // Bashing allowed - protection disabled |
| 94 | 94 | return ATTACK_ALLOWED; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $bashing_result = ATTACK_BASHING; |
| 98 | - if($user['ally_id'] && $enemy['ally_id']) { |
|
| 98 | + if ($user['ally_id'] && $enemy['ally_id']) { |
|
| 99 | 99 | $relations = ali_relations($user['ally_id'], $enemy['ally_id']); |
| 100 | - if(!empty($relations)) { |
|
| 100 | + if (!empty($relations)) { |
|
| 101 | 101 | $relations = $relations[$enemy['ally_id']]; |
| 102 | - switch($relations['alliance_diplomacy_relation']) { |
|
| 102 | + switch ($relations['alliance_diplomacy_relation']) { |
|
| 103 | 103 | case ALLY_DIPLOMACY_WAR: |
| 104 | - if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
| 104 | + if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
| 105 | 105 | $bashing_result = ATTACK_BASHING_WAR_DELAY; |
| 106 | 106 | } else { |
| 107 | 107 | return ATTACK_ALLOWED; |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | // Retrieving flying fleets |
| 125 | 125 | $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst); |
| 126 | - foreach($objFleetsBashing->_container as $fleetBashing) { |
|
| 126 | + foreach ($objFleetsBashing->_container as $fleetBashing) { |
|
| 127 | 127 | // Checking for ACS - each ACS count only once |
| 128 | - if($fleetBashing->group_id) { |
|
| 128 | + if ($fleetBashing->group_id) { |
|
| 129 | 129 | $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target; |
| 130 | 130 | } else { |
| 131 | 131 | $bashing_list[] = $fleetBashing->time_arrive_to_target; |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Check for joining to ACS - if there are already fleets in ACS no checks should be done |
| 136 | - if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
| 136 | + if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
| 137 | 137 | return ATTACK_ALLOWED; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $query = db_bashing_list_get($user, $planet_dst, $time_limit); |
| 141 | - while($bashing_row = db_fetch($query)) { |
|
| 141 | + while ($bashing_row = db_fetch($query)) { |
|
| 142 | 142 | $bashing_list[] = $bashing_row['bashing_time']; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | $last_attack = 0; |
| 148 | 148 | $wave = 0; |
| 149 | 149 | $attack = 1; |
| 150 | - foreach($bashing_list as &$bash_time) { |
|
| 150 | + foreach ($bashing_list as &$bash_time) { |
|
| 151 | 151 | $attack++; |
| 152 | - if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
| 152 | + if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
| 153 | 153 | $attack = 1; |
| 154 | 154 | $wave++; |
| 155 | 155 | } |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | //TODO: try..catch |
| 167 | 167 | global $config, $user; |
| 168 | 168 | |
| 169 | - if($user['vacation']) { |
|
| 169 | + if ($user['vacation']) { |
|
| 170 | 170 | return $result = ATTACK_OWN_VACATION; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if(empty($fleet) || !is_array($fleet)) { |
|
| 173 | + if (empty($fleet) || !is_array($fleet)) { |
|
| 174 | 174 | return $result = ATTACK_NO_FLEET; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | $sn_groups_mission = sn_get_groups('missions'); |
| 178 | - if(!isset($sn_groups_mission[$mission])) { |
|
| 178 | + if (!isset($sn_groups_mission[$mission])) { |
|
| 179 | 179 | return $result = ATTACK_MISSION_ABSENT; |
| 180 | 180 | } |
| 181 | 181 | $sn_data_mission = $sn_groups_mission[$mission]; |
@@ -194,32 +194,32 @@ discard block |
||
| 194 | 194 | $resources = 0; |
| 195 | 195 | $ship_ids = sn_get_groups('fleet'); |
| 196 | 196 | $resource_ids = sn_get_groups('resources_loot'); |
| 197 | - foreach($fleet as $ship_id => $ship_count) { |
|
| 197 | + foreach ($fleet as $ship_id => $ship_count) { |
|
| 198 | 198 | $is_ship = in_array($ship_id, $ship_ids); |
| 199 | 199 | $is_resource = in_array($ship_id, $resource_ids); |
| 200 | - if(!$is_ship && !$is_resource) { |
|
| 200 | + if (!$is_ship && !$is_resource) { |
|
| 201 | 201 | // TODO Спецобработчик для Капитана и модулей |
| 202 | 202 | // return ATTACK_WRONG_UNIT; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if($ship_count < 0) { |
|
| 205 | + if ($ship_count < 0) { |
|
| 206 | 206 | return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
| 209 | + if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
| 210 | 210 | // TODO ATTACK_NO_MISSILE |
| 211 | 211 | return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if($is_ship) { |
|
| 214 | + if ($is_ship) { |
|
| 215 | 215 | $single_ship_data = get_ship_data($ship_id, $user); |
| 216 | - if($single_ship_data[P_SPEED] <= 0) { |
|
| 216 | + if ($single_ship_data[P_SPEED] <= 0) { |
|
| 217 | 217 | return $result = ATTACK_ZERO_SPEED; |
| 218 | 218 | } |
| 219 | 219 | $ships += $ship_count; |
| 220 | 220 | $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0; |
| 221 | 221 | $spies += $ship_id == SHIP_SPY ? $ship_count : 0; |
| 222 | - } elseif($is_resource) { |
|
| 222 | + } elseif ($is_resource) { |
|
| 223 | 223 | $resources += $ship_count; |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | */ |
| 232 | 232 | |
| 233 | - if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
| 233 | + if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
| 234 | 234 | return $result = ATTACK_RESOURCE_FORBIDDEN; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -242,78 +242,78 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | 244 | $speed = $options['fleet_speed_percent']; |
| 245 | - if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
| 245 | + if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
| 246 | 246 | return $result = ATTACK_WRONG_SPEED; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']); |
| 250 | 250 | |
| 251 | 251 | |
| 252 | - if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
| 252 | + if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
| 253 | 253 | return $result = ATTACK_NO_FUEL; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - if($travel_data['consumption'] > $travel_data['capacity']) { |
|
| 256 | + if ($travel_data['consumption'] > $travel_data['capacity']) { |
|
| 257 | 257 | return $result = ATTACK_TOO_FAR; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if($travel_data['hold'] < $resources) { |
|
| 260 | + if ($travel_data['hold'] < $resources) { |
|
| 261 | 261 | return $result = ATTACK_OVERLOADED; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
| 265 | 265 | |
| 266 | 266 | $fleet_group = $options['fleet_group']; |
| 267 | - if($fleet_group) { |
|
| 268 | - if($mission != MT_AKS) { |
|
| 267 | + if ($fleet_group) { |
|
| 268 | + if ($mission != MT_AKS) { |
|
| 269 | 269 | return $result = ATTACK_WRONG_MISSION; |
| 270 | 270 | }; |
| 271 | 271 | |
| 272 | 272 | $acs = db_acs_get_by_group_id($fleet_group); |
| 273 | - if(!$acs['id']) { |
|
| 273 | + if (!$acs['id']) { |
|
| 274 | 274 | return $result = ATTACK_NO_ACS; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { |
|
| 277 | + if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { |
|
| 278 | 278 | return $result = ATTACK_ACS_WRONG_TARGET; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if($fleet_start_time > $acs['ankunft']) { |
|
| 281 | + if ($fleet_start_time > $acs['ankunft']) { |
|
| 282 | 282 | return $result = ATTACK_ACS_TOO_LATE; |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $flying_fleets = $options['flying_fleets']; |
| 287 | - if(!$flying_fleets) { |
|
| 287 | + if (!$flying_fleets) { |
|
| 288 | 288 | $flying_fleets = FleetList::fleet_count_flying($user['id']); |
| 289 | 289 | } |
| 290 | - if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
| 290 | + if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
| 291 | 291 | return $result = ATTACK_NO_SLOTS; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт |
| 295 | - if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
| 295 | + if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
| 296 | 296 | return $result = ATTACK_SPIES_LONLY; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Checking for no planet |
| 300 | - if(!$planet_dst['id_owner']) { |
|
| 301 | - if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
| 300 | + if (!$planet_dst['id_owner']) { |
|
| 301 | + if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
| 302 | 302 | return $result = ATTACK_NO_COLONIZER; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
| 305 | + if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
| 306 | 306 | return $result = ATTACK_ALLOWED; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | return $result = ATTACK_NO_TARGET; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if($mission == MT_RECYCLE) { |
|
| 313 | - if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
| 312 | + if ($mission == MT_RECYCLE) { |
|
| 313 | + if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
| 314 | 314 | return $result = ATTACK_NO_DEBRIS; |
| 315 | 315 | } |
| 316 | - if($recyclers <= 0) { |
|
| 316 | + if ($recyclers <= 0) { |
|
| 317 | 317 | return $result = ATTACK_NO_RECYCLERS; |
| 318 | 318 | } |
| 319 | 319 | |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Got planet. Checking if it is ours |
| 324 | - if($planet_dst['id_owner'] == $user['id']) { |
|
| 325 | - if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
| 324 | + if ($planet_dst['id_owner'] == $user['id']) { |
|
| 325 | + if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
| 326 | 326 | return $result = ATTACK_ALLOWED; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -330,19 +330,19 @@ discard block |
||
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // No, planet not ours. Cutting mission that can't be send to not-ours planet |
| 333 | - if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
| 333 | + if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
| 334 | 334 | return $result = ATTACK_WRONG_MISSION; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | $enemy = db_user_by_id($planet_dst['id_owner']); |
| 338 | 338 | // We cannot attack or send resource to users in VACATION mode |
| 339 | - if($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
| 339 | + if ($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
| 340 | 340 | return $result = ATTACK_VACATION; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // Multi IP protection |
| 344 | 344 | // TODO: Here we need a procedure to check proxies |
| 345 | - if(sys_is_multiaccount($user, $enemy)) { |
|
| 345 | + if (sys_is_multiaccount($user, $enemy)) { |
|
| 346 | 346 | return $result = ATTACK_SAME_IP; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -350,8 +350,8 @@ discard block |
||
| 350 | 350 | $enemy_points = $enemy['total_points']; |
| 351 | 351 | |
| 352 | 352 | // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer |
| 353 | - if($mission == MT_TRANSPORT) { |
|
| 354 | - if($user_points >= $enemy_points || $config->allow_buffing) { |
|
| 353 | + if ($mission == MT_TRANSPORT) { |
|
| 354 | + if ($user_points >= $enemy_points || $config->allow_buffing) { |
|
| 355 | 355 | return $result = ATTACK_ALLOWED; |
| 356 | 356 | } else { |
| 357 | 357 | return $result = ATTACK_BUFFING; |
@@ -361,66 +361,66 @@ discard block |
||
| 361 | 361 | // Only aggresive missions passed to this point. HOLD counts as passive but aggresive |
| 362 | 362 | |
| 363 | 363 | // Is it admin with planet protection? |
| 364 | - if($planet_dst['id_level'] > $user['authlevel']) { |
|
| 364 | + if ($planet_dst['id_level'] > $user['authlevel']) { |
|
| 365 | 365 | return $result = ATTACK_ADMIN; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | // Okay. Now skipping protection checks for inactive longer then 1 week |
| 369 | - if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
| 370 | - if( |
|
| 369 | + if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
| 370 | + if ( |
|
| 371 | 371 | ($enemy_points <= $config->game_noob_points && $user_points > $config->game_noob_points) |
| 372 | 372 | || |
| 373 | 373 | ($config->game_noob_factor && $user_points > $enemy_points * $config->game_noob_factor) |
| 374 | 374 | ) { |
| 375 | - if($mission != MT_HOLD) { |
|
| 375 | + if ($mission != MT_HOLD) { |
|
| 376 | 376 | return $result = ATTACK_NOOB; |
| 377 | 377 | } |
| 378 | - if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
| 378 | + if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
| 379 | 379 | return $result = ATTACK_NOOB; |
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // Is it HOLD mission? If yes - there should be ally deposit |
| 385 | - if($mission == MT_HOLD) { |
|
| 386 | - if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
| 385 | + if ($mission == MT_HOLD) { |
|
| 386 | + if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
| 387 | 387 | return $result = ATTACK_ALLOWED; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | return $result = ATTACK_NO_ALLY_DEPOSIT; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if($mission == MT_SPY) { |
|
| 393 | + if ($mission == MT_SPY) { |
|
| 394 | 394 | return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Is it MISSILE mission? |
| 398 | - if($mission == MT_MISSILE) { |
|
| 398 | + if ($mission == MT_MISSILE) { |
|
| 399 | 399 | $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
| 400 | - if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
| 400 | + if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
| 401 | 401 | return $result = ATTACK_NO_SILO; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
| 404 | + if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
| 405 | 405 | return $result = ATTACK_NO_MISSILE; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | $distance = abs($planet_dst['system'] - $planet_src['system']); |
| 409 | 409 | $mip_range = flt_get_missile_range($user); |
| 410 | - if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
| 410 | + if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
| 411 | 411 | return $result = ATTACK_MISSILE_TOO_FAR; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
| 414 | + if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
| 415 | 415 | return $result = ATTACK_WRONG_STRUCTURE; |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
| 419 | + if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
| 420 | 420 | return $result = ATTACK_WRONG_MISSION; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
| 423 | + if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
| 424 | 424 | return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group); |
| 425 | 425 | } |
| 426 | 426 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | $from = $from['planet']; |
| 448 | 448 | |
| 449 | 449 | $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options); |
| 450 | - if($can_attack != ATTACK_ALLOWED) { |
|
| 450 | + if ($can_attack != ATTACK_ALLOWED) { |
|
| 451 | 451 | $internal_transaction ? sn_db_transaction_rollback() : false; |
| 452 | 452 | |
| 453 | 453 | return $can_attack; |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']); |
| 459 | 459 | |
| 460 | 460 | $time_on_mission = 0; |
| 461 | - if($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
| 461 | + if ($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
| 462 | 462 | // TODO - include some checks about maximum and minumum stay_duration |
| 463 | 463 | $time_on_mission = $options['stay_time'] * 3600; |
| 464 | 464 | } |
@@ -481,14 +481,14 @@ discard block |
||
| 481 | 481 | $sn_group_resources_loot = sn_get_groups('resources_loot'); |
| 482 | 482 | $db_changeset = array(); |
| 483 | 483 | $planet_row_changed_fields = array(); |
| 484 | - foreach($fleet_REAL_array as $unit_id => $amount) { |
|
| 485 | - if(!$amount || !$unit_id) { |
|
| 484 | + foreach ($fleet_REAL_array as $unit_id => $amount) { |
|
| 485 | + if (!$amount || !$unit_id) { |
|
| 486 | 486 | continue; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if(in_array($unit_id, $sn_group_fleet)) { |
|
| 489 | + if (in_array($unit_id, $sn_group_fleet)) { |
|
| 490 | 490 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']); |
| 491 | - } elseif(in_array($unit_id, $sn_group_resources_loot)) { |
|
| 491 | + } elseif (in_array($unit_id, $sn_group_resources_loot)) { |
|
| 492 | 492 | $planet_row_changed_fields[pname_resource_name($unit_id)]['delta'] -= $amount; |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -527,16 +527,16 @@ discard block |
||
| 527 | 527 | |
| 528 | 528 | $ship_data = array(); |
| 529 | 529 | $fleet_array = array(); |
| 530 | - foreach($ship_list as $transport_id => $cork) { |
|
| 530 | + foreach ($ship_list as $transport_id => $cork) { |
|
| 531 | 531 | $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); |
| 532 | 532 | } |
| 533 | 533 | uasort($ship_data, 'flt_calculate_ship_to_transport_sort'); |
| 534 | 534 | |
| 535 | 535 | $fleet_capacity = 0; |
| 536 | 536 | $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); |
| 537 | - foreach($ship_data as $transport_id => &$ship_info) { |
|
| 537 | + foreach ($ship_data as $transport_id => &$ship_info) { |
|
| 538 | 538 | $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); |
| 539 | - if($ship_loaded) { |
|
| 539 | + if ($ship_loaded) { |
|
| 540 | 540 | $fleet_array[$transport_id] = $ship_loaded; |
| 541 | 541 | $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); |
| 542 | 542 | $fuel_left -= $ship_info['consumption'] * $ship_loaded; |
@@ -29,6 +29,9 @@ |
||
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | +/** |
|
| 33 | + * @param string $group_name |
|
| 34 | + */ |
|
| 32 | 35 | function flt_spy_scan($target_planet, $group_name, $section_title, $target_user = array()) |
| 33 | 36 | { |
| 34 | 37 | global $lang; |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | // ---------------------------------------------------------------------------------------------------------------- |
| 13 | 13 | function coe_compress_add_units($unit_group, $target_planet, &$compress_data, $target_user = array()) { |
| 14 | - foreach($unit_group as $unit_id) { |
|
| 15 | - if(($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 14 | + foreach ($unit_group as $unit_id) { |
|
| 15 | + if (($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 16 | 16 | $compress_data[$unit_id] = $unit_count; |
| 17 | 17 | } |
| 18 | 18 | } |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | global $lang; |
| 23 | 23 | |
| 24 | 24 | $result = "<tr><td class=\"c\" colspan=\"4\">{$section_title}</td></tr>"; |
| 25 | - foreach(sn_get_groups($group_name) as $unit_id) { |
|
| 26 | - if(($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 25 | + foreach (sn_get_groups($group_name) as $unit_id) { |
|
| 26 | + if (($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 27 | 27 | $result .= "<tr><td align=\"left\" colspan=\"3\">{$lang['tech'][$unit_id]}</td><td align=\"right\">{$unit_amount}</td></tr>"; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | $objFleet = $mission_data->fleet; |
| 56 | 56 | |
| 57 | - if(empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) { |
|
| 57 | + if (empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) { |
|
| 58 | 58 | $objFleet->mark_fleet_as_returned_and_save(); |
| 59 | 59 | |
| 60 | 60 | return $result; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $spy_probes = $objFleet->shipCountById(SHIP_SPY); |
| 64 | - if($spy_probes > 0) { |
|
| 64 | + if ($spy_probes > 0) { |
|
| 65 | 65 | $TargetSpyLvl = GetSpyLevel($target_user_row); |
| 66 | 66 | $CurrentSpyLvl = GetSpyLevel($spying_user_row); |
| 67 | 67 | $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl; |
@@ -85,19 +85,19 @@ discard block |
||
| 85 | 85 | $spy_message .= "<td width=220>{$lang['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>"; |
| 86 | 86 | $spy_message .= "<td width=220>{$lang['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>"; |
| 87 | 87 | $spy_message .= "</tr>"; |
| 88 | - if($spy_diff >= 2) { |
|
| 88 | + if ($spy_diff >= 2) { |
|
| 89 | 89 | $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', $lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>"; |
| 90 | 90 | coe_compress_add_units(sn_get_groups('fleet'), $target_planet_row, $combat_pack[0]); |
| 91 | 91 | } |
| 92 | - if($spy_diff >= 3) { |
|
| 92 | + if ($spy_diff >= 3) { |
|
| 93 | 93 | $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', $lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>"; |
| 94 | 94 | coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]); |
| 95 | 95 | } |
| 96 | - if($spy_diff >= 5) { |
|
| 96 | + if ($spy_diff >= 5) { |
|
| 97 | 97 | $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', $lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if($spy_diff_empire >= 0) { |
|
| 100 | + if ($spy_diff_empire >= 0) { |
|
| 101 | 101 | $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', $lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>"; |
| 102 | 102 | coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row); |
| 103 | 103 | } |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D'); |
| 107 | 107 | |
| 108 | 108 | $target_unit_list = 0; |
| 109 | - foreach(sn_get_groups('fleet') as $unit_id) { |
|
| 109 | + foreach (sn_get_groups('fleet') as $unit_id) { |
|
| 110 | 110 | $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true)); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl); |
| 114 | 114 | |
| 115 | - if(mt_rand(0, 99) > $spy_detected) { |
|
| 115 | + if (mt_rand(0, 99) > $spy_detected) { |
|
| 116 | 116 | $spy_outcome_str = sprintf($lang['sys_mess_spy_detect_chance'], $spy_detected); |
| 117 | 117 | $spy_detected = false; |
| 118 | 118 | } else { |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $target_message = "{$lang['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3); |
| 133 | 133 | $target_message .= " {$lang['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row); |
| 134 | 134 | |
| 135 | - if($spy_detected) { |
|
| 135 | + if ($spy_detected) { |
|
| 136 | 136 | $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet']; |
| 137 | 137 | |
| 138 | 138 | $spy_cost = get_unit_param(SHIP_SPY, P_COST); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $target_message); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if($spy_detected) { |
|
| 152 | + if ($spy_detected) { |
|
| 153 | 153 | $objFleet->db_delete_this_fleet(); |
| 154 | 154 | } else { |
| 155 | 155 | $objFleet->mark_fleet_as_returned_and_save(); |
@@ -26,6 +26,10 @@ |
||
| 26 | 26 | return true; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | +/** |
|
| 30 | + * @param integer $mode |
|
| 31 | + * @param integer $mercenary_id |
|
| 32 | + */ |
|
| 29 | 33 | function mrc_mercenary_hire($mode, $user, $mercenary_id) { |
| 30 | 34 | global $config, $lang, $sn_powerup_buy_discounts; |
| 31 | 35 | |
@@ -62,8 +62,8 @@ |
||
| 62 | 62 | if($mercenary_level) { |
| 63 | 63 | $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level); |
| 64 | 64 | if(!$config->empire_mercenary_temporary && $mercenary_level_old) { |
| 65 | - $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); |
|
| 66 | - $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; |
|
| 65 | + $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); |
|
| 66 | + $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; |
|
| 67 | 67 | } |
| 68 | 68 | $darkmater_cost = ceil($darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] * $mercenary_period * $sn_powerup_buy_discounts[$mercenary_period] / $config->empire_mercenary_base_period); |
| 69 | 69 | } else { |
@@ -7,16 +7,16 @@ discard block |
||
| 7 | 7 | global $config; |
| 8 | 8 | |
| 9 | 9 | $mercenary_info = get_unit_param($mercenary_id); |
| 10 | - if($config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) |
|
| 10 | + if ($config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) |
|
| 11 | 11 | { |
| 12 | 12 | return true; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - if(isset($mercenary_info[P_REQUIRE])) |
|
| 15 | + if (isset($mercenary_info[P_REQUIRE])) |
|
| 16 | 16 | { |
| 17 | - foreach($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) |
|
| 17 | + foreach ($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) |
|
| 18 | 18 | { |
| 19 | - if(mrc_get_level($user, null, $unit_id) < $unit_level) |
|
| 19 | + if (mrc_get_level($user, null, $unit_id) < $unit_level) |
|
| 20 | 20 | { |
| 21 | 21 | return false; |
| 22 | 22 | } |
@@ -33,35 +33,35 @@ discard block |
||
| 33 | 33 | $is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary; |
| 34 | 34 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? $config->ali_bonus_members : 1); |
| 35 | 35 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; |
| 36 | - if(!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { |
|
| 36 | + if (!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { |
|
| 37 | 37 | throw new Exception($lang['mrc_msg_error_wrong_mercenary'], ERR_ERROR); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if(!mrc_officer_accessible($user, $mercenary_id)) { |
|
| 40 | + if (!mrc_officer_accessible($user, $mercenary_id)) { |
|
| 41 | 41 | throw new Exception($lang['mrc_msg_error_requirements'], ERR_ERROR); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $mercenary_level = sys_get_param_int('mercenary_level'); |
| 45 | - if($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { |
|
| 45 | + if ($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { |
|
| 46 | 46 | throw new Exception($lang['mrc_msg_error_wrong_level'], ERR_ERROR); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { |
|
| 49 | + if ($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { |
|
| 50 | 50 | throw new Exception($lang['mrc_msg_error_wrong_period'], ERR_ERROR); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | sn_db_transaction_start(); |
| 54 | 54 | |
| 55 | 55 | $mercenary_level_old = mrc_get_level($user, $planetrow, $mercenary_id, true, true); |
| 56 | - if($config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { |
|
| 56 | + if ($config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { |
|
| 57 | 57 | throw new Exception($lang['mrc_msg_error_already_hired'], ERR_ERROR); // Can't hire already hired temp mercenary - dismiss first |
| 58 | - } elseif($config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { |
|
| 58 | + } elseif ($config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { |
|
| 59 | 59 | throw new Exception('', ERR_NONE); // Can't dismiss (!$mercenary_level) not hired (!$mercenary_level_old) temp mercenary. But no error |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if($mercenary_level) { |
|
| 62 | + if ($mercenary_level) { |
|
| 63 | 63 | $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level); |
| 64 | - if(!$config->empire_mercenary_temporary && $mercenary_level_old) { |
|
| 64 | + if (!$config->empire_mercenary_temporary && $mercenary_level_old) { |
|
| 65 | 65 | $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); |
| 66 | 66 | $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; |
| 67 | 67 | } |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | $darkmater_cost *= $cost_alliance_multiplyer; |
| 73 | 73 | |
| 74 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { |
|
| 74 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { |
|
| 75 | 75 | throw new Exception($lang['mrc_msg_error_no_resource'], ERR_ERROR); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if(($darkmater_cost && $mercenary_level) || !$is_permanent) { |
|
| 78 | + if (($darkmater_cost && $mercenary_level) || !$is_permanent) { |
|
| 79 | 79 | $unit_row = db_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id); |
| 80 | - if(is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { |
|
| 80 | + if (is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { |
|
| 81 | 81 | $dismiss_full_cost = eco_get_total_cost($mercenary_id, $unit_row['unit_level']); |
| 82 | 82 | $dismiss_full_cost = $dismiss_full_cost[BUILD_CREATE][RES_DARK_MATTER]; |
| 83 | 83 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | db_unit_list_delete($user['id'], LOC_USER, $user['id'], $mercenary_id); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if($darkmater_cost && $mercenary_level) { |
|
| 98 | + if ($darkmater_cost && $mercenary_level) { |
|
| 99 | 99 | db_unit_set_insert( |
| 100 | 100 | "unit_player_id = {$user['id']}, |
| 101 | 101 | unit_location_type = " . LOC_USER . ", |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $mode = in_array($mode, array(UNIT_MERCENARIES, UNIT_PLANS)) ? $mode : UNIT_MERCENARIES; |
| 131 | 131 | $is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary; |
| 132 | 132 | |
| 133 | - if($mercenary_id = sys_get_param_int('mercenary_id')) |
|
| 133 | + if ($mercenary_id = sys_get_param_int('mercenary_id')) |
|
| 134 | 134 | { |
| 135 | 135 | $operation_result = mrc_mercenary_hire($mode, $user, $mercenary_id); |
| 136 | 136 | } |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | $template = gettemplate('mrc_mercenary_hire', true); |
| 141 | 141 | |
| 142 | - if(!empty($operation_result)) |
|
| 142 | + if (!empty($operation_result)) |
|
| 143 | 143 | { |
| 144 | 144 | $template->assign_block_vars('result', $operation_result); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - foreach($sn_powerup_buy_discounts as $hire_period => $hire_discount) |
|
| 147 | + foreach ($sn_powerup_buy_discounts as $hire_period => $hire_discount) |
|
| 148 | 148 | { |
| 149 | 149 | $template->assign_block_vars('period', array( |
| 150 | 150 | 'LENGTH' => $hire_period, |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | $user_dark_matter = mrc_get_level($user, '', RES_DARK_MATTER); |
| 158 | 158 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? $config->ali_bonus_members : 1); |
| 159 | 159 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; |
| 160 | - foreach(sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) |
|
| 160 | + foreach (sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) |
|
| 161 | 161 | { |
| 162 | 162 | { |
| 163 | 163 | $mercenary = get_unit_param($mercenary_id); |
| 164 | 164 | $mercenary_bonus = $mercenary['bonus']; |
| 165 | 165 | $mercenary_bonus = $mercenary_bonus >= 0 ? "+{$mercenary_bonus}" : "{$mercenary_bonus}"; |
| 166 | - switch($mercenary['bonus_type']) |
|
| 166 | + switch ($mercenary['bonus_type']) |
|
| 167 | 167 | { |
| 168 | 168 | case BONUS_PERCENT: |
| 169 | 169 | $mercenary_bonus = "{$mercenary_bonus}% "; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $mercenary_level = mrc_get_level($user, null, $mercenary_id, false, true); |
| 182 | 182 | $mercenary_level_bonus = max(0, mrc_get_level($user, null, $mercenary_id) - $mercenary_level); |
| 183 | 183 | $total_cost_old = 0; |
| 184 | - if($is_permanent) |
|
| 184 | + if ($is_permanent) |
|
| 185 | 185 | { |
| 186 | 186 | $total_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level); |
| 187 | 187 | $total_cost_old = $total_cost_old[BUILD_CREATE][RES_DARK_MATTER] * $cost_alliance_multiplyer; |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | 'BONUS_TYPE' => $mercenary['bonus_type'], |
| 206 | 206 | 'HIRE_END' => $mercenary_time_finish && $mercenary_time_finish >= SN_TIME_NOW ? date(FMT_DATE_TIME, $mercenary_time_finish) : '', |
| 207 | 207 | 'HIRE_LEFT_PERCENT' => $mercenary_time_finish && $mercenary_time_finish >= SN_TIME_NOW |
| 208 | - ? round(($mercenary_time_finish - SN_TIME_NOW)/($mercenary_time_finish - $mercenary_time_start) * 100, 1) |
|
| 208 | + ? round(($mercenary_time_finish - SN_TIME_NOW) / ($mercenary_time_finish - $mercenary_time_start) * 100, 1) |
|
| 209 | 209 | : 0, |
| 210 | 210 | 'CAN_BUY' => mrc_officer_accessible($user, $mercenary_id), |
| 211 | 211 | )); |
| 212 | 212 | |
| 213 | 213 | $upgrade_cost = 1; |
| 214 | - for($i = $config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) |
|
| 214 | + for ($i = $config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) |
|
| 215 | 215 | { |
| 216 | 216 | $total_cost = eco_get_total_cost($mercenary_id, $i); |
| 217 | 217 | $total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer; |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | for ($Option = 10; $Option >= 0; $Option--) |
| 94 | 94 | { |
| 95 | - $template->assign_block_vars('option', array( |
|
| 96 | - 'VALUE' => $Option * 10, |
|
| 97 | - )); |
|
| 95 | + $template->assign_block_vars('option', array( |
|
| 96 | + 'VALUE' => $Option * 10, |
|
| 97 | + )); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $caps_real = eco_get_planet_caps($user, $planetrow, 3600); |
@@ -163,14 +163,14 @@ discard block |
||
| 163 | 163 | int_calc_storage_bar(RES_DEUTERIUM); |
| 164 | 164 | |
| 165 | 165 | $template->assign_vars(array( |
| 166 | - 'PLANET_NAME' => $planetrow['name'], |
|
| 167 | - 'PLANET_TYPE' => $planetrow['planet_type'], |
|
| 168 | - 'PLANET_DENSITY_INDEX' => $planet_density_index, |
|
| 169 | - 'PLANET_CORE_TEXT' => $lang['uni_planet_density_types'][$planet_density_index], |
|
| 166 | + 'PLANET_NAME' => $planetrow['name'], |
|
| 167 | + 'PLANET_TYPE' => $planetrow['planet_type'], |
|
| 168 | + 'PLANET_DENSITY_INDEX' => $planet_density_index, |
|
| 169 | + 'PLANET_CORE_TEXT' => $lang['uni_planet_density_types'][$planet_density_index], |
|
| 170 | 170 | |
| 171 | - 'PRODUCTION_LEVEL' => floor($caps_real['efficiency'] * 100), |
|
| 171 | + 'PRODUCTION_LEVEL' => floor($caps_real['efficiency'] * 100), |
|
| 172 | 172 | |
| 173 | - 'PAGE_HINT' => $lang['res_hint'], |
|
| 173 | + 'PAGE_HINT' => $lang['res_hint'], |
|
| 174 | 174 | )); |
| 175 | 175 | |
| 176 | 176 | display($template, $lang['res_planet_production']); |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | )); |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | -$ValidList['percent'] = array ( 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ); |
|
| 49 | +$ValidList['percent'] = array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); |
|
| 50 | 50 | $template = gettemplate('resources', true); |
| 51 | 51 | |
| 52 | 52 | $transmutation_result = sn_sys_planet_core_transmute($user, $planetrow); |
| 53 | -if(!empty($transmutation_result)) |
|
| 53 | +if (!empty($transmutation_result)) |
|
| 54 | 54 | { |
| 55 | 55 | $template->assign_block_vars('result', $transmutation_result); // array('STATUS' => $transmutation_result['STATUS'], 'MESSAGE' => $transmutation_result['MESSAGE'])); |
| 56 | 56 | } |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | $production = $_POST['production']; |
| 60 | 60 | //$SubQry = ''; |
| 61 | 61 | $SubQry = array(); |
| 62 | -if(is_array($production)) { |
|
| 63 | - foreach($production as $prod_id => $percent) { |
|
| 64 | - if($percent > 100 || $percent < 0) { |
|
| 62 | +if (is_array($production)) { |
|
| 63 | + foreach ($production as $prod_id => $percent) { |
|
| 64 | + if ($percent > 100 || $percent < 0) { |
|
| 65 | 65 | $debug->warning('Supplying wrong production percent (less then 0 or greater then 100)', 'Hack attempt', 302, array('base_dump' => true)); |
| 66 | 66 | die(); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $prod_id = intval($prod_id); |
| 70 | - if(in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) { |
|
| 70 | + if (in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) { |
|
| 71 | 71 | $field_name = pname_factory_production_field_name($prod_id); |
| 72 | 72 | $percent = floor($percent / 10); |
| 73 | 73 | $planetrow[$field_name] = $percent; |
| 74 | 74 | //$SubQry .= "`{$field_name}` = '{$percent}',"; |
| 75 | - $SubQry[] = "`{$field_name}` = '{$percent}'"; |
|
| 75 | + $SubQry[] = "`{$field_name}` = '{$percent}'"; |
|
| 76 | 76 | } else { |
| 77 | 77 | $debug->warning('Supplying wrong ID in production array - attempt to change some field - ID' . $prod_id, 'Resource Page', 301); |
| 78 | 78 | continue; |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | 'ENERGY_TYPE' => pretty_number($caps_real['production'][RES_ENERGY][0], true, true), |
| 109 | 109 | )); |
| 110 | 110 | |
| 111 | -foreach($sn_group_factories as $unit_id) |
|
| 111 | +foreach ($sn_group_factories as $unit_id) |
|
| 112 | 112 | { |
| 113 | - if(mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id)) |
|
| 113 | + if (mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id)) |
|
| 114 | 114 | { |
| 115 | 115 | $level_plain = mrc_get_level($user, $planetrow, $unit_id, false, true); |
| 116 | 116 | $template->assign_block_vars('production', array( |
@@ -39,8 +39,8 @@ |
||
| 39 | 39 | 0 => $row['visit_time'], // start |
| 40 | 40 | 1 => $row['visit_time'], // end |
| 41 | 41 | ) |
| 42 | - //: false |
|
| 43 | - ; |
|
| 42 | + //: false |
|
| 43 | + ; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $session_list = array(); |
@@ -12,20 +12,20 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
| 14 | 14 | |
| 15 | -if($user['authlevel'] < 3) { |
|
| 15 | +if ($user['authlevel'] < 3) { |
|
| 16 | 16 | AdminMessage($lang['adm_err_denied']); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // define('SESSION_INTERRUPT', 15*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов |
| 20 | 20 | // define('SUSPICIOUS_LONG', 2 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим |
| 21 | 21 | |
| 22 | -define('SESSION_INTERRUPT', 1 * 60*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов |
|
| 23 | -define('SUSPICIOUS_LONG', 16 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим |
|
| 22 | +define('SESSION_INTERRUPT', 1 * 60 * 60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов |
|
| 23 | +define('SUSPICIOUS_LONG', 16 * 60 * 60); // Тогда это увеличиваем до, скажем суток - и там смотрим |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | function check_suspicious(&$session, &$session_list_last_id, &$row) { |
| 27 | 27 | $session[2] = $session[1] - $session[0]; |
| 28 | - if($session[2] > SUSPICIOUS_LONG) |
|
| 28 | + if ($session[2] > SUSPICIOUS_LONG) |
|
| 29 | 29 | { |
| 30 | 30 | $session[2] = pretty_time($session[2]); |
| 31 | 31 | $session[0] = date(FMT_DATE_TIME_SQL, $session[0]); |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | $session_list = array(); |
| 47 | 47 | $query = doquery("SELECT `visit_time`, user_id FROM {{counter}} where user_id <> 0 and visit_time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) order by user_id, visit_time;"); |
| 48 | 48 | $session = array(); |
| 49 | -if($row = db_fetch($query)) { |
|
| 49 | +if ($row = db_fetch($query)) { |
|
| 50 | 50 | $session = array( |
| 51 | 51 | 0 => strtotime($row['visit_time']), // start |
| 52 | 52 | 1 => strtotime($row['visit_time']), // end |
| 53 | 53 | ); |
| 54 | 54 | $last_id = $row['user_id']; |
| 55 | 55 | } |
| 56 | -while($row = db_fetch($query)) { |
|
| 56 | +while ($row = db_fetch($query)) { |
|
| 57 | 57 | $row['visit_time'] = strtotime($row['visit_time']); |
| 58 | - if($last_id == $row['user_id']) { |
|
| 58 | + if ($last_id == $row['user_id']) { |
|
| 59 | 59 | // Тот же юзер |
| 60 | - if($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия |
|
| 60 | + if ($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия |
|
| 61 | 61 | $session[1] = $row['visit_time']; |
| 62 | 62 | } else { |
| 63 | 63 | // Новая сессия |
| 64 | 64 | // check_suspicious($session, $session_list[$last_id], $row); |
| 65 | 65 | $session[2] = $session[1] - $session[0]; |
| 66 | - if($session[2] > SUSPICIOUS_LONG) |
|
| 66 | + if ($session[2] > SUSPICIOUS_LONG) |
|
| 67 | 67 | { |
| 68 | 68 | $session[2] = pretty_time($session[2]); |
| 69 | 69 | $session[0] = date(FMT_DATE_TIME_SQL, $session[0]); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } else { |
| 79 | 79 | // check_suspicious($session, $session_list[$last_id], $row); |
| 80 | 80 | $session[2] = $session[1] - $session[0]; |
| 81 | - if($session[2] > SUSPICIOUS_LONG) |
|
| 81 | + if ($session[2] > SUSPICIOUS_LONG) |
|
| 82 | 82 | { |
| 83 | 83 | $session[2] = pretty_time($session[2]); |
| 84 | 84 | $session[0] = date(FMT_DATE_TIME_SQL, $session[0]); |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | -if($last_id) { |
|
| 96 | +if ($last_id) { |
|
| 97 | 97 | // check_suspicious($session, $session_list[$last_id], $row = array('time' => 0)); |
| 98 | 98 | $session[2] = $session[1] - $session[0]; |
| 99 | 99 | |
| 100 | - if($session[2] > SUSPICIOUS_LONG) |
|
| 100 | + if ($session[2] > SUSPICIOUS_LONG) |
|
| 101 | 101 | { |
| 102 | 102 | $session[2] = pretty_time($session[2]); |
| 103 | 103 | $session[0] = date(FMT_DATE_TIME_SQL, $session[0]); |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | print("<td>ID</td><td>Username</td><td>Start</td><td>End</td><td>Length</td>"); |
| 112 | 112 | print("<td>Last online</td>"); |
| 113 | 113 | print("</tr>"); |
| 114 | -foreach($session_list as $user_id => $value) { |
|
| 114 | +foreach ($session_list as $user_id => $value) { |
|
| 115 | 115 | $user_record = doquery("SELECT `username`, onlinetime FROM {{users}} WHERE id = {$user_id};", true); |
| 116 | - foreach($value as $interval_data) { |
|
| 116 | + foreach ($value as $interval_data) { |
|
| 117 | 117 | print("<tr>"); |
| 118 | 118 | print("<td>{$user_id}</td><td>{$user_record['username']}</td><td>{$interval_data[0]}</td><td>{$interval_data[1]}</td><td>{$interval_data[2]}</td>"); |
| 119 | 119 | print("<td>" . date(FMT_DATE_TIME_SQL, $user_record['onlinetime']) . "</td>"); |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | $action = sys_get_param_str('action'); |
| 28 | 28 | |
| 29 | 29 | $player_banned_row = db_user_by_username($name_unsafe); |
| 30 | -if($mode == 'banit' && $action) |
|
| 30 | +if ($mode == 'banit' && $action) |
|
| 31 | 31 | { |
| 32 | - if($player_banned_row) |
|
| 32 | + if ($player_banned_row) |
|
| 33 | 33 | { |
| 34 | 34 | $reas = $_POST['why']; |
| 35 | 35 | $days = $_POST['days']; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $DoneMessage = "{$lang['adm_bn_thpl']} {$name_output} {$lang['adm_bn_isbn']}"; |
| 50 | 50 | |
| 51 | - if($is_vacation) |
|
| 51 | + if ($is_vacation) |
|
| 52 | 52 | { |
| 53 | 53 | $DoneMessage .= $lang['adm_bn_vctn']; |
| 54 | 54 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | AdminMessage($DoneMessage, $lang['adm_ban_title']); |
| 64 | 64 | } |
| 65 | -elseif($mode == 'unbanit' && $action) |
|
| 65 | +elseif ($mode == 'unbanit' && $action) |
|
| 66 | 66 | { |
| 67 | 67 | sys_admin_player_ban_unset($user, $player_banned_row, ($reason = sys_get_param_str('why')) ? $reason : $lang['sys_unbanned']); |
| 68 | 68 | |
@@ -54,15 +54,13 @@ |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $DoneMessage .= $lang['adm_bn_plnt']; |
| 57 | - } |
|
| 58 | - else |
|
| 57 | + } else |
|
| 59 | 58 | { |
| 60 | 59 | $DoneMessage = sprintf($lang['adm_bn_errr'], $name_output); |
| 61 | 60 | } |
| 62 | 61 | |
| 63 | 62 | AdminMessage($DoneMessage, $lang['adm_ban_title']); |
| 64 | -} |
|
| 65 | -elseif($mode == 'unbanit' && $action) |
|
| 63 | +} elseif($mode == 'unbanit' && $action) |
|
| 66 | 64 | { |
| 67 | 65 | sys_admin_player_ban_unset($user, $player_banned_row, ($reason = sys_get_param_str('why')) ? $reason : $lang['sys_unbanned']); |
| 68 | 66 | |