public static function getInput($dat, $key, $type, $default = false) { global ${$dat}; $dat = ${$dat}; if (!isset($dat[$key])) { return $default; } else { // Check if the value has the right type if (Neuron_Core_Tools::checkInput($dat[$key], $type)) { return $dat[$key]; } else { return $default; } } }
public function processInput() { $_SESSION['clan_overview_lastrefresh'] = null; $login = Neuron_Core_Login::__getInstance(); $data = $this->getRequestData(); $input = $this->getInputData(); if (isset($data['id']) && $data['id'] > 0) { $clan = new Dolumar_Players_Clan($data['id']); if ($clan) { if (!isset($input['action'])) { $input['action'] = 'overview'; } switch ($input['action']) { case 'join': $this->updateContent($this->getJoinClan($clan)); break; case 'government': $this->updateContent($this->getGovernment($clan)); break; case 'leave': $this->updateContent($this->getLeaveClan($clan)); break; case 'overview': default: $this->updateContent($this->getOverview($clan)); break; } } } elseif ($login->isLogin()) { $profile = Neuron_GameServer::getPlayer(); $clans = $profile->getClans(); if (count($clans) == 0 && isset($input['clanname'])) { if (Neuron_Core_Tools::checkInput($input['clanname'], 'unitname')) { if ($this->makeClan($input['clanname'])) { $this->updateContent(); } else { $this->updateContent($this->getNoClan($profile, $this->getError())); } } else { $this->updateContent($this->getNoClan($profile, 'err_clanname')); } } } }
private function getAddSquad() { $input = $this->getInputData(); if (isset($input['squadName']) && Neuron_Core_Tools::checkInput($input['squadName'], 'unitname') && isset($input['squadUnit'])) { // Check if unit type exists $unit = Dolumar_Units_Unit::getUnitFromId($input['squadUnit'], $this->village->getRace(), $this->village); if ($unit) { // Add the squad $objSquad = $this->village->addSquad($input['squadName'], $input['squadUnit']); if ($objSquad) { return $this->getAddUnits($objSquad); } else { return $this->getOverview(); } } else { $this->alert('Invalid unit type: ' . $input['squadUnit']); } } else { $text = Neuron_Core_Text::__getInstance(); $text->setFile('squads'); $text->setSection('addSquad'); $page = new Neuron_Core_Template(); if (isset($input['squadName'])) { $page->set('warning', $text->get('squadNameSyntax')); } $page->set('title', $text->get('title')); $page->set('name', $text->get('name')); $page->set('submit', $text->get('submit')); $page->set('toReturn', $text->getClickTo($text->get('toReturn'))); // Load all units $units = $this->village->getMyUnits(); foreach ($units as $unit) { if ($unit->getSquadlessAmount() > 0) { $page->addListValue('units', array('name' => $unit->getName(), 'id' => $unit->getUnitId())); } } return $page->parse('squads/add.tpl'); } }
public function setName($name) { $this->loadData(); if (Neuron_Core_Tools::checkInput($name, 'village')) { if ($this->isFound()) { // Check if this name exists $db = Neuron_Core_Database::__getInstance(); $found = $db->select('villages', array('vid'), "vname = '{$db->escape($name)}' AND vid != {$this->getId()}"); if (count($found) == 0) { $db->update('villages', array('vname' => $name), "vid = '" . $this->id . "'"); $this->data['vname'] = $name; return true; } else { $this->error = 'village_name_duplicate'; return false; } } else { $this->error = 'village_not_found'; return false; } } else { $this->error = 'invalid_village_syntax'; return false; } }
public function changeNickname($nickname) { $db = Neuron_Core_Database::__getInstance(); $this->loadData(); if (!empty($this->data['nickname'])) { if (Neuron_Core_Tools::checkInput($nickname, 'username')) { $data = Neuron_GameServer_Mappers_PlayerMapper::getFromNickname($nickname); if (!isset($data)) { Neuron_GameServer_Mappers_PlayerMapper::setNickname($this, $nickname); if ($chk == 1) { $this->data['nickname'] = $nickname; return true; } else { $this->error = 'update_failed'; return false; } } else { $this->error = 'user_found'; return false; } } else { $this->error = 'error_username'; return false; } } else { $this->error = 'nickname_not_set'; } }
private function processRegistration($username, $email, $password, $password2) { $db = Neuron_Core_Database::__getInstance(); $login = Neuron_Core_Login::__getInstance(); $text = Neuron_Core_Text::__getInstance(); $text->setFile('account'); $text->setSection('register'); // Check input if (!Neuron_Core_Tools::checkInput($username, 'username')) { $this->updateContent($this->showRegisterForm('usernameFormat')); } elseif (!Neuron_Core_Tools::checkInput($password, 'password')) { $this->updateContent($this->showRegisterForm('passwordFormat')); } elseif (!Neuron_Core_Tools::checkInput($email, 'email')) { $this->updateContent($this->showRegisterForm('emailFormat')); } elseif ($password != $password2) { $this->updateContent($this->showRegisterForm('passwordMismatch')); } else { // Next step: checking username and stuff $userCheck = $db->select('n_players', array('plid'), "nickname = '{$username}' AND isRemoved = 0"); $mailCheck = $db->select('n_players', array('plid'), "email = '{$email}' AND isRemoved = 0"); if (count($userCheck) > 0) { $this->updateContent($this->showRegisterForm('userFound')); } elseif (count($mailCheck) > 0) { $this->updateContent($this->showRegisterForm('emailFound')); } else { /* Check for referrer. */ $referrer = intval(Neuron_Core_Tools::getInput('_COOKIE', 'preferrer', 'int')); $user = Neuron_GameServer::getPlayer($referrer); $ref_id = $user ? $user->getId() : null; // Create the account $id = $login->registerAccount($username, $email, $password, $ref_id); $user = Neuron_GameServer::getPlayer($id); /* if (!$isInfinite) { // Withdraw 1 invitation $db->update ( 'invitation_codes', array ( 'invLeft' => '--' ), "invCode = '$invitation'" ); } else { // Add 1 invitation $db->update ( 'invitation_codes', array ( 'invLeft' => '++' ), "invCode = '$invitation'" ); } */ // Show "finished" page $page = new Neuron_Core_Template(); $page->set('done', $text->get('done')); $page->set('login', $text->get('login')); $page->set('tracker_url', htmlentities($user->getTrackerUrl('registration'))); $this->updateContent($page->parse('register/register_done.tpl')); } } }