Sebastian Vega
New Member
Hello guys, i'm having problems, it doesn't load the page and other things, please help u.u
new.php
functions.php
new.php
Code:
<?
/*FILE INFO:
new account creation*/
session_start();
include ("config.php");
include ("functions.php");
$ptitle="Account Registration - $cfg[server_name]";
include ("header.php");
?>
<div id="content">
<div class="top">.:Account Registration:.</div>
<div class="mid">
<?
if (!empty($_POST['account'])){
$_POST['email']=trim($_POST['email']);
$_POST['account']=trim($_POST['account']);
if ((strtolower($_POST['captcha']) == $_SESSION['RandomText']) || !$cfg['use_captha']){
if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$",$_POST['email']) || empty($_POST['email'])){
$account = new Account($_POST['account']);
if (!$account->exist() && $account->isValid()){
if ($cfg['account_number'] !== 2 or $_SESSION['acc'] == $account->number){
if (ereg('^[A-Za-z0-9@#$%^+=]{5,60}$',$_POST['password']) || !$cfg['md5passwords']){
if ($_POST['password'] == $_POST['confirm']){
if ($_POST['password'] != $account->number){
if (!empty($_SESSION['RandomText']) || !$cfg['use_captha']){
$body = "
Thank you for registering at http://$_SERVER[SERVER_NAME]/
Here's your login information:
Account number: $_POST[account]
Password: $_POST[password]
Note that you must use IP Changer to login to 7.6 server.
Yours sincerely,
GM Nicaw";
echo "<!--";
if (!empty($_POST['email'])){echo mailex($_POST['email'], "OTS Login Details", $body);}
echo "-->\n";
$account->make($_POST['password']);
$account->save();
if (is_dir($cfg['dirvip'])){
$file = fopen($cfg['dirvip'].$account->number.'.xml', 'w');
fwrite($file,$cfg['vip_file']);
fclose($file);
}
echo "<p>You have succesfuly created a new account. You can now <a href=\"account.php\">create characters here</a>.<br/>";
$_POST['password']=''; $_POST['confirm']=''; $_POST['account']=''; $_POST['email']='';
}else{ $error = "Your browser might be rejecting cookies";}
}else{ $error = "Choose a safe password, please."; $_POST['password']=''; $_POST['confirm']='';}
}else{ $error = "Passwords do not match"; $_POST['password']=''; $_POST['confirm']='';}
}else{ $error = "Invalid password"; $_POST['password']=''; $_POST['confirm']='';}
}else{ $error = "WTF? You can't choose account number.";}
}else{ $error = "Invalid account number"; $_POST['account']='';}
}else{ $error = "If you don't want to enter your email just leave it empty"; $_POST['email']='';}
}else{ $error = "Image verification failed";}
}
$_SESSION['RandomText'] = '';
if (!empty($_POST['account']) && $cfg['account_number'] != 2){
$_SESSION['acc'] = htmlspecialchars($_POST['account']);
}elseif ($cfg['account_number'] >= 1){
$_SESSION['acc']="-1";
$tmp = new Account($_SESSION['acc']);
while ( !$tmp->isValid() || $tmp->exist() ){
$_SESSION['acc'] = rand(100000,999999);
$tmp = new Account($_SESSION['acc']);
}
}else{$_SESSION['acc']='';}
?>
<div id="account-image"></div>
<form action="<?=htmlspecialchars($_SERVER['PHP_SELF'])?>" method="post">
<label for="account">Account Number</label><br/>
<input name="account" id="account" type="<?
if ($cfg['account_number'] == 2){echo "hidden";} else {echo "text";}
?>" class="textfield" size="30" maxlength="10" value="<?=$_SESSION['acc']?>"/>
functions.php
Code:
<?
/*FILE INFO:
all the funcions we ever need*/
class Account{
var $number;
var $filename;
var $contents;
var $data;
var $characters;
function _makeCharList(){
unset ($this->characters);
foreach($this->data->characters->character as $char){
$this->characters[] = (string)$char['name'];
}
}
function correctPass($pass)
{global $cfg;
if ($cfg['md5passwords']){
$pass=md5($pass);
}
return ($pass === (string)$this->data['pass']);
}
function changePass($new)
{global $cfg;
if ($cfg['md5passwords']){
$new=md5($new);
}
$this->data['pass'] = $new;
$this->contents = $this->data->asXML();
}
function Account($n)
{global $cfg;
$this->filename = $cfg['diraccount'].$n.'.xml';
$this->number = $n;
}
function isValid()
{
return ereg("^[1-9][0-9]{5,7}$",$this->number);
}
function getCharCount()
{
return count($this->characters);
}
function changeName($old,$new)
{
$this->contents = str_ireplace ('name="'.$old.'"','name="'.$new.'"',$this->contents);
return $this->data = simplexml_load_string($this->contents);
}
function addComment($c)
{
$c = trim(htmlspecialchars($c));
if (strlen($c) > 255){return false;}
$this->contents = preg_replace('/<comment>(\r|\n|.)*?<\/comment>/','',$this->contents);
$this->contents = str_ireplace ('<characters>','<comment>'.$c.'</comment><characters>',$this->contents);
return $this->data = simplexml_load_string($this->contents);
}
function deleteChar($n)
{
$this->contents = preg_replace('/<character\\s+name="'.$n.'"\\s\/>/','',$this->contents);
$this->data = simplexml_load_string($this->contents);
$this->_makeCharList();
}
function addChar($n)
{
$this->contents = str_ireplace ("<characters/>",'<characters></characters>',$this->contents);
$this->contents = substr_replace($this->contents, '<character name="'.$n.'" />'."\r\n", stripos($this->contents,"</characters"), 0);
$this->data = simplexml_load_string($this->contents);
$this->_makeCharList();
}
function load()
{
$result = ($this->contents = @file_get_contents($this->filename))
&& ($this->data = @simplexml_load_string($this->contents));
if ($result){
$this->_makeCharList();
}
return $result;
}
function save()
{
file_put_contents($this->filename,$this->contents);
}
function exist()
{
return file_exists($this->filename);
}
function make($pass)
{global $cfg;
if ($cfg['md5passwords']){
$pass=md5($pass);
}
$this->contents = '<?xml version="1.0"?>
<account pass="'.$pass.'" type="1" premDays="0" ip="'.$_SERVER['REMOTE_ADDR'].'">
<characters>
</characters>
</account>';
$this->data = @simplexml_load_string($this->contents);
}
}//end class Account
################################################################################
class Player{
var $data;
var $contents;
var $filename;
var $name;
function _skills($vocation)
{global $cfg;
$str = "";
for ($id = 0; $id <= 6; $id++)
$str .= ('<skill skillid="' . $id . '" level="' . $cfg['skill'][$vocation][$id] . '" tries="10"/>' . "\n");
return $str;
}
function _equip($vocation)
{global $cfg;
$str = "";
for ($id = 1; $id <= 10; $id++)
{
if ($cfg['equip'][$vocation][$id-1] != 0)
{
$str .= ('<slot slotid="' . $id . '"><item id="' . $cfg['equip'][$vocation][$id-1] . '"');
if ($id == 3) // backpack
$str .= ('><inside>' . $cfg['bp'][$vocation] . '</inside></item>');
else
$str .= ('/>');
$str .= ('</slot>' . "\n");
}
}
return $str;
}
function Player($n)
{global $cfg;
$this->filename = $cfg['dirplayer'].strtolower($n).'.xml';
$this->name = $n;
}
function load()
{
return ($this->contents = @file_get_contents($this->filename))
&& ($this->data = @simplexml_load_string($this->contents));
}
function save()
{
file_put_contents($this->filename,$this->data->asXML());
}
function exist()
{
return file_exists(strtolower($this->filename));
}
function teleportToTemple()
{
$this->data->spawn['x'] = (int)$this->data->temple['x'];
$this->data->spawn['y'] = (int)$this->data->temple['y'];
$this->data->spawn['z'] = (int)$this->data->temple['z'];
$this->contents = $this->data->asXML();
}
function isValidName()
{global $cfg;
$name = $this->name;
return !eregi("^gm",$name)
&& !eregi("^god",$name)
&& !eregi("admin",$name)
&& preg_match("/^[A-Z][a-z]{1,20}([ \-][A-Za-z][a-z]{1,15}){0,3}$/",$name)
&& strlen($name) <= 25 && strlen($name) >= 4
&& !file_exists($cfg['dirmonster'].$name.'.xml');
}
function getGuild(){
require ("config.php");
if (!file_exists($cfg['dirdata'].'guilds.xml')){return false;}
$guildsXML = simplexml_load_file($cfg['dirdata'].'guilds.xml');
//loop through each guild searching for player
foreach ($guildsXML -> guild as $guild){
foreach ($guild -> member as $member){
if (strtolower($member['name']) == strtolower($this->name)){
$result['name'] = (string)$guild['name'];
$result['nick'] = (string)$member['nick'];
$result['rank'] = (string)$member['rank'];
$result['status'] = (int)$member['status'];
}
}
}
if (isset($result)){return $result;}
else {return false;}
}
function deleteChar(){
global $cfg;
if (!is_dir($cfg['dirdeleted'])){mkdir($cfg['dirdeleted']);}
@copy($this->filename,$cfg['dirdeleted'].$this->name.'.xml');
@unlink($this->filename);
}
function getCash(){
$gold='2148';
$plat='2152';
$crys='2160';
$pattern='/<item id="([0-9]{1,5})"\s[^\r\n<>]*?count="([0-9]{1,3})"/';
preg_match_all($pattern,$this->contents,$out,PREG_PATTERN_ORDER);
$i=0;
$money=0;
while (isset($out[1][$i])){
if ($out[1][$i] == $gold){$money+=$out[2][$i];}
elseif ($out[1][$i] == $plat){$money+=$out[2][$i]*100;}
elseif ($out[1][$i] == $crys){$money+=$out[2][$i]*10000;}
$i++;
}
return $money;
}
function changeName($p){
global $cfg;
if (file_exists($cfg['dirplayer'].$p.'.xml')){return false;}
$this->data['name'] = $p;
$this->save();
if (@copy($this->filename,$cfg['dirplayer'].$p.'.xml')){
@unlink($this->filename);
}
$this->filename = $cfg['dirplayer'].$n.'.xml';
$this->name = $n;
return $this->load();
}
function make($vocation,$account,$sex,$city)
{global $cfg;
$this->contents ='<?xml version="1.0"?>
<player name="' . $this->name . '" account="' . $account . '" sex="' . $sex . '" lookdir="1" exp="' . $cfg['exp'] . '" voc="' . $vocation . '" level="' . $cfg['lvl'] . '" access="0" cap="' . $cfg['cap'][$vocation] . '" maglevel="' . $cfg['mlvl'][$vocation] . '" lastlogin="'.time().'" banned="0" premticks="0" promoted="0" >
<spawn x="' . $cfg['temple'][$city][x] . '" y="' . $cfg['temple'][$city][y] . '" z="' . $cfg['temple'][$city][z] . '"/>
<temple x="' . $cfg['temple'][$city][x] . '" y="' . $cfg['temple'][$city][y] . '" z="' . $cfg['temple'][$city][z] . '"/>
<health now="' . $cfg['health'][$vocation] . '" max="' . $cfg['health'][$vocation] . '" food="0"/>
<mana now="' . $cfg['mana'][$vocation] . '" max="' . $cfg['mana'][$vocation] . '" spent="0"/>
<look type="' . $cfg['look'][$vocation][$sex] . '" head="20" body="30" legs="40" feet="50"/>
<skills>' . "\n" . $this->_skills($vocation) . '</skills>
<inventory>' . $this->_equip($vocation) . '</inventory>'.$cfg['depots'].'<storage/>
</player>';
$this->data = simplexml_load_string($this->contents);
return true;
}
}//end class Player
################################################################################
function getinfo($host='localhost',$port=7171){
// connects to server
$socket = @fsockopen($host, $port, $errorCode, $errorString, 0.5);
// if connected then checking statistics
if($socket)
{
// sets 5 second timeout for reading and writing
stream_set_timeout($socket, 5);
// sends packet with request
// 06 - length of packet, 255, 255 is the comamnd identifier, 'info' is a request
fwrite($socket, chr(6).chr(0).chr(255).chr(255).'info');
// reads respond
while (!feof($socket)){
$data .= fread($socket, 128);
}
// closing connection to current server
fclose($socket);
}
return $data;
}
function indexPlayers(){
global $cfg;
$file_handle = fopen($cfg['dirplayer']."players.xml", "w");
fwrite ($file_handle, "<players>\r\n");
$uid = 0;
$dir_handle = opendir($cfg['dirplayer']);
while ( $file = readdir($dir_handle) ){
if (eregi('\.xml$',$file) ){
$uid++;
$pieces = explode (".",$file);
fwrite ($file_handle, '<player guid="'.$uid.'" name="'.htmlspecialchars($pieces[0]).'"/>'."\r\n");
}
}
fwrite ($file_handle, "</players>");
fclose($file_handle);
}
function mailex($recipient,$subject,$content){
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.hotpop.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "xxxxxxx"; // SMTP password
$mail->From = "[email protected]"; //do NOT fake header. must be same as host
$mail->FromName = "MailMan";
$mail->AddAddress($recipient);
$mail->AddReplyTo("[email protected]", "Support and Help"); //your public email goes here
$mail->Subject = $subject;
$mail->Body = $content;
if(!$mail->Send())
{
return $mail->ErrorInfo;
} else { return "1";}
}
?>
Last edited: