function run()
    {
        if (Config::get(ROOT_UNI)->ref_active != 1) {
            return null;
        }
        /** @var $langObjects Language[] */
        $langObjects = array();
        $db = Database::get();
        $sql = 'SELECT `username`, `ref_id`, `id`, `lang`, user.`universe`
		FROM %%USERS%% user
		INNER JOIN %%STATPOINTS%% as stats
		ON stats.`id_owner` = user.`id` AND stats.`stat_type` = :type AND stats.`total_points` >= :points
		WHERE user.`ref_bonus` = 1;';
        $userArray = $db->select($sql, array(':type' => 1, ':points' => Config::get(ROOT_UNI)->ref_minpoints));
        foreach ($userArray as $user) {
            if (!isset($langObjects[$user['lang']])) {
                $langObjects[$user['lang']] = new Language($user['lang']);
                $langObjects[$user['lang']]->includeData(array('L18N', 'INGAME', 'TECH', 'CUSTOM'));
            }
            $userConfig = Config::get($user['universe']);
            $LNG = $langObjects[$user['lang']];
            $sql = 'UPDATE %%USERS%% SET `darkmatter` = `darkmatter` + :bonus WHERE `id` = :userId;';
            $db->update($sql, array(':bonus' => $userConfig->ref_bonus, ':userId' => $user['ref_id']));
            $sql = 'UPDATE %%USERS%% SET `ref_bonus` = 0 WHERE `id` = :userId;';
            $db->update($sql, array(':userId' => $user['id']));
            $Message = sprintf($LNG['sys_refferal_text'], $user['username'], pretty_number($userConfig->ref_minpoints), pretty_number($userConfig->ref_bonus), $LNG['tech'][921]);
            PlayerUtil::sendMessage($user['ref_id'], '', $LNG['sys_refferal_from'], 4, sprintf($LNG['sys_refferal_title'], $user['username']), $Message, TIMESTAMP);
        }
        return true;
    }
 function send()
 {
     $username = HTTP::_GP('username', '', UTF8_SUPPORT);
     $prenom = HTTP::_GP('prenom', '', UTF8_SUPPORT);
     $email = HTTP::_GP('email', '');
     $sujet = HTTP::_GP('sujet', 0);
     $message = HTTP::_GP('message', '');
     $errors = array();
     if (!PlayerUtil::isMailValid($email)) {
         $errors[] = t('registerErrorMailInvalid');
     }
     if (empty($email)) {
         $errors[] = t('registerErrorMailEmpty');
     }
     if (empty($username)) {
         $errors[] = t('registerErrorMailEmpty');
     }
     if (empty($message)) {
         $errors[] = t('registerErrorMailEmpty');
     }
     if (!empty($errors)) {
         $this->printMessage(implode("<br>\r\n", $errors), NULL, array(array('label' => t('registerBack'), 'url' => 'javascript:window.history.back()')));
     }
     require 'includes/classes/Mail.class.php';
     $MailRAW = $GLOBALS['LNG']->getTemplate('email_vaild_contact');
     $MailContent = str_replace(array('{NAME}', '{FIRSTNAME}', '{EMAIL}', '{SUBJECT}', '{MESSAGE}', '{IP}'), array($username, $prenom, $email, $sujet, $message, $_SERVER['REMOTE_ADDR']), $MailRAW);
     $to = '(EMAIL)';
     $headers = 'From: ' . $email . '' . "\r\n";
     $headers .= 'Reply-To: ' . $email . '' . "\r\n";
     $headers .= "MIME-Version: 1.0\r\n";
     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
     //Mail::send($to, $username, Config::get('game_name'), $MailContent);
     mail('(EMAIL)', Config::get('game_name'), $MailContent, $headers);
     $this->redirectTo('index.php?page=disclamer');
 }
 function ReturnEvent()
 {
     $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
     $Message = sprintf($LNG['sys_stat_mess'], GetStartAddressLink($this->_fleet, ''), pretty_number($this->_fleet['fleet_resource_metal']), $LNG['tech'][901], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['tech'][902], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['tech'][903]);
     PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 4, $LNG['sys_mess_fleetback'], $Message, $this->_fleet['fleet_end_time'], NULL, 1, $this->_fleet['fleet_universe']);
     $this->RestoreFleet();
 }
Beispiel #4
0
 function send()
 {
     global $USER, $LNG;
     $ticketID = HTTP::_GP('id', 0);
     $message = HTTP::_GP('message', '', true);
     $change = HTTP::_GP('change_status', 0);
     $ticketDetail = $GLOBALS['DATABASE']->getFirstRow("SELECT ownerID, subject, status FROM " . TICKETS . " WHERE ticketID = " . $ticketID . ";");
     $status = $change ? $ticketDetail['status'] <= 1 ? 2 : 1 : 1;
     if (!$change && empty($message)) {
         HTTP::redirectTo('admin.php?page=support&mode=view&id=' . $ticketID);
     }
     $subject = "RE: " . $ticketDetail['subject'];
     if ($change && $status == 1) {
         $this->ticketObj->createAnswer($ticketID, $USER['id'], $USER['username'], $subject, $LNG['ti_admin_open'], $status);
     }
     if (!empty($message)) {
         $this->ticketObj->createAnswer($ticketID, $USER['id'], $USER['username'], $subject, $message, $status);
     }
     if ($change && $status == 2) {
         $this->ticketObj->createAnswer($ticketID, $USER['id'], $USER['username'], $subject, $LNG['ti_admin_close'], $status);
     }
     $subject = sprintf($LNG['sp_answer_message_title'], $ticketID);
     $text = sprintf($LNG['sp_answer_message'], $ticketID);
     PlayerUtil::sendMessage($ticketDetail['ownerID'], $USER['id'], $USER['username'], 4, $subject, $text, TIMESTAMP, NULL, 1, Universe::getEmulated());
     HTTP::redirectTo('admin.php?page=support');
 }
 function newPassword()
 {
     global $LNG;
     $userID = HTTP::_GP('u', 0);
     $validationKey = HTTP::_GP('k', '');
     $db = Database::get();
     $sql = "SELECT COUNT(*) as state FROM %%LOSTPASSWORD%% WHERE userID = :userID AND `key` = :validationKey AND `time` > :time AND hasChanged = 0;";
     $isValid = $db->selectSingle($sql, array(':userID' => $userID, ':validationKey' => $validationKey, ':time' => TIMESTAMP - 1800), 'state');
     if (empty($isValid)) {
         $this->printMessage($LNG['passwordValidInValid'], array(array('label' => $LNG['passwordBack'], 'url' => 'index.php')));
     }
     $newPassword = uniqid();
     $sql = "SELECT username, email_2 as mail, universe FROM %%USERS%% WHERE id = :userID;";
     $userData = $db->selectSingle($sql, array(':userID' => $userID));
     $config = Config::get($userData['universe']);
     $MailRAW = $LNG->getTemplate('email_lost_password_changed');
     $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{GAMEMAIL}', '{PASSWORD}'), array($userData['username'], $config->game_name . ' - ' . $config->uni_name, $config->smtp_sendmail, $newPassword), $MailRAW);
     $sql = "UPDATE %%USERS%% SET password = :newPassword WHERE id = :userID;";
     $db->update($sql, array(':userID' => $userID, ':newPassword' => PlayerUtil::cryptPassword($newPassword)));
     require 'includes/classes/Mail.class.php';
     $subject = sprintf($LNG['passwordChangedMailTitle'], $config->game_name);
     Mail::send($userData['mail'], $userData['username'], $subject, $MailContent);
     $sql = "UPDATE %%LOSTPASSWORD%% SET hasChanged = 1 WHERE userID = :userID AND `key` = :validationKey;";
     $db->update($sql, array(':userID' => $userID, ':validationKey' => $validationKey));
     $this->printMessage($LNG['passwordChangedMailSend'], array(array('label' => $LNG['passwordNext'], 'url' => 'index.php')));
 }
 function show()
 {
     if (empty($_POST)) {
         HTTP::redirectTo('index.php');
     }
     $db = Database::get();
     $username = HTTP::_GP('username', '', UTF8_SUPPORT);
     $password = HTTP::_GP('password', '', true);
     $sql = "SELECT id, password FROM %%USERS%% WHERE universe = :universe AND username = :username;";
     $loginData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':username' => $username));
     if (isset($loginData)) {
         $hashedPassword = PlayerUtil::cryptPassword($password);
         if ($loginData['password'] != $hashedPassword) {
             // Fallback pre 1.7
             if ($loginData['password'] == md5($password)) {
                 $sql = "UPDATE %%USERS%% SET password = :hashedPassword WHERE id = :loginID;";
                 $db->update($sql, array(':hashedPassword' => $hashedPassword, ':loginID' => $loginData['id']));
             } else {
                 HTTP::redirectTo('index.php?code=1');
             }
         }
         $session = Session::create();
         $session->userId = (int) $loginData['id'];
         $session->adminAccess = 0;
         $session->save();
         HTTP::redirectTo('game.php');
     } else {
         HTTP::redirectTo('index.php?code=1');
     }
 }
 private function _activeUser()
 {
     $validationID = HTTP::_GP('i', 0);
     $validationKey = HTTP::_GP('k', '');
     $userData = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS_VALID . " WHERE validationID = " . $validationID . " AND validationKey = '" . $GLOBALS['DATABASE']->escape($validationKey) . "';");
     if (!isset($userData)) {
         $this->printMessage(t('vertifyNoUserFound'));
     }
     $GLOBALS['DATABASE']->query("DELETE FROM " . USERS_VALID . " WHERE validationID = " . $validationID . ";");
     list($userID, $planetID) = PlayerUtil::createPlayer($userData['universe'], $userData['userName'], $userData['password'], $userData['email'], $userData['race'], $userData['language']);
     if (Config::get('mail_active', $userData['universe']) == 1) {
         require 'includes/classes/Mail.class.php';
         $MailSubject = t('registerMailCompleteTitle', Config::get('game_name', $userData['universe']));
         $MailRAW = $GLOBALS['LNG']->getTemplate('email_reg_done');
         $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{GAMEMAIL}'), array($userData['email'], Config::get('game_name') . ' - ' . Config::get('uni_name'), Config::get('smtp_sendmail')), $MailRAW);
         try {
             Mail::send($userData['email'], $userData['userName'], $MailSubject, $MailContent);
         } catch (Exception $e) {
             // This mail is wayne.
         }
     }
     if (!empty($userData['referralID'])) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET\n\t\t\t`ref_id`\t= " . $userData['referralID'] . ",\n\t\t\t`ref_bonus`\t= 1\n\t\t\tWHERE\n\t\t\t`id`\t\t= " . $userID . ";");
     }
     if (!empty($userData['externalAuthUID'])) {
         $GLOBALS['DATABASE']->query("INSERT INTO " . USERS_AUTH . " SET\n\t\t\t`id`\t\t= " . $userID . ",\n\t\t\t`account`\t= '" . $GLOBALS['DATABASE']->escape($userData['externalAuthUID']) . "',\n\t\t\t`mode`\t\t= '" . $GLOBALS['DATABASE']->escape($userData['externalAuthMethod']) . "';");
     }
     $nameSender = t('registerWelcomePMSenderName');
     $subject = t('registerWelcomePMSubject');
     $message = t('registerWelcomePMText', Config::get('game_name', $userData['universe']));
     SendSimpleMessage($userID, 1, TIMESTAMP, 1, $nameSender, $subject, $message);
     return array('userID' => $userID, 'userName' => $userData['userName'], 'planetID' => $planetID);
 }
