Exemplo n.º 1
0
function db_change_units(&$user, &$planet, $unit_list = array(), $query = null)
{
    $query = is_array($query) ? $query : array(LOC_USER => array(), LOC_PLANET => array());
    $group = sn_get_groups('resources_loot');
    foreach ($unit_list as $unit_id => $unit_amount) {
        if (!in_array($unit_id, $group)) {
            // TODO - remove later
            print '<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>';
            pdump(debug_backtrace());
            die('db_change_units() вызван для не-ресурсов!');
        }
        if (!$unit_amount) {
            continue;
        }
        $unit_db_name = pname_resource_name($unit_id);
        $unit_location = sys_get_unit_location($user, $planet, $unit_id);
        // Changing value in object
        switch ($unit_location) {
            case LOC_USER:
                $user[$unit_db_name] += $unit_amount;
                break;
            case LOC_PLANET:
                $planet[$unit_db_name] += $unit_amount;
                break;
        }
        $unit_amount = $unit_amount < 0 ? $unit_amount : "+{$unit_amount}";
        // Converting positive unit_amount to string '+unit_amount'
        $query[$unit_location][$unit_id] = "`{$unit_db_name}`=`{$unit_db_name}`{$unit_amount}";
    }
    db_change_units_perform($query[LOC_USER], 'users', $user['id']);
    db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']);
}
Exemplo n.º 2
0
 function mysql_query($query_string)
 {
     if (!is_object($this->link)) {
         pdump(debug_backtrace());
     }
     return $this->link->query($query_string);
 }
Exemplo n.º 3
0
function lng_die_not_an_object()
{
    print 'Ошибка - $lang не объект! Сообщите Администратору сервера и приложите содержимое страницы';
    $trace = debug_backtrace();
    unset($trace[0]);
    pdump($trace);
    return die;
}
Exemplo n.º 4
0
function upd_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id = null)
{
    if (!is_array($user)) {
        // TODO - remove later
        print '<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>';
        pdump(debug_backtrace());
        die('USER is not ARRAY');
    }
    if (!isset($user['id']) || !$user['id']) {
        // TODO - remove later
        print '<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>';
        pdump($user);
        pdump(debug_backtrace());
        die('USER[id] пустой');
    }
    $planet_id = is_array($planet_id) && isset($planet_id['id']) ? $planet_id['id'] : $planet_id;
    $unit_location = get_unit_param($unit_id, 'location');
    // sys_get_unit_location($user, array(), $unit_id);
    $location_id = $unit_location == LOC_USER ? $user['id'] : $planet_id;
    $location_id = $location_id ? $location_id : 'NULL';
    $db_changeset = array();
    $temp = upd_db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id');
    if ($temp['unit_id']) {
        // update
        $db_changeset = array('action' => SQL_OP_UPDATE, 'where' => array("`unit_id` = {$temp['unit_id']}"), 'fields' => array('unit_level' => array('delta' => $unit_value)));
    } else {
        // insert
        $db_changeset = array('action' => SQL_OP_INSERT, 'fields' => array('unit_player_id' => array('set' => $user['id']), 'unit_location_type' => array('set' => $unit_location), 'unit_location_id' => array('set' => $unit_location == LOC_USER ? $user['id'] : $planet_id), 'unit_type' => array('set' => get_unit_param($unit_id, P_UNIT_TYPE)), 'unit_snid' => array('set' => $unit_id), 'unit_level' => array('set' => $unit_value)));
    }
    return $db_changeset;
}
Exemplo n.º 5
0
 function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true)
 {
     global $config, $sys_stop_log_hit, $lang, $sys_log_disabled, $user;
     if (empty(classSupernova::$db->connected)) {
         // TODO - писать ошибку в файл
         die('SQL server currently unavailable. Please contact Administration...');
     }
     sn_db_transaction_rollback();
     if ($config->debug == 1) {
         echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>";
         echo "<table>{$this->log}</table>";
     }
     $fatal_error = 'Fatal error: cannot write to `logs` table. Please contact Administration...';
     $error_text = db_escape($message);
     $error_backtrace = $this->dump($dump, true, strpos($message, 'Deadlock') !== false);
     if (!$sys_log_disabled) {
         $query = "INSERT INTO `{{logs}}` SET\n        `log_time` = '" . time() . "', `log_code` = '" . db_escape($error_code) . "', `log_sender` = '" . db_escape($user['id']) . "',\n        `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "',  `log_text` = '" . db_escape($message) . "',\n        `log_page` = '" . db_escape(strpos($_SERVER['SCRIPT_NAME'], SN_ROOT_RELATIVE) === false ? $_SERVER['SCRIPT_NAME'] : substr($_SERVER['SCRIPT_NAME'], strlen(SN_ROOT_RELATIVE))) . "'" . ($error_backtrace ? ", `log_dump` = '" . db_escape(serialize($error_backtrace)) . "'" : '') . ";";
         doquery($query, '', false, true) or die($fatal_error . db_error());
         $message = "Пожалуйста, свяжитесь с админом, если ошибка повторится. Ошибка №: <b>" . db_insert_id() . "</b>";
         $sys_stop_log_hit = true;
         $sys_log_disabled = true;
         !function_exists('message') ? die($message) : message($message, 'Ошибка', '', 0, false);
     } else {
         //        // TODO Здесь надо писать в файло
         ob_start();
         print "<hr>User ID {$user['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}";
         foreach ($error_backtrace as $name => $value) {
             print '<hr>';
             pdump($value, $name);
         }
         ob_end_flush();
         die;
     }
 }
