public static function createPlayer($universe, $userName, $userPassword, $userMail, $userLanguage = NULL, $galaxy = NULL, $system = NULL, $position = NULL, $name = NULL, $authlevel = 0, $userIpAddress = NULL) { $config = Config::get($universe); if (isset($universe, $galaxy, $system, $position)) { if (self::checkPosition($universe, $galaxy, $system, $position) === false) { throw new Exception(sprintf("Try to create a planet at position: %s:%s:%s!", $galaxy, $system, $position)); } if (self::isPositionFree($universe, $galaxy, $system, $position) === false) { throw new Exception(sprintf("Position is not empty: %s:%s:%s!", $galaxy, $system, $position)); } } else { $galaxy = $config->LastSettedGalaxyPos; $system = $config->LastSettedSystemPos; $planet = $config->LastSettedPlanetPos; if ($galaxy > $config->max_galaxy) { $galaxy = 1; } if ($system > $config->max_system) { $system = 1; } do { $position = mt_rand(round($config->max_planets * 0.2), round($config->max_planets * 0.8)); if ($planet < 3) { $planet += 1; } else { if ($system > $config->max_system) { $system = 1; if ($galaxy > $config->max_galaxy) { $galaxy = 1; } else { $galaxy += 1; } } else { $system += 1; } } } while (self::isPositionFree($universe, $galaxy, $system, $position) === false); // Update last coordinates to config table $config->LastSettedGalaxyPos = $galaxy; $config->LastSettedSystemPos = $system; $config->LastSettedPlanetPos = $planet; } $params = array(':username' => $userName, ':email' => $userMail, ':email2' => $userMail, ':authlevel' => $authlevel, ':universe' => $universe, ':language' => $userLanguage, ':registerAddress' => !empty($userIpAddress) ? $userIpAddress : Session::getClientIp(), ':onlinetime' => TIMESTAMP, ':registerTimestamp' => TIMESTAMP, ':password' => $userPassword, ':dpath' => DEFAULT_THEME, ':timezone' => $config->timezone, ':nameLastChanged' => 0, ':darkmatter_start' => $config->darkmatter_start); $sql = 'INSERT INTO %%USERS%% SET username = :username, email = :email, email_2 = :email2, authlevel = :authlevel, universe = :universe, lang = :language, ip_at_reg = :registerAddress, onlinetime = :onlinetime, register_time = :registerTimestamp, password = :password, dpath = :dpath, timezone = :timezone, uctime = :nameLastChanged, darkmatter = :darkmatter_start;'; $db = Database::get(); $db->insert($sql, $params); $userId = $db->lastInsertId(); $planetId = self::createPlanet($galaxy, $system, $position, $universe, $userId, $name, true, $authlevel); $currentUserAmount = $config->users_amount + 1; $config->users_amount = $currentUserAmount; $sql = "UPDATE %%USERS%% SET\n\t\tgalaxy = :galaxy,\n\t\tsystem = :system,\n\t\tplanet = :position,\n\t\tid_planet = :planetId\n\t\tWHERE id = :userId;"; $db->update($sql, array(':galaxy' => $galaxy, ':system' => $system, ':position' => $position, ':planetId' => $planetId, ':userId' => $userId)); $sql = "SELECT MAX(total_rank) as rank FROM %%STATPOINTS%% WHERE universe = :universe AND stat_type = :type;"; $rank = $db->selectSingle($sql, array(':universe' => $universe, ':type' => 1), 'rank'); $sql = "INSERT INTO %%STATPOINTS%% SET\n\t\t\t\tid_owner\t= :userId,\n\t\t\t\tuniverse\t= :universe,\n\t\t\t\tstat_type\t= :type,\n\t\t\t\ttech_rank\t= :rank,\n\t\t\t\tbuild_rank\t= :rank,\n\t\t\t\tdefs_rank\t= :rank,\n\t\t\t\tfleet_rank\t= :rank,\n\t\t\t\ttotal_rank\t= :rank;"; $db->insert($sql, array(':universe' => $universe, ':userId' => $userId, ':type' => 1, ':rank' => $rank + 1)); $config->save(); return array($userId, $planetId); }
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 send() { global $LNG; $username = HTTP::_GP('username', '', UTF8_SUPPORT); $mail = HTTP::_GP('mail', '', true); $errorMessages = array(); if (empty($username)) { $errorMessages[] = $LNG['passwordUsernameEmpty']; } if (empty($mail)) { $errorMessages[] = $LNG['passwordErrorMailEmpty']; } $config = Config::get(); 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) { $errorMessages[] = $LNG['registerErrorCaptcha']; } } if (!empty($errorMessages)) { $message = implode("<br>\r\n", $errorMessages); $this->printMessage($message, array(array('label' => $LNG['passwordBack'], 'url' => 'index.php?page=lostPassword'))); } $db = Database::get(); $sql = "SELECT id FROM %%USERS%% WHERE universe = :universe AND username = :username AND email_2 = :mail;"; $userID = $db->selectSingle($sql, array(':universe' => Universe::current(), ':username' => $username, ':mail' => $mail), 'id'); if (empty($userID)) { $this->printMessage($LNG['passwordErrorUnknown'], array(array('label' => $LNG['passwordBack'], 'url' => 'index.php?page=lostPassword'))); } $sql = "SELECT COUNT(*) as state FROM %%LOSTPASSWORD%% WHERE userID = :userID AND time > :time AND hasChanged = 0;"; $hasChanged = $db->selectSingle($sql, array(':userID' => $userID, ':time' => TIMESTAMP - 86400), 'state'); if (!empty($hasChanged)) { $this->printMessage($LNG['passwordErrorOnePerDay'], array(array('label' => $LNG['passwordBack'], 'url' => 'index.php?page=lostPassword'))); } $validationKey = md5(uniqid()); $MailRAW = $LNG->getTemplate('email_lost_password_validation'); $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{VALIDURL}'), array($username, $config->game_name . ' - ' . $config->uni_name, HTTP_PATH . 'index.php?page=lostPassword&mode=newPassword&u=' . $userID . '&k=' . $validationKey), $MailRAW); require 'includes/classes/Mail.class.php'; $subject = sprintf($LNG['passwordValidMailTitle'], $config->game_name); Mail::send($mail, $username, $subject, $MailContent); $sql = "INSERT INTO %%LOSTPASSWORD%% SET userID = :userID, `key` = :validationKey, `time` = :timestamp, fromIP = :remoteAddr;"; $db->insert($sql, array(':userID' => $userID, ':timestamp' => TIMESTAMP, ':validationKey' => $validationKey, ':remoteAddr' => Session::getClientIp())); $this->printMessage($LNG['passwordValidMailSend'], array(array('label' => $LNG['passwordNext'], 'url' => 'index.php'))); }