@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * <p>null - транзакция НЕ должна быть запущена</p> |
324 | 324 | * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
325 | 325 | * <p>false - всё равно - для совместимости с $for_update</p> |
326 | - * @return bool Текущий статус транзакции |
|
326 | + * @return null|boolean Текущий статус транзакции |
|
327 | 327 | */ |
328 | 328 | public static function db_transaction_check($status = null) { |
329 | 329 | $error_msg = false; |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * Блокирует указанные таблицу/список таблиц |
401 | 401 | * |
402 | - * @param string|array $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
402 | + * @param string $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
403 | 403 | * <p>string - название таблицы для блокировки</p> |
404 | 404 | * <p>array - массив, где ключ - имя таблицы, а значение - условия блокировки элементов</p> |
405 | 405 | */ |
@@ -587,6 +587,9 @@ discard block |
||
587 | 587 | return $result; |
588 | 588 | } |
589 | 589 | |
590 | + /** |
|
591 | + * @param integer $location_type |
|
592 | + */ |
|
590 | 593 | public static function db_ins_field_set($location_type, $field_set, $serialize = false) { |
591 | 594 | // TODO multiinsert |
592 | 595 | !sn_db_field_set_is_safe($field_set) ? $field_set = sn_db_field_set_make_safe($field_set, $serialize) : false; |
@@ -809,7 +812,7 @@ discard block |
||
809 | 812 | * @param $location_type |
810 | 813 | * @param $location_id |
811 | 814 | * |
812 | - * @return array|bool |
|
815 | + * @return boolean |
|
813 | 816 | */ |
814 | 817 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
815 | 818 | { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | |
204 | 204 | public static function log_file($message, $spaces = 0) { |
205 | - if(self::$debug) { |
|
205 | + if (self::$debug) { |
|
206 | 206 | self::$debug->log_file($message, $spaces); |
207 | 207 | } |
208 | 208 | } |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | // Перепаковывает массив на заданную глубину, убирая поля с null |
215 | 215 | public static function array_repack(&$array, $level = 0) { |
216 | 216 | // TODO $lock_table не нужна тут |
217 | - if(!is_array($array)) { |
|
217 | + if (!is_array($array)) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - foreach($array as $key => &$value) { |
|
222 | - if($value === null) { |
|
221 | + foreach ($array as $key => &$value) { |
|
222 | + if ($value === null) { |
|
223 | 223 | unset($array[$key]); |
224 | - } elseif($level > 0 && is_array($value)) { |
|
224 | + } elseif ($level > 0 && is_array($value)) { |
|
225 | 225 | static::array_repack($value, $level - 1); |
226 | - if(empty($value)) { |
|
226 | + if (empty($value)) { |
|
227 | 227 | unset($array[$key]); |
228 | 228 | } |
229 | 229 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | // TODO Вынести в отдельный объект |
235 | 235 | public static function cache_repack($location_type, $record_id = 0) { |
236 | 236 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
237 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
237 | + if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | |
246 | 246 | public static function cache_clear($location_type, $hard = true) { |
247 | 247 | //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />"); |
248 | - if($hard && !empty(static::$data[$location_type])) { |
|
248 | + if ($hard && !empty(static::$data[$location_type])) { |
|
249 | 249 | // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях |
250 | - array_walk(static::$data[$location_type], function (&$item) { $item = null; }); |
|
250 | + array_walk(static::$data[$location_type], function(&$item) { $item = null; }); |
|
251 | 251 | } |
252 | 252 | static::$locator[$location_type] = array(); |
253 | 253 | static::$queries[$location_type] = array(); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | public static function cache_clear_all($hard = true) { |
258 | 258 | //print('<br />CACHE CLEAR ALL<br />'); |
259 | - if($hard) { |
|
259 | + if ($hard) { |
|
260 | 260 | static::$data = array(); |
261 | 261 | static::cache_lock_unset_all(); |
262 | 262 | } |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
287 | 287 | // нет идентификатора - выход |
288 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
288 | + if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | 292 | $in_transaction = static::db_transaction_check(false); |
293 | - if( |
|
293 | + if ( |
|
294 | 294 | $force_overwrite |
295 | 295 | || |
296 | 296 | // Не заменяются заблокированные записи во время транзакции |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | !static::cache_isset($location_type, $record_id) |
301 | 301 | ) { |
302 | 302 | static::$data[$location_type][$record_id] = $record; |
303 | - if($in_transaction && !$skip_lock) { |
|
303 | + if ($in_transaction && !$skip_lock) { |
|
304 | 304 | static::cache_lock_set($location_type, $record_id); |
305 | 305 | } |
306 | 306 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | public static function cache_unset($cache_id, $safe_record_id) { |
310 | 310 | // $record_id должен быть проверен заранее ! |
311 | - if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
311 | + if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
312 | 312 | // Выставляем запись в null |
313 | 313 | static::$data[$cache_id][$safe_record_id] = null; |
314 | 314 | // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | public static function cache_lock_unset($location_type, $record_id) { |
328 | - if(isset(static::$locks[$location_type][$record_id])) { |
|
328 | + if (isset(static::$locks[$location_type][$record_id])) { |
|
329 | 329 | unset(static::$locks[$location_type][$record_id]); |
330 | 330 | } |
331 | 331 | |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public static function db_transaction_check($status = null) { |
361 | 361 | $error_msg = false; |
362 | - if($status && !static::$db_in_transaction) { |
|
362 | + if ($status && !static::$db_in_transaction) { |
|
363 | 363 | $error_msg = 'No transaction started for current operation'; |
364 | - } elseif($status === null && static::$db_in_transaction) { |
|
364 | + } elseif ($status === null && static::$db_in_transaction) { |
|
365 | 365 | $error_msg = 'Transaction is already started'; |
366 | 366 | } |
367 | 367 | |
368 | - if($error_msg) { |
|
368 | + if ($error_msg) { |
|
369 | 369 | // TODO - Убрать позже |
370 | 370 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>'); |
371 | 371 | $backtrace = debug_backtrace(); |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | static::$transaction_id++; |
388 | 388 | doquery('START TRANSACTION'); |
389 | 389 | |
390 | - if($config->db_manual_lock_enabled) { |
|
390 | + if ($config->db_manual_lock_enabled) { |
|
391 | 391 | $config->db_loadItem('var_db_manually_locked'); |
392 | 392 | $config->db_saveItem('var_db_manually_locked', SN_TIME_SQL); |
393 | 393 | } |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | public static function db_transaction_commit() { |
405 | 405 | static::db_transaction_check(true); |
406 | 406 | |
407 | - if(!empty(static::$delayed_changset)) { |
|
407 | + if (!empty(static::$delayed_changset)) { |
|
408 | 408 | static::db_changeset_apply(static::$delayed_changset, true); |
409 | 409 | // pdump(static::$delayed_changset); |
410 | 410 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | |
421 | 421 | public static function db_transaction_rollback() { |
422 | 422 | // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция |
423 | - if(!empty(static::$delayed_changset)) { |
|
423 | + if (!empty(static::$delayed_changset)) { |
|
424 | 424 | static::db_changeset_revert(); |
425 | 425 | } |
426 | 426 | static::$delayed_changset = array(); |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public static function db_lock_tables($tables) { |
445 | 445 | $tables = is_array($tables) ? $tables : array($tables => ''); |
446 | - foreach($tables as $table_name => $condition) { |
|
446 | + foreach ($tables as $table_name => $condition) { |
|
447 | 447 | self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
448 | 448 | } |
449 | 449 | } |
@@ -486,17 +486,17 @@ discard block |
||
486 | 486 | //pdump($filter, 'Выбираем ' . $location_type); |
487 | 487 | $query_cache = &static::$queries[$location_type][$filter]; |
488 | 488 | |
489 | - if(!isset($query_cache) || $query_cache === null) { |
|
489 | + if (!isset($query_cache) || $query_cache === null) { |
|
490 | 490 | // pdump($filter, 'Кэш пустой, начинаем возню'); |
491 | 491 | $location_info = &static::$location_info[$location_type]; |
492 | 492 | $id_field = $location_info[P_ID]; |
493 | 493 | $query_cache = array(); |
494 | 494 | |
495 | - if(static::db_transaction_check(false)) { |
|
495 | + if (static::db_transaction_check(false)) { |
|
496 | 496 | //pdump($filter, 'Транзакция - блокируем ' . $location_type); |
497 | 497 | // Проходим по всем родителям данной записи |
498 | 498 | // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data) |
499 | - foreach($location_info[P_OWNER_INFO] as $owner_data) { |
|
499 | + foreach ($location_info[P_OWNER_INFO] as $owner_data) { |
|
500 | 500 | $owner_location_type = $owner_data[P_LOCATION]; |
501 | 501 | //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type); |
502 | 502 | $parent_id_list = array(); |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | ($fetch ? ' LIMIT 1' : ''), false, true); |
510 | 510 | |
511 | 511 | //pdump($q, 'Запрос блокировки'); |
512 | - while($row = db_fetch($query)) { |
|
512 | + while ($row = db_fetch($query)) { |
|
513 | 513 | // Исключаем из списка родительских ИД уже заблокированные записи |
514 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
514 | + if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
515 | 515 | $parent_id_list[$row['parent_id']] = $row['parent_id']; |
516 | 516 | } |
517 | 517 | } |
518 | 518 | //pdump($parent_id_list, 'Выбраны родители'); |
519 | 519 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
520 | - if($indexes_str = implode(',', $parent_id_list)) { |
|
520 | + if ($indexes_str = implode(',', $parent_id_list)) { |
|
521 | 521 | //pdump($indexes_str, '$indexes_str'); |
522 | 522 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
523 | 523 | static::db_get_record_list($owner_location_type, |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . |
533 | 533 | (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
534 | 534 | ); |
535 | - while($row = db_fetch($query)) { |
|
535 | + while ($row = db_fetch($query)) { |
|
536 | 536 | // static::db_get_record_by_id($location_type, $row[$id_field]); |
537 | 537 | static::cache_set($location_type, $row[$id_field], $row); |
538 | 538 | $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]]; |
@@ -540,14 +540,14 @@ discard block |
||
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | - if($no_return) { |
|
543 | + if ($no_return) { |
|
544 | 544 | return true; |
545 | 545 | } else { |
546 | 546 | $result = false; |
547 | - if(is_array($query_cache)) { |
|
548 | - foreach($query_cache as $key => $value) { |
|
547 | + if (is_array($query_cache)) { |
|
548 | + foreach ($query_cache as $key => $value) { |
|
549 | 549 | $result[$key] = $value; |
550 | - if($fetch) { |
|
550 | + if ($fetch) { |
|
551 | 551 | break; |
552 | 552 | } |
553 | 553 | } |
@@ -566,16 +566,16 @@ discard block |
||
566 | 566 | */ |
567 | 567 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
568 | 568 | //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false; |
569 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
569 | + if (!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
570 | 570 | return false; |
571 | 571 | } |
572 | 572 | |
573 | 573 | $location_info = &static::$location_info[$location_type]; |
574 | 574 | $id_field = $location_info[P_ID]; |
575 | 575 | $table_name = $location_info[P_TABLE_NAME]; |
576 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
576 | + if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
577 | 577 | { |
578 | - if(static::$db->db_affected_rows()) { |
|
578 | + if (static::$db->db_affected_rows()) { |
|
579 | 579 | // Обновляем данные только если ряд был затронут |
580 | 580 | // TODO - переделать под работу со структурированными $set |
581 | 581 | |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | } |
592 | 592 | |
593 | 593 | public static function db_upd_record_list($location_type, $condition, $set) { |
594 | - if(!($set = trim($set))) { |
|
594 | + if (!($set = trim($set))) { |
|
595 | 595 | return false; |
596 | 596 | } |
597 | 597 | |
@@ -600,9 +600,9 @@ discard block |
||
600 | 600 | |
601 | 601 | //static::db_get_record_list($location_type, $condition, false, true); |
602 | 602 | |
603 | - if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
603 | + if ($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
604 | 604 | |
605 | - if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
605 | + if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
606 | 606 | // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью |
607 | 607 | // TODO - когда будет структурированный $condition и $set - перепаковывать данные |
608 | 608 | static::cache_clear($location_type, true); |
@@ -621,8 +621,8 @@ discard block |
||
621 | 621 | public static function db_ins_record($location_type, $set) { |
622 | 622 | $set = trim($set); |
623 | 623 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
624 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
625 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
624 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
625 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
626 | 626 | { |
627 | 627 | $record_id = db_insert_id(); |
628 | 628 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -644,8 +644,8 @@ discard block |
||
644 | 644 | $fields = implode(',', array_keys($field_set)); |
645 | 645 | |
646 | 646 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
647 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
648 | - if(static::$db->db_affected_rows()) { |
|
647 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
648 | + if (static::$db->db_affected_rows()) { |
|
649 | 649 | // Обновляем данные только если ряд был затронут |
650 | 650 | $record_id = db_insert_id(); |
651 | 651 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -661,15 +661,15 @@ discard block |
||
661 | 661 | |
662 | 662 | public static function db_del_record_by_id($location_type, $safe_record_id) { |
663 | 663 | // if(!($safe_record_id = intval($safe_record_id))) return false; |
664 | - if(!($safe_record_id = idval($safe_record_id))) { |
|
664 | + if (!($safe_record_id = idval($safe_record_id))) { |
|
665 | 665 | return false; |
666 | 666 | } |
667 | 667 | |
668 | 668 | $location_info = &static::$location_info[$location_type]; |
669 | 669 | $id_field = $location_info[P_ID]; |
670 | 670 | $table_name = $location_info[P_TABLE_NAME]; |
671 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
672 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
671 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
672 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
673 | 673 | { |
674 | 674 | static::cache_unset($location_type, $safe_record_id); |
675 | 675 | } |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | } |
680 | 680 | |
681 | 681 | public static function db_del_record_list($location_type, $condition) { |
682 | - if(!($condition = trim($condition))) { |
|
682 | + if (!($condition = trim($condition))) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | 685 | |
@@ -688,8 +688,8 @@ discard block |
||
688 | 688 | |
689 | 689 | //static::db_get_record_list($location_type, $condition, false, true); |
690 | 690 | |
691 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
692 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
691 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
692 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
693 | 693 | { |
694 | 694 | // Обнуление кэша, потому что непонятно, что поменялось |
695 | 695 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
@@ -736,20 +736,20 @@ discard block |
||
736 | 736 | |
737 | 737 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
738 | 738 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
739 | - if(!($username_unsafe = trim($username_unsafe))) { |
|
739 | + if (!($username_unsafe = trim($username_unsafe))) { |
|
740 | 740 | return false; |
741 | 741 | } |
742 | 742 | |
743 | 743 | $user = null; |
744 | - if(is_array(static::$data[LOC_USER])) { |
|
745 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
746 | - if(is_array($user_data) && isset($user_data['username'])) { |
|
744 | + if (is_array(static::$data[LOC_USER])) { |
|
745 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
746 | + if (is_array($user_data) && isset($user_data['username'])) { |
|
747 | 747 | // проверяем поле |
748 | 748 | // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить! |
749 | - if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
749 | + if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
750 | 750 | // $user_as_ally = intval($user_data['user_as_ally']); |
751 | 751 | $user_as_ally = idval($user_data['user_as_ally']); |
752 | - if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
752 | + if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
753 | 753 | $user = $user_data; |
754 | 754 | break; |
755 | 755 | } |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
761 | - if($user === null) { |
|
761 | + if ($user === null) { |
|
762 | 762 | // Вытаскиваем запись |
763 | 763 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
764 | 764 | |
@@ -776,17 +776,17 @@ discard block |
||
776 | 776 | |
777 | 777 | // UNUSED |
778 | 778 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
779 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
779 | + if (!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
780 | 780 | return false; |
781 | 781 | } |
782 | 782 | |
783 | 783 | $user = null; |
784 | 784 | // TODO переделать на индексы |
785 | - if(is_array(static::$data[LOC_USER])) { |
|
786 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
787 | - if(is_array($user_data) && isset($user_data['email_2'])) { |
|
785 | + if (is_array(static::$data[LOC_USER])) { |
|
786 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
787 | + if (is_array($user_data) && isset($user_data['email_2'])) { |
|
788 | 788 | // проверяем поле |
789 | - if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
789 | + if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
790 | 790 | $user = $user_data; |
791 | 791 | break; |
792 | 792 | } |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | } |
795 | 795 | } |
796 | 796 | |
797 | - if($user === null) { |
|
797 | + if ($user === null) { |
|
798 | 798 | // Вытаскиваем запись |
799 | 799 | $email_safe = db_escape($email_unsafe); |
800 | 800 | $user = static::db_query( |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | $user = null; |
814 | 814 | // TODO переделать на индексы |
815 | 815 | |
816 | - if($user === null && !empty($where_safe)) { |
|
816 | + if ($user === null && !empty($where_safe)) { |
|
817 | 817 | // Вытаскиваем запись |
818 | 818 | $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true); |
819 | 819 | |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') { |
836 | 836 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
837 | 837 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
838 | - if(is_array($unit)) { |
|
838 | + if (is_array($unit)) { |
|
839 | 839 | static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
840 | 840 | } |
841 | 841 | |
@@ -851,15 +851,15 @@ discard block |
||
851 | 851 | */ |
852 | 852 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) { |
853 | 853 | //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false; |
854 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
854 | + if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
855 | 855 | return false; |
856 | 856 | } |
857 | 857 | |
858 | 858 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
859 | - if(!isset($query_cache)) { |
|
859 | + if (!isset($query_cache)) { |
|
860 | 860 | $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions()); |
861 | - if(is_array($got_data)) { |
|
862 | - foreach($got_data as $unit_id => $unit_data) { |
|
861 | + if (is_array($got_data)) { |
|
862 | + foreach ($got_data as $unit_id => $unit_data) { |
|
863 | 863 | // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
864 | 864 | $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
865 | 865 | } |
@@ -867,8 +867,8 @@ discard block |
||
867 | 867 | } |
868 | 868 | |
869 | 869 | $result = false; |
870 | - if(is_array($query_cache)) { |
|
871 | - foreach($query_cache as $key => $value) { |
|
870 | + if (is_array($query_cache)) { |
|
871 | + foreach ($query_cache as $key => $value) { |
|
872 | 872 | $result[$key] = $value; |
873 | 873 | } |
874 | 874 | } |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | * |
904 | 904 | */ |
905 | 905 | public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) { |
906 | - if(!$user_id) { |
|
906 | + if (!$user_id) { |
|
907 | 907 | pdump(debug_backtrace()); |
908 | 908 | die('No user_id for que_get_que()'); |
909 | 909 | } |
@@ -913,16 +913,16 @@ discard block |
||
913 | 913 | $query = array(); |
914 | 914 | |
915 | 915 | // if($user_id = intval($user_id)) |
916 | - if($user_id = idval($user_id)) { |
|
916 | + if ($user_id = idval($user_id)) { |
|
917 | 917 | $query[] = "`que_player_id` = {$user_id}"; |
918 | 918 | } |
919 | 919 | |
920 | - if($que_type == QUE_RESEARCH || $planet_id === null) { |
|
920 | + if ($que_type == QUE_RESEARCH || $planet_id === null) { |
|
921 | 921 | $query[] = "`que_planet_id` IS NULL"; |
922 | - } elseif($planet_id) { |
|
922 | + } elseif ($planet_id) { |
|
923 | 923 | $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
924 | 924 | } |
925 | - if($que_type) { |
|
925 | + if ($que_type) { |
|
926 | 926 | $query[] = "`que_type` = {$que_type}"; |
927 | 927 | } |
928 | 928 | |
@@ -955,13 +955,13 @@ discard block |
||
955 | 955 | |
956 | 956 | |
957 | 957 | public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) { |
958 | - if(!is_array($user)) { |
|
958 | + if (!is_array($user)) { |
|
959 | 959 | // TODO - remove later |
960 | 960 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
961 | 961 | pdump(debug_backtrace()); |
962 | 962 | die('USER is not ARRAY'); |
963 | 963 | } |
964 | - if(!isset($user['id']) || !$user['id']) { |
|
964 | + if (!isset($user['id']) || !$user['id']) { |
|
965 | 965 | // TODO - remove later |
966 | 966 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
967 | 967 | pdump($user); |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | |
977 | 977 | $db_changeset = array(); |
978 | 978 | $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
979 | - if($temp['unit_id']) { |
|
979 | + if ($temp['unit_id']) { |
|
980 | 980 | $db_changeset = array( |
981 | 981 | 'action' => SQL_OP_UPDATE, |
982 | 982 | P_VERSION => 1, |
@@ -1045,9 +1045,9 @@ discard block |
||
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | public function db_changeset_condition_compile(&$conditions, &$table_name = '') { |
1048 | - if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1048 | + if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1049 | 1049 | $conditions[P_LOCATION] = LOC_NONE; |
1050 | - switch($table_name) { |
|
1050 | + switch ($table_name) { |
|
1051 | 1051 | case 'users': |
1052 | 1052 | case LOC_USER: |
1053 | 1053 | $conditions[P_TABLE_NAME] = $table_name = 'users'; |
@@ -1069,18 +1069,18 @@ discard block |
||
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | $conditions[P_FIELDS_STR] = ''; |
1072 | - if($conditions['fields']) { |
|
1072 | + if ($conditions['fields']) { |
|
1073 | 1073 | $fields = array(); |
1074 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
1074 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
1075 | 1075 | $condition = "`{$field_name}` = "; |
1076 | 1076 | $value = ''; |
1077 | - if($field_data['delta']) { |
|
1077 | + if ($field_data['delta']) { |
|
1078 | 1078 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
1079 | - } elseif($field_data['set']) { |
|
1079 | + } elseif ($field_data['set']) { |
|
1080 | 1080 | $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - if($value) { |
|
1083 | + if ($value) { |
|
1084 | 1084 | $fields[] = $condition . $value; |
1085 | 1085 | } |
1086 | 1086 | } |
@@ -1088,16 +1088,14 @@ discard block |
||
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | $conditions[P_WHERE_STR] = ''; |
1091 | - if(!empty($conditions['where'])) { |
|
1092 | - if($conditions[P_VERSION] == 1) { |
|
1091 | + if (!empty($conditions['where'])) { |
|
1092 | + if ($conditions[P_VERSION] == 1) { |
|
1093 | 1093 | $the_conditions = array(); |
1094 | - foreach($conditions['where'] as $field_id => $field_value) { |
|
1094 | + foreach ($conditions['where'] as $field_id => $field_value) { |
|
1095 | 1095 | // Простое условие - $field_id = $field_value |
1096 | - if(is_string($field_id)) { |
|
1096 | + if (is_string($field_id)) { |
|
1097 | 1097 | $field_value = |
1098 | - $field_value === null ? 'NULL' : |
|
1099 | - (is_string($field_value) ? "'" . db_escape($field_value) . "'" : |
|
1100 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1098 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1101 | 1099 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
1102 | 1100 | } else { |
1103 | 1101 | die('Неподдерживаемый тип условия'); |
@@ -1114,7 +1112,7 @@ discard block |
||
1114 | 1112 | $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions); |
1115 | 1113 | } |
1116 | 1114 | |
1117 | - switch($conditions['action']) { |
|
1115 | + switch ($conditions['action']) { |
|
1118 | 1116 | case SQL_OP_DELETE: |
1119 | 1117 | $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); |
1120 | 1118 | break; |
@@ -1134,11 +1132,11 @@ discard block |
||
1134 | 1132 | |
1135 | 1133 | public static function db_changeset_apply($db_changeset, $flush_delayed = false) { |
1136 | 1134 | $result = true; |
1137 | - if(!is_array($db_changeset) || empty($db_changeset)) { |
|
1135 | + if (!is_array($db_changeset) || empty($db_changeset)) { |
|
1138 | 1136 | return $result; |
1139 | 1137 | } |
1140 | 1138 | |
1141 | - foreach($db_changeset as $table_name => &$table_data) { |
|
1139 | + foreach ($db_changeset as $table_name => &$table_data) { |
|
1142 | 1140 | // TODO - delayed changeset |
1143 | 1141 | /* |
1144 | 1142 | if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit')) |
@@ -1147,19 +1145,19 @@ discard block |
||
1147 | 1145 | continue; |
1148 | 1146 | } |
1149 | 1147 | */ |
1150 | - foreach($table_data as $record_id => &$conditions) { |
|
1148 | + foreach ($table_data as $record_id => &$conditions) { |
|
1151 | 1149 | static::db_changeset_condition_compile($conditions, $table_name); |
1152 | 1150 | |
1153 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
1151 | + if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
1154 | 1152 | continue; |
1155 | 1153 | } |
1156 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
1154 | + if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
1157 | 1155 | continue; |
1158 | 1156 | } // Защита от случайного удаления всех данных в таблице |
1159 | 1157 | |
1160 | - if($conditions[P_LOCATION] != LOC_NONE) { |
|
1158 | + if ($conditions[P_LOCATION] != LOC_NONE) { |
|
1161 | 1159 | //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд'); |
1162 | - switch($conditions['action']) { |
|
1160 | + switch ($conditions['action']) { |
|
1163 | 1161 | case SQL_OP_DELETE: |
1164 | 1162 | $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; |
1165 | 1163 | break; |
@@ -1241,13 +1239,13 @@ discard block |
||
1241 | 1239 | public static function init_0_prepare() { |
1242 | 1240 | // Отключаем magic_quotes |
1243 | 1241 | ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false; |
1244 | - if(@get_magic_quotes_gpc()) { |
|
1242 | + if (@get_magic_quotes_gpc()) { |
|
1245 | 1243 | $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); |
1246 | - array_walk_recursive($gpcr, function (&$value, $key) { |
|
1244 | + array_walk_recursive($gpcr, function(&$value, $key) { |
|
1247 | 1245 | $value = stripslashes($value); |
1248 | 1246 | }); |
1249 | 1247 | } |
1250 | - if(function_exists('set_magic_quotes_runtime')) { |
|
1248 | + if (function_exists('set_magic_quotes_runtime')) { |
|
1251 | 1249 | @set_magic_quotes_runtime(0); |
1252 | 1250 | @ini_set('magic_quotes_runtime', 0); |
1253 | 1251 | @ini_set('magic_quotes_sybase', 0); |
@@ -1325,7 +1323,7 @@ discard block |
||
1325 | 1323 | } |
1326 | 1324 | |
1327 | 1325 | public static function init_debug_state() { |
1328 | - if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1326 | + if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1329 | 1327 | define('BE_DEBUG', true); |
1330 | 1328 | } |
1331 | 1329 | // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение |
@@ -1337,7 +1335,7 @@ discard block |
||
1337 | 1335 | defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1338 | 1336 | defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1339 | 1337 | |
1340 | - if(defined('BE_DEBUG') || static::$config->debug) { |
|
1338 | + if (defined('BE_DEBUG') || static::$config->debug) { |
|
1341 | 1339 | @define('BE_DEBUG', true); |
1342 | 1340 | @ini_set('display_errors', 1); |
1343 | 1341 | @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
@@ -573,7 +573,8 @@ discard block |
||
573 | 573 | $location_info = &static::$location_info[$location_type]; |
574 | 574 | $id_field = $location_info[P_ID]; |
575 | 575 | $table_name = $location_info[P_TABLE_NAME]; |
576 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
576 | + if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) { |
|
577 | + // TODO Как-то вернуть может быть LIMIT 1 ? |
|
577 | 578 | { |
578 | 579 | if(static::$db->db_affected_rows()) { |
579 | 580 | // Обновляем данные только если ряд был затронут |
@@ -581,6 +582,7 @@ discard block |
||
581 | 582 | |
582 | 583 | // Тут именно так, а не cache_unset - что бы в кэшах автоматически обновилась запись. Будет нужно на будущее |
583 | 584 | static::$data[$location_type][$record_id] = null; |
585 | + } |
|
584 | 586 | // Вытаскиваем обновленную запись |
585 | 587 | static::db_get_record_by_id($location_type, $record_id); |
586 | 588 | static::cache_clear($location_type, false); // Мягкий сброс - только $queries |
@@ -622,9 +624,11 @@ discard block |
||
622 | 624 | $set = trim($set); |
623 | 625 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
624 | 626 | if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
625 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
627 | + if(static::$db->db_affected_rows()) { |
|
628 | + // Обновляем данные только если ряд был затронут |
|
626 | 629 | { |
627 | 630 | $record_id = db_insert_id(); |
631 | + } |
|
628 | 632 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
629 | 633 | $result = static::db_get_record_by_id($location_type, $record_id); |
630 | 634 | // Очищаем второстепенные кэши - потому что вставленная запись могла повлиять на результаты запросов или локация или еще чего |
@@ -669,10 +673,12 @@ discard block |
||
669 | 673 | $id_field = $location_info[P_ID]; |
670 | 674 | $table_name = $location_info[P_TABLE_NAME]; |
671 | 675 | if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
672 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
676 | + if(static::$db->db_affected_rows()) { |
|
677 | + // Обновляем данные только если ряд был затронут |
|
673 | 678 | { |
674 | 679 | static::cache_unset($location_type, $safe_record_id); |
675 | 680 | } |
681 | + } |
|
676 | 682 | } |
677 | 683 | |
678 | 684 | return $result; |
@@ -689,12 +695,14 @@ discard block |
||
689 | 695 | //static::db_get_record_list($location_type, $condition, false, true); |
690 | 696 | |
691 | 697 | if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
692 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
698 | + if(static::$db->db_affected_rows()) { |
|
699 | + // Обновляем данные только если ряд был затронут |
|
693 | 700 | { |
694 | 701 | // Обнуление кэша, потому что непонятно, что поменялось |
695 | 702 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
696 | 703 | static::cache_clear($location_type); |
697 | 704 | } |
705 | + } |
|
698 | 706 | } |
699 | 707 | |
700 | 708 | return $result; |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * Преобразовывает данные симулятора в данные для расчета боя |
465 | 465 | * |
466 | 466 | * @param $side_info |
467 | - * @param $attacker |
|
467 | + * @param boolean $attacker |
|
468 | 468 | * @param int $player_id |
469 | 469 | * |
470 | 470 | * @version 41a6.22 |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
575 | - * @param $template |
|
575 | + * @param null|template $template |
|
576 | 576 | * |
577 | 577 | * @return template |
578 | 578 | */ |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $this->players->db_load_player_by_id($player_id, UBE_PLAYER_IS_DEFENDER); |
148 | 148 | |
149 | 149 | $player_db_row = $this->players[$player_id]->getDbRow(); |
150 | - if($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
150 | + if ($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
151 | 151 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $fortifier_level); |
152 | 152 | } |
153 | 153 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $this->rounds[0] = new UBERound(0); |
180 | 180 | $this->rounds[0]->make_snapshot($this->fleet_list); |
181 | 181 | |
182 | - for($round = 1; $round <= 10; $round++) { |
|
182 | + for ($round = 1; $round <= 10; $round++) { |
|
183 | 183 | // Проводим раунд |
184 | 184 | defined('DEBUG_UBE') ? print("Round {$round}<br>") : false; |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | // Анализируем итоги текущего раунда и готовим данные для следующего |
194 | 194 | $this->combat_result = $this->fleet_list->ubeAnalyzeFleetOutcome($round); |
195 | - if($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
195 | + if ($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
196 | 196 | break; |
197 | 197 | } |
198 | 198 | |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | // Генерируем результат боя |
222 | 222 | $this->fleet_list->ube_analyze_fleets($this->is_simulator, $this->debris, $this->resource_exchange_rates); |
223 | 223 | |
224 | - if(!$this->is_ube_loaded) { |
|
224 | + if (!$this->is_ube_loaded) { |
|
225 | 225 | $this->moon_calculator->calculate_moon($this); |
226 | 226 | |
227 | 227 | // Лутаем ресурсы - если аттакер выиграл |
228 | - if($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
228 | + if ($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
229 | 229 | $this->sn_ube_combat_analyze_loot(); |
230 | 230 | } |
231 | 231 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | RES_DEUTERIUM => 0, |
246 | 246 | ); |
247 | 247 | |
248 | - if( |
|
248 | + if ( |
|
249 | 249 | (($planet_resource_total = $this->fleet_list[0]->get_resources_amount()) > 0) |
250 | 250 | && |
251 | 251 | (($total_capacity = $this->fleet_list->ube_get_capacity_attackers()) > 0) |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | $planet_lootable_percent = $planet_lootable / $planet_resource_total; |
258 | 258 | |
259 | 259 | // Вычисляем сколько ресурсов вывезено |
260 | - foreach($this->fleet_list->_container as $fleet_id => $fleet) { |
|
260 | + foreach ($this->fleet_list->_container as $fleet_id => $fleet) { |
|
261 | 261 | $looted_in_metal = 0; |
262 | - foreach($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
262 | + foreach ($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
263 | 263 | // Вычисляем какой процент общей емкости трюмов атакующих будет задействован |
264 | 264 | $fleet_lootable_percent = $fleet->fleet_capacity / $total_capacity; |
265 | 265 | $looted = floor($resource_amount * $planet_lootable_percent * $fleet_lootable_percent); |
@@ -325,16 +325,16 @@ discard block |
||
325 | 325 | $destination_user_id = $this->fleet_list[0]->owner_id; |
326 | 326 | |
327 | 327 | // Обновляем поле обломков на планете |
328 | - if(!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
328 | + if (!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
329 | 329 | db_planet_set_by_gspt($this->ube_planet_info[PLANET_GALAXY], $this->ube_planet_info[PLANET_SYSTEM], $this->ube_planet_info[PLANET_PLANET], PT_PLANET, |
330 | 330 | "`debris_metal` = `debris_metal` + " . $this->debris->debris_get_resource(RES_METAL) . ", `debris_crystal` = `debris_crystal` + " . $this->debris->debris_get_resource(RES_CRYSTAL) |
331 | 331 | ); |
332 | 332 | } |
333 | 333 | |
334 | - foreach($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
334 | + foreach ($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
335 | 335 | $ship_count_lost = $UBEFleet->unit_list->unitCountLost(); |
336 | 336 | |
337 | - if($fleet_id) { |
|
337 | + if ($fleet_id) { |
|
338 | 338 | // Флот |
339 | 339 | $UBEFleet->db_save_combat_result_fleet($this->is_small_fleet_recce, $this->moon_calculator->get_reapers_status()); |
340 | 340 | } else { |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | |
343 | 343 | // Сохраняем изменения ресурсов - если они есть |
344 | 344 | $resource_delta = $UBEFleet->ube_combat_result_calculate_resources(); |
345 | - if(!empty($resource_delta)) { |
|
345 | + if (!empty($resource_delta)) { |
|
346 | 346 | $temp = array(); |
347 | - foreach($resource_delta as $resource_id => $resource_amount) { |
|
347 | + foreach ($resource_delta as $resource_id => $resource_amount) { |
|
348 | 348 | $resource_db_name = pname_resource_name($resource_id); |
349 | 349 | $temp[] = "`{$resource_db_name}` = `{$resource_db_name}` + ({$resource_amount})"; |
350 | 350 | } |
351 | 351 | db_planet_set_by_id($this->ube_planet_info[PLANET_ID], implode(',', $temp)); |
352 | 352 | } |
353 | 353 | |
354 | - if($ship_count_lost) { |
|
354 | + if ($ship_count_lost) { |
|
355 | 355 | $db_changeset = array(); |
356 | 356 | $planet_row_cache = $this->players[$destination_user_id]->getDbRow(); |
357 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
357 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
358 | 358 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($UBEUnit->unitId, -$UBEUnit->units_lost, $planet_row_cache, $this->ube_planet_info[PLANET_ID]); |
359 | 359 | } |
360 | 360 | db_changeset_apply($db_changeset); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL |
366 | 366 | // Для САБов |
367 | 367 | $fleet_group_id_list = $this->fleet_list->ube_get_groups(); |
368 | - if(!empty($fleet_group_id_list)) { |
|
368 | + if (!empty($fleet_group_id_list)) { |
|
369 | 369 | $fleet_group_id_list = implode(',', $fleet_group_id_list); |
370 | 370 | db_acs_delete_by_list($fleet_group_id_list); |
371 | 371 | } |
@@ -374,19 +374,19 @@ discard block |
||
374 | 374 | |
375 | 375 | $bashing_list = array(); |
376 | 376 | $players_sides = $this->players->get_player_sides(); |
377 | - foreach($players_sides as $player_id => $player_side) { |
|
378 | - if($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
377 | + foreach ($players_sides as $player_id => $player_side) { |
|
378 | + if ($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
379 | 379 | continue; |
380 | 380 | } |
381 | - if($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
381 | + if ($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
382 | 382 | $bashing_list[] = "({$player_id}, {$this->ube_planet_info[PLANET_ID]}, {$this->combat_timestamp})"; |
383 | 383 | } |
384 | - if($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
384 | + if ($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
385 | 385 | $str_loose_or_win = $this->combat_result == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose'; |
386 | 386 | db_user_set_by_id($player_id, "`xpraid` = `xpraid` + 1, `raids` = `raids` + 1, `{$str_loose_or_win}` = `{$str_loose_or_win}` + 1"); |
387 | 387 | } |
388 | 388 | } |
389 | - if(!empty($bashing_list)) { |
|
389 | + if (!empty($bashing_list)) { |
|
390 | 390 | $bashing_list = implode(',', $bashing_list); |
391 | 391 | db_bashing_insert($bashing_list); |
392 | 392 | } |
@@ -413,20 +413,19 @@ discard block |
||
413 | 413 | $planet_info[PLANET_SYSTEM], |
414 | 414 | $planet_info[PLANET_PLANET], |
415 | 415 | htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'), |
416 | - $lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : |
|
417 | - ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
416 | + $lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
418 | 417 | ); |
419 | 418 | |
420 | 419 | $text_defender = ''; |
421 | 420 | $debris = $this->debris->get_debris(); |
422 | - foreach($debris as $resource_id => $resource_amount) { |
|
423 | - if($resource_id == RES_DEUTERIUM) { |
|
421 | + foreach ($debris as $resource_id => $resource_amount) { |
|
422 | + if ($resource_id == RES_DEUTERIUM) { |
|
424 | 423 | continue; |
425 | 424 | } |
426 | 425 | |
427 | 426 | $text_defender .= "{$lang['tech'][$resource_id]}: " . pretty_number($resource_amount) . '<br />'; |
428 | 427 | } |
429 | - if($text_defender) { |
|
428 | + if ($text_defender) { |
|
430 | 429 | $text_defender = "{$lang['ube_report_msg_body_debris']}{$text_defender}<br />"; |
431 | 430 | } |
432 | 431 | |
@@ -436,7 +435,7 @@ discard block |
||
436 | 435 | |
437 | 436 | // TODO: Оптимизировать отсылку сообщений - отсылать пакетами |
438 | 437 | $player_sides = $this->players->get_player_sides(); |
439 | - foreach($player_sides as $player_id => $player_side) { |
|
438 | + foreach ($player_sides as $player_id => $player_side) { |
|
440 | 439 | $message = $text_common . ($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? $lang['ube_report_msg_body_sfr'] : $text_defender); |
441 | 440 | msg_send_simple_message($player_id, '', $this->combat_timestamp, MSG_TYPE_COMBAT, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $message); |
442 | 441 | } |
@@ -473,11 +472,11 @@ discard block |
||
473 | 472 | $player_id = $player_id == -1 ? $this->players->count() : $player_id; |
474 | 473 | $fleet_id = $player_id; // FOR SIMULATOR! |
475 | 474 | |
476 | - if(empty($this->players[$player_id])) { |
|
475 | + if (empty($this->players[$player_id])) { |
|
477 | 476 | $this->players[$player_id] = new UBEPlayer(); |
478 | 477 | } |
479 | 478 | |
480 | - foreach($side_info as $fleet_data) { |
|
479 | + foreach ($side_info as $fleet_data) { |
|
481 | 480 | $this->players[$player_id]->name = $player_id; |
482 | 481 | $this->players[$player_id]->setSide($attacker); |
483 | 482 | |
@@ -485,32 +484,32 @@ discard block |
||
485 | 484 | $this->fleet_list[$fleet_id] = $objFleet; |
486 | 485 | |
487 | 486 | $this->fleet_list[$fleet_id]->owner_id = $player_id; |
488 | - foreach($fleet_data as $unit_id => $unit_count) { |
|
489 | - if(!$unit_count) { |
|
487 | + foreach ($fleet_data as $unit_id => $unit_count) { |
|
488 | + if (!$unit_count) { |
|
490 | 489 | continue; |
491 | 490 | } |
492 | 491 | |
493 | 492 | $unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
494 | 493 | |
495 | - if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
494 | + if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
496 | 495 | $this->fleet_list[$fleet_id]->unit_list->unitAdjustCount($unit_id, $unit_count); |
497 | - } elseif($unit_type == UNIT_RESOURCES) { |
|
496 | + } elseif ($unit_type == UNIT_RESOURCES) { |
|
498 | 497 | $this->fleet_list[$fleet_id]->resource_list[$unit_id] = $unit_count; |
499 | - } elseif($unit_type == UNIT_TECHNOLOGIES) { |
|
500 | - if($unit_id == TECH_WEAPON) { |
|
498 | + } elseif ($unit_type == UNIT_TECHNOLOGIES) { |
|
499 | + if ($unit_id == TECH_WEAPON) { |
|
501 | 500 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_WEAPON, $unit_count); |
502 | - } elseif($unit_id == TECH_SHIELD) { |
|
501 | + } elseif ($unit_id == TECH_SHIELD) { |
|
503 | 502 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_SHIELD, $unit_count); |
504 | - } elseif($unit_id == TECH_ARMOR) { |
|
503 | + } elseif ($unit_id == TECH_ARMOR) { |
|
505 | 504 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_ARMOR, $unit_count); |
506 | 505 | } |
507 | - } elseif($unit_type == UNIT_GOVERNORS) { |
|
508 | - if($unit_id == MRC_FORTIFIER) { |
|
506 | + } elseif ($unit_type == UNIT_GOVERNORS) { |
|
507 | + if ($unit_id == MRC_FORTIFIER) { |
|
509 | 508 | // Фортифаер даёт бонус ко всему |
510 | 509 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $unit_count); |
511 | 510 | } |
512 | - } elseif($unit_type == UNIT_MERCENARIES) { |
|
513 | - if($unit_id == MRC_ADMIRAL) { |
|
511 | + } elseif ($unit_type == UNIT_MERCENARIES) { |
|
512 | + if ($unit_id == MRC_ADMIRAL) { |
|
514 | 513 | $this->players[$player_id]->player_bonus->add_unit_by_snid(MRC_ADMIRAL, $unit_count); |
515 | 514 | } |
516 | 515 | } |
@@ -581,7 +580,7 @@ discard block |
||
581 | 580 | |
582 | 581 | $ube_report = new UBEReport(); |
583 | 582 | $ube = $ube_report->sn_ube_report_load(sys_get_param_str('cypher')); |
584 | - if($ube != UBE_REPORT_NOT_FOUND) { |
|
583 | + if ($ube != UBE_REPORT_NOT_FOUND) { |
|
585 | 584 | $ube_report->sn_ube_report_generate($ube, $template_result); |
586 | 585 | |
587 | 586 | $template = gettemplate('ube_combat_report', $template); |
@@ -614,9 +613,9 @@ discard block |
||
614 | 613 | // sn_ube_report_save($combat_data); |
615 | 614 | // } |
616 | 615 | |
617 | - if(sys_get_param_str('reload')) { |
|
616 | + if (sys_get_param_str('reload')) { |
|
618 | 617 | $ube_new = $ube_report->sn_ube_report_load($ube->get_cypher()); // $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]); |
619 | - if($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
618 | + if ($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
620 | 619 | $ube = $ube_new; |
621 | 620 | } |
622 | 621 | } |
@@ -664,7 +663,7 @@ discard block |
||
664 | 663 | $this->debris->load_from_report_row($report_row); |
665 | 664 | |
666 | 665 | $query = doquery("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
667 | - while($player_row = db_fetch($query)) { |
|
666 | + while ($player_row = db_fetch($query)) { |
|
668 | 667 | $this->players->init_player_from_report_info($player_row); |
669 | 668 | } |
670 | 669 |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @param $moon_debris_left_part |
|
96 | + * @param double $moon_debris_left_part |
|
97 | 97 | */ |
98 | 98 | public function debris_adjust_proportional($moon_debris_left_part) { |
99 | 99 | foreach($this->debris as $resource_id => &$resource_amount) { |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @param classConfig $config |
106 | 106 | * |
107 | - * @return int |
|
107 | + * @return double |
|
108 | 108 | */ |
109 | 109 | public function debris_in_metal($config) { |
110 | 110 | return floatval( |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function debris_add_resource($resource_id, $resource_amount) { |
32 | 32 | // В обломках может быть только металл или кристалл |
33 | - if($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
33 | + if ($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | $this->debris[$resource_id] += $resource_amount; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param bool $is_simulator |
42 | 42 | */ |
43 | 43 | public function add_wrecks(array $wreckage, $is_simulator) { |
44 | - foreach($wreckage as $resource_id => $resource_amount) { |
|
44 | + foreach ($wreckage as $resource_id => $resource_amount) { |
|
45 | 45 | $this->debris_add_resource($resource_id, floor($resource_amount * |
46 | 46 | ($is_simulator |
47 | 47 | ? UBE_SHIP_WRECKS_TO_DEBRIS_AVG |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param bool $is_simulator |
58 | 58 | */ |
59 | 59 | public function add_cargo_drop(array $dropped_resources, $is_simulator) { |
60 | - foreach($dropped_resources as $resource_id => $resource_amount) { |
|
60 | + foreach ($dropped_resources as $resource_id => $resource_amount) { |
|
61 | 61 | $this->debris_add_resource($resource_id, floor($resource_amount * |
62 | 62 | ($is_simulator |
63 | 63 | ? UBE_CARGO_DROPPED_TO_DEBRIS_AVG |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param $moon_debris_left_part |
97 | 97 | */ |
98 | 98 | public function debris_adjust_proportional($moon_debris_left_part) { |
99 | - foreach($this->debris as $resource_id => &$resource_amount) { |
|
99 | + foreach ($this->debris as $resource_id => &$resource_amount) { |
|
100 | 100 | $resource_amount = floor($resource_amount * $moon_debris_left_part); |
101 | 101 | } |
102 | 102 | } |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function report_generate_sql(classConfig $config) { |
123 | 123 | return " |
124 | - `ube_report_debris_metal` = " . (float)$this->debris_get_resource(RES_METAL) . ", |
|
125 | - `ube_report_debris_crystal` = " . (float)$this->debris_get_resource(RES_CRYSTAL) . ", |
|
126 | - `ube_report_debris_total_in_metal` = " . (float)$this->debris_in_metal($config) . ", "; |
|
124 | + `ube_report_debris_metal` = " . (float) $this->debris_get_resource(RES_METAL) . ", |
|
125 | + `ube_report_debris_crystal` = " . (float) $this->debris_get_resource(RES_CRYSTAL) . ", |
|
126 | + `ube_report_debris_total_in_metal` = " . (float) $this->debris_in_metal($config) . ", "; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -278,6 +278,9 @@ |
||
278 | 278 | return count($this->ube_side_present_at_round_start); |
279 | 279 | } |
280 | 280 | |
281 | + /** |
|
282 | + * @param integer $round |
|
283 | + */ |
|
281 | 284 | public function ubeAnalyzeFleetOutcome($round) { |
282 | 285 | $this->ube_actualize_sides(); |
283 | 286 |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function ube_db_load_fleets_outcome($report_row) { |
84 | 84 | $query = doquery("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
85 | - while($row = db_fetch($query)) { |
|
85 | + while ($row = db_fetch($query)) { |
|
86 | 86 | $fleet_id = $row['ube_report_outcome_fleet_fleet_id']; |
87 | 87 | $this[$fleet_id]->load_outcome_from_report_row($row); |
88 | 88 | } |
89 | 89 | |
90 | 90 | $query = doquery("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`"); |
91 | - while($row = db_fetch($query)) { |
|
91 | + while ($row = db_fetch($query)) { |
|
92 | 92 | $fleet_id = $row['ube_report_outcome_unit_fleet_id']; |
93 | 93 | $this[$fleet_id]->load_unit_outcome_from_row($row); |
94 | 94 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | UBE_PLAYER_IS_DEFENDER => array(), |
109 | 109 | ); |
110 | 110 | |
111 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
111 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
112 | 112 | $result[$UBEFleet->is_attacker][] = array( |
113 | 113 | 'ID' => $fleet_id, |
114 | 114 | 'NAME' => $ube->players[$UBEFleet->owner_id]->name, |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function ube_analyze_fleets($is_simulator, UBEDebris $debris, array $resource_exchange_rates) { |
133 | 133 | // Генерируем результат боя |
134 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
134 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
135 | 135 | // Инициализируем массив результатов для флота |
136 | 136 | // $this->init_fleet_outcome_and_link_to_side($UBEFleet); |
137 | 137 | |
138 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
138 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
139 | 139 | $UBEUnit->ube_analyze_unit($is_simulator); |
140 | 140 | } |
141 | 141 | |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | $this->resources_lost_in_metal = array( |
153 | 153 | RES_METAL => 0, |
154 | 154 | ); |
155 | - foreach($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
155 | + foreach ($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
156 | 156 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
157 | 157 | } |
158 | - foreach($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
158 | + foreach ($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
159 | 159 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
160 | 160 | } |
161 | 161 | } |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function ube_get_groups() { |
168 | 168 | $result = array(); |
169 | - foreach($this->_container as $UBEFleet) { |
|
170 | - if($UBEFleet->group_id) { |
|
169 | + foreach ($this->_container as $UBEFleet) { |
|
170 | + if ($UBEFleet->group_id) { |
|
171 | 171 | $result[$UBEFleet->group_id] = $UBEFleet->group_id; |
172 | 172 | } |
173 | 173 | } |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function ube_get_capacity_attackers() { |
182 | 182 | $result = 0; |
183 | - foreach($this->_container as $UBEFleet) { |
|
184 | - if($UBEFleet->is_attacker) { |
|
183 | + foreach ($this->_container as $UBEFleet) { |
|
184 | + if ($UBEFleet->is_attacker) { |
|
185 | 185 | $result += $UBEFleet->fleet_capacity; |
186 | 186 | } |
187 | 187 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function ube_db_load_from_report_row(array $report_row, UBE $ube) { |
197 | 197 | $query = doquery("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
198 | - while($fleet_row = db_fetch($query)) { |
|
198 | + while ($fleet_row = db_fetch($query)) { |
|
199 | 199 | $objFleet = new UBEFleet(); |
200 | 200 | $objFleet->load_from_report($fleet_row, $ube); |
201 | 201 | $this[$objFleet->db_id] = $objFleet; |
@@ -209,20 +209,20 @@ discard block |
||
209 | 209 | * @version 2016-02-25 23:42:45 41a4.68 |
210 | 210 | */ |
211 | 211 | public function ube_prepare_for_next_round($is_simulator) { |
212 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
212 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
213 | 213 | $UBEFleet->prepare_for_next_round($is_simulator); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Суммируем данные по атакующим и защитникам |
217 | 217 | $this->ube_total[UBE_PLAYER_IS_ATTACKER]->_reset(); |
218 | 218 | $this->ube_total[UBE_PLAYER_IS_DEFENDER]->_reset(); |
219 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
219 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
220 | 220 | $this->ube_total[$UBEFleet->is_attacker]->add_unit_stats_array($UBEFleet->total_stats); |
221 | 221 | } |
222 | 222 | //pvar_dump($this->ube_total); |
223 | 223 | |
224 | 224 | // Высчитываем долю атаки, приходящейся на юнит равную отношению брони юнита к общей броне - крупные цели атакуют чаще |
225 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
225 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
226 | 226 | $UBEFleet->calculate_unit_partial_data($this->ube_total[$UBEFleet->is_attacker]); |
227 | 227 | } |
228 | 228 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function ube_calculate_attack_results(UBE $ube) { |
238 | 238 | // Каждый флот атакует все |
239 | - foreach($this->_container as $attack_fleet_data) { |
|
239 | + foreach ($this->_container as $attack_fleet_data) { |
|
240 | 240 | defined('DEBUG_UBE') ? print("Fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false; |
241 | 241 | |
242 | 242 | $attack_fleet_data->attack_fleets($this, $ube->is_simulator); |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @version 2016-02-25 23:42:45 41a4.68 |
252 | 252 | */ |
253 | 253 | public function ube_actualize_sides() { |
254 | - foreach($this->_container as $UBEFleet) { |
|
255 | - if($UBEFleet->get_unit_count() > 0) { |
|
254 | + foreach ($this->_container as $UBEFleet) { |
|
255 | + if ($UBEFleet->get_unit_count() > 0) { |
|
256 | 256 | $this->ube_side_present_at_round_start[$UBEFleet->is_attacker] = 1; |
257 | 257 | } |
258 | 258 | } |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function ube_calculate_attack_reapers() { |
267 | 267 | $reapers = 0; |
268 | - foreach($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
269 | - if($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
268 | + foreach ($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
269 | + if ($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
270 | 270 | $reapers += $UBERoundFleetCombat->unit_list->unitCountReapers(); |
271 | 271 | } |
272 | 272 | } |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | |
284 | 284 | $result = UBE_COMBAT_RESULT_DRAW; |
285 | 285 | // Проверяем результат боя |
286 | - if($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
286 | + if ($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
287 | 287 | // Если кого-то не осталось или не осталось обоих - заканчиваем цикл |
288 | 288 | $result = UBE_COMBAT_RESULT_DRAW_END; |
289 | - } elseif($this->ube_get_sides_count() == 1) { |
|
289 | + } elseif ($this->ube_get_sides_count() == 1) { |
|
290 | 290 | // Если осталась одна сторона - она и выиграла |
291 | 291 | $result = isset($this->ube_side_present_at_round_start[UBE_PLAYER_IS_ATTACKER]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS; |
292 | 292 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @version 41a6.16 |
304 | 304 | */ |
305 | 305 | public function ubeInitGetAttackers(Fleet $objFleet, UBEPlayerList $players) { |
306 | - if($objFleet->group_id) { |
|
306 | + if ($objFleet->group_id) { |
|
307 | 307 | $fleets_added = $this->dbLoadWhere("`fleet_group` = {$objFleet->group_id}"); |
308 | 308 | } else { |
309 | 309 | $this->ube_insert_from_Fleet($objFleet); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @param UBE $ube |
9 | 9 | * |
10 | - * @return bool|string |
|
10 | + * @return false|string |
|
11 | 11 | * |
12 | 12 | * @version 2016-02-25 23:42:45 41a4.68 |
13 | 13 | */ |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | // ------------------------------------------------------------------------------------------------ |
187 | 187 | // Читает боевой отчет из БД |
188 | 188 | /** |
189 | - * @param $report_cypher |
|
189 | + * @param string $report_cypher |
|
190 | 190 | * |
191 | 191 | * @return string|UBE |
192 | 192 | */ |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | global $config; |
16 | 16 | |
17 | 17 | // Если уже есть ИД репорта - значит репорт был взят из таблицы. С таким мы не работаем |
18 | - if($ube->get_cypher()) { |
|
18 | + if ($ube->get_cypher()) { |
|
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | 22 | // Генерируем уникальный секретный ключ и проверяем наличие в базе |
23 | 23 | do { |
24 | 24 | $ube->report_cypher = sys_random_string(32); |
25 | - } while(doquery("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE", true)); |
|
25 | + } while (doquery("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE", true)); |
|
26 | 26 | |
27 | 27 | // Инициализация таблицы для пакетной вставки информации |
28 | 28 | $sql_perform = array( |
@@ -113,21 +113,21 @@ discard block |
||
113 | 113 | `ube_report_time_combat` = '" . date(FMT_DATE_TIME_SQL, $ube->combat_timestamp) . "', |
114 | 114 | `ube_report_time_spent` = {$ube->time_spent}, |
115 | 115 | |
116 | - `ube_report_combat_admin` = " . (int)$ube->is_admin_in_combat . ", |
|
116 | + `ube_report_combat_admin` = " . (int) $ube->is_admin_in_combat . ", |
|
117 | 117 | `ube_report_mission_type` = {$ube->mission_type_id}, |
118 | 118 | |
119 | 119 | `ube_report_combat_result` = {$ube->combat_result}, |
120 | - `ube_report_combat_sfr` = " . (int)$ube->is_small_fleet_recce . ", |
|
120 | + `ube_report_combat_sfr` = " . (int) $ube->is_small_fleet_recce . ", |
|
121 | 121 | |
122 | - `ube_report_planet_id` = " . (int)$ube->ube_planet_info[PLANET_ID] . ", |
|
122 | + `ube_report_planet_id` = " . (int) $ube->ube_planet_info[PLANET_ID] . ", |
|
123 | 123 | `ube_report_planet_name` = '" . db_escape($ube->ube_planet_info[PLANET_NAME]) . "', |
124 | - `ube_report_planet_size` = " . (int)$ube->ube_planet_info[PLANET_SIZE] . ", |
|
125 | - `ube_report_planet_galaxy` = " . (int)$ube->ube_planet_info[PLANET_GALAXY] . ", |
|
126 | - `ube_report_planet_system` = " . (int)$ube->ube_planet_info[PLANET_SYSTEM] . ", |
|
127 | - `ube_report_planet_planet` = " . (int)$ube->ube_planet_info[PLANET_PLANET] . ", |
|
128 | - `ube_report_planet_planet_type` = " . (int)$ube->ube_planet_info[PLANET_TYPE] . ", |
|
124 | + `ube_report_planet_size` = " . (int) $ube->ube_planet_info[PLANET_SIZE] . ", |
|
125 | + `ube_report_planet_galaxy` = " . (int) $ube->ube_planet_info[PLANET_GALAXY] . ", |
|
126 | + `ube_report_planet_system` = " . (int) $ube->ube_planet_info[PLANET_SYSTEM] . ", |
|
127 | + `ube_report_planet_planet` = " . (int) $ube->ube_planet_info[PLANET_PLANET] . ", |
|
128 | + `ube_report_planet_planet_type` = " . (int) $ube->ube_planet_info[PLANET_TYPE] . ", |
|
129 | 129 | |
130 | - `ube_report_capture_result` = " . (int)$ube->capture_result . ", " |
|
130 | + `ube_report_capture_result` = " . (int) $ube->capture_result . ", " |
|
131 | 131 | . $ube->debris->report_generate_sql($config) |
132 | 132 | . $ube->moon_calculator->report_generate_sql(); |
133 | 133 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | // Сохраняем общую информацию по игрокам |
138 | 138 | $player_sides = $ube->players->get_player_sides(); |
139 | - foreach($player_sides as $player_id => $player_side) { |
|
139 | + foreach ($player_sides as $player_id => $player_side) { |
|
140 | 140 | $sql_perform['ube_report_player'][] = array( |
141 | 141 | $ube_report_id, |
142 | 142 | $player_id, |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | "'" . db_escape($ube->players[$player_id]->name) . "'", |
145 | 145 | $ube->players[$player_id]->getSide() == UBE_PLAYER_IS_ATTACKER ? 1 : 0, |
146 | 146 | |
147 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
148 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
149 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
147 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
148 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
149 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
150 | 150 | ); |
151 | 151 | } |
152 | 152 | |
153 | 153 | // Всякая информация по флотам |
154 | - foreach($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
154 | + foreach ($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
155 | 155 | // Сохраняем общую информацию по флотам |
156 | 156 | $sql_perform['ube_report_fleet'][] = $UBEFleet->sql_generate_array($ube_report_id); |
157 | 157 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | $ube->rounds->sql_generate_unit_array($sql_perform['ube_report_unit'], $ube_report_id, $ube->fleet_list); |
168 | 168 | |
169 | 169 | // Пакетная вставка данных |
170 | - foreach($sql_perform as $table_name => $table_data) { |
|
171 | - if(count($table_data) < 2) { |
|
170 | + foreach ($sql_perform as $table_name => $table_data) { |
|
171 | + if (count($table_data) < 2) { |
|
172 | 172 | continue; |
173 | 173 | } |
174 | - foreach($table_data as &$record_data) { |
|
174 | + foreach ($table_data as &$record_data) { |
|
175 | 175 | $record_data = '(' . implode(',', $record_data) . ')'; |
176 | 176 | } |
177 | 177 | $fields = $table_data[0]; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $report_cypher = db_escape($report_cypher); |
195 | 195 | |
196 | 196 | $report_row = doquery("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1", true); |
197 | - if(!$report_row) { |
|
197 | + if (!$report_row) { |
|
198 | 198 | return UBE_REPORT_NOT_FOUND; |
199 | 199 | } |
200 | 200 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param $template_result |
211 | 211 | */ |
212 | 212 | function sn_ube_report_generate(UBE $ube, &$template_result) { |
213 | - if(!is_object($ube)) { |
|
213 | + if (!is_object($ube)) { |
|
214 | 214 | return; |
215 | 215 | } |
216 | 216 | |
@@ -227,15 +227,15 @@ discard block |
||
227 | 227 | |
228 | 228 | // Координаты, тип и название планеты - если есть |
229 | 229 | //R $planet_owner_id = $combat_data[UBE_FLEETS][0][UBE_OWNER]; |
230 | - if(isset($ube->ube_planet_info)) { |
|
230 | + if (isset($ube->ube_planet_info)) { |
|
231 | 231 | $template_result += $ube->ube_planet_info; |
232 | 232 | $template_result[PLANET_NAME] = str_replace(' ', ' ', htmlentities($template_result[PLANET_NAME], ENT_COMPAT, 'UTF-8')); |
233 | 233 | } |
234 | 234 | |
235 | 235 | // Обломки |
236 | 236 | $debris = array(); |
237 | - foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
238 | - if($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
237 | + foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
238 | + if ($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
239 | 239 | $debris[] = array( |
240 | 240 | 'NAME' => $lang['tech'][$resource_id], |
241 | 241 | 'AMOUNT' => pretty_number($resource_amount), |
@@ -188,6 +188,11 @@ discard block |
||
188 | 188 | */ |
189 | 189 | // OK v4 |
190 | 190 | // TODO - вынести в отдельный класс |
191 | +/** |
|
192 | + * @param string $db_id_field_name |
|
193 | + * @param string $db_table_name |
|
194 | + * @param string $db_value_field_name |
|
195 | + */ |
|
191 | 196 | function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) { |
192 | 197 | $current_value_safe = db_escape($current_value_unsafe); |
193 | 198 | $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true); |
@@ -220,7 +225,7 @@ discard block |
||
220 | 225 | |
221 | 226 | /** |
222 | 227 | * @param $user |
223 | - * @param $username_safe |
|
228 | + * @param string $username_safe |
|
224 | 229 | */ |
225 | 230 | function db_player_name_history_replace($user, $username_safe) { |
226 | 231 | doquery("REPLACE INTO {{player_name_history}} SET `player_id` = {$user['id']}, `player_name` = '{$username_safe}'"); |
@@ -228,7 +233,7 @@ discard block |
||
228 | 233 | |
229 | 234 | |
230 | 235 | /** |
231 | - * @param $username_safe |
|
236 | + * @param string $username_safe |
|
232 | 237 | * |
233 | 238 | * @return array|bool|mysqli_result|null |
234 | 239 | */ |
@@ -488,9 +493,9 @@ discard block |
||
488 | 493 | * @param $user_id |
489 | 494 | * @param $change_type |
490 | 495 | * @param $dark_matter |
491 | - * @param $comment |
|
496 | + * @param string $comment |
|
492 | 497 | * @param $row |
493 | - * @param $page_url |
|
498 | + * @param string $page_url |
|
494 | 499 | */ |
495 | 500 | function db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment, $row, $page_url) { |
496 | 501 | doquery( |
@@ -534,9 +539,9 @@ discard block |
||
534 | 539 | |
535 | 540 | // Quests *********************************************************************************************************** |
536 | 541 | /** |
537 | - * @param $query_add_select |
|
542 | + * @param string $query_add_select |
|
538 | 543 | * @param $query_add_from |
539 | - * @param $query_add_where |
|
544 | + * @param string $query_add_where |
|
540 | 545 | * |
541 | 546 | * @return array|bool|mysqli_result|null |
542 | 547 | */ |
@@ -580,11 +585,11 @@ discard block |
||
580 | 585 | } |
581 | 586 | |
582 | 587 | /** |
583 | - * @param $quest_name |
|
584 | - * @param $quest_type |
|
585 | - * @param $quest_description |
|
588 | + * @param string $quest_name |
|
589 | + * @param integer $quest_type |
|
590 | + * @param string $quest_description |
|
586 | 591 | * @param $quest_conditions |
587 | - * @param $quest_rewards |
|
592 | + * @param string $quest_rewards |
|
588 | 593 | * @param $quest_id |
589 | 594 | */ |
590 | 595 | function db_quest_update($quest_name, $quest_type, $quest_description, $quest_conditions, $quest_rewards, $quest_id) { |
@@ -607,7 +612,7 @@ discard block |
||
607 | 612 | /** |
608 | 613 | * @param $banner |
609 | 614 | * @param $banned |
610 | - * @param $reason |
|
615 | + * @param string $reason |
|
611 | 616 | * @param $ban_until |
612 | 617 | */ |
613 | 618 | function db_ban_insert($banner, $banned, $reason, $ban_until) { |
@@ -630,7 +635,7 @@ discard block |
||
630 | 635 | /** |
631 | 636 | * @param $banner |
632 | 637 | * @param $banned |
633 | - * @param $reason |
|
638 | + * @param string $reason |
|
634 | 639 | */ |
635 | 640 | function db_ban_insert_unset($banner, $banned, $reason) { |
636 | 641 | doquery( |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | function db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source = false) { |
87 | 87 | // pdump($source); |
88 | - if(!$source) { |
|
88 | + if (!$source) { |
|
89 | 89 | $source = array( |
90 | 90 | 'statpoints' => 'statpoints', |
91 | 91 | 'users' => 'users', |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | // pdump($source); |
109 | - if($who == 1) { |
|
110 | - if($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
109 | + if ($who == 1) { |
|
110 | + if ($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
111 | 111 | $query_str = |
112 | 112 | "SELECT |
113 | 113 | @rownum:=@rownum+1 rownum, subject.{$source['id']} as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.{$source['username']} as `name`, subject.* |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) { |
192 | 192 | $current_value_safe = db_escape($current_value_unsafe); |
193 | 193 | $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true); |
194 | - if(!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
194 | + if (!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
195 | 195 | doquery("INSERT INTO {{{$db_table_name}}} (`{$db_value_field_name}`) VALUES ('{$current_value_safe}');"); |
196 | 196 | $variable_id = db_insert_id(); |
197 | 197 | } else { |
@@ -293,7 +293,7 @@ |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
296 | - * @param $ranklist |
|
296 | + * @param string $ranklist |
|
297 | 297 | * @param $user |
298 | 298 | */ |
299 | 299 | function db_ally_update_ranklist($ranklist, $user) { |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param $user_id |
20 | - * @param $nick |
|
20 | + * @param string $nick |
|
21 | 21 | * @param $ally_id |
22 | - * @param $message |
|
22 | + * @param string $message |
|
23 | 23 | * @param $chat_message_sender_name |
24 | 24 | * @param $chat_message_recipient_id |
25 | 25 | * @param $chat_message_recipient_name |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param $alliance |
56 | 56 | * @param $where_add |
57 | 57 | * @param $start_row |
58 | - * @param $page_limit |
|
58 | + * @param integer $page_limit |
|
59 | 59 | * |
60 | 60 | * @return array|bool|mysqli_result|null |
61 | 61 | */ |
@@ -22,6 +22,10 @@ discard block |
||
22 | 22 | doquery('DELETE FROM `{{aks}}` WHERE `id` NOT IN (SELECT DISTINCT `fleet_group` FROM `{{fleets}}`);'); |
23 | 23 | } |
24 | 24 | |
25 | +/** |
|
26 | + * @param double $arrival |
|
27 | + * @param integer $target_structure |
|
28 | + */ |
|
25 | 29 | function db_missile_insert($target_coord, $user, $planetrow, $arrival, $fleet_ship_count, $target_structure) { |
26 | 30 | doquery( |
27 | 31 | "INSERT INTO `{{iraks}}` SET |
@@ -114,14 +118,14 @@ discard block |
||
114 | 118 | |
115 | 119 | |
116 | 120 | /** |
117 | - * @param $fleet_group_id_list |
|
121 | + * @param string $fleet_group_id_list |
|
118 | 122 | */ |
119 | 123 | function db_acs_delete_by_list($fleet_group_id_list) { |
120 | 124 | doquery("DELETE FROM {{aks}} WHERE `id` IN ({$fleet_group_id_list})"); |
121 | 125 | } |
122 | 126 | |
123 | 127 | /** |
124 | - * @param $bashing_list |
|
128 | + * @param string $bashing_list |
|
125 | 129 | */ |
126 | 130 | function db_bashing_insert($bashing_list) { |
127 | 131 | doquery("INSERT INTO {{bashing}} (bashing_user_id, bashing_planet_id, bashing_time) VALUES {$bashing_list};"); |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * DB ACS functions |
|
4 | - */ |
|
3 | + * DB ACS functions |
|
4 | + */ |
|
5 | 5 | |
6 | 6 | /* ACS ****************************************************************************************************************/ |
7 | 7 | /** |