Exemplo n.º 6
0
function debug($value, $varname = '')
{
    return pdump($value, $varname);
}
Exemplo n.º 7
0
        'Игрок32'
        'Игрок40'
        */
        if (sys_get_param_str('prize_calculate') && $blitz_prize_players_active && ($blitz_prize_dark_matter_actual = sys_get_param_int('blitz_prize_dark_matter'))) {
            // $blitz_prize_dark_matter_actual = sys_get_param_int('blitz_prize_dark_matter');
            $blitz_prize_places_actual = sys_get_param_int('blitz_prize_places');
            sn_db_transaction_start();
            $query = doquery("SELECT * FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY `blitz_place` FOR UPDATE;");
            while ($row = db_fetch($query)) {
                if (!$row['blitz_place']) {
                    continue;
                }
                $blitz_prize_dark_matter_actual = round($blitz_prize_dark_matter_actual / 2);
                $blitz_prize_places_actual--;
                $reward = $blitz_prize_dark_matter_actual - $row['blitz_reward_dark_matter'];
                pdump("{{$row['id']}} {$row['blitz_name']}, Place {$row['blitz_place']}, Prize places {$blitz_prize_places_actual}, Prize {$reward}", $row['id']);
                if ($reward) {
                    rpg_points_change($row['user_id'], RPG_BLITZ, $reward, sprintf($lang['sys_blitz_reward_log_message'], $row['blitz_place'], $row['blitz_name']));
                    doquery("UPDATE {{blitz_registrations}} SET blitz_reward_dark_matter = blitz_reward_dark_matter + ({$reward}) WHERE id = {$row['id']} AND `round_number` = {$current_round};");
                }
                if (!$blitz_prize_places_actual || $blitz_prize_dark_matter_actual < 1000) {
                    break;
                }
            }
            sn_db_transaction_commit();
        }
    }
}
$template = gettemplate('blitz_register', true);
$player_registered = false;
$query = doquery("SELECT u.*, br.blitz_name, br.blitz_password, br.blitz_place, br.blitz_status, br.blitz_points, br.blitz_reward_dark_matter\n    FROM {{blitz_registrations}} AS br\n    JOIN {{users}} AS u ON u.id = br.user_id\n  WHERE br.`round_number` = {$current_round}\n  order by `blitz_place`, `timestamp`;");
Exemplo n.º 8
0
function linear_calc(&$linear, $from = 0, $debug = false)
{
    for ($i = $from; $i < count($linear); $i++) {
        $eq =& $linear[$i];
        for ($j = count($eq) - 1; $j >= $from; $j--) {
            $eq[$j] /= $eq[$from];
        }
    }
    if ($debug) {
        pdump($linear, 'Нормализовано по х' . $from);
    }
    for ($i = $from + 1; $i < count($linear); $i++) {
        $eq =& $linear[$i];
        for ($j = count($eq) - 1; $j >= $from; $j--) {
            $eq[$j] -= $linear[$from][$j];
        }
    }
    if ($debug) {
        pdump($linear, 'Подставили х' . $from);
    }
    if ($from < count($linear) - 1) {
        linear_calc($linear, $from + 1, $debug);
    }
    if ($from) {
        for ($i = 0; $i < $from; $i++) {
            $eq =& $linear[$i];
            for ($j = count($eq) - 1; $j >= $from; $j--) {
                $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j];
            }
        }
        if ($debug) {
            pdump($linear, 'Подставили обратно х' . $from);
        }
    } else {
        if ($debug) {
            pdump($linear, 'Результат' . $from);
        }
        foreach ($linear as $index => &$eq) {
            pdump($eq[count($linear)], 'x' . $index);
        }
    }
}
Exemplo n.º 9
0
 function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true)
 {
     mysql_query("ROLLBACK;");
     global $config;
     if ($config->debug == 1) {
         echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>";
         echo "<table>{$this->log}</table>";
     }
     global $link, $sys_stop_log_hit;
     require SN_ROOT_PHYSICAL . 'config.' . PHP_EX;
     if (!$link) {
         $link = mysql_connect($dbsettings['server'], $dbsettings['user'], $dbsettings['pass']);
         mysql_query('/*!40101 SET NAMES \'cp1251\' */');
         mysql_select_db($dbsettings['name']);
         if (!$link) {
             die('mySQL server currently unavailable. Please contact Administration...');
         }
     }
     $fatal_error = 'Fatal error: cannot write to `logs` table. Please contact Administration...';
     $error_text = mysql_real_escape_string($message);
     $error_backtrace = $this->dump($dump, true);
     if (!$GLOBALS['sys_log_disabled']) {
         if ($error_backtrace) {
             $error_backtrace = ", `log_dump` = '" . mysql_real_escape_string(serialize($error_backtrace)) . "'";
         } else {
             $error_backtrace = '';
         }
         mysql_query("INSERT INTO `{$dbsettings['prefix']}logs` SET\r\n        `log_time` = '" . time() . "', `log_code` = '{$error_code}', `log_sender` = '{$GLOBALS['user']['id']}', `log_username` = '{$GLOBALS['user']['username']}',\r\n        `log_title` = '{$title}',  `log_text` = '{$error_text}', `log_page` = '" . mysql_real_escape_string($_SERVER['SCRIPT_NAME']) . "'{$error_backtrace};") or die($fatal_error . mysql_error());
         /*
               $q = mysql_fetch_assoc(mysql_query("SELECT max(log_id) AS rows FROM {$dbsettings['prefix']}logs;"))
                 or die($fatal_error);
         */
         $message = "Пожалуйста, свяжитесь с админом, если ошибка повторится. Ошибка №: <b>" . mysql_insert_id() . "</b>";
         $sys_stop_log_hit = true;
         $GLOBALS['sys_log_disabled'] = true;
         if (!function_exists('message')) {
             die($message);
         } else {
             message($message, 'Ошибка', $dest, 0, false);
         }
     } else {
         ob_start();
         print "<hr>User ID {$GLOBALS['user']['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}";
         foreach ($error_backtrace as $name => $value) {
             print '<hr>';
             pdump($value, $name);
         }
         ob_end_flush();
         die;
     }
 }