function ShowPassEncripterPage()
{
    global $LNG;
    $Password = HTTP::_GP('md5q', '', true);
    $template = new template();
    $template->assign_vars(array('md5_md5' => $Password, 'md5_enc' => PlayerUtil::cryptPassword($Password), 'et_md5_encripter' => $LNG['et_md5_encripter'], 'et_encript' => $LNG['et_encript'], 'et_result' => $LNG['et_result'], 'et_pass' => $LNG['et_pass']));
    $template->show('PassEncripterPage.tpl');
}
function ShowSendMessagesPage()
{
    global $USER, $LNG;
    $ACTION = HTTP::_GP('action', '');
    if ($ACTION == 'send') {
        switch ($USER['authlevel']) {
            case AUTH_MOD:
                $class = 'mod';
                break;
            case AUTH_OPS:
                $class = 'ops';
                break;
            case AUTH_ADM:
                $class = 'admin';
                break;
            default:
                $class = '';
                break;
        }
        $Subject = HTTP::_GP('subject', '', true);
        $Message = HTTP::_GP('text', '', true);
        $Mode = HTTP::_GP('mode', 0);
        $Lang = HTTP::_GP('lang', '');
        if (!empty($Message) && !empty($Subject)) {
            require 'includes/classes/BBCode.class.php';
            if ($Mode == 0 || $Mode == 2) {
                $From = '<span class="' . $class . '">' . $LNG['user_level'][$USER['authlevel']] . ' ' . $USER['username'] . '</span>';
                $pmSubject = '<span class="' . $class . '">' . $Subject . '</span>';
                $pmMessage = '<span class="' . $class . '">' . BBCode::parse($Message) . '</span>';
                $USERS = $GLOBALS['DATABASE']->query("SELECT `id`, `username` FROM " . USERS . " WHERE `universe` = '" . Universe::getEmulated() . "'" . (!empty($Lang) ? " AND `lang` = '" . $GLOBALS['DATABASE']->sql_escape($Lang) . "'" : "") . ";");
                while ($UserData = $GLOBALS['DATABASE']->fetch_array($USERS)) {
                    $sendMessage = str_replace('{USERNAME}', $UserData['username'], $pmMessage);
                    PlayerUtil::sendMessage($UserData['id'], $USER['id'], $From, 50, $pmSubject, $sendMessage, TIMESTAMP, NULL, 1, Universe::getEmulated());
                }
            }
            if ($Mode == 1 || $Mode == 2) {
                require 'includes/classes/Mail.class.php';
                $userList = array();
                $USERS = $GLOBALS['DATABASE']->query("SELECT `email`, `username` FROM " . USERS . " WHERE `universe` = '" . Universe::getEmulated() . "'" . (!empty($Lang) ? " AND `lang` = '" . $GLOBALS['DATABASE']->sql_escape($Lang) . "'" : "") . ";");
                while ($UserData = $GLOBALS['DATABASE']->fetch_array($USERS)) {
                    $userList[$UserData['email']] = array('username' => $UserData['username'], 'body' => BBCode::parse(str_replace('{USERNAME}', $UserData['username'], $Message)));
                }
                Mail::multiSend($userList, strip_tags($Subject));
            }
            exit($LNG['ma_message_sended']);
        } else {
            exit($LNG['ma_subject_needed']);
        }
    }
    $sendModes = $LNG['ma_modes'];
    if (Config::get()->mail_active == 0) {
        unset($sendModes[1]);
        unset($sendModes[2]);
    }
    $template = new template();
    $template->assign_vars(array('langSelector' => array_merge(array('' => $LNG['ma_all']), $LNG->getAllowedLangs(false)), 'modes' => $sendModes));
    $template->show('SendMessagesPage.tpl');
}
 function ReturnEvent()
 {
     $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
     $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;';
     $planetName = Database::get()->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name');
     $Message = sprintf($LNG['sys_tran_mess_back'], $planetName, GetStartAddressLink($this->_fleet, ''));
     PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 4, $LNG['sys_mess_fleetback'], $Message, $this->_fleet['fleet_end_time'], NULL, 1, $this->_fleet['fleet_universe']);
     $this->RestoreFleet();
 }
 function TargetEvent()
 {
     global $resource;
     $iPlanetCount = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE `id_owner` = '" . $this->_fleet['fleet_owner'] . "' AND `planet_type` = '1' AND `destruyed` = '0';");
     $iGalaxyPlace = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE `id` = '" . $this->_fleet['fleet_end_id'] . "';");
     $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE `id` = '" . $this->_fleet['fleet_owner'] . "';");
     $senderPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . $this->_fleet['fleet_start_id'] . "';");
     $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
     $LNG = $this->getLanguage($senderUser['lang']);
     $MaxPlanets = PlayerUtil::maxPlanetCount($senderUser);
     if ($iGalaxyPlace != 0) {
         $TheMessage = sprintf($LNG['sys_colo_notfree'], GetTargetAdressLink($this->_fleet, ''));
         $this->setState(FLEET_RETURN);
     } elseif ($iPlanetCount >= $MaxPlanets) {
         $TheMessage = sprintf($LNG['sys_colo_maxcolo'], GetTargetAdressLink($this->_fleet, ''), $MaxPlanets);
         $this->setState(FLEET_RETURN);
     } elseif (PlayerUtil::allowPlanetPosition($this->_fleet['fleet_end_planet'], $senderUser) == false) {
         $TheMessage = sprintf($LNG['sys_colo_notech'], GetTargetAdressLink($this->_fleet, ''), $MaxPlanets);
         $this->setState(FLEET_RETURN);
     } else {
         require_once 'includes/functions/CreateOnePlanetRecord.php';
         $NewOwnerPlanet = CreateOnePlanetRecord($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $this->_fleet['fleet_universe'], $this->_fleet['fleet_owner'], $LNG['fcp_colony'], false, $senderUser['authlevel']);
         if ($NewOwnerPlanet === false) {
             $TheMessage = sprintf($LNG['sys_colo_badpos'], GetTargetAdressLink($this->_fleet, ''));
             $this->setState(FLEET_RETURN);
         } else {
             $this->_fleet['fleet_end_id'] = $NewOwnerPlanet;
             $TheMessage = sprintf($LNG['sys_colo_allisok'], GetTargetAdressLink($this->_fleet, ''));
             $this->StoreGoodsToPlanet();
             if ($this->_fleet['fleet_amount'] == 1) {
                 $this->KillFleet();
             } else {
                 $CurrentFleet = explode(";", $this->_fleet['fleet_array']);
                 $NewFleet = '';
                 foreach ($CurrentFleet as $Item => $Group) {
                     if (empty($Group)) {
                         continue;
                     }
                     $Class = explode(",", $Group);
                     if ($Class[0] == 208 && $Class[1] > 1) {
                         $NewFleet .= $Class[0] . "," . ($Class[1] - 1) . ";";
                     } elseif ($Class[0] != 208 && $Class[1] > 0) {
                         $NewFleet .= $Class[0] . "," . $Class[1] . ";";
                     }
                 }
                 $this->UpdateFleet('fleet_array', $NewFleet);
                 $this->UpdateFleet('fleet_amount', $this->_fleet['fleet_amount'] - 1);
                 $this->UpdateFleet('fleet_resource_metal', 0);
                 $this->UpdateFleet('fleet_resource_crystal', 0);
                 $this->UpdateFleet('fleet_resource_deuterium', 0);
                 $this->setState(FLEET_RETURN);
             }
         }
     }
     SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_start_time'], 4, $LNG['sys_colo_mess_from'], $LNG['sys_colo_mess_report'], $TheMessage);
     $this->SaveFleet();
 }
 function ReturnEvent()
 {
     $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
     $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;';
     $planetName = Database::get()->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name');
     $Message = sprintf($LNG['sys_fleet_won'], $planetName, GetTargetAdressLink($this->_fleet, ''), pretty_number($this->_fleet['fleet_resource_metal']), $LNG['tech'][901], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['tech'][902], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['tech'][903]);
     PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 4, $LNG['sys_mess_fleetback'], $Message, $this->_fleet['fleet_end_time'], NULL, 1, $this->_fleet['fleet_universe']);
     $this->RestoreFleet();
 }
 function ReturnEvent()
 {
     $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
     if ($this->_fleet['fleet_resource_darkmatter'] > 0) {
         $message = sprintf($LNG['sys_expe_back_home_with_dm'], $LNG['tech'][921], pretty_number($this->_fleet['fleet_resource_darkmatter']), $LNG['tech'][921]);
         $this->UpdateFleet('fleet_array', '220,0;');
     } else {
         $message = $LNG['sys_expe_back_home_without_dm'];
     }
     PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 4, $LNG['sys_mess_fleetback'], $message, $this->_fleet['fleet_end_time'], NULL, 1, $this->_fleet['fleet_universe']);
     $this->RestoreFleet();
 }
Beispiel #14
0
    function run()
    {
        $config = Config::get(ROOT_UNI);
        $unis = Universe::availableUniverses();
        //Delete old messages
        $del_before = TIMESTAMP - $config->del_oldstuff * 86400;
        $del_inactive = TIMESTAMP - $config->del_user_automatic * 86400;
        $del_deleted = TIMESTAMP - $config->del_user_manually * 86400;
        if ($del_inactive === TIMESTAMP) {
            $del_inactive = 2147483647;
        }
        $sql = 'DELETE FROM %%MESSAGES%% WHERE `message_time` < :time;';
        Database::get()->delete($sql, array(':time' => $del_before));
        $sql = 'DELETE FROM %%ALLIANCE%% WHERE `ally_members` = 0;';
        Database::get()->delete($sql);
        $sql = 'DELETE FROM %%PLANETS%% WHERE `destruyed` < :time AND `destruyed` != 0;';
        Database::get()->delete($sql, array(':time' => TIMESTAMP));
        $sql = 'DELETE FROM %%SESSION%% WHERE `lastonline` < :time;';
        Database::get()->delete($sql, array(':time' => TIMESTAMP - SESSION_LIFETIME));
        $sql = 'DELETE FROM %%FLEETS_EVENT%% WHERE fleetID NOT IN (SELECT fleet_id FROM %%FLEETS%%);';
        Database::get()->delete($sql);
        $sql = 'UPDATE %%USERS%% SET `email_2` = `email` WHERE `setmail` < :time;';
        Database::get()->update($sql, array(':time' => TIMESTAMP));
        $sql = 'SELECT `id` FROM %%USERS%% WHERE `authlevel` = :authlevel
		AND ((`db_deaktjava` != 0 AND `db_deaktjava` < :timeDeleted) OR `onlinetime` < :timeInactive);';
        $deleteUserIds = Database::get()->select($sql, array(':authlevel' => AUTH_USR, ':timeDeleted' => $del_deleted, ':timeInactive' => $del_inactive));
        if (empty($deleteUserIds)) {
            foreach ($deleteUserIds as $dataRow) {
                PlayerUtil::deletePlayer($dataRow['id']);
            }
        }
        foreach ($unis as $uni) {
            $sql = 'SELECT units FROM %%TOPKB%% WHERE `universe` = :universe ORDER BY units DESC LIMIT 99,1;';
            $battleHallLowest = Database::get()->selectSingle($sql, array(':universe' => $uni), 'units');
            if (!is_null($battleHallLowest)) {
                $sql = 'DELETE %%TOPKB%%, %%TOPKB_USERS%%
				FROM %%TOPKB%%
				INNER JOIN %%TOPKB_USERS%% USING (rid)
				WHERE `universe` = :universe AND `units` < :battleHallLowest;';
                Database::get()->delete($sql, array(':universe' => $uni, ':battleHallLowest' => $battleHallLowest));
            }
        }
        $sql = 'DELETE FROM %%RW%% WHERE `time` < :time AND `rid` NOT IN (SELECT `rid` FROM %%TOPKB%%);';
        Database::get()->delete($sql, array(':time' => $del_before));
    }
