Пример #1
0
function deparse_sql($str)
{
    $sql_cmds = array('select', 'update', 'insert', 'delete', 'replace', 'create');
    for ($i = 0; $i < count($sql_cmds); ++$i) {
        if (stristr($str, $sql_cmds[$i])) {
            stgc_log('deparse_sql', 'Found ' . $sql_cmds[$i] . ' in ' . $str);
            message(GENERAL, 'Found illegal cmd in string', $sql_cmds[$i] . ' in ' . $str);
        }
    }
    return $str;
}
Пример #2
0
function create_planet($user_id, $id_type, $id_value, $selected_type = 'r', $race = 0)
{
    global $db, $game, $PLANETS_DATA;
    // Planet raw materials production according to its type
    $planet_templates = array('bbb' => array(-0.25, -0.25, -0.25), 'bnb' => array(-0.25, 0, -0.25), 'nbb' => array(0, -0.25, -0.25), 'bbn' => array(-0.25, -0.25, 0), 'nnb' => array(0, 0, -0.25), 'nbn' => array(0, -0.25, 0), 'bnn' => array(-0.25, 0, 0), 'nnn' => array(0, 0, 0), 'gnn' => array(0.25, 0, 0), 'ngn' => array(0, 0.25, 0), 'nng' => array(0, 0, 0.25), 'ggn' => array(0.25, 0.25, 0), 'ngg' => array(0, 0.25, 0.25), 'gng' => array(0.25, 0, 0.25), 'ggg' => array(0.25, 0.25, 0.25));
    // Planet type probability according to its orbit
    $planet_type_probabilities = array(0 => array('a' => 30, 'b' => 35, 'c' => 10, 'd' => 10, 's' => 5, 't' => 4, 'x' => 4, 'y' => 2), 1 => array('a' => 30, 'b' => 35, 'c' => 10, 'd' => 10, 's' => 5, 't' => 4, 'x' => 4, 'y' => 2), 2 => array('a' => 2, 'c' => 8, 'd' => 8, 'e' => 15, 'f' => 13, 'g' => 8, 'h' => 13, 'k' => 10, 'l' => 4, 'm' => 2, 'n' => 14, 'o' => 2, 'p' => 1), 3 => array('a' => 1, 'c' => 8, 'd' => 8, 'e' => 12, 'f' => 13, 'g' => 13, 'h' => 8, 'k' => 8, 'l' => 8, 'm' => 4, 'n' => 10, 'o' => 4, 'p' => 3), 4 => array('a' => 1, 'c' => 8, 'd' => 8, 'e' => 12, 'f' => 18, 'g' => 19, 'h' => 10, 'k' => 6, 'l' => 4, 'm' => 3, 'n' => 4, 'o' => 3, 'p' => 4), 5 => array('a' => 3, 'c' => 8, 'd' => 8, 'e' => 12, 'f' => 18, 'g' => 18, 'h' => 8, 'k' => 6, 'l' => 8, 'm' => 2, 'n' => 1, 'o' => 2, 'p' => 6), 6 => array('a' => 6, 'c' => 10, 'd' => 10, 'i' => 22, 'j' => 23, 's' => 14, 't' => 14), 7 => array('a' => 6, 'c' => 22, 'd' => 23, 'i' => 14, 'j' => 14, 's' => 10, 't' => 10));
    $system_id = $sector_id = 0;
    switch ($id_type) {
        case 'quadrant':
            $quadrant_id = $id_value;
            // Verify that a suitable system already exists
            // In one of 5 cases it creates in any case a new system
            if (mt_rand(1, 5) != 3) {
                $sector_id_min = ($quadrant_id - 1) * $game->sectors_per_quadrant + 1;
                // (id - 1) * 81
                $sector_id_max = $quadrant_id * $game->sectors_per_quadrant;
                // id * 81
                $sql = 'SELECT system_id, sector_id, system_n_planets
                        FROM starsystems
                        WHERE sector_id >= ' . $sector_id_min . ' AND
                              sector_id <= ' . $sector_id_max . ' AND
                              system_closed = 0 AND
                              system_n_planets < system_max_planets';
                if (($q_systems = $db->query($sql)) === false) {
                    message(DATABASE_ERROR, 'world::create_planet(): Could not query systems data');
                }
                $available_systems = array();
                $n_available = 0;
                while ($system = $db->fetchrow($q_systems)) {
                    $available_systems[] = array($system['sector_id'], $system['system_id']);
                    //if( ++$n_available > 30) break;
                }
                // Check if there are available systems!
                if (!empty($available_systems)) {
                    $chosen_system = $available_systems[array_rand($available_systems)];
                    $sector_id = $chosen_system[0];
                    $system_id = $chosen_system[1];
                }
            }
            // If a new system must be created ($system_id = 0), then it's orbitals are all free
            // (in the Alpha-2 it has nevertheless searched * roll *) )
            // Otherwise, a free search
            $free_distances = $game->planet_distances;
            if (!$system_id) {
                $_temp = create_system('quadrant', $quadrant_id, 0);
                $system_id = $_temp[0];
                $sector_id = $_temp[1];
            } else {
                $sql = 'SELECT planet_distance_id
                        FROM planets
                        WHERE system_id = ' . $system_id;
                if (($planet_did = $db->queryrowset($sql)) === false) {
                    message(DATABASE_ERROR, 'world::create_planet(): Could not query planets did data');
                }
                for ($i = 0; $i < count($planet_did); ++$i) {
                    unset($free_distances[$planet_did[$i]['planet_distance_id']]);
                }
                if (empty($free_distances)) {
                    message(GENERAL, 'Planet could not be created', 'world::create_planet(): $free_distances[] = empty');
                }
            }
            break;
        case 'sector':
            $sector_id = $id_value;
            // Verify that a suitable system already exists
            // In one of 3 cases it creates in any case a new system
            if (mt_rand(1, 3) != 2) {
                $sql = 'SELECT system_id, sector_id, system_n_planets, system_max_planets
                        FROM starsystems
                        WHERE sector_id >= ' . $sector_id . ' AND
                              system_closed = 0';
                if (($q_systems = $db->query($sql)) === false) {
                    message(DATABASE_ERROR, 'world::create_planet(): Could not query systems data');
                }
                while ($system = $db->fetchrow($q_systems)) {
                    if ($system['system_n_planets'] > $system['system_max_planets']) {
                        stgc_log('world', 'System ' . $system['system_id'] . ' has ' . $system['system_n_planets']);
                    } elseif ($system['system_n_planets'] < $system['system_max_planets']) {
                        $system_id = $system['system_id'];
                        $sector_id = $system['sector_id'];
                        break;
                    }
                }
            }
            // If a new system must be created ($system_id = 0), then it's orbitals are all free
            // (in the Alpha-2 it has nevertheless searched * roll *) )
            // Otherwise, a free search
            $free_distances = $game->planet_distances;
            if (!$system_id) {
                $_temp = create_system('sector', $sector_id, 0);
                $system_id = $_temp[0];
                //$sector_id = $_temp[1];
            } else {
                $sql = 'SELECT planet_distance_id
                        FROM planets
                        WHERE system_id = ' . $system_id;
                if (($planet_did = $db->queryrowset($sql)) === false) {
                    message(DATABASE_ERROR, 'world::create_planet(): Could not query planets did data');
                }
                for ($i = 0; $i < count($planet_did); ++$i) {
                    unset($free_distances[$planet_did[$i]['planet_distance_id']]);
                }
                if (empty($free_distances)) {
                    message(GENERAL, 'Planet could not be created', 'world::create_planet(): $free_distances[] = empty');
                }
            }
            break;
        case 'system':
            $free_distances = $game->planet_distances;
            $system_id = $id_value;
            // NOTE: The system chosen must exist
            /*
            $sql = 'SELECT sector_id, planet_distance_id
                    FROM planets
                    WHERE system_id = '.$system_id;
            */
            /* 16/06/08 - AC: First of all, obtain sector ID, starsystem may be empty! */
            $sql = 'SELECT sector_id
                    FROM starsystems
                    WHERE system_id = ' . $system_id;
            if (($system = $db->queryrow($sql)) === false) {
                message(DATABASE_ERROR, 'world::create_planet(): Could not query sector did data');
            }
            $sector_id = $system['sector_id'];
            /* 16/06/08 - AC: then check for already occupied planet slot */
            $sql = 'SELECT planet_distance_id
                    FROM planets
                    WHERE system_id = ' . $system_id;
            if (($planet_did = $db->queryrowset($sql)) === false) {
                message(DATABASE_ERROR, 'world::create_planet(): Could not query planet did data');
            }
            for ($i = 0; $i < count($planet_did); ++$i) {
                unset($free_distances[$planet_did[$i]['planet_distance_id']]);
            }
            break;
    }
    $planet_distance_id = array_rand($free_distances);
    $planet_distance_px = mt_rand($game->planet_distances[$planet_distance_id][0], $game->planet_distances[$planet_distance_id][1]);
    // Create!
    if (!$user_id) {
        $type_array = array();
        foreach ($planet_type_probabilities[$planet_distance_id] as $type => $probability) {
            for ($i = 0; $i < $probability; ++$i) {
                $type_array[] = $type;
            }
        }
        $planet_type = $type_array[array_rand($type_array)];
        $type_probabilities = array('bbb' => 1, 'bbn' => 3, 'bnb' => 3, 'nbb' => 3, 'bnn' => 5, 'nbn' => 5, 'nnb' => 5, 'nnn' => 50, 'gnn' => 5, 'ngn' => 5, 'nng' => 5, 'ggn' => 3, 'ngg' => 3, 'gng' => 3, 'ggg' => 1);
        $template_array = array();
        foreach ($type_probabilities as $type => $probability) {
            for ($i = 0; $i < $probability; ++$i) {
                $template_array[] = $type;
            }
        }
        $planet_template = $template_array[array_rand($template_array)];
        // Random variance of the constants basis of the planet
        $rateo_1 = round($PLANETS_DATA[$planet_type][0] + $planet_templates[$planet_template][0], 2);
        if ($rateo_1 < 0.1) {
            $rateo_1 = 0.1;
        }
        $rateo_2 = round($PLANETS_DATA[$planet_type][1] + $planet_templates[$planet_template][1], 2);
        if ($rateo_2 < 0.1) {
            $rateo_2 = 0.1;
        }
        $rateo_3 = round($PLANETS_DATA[$planet_type][2] + $planet_templates[$planet_template][2], 2);
        if ($rateo_3 < 0.1) {
            $rateo_3 = 0.1;
        }
        $rateo_4 = $PLANETS_DATA[$planet_type][3];
        $sql = 'INSERT INTO planets (planet_name, system_id, sector_id, planet_type, planet_owner, planet_owned_date, planet_distance_id, planet_distance_px, planet_covered_distance, planet_tick_cdistance, planet_max_cdistance, resource_1, resource_2, resource_3, resource_4, planet_points, rateo_1, rateo_2, rateo_3, rateo_4)
                VALUES ("' . UNINHABITATED_PLANET . '", ' . $system_id . ', ' . $sector_id . ', "' . $planet_type . '", 0, ' . $game->TIME . ', ' . $planet_distance_id . ', ' . $planet_distance_px . ', 0, ' . mt_rand(10, 30) . ', ' . 2 * M_PI * $planet_distance_px . ', 0, 0, 0, 0, 0, ' . $rateo_1 . ', ' . $rateo_2 . ', ' . $rateo_3 . ', ' . $rateo_4 . ')';
    } else {
        // If player selected a specific planet type
        if ($selected_type != 'r') {
            $planet_type = $selected_type;
        } else {
            $planet_type = mt_rand(1, 2) == 1 ? 'm' : 'o';
        }
        $rateo_1 = $PLANETS_DATA[$planet_type][0];
        $rateo_2 = $PLANETS_DATA[$planet_type][1];
        $rateo_3 = $PLANETS_DATA[$planet_type][2];
        $rateo_4 = $PLANETS_DATA[$planet_type][3];
        // Ok, let's boost new players a bit
        if (USER_START_BOOST) {
            global $MAX_BUILDING_LVL, $MAX_RESEARCH_LVL, $RACE_DATA, $MAX_POINTS;
            $sql = 'INSERT INTO planets
                        (planet_name,
                        system_id,
                        sector_id,
                        planet_type,
                        planet_owner,
                        planet_owned_date,
                        planet_distance_id,
                        planet_distance_px,
                        planet_covered_distance,
                        planet_tick_cdistance,
                        planet_max_cdistance,
                        building_1,
                        building_2,
                        building_3,
                        building_4,
                        building_5,
                        building_6,
                        building_7,
                        building_8,
                        building_9,
                        building_10,
                        building_11,
                        building_12,
                        research_1,
                        research_2,
                        research_4,
                        research_5,
                        resource_1,
                        resource_2,
                        resource_3,
                        resource_4,
                        planet_points,
                        planet_available_points,
                        recompute_static,
                        max_resources,
                        max_worker,
                        max_units,
                        workermine_1,workermine_2,workermine_3,
                        unit_1,unit_2,unit_3,unit_4,unit_5,unit_6,
                        rateo_1,rateo_2,rateo_3,rateo_4)
                    VALUES ("' . UNINHABITATED_COLONY . '",
                        ' . $system_id . ',
                        ' . $sector_id . ',
                        "' . $planet_type . '",
                        ' . $user_id . ',
                        ' . $game->TIME . ',
                        ' . $planet_distance_id . ',
                        ' . $planet_distance_px . ',
                        0,
                        ' . mt_rand(10, 30) . ',
                        ' . 2 * M_PI * $planet_distance_px . ',
                        ' . $MAX_BUILDING_LVL[1][0] . ',
                        ' . $MAX_BUILDING_LVL[1][1] . ',
                        ' . $MAX_BUILDING_LVL[1][2] . ',
                        ' . $MAX_BUILDING_LVL[1][3] . ',
                        ' . $MAX_BUILDING_LVL[1][4] . ',
                        ' . $MAX_BUILDING_LVL[1][5] . ',
                        ' . $MAX_BUILDING_LVL[1][6] . ',
                        ' . $MAX_BUILDING_LVL[1][7] . ',
                        ' . $MAX_BUILDING_LVL[1][8] . ',
                        ' . $MAX_BUILDING_LVL[1][9] . ',
                        ' . $MAX_BUILDING_LVL[1][10] . ',
                        ' . $MAX_BUILDING_LVL[1][11] . ',
                        5,
                        4,
                        6,
                        ' . $MAX_RESEARCH_LVL[1][4] . ',
                        ' . 150000 * $RACE_DATA[$race][9] . ',
                        ' . 150000 * $RACE_DATA[$race][10] . ',
                        ' . 150000 * $RACE_DATA[$race][11] . ',
                        ' . 10000 * $RACE_DATA[$race][12] . ',
                        10,
                        ' . $MAX_POINTS[1] . ',
                        1,
                        ' . $PLANETS_DATA[$planet_type][6] . ',
                        ' . $PLANETS_DATA[$planet_type][7] . ',
                        ' . $PLANETS_DATA[$planet_type][7] . ',
                        1600,1600,1600,
                        4000,2000,500,100,150,100,
                        ' . $rateo_1 . ',' . $rateo_2 . ',' . $rateo_3 . ',' . $rateo_4 . ')';
        } else {
            global $MAX_POINTS;
            $sql = 'INSERT INTO planets (planet_name, system_id, sector_id, planet_type, planet_owner, planet_owned_date, planet_distance_id, planet_distance_px, planet_covered_distance, planet_tick_cdistance, planet_max_cdistance, resource_1, resource_2, resource_3, resource_4, planet_points, planet_available_points, recompute_static, max_resources, max_worker, max_units, workermine_1, workermine_2, workermine_3, rateo_1, rateo_2, rateo_3, rateo_4)
                    VALUES ("' . UNINHABITATED_COLONY . '", ' . $system_id . ', ' . $sector_id . ', "' . $planet_type . '", ' . $user_id . ', ' . $game->TIME . ', ' . $planet_distance_id . ', ' . $planet_distance_px . ', 0, ' . mt_rand(10, 30) . ', ' . 2 * M_PI * $planet_distance_px . ', 200, 200, 100, 100, 10, ' . $MAX_POINTS[1] . ', 1, ' . $PLANETS_DATA[$planet_type][6] . ', ' . $PLANETS_DATA[$planet_type][7] . ', ' . $PLANETS_DATA[$planet_type][7] . ', 100, 100, 100, ' . $rateo_1 . ', ' . $rateo_2 . ', ' . $rateo_3 . ', ' . $rateo_4 . ')';
        }
    }
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'world::create_planet(): Could not insert new planet data');
    }
    $planet_id = $db->insert_id();
    $sql = 'UPDATE starsystems
            SET system_n_planets = system_n_planets + 1
            WHERE system_id = ' . $system_id;
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'world::create_planet(): Could not update starsystem data');
    }
    return $planet_id;
}
Пример #3
0
             $game->print_login_error('User is not yet activated');
             break;
         case 3:
             $game->print_login_error('User has requested cancellation');
             break;
         case 4:
             $game->print_login_error('User has requested cancellation');
             break;
     }
 }
 if ($player_data['user_vacation_start'] < $ACTUAL_TICK && $player_data['user_vacation_end'] > $ACTUAL_TICK) {
     $game->print_login_error('Holiday mode is running ' . format_time(3 * ($player_data['user_vacation_end'] - $ACTUAL_TICK)));
 }
 if ($player_data['user_override_uid'] != 0) {
     if ($player_data['user_auth_level'] != STGC_DEVELOPER) {
         stgc_log('override_error', $player_data['user_name'] . ' tried to override user ' . $player_data['user_override_uid']);
         $sql = 'UPDATE user
                 SET user_active = 0
                 WHERE user_id = ' . $player_data['user_id'];
         if (!$db->query($sql)) {
             message(DATABASE_ERROR, 'Could not update user ban data');
         }
         message(GENERAL, 'Protection violation occurred');
     }
     $sql = 'SELECT *
             FROM user
             WHERE user_id = ' . $player_data['user_override_uid'];
     if (($override_data = $db->queryrow($sql)) === false) {
         message(DATABASE_ERROR, 'Could not query user override data');
     }
     if (empty($override_data['user_id'])) {
Пример #4
0
$ACTUAL_TICK = $game->config['tick_id'];
$NEXT_TICK = $game->config['tick_time'] - time();
//$game->TIME;
$LAST_TICK_TIME = $game->config['tick_time'] - TICK_DURATION * 60;
// #############################################################################
// Session-System
include 'include/session.php';
if ($game->config['game_stopped'] == 1 && $game->player['user_auth_level'] != STGC_DEVELOPER) {
    message(GENERAL, $game->config['stop_message']);
}
// Define the Overlib Stylesets:
define('OVERLIB_STANDARD', "FGCOLOR, '#000000', TEXTCOLOR, '#ffffff', FGBACKGROUND,'" . FIXED_GFX_PATH . "skin1/bg_stars1.gif', BGCOLOR, '#335E35', BORDER, 2, CAPTIONFONT, 'Arial', CAPTIONSIZE, 2, TEXTFONT, 'Arial', TEXTSIZE, 2");
// #############################################################################
// Nach PHP/Perl-UserAgent suchen
if (stristr($_SERVER['HTTP_USER_AGENT'], 'php') || stristr($_SERVER['HTTP_USER_AGENT'], 'perl')) {
    stgc_log('illegal_user_agent', 'I don\'t like the user agent ' . $_SERVER['HTTP_USER_AGENT'] . ' of ' . $game->player['user_name']);
}
// #############################################################################
// Notepad-Actions
if (isset($_GET['show_notepad'])) {
    $db->query('UPDATE user SET user_hidenotepad = 0 WHERE user_id = ' . $game->player['user_id']);
    $game->player['user_hidenotepad'] = 0;
}
if (isset($_GET['hide_notepad'])) {
    $db->query('UPDATE user SET user_hidenotepad = 1 WHERE user_id = ' . $game->player['user_id']);
    $game->player['user_hidenotepad'] = 1;
}
if (isset($_POST['set_planet'])) {
    $game->set_planet((int) $_POST['quadrant'], $_POST['type']);
}
// #############################################################################