Exemplo n.º 10
0
function sys_o_get_updated($user, $planet, $UpdateTime, $simulation = false, $no_user_update = false)
{
    sn_db_transaction_check(true);
    $no_data = array('user' => false, 'planet' => false, 'que' => false);
    if (!$planet) {
        return $no_data;
    }
    if (!$no_user_update) {
        $user = intval(is_array($user) && $user['id'] ? $user['id'] : $user);
        if (!$user) {
            // TODO - Убрать позже
            print '<h1>СООБЩИТЕ ЭТО АДМИНУ: sys_o_get_updated() - USER пустой!</h1>';
            $backtrace = debug_backtrace();
            array_shift($backtrace);
            pdump($backtrace);
            die;
        }
        $user = db_user_by_id($user, !$simulation, '*', true);
    }
    if (empty($user['id'])) {
        return $no_data;
    }
    if (is_array($planet) && isset($planet['galaxy']) && $planet['galaxy']) {
        $planet = db_planet_by_vector($planet, '', !$simulation);
    } else {
        $planet = intval(is_array($planet) && isset($planet['id']) ? $planet['id'] : $planet);
        $planet = db_planet_by_id($planet, !$simulation);
    }
    if (!is_array($planet) || !isset($planet['id'])) {
        return $no_data;
    }
    $que = que_process($user, $planet, $UpdateTime);
    $ProductionTime = max(0, $UpdateTime - $planet['last_update']);
    $planet['prev_update'] = $planet['last_update'];
    $planet['last_update'] += $ProductionTime;
    /*
    $que = eco_que_process($user, $planet, $ProductionTime);
    $hangar_built = $ProductionTime && !$simulation ? eco_bld_que_hangar($user, $planet, $ProductionTime) : array();
    */
    // TODO ЭТО НАДО ДЕЛАТЬ ТОЛЬКО ПРИ СПЕЦУСЛОВИЯХ
    $caps_real = eco_get_planet_caps($user, $planet, $ProductionTime);
    $resources_increase = array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0);
    switch ($planet['planet_type']) {
        case PT_PLANET:
            foreach ($resources_increase as $resource_id => &$increment) {
                $resource_name = pname_resource_name($resource_id);
                $increment = $caps_real['total'][$resource_id] * $ProductionTime / 3600;
                $store_free = $caps_real['total_storage'][$resource_id] - $planet[$resource_name];
                $increment = min($increment, max(0, $store_free));
                if ($planet[$resource_name] + $increment < 0 && !$simulation) {
                    global $debug;
                    $debug->warning("Player ID {$user['id']} have negative resources on ID {$planet['id']}.{$planet['planet_type']} [{$planet['galaxy']}:{$planet['system']}:{$planet['planet']}]. Difference {$planet[$resource_name]} of {$resource_name}", 'Negative Resources', 501);
                }
                $planet[$resource_name] += $increment;
                $planet[$resource_name . '_perhour'] = $caps_real['total'][$resource_id];
            }
            break;
        case PT_MOON:
        default:
            $planet['metal_perhour'] = 0;
            $planet['crystal_perhour'] = 0;
            $planet['deuterium_perhour'] = 0;
            $planet['energy_used'] = 0;
            $planet['energy_max'] = 0;
            break;
    }
    // TODO пересчитывать размер планеты только при постройке чего-нибудь и при покупке сектора
    $planet['field_current'] = 0;
    $sn_group_build_allow = sn_get_groups('build_allow');
    if (is_array($sn_group_build_allow[$planet['planet_type']])) {
        foreach ($sn_group_build_allow[$planet['planet_type']] as $building_id) {
            $planet['field_current'] += mrc_get_level($user, $planet, $building_id, !$simulation, true);
        }
    }
    if ($simulation) {
        return array('user' => $user, 'planet' => $planet, 'que' => $que);
    }
    db_planet_set_by_id($planet['id'], "`last_update` = '{$planet['last_update']}', `field_current` = {$planet['field_current']},\n    `metal` = `metal` + '{$resources_increase[RES_METAL]}', `crystal` = `crystal` + '{$resources_increase[RES_CRYSTAL]}', `deuterium` = `deuterium` + '{$resources_increase[RES_DEUTERIUM]}',\n    `metal_perhour` = '{$planet['metal_perhour']}', `crystal_perhour` = '{$planet['crystal_perhour']}', `deuterium_perhour` = '{$planet['deuterium_perhour']}',\n    `energy_used` = '{$planet['energy_used']}', `energy_max` = '{$planet['energy_max']}'");
    return array('user' => $user, 'planet' => $planet, 'que' => $que);
}
Exemplo n.º 11
0
// В этой точке пользователь либо авторизирован - и есть его запись - либо пользователя гарантированно нет в базе
$template_result[F_ACCOUNT_IS_AUTHORIZED] = $sys_user_logged_in = !empty($user) && isset($user['id']) && $user['id'];
//pdump($template_result[F_ACCOUNT_IS_AUTHORIZED]);die();
if (!empty($user['id'])) {
    classSupernova::$user_options->user_change($user['id']);
}
// Если сообщение пустое - заполняем его по коду
$template_result[F_LOGIN_MESSAGE] = isset($template_result[F_LOGIN_MESSAGE]) && $template_result[F_LOGIN_MESSAGE] ? $template_result[F_LOGIN_MESSAGE] : ($template_result[F_LOGIN_STATUS] != LOGIN_UNDEFINED ? $lang['sys_login_messages'][$template_result[F_LOGIN_STATUS]] : false);
if ($template_result[F_LOGIN_STATUS] == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
    $prohibited_characters = array_map(function ($value) {
        return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'";
    }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED));
    $template_result[F_LOGIN_MESSAGE] .= implode(', ', $prohibited_characters);
}
if (defined('DEBUG_AUTH') && DEBUG_AUTH && !defined('IN_AJAX')) {
    pdump("Отключи отладку перед продакшном!");
}
// Это уже переключаемся на пользовательский язык с откатом до языка в параметрах запроса
$lang->lng_switch(sys_get_param_str('lang'));
global $dpath;
$dpath = $user["dpath"] ? $user["dpath"] : DEFAULT_SKINPATH;
$config->db_loadItem('game_disable') == GAME_DISABLE_INSTALL ? define('INSTALL_MODE', GAME_DISABLE_INSTALL) : false;
if ($template_result[F_GAME_DISABLE] = $config->game_disable) {
    $template_result[F_GAME_DISABLE_REASON] = sys_bbcodeParse($config->game_disable == GAME_DISABLE_REASON ? $config->game_disable_reason : $lang['sys_game_disable_reason'][$config->game_disable]);
    if (defined('IN_API')) {
        return;
    }
    if (($user['authlevel'] < 1 || !(defined('IN_ADMIN') && IN_ADMIN)) && !(defined('INSTALL_MODE') && defined('LOGIN_LOGOUT'))) {
        message($template_result[F_GAME_DISABLE_REASON], $config->game_name);
        ob_end_flush();
        die;