Beispiel #15
0
function ShowLoginPage()
{
    global $USER;
    $session = Session::create();
    if ($session->adminAccess == 1) {
        HTTP::redirectTo('admin.php');
    }
    if (isset($_REQUEST['admin_pw'])) {
        $password = PlayerUtil::cryptPassword($_REQUEST['admin_pw']);
        if ($password == $USER['password']) {
            $session->adminAccess = 1;
            HTTP::redirectTo('admin.php');
        }
    }
    $template = new template();
    $template->assign_vars(array('bodyclass' => 'standalone', 'username' => $USER['username']));
    $template->show('LoginPage.tpl');
}
 function lotinfo()
 {
     global $USER, $PLANET, $LNG, $UNI, $CONF, $resource, $pricelist;
     $lotID = HTTP::_GP('lotID', 0);
     $info = $GLOBALS['DATABASE']->query("SELECT DISTINCT ps.*, p.field_current, p.field_max, p.id_luna FROM uni1_planetauction as ps \n\tINNER JOIN " . PLANETS . " as p ON p.id = ps.planetID WHERE auctionID = " . $lotID . ";");
     $info = $GLOBALS['DATABASE']->fetch_array($info);
     $iPlanetCount = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE `id_owner` = '" . $USER['id'] . "' AND `planet_type` = '1' AND `destruyed` = '0' AND universe = " . $UNI . ";");
     $MaxPlanets = PlayerUtil::maxPlanetCount($USER);
     if ($iPlanetCount >= $MaxPlanets) {
         $this->printMessage("you can not buy additional planets as you have reached the max allowed planets / user!", true, array('game.php?page=Planeta', 2));
         die;
     } elseif ($USER['id'] == $info['selledID']) {
         $this->printMessage("you can not rebuy your old planets!", true, array('game.php?page=Planeta', 2));
         die;
     } else {
         $this->tplObj->loadscript("jquery.countdown.js");
         $this->tplObj->assign_vars(array('lotID' => $lotID, 'type' => $info['type'], 'field_max' => $info['field_max'], 'id_luna' => $info['id_luna'], 'planetID' => $info['planetID'], 'time' => !empty($info['time']) && $info['time'] > TIMESTAMP ? $info['time'] - TIMESTAMP : 0, 'current_price' => round($info['price'] + $info['price'] / 100 * 1)));
         $this->display("page.planetauctions.lot.tpl");
     }
 }
 private function _activeUser()
 {
     $validationID = HTTP::_GP('i', 0);
     $validationKey = HTTP::_GP('k', '');
     $userData = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS_VALID . " WHERE validationID = " . $validationID . " AND validationKey = '" . $GLOBALS['DATABASE']->escape($validationKey) . "';");
     if (!isset($userData)) {
         $this->printMessage(t('vertifyNoUserFound'));
     }
     $GLOBALS['DATABASE']->query("DELETE FROM " . USERS_VALID . " WHERE validationID = " . $validationID . ";");
     list($userID, $planetID) = PlayerUtil::createPlayer($userData['universe'], $userData['userName'], $userData['password'], $userData['email'], $userData['language'], $userData['planetName']);
     if (!empty($userData['referralID'])) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET\n\t\t\t`ref_id`\t= " . $userData['referralID'] . ",\n\t\t\t`ref_bonus`\t= 1\n\t\t\tWHERE\n\t\t\t`id`\t\t= " . $userID . ";");
     }
     if (!empty($userData['externalAuthUID'])) {
         $GLOBALS['DATABASE']->query("INSERT INTO " . USERS_AUTH . " SET\n\t\t\t`id`\t\t= " . $userID . ",\n\t\t\t`account`\t= '" . $GLOBALS['DATABASE']->escape($userData['externalAuthUID']) . "',\n\t\t\t`mode`\t\t= '" . $GLOBALS['DATABASE']->escape($userData['externalAuthMethod']) . "';");
     }
     $nameSender = t('registerWelcomePMSenderName');
     $subject = t('registerWelcomePMSubject');
     $message = t('registerWelcomePMText', Config::get('game_name', $userData['universe']));
     return array('userID' => $userID, 'userName' => $userData['userName'], 'planetID' => $planetID);
 }
 private function _activeUser()
 {
     global $LNG;
     $validationID = HTTP::_GP('i', 0);
     $validationKey = HTTP::_GP('k', '');
     $db = Database::get();
     $sql = "SELECT * FROM %%USERS_VALID%%\n\t\tWHERE validationID\t= :validationID\n\t\tAND validationKey\t= :validationKey\n\t\tAND universe\t\t= :universe;";
     $userData = $db->selectSingle($sql, array(':validationKey' => $validationKey, ':validationID' => $validationID, ':universe' => Universe::current()));
     if (empty($userData)) {
         $this->printMessage($LNG['vertifyNoUserFound']);
     }
     $config = Config::get();
     $sql = "DELETE FROM %%USERS_VALID%% WHERE validationID = :validationID;";
     $db->delete($sql, array(':validationID' => $validationID));
     list($userID, $planetID) = PlayerUtil::createPlayer($userData['universe'], $userData['userName'], $userData['password'], $userData['email'], $userData['language']);
     if ($config->mail_active == 1) {
         require 'includes/classes/Mail.class.php';
         $MailSubject = sprintf($LNG['registerMailCompleteTitle'], $config->game_name, Universe::current());
         $MailRAW = $LNG->getTemplate('email_reg_done');
         $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{GAMEMAIL}'), array($userData['userName'], $config->game_name . ' - ' . $config->uni_name, $config->smtp_sendmail), $MailRAW);
         try {
             Mail::send($userData['email'], $userData['userName'], $MailSubject, $MailContent);
         } catch (Exception $e) {
             // This mail is wayne.
         }
     }
     if (!empty($userData['referralID'])) {
         $sql = "UPDATE %%USERS%% SET\n\t\t\t`ref_id`\t= :referralId,\n\t\t\t`ref_bonus`\t= 1\n\t\t\tWHERE\n\t\t\t`id`\t\t= :userID;";
         $db->update($sql, array(':referralId' => $userData['referralID'], ':userID' => $userID));
     }
     if (!empty($userData['externalAuthUID'])) {
         $sql = "INSERT INTO %%USERS_AUTH%% SET\n\t\t\t`id`\t\t= :userID,\n\t\t\t`account`\t= :externalAuthUID,\n\t\t\t`mode`\t\t= :externalAuthMethod;";
         $db->insert($sql, array(':userID' => $userID, ':externalAuthUID' => $userData['externalAuthUID'], ':externalAuthMethod' => $userData['externalAuthMethod']));
     }
     $senderName = $LNG['registerWelcomePMSenderName'];
     $subject = $LNG['registerWelcomePMSubject'];
     $message = sprintf($LNG['registerWelcomePMText'], $config->game_name, $userData['universe']);
     PlayerUtil::sendMessage($userID, 1, $senderName, 1, $subject, $message, TIMESTAMP);
     return array('userID' => $userID, 'userName' => $userData['userName'], 'planetID' => $planetID);
 }
 function newPassword()
 {
     $userID = HTTP::_GP('u', 0);
     $validationKey = HTTP::_GP('k', '');
     $isValid = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . LOSTPASSWORD . " WHERE userID = " . $userID . " AND `key` = '" . $GLOBALS['DATABASE']->escape($validationKey) . "' AND time > " . (TIMESTAMP - 1800) . " AND hasChanged = 0;");
     if (empty($isValid)) {
         $this->printMessage(t('passwordValidInValid'), NULL, array(array('label' => t('passwordBack'), 'url' => 'index.php')));
     }
     $newPassword = uniqid();
     $userData = $GLOBALS['DATABASE']->getFirstRow("SELECT username, email_2 as mail FROM " . USERS . " WHERE id = " . $userID . ";");
     $MailRAW = $GLOBALS['LNG']->getTemplate('email_lost_password_changed');
     $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{GAMEMAIL}', '{PASSWORD}', '{EMAIL}', '{IP}', '{DATE}'), array($userData['username'], Config::get('game_name') . ' - ' . Config::get('uni_name'), Config::get('smtp_sendmail'), $newPassword, $email_2, $_SERVER['REMOTE_ADDR'], date("m.d.y")), $MailRAW);
     $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET password = '******' WHERE id = " . $userID . ";");
     require 'includes/classes/Mail.class.php';
     $headers = "From: support@battle-fighter.org\r\n";
     $headers .= "Reply-To: support@battle-fighter.org\r\n";
     $headers .= "MIME-Version: 1.0\r\n";
     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
     mail($userData['mail'], t('passwordChangedMailTitle', Config::get('game_name')), $MailContent, $headers);
     $GLOBALS['DATABASE']->query("UPDATE " . LOSTPASSWORD . " SET hasChanged = 1 WHERE userID = " . $userID . " AND `key` = '" . $GLOBALS['DATABASE']->escape($validationKey) . "';");
     $this->printMessage(t('passwordChangedMailSend'), NULL, array(array('label' => t('passwordNext'), 'url' => 'index.php')));
 }
 public function SetNextQueueTechOnTop()
 {
     global $resource, $LNG;
     if (empty($this->USER['b_tech_queue'])) {
         $this->USER['b_tech'] = 0;
         $this->USER['b_tech_id'] = 0;
         $this->USER['b_tech_planet'] = 0;
         $this->USER['b_tech_queue'] = '';
         return false;
     }
     $CurrentQueue = unserialize($this->USER['b_tech_queue']);
     $Loop = true;
     while ($Loop == true) {
         $ListIDArray = $CurrentQueue[0];
         $isAnotherPlanet = $ListIDArray[4] != $this->PLANET['id'];
         if ($isAnotherPlanet) {
             $sql = 'SELECT * FROM %%PLANETS%% WHERE id = :planetId;';
             $PLANET = Database::get()->selectSingle($sql, array(':planetId' => $ListIDArray[4]));
             $RPLANET = new ResourceUpdate(true, false);
             list(, $PLANET) = $RPLANET->CalcResource($this->USER, $PLANET, false, $this->USER['b_tech']);
         } else {
             $PLANET = $this->PLANET;
         }
         $PLANET[$resource[31] . '_inter'] = self::getNetworkLevel($this->USER, $PLANET);
         $Element = $ListIDArray[0];
         $Level = $ListIDArray[1];
         $costResources = BuildFunctions::getElementPrice($this->USER, $PLANET, $Element);
         $BuildTime = BuildFunctions::getBuildingTime($this->USER, $PLANET, $Element, $costResources);
         $HaveResources = BuildFunctions::isElementBuyable($this->USER, $PLANET, $Element, $costResources);
         $BuildEndTime = $this->USER['b_tech'] + $BuildTime;
         $CurrentQueue[0] = array($Element, $Level, $BuildTime, $BuildEndTime, $PLANET['id']);
         if ($HaveResources == true) {
             if (isset($costResources[901])) {
                 $PLANET[$resource[901]] -= $costResources[901];
             }
             if (isset($costResources[902])) {
                 $PLANET[$resource[902]] -= $costResources[902];
             }
             if (isset($costResources[903])) {
                 $PLANET[$resource[903]] -= $costResources[903];
             }
             if (isset($costResources[921])) {
                 $this->USER[$resource[921]] -= $costResources[921];
             }
             $this->USER['b_tech_id'] = $Element;
             $this->USER['b_tech'] = $BuildEndTime;
             $this->USER['b_tech_planet'] = $PLANET['id'];
             $this->USER['b_tech_queue'] = serialize($CurrentQueue);
             $Loop = false;
         } else {
             if ($this->USER['hof'] == 1) {
                 if (!isset($costResources[901])) {
                     $costResources[901] = 0;
                 }
                 if (!isset($costResources[902])) {
                     $costResources[902] = 0;
                 }
                 if (!isset($costResources[903])) {
                     $costResources[903] = 0;
                 }
                 $Message = sprintf($LNG['sys_notenough_money'], $PLANET['name'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $LNG['tech'][$Element], pretty_number($PLANET['metal']), $LNG['tech'][901], pretty_number($PLANET['crystal']), $LNG['tech'][902], pretty_number($PLANET['deuterium']), $LNG['tech'][903], pretty_number($costResources[901]), $LNG['tech'][901], pretty_number($costResources[902]), $LNG['tech'][902], pretty_number($costResources[903]), $LNG['tech'][903]);
                 PlayerUtil::sendMessage($this->USER['id'], 0, $this->USER['b_tech'], 99, $LNG['sys_techlist'], $LNG['sys_buildlist_fail'], $Message);
             }
             array_shift($CurrentQueue);
             if (count($CurrentQueue) == 0) {
                 $this->USER['b_tech'] = 0;
                 $this->USER['b_tech_id'] = 0;
                 $this->USER['b_tech_planet'] = 0;
                 $this->USER['b_tech_queue'] = '';
                 $Loop = false;
             } else {
                 $BaseTime = $BuildEndTime - $BuildTime;
                 $NewQueue = array();
                 foreach ($CurrentQueue as $ListIDArray) {
                     $ListIDArray[2] = BuildFunctions::getBuildingTime($this->USER, $PLANET, $ListIDArray[0]);
                     $BaseTime += $ListIDArray[2];
                     $ListIDArray[3] = $BaseTime;
                     $NewQueue[] = $ListIDArray;
                 }
                 $CurrentQueue = $NewQueue;
             }
         }
         if ($isAnotherPlanet) {
             $RPLANET->SavePlanetToDB($this->USER, $PLANET);
             $RPLANET = NULL;
             unset($RPLANET);
         } else {
             $this->PLANET = $PLANET;
         }
     }
     return true;
 }
 function delete()
 {
     global $LNG, $PLANET, $USER;
     $password = HTTP::_GP('password', '', true);
     if (!empty($password)) {
         $db = Database::get();
         $sql = "SELECT COUNT(*) as state FROM %%FLEETS%% WHERE\n                      (fleet_owner = :userID AND (fleet_start_id = :planetID OR fleet_start_id = :lunaID)) OR\n                      (fleet_target_owner = :userID AND (fleet_end_id = :planetID OR fleet_end_id = :lunaID));";
         $IfFleets = $db->selectSingle($sql, array(':userID' => $USER['id'], ':planetID' => $PLANET['id'], ':lunaID' => $PLANET['id_luna']), 'state');
         if ($IfFleets > 0) {
             $this->sendJSON(array('message' => $LNG['ov_abandon_planet_not_possible']));
         } elseif ($USER['id_planet'] == $PLANET['id']) {
             $this->sendJSON(array('message' => $LNG['ov_principal_planet_cant_abanone']));
         } elseif (PlayerUtil::cryptPassword($password) != $USER['password']) {
             $this->sendJSON(array('message' => $LNG['ov_wrong_pass']));
         } else {
             if ($PLANET['planet_type'] == 1) {
                 $sql = "UPDATE %%PLANETS%% SET destruyed = :time WHERE id = :planetID;";
                 $db->update($sql, array(':time' => TIMESTAMP + 86400, ':planetID' => $PLANET['id']));
                 $sql = "DELETE FROM %%PLANETS%% WHERE id = :lunaID;";
                 $db->delete($sql, array(':lunaID' => $PLANET['id_luna']));
             } else {
                 $sql = "UPDATE %%PLANETS%% SET id_luna = 0 WHERE id_luna = :planetID;";
                 $db->update($sql, array(':planetID' => $PLANET['id']));
                 $sql = "DELETE FROM %%PLANETS%% WHERE id = :planetID;";
                 $db->delete($sql, array(':planetID' => $PLANET['id']));
             }
             $session->planetId = $USER['id_planet'];
             $this->sendJSON(array('ok' => true, 'message' => $LNG['ov_planet_abandoned']));
         }
     }
 }
 function send()
 {
     global $LNG;
     $config = Config::get();
     if ($config->game_disable == 0 || $config->reg_closed == 1) {
         $this->printMessage($LNG['registerErrorUniClosed'], array(array('label' => $LNG['registerBack'], 'url' => 'javascript:window.history.back()')));
     }
     $userName = HTTP::_GP('username', '', UTF8_SUPPORT);
     $password = HTTP::_GP('password', '', true);
     $password2 = HTTP::_GP('passwordReplay', '', true);
     $mailAddress = HTTP::_GP('email', '');
     $mailAddress2 = HTTP::_GP('emailReplay', '');
     $rulesChecked = HTTP::_GP('rules', 0);
     $language = HTTP::_GP('lang', '');
     $referralID = HTTP::_GP('referralID', 0);
     $externalAuth = HTTP::_GP('externalAuth', array());
     if (!isset($externalAuth['account'], $externalAuth['method'])) {
         $externalAuthUID = 0;
         $externalAuthMethod = '';
     } else {
         $externalAuthUID = $externalAuth['account'];
         $externalAuthMethod = strtolower(str_replace(array('_', '\\', '/', '.', ""), '', $externalAuth['method']));
     }
     $errors = array();
     if (empty($userName)) {
         $errors[] = $LNG['registerErrorUsernameEmpty'];
     }
     if (!PlayerUtil::isNameValid($userName)) {
         $errors[] = $LNG['registerErrorUsernameChar'];
     }
     if (strlen($password) < 6) {
         $errors[] = $LNG['registerErrorPasswordLength'];
     }
     if ($password != $password2) {
         $errors[] = $LNG['registerErrorPasswordSame'];
     }
     if (!PlayerUtil::isMailValid($mailAddress)) {
         $errors[] = $LNG['registerErrorMailInvalid'];
     }
     if (empty($mailAddress)) {
         $errors[] = $LNG['registerErrorMailEmpty'];
     }
     if ($mailAddress != $mailAddress2) {
         $errors[] = $LNG['registerErrorMailSame'];
     }
     if ($rulesChecked != 1) {
         $errors[] = $LNG['registerErrorRules'];
     }
     $db = Database::get();
     $sql = "SELECT (\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM %%USERS%%\n\t\t\t\tWHERE universe = :universe\n\t\t\t\tAND username = :userName\n\t\t\t) + (\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM %%USERS_VALID%%\n\t\t\t\tWHERE universe = :universe\n\t\t\t\tAND username = :userName\n\t\t\t) as count;";
     $countUsername = $db->selectSingle($sql, array(':universe' => Universe::current(), ':userName' => $userName), 'count');
     $sql = "SELECT (\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM %%USERS%%\n\t\t\tWHERE universe = :universe\n\t\t\tAND (\n\t\t\t\temail = :mailAddress\n\t\t\t\tOR email_2 = :mailAddress\n\t\t\t)\n\t\t) + (\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM %%USERS_VALID%%\n\t\t\tWHERE universe = :universe\n\t\t\tAND email = :mailAddress\n\t\t) as count;";
     $countMail = $db->selectSingle($sql, array(':universe' => Universe::current(), ':mailAddress' => $mailAddress), 'count');
     if ($countUsername != 0) {
         $errors[] = $LNG['registerErrorUsernameExist'];
     }
     if ($countMail != 0) {
         $errors[] = $LNG['registerErrorMailExist'];
     }
     if ($config->capaktiv === '1') {
         require_once 'includes/libs/reCAPTCHA/recaptchalib.php';
         $recaptcha_challenge_field = HTTP::_GP('recaptcha_challenge_field', '');
         $recaptcha_response_field = HTTP::_GP('recaptcha_response_field', '');
         $resp = recaptcha_check_answer($config->capprivate, Session::getClientIp(), $recaptcha_challenge_field, $recaptcha_response_field);
         if (!$resp->is_valid) {
             $errors[] = $LNG['registerErrorCaptcha'];
         }
     }
     if (!empty($errors)) {
         $this->printMessage(implode("<br>\r\n", $errors), array(array('label' => $LNG['registerBack'], 'url' => 'javascript:window.history.back()')));
     }
     $path = 'includes/extauth/' . $externalAuthMethod . '.class.php';
     if (!empty($externalAuth['account']) && file_exists($path)) {
         require $path;
         $methodClass = ucwords($externalAuthMethod) . 'Auth';
         /** @var $authObj externalAuth */
         $authObj = new $methodClass();
         $externalAuthUID = 0;
         if ($authObj->isActiveMode() && $authObj->isValid()) {
             $externalAuthUID = $authObj->getAccount();
         }
     }
     if ($config->ref_active == 1 && !empty($referralID)) {
         $sql = "SELECT COUNT(*) as state FROM %%USERS%% WHERE id = :referralID AND universe = :universe;";
         $Count = $db->selectSingle($sql, array(':referralID' => $referralID, ':universe' => Universe::current()), 'state');
         if ($Count == 0) {
             $referralID = 0;
         }
     } else {
         $referralID = 0;
     }
     $validationKey = md5(uniqid('2m'));
     $sql = "INSERT INTO %%USERS_VALID%% SET\n\t\t\t\t`userName` = :userName,\n\t\t\t\t`validationKey` = :validationKey,\n\t\t\t\t`password` = :password,\n\t\t\t\t`email` = :mailAddress,\n\t\t\t\t`date` = :timestamp,\n\t\t\t\t`ip` = :remoteAddr,\n\t\t\t\t`language` = :language,\n\t\t\t\t`universe` = :universe,\n\t\t\t\t`referralID` = :referralID,\n\t\t\t\t`externalAuthUID` = :externalAuthUID,\n\t\t\t\t`externalAuthMethod` = :externalAuthMethod;";
     $db->insert($sql, array(':userName' => $userName, ':validationKey' => $validationKey, ':password' => PlayerUtil::cryptPassword($password), ':mailAddress' => $mailAddress, ':timestamp' => TIMESTAMP, ':remoteAddr' => Session::getClientIp(), ':language' => $language, ':universe' => Universe::current(), ':referralID' => $referralID, ':externalAuthUID' => $externalAuthUID, ':externalAuthMethod' => $externalAuthMethod));
     $validationID = $db->lastInsertId();
     $verifyURL = 'index.php?page=vertify&i=' . $validationID . '&k=' . $validationKey;
     if ($config->user_valid == 0 || !empty($externalAuthUID)) {
         $this->redirectTo($verifyURL);
     } else {
         require 'includes/classes/Mail.class.php';
         $MailRAW = $LNG->getTemplate('email_vaild_reg');
         $MailContent = str_replace(array('{USERNAME}', '{PASSWORD}', '{GAMENAME}', '{VERTIFYURL}', '{GAMEMAIL}'), array($userName, $password, $config->game_name . ' - ' . $config->uni_name, HTTP_PATH . $verifyURL, $config->smtp_sendmail), $MailRAW);
         $subject = sprintf($LNG['registerMailVertifyTitle'], $config->game_name);
         Mail::send($mailAddress, $userName, $subject, $MailContent);
         $this->printMessage($LNG['registerSendComplete']);
     }
 }
 function show()
 {
     global $USER, $CONF, $LNG, $UNI;
     $ranki = $GLOBALS['DATABASE']->query("SELECT `id`, s.total_rank, s.build_rank, s.tech_rank FROM " . USERS . " as u INNER JOIN " . STATPOINTS . " as s ON u.id = s.id_owner WHERE onlinetime < " . (TIMESTAMP - 15 * 24 * 60 * 60) . " AND bana = '0' LIMIT  5 ;");
     $balken = $GLOBALS['DATABASE']->countquery("SELECT COUNT(*) FROM " . USERS . " WHERE universe = " . $UNI . " AND onlinetime > '" . (TIMESTAMP - 45 * 60) . "';");
     $länge2 = 365 / $CONF['users_amount'];
     $länge = $balken * $länge2;
     $RangeList = array();
     while ($StatRow = $GLOBALS['DATABASE']->fetch_array($ranki)) {
         $RangeList[] = array('id' => $StatRow['id'], 'total_rank' => $StatRow['total_rank'], 'build_rank' => $StatRow['build_rank'], 'tech_rank' => $StatRow['tech_rank']);
     }
     if ($_POST) {
         $userName = HTTP::_GP('username', '', UTF8_SUPPORT);
         $password = HTTP::_GP('password', '', true);
         $mailAddress = HTTP::_GP('email', '');
         $rulesChecked = HTTP::_GP('rules', 0);
         $id = HTTP::_GP('idc', '');
         $allowedTo = $GLOBALS['DATABASE']->query("SELECT `id`, onlinetime, authlevel FROM " . USERS . " WHERE id = " . $id . " ;");
         $allowedTo = $GLOBALS['DATABASE']->fetch_array($allowedTo);
         $errors = array();
         if (Config::get('game_disable') == 0 || Config::get('reg_closed') == 1) {
             $this->printMessage(t('registerErrorUniClosed'), NULL, array(array('label' => t('registerBack'), 'url' => 'javascript:window.history.back()')));
         }
         //Esto es para verificar si existe ya un usuario con esa ip.
         if (empty($userName)) {
             $errors[] = t('registerErrorUsernameEmpty');
         }
         if ($allowedTo['onlinetime'] > TIMESTAMP - 15 * 24 * 60 * 60) {
             $errors[] = t('youcanttakeoverthisaccount');
         }
         if ($allowedTo['authlevel'] > 0) {
             $errors[] = t('adminaccount');
         }
         if (!PlayerUtil::isNameValid($userName)) {
             $errors[] = t('registerErrorUsernameChar');
         }
         if (strlen($password) < 6) {
             $errors[] = t('registerErrorPasswordLength');
         }
         if (!PlayerUtil::isMailValid($mailAddress)) {
             $errors[] = t('registerErrorMailInvalid');
         }
         if (empty($mailAddress)) {
             $errors[] = t('registerErrorMailEmpty');
         }
         if ($rulesChecked != 1) {
             $errors[] = t('registerErrorRules');
         }
         $countUsername = $GLOBALS['DATABASE']->getFirstCell("SELECT (\n\t\t\tSELECT COUNT(*) \n\t\t\tFROM " . USERS . " \n\t\t\tWHERE universe = " . $GLOBALS['UNI'] . "\n\t\t\tAND username = '******'DATABASE']->escape($userName) . "'\n\t\t) + (\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM " . USERS_VALID . "\n\t\t\tWHERE universe = " . $GLOBALS['UNI'] . "\n\t\t\tAND username = '******'DATABASE']->escape($userName) . "'\n\t\t);");
         $countMail = $GLOBALS['DATABASE']->getFirstCell("SELECT (\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM " . USERS . "\n\t\t\tWHERE universe = " . $GLOBALS['UNI'] . "\n\t\t\tAND (\n\t\t\t\temail = '" . $GLOBALS['DATABASE']->escape($mailAddress) . "'\n\t\t\t\tOR email_2 = '" . $GLOBALS['DATABASE']->escape($mailAddress) . "'\n\t\t\t)\n\t\t) + (\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM " . USERS_VALID . "\n\t\t\tWHERE universe = " . $GLOBALS['UNI'] . "\n\t\t\tAND email = '" . $GLOBALS['DATABASE']->escape($mailAddress) . "'\n\t\t);");
         if ($countUsername != 0) {
             $errors[] = t('registerErrorUsernameExist');
         }
         if ($countMail != 0) {
             $errors[] = t('registerErrorMailExist');
         }
         if (!empty($errors)) {
             $this->printMessage(implode("<br>\r\n", $errors), NULL, array(array('label' => t('registerBack'), 'url' => 'javascript:window.history.back()')));
         }
         $validationKey = md5(uniqid('2m'));
         $SQL = "UPDATE " . USERS . " SET\n\t\t\t\t`userName` = '" . $GLOBALS['DATABASE']->escape($userName) . "',\n\t\t\t\t`password` = '" . PlayerUtil::cryptPassword($password) . "',\n\t\t\t\t`email` = '" . $GLOBALS['DATABASE']->escape($mailAddress) . "',\n\t\t\t\t`darkmatter` = '300000',\n\t\t\t\t`ip_at_reg` = '" . $_SERVER['REMOTE_ADDR'] . "' WHERE id = '" . $id . "' ;";
         $GLOBALS['DATABASE']->query($SQL);
         $vertifyURL = 'game.php?page=overview';
         if (Config::get('user_valid') == 0 || !empty($externalAuthUID)) {
             $this->redirectTo($vertifyURL);
         } else {
             require 'includes/classes/Mail.class.php';
             $MailSubject = t('registerMailVertifyTitle');
             $MailRAW = $GLOBALS['LNG']->getTemplate('email_vaild_reg');
             $MailContent = str_replace(array('{USERNAME}', '{PASSWORD}', '{GAMENAME}', '{GAMEMAIL}'), array($userName, $password, Config::get('game_name') . ' - ' . Config::get('uni_name'), Config::get('smtp_sendmail')), $MailRAW);
             Mail::send($mailAddress, $userName, t('registerMailVertifyTitle', Config::get('game_name')), $MailContent);
             $this->printMessage(t('registerSendComplete'));
         }
     }
     $this->tplObj->assign_vars(array('RangeList' => $RangeList, 'reg_user' => $CONF['users_amount'], 'online_users' => $balken, 'balken'));
     $this->render('page.takeover.default.tpl');
 }
