Пример #1
0
require '../common.' . substr(strrchr(__FILE__, '.'), 1);
// if($user['authlevel'] < 2)
if ($user['authlevel'] < 3) {
    AdminMessage($lang['adm_err_denied']);
}
AdminMessage('Временно не работает');
require "includes/admin_planet_edit.inc" . DOT_PHP_EX;
$template = gettemplate('admin/admin_planet_edit', true);
$mode = admin_planet_edit_mode($template, $admin_planet_edit_mode_list);
$planet_id = sys_get_param_id('planet_id');
$unit_list = sys_get_param('unit_list');
if (sys_get_param('change_data') && !empty($unit_list)) {
    $query_string = array();
    foreach ($unit_list as $unit_id => $unit_amount) {
        if ($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode)) {
            $query_string[] = $unit_query_string;
        }
    }
    if (!empty($query_string)) {
        db_planet_set_by_id($planet_id, implode(', ', $query_string));
    }
}
if ($planet_id) {
    $edit_planet_row = db_planet_by_id($planet_id);
    admin_planet_edit_template($template, $edit_planet_row, $mode);
}
foreach ($admin_planet_edit_mode_list as $page_mode => $mode_locale) {
    $template->assign_block_vars('page_menu', array('ID' => $page_mode, 'TEXT' => $mode_locale));
}
$template->assign_vars(array('MODE' => $mode, 'PLANET_ID' => $planet_id, 'PLANET_NAME' => empty($edit_planet_row) ? '' : $lang['sys_planet_type'][$edit_planet_row['planet_type']] . ' ' . uni_render_planet($edit_planet_row), 'PAGE_HINT' => $lang['adm_planet_edit_hint']));
display($template, $lang['adm_am_ttle'], false, '', true);
Пример #2
0
         continue;
     }
     $moon = db_planet_by_parent($UserPlanet['id']);
     if ($moon) {
         $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100));
     } else {
         $moon_fill = 0;
     }
     $moon_fleets = flt_get_fleets_to_planet($moon);
     $template->assign_block_vars('planet', array_merge($template_planet, array('PLANET_FLEET_ID' => $planet_fleet_id, 'MOON_ID' => $moon['id'], 'MOON_NAME' => $moon['name'], 'MOON_IMG' => $moon['image'], 'MOON_FILL' => min(100, $moon_fill), 'MOON_ENEMY' => $moon_fleets['enemy']['count'], 'MOON_PLANET' => $moon['parent_planet'])));
     $planet_count++;
 }
 sn_db_transaction_commit();
 tpl_assign_fleet($template, $fleets_to_planet);
 tpl_assign_fleet($template, $fleets);
 $lune = $planetrow['planet_type'] == PT_PLANET ? db_planet_by_parent($planetrow['id']) : db_planet_by_id($planetrow['parent_planet']);
 if ($lune) {
     $template->assign_vars(array('MOON_ID' => $lune['id'], 'MOON_IMG' => $lune['image'], 'MOON_NAME' => $lune['name']));
 }
 $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
 $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
 $planet_recyclers_orbiting = 0;
 foreach (sn_get_groups('flt_recyclers') as $recycler_id) {
     $planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id);
 }
 int_planet_pretemplate($planetrow, $template);
 $sn_group_ques = sn_get_groups('ques');
 foreach (array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) {
     $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']];
     $template->assign_block_vars('ques', array('ID' => $que_id, 'NAME' => $lang['sys_ques'][$que_id], 'LENGTH' => empty($this_que) ? 0 : count($this_que)));
     if (!empty($this_que)) {
Пример #3
0
function SetSelectedPlanet(&$user)
{
    $planet_row['id'] = $user['current_planet'];
    // Пытаемся переключить на новую планету
    if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
        $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id');
    } else {
        $planet_row = db_planet_by_id($planet_row['id']);
    }
    // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету
    if (!isset($planet_row['id'])) {
        $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id');
        // Если текущей планеты не существует - выставляем Столицу
        if (!isset($planet_row['id'])) {
            $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id');
            // Если и столицы не существует - значит что-то очень не так с записью пользователя
            if (!isset($planet_row['id'])) {
                global $debug;
                $debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502);
            }
        }
    }
    // Если производилось переключение планеты - делаем запись в юзере
    if ($user['current_planet'] != $planet_row['id']) {
        db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'");
        $user['current_planet'] = $planet_row['id'];
    }
    return $user['current_planet'];
}
Пример #4
0
                message($lang['sys_noalloaw'], $lang['sys_noaccess']);
                die;
            }
            $selected_user = db_user_by_username($Pattern, false, 'id');
            $QryUpdate = db_user_set_by_id($selected_user['id'], "`authlevel` = '{$NewLvl}'");
            $Message = $lang['adm_mess_lvl1'] . " " . $Pattern . " " . $lang['adm_mess_lvl2'];
            $Message .= "<font color=\"red\">" . $lang['adm_usr_level'][$NewLvl] . "</font>!";
            AdminMessage($Message, $lang['adm_mod_level']);
            break;
        case 'ip_search':
            $bloc = $lang;
            $bloc['adm_this_ip'] = $ip;
            $SelUser = db_user_list("`user_lastip` = '{$ip}'");
            //while ( $Usr = db_fetch($SelUser) ) {
            foreach ($SelUser as $Usr) {
                $UsrMain = db_planet_by_id($Usr['id_planet'], false, 'name');
                $bloc['adm_plyer_lst'] .= "<tr><th>" . $Usr['username'] . "</th><th>[" . $Usr['galaxy'] . ":" . $Usr['system'] . ":" . $Usr['planet'] . "] " . $UsrMain['name'] . "</th></tr>";
            }
            $SubPanelTPL = gettemplate('admin/admin_panel_asw2');
            $parse['adm_sub_form2'] = parsetemplate($SubPanelTPL, $bloc);
            break;
        default:
            break;
    }
}
// Traiter les reponses aux formulaires
if (isset($GET_action)) {
    $bloc = $lang;
    switch ($GET_action) {
        case 'usr_search':
            $SubPanelTPL = gettemplate('admin/admin_panel_frm1');
Пример #5
0
 * jumpgate.php
 *
 * Jump Gate interface, I presume
 *
 * @version 1.0st Security checks & tests by Gorlum for http://supernova.ws
 * @version 1
 * @copyright 2008 By Chlorel for XNova
 */
include 'common.' . substr(strrchr(__FILE__, '.'), 1);
lng_include('fleet');
if ($TargetPlanet = sys_get_param_id('jmpto')) {
    sn_db_transaction_start();
    db_user_by_id($user['id'], true, 'id');
    $planetrow = db_planet_by_id($planetrow['id'], true);
    if (!($NextJumpTime = uni_get_time_to_jump($planetrow))) {
        $TargetGate = db_planet_by_id($TargetPlanet, true, '`id`, `last_jump_time`');
        if (mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0) {
            $NextDestTime = uni_get_time_to_jump($TargetGate);
            if (!$NextDestTime) {
                // $SubQueryOri = "";
                // $SubQueryDes = "";
                $ship_list = sys_get_param('ships');
                $db_changeset = array();
                foreach ($ship_list as $ship_id => $ship_count) {
                    if (!in_array($ship_id, sn_get_groups('fleet'))) {
                        continue;
                    }
                    $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
                    if ($ship_count) {
                        $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, -$ship_count, $user, $planetrow['id']);
                        $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, $ship_count, $user, $TargetGate['id']);
Пример #6
0
function que_delete($que_type, $user = array(), $planet = array(), $clear = false)
{
    $planets_locked = array();
    // TODO: Some checks
    sn_db_transaction_start();
    $user = db_user_by_id($user['id'], true);
    $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
    $global_que = que_get($user['id'], $planet['id'], $que_type, true);
    //pdump($global_que);
    //pdump($planet['id']);
    //pdump($global_que[$que_type][$planet['id']]);
    if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
        $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
        foreach ($que as $que_item) {
            db_que_delete_by_id($que_item['que_id']);
            if ($que_item['que_planet_id_origin']) {
                $planet['id'] = $que_item['que_planet_id_origin'];
            }
            if (!isset($planets_locked[$planet['id']])) {
                $planets_locked[$planet['id']] = $planet['id'] ? db_planet_by_id($planet['id'], true) : $planet;
            }
            $build_data = sys_unit_str2arr($que_item['que_unit_price']);
            db_change_units($user, $planets_locked[$planet['id']], array(RES_METAL => $build_data[RES_METAL] * $que_item['que_unit_amount'], RES_CRYSTAL => $build_data[RES_CRYSTAL] * $que_item['que_unit_amount'], RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount']));
            if (!$clear) {
                break;
            }
        }
        if (is_numeric($planet['id'])) {
            db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
        } elseif (is_numeric($user['id'])) {
            db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
        }
        sn_db_transaction_commit();
    } else {
        sn_db_transaction_rollback();
    }
    //die();
    header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}" . "&ally_id=" . sys_get_param_id('ally_id'));
}
Пример #7
0
header("Content-type: text/html; charset=utf-8");
lng_include('universe');
lng_include('fleet');
require_once 'includes/includes/flt_functions.php';
$target_coord = array('galaxy' => $target_galaxy = sys_get_param_int('galaxy'), 'system' => $target_system = sys_get_param_int('system'), 'planet' => $target_planet = sys_get_param_int('planet'));
if (!uni_coordinates_valid($target_coord)) {
    die($lang['gs_c02']);
}
$target_mission = sys_get_param_int('mission');
$sn_group_missions = sn_get_groups('missions');
if (!isset($sn_group_missions[$target_mission]['AJAX']) || !$sn_group_missions[$target_mission]['AJAX']) {
    die($lang['gs_c00']);
}
sn_db_transaction_start();
$user = db_user_by_id($user['id'], true);
$planetrow = db_planet_by_id($user['current_planet'], true);
$target_planet_type = sys_get_param_int('planet_type');
$target_planet_check = $target_planet_type == PT_DEBRIS ? PT_PLANET : $target_planet_type;
$target_coord['planet_type'] = $target_planet_check;
$target_row = db_planet_by_vector($target_coord);
if (empty($target_row)) {
    $target_row = array('galaxy' => $target_coord['galaxy'], 'system' => $target_coord['system'], 'planet' => $target_coord['planet'], 'planet_type' => $target_planet_check, 'id_owner' => 0);
}
$fleet_array = array();
switch ($target_mission) {
    case MT_SPY:
        $fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs($user['spio_anz']));
        $unit_group = 'flt_spies';
        break;
    case MT_RECYCLE:
        foreach (sn_get_groups('flt_recyclers') as $unit_id) {
Пример #8
0
function flt_t_send_fleet($user, &$from, $to, $fleet, $mission, $options = array())
{
    //ini_set('error_reporting', E_ALL);
    $internal_transaction = !sn_db_transaction_check(false) ? sn_db_transaction_start() : false;
    //pdump($internal_transaction);
    // TODO Потенциальный дедлок - если успела залочится запись пользователя - хозяина планеты
    $user = db_user_by_id($user['id'], true);
    $from = sys_o_get_updated($user, $from['id'], SN_TIME_NOW);
    $from = $from['planet'];
    $can_attack = flt_can_attack($from, $to, $fleet, $mission, $options);
    if ($can_attack != ATTACK_ALLOWED) {
        $internal_transaction ? sn_db_transaction_rollback() : false;
        return $can_attack;
    }
    $fleet_group = isset($options['fleet_group']) ? floatval($options['fleet_group']) : 0;
    $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']);
    $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
    if ($mission == MT_EXPLORE || $mission == MT_HOLD) {
        $stay_duration = $options['stay_time'] * 3600;
        $stay_time = $fleet_start_time + $stay_duration;
    } else {
        $stay_duration = 0;
        $stay_time = 0;
    }
    $fleet_end_time = $fleet_start_time + $travel_data['duration'] + $stay_duration;
    $fleet_ship_count = 0;
    $fleet_string = '';
    $db_changeset = array();
    $planet_fields = array();
    foreach ($fleet as $unit_id => $amount) {
        if (!$amount || !$unit_id) {
            continue;
        }
        if (in_array($unit_id, sn_get_groups('fleet'))) {
            $fleet_ship_count += $amount;
            $fleet_string .= "{$unit_id},{$amount};";
            $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']);
        } elseif (in_array($unit_id, sn_get_groups('resources_loot'))) {
            $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
        }
    }
    $to['id_owner'] = intval($to['id_owner']);
    $QryInsertFleet = "INSERT INTO {{fleets}} SET ";
    $QryInsertFleet .= "`fleet_owner` = '{$user['id']}', ";
    $QryInsertFleet .= "`fleet_mission` = '{$mission}', ";
    $QryInsertFleet .= "`fleet_amount` = '{$fleet_ship_count}', ";
    $QryInsertFleet .= "`fleet_array` = '{$fleet_string}', ";
    $QryInsertFleet .= "`fleet_start_time` = '{$fleet_start_time}', ";
    if ($from['id']) {
        $QryInsertFleet .= "`fleet_start_planet_id` = '{$from['id']}', ";
    }
    $QryInsertFleet .= "`fleet_start_galaxy` = '{$from['galaxy']}', ";
    $QryInsertFleet .= "`fleet_start_system` = '{$from['system']}', ";
    $QryInsertFleet .= "`fleet_start_planet` = '{$from['planet']}', ";
    $QryInsertFleet .= "`fleet_start_type` = '{$from['planet_type']}', ";
    $QryInsertFleet .= "`fleet_end_time` = '{$fleet_end_time}', ";
    $QryInsertFleet .= "`fleet_end_stay` = '{$stay_time}', ";
    if ($to['id']) {
        $QryInsertFleet .= "`fleet_end_planet_id` = '{$to['id']}', ";
    }
    $QryInsertFleet .= "`fleet_end_galaxy` = '{$to['galaxy']}', ";
    $QryInsertFleet .= "`fleet_end_system` = '{$to['system']}', ";
    $QryInsertFleet .= "`fleet_end_planet` = '{$to['planet']}', ";
    $QryInsertFleet .= "`fleet_end_type` = '{$to['planet_type']}', ";
    $QryInsertFleet .= "`fleet_resource_metal` = " . floatval($fleet[RES_METAL]) . ", ";
    $QryInsertFleet .= "`fleet_resource_crystal` = " . floatval($fleet[RES_CRYSTAL]) . ", ";
    $QryInsertFleet .= "`fleet_resource_deuterium` = " . floatval($fleet[RES_DEUTERIUM]) . ", ";
    $QryInsertFleet .= "`fleet_target_owner` = '{$to['id_owner']}', ";
    $QryInsertFleet .= "`fleet_group` = '{$fleet_group}', ";
    $QryInsertFleet .= "`start_time` = " . SN_TIME_NOW . ";";
    doquery($QryInsertFleet);
    $planet_fields[pname_resource_name(RES_DEUTERIUM)]['delta'] -= $travel_data['consumption'];
    $db_changeset['planets'][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array('id' => $from['id']), 'fields' => $planet_fields);
    db_changeset_apply($db_changeset);
    $internal_transaction ? sn_db_transaction_commit() : false;
    $from = db_planet_by_id($from['id']);
    return ATTACK_ALLOWED;
    //ini_set('error_reporting', E_ALL ^ E_NOTICE);
}
Пример #9
0
<?php

/**
 * admin/add_moon.php
 *
 * @version 2
 * @copyright 2014 Gorlum for http://supernova.ws
 */
define('INSIDE', true);
define('INSTALL', false);
define('IN_ADMIN', true);
require '../common.' . substr(strrchr(__FILE__, '.'), 1);
// if ($user['authlevel'] < 2)
if ($user['authlevel'] < 3) {
    AdminMessage($lang['adm_err_denied']);
}
$template = gettemplate("admin/add_moon", true);
if (sys_get_param_str('mode') == 'addit') {
    $PlanetID = sys_get_param_id('user');
    $MoonName = sys_get_param_str('name');
    sn_db_transaction_start();
    $PlanetSelected = db_planet_by_id($PlanetID, true, '`galaxy`, `system`, `planet`, `id_owner`');
    uni_create_moon($PlanetSelected['galaxy'], $PlanetSelected['system'], $PlanetSelected['planet'], $PlanetSelected['id_owner'], 0, $MoonName);
    sn_db_transaction_commit();
    AdminMessage($lang['addm_done'], $lang['addm_title']);
}
display($template, $lang['addm_title'], false, '', true);
Пример #10
0
function sn_sys_planet_core_transmute(&$user, &$planetrow)
{
    if (!sys_get_param_str('transmute')) {
        return array();
    }
    global $lang;
    try {
        if ($planetrow['planet_type'] != PT_PLANET) {
            throw new exception($lang['ov_core_err_not_a_planet'], ERR_ERROR);
        }
        if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) {
            throw new exception($lang['ov_core_err_same_density'], ERR_WARNING);
        }
        sn_db_transaction_start();
        $user = db_user_by_id($user['id'], true, '*');
        $planetrow = db_planet_by_id($planetrow['id'], true, '*');
        //    $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
        //    $user = $global_data['user'];
        //    $planetrow = $global_data['planet'];
        $planet_density_index = $planetrow['density_index'];
        $density_price_chart = planet_density_price_chart($planet_density_index);
        if (!isset($density_price_chart[$new_density_index])) {
            // Hack attempt
            throw new exception($lang['ov_core_err_denisty_type_wrong'], ERR_ERROR);
        }
        $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
        $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost');
        $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index];
        if ($user_dark_matter < $transmute_cost) {
            throw new exception($lang['ov_core_err_no_dark_matter'], ERR_ERROR);
        }
        $sn_data_planet_density = sn_get_groups('planet_density');
        foreach ($sn_data_planet_density as $key => $value) {
            if ($key == $new_density_index) {
                break;
            }
            $prev_density_index = $key;
        }
        $new_density = round(($sn_data_planet_density[$new_density_index][UNIT_PLANET_DENSITY] + $sn_data_planet_density[$prev_density_index][UNIT_PLANET_DENSITY]) / 2);
        rpg_points_change($user['id'], RPG_PLANET_DENSITY_CHANGE, -$transmute_cost, array('Planet %1$s ID %2$d at coordinates %3$s changed density type from %4$d "%5$s" to %6$d "%7$s". New density is %8$d kg/m3', $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), $planet_density_index, $lang['uni_planet_density_types'][$planet_density_index], $new_density_index, $lang['uni_planet_density_types'][$new_density_index], $new_density));
        db_planet_set_by_id($planetrow['id'], "`density` = {$new_density}, `density_index` = {$new_density_index}");
        sn_db_transaction_commit();
        $planetrow['density'] = $new_density;
        $planetrow['density_index'] = $new_density_index;
        $result = array('STATUS' => ERR_NONE, 'MESSAGE' => sprintf($lang['ov_core_err_none'], $lang['uni_planet_density_types'][$planet_density_index], $lang['uni_planet_density_types'][$new_density_index], $new_density));
    } catch (exception $e) {
        sn_db_transaction_rollback();
        $result = array('STATUS' => $e->getCode(), 'MESSAGE' => $e->getMessage());
    }
    return $result;
}
Пример #11
0
/**
* int_banner_create.php
* @version 2.0
* @copyright 2010 Gorlum for http://supernova.ws
*
* heavily based on
*   CreateBanner.php
*   @version 1.2 by Ihor
*   @version 1.0 copyright 2008 By e-Zobar for XNova
*/
function int_banner_create($id, $type = 'userbar', $format = 'png')
{
    // banner.php?id=<userid>&type=<banner|userbar>&format=<png>
    global $config, $lang;
    $id = intval($id);
    switch ($type) {
        case 'banner':
            $img_name = $config->int_banner_background;
            break;
        default:
            $img_name = $config->int_userbar_background;
            break;
    }
    $size = getimagesize(SN_ROOT_PHYSICAL . $img_name);
    $im = imagecreatefrompng(SN_ROOT_PHYSICAL . $img_name);
    $image = imagecreatetruecolor($size[0], $size[1]);
    imagecopy($image, $im, 0, 0, 0, 0, $size[0], $size[1]);
    imagedestroy($im);
    // Colors
    $color = "FFFFFF";
    $red = hexdec(substr($color, 0, 2));
    $green = hexdec(substr($color, 2, 4));
    $blue = hexdec(substr($color, 4, 6));
    $select = imagecolorallocate($image, $red, $green, $blue);
    $txt_shadow = imagecolorallocatealpha($image, 255, 255, 255, 255);
    $txt_color = imagecolorallocatealpha($image, 255, 255, 255, 2);
    $txt_shadow2 = imagecolorallocatealpha($image, 255, 255, 255, 255);
    $txt_color2 = imagecolorallocatealpha($image, 255, 255, 255, 40);
    $fonts = array('userbar' => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_userbar_font, 'universe' => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontUniverse, 'raids' => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontRaids, 'info' => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontInfo);
    if ($id) {
        // Querys
        $user = db_user_by_id($id);
        $planet_row = db_planet_by_id($user['id_planet']);
        // Variables
        $b_user = $user['username'];
        $b_ally = $user['ally_name'];
        $b_planet = $planet_row['name'];
        $b_xyz = "[" . $planet_row['galaxy'] . ":" . $planet_row['system'] . ":" . $planet_row['planet'] . "]";
        $b_lvl = ($user['total_rank'] ? $user['total_rank'] : $config->users_amount) . "/{$config->users_amount}";
    } else {
        $b_user = $lang['ov_banner_empty_id'];
    }
    $b_univ = $config->game_name;
    switch ($type) {
        case 'banner':
            // Banner size 416 x 58
            $fsize = 15;
            $is = imagettfbbox($fsize, 0, $fonts['universe'], $b_univ);
            imagettftext($image, $fsize, 0, $size[0] - 4 - $is[2], $size[1] - 2, $txt_shadow, $fonts['universe'], $b_univ);
            imagettftext($image, $fsize, 0, $size[0] - 6 - $is[2], $size[1] - 4, $txt_color, $fonts['universe'], $b_univ);
            // Player name
            imagettftext($image, 11, 0, 8, 26, $txt_shadow, $fonts['info'], $b_user);
            imagettftext($image, 11, 0, 6, 23, $txt_color, $fonts['info'], $b_user);
            if ($id) {
                // Player level - right-alligned
                $is = imagettfbbox(11, 0, $fonts['info'], $b_lvl);
                imagettftext($image, 11, 0, $size[0] - 4 - $is[2], 25, $txt_shadow, $fonts['info'], $b_lvl);
                imagettftext($image, 11, 0, $size[0] - 6 - $is[2], 23, $txt_color, $fonts['info'], $b_lvl);
                // Ally name
                $is = imagettfbbox(9, 0, $fonts['info'], $b_ally);
                imagettftext($image, 9, 0, 412 - $is[2], 37, $txt_shadow, $fonts['info'], $b_ally);
                imagettftext($image, 9, 0, 410 - $is[2], 35, $txt_color, $fonts['info'], $b_ally);
                // Player b_planet
                imagettftext($image, 6, 0, 8, 10, $txt_shadow2, $fonts['raids'], $b_planet . " " . $b_xyz);
                imagettftext($image, 6, 0, 6, 9, $txt_color2, $fonts['raids'], $b_planet . " " . $b_xyz);
                //StatPoint
                $b_points = $lang['ov_points'] . ": " . pretty_number($user['total_points']);
                $is = imagettfbbox(8, 0, $fonts['info'], $b_points);
                imagettftext($image, 8, 0, 412 - $is[2], 11, $txt_shadow, $fonts['info'], $b_points);
                imagettftext($image, 8, 0, 410 - $is[2], 9, $txt_color, $fonts['info'], $b_points);
                //Raids Total
                imagettftext($image, 6, 0, 8, 37, $txt_shadow2, $fonts['raids'], $lang['NumberOfRaids']);
                imagettftext($image, 6, 0, 6, 35, $txt_color2, $fonts['raids'], $lang['NumberOfRaids']);
                $b_points = ": " . pretty_number($user['raids']);
                imagettftext($image, 6, 0, 61, 37, $txt_shadow2, $fonts['raids'], $b_points);
                imagettftext($image, 6, 0, 59, 35, $txt_color2, $fonts['raids'], $b_points);
                //Raids Won
                imagettftext($image, 6, 0, 8, 47, $txt_shadow2, $fonts['raids'], $lang['RaidsWin']);
                imagettftext($image, 6, 0, 6, 45, $txt_color2, $fonts['raids'], $lang['RaidsWin']);
                $b_points = ": " . pretty_number($user['raidswin']);
                imagettftext($image, 6, 0, 61, 47, $txt_shadow2, $fonts['raids'], $b_points);
                imagettftext($image, 6, 0, 59, 45, $txt_color2, $fonts['raids'], $b_points);
                //Raids Lost
                imagettftext($image, 6, 0, 8, 57, $txt_shadow2, $fonts['raids'], $lang['RaidsLoose']);
                imagettftext($image, 6, 0, 6, 55, $txt_color2, $fonts['raids'], $lang['RaidsLoose']);
                $b_points = ": " . pretty_number($user['raidsloose']);
                imagettftext($image, 6, 0, 61, 57, $txt_shadow2, $fonts['raids'], $b_points);
                imagettftext($image, 6, 0, 59, 55, $txt_color2, $fonts['raids'], $b_points);
            }
            break;
        default:
            // Userbar 350 x 19
            $b_univ = strtoupper($b_univ);
            $is = imagettfbbox(9, 0, $fonts['userbar'], $b_univ);
            $is = $size[0] - $is[2] - 2;
            imagettftext($image, 9, 0, $is, $size[1] - 3, $txt_shadow, $fonts['userbar'], $b_univ);
            imagettftext($image, 9, 0, $is - 1, $size[1] - 5, $txt_color, $fonts['userbar'], $b_univ);
            imagettftext($image, 22, 0, $is - 8, $size[1], $txt_color, $fonts['userbar'], '/');
            // Player name
            imagettftext($image, 9, 0, 4, $size[1] - 4, $txt_shadow, $fonts['userbar'], $b_user);
            imagettftext($image, 9, 0, 2, $size[1] - 6, $txt_color, $fonts['userbar'], $b_user);
            if ($id) {
                // Player level - right-alligned
                $isp = imagettfbbox(9, 0, $fonts['userbar'], $b_lvl);
                imagettftext($image, 9, 0, $is - $isp[2] - 10, $size[1] - 4, $txt_shadow, $fonts['userbar'], $b_lvl);
                imagettftext($image, 9, 0, $is - $isp[2] - 10 - 1, $size[1] - 4 - 1, $txt_color, $fonts['userbar'], $b_lvl);
            }
    }
    //And now convert it back to PNG-8
    $im_result = imagecreate($size[0], $size[1]);
    imagecopy($im_result, $image, 0, 0, 0, 0, $size[0], $size[1]);
    imagedestroy($image);
    //And save it
    $imagetypes = imagetypes();
    // TODO: Add support to different image types
    header("Content-type: image/png");
    imagepng($im_result);
    imagedestroy($im_result);
}
Пример #12
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);
}
Пример #13
0
function art_use(&$user, &$planetrow, $unit_id)
{
    global $lang;
    if (!in_array($unit_id, sn_get_groups('artifacts'))) {
        return;
    }
    sn_db_transaction_start();
    $user = db_user_by_id($user['id'], true);
    $unit_level = $artifact_level_old = mrc_get_level($user, array(), $unit_id, true);
    if ($unit_level > 0) {
        $db_changeset = array();
        switch ($unit_id) {
            case ART_LHC:
            case ART_HOOK_SMALL:
            case ART_HOOK_MEDIUM:
            case ART_HOOK_LARGE:
                $has_moon = db_planet_by_parent($planetrow['id'], true, '`id`');
                if ($planetrow['planet_type'] == PT_PLANET && !$has_moon['id']) {
                    $unit_level--;
                    $moon_chance = $unit_id == ART_LHC ? uni_calculate_moon_chance($planetrow['debris_metal'] + $planetrow['debris_crystal']) : ($unit_id == ART_HOOK_MEDIUM ? mt_rand(1100, 8999) : ($unit_id == ART_HOOK_SMALL ? 1100 : 8999));
                    $random = $unit_id == ART_LHC ? mt_rand(1, 100) : $moon_chance;
                    if ($random <= $moon_chance) {
                        $new_moon_row = uni_create_moon($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], $user['id'], $moon_chance);
                        $message = sprintf($lang['art_moon_create'][$unit_id], $new_moon_row['name'], uni_render_coordinates($planetrow), pretty_number($moon_chance));
                    } else {
                        $message = $lang['art_lhc_moon_fail'];
                    }
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_ADMIN, $lang['art_lhc_from'], $lang['art_lhc_subj'], $message);
                } else {
                    $message = $lang['art_moon_exists'];
                }
                break;
            case ART_RCD_SMALL:
            case ART_RCD_MEDIUM:
            case ART_RCD_LARGE:
                $planetrow = db_planet_by_id($planetrow['id'], true);
                if ($planetrow['planet_type'] != PT_PLANET) {
                    $message = $lang['art_rcd_err_moon'];
                    break;
                }
                $que = que_get($user['id'], $planetrow['id'], QUE_STRUCTURES, false);
                if (!empty($que['items'])) {
                    $message = $lang['art_rcd_err_que'];
                    break;
                }
                $artifact_deploy = get_unit_param($unit_id, P_DEPLOY);
                // $deployment_str = '';
                $sectors_used = 0;
                foreach ($artifact_deploy as $deploy_unit_id => $deploy_unit_level) {
                    if (!($levels_deployed = max(0, $deploy_unit_level - mrc_get_level($user, $planetrow, $deploy_unit_id, true, true)))) {
                        continue;
                    }
                    $sectors_used += $levels_deployed;
                    $db_changeset['unit'][] = sn_db_unit_changeset_prepare($deploy_unit_id, $levels_deployed, $user, $planetrow['id']);
                    //$deploy_unit_name = get_unit_param($deploy_unit_id, P_NAME);
                    //$deployment_str .= ",`{$deploy_unit_name}` = GREATEST(`{$deploy_unit_name}`, {$deploy_unit_level})";
                }
                if ($sectors_used == 0) {
                    $message = $lang['art_rcd_err_no_sense'];
                    break;
                }
                $unit_level--;
                db_planet_set_by_id($planetrow['id'], "`field_current` = `field_current` + {$sectors_used}");
                $message = sprintf($lang['art_rcd_ok'], $lang['tech'][$unit_id], $planetrow['name'], uni_render_coordinates($planetrow));
                msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_rcd_subj'], $lang['art_rcd_subj'], $message);
                break;
            case ART_HEURISTIC_CHIP:
                $que_item = null;
                $que = que_get($user['id'], $planetrow['id'], QUE_RESEARCH, true);
                $current_que =& $que['ques'][QUE_RESEARCH][$user['id']][0];
                if (!empty($current_que)) {
                    reset($current_que);
                    $que_item =& $que['ques'][QUE_RESEARCH][$user['id']][0][key($current_que)];
                }
                if (!empty($que_item) && $que_item['que_time_left'] > 60) {
                    $unit_level--;
                    $old_time = $que_item['que_time_left'];
                    $que_item['que_time_left'] = $que_item['que_time_left'] > PERIOD_HOUR ? ceil($que_item['que_time_left'] / 2) : 0;
                    db_que_set_time_left_by_id($que_item['que_id'], $que_item['que_time_left']);
                    $message = sprintf($lang['art_heurestic_chip_ok'], $lang['tech'][$que_item['que_unit_id']], $que_item['que_unit_level'], sys_time_human($old_time - $que_item['que_time_left']));
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_heurestic_chip_subj'], $lang['art_heurestic_chip_subj'], $message);
                } else {
                    $message = $lang['art_heurestic_chip_no_research'];
                }
                break;
            case ART_NANO_BUILDER:
                $planetrow = db_planet_by_id($planetrow['id'], true);
                $que_item = null;
                $que = que_get($user['id'], $planetrow['id'], QUE_STRUCTURES, true);
                $current_que =& $que['ques'][QUE_STRUCTURES][$user['id']][$planetrow['id']];
                // $que_item = &$que['que'][QUE_STRUCTURES][0];
                if (!empty($current_que)) {
                    reset($current_que);
                    $que_item =& $que['ques'][QUE_STRUCTURES][$user['id']][$planetrow['id']][key($current_que)];
                }
                if (isset($que_item) && $que_item['que_time_left'] > 60) {
                    $unit_level--;
                    $old_time = $que_item['que_time_left'];
                    $que_item['que_time_left'] = $que_item['que_time_left'] > PERIOD_HOUR ? ceil($que_item['que_time_left'] / 2) : 0;
                    db_que_set_time_left_by_id($que_item['que_id'], $que_item['que_time_left']);
                    $message = sprintf($lang['art_nano_builder_ok'], $que_item['que_unit_mode'] == BUILD_CREATE ? $lang['art_nano_builder_build'] : $lang['art_nano_builder_destroy'], $lang['tech'][$que_item['que_unit_id']], $que_item['que_unit_level'], $planetrow['name'], uni_render_coordinates($planetrow), sys_time_human($old_time - $que_item['que_time_left']));
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_nano_builder_subj'], $lang['art_nano_builder_subj'], $message);
                } else {
                    $message = $lang['art_nano_builder_no_que'];
                }
                break;
        }
        if ($unit_level != $artifact_level_old) {
            $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_level - $artifact_level_old, $user);
            db_changeset_apply($db_changeset);
        }
    } else {
        $message = $lang['art_err_no_artifact'];
    }
    sn_db_transaction_commit();
    message($message, "{$lang['tech'][UNIT_ARTIFACTS]} - {$lang['tech'][$unit_id]}", ($request_uri = sys_get_param_str_unsafe('REQUEST_URI')) ? $request_uri : 'artifacts' . DOT_PHP_EX . '#' . $unit_id, 5);
}