public function create_do() { global $Template, $Database, $Character; LoggedInOnlyFeature(); if (empty($_POST['charactername']) || empty($_POST['class'])) { MessageHandler::HandleUserError("It appears that you didn't fill all fields"); $this->Create(); return; } if (strpos($_POST['charactername'], ' ') !== FALSE) { MessageHandler::HandleUserError("Sorry, but you can not include spaces in your character's name."); $this->Create(); return; } if (strlen($_POST['charactername']) > 20) { MessageHandler::HandleUserError("Sorry, but the maximum length of the character's name can not be over twenty characters."); $this->Create(); return; } if (intval($_POST['class']) == 0) { MessageHandler::HandleUserError("Sorry, but there was a problem with the form. Care to try again?"); $this->Create(); return; } $CharacterName = mysql_real_escape_string($_POST['charactername']); $Class = intval($_POST['class']); if (mysql_num_rows($Database->Query("SELECT Name FROM characters WHERE Name = '{$CharacterName}'")) > 0) { MessageHandler::HandleUserError("It appears that the name of the character, \"{$CharacterName}\", is used by someone else right now. Please, try another one."); $this->Create(); return; } //Everything seems okay. Execute queries. $OwnerID = $_SESSION['USERINFO']['id']; $Skills = addslashes(json_encode(array())); $Inventory = addslashes(json_encode(array('Gold' => 10))); $Equipment = addslashes(json_encode(array())); $Stats = addslashes(json_encode(array('Life' => 100, 'Mana' => 100, 'MaxLife' => 100, 'MaxMana' => 100, 'Defense' => 10, 'Strength' => 5, 'Agility' => 5, 'Intelligence' => 5, 'Left_Stats' => 10))); $Character->create($CharacterName, $OwnerID, $Class, $Skills, $Inventory, $Equipment, $Stats); MessageHandler::HandleAnnouncement("Congratulations. Your character, {$CharacterName}, has been created."); $this->Render(); }
define("DB_PASSWORD", ""); define("DB_NAME", "BFERev"); //start the session - no headers to be sent before this session_start(); $BaseURL = substr(BaseURL, 0, -1); //include libraries located at ./classes include "classes/MessageHandler.php"; include "classes/Database.php"; include "classes/URL.php"; include "classes/Template.php"; include "classes/Libraries.php"; include "functions.php"; //Set error handler. Personal error handler handles errors the nice way! :D set_error_handler(array("MessageHandler", "HandleError")); //First announcement. MessageHandler::HandleAnnouncement("Ahoy! We're on alpha! Please, report any bugs you may find."); //Initialize some classes, analyze the URL and call classes and their methods to render // i.e. -> /Bloomie/index.php/Blog/12/LeNotBlogFunny includes /pages/Blog.php, initializes class Blog and calls method Render with parameters [12,'LeNotBlogFunny'] $Database = new Database(HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $URL = new URL(); $Template = new Template(); $Template->set_filenames(array('index' => 'templates/index.html', 'header' => 'templates/head.html', 'footer' => 'templates/footer.html', 'basepage' => 'templates/basepage.html', 'characterpage' => 'templates/basepage.html', 'characterform' => 'templates/charcreationform.html', 'login' => 'templates/login.html', 'inventory' => 'templates/inventory.html')); $Template->assign_var("ProjectFolder", $BaseURL); //Call the class requested by the user. if (!file_exists("pages/" . addslashes($URL->Class) . ".php")) { trigger_error("The page you requested does not exist."); } else { include "pages/" . addslashes($URL->Class) . ".php"; $ClassName = $URL->Class; ${$ClassName} = new $ClassName(); call_user_func_array(array(${$ClassName}, '' . $URL->Function), $URL->Parameters);