Beispiel #24
0
function ShowCreatorPage()
{
    global $LNG, $USER;
    $template = new template();
    switch ($_GET['mode']) {
        case 'user':
            $LNG->includeData(array('PUBLIC'));
            if ($_POST) {
                $UserName = HTTP::_GP('name', '', UTF8_SUPPORT);
                $UserPass = HTTP::_GP('password', '');
                $UserPass2 = HTTP::_GP('password2', '');
                $UserMail = HTTP::_GP('email', '');
                $UserMail2 = HTTP::_GP('email2', '');
                $UserAuth = HTTP::_GP('authlevel', 0);
                $Galaxy = HTTP::_GP('galaxy', 0);
                $System = HTTP::_GP('system', 0);
                $Planet = HTTP::_GP('planet', 0);
                $Language = HTTP::_GP('lang', '');
                $ExistsUser = $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . USERS . " WHERE universe = " . Universe::getEmulated() . " AND username = '******'DATABASE']->sql_escape($UserName) . "') + (SELECT COUNT(*) FROM " . USERS_VALID . " WHERE universe = " . Universe::getEmulated() . " AND username = '******'DATABASE']->sql_escape($UserName) . "')");
                $ExistsMails = $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . USERS . " WHERE universe = " . Universe::getEmulated() . " AND (email = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "' OR email_2 = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "')) + (SELECT COUNT(*) FROM " . USERS_VALID . " WHERE universe = " . Universe::getEmulated() . " AND email = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "')");
                $errors = "";
                $config = Config::get(Universe::getEmulated());
                if (!PlayerUtil::isMailValid($UserMail)) {
                    $errors .= $LNG['invalid_mail_adress'];
                }
                if (empty($UserName)) {
                    $errors .= $LNG['empty_user_field'];
                }
                if (strlen($UserPass) < 6) {
                    $errors .= $LNG['password_lenght_error'];
                }
                if ($UserPass != $UserPass2) {
                    $errors .= $LNG['different_passwords'];
                }
                if ($UserMail != $UserMail2) {
                    $errors .= $LNG['different_mails'];
                }
                if (!PlayerUtil::isNameValid($UserName)) {
                    $errors .= $LNG['user_field_specialchar'];
                }
                if ($ExistsUser != 0) {
                    $errors .= $LNG['user_already_exists'];
                }
                if ($ExistsMails != 0) {
                    $errors .= $LNG['mail_already_exists'];
                }
                if (!PlayerUtil::isPositionFree(Universe::getEmulated(), $Galaxy, $System, $Planet)) {
                    $errors .= $LNG['planet_already_exists'];
                }
                if ($Galaxy > $config->max_galaxy || $System > $config->max_system || $Planet > $config->max_planets) {
                    $errors .= $LNG['po_complete_all2'];
                }
                if (!empty($errors)) {
                    $template->message($errors, '?page=create&mode=user', 10, true);
                    exit;
                }
                $Language = array_key_exists($Language, $LNG->getAllowedLangs(false)) ? $Language : $config->lang;
                PlayerUtil::createPlayer(Universe::getEmulated(), $UserName, PlayerUtil::cryptPassword($UserPass), $UserMail, $Language, $Galaxy, $System, $Planet, $LNG['fcm_planet'], $UserAuth);
                $template->message($LNG['new_user_success'], '?page=create&mode=user', 5, true);
                exit;
            }
            $AUTH = array();
            $AUTH[AUTH_USR] = $LNG['user_level'][AUTH_USR];
            if ($USER['authlevel'] >= AUTH_OPS) {
                $AUTH[AUTH_OPS] = $LNG['user_level'][AUTH_OPS];
            }
            if ($USER['authlevel'] >= AUTH_MOD) {
                $AUTH[AUTH_MOD] = $LNG['user_level'][AUTH_MOD];
            }
            if ($USER['authlevel'] >= AUTH_ADM) {
                $AUTH[AUTH_ADM] = $LNG['user_level'][AUTH_ADM];
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'new_add_user' => $LNG['new_add_user'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'new_creator_go_back' => $LNG['new_creator_go_back'], 'universe' => $LNG['mu_universe'], 'user_reg' => $LNG['user_reg'], 'pass_reg' => $LNG['pass_reg'], 'pass2_reg' => $LNG['pass2_reg'], 'email_reg' => $LNG['email_reg'], 'email2_reg' => $LNG['email2_reg'], 'new_coord' => $LNG['new_coord'], 'new_range' => $LNG['new_range'], 'lang_reg' => $LNG['lang_reg'], 'new_title' => $LNG['new_title'], 'Selector' => array('auth' => $AUTH, 'lang' => $LNG->getAllowedLangs(false))));
            $template->show('CreatePageUser.tpl');
            break;
        case 'moon':
            if ($_POST) {
                $PlanetID = HTTP::_GP('add_moon', 0);
                $MoonName = HTTP::_GP('name', '', UTF8_SUPPORT);
                $Diameter = HTTP::_GP('diameter', 0);
                $MoonPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT temp_max, temp_min, id_luna, galaxy, system, planet, planet_type, destruyed, id_owner FROM " . PLANETS . " WHERE id = '" . $PlanetID . "' AND universe = '" . Universe::getEmulated() . "' AND planet_type = '1' AND destruyed = '0';");
                if (!isset($MoonPlanet)) {
                    $template->message($LNG['mo_planet_doesnt_exist'], '?page=create&mode=moon', 3, true);
                    exit;
                }
                $moonId = PlayerUtil::createMoon(Universe::getEmulated(), $MoonPlanet['galaxy'], $MoonPlanet['system'], $MoonPlanet['planet'], $MoonPlanet['id_owner'], 20, $_POST['diameter_check'] == 'on' ? NULL : $Diameter, $MoonName);
                if ($moonId !== false) {
                    $template->message($LNG['mo_moon_added'], '?page=create&mode=moon', 3, true);
                } else {
                    $template->message($LNG['mo_moon_unavaible'], '?page=create&mode=moon', 3, true);
                }
                exit;
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'universum' => $LNG['mu_universe'], 'po_add_moon' => $LNG['po_add_moon'], 'input_id_planet' => $LNG['input_id_planet'], 'mo_moon_name' => $LNG['mo_moon_name'], 'mo_diameter' => $LNG['mo_diameter'], 'mo_temperature' => $LNG['mo_temperature'], 'mo_fields_avaibles' => $LNG['mo_fields_avaibles'], 'button_add' => $LNG['button_add'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'mo_moon' => $LNG['fcm_moon'], 'new_creator_go_back' => $LNG['new_creator_go_back']));
            $template->show('CreatePageMoon.tpl');
            break;
        case 'planet':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $Galaxy = HTTP::_GP('galaxy', 0);
                $System = HTTP::_GP('system', 0);
                $Planet = HTTP::_GP('planet', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $field_max = HTTP::_GP('field_max', 0);
                $config = Config::get(Universe::getEmulated());
                if ($Galaxy > $config->max_galaxy || $System > $config->max_system || $Planet > $config->max_planets) {
                    $template->message($LNG['po_complete_all2'], '?page=create&mode=planet', 3, true);
                    exit;
                }
                $ISUser = $GLOBALS['DATABASE']->getFirstRow("SELECT id, authlevel FROM " . USERS . " WHERE id = '" . $id . "' AND universe = '" . Universe::getEmulated() . "';");
                if (!PlayerUtil::checkPosition(Universe::getEmulated(), $Galaxy, $System, $Planet) || !isset($ISUser)) {
                    $template->message($LNG['po_complete_all'], '?page=create&mode=planet', 3, true);
                    exit;
                }
                $planetId = PlayerUtil::createPlanet($Galaxy, $System, $Planet, Universe::getEmulated(), $id, NULL, false, $ISUser['authlevel']);
                $SQL = "UPDATE " . PLANETS . " SET ";
                if ($_POST['diameter_check'] != 'on' || $field_max > 0) {
                    $SQL .= "field_max = '" . $field_max . "' ";
                }
                if (!empty($name)) {
                    $SQL .= ", name = '" . $GLOBALS['DATABASE']->sql_escape($name) . "' ";
                }
                $SQL .= "WHERE ";
                $SQL .= "id = '" . $planetId . "'";
                $GLOBALS['DATABASE']->query($SQL);
                $template->message($LNG['po_complete_succes'], '?page=create&mode=planet', 3, true);
                exit;
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'po_add_planet' => $LNG['po_add_planet'], 'po_galaxy' => $LNG['po_galaxy'], 'po_system' => $LNG['po_system'], 'po_planet' => $LNG['po_planet'], 'input_id_user' => $LNG['input_id_user'], 'new_creator_coor' => $LNG['new_creator_coor'], 'po_name_planet' => $LNG['po_name_planet'], 'po_fields_max' => $LNG['po_fields_max'], 'button_add' => $LNG['button_add'], 'po_colony' => $LNG['fcp_colony'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'new_creator_go_back' => $LNG['new_creator_go_back']));
            $template->show('CreatePagePlanet.tpl');
            break;
        default:
            $template->assign_vars(array('new_creator_title_u' => $LNG['new_creator_title_u'], 'new_creator_title_p' => $LNG['new_creator_title_p'], 'new_creator_title_l' => $LNG['new_creator_title_l'], 'new_creator_title' => $LNG['new_creator_title']));
            $template->show('CreatePage.tpl');
            break;
    }
}
Beispiel #25
0
function ShowSearchPage()
{
    global $LNG, $USER;
    if ($_GET['delete'] == 'user') {
        PlayerUtil::deletePlayer((int) $_GET['user']);
        message($LNG['se_delete_succes_p'], '?page=search&search=users&minimize=on', 2);
    } elseif ($_GET['delete'] == 'planet') {
        PlayerUtil::deletePlanet((int) $_GET['planet']);
        message($LNG['se_delete_succes_p'], '?page=search&search=planet&minimize=on', 2);
    }
    $SearchFile = HTTP::_GP('search', '');
    $SearchFor = HTTP::_GP('search_in', '');
    $SearchMethod = HTTP::_GP('fuki', '');
    $SearchKey = HTTP::_GP('key_user', '', UTF8_SUPPORT);
    $Page = HTTP::_GP('side', 0);
    $Order = HTTP::_GP('key_order', '');
    $OrderBY = HTTP::_GP('key_acc', '');
    $limit = HTTP::_GP('limit', 25);
    $Selector = array('list' => array('users' => $LNG['se_users'], 'planet' => $LNG['se_planets'], 'moon' => $LNG['se_moons'], 'alliance' => $LNG['se_allys'], 'vacation' => $LNG['se_vacations'], 'banned' => $LNG['se_suspended'], 'admin' => $LNG['se_authlevels'], 'inactives' => $LNG['se_inactives'], 'online' => $LNG['online_users'], 'p_connect' => $LNG['se_planets_act']), 'search' => array('name' => $LNG['se_input_name'], 'id' => $LNG['input_id']), 'filter' => array('normal' => $LNG['se_type_all'], 'exacto' => $LNG['se_type_exact'], 'last' => $LNG['se_type_last'], 'first' => $LNG['se_type_first']), 'order' => array('ASC' => $LNG['se_input_asc'], 'DESC' => $LNG['se_input_desc']), 'limit' => array('1' => '1', '5' => '5', '10' => '10', '15' => '15', '20' => '20', '25' => '25', '50' => '50', '100' => '100', '200' => '200', '500' => '500'));
    $template = new template();
    if (HTTP::_GP('minimize', '') == 'on') {
        $Minimize = "&amp;minimize=on";
        $template->assign_vars(array('minimize' => 'checked = "checked"', 'diisplaay' => 'style="display:none;"'));
    }
    switch ($SearchMethod) {
        case 'exacto':
            $SpecifyWhere = "= '" . $GLOBALS['DATABASE']->sql_escape($SearchKey) . "'";
            break;
        case 'last':
            $SpecifyWhere = "LIKE '" . $GLOBALS['DATABASE']->sql_escape($SearchKey, true) . "%'";
            break;
        case 'first':
            $SpecifyWhere = "LIKE '%" . $GLOBALS['DATABASE']->sql_escape($SearchKey, true) . "'";
            break;
        default:
            $SpecifyWhere = "LIKE '%" . $GLOBALS['DATABASE']->sql_escape($SearchKey, true) . "%'";
            break;
    }
    if (!empty($SearchFile)) {
        $ArrayUsers = array("users", "vacation", "admin", "inactives", "online");
        $ArrayPlanets = array("planet", "moon", "p_connect");
        $ArrayBanned = array("banned");
        $ArrayAlliance = array("alliance");
        if (in_array($SearchFile, $ArrayUsers)) {
            $Table = "users";
            $NameLang = $LNG['se_search_users'];
            $SpecifyItems = "id,username,email_2,onlinetime,register_time,user_lastip,authlevel,bana,urlaubs_modus";
            $SName = $LNG['se_input_userss'];
            $SpecialSpecify = "";
            if ($SearchFile == "vacation") {
                $SpecialSpecify = "AND urlaubs_modus = '1'";
                $SName = $LNG['se_input_vacatii'];
            }
            if ($SearchFile == "online") {
                $SpecialSpecify = "AND onlinetime >= '" . (TIMESTAMP - 15 * 60) . "'";
                $SName = $LNG['se_input_connect'];
            }
            if ($SearchFile == "inactives") {
                $SpecialSpecify = "AND onlinetime < '" . (TIMESTAMP - 60 * 60 * 24 * 7) . "'";
                $SName = $LNG['se_input_inact'];
            }
            if ($SearchFile == "admin") {
                $SpecialSpecify = "AND authlevel <= '" . $USER['authlevel'] . "' AND authlevel > '0'";
                $SName = $LNG['se_input_admm'];
            }
            $SpecialSpecify .= " AND universe = '" . Universe::getEmulated() . "'";
            $SearchFor == "name" ? $WhereItem = "WHERE username" : ($WhereItem = "WHERE id");
            $ArrayOSec = array("id", "username", "email_2", "onlinetime", "register_time", "user_lastip", "authlevel", "bana", "urlaubs_modus");
            $Array0SecCount = count($ArrayOSec);
            for ($OrderNum = 0; $OrderNum < $Array0SecCount; $OrderNum++) {
                $OrderBYParse[$ArrayOSec[$OrderNum]] = $LNG['se_search_users'][$OrderNum];
            }
        } elseif (in_array($SearchFile, $ArrayPlanets)) {
            $Table = "planets p";
            $TableUsers = "2";
            $NameLang = $LNG['se_search_planets'];
            $SpecifyItems = "p.id,p.name,CONCAT(u.username, ' (ID:&nbsp;', p.id_owner, ')'),p.last_update,p.galaxy,p.system,p.planet,p.id_luna";
            if ($SearchFile == "planet") {
                $SpecialSpecify = "AND planet_type = '1'";
                $SName = $LNG['se_input_planett'];
            } elseif ($SearchFile == "moon") {
                $SpecialSpecify = "AND planet_type = '3'";
                $SName = $LNG['se_input_moonn'];
            } elseif ($SearchFile == "p_connect") {
                $SpecialSpecify = "AND last_update >= " . (TIMESTAMP - 60 * 60) . "";
                $SName = $LNG['se_input_act_pla'];
            }
            $SpecialSpecify .= " AND p.universe = " . Universe::getEmulated();
            $WhereItem = "LEFT JOIN " . USERS . " u ON u.id = p.id_owner ";
            if ($SearchFor == "name") {
                $WhereItem .= "WHERE p.name";
            } else {
                $WhereItem .= "WHERE p.id";
            }
            $ArrayOSec = array("id", "name", "id_owner", "id_luna", "last_update", "galaxy", "system", "planet");
            $Array0SecCount = count($ArrayOSec);
            for ($OrderNum = 0; $OrderNum < $Array0SecCount; $OrderNum++) {
                $OrderBYParse[$ArrayOSec[$OrderNum]] = $LNG['se_search_planets'][$OrderNum];
            }
        } elseif (in_array($SearchFile, $ArrayBanned)) {
            $Table = "banned";
            $NameLang = $LNG['se_search_banned'];
            $SpecifyItems = "id,who,time,longer,theme,author";
            $SName = $LNG['se_input_susss'];
            $SpecialSpecify = " AND universe = '" . Universe::getEmulated() . "'";
            $SearchFor == "name" ? $WhereItem = "WHERE who" : ($WhereItem = "WHERE id");
            $ArrayOSec = array("id", "who", "time", "longer", "theme", "author");
            $Array0SecCount = count($ArrayOSec);
            for ($OrderNum = 0; $OrderNum < $Array0SecCount; $OrderNum++) {
                $OrderBYParse[$ArrayOSec[$OrderNum]] = $LNG['se_search_banned'][$OrderNum];
            }
        } elseif (in_array($SearchFile, $ArrayAlliance)) {
            $Table = "alliance";
            $NameLang = $LNG['se_search_alliance'];
            $SpecifyItems = "id,ally_name,ally_tag,ally_owner,ally_register_time,ally_members";
            $SName = $LNG['se_input_allyy'];
            $SpecialSpecify = " AND ally_universe = '" . Universe::getEmulated() . "'";
            $SearchFor == "name" ? $WhereItem = "WHERE ally_name" : ($WhereItem = "WHERE id");
            $ArrayOSec = array("id", "ally_name", "ally_tag", "ally_owner", "ally_register_time", "ally_members");
            $Array0SecCount = count($ArrayOSec);
            for ($OrderNum = 0; $OrderNum < $Array0SecCount; $OrderNum++) {
                $OrderBYParse[$ArrayOSec[$OrderNum]] = $LNG['se_search_alliance'][$OrderNum];
            }
        }
        $RESULT = MyCrazyLittleSearch($SpecifyItems, $WhereItem, $SpecifyWhere, $SpecialSpecify, $Order, $OrderBY, $limit, $Table, $Page, $NameLang, $ArrayOSec, $Minimize, $SName, $SearchFile);
    }
    $template->assign_vars(array('Selector' => $Selector, 'limit' => $limit, 'search' => $SearchKey, 'SearchFile' => $SearchFile, 'SearchFor' => $SearchFor, 'SearchMethod' => $SearchMethod, 'Order' => $Order, 'OrderBY' => $OrderBY, 'OrderBYParse' => $OrderBYParse, 'se_search' => $LNG['se_search'], 'se_limit' => $LNG['se_limit'], 'se_asc_desc' => $LNG['se_asc_desc'], 'se_filter_title' => $LNG['se_filter_title'], 'se_search_in' => $LNG['se_search_in'], 'se_type_typee' => $LNG['se_type_typee'], 'se_intro' => $LNG['se_intro'], 'se_search_title' => $LNG['se_search_title'], 'se_contrac' => $LNG['se_contrac'], 'se_search_order' => $LNG['se_search_order'], 'ac_minimize_maximize' => $LNG['ac_minimize_maximize'], 'LIST' => $RESULT['LIST'], 'PAGES' => $RESULT['PAGES']));
    $template->show('SearchPage.tpl');
}
 function accept()
 {
     global $USER, $LNG;
     $id = HTTP::_GP('id', 0);
     $db = Database::get();
     $sql = "DELETE FROM %%BUDDY_REQUEST%% WHERE id = :id;";
     $db->delete($sql, array(':id' => $id));
     $sql = "SELECT sender, u.username FROM %%BUDDY%% b INNER JOIN %%USERS%% u ON sender = u.id WHERE b.id = :id;";
     $sender = $db->selectSingle($sql, array(':id' => $id));
     PlayerUtil::sendMessage($sender['sender'], $USER['id'], $USER['username'], 4, $LNG['bu_accepted_request_title'], sprintf($LNG['bu_accepted_request_body'], $sender['username'], $USER['username']), TIMESTAMP);
     $this->redirectTo("game.php?page=buddyList");
 }
 public function getACSPageData($fleetID)
 {
     global $USER, $LNG;
     $db = Database::get();
     $sql = "SELECT fleet_start_time, fleet_end_id, fleet_group, fleet_mess FROM %%FLEETS%% WHERE fleet_id = :fleetID;";
     $fleetData = $db->selectSingle($sql, array(':fleetID' => $fleetID));
     if ($db->rowCount() != 1) {
         return array();
     }
     if ($fleetData['fleet_mess'] == 1 || $fleetData['fleet_start_time'] <= TIMESTAMP) {
         return array();
     }
     if ($fleetData['fleet_group'] == 0) {
         $acsData = $this->createACS($fleetID, $fleetData);
     } else {
         $acsData = $this->loadACS($fleetData);
     }
     if (empty($acsData)) {
         return array();
     }
     $acsName = HTTP::_GP('acsName', '', UTF8_SUPPORT);
     if (!empty($acsName)) {
         if (PlayerUtil::isNameValid($acsName)) {
             $this->sendJSON($LNG['fl_acs_newname_alphanum']);
         }
         $sql = "UPDATE %%AKS%% SET name = acsName WHERE id = :acsID;";
         $db->update($sql, array(':acsName' => $acsName, ':acsID' => $acsData['id']));
         $this->sendJSON(false);
     }
     $invitedUsers = array();
     $sql = "SELECT id, username FROM %%USERS_ACS%% INNER JOIN %%USERS%% ON userID = id WHERE acsID = :acsID;";
     $userResult = $db->select($sql, array(':acsID' => $acsData['id']));
     foreach ($userResult as $userRow) {
         $invitedUsers[$userRow['id']] = $userRow['username'];
     }
     $newUser = HTTP::_GP('username', '', UTF8_SUPPORT);
     $statusMessage = "";
     if (!empty($newUser)) {
         $sql = "SELECT id FROM %%USERS%% WHERE universe = :universe AND username = :username;";
         $newUserID = $db->selectSingle($sql, array(':universe' => Universe::current(), ':username' => $newUser), 'id');
         if (empty($newUserID)) {
             $statusMessage = $LNG['fl_player'] . " " . $newUser . " " . $LNG['fl_dont_exist'];
         } elseif (isset($invitedUsers[$newUserID])) {
             $statusMessage = $LNG['fl_player'] . " " . $newUser . " " . $LNG['fl_already_invited'];
         } else {
             $statusMessage = $LNG['fl_player'] . " " . $newUser . " " . $LNG['fl_add_to_attack'];
             $sql = "INSERT INTO %%USERS_ACS%% SET acsID = :acsID, userID = :newUserID;";
             $db->insert($sql, array(':acsID' => $acsData['id'], ':newUserID' => $newUserID));
             $invitedUsers[$newUserID] = $newUser;
             $inviteTitle = $LNG['fl_acs_invitation_title'];
             $inviteMessage = $LNG['fl_player'] . $USER['username'] . $LNG['fl_acs_invitation_message'];
             PlayerUtil::sendMessage($newUserID, $USER['id'], TIMESTAMP, 1, $USER['username'], $inviteTitle, $inviteMessage);
         }
     }
     return array('invitedUsers' => $invitedUsers, 'acsName' => $acsData['name'], 'mainFleetID' => $fleetID, 'statusMessage' => $statusMessage);
 }
function ShowAccountEditorPage()
{
    global $LNG, $reslist, $resource;
    $template = new template();
    switch ($_GET['edit']) {
        case 'resources':
            $id = HTTP::_GP('id', 0);
            $id_dark = HTTP::_GP('id_dark', 0);
            $metal = max(0, round(HTTP::_GP('metal', 0.0)));
            $cristal = max(0, round(HTTP::_GP('cristal', 0.0)));
            $deut = max(0, round(HTTP::_GP('deut', 0.0)));
            $dark = HTTP::_GP('dark', 0);
            if ($_POST) {
                if (!empty($id)) {
                    $before = $GLOBALS['DATABASE']->getFirstRow("SELECT `metal`,`crystal`,`deuterium`,`universe`  FROM " . PLANETS . " WHERE `id` = '" . $id . "';");
                }
                if (!empty($id_dark)) {
                    $before_dm = $GLOBALS['DATABASE']->getFirstRow("SELECT `darkmatter` FROM " . USERS . " WHERE `id` = '" . $id_dark . "';");
                }
                if ($_POST['add']) {
                    if (!empty($id)) {
                        $SQL = "UPDATE " . PLANETS . " SET ";
                        $SQL .= "`metal` = `metal` + '" . $metal . "', ";
                        $SQL .= "`crystal` = `crystal` + '" . $cristal . "', ";
                        $SQL .= "`deuterium` = `deuterium` + '" . $deut . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after = array('metal' => $before['metal'] + $metal, 'crystal' => $before['crystal'] + $cristal, 'deuterium' => $before['deuterium'] + $deut);
                    }
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` + '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "' AND `universe` = '" . Universe::getEmulated() . "' ";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after_dm = array('darkmatter' => $before_dm['darkmatter'] + $dark);
                    }
                } elseif ($_POST['delete']) {
                    if (!empty($id)) {
                        $SQL = "UPDATE " . PLANETS . " SET ";
                        $SQL .= "`metal` = `metal` - '" . $metal . "', ";
                        $SQL .= "`crystal` = `crystal` - '" . $cristal . "', ";
                        $SQL .= "`deuterium` = `deuterium` - '" . $deut . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after = array('metal' => $before['metal'] - $metal, 'crystal' => $before['crystal'] - $cristal, 'deuterium' => $before['deuterium'] - $deut);
                    }
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` - '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after_dm = array('darkmatter' => $before_dm['darkmatter'] - $dark);
                    }
                }
                if (!empty($id)) {
                    $LOG = new Log(2);
                    $LOG->target = $id;
                    $LOG->universe = $before_dm['universe'];
                    $LOG->old = $before;
                    $LOG->new = $after;
                    $LOG->save();
                }
                if (!empty($id_dark)) {
                    $LOG = new Log(1);
                    $LOG->target = $id_dark;
                    $LOG->universe = $before_dm['universe'];
                    $LOG->old = $before_dm;
                    $LOG->new = $after_dm;
                    $LOG->save();
                }
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_res_sucess'], '?page=accounteditor&edit=resources');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_res_sucess'], '?page=accounteditor&edit=resources');
                    }
                }
                exit;
            }
            $template->show('AccountEditorPageResources.tpl');
            break;
        case 'ships':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['fleet'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_ships_sucess'], '?page=accounteditor&edit=ships');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_ships_sucess'], '?page=accounteditor&edit=ships');
                    }
                }
                exit;
            }
            $parse['ships'] = "";
            foreach ($reslist['fleet'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageShips.tpl');
            break;
        case 'defenses':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['defense'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                    $Name = $LNG['log_nomoree'];
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_defenses_success'], '?page=accounteditor&edit=defenses');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_defenses_success'], '?page=accounteditor&edit=defenses');
                    }
                }
                exit;
            }
            foreach ($reslist['defense'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageDefenses.tpl');
            break;
            break;
        case 'buildings':
            if ($_POST) {
                $PlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                if (!isset($PlanetData)) {
                    $template->message($LNG['ad_add_not_exist'], '?page=accounteditor&edit=buildings');
                }
                $before = array();
                $after = array();
                foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                    $before[$ID] = $PlanetData[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $Fields = 0;
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $Count = max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . $Count . "'";
                        $after[$ID] = $before[$ID] + $Count;
                        $Fields += $Count;
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= ", `field_current` = `field_current` + '" . $Fields . "'";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $Fields = 0;
                    $QryUpdate = array();
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $Count = max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . $Count . "'";
                        $after[$ID] = max($before[$ID] - $Count, 0);
                        $Fields += $Count;
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= ", `field_current` = `field_current` - '" . $Fields . "'";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = Universe::getEmulated();
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_build_success'], '?page=accounteditor&edit=buildings');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_build_success'], '?page=accounteditor&edit=buildings');
                    }
                }
                exit;
            }
            foreach ($reslist['build'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageBuilds.tpl');
            break;
        case 'researchs':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['tech'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(1);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_tech_success'], '?page=accounteditor&edit=researchs');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_tech_success'], '?page=accounteditor&edit=researchs');
                    }
                }
                exit;
            }
            foreach ($reslist['tech'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageResearch.tpl');
            break;
        case 'personal':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $username = HTTP::_GP('username', '', UTF8_SUPPORT);
                $password = HTTP::_GP('password', '', true);
                $email = HTTP::_GP('email', '');
                $email_2 = HTTP::_GP('email_2', '');
                $vacation = HTTP::_GP('vacation', '');
                $before = $GLOBALS['DATABASE']->getFirstRow("SELECT `username`,`email`,`email_2`,`password`,`urlaubs_modus`,`urlaubs_until` FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $after = array();
                $PersonalQuery = "UPDATE " . USERS . " SET ";
                if (!empty($username) && $id != ROOT_USER) {
                    $PersonalQuery .= "`username` = '" . $GLOBALS['DATABASE']->sql_escape($username) . "', ";
                    $after['username'] = $username;
                }
                if (!empty($email) && $id != ROOT_USER) {
                    $PersonalQuery .= "`email` = '" . $GLOBALS['DATABASE']->sql_escape($email) . "', ";
                    $after['email'] = $email;
                }
                if (!empty($email_2) && $id != ROOT_USER) {
                    $PersonalQuery .= "`email_2` = '" . $GLOBALS['DATABASE']->sql_escape($email_2) . "', ";
                    $after['email_2'] = $email_2;
                }
                if (!empty($password) && $id != ROOT_USER) {
                    $PersonalQuery .= "`password` = '" . $GLOBALS['DATABASE']->sql_escape(cryptPassword($password)) . "', ";
                    $after['password'] = cryptPassword($password) != $before['password'] ? 'CHANGED' : '';
                }
                $before['password'] = '';
                $Answer = 0;
                $TimeAns = 0;
                if ($vacation == 'yes') {
                    $Answer = 1;
                    $after['urlaubs_modus'] = 1;
                    $TimeAns = TIMESTAMP + $_POST['d'] * 86400 + $_POST['h'] * 3600 + $_POST['m'] * 60 + $_POST['s'];
                    $after['urlaubs_until'] = $TimeAns;
                }
                $PersonalQuery .= "`urlaubs_modus` = '" . $Answer . "', `urlaubs_until` = '" . $TimeAns . "' ";
                $PersonalQuery .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "'";
                $GLOBALS['DATABASE']->query($PersonalQuery);
                $LOG = new Log(1);
                $LOG->target = $id;
                $LOG->universe = $before['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                $template->message($LNG['ad_personal_succes'], '?page=accounteditor&edit=personal');
                exit;
            }
            $template->assign_vars(array('Selector' => array('' => $LNG['select_option'], 'yes' => $LNG['one_is_yes'][1], 'no' => $LNG['one_is_yes'][0])));
            $template->show('AccountEditorPagePersonal.tpl');
            break;
        case 'officiers':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['officier'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['officier'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['officier'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(1);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_offi_success'], '?page=accounteditor&edit=officiers');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_offi_success'], '?page=accounteditor&edit=officiers');
                    }
                }
                exit;
            }
            foreach ($reslist['officier'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageOfficiers.tpl');
            break;
        case 'planets':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $diameter = HTTP::_GP('diameter', 0);
                $fields = HTTP::_GP('fields', 0);
                $buildings = HTTP::_GP('0_buildings', '');
                $ships = HTTP::_GP('0_ships', '');
                $defenses = HTTP::_GP('0_defenses', '');
                $c_hangar = HTTP::_GP('0_c_hangar', '');
                $c_buildings = HTTP::_GP('0_c_buildings', '');
                $change_pos = HTTP::_GP('change_position', '');
                $galaxy = HTTP::_GP('g', 0);
                $system = HTTP::_GP('s', 0);
                $planet = HTTP::_GP('p', 0);
                if (!empty($name)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `name` = '" . $GLOBALS['DATABASE']->sql_escape($name) . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($buildings == 'on') {
                    foreach ($reslist['build'] as $ID) {
                        $BUILD[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $BUILD) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($ships == 'on') {
                    foreach ($reslist['fleet'] as $ID) {
                        $SHIPS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $SHIPS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($defenses == 'on') {
                    foreach ($reslist['defense'] as $ID) {
                        $DEFS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $DEFS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($c_hangar == 'on') {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `b_hangar` = '0', `b_hangar_plus` = '0', `b_hangar_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($c_buildings == 'on') {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `b_building` = '0', `b_building_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($diameter)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `diameter` = '" . $diameter . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($fields)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `field_max` = '" . $fields . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($change_pos == 'on' && $galaxy > 0 && $system > 0 && $planet > 0 && $galaxy <= Config::get(Universe::getEmulated())->max_galaxy && $system <= Config::get(Universe::getEmulated())->max_system && $planet <= Config::get(Universe::getEmulated())->max_planets) {
                    $P = $GLOBALS['DATABASE']->getFirstRow("SELECT galaxy,system,planet,planet_type FROM " . PLANETS . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                    if ($P['planet_type'] == '1') {
                        if (PlayerUtil::checkPosition(Universe::getEmulated(), $galaxy, $system, $planet, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets3'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                    } else {
                        if (PlayerUtil::checkPosition(Universe::getEmulated(), $galaxy, $system, $planet, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets5'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $Target = $GLOBALS['DATABASE']->getFirstRow("SELECT id_luna FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND `planet_type` = '1';");
                        if ($Target['id_luna'] != '0') {
                            $template->message($LNG['ad_pla_error_planets4'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $GLOBALS['DATABASE']->multi_query("UPDATE " . PLANETS . " SET `id_luna` = '0' WHERE `galaxy` = '" . $P['galaxy'] . "' AND `system` = '" . $P['system'] . "' AND `planet` = '" . $P['planet'] . "' AND `planet_type` = '1';UPDATE " . PLANETS . " SET `id_luna` = '" . $id . "'  WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND planet_type = '1';UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                        $QMOON2 = $GLOBALS['DATABASE']->getFirstRow("SELECT id_owner FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "';");
                        $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "', `id_owner` = '" . $QMOON2['id_owner'] . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "' AND `planet_type` = '3';");
                    }
                }
                $template->message($LNG['ad_pla_succes'], '?page=accounteditor&edit=planets');
                exit;
            }
            $template->show('AccountEditorPagePlanets.tpl');
            break;
        case 'alliances':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $changeleader = HTTP::_GP('changeleader', 0);
                $tag = HTTP::_GP('tag', '', UTF8_SUPPORT);
                $externo = HTTP::_GP('externo', '', true);
                $interno = HTTP::_GP('interno', '', true);
                $solicitud = HTTP::_GP('solicitud', '', true);
                $delete = HTTP::_GP('delete', '');
                $delete_u = HTTP::_GP('delete_u', '');
                $QueryF = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                if (!empty($name)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_name` = '" . $name . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($tag)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_tag` = '" . $tag . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                $QueryF2 = $GLOBALS['DATABASE']->getFirstRow("SELECT ally_id FROM " . USERS . " WHERE `id` = '" . $changeleader . "';");
                $GLOBALS['DATABASE']->multi_query("UPDATE " . ALLIANCE . " SET `ally_owner` = '" . $changeleader . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_rank_id` = '0' WHERE `id` = '" . $changeleader . "';");
                if (!empty($externo)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_description` = '" . $externo . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($interno)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_text` = '" . $interno . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($solicitud)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_request` = '" . $solicitud . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if ($delete == 'on') {
                    $GLOBALS['DATABASE']->multi_query("DELETE FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_rank_id` = '0', `ally_register_time` = '0' WHERE `ally_id` = '" . $id . "';");
                }
                if (!empty($delete_u)) {
                    $GLOBALS['DATABASE']->multi_query("UPDATE " . ALLIANCE . " SET `ally_members` = ally_members - 1 WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_rank_id` = '0', `ally_register_time` = '0' WHERE `id` = '" . $delete_u . "' AND `ally_id` = '" . $id . "';");
                }
                $template->message($LNG['ad_ally_succes'], '?page=accounteditor&edit=alliances');
                exit;
            }
            $template->show('AccountEditorPageAlliance.tpl');
            break;
        default:
            $template->show('AccountEditorPageMenu.tpl');
            break;
    }
}
Beispiel #29
0
function ShowQuickEditorPage()
{
    global $USER, $LNG, $reslist, $resource;
    $action = HTTP::_GP('action', '');
    $edit = HTTP::_GP('edit', '');
    $id = HTTP::_GP('id', 0);
    switch ($edit) {
        case 'planet':
            $DataIDs = array_merge($reslist['fleet'], $reslist['build'], $reslist['defense']);
            $SpecifyItemsPQ = "";
            foreach ($DataIDs as $ID) {
                $SpecifyItemsPQ .= "`" . $resource[$ID] . "`,";
            }
            $PlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT " . $SpecifyItemsPQ . " `name`, `id_owner`, `planet_type`, `galaxy`, `system`, `planet`, `destruyed`, `diameter`, `field_current`, `field_max`, `temp_min`, `temp_max`, `metal`, `crystal`, `deuterium` FROM " . PLANETS . " WHERE `id` = '" . $id . "';");
            if ($action == 'send') {
                $SQL = "UPDATE " . PLANETS . " SET ";
                $Fields = $PlanetData['field_current'];
                foreach ($DataIDs as $ID) {
                    $level = min(max(0, round(HTTP::_GP($resource[$ID], 0.0))), in_array($ID, $reslist['build']) ? 255 : 1.8446744073709552E+19);
                    if (in_array($ID, $reslist['allow'][$PlanetData['planet_type']])) {
                        $Fields += $level - $PlanetData[$resource[$ID]];
                    }
                    $SQL .= "`" . $resource[$ID] . "` = " . $level . ", ";
                }
                $SQL .= "`metal` = " . max(0, round(HTTP::_GP('metal', 0.0))) . ", ";
                $SQL .= "`crystal` = " . max(0, round(HTTP::_GP('crystal', 0.0))) . ", ";
                $SQL .= "`deuterium` = " . max(0, round(HTTP::_GP('deuterium', 0.0))) . ", ";
                $SQL .= "`field_current` = '" . $Fields . "', ";
                $SQL .= "`field_max` = '" . HTTP::_GP('field_max', 0) . "', ";
                $SQL .= "`name` = '" . $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT)) . "', ";
                $SQL .= "`eco_hash` = '' ";
                $SQL .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                $GLOBALS['DATABASE']->query($SQL);
                $old = array();
                $new = array();
                foreach (array_merge($DataIDs, $reslist['resstype'][1]) as $IDs) {
                    $old[$IDs] = $PlanetData[$resource[$IDs]];
                    $new[$IDs] = max(0, round(HTTP::_GP($resource[$IDs], 0.0)));
                }
                $old['field_max'] = $PlanetData['field_max'];
                $new['field_max'] = HTTP::_GP('field_max', 0);
                $LOG = new Log(2);
                $LOG->target = $id;
                $LOG->old = $old;
                $LOG->new = $new;
                $LOG->save();
                exit(sprintf($LNG['qe_edit_planet_sucess'], $PlanetData['name'], $PlanetData['galaxy'], $PlanetData['system'], $PlanetData['planet']));
            }
            $UserInfo = $GLOBALS['DATABASE']->getFirstRow("SELECT `username` FROM " . USERS . " WHERE `id` = '" . $PlanetData['id_owner'] . "' AND `universe` = '" . Universe::getEmulated() . "';");
            $build = $defense = $fleet = array();
            foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                $build[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            foreach ($reslist['fleet'] as $ID) {
                $fleet[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            foreach ($reslist['defense'] as $ID) {
                $defense[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            $template = new template();
            $template->assign_vars(array('build' => $build, 'fleet' => $fleet, 'defense' => $defense, 'id' => $id, 'ownerid' => $PlanetData['id_owner'], 'ownername' => $UserInfo['username'], 'name' => $PlanetData['name'], 'galaxy' => $PlanetData['galaxy'], 'system' => $PlanetData['system'], 'planet' => $PlanetData['planet'], 'field_min' => $PlanetData['field_current'], 'field_max' => $PlanetData['field_max'], 'temp_min' => $PlanetData['temp_min'], 'temp_max' => $PlanetData['temp_max'], 'metal' => floatToString($PlanetData['metal']), 'crystal' => floatToString($PlanetData['crystal']), 'deuterium' => floatToString($PlanetData['deuterium']), 'metal_c' => pretty_number($PlanetData['metal']), 'crystal_c' => pretty_number($PlanetData['crystal']), 'deuterium_c' => pretty_number($PlanetData['deuterium'])));
            $template->show('QuickEditorPlanet.tpl');
            break;
        case 'player':
            $DataIDs = array_merge($reslist['tech'], $reslist['officier']);
            $SpecifyItemsPQ = "";
            foreach ($DataIDs as $ID) {
                $SpecifyItemsPQ .= "`" . $resource[$ID] . "`,";
            }
            $UserData = $GLOBALS['DATABASE']->getFirstRow("SELECT " . $SpecifyItemsPQ . " `username`, `authlevel`, `galaxy`, `system`, `planet`, `id_planet`, `darkmatter`, `authattack`, `authlevel` FROM " . USERS . " WHERE `id` = '" . $id . "';");
            $ChangePW = $USER['id'] == ROOT_USER || $id != ROOT_USER && $USER['authlevel'] > $UserData['authlevel'];
            if ($action == 'send') {
                $SQL = "UPDATE " . USERS . " SET ";
                foreach ($DataIDs as $ID) {
                    $SQL .= "`" . $resource[$ID] . "` = " . min(abs(HTTP::_GP($resource[$ID], 0)), 255) . ", ";
                }
                $SQL .= "`darkmatter` = '" . max(HTTP::_GP('darkmatter', 0), 0) . "', ";
                if (!empty($_POST['password']) && $ChangePW) {
                    $SQL .= "`password` = '" . PlayerUtil::cryptPassword(HTTP::_GP('password', '', true)) . "', ";
                }
                $SQL .= "`username` = '" . $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT)) . "', ";
                $SQL .= "`authattack` = '" . ($UserData['authlevel'] != AUTH_USR && HTTP::_GP('authattack', '') == 'on' ? $UserData['authlevel'] : 0) . "' ";
                $SQL .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                $GLOBALS['DATABASE']->query($SQL);
                $old = array();
                $new = array();
                $multi = HTTP::_GP('multi', 0);
                foreach ($DataIDs as $IDs) {
                    $old[$IDs] = $UserData[$resource[$IDs]];
                    $new[$IDs] = abs(HTTP::_GP($resource[$IDs], 0));
                }
                $old[921] = $UserData[$resource[921]];
                $new[921] = abs(HTTP::_GP($resource[921], 0));
                $old['username'] = $UserData['username'];
                $new['username'] = $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT));
                $old['authattack'] = $UserData['authattack'];
                $new['authattack'] = $UserData['authlevel'] != AUTH_USR && HTTP::_GP('authattack', '') == 'on' ? $UserData['authlevel'] : 0;
                $old['multi'] = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $id . ";");
                $new['authattack'] = $multi;
                if ($old['multi'] != $multi) {
                    if ($multi == 0) {
                        $GLOBALS['DATABASE']->query("DELETE FROM " . MULTI . " WHERE userID = " . (int) $id . ";");
                    } elseif ($multi == 1) {
                        $GLOBALS['DATABASE']->query("INSERT INTO " . MULTI . " SET userID = " . (int) $id . ";");
                    }
                }
                $LOG = new Log(1);
                $LOG->target = $id;
                $LOG->old = $old;
                $LOG->new = $new;
                $LOG->save();
                exit(sprintf($LNG['qe_edit_player_sucess'], $UserData['username'], $id));
            }
            $PlanetInfo = $GLOBALS['DATABASE']->getFirstRow("SELECT `name` FROM " . PLANETS . " WHERE `id` = '" . $UserData['id_planet'] . "' AND `universe` = '" . Universe::getEmulated() . "';");
            $tech = array();
            $officier = array();
            foreach ($reslist['tech'] as $ID) {
                $tech[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($UserData[$resource[$ID]]), 'input' => $UserData[$resource[$ID]]);
            }
            foreach ($reslist['officier'] as $ID) {
                $officier[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($UserData[$resource[$ID]]), 'input' => $UserData[$resource[$ID]]);
            }
            $template = new template();
            $template->assign_vars(array('tech' => $tech, 'officier' => $officier, 'id' => $id, 'planetid' => $UserData['id_planet'], 'planetname' => $PlanetInfo['name'], 'name' => $UserData['username'], 'galaxy' => $UserData['galaxy'], 'system' => $UserData['system'], 'planet' => $UserData['planet'], 'authlevel' => $UserData['authlevel'], 'authattack' => $UserData['authattack'], 'multi' => $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $id . ";"), 'ChangePW' => $ChangePW, 'darkmatter' => floatToString($UserData['darkmatter']), 'darkmatter_c' => pretty_number($UserData['darkmatter'])));
            $template->show('QuickEditorUser.tpl');
            break;
    }
}
Beispiel #30
0
    function TargetEvent()
    {
        global $pricelist, $reslist, $resource;
        $db = Database::get();
        $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
        $senderUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
        $targetUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_target_owner']));
        $sql = 'SELECT * FROM %%PLANETS%% WHERE id = :planetId;';
        $targetPlanet = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id']));
        $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;';
        $senderPlanetName = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name');
        $LNG = $this->getLanguage($senderUser['lang']);
        $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
        $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']);
        $planetUpdater = new ResourceUpdate();
        list($targetUser, $targetPlanet) = $planetUpdater->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']);
        $sql = 'SELECT * FROM %%FLEETS%% WHERE fleet_end_id = :planetId AND fleet_mission = 5 AND fleet_end_stay > :time;';
        $targetStayFleets = $db->select($sql, array(':planetId' => $this->_fleet['fleet_end_id'], ':time' => $this->_fleet['fleet_start_time']));
        foreach ($targetStayFleets as $fleetRow) {
            $fleetData = FleetFunctions::unserialize($fleetRow['fleet_array']);
            foreach ($fleetData as $shipId => $shipAmount) {
                $targetPlanet[$resource[$shipId]] += $shipAmount;
            }
        }
        $fleetAmount = $this->_fleet['fleet_amount'] * (1 + $senderUser['factor']['SpyPower']);
        $senderSpyTech = max($senderUser['spy_tech'], 1);
        $targetSpyTech = max($targetUser['spy_tech'], 1);
        $techDifference = abs($senderSpyTech - $targetSpyTech);
        $MinAmount = ($senderSpyTech > $targetSpyTech ? -1 : 1) * pow($techDifference * SPY_DIFFENCE_FACTOR, 2);
        $SpyFleet = $fleetAmount >= $MinAmount;
        $SpyDef = $fleetAmount >= $MinAmount + 1 * SPY_VIEW_FACTOR;
        $SpyBuild = $fleetAmount >= $MinAmount + 3 * SPY_VIEW_FACTOR;
        $SpyTechno = $fleetAmount >= $MinAmount + 5 * SPY_VIEW_FACTOR;
        $classIDs[900] = array_merge($reslist['resstype'][1], $reslist['resstype'][2]);
        if ($SpyFleet) {
            $classIDs[200] = $reslist['fleet'];
        }
        if ($SpyDef) {
            $classIDs[400] = array_merge($reslist['defense'], $reslist['missile']);
        }
        if ($SpyBuild) {
            $classIDs[0] = $reslist['build'];
        }
        if ($SpyTechno) {
            $classIDs[100] = $reslist['tech'];
        }
        $targetChance = mt_rand(0, min($fleetAmount / 4 * ($targetSpyTech / $senderSpyTech), 100));
        $spyChance = mt_rand(0, 100);
        $spyData = array();
        foreach ($classIDs as $classID => $elementIDs) {
            foreach ($elementIDs as $elementID) {
                if (isset($targetUser[$resource[$elementID]])) {
                    $spyData[$classID][$elementID] = $targetUser[$resource[$elementID]];
                } else {
                    $spyData[$classID][$elementID] = $targetPlanet[$resource[$elementID]];
                }
            }
            if ($senderUser['spyMessagesMode'] == 1) {
                $spyData[$classID] = array_filter($spyData[$classID]);
            }
        }
        // I'm use template class here, because i want to exclude HTML in PHP.
        require_once 'includes/classes/class.template.php';
        $template = new template();
        $template->caching = true;
        $template->compile_id = $senderUser['lang'];
        $template->loadFilter('output', 'trimwhitespace');
        list($tplDir) = $template->getTemplateDir();
        $template->setTemplateDir($tplDir . 'game/');
        $template->assign_vars(array('spyData' => $spyData, 'targetPlanet' => $targetPlanet, 'targetChance' => $targetChance, 'spyChance' => $spyChance, 'isBattleSim' => ENABLE_SIMULATOR_LINK == true && isModuleAvailable(MODULE_SIMULATOR), 'title' => sprintf($LNG['sys_mess_head'], $targetPlanet['name'], $targetPlanet['galaxy'], $targetPlanet['system'], $targetPlanet['planet'], _date($LNG['php_tdformat'], $this->_fleet['fleet_end_time'], $targetUser['timezone'], $LNG))));
        $template->assign_vars(array('LNG' => $LNG), false);
        $spyReport = $template->fetch('shared.mission.spyReport.tpl');
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_qg'], 0, $LNG['sys_mess_spy_report'], $spyReport, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        $LNG = $this->getLanguage($targetUser['lang']);
        $targetMessage = $LNG['sys_mess_spy_ennemyfleet'] . " " . $senderPlanetName;
        if ($this->_fleet['fleet_start_type'] == 3) {
            $targetMessage .= $LNG['sys_mess_spy_report_moon'] . ' ';
        }
        $text = '<a href="game.php?page=galaxy&amp;galaxy=%1$s&amp;system=%2$s">[%1$s:%2$s:%3$s]</a> %7$s
		%8$s <a href="game.php?page=galaxy&amp;galaxy=%4$s&amp;system=%5$s">[%4$s:%5$s:%6$s]</a> %9$s';
        $targetMessage .= sprintf($text, $this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $LNG['sys_mess_spy_seen_at'], $targetPlanet['name'], $LNG['sys_mess_spy_seen_at2']);
        PlayerUtil::sendMessage($this->_fleet['fleet_target_owner'], 0, $LNG['sys_mess_spy_control'], 0, $LNG['sys_mess_spy_activity'], $targetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        if ($targetChance >= $spyChance) {
            $config = Config::get($this->_fleet['fleet_universe']);
            $whereCol = $this->_fleet['fleet_end_type'] == 3 ? "id_luna" : "id";
            $sql = 'UPDATE %%PLANETS%% SET
			der_metal	= der_metal + :metal,
			der_crystal = der_crystal + :crystal
			WHERE ' . $whereCol . ' = :planetId;';
            $db->update($sql, array(':metal' => $fleetAmount * $pricelist[210]['cost'][901] * $config->Fleet_Cdr / 100, ':crystal' => $fleetAmount * $pricelist[210]['cost'][902] * $config->Fleet_Cdr / 100, ':planetId' => $this->_fleet['fleet_end_id']));
            $this->KillFleet();
        } else {
            $this->setState(FLEET_RETURN);
            $this->SaveFleet();
        }
    }