What's new

Account Maker Par? b??d?w.

Status
Not open for further replies.

Ematerion

Advanced User
Joined
Feb 18, 2013
Messages
176
Reaction score
5
Witam, mo?e od razu przejd? do rzeczy.

1. Status:
Sytuacja dosy? dziwna i najlepiej je?eli poka?? j? za pomoc? ss'?w. a tu par? minut p??niej . Dodam, ?e po od?wie?eniu strony zn?w wszystko wraca do normy, jednak?e zn?w niestety tylko na par? minut.

Status.php:​
PHP:
<?php 
include ('config.inc.php');
function getinfo($host='localhost',$port=7171){
		// connects to server
        $socket = @fsockopen($host, $port, $errorCode, $errorString, 1);
		$data = '';
        // if connected then checking statistics
        if($socket)
        {
            // sets 1 second timeout for reading and writing
            stream_set_timeout($socket, 1);

            // 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;
}
if ($cfg['status_update_interval'] < 60) $cfg['status_update_interval'] = 60;
$modtime = filemtime('status.xml');
if (time() - $modtime > $cfg['status_update_interval'] || $modtime > time()){
	$info = getinfo($cfg['server_ip'], $cfg['server_port']);
	if (!empty($info)) file_put_contents('status.xml',$info);
}else $info = file_get_contents('status.xml');
if (!empty($info)) {
$infoXML = simplexml_load_string($info);

	$up = (int)$infoXML->serverinfo['uptime'];
	$online = (int)$infoXML->players['online'];
	$max = (int)$infoXML->players['max'];

	$h = floor($up/3600);
	$up = $up - $h*3600;
	$m = floor($up/60);
	$up = $up - $m*60;
	if ($h < 10) {$h = "0".$h;}
	if ($m < 10) {$m = "0".$m;}
	echo "<span class=\"online\">Online</span><br/>\n";
	echo "<span class=\"players\">Players: <b>$online/$max</b></span><br/>\n";
	//echo "<span class=\"monsters\">Monsters: <b>".$infoXML->monsters['total']."</b></span><br/>\n";
	echo "<span class=\"uptime\">Uptime: <b>$h:$m</b></span><br/>\n";
} else {
	echo "<span class=\"offline\">Offline</span>\n";
}
?>

Status.xml:​
[XML]<?xml version="1.0"?>
<tsqp version="1.0"><serverinfo uptime="34" ip="127.0.0.1" servername="Dragon Ball Midnight Online" port="7171" location="Poland" url="" server="DevLand" version="" client="8.0"/><owner name="Ematerion" email=""/><players online="0" max="120" peak="0"/><monsters total="5153"/><map name="" author="" width="" height=""/><motd>Welcome to Dragon Ball Midnight Online!</motd></tsqp>
[/XML]

Header.inc​
PHP:
<div id="container">
<div id="panel2"><div class="top">Status</div><div class="mid">
<div id="server_state">
<span class="offline"><img src="skins/essense/offline.png" /></span>
<div class="mid">
<script type="text/javascript">
//<![CDATA[
    new Ajax.PeriodicalUpdater('server_state', 'status.php', {
      method: 'get', frequency: 60, decay: 1
    });
//]]>
</script>
</div>

2. Zak?adanie konta:
Podczas zak?adania konta oraz postaci wyskakuj? nast?puj?ce b??dy:

Code:
Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\iobox.php on line 105

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\iobox.php on line 105

Deprecated: Function ereg() is deprecated in C:\xampplite\htdocs\modules\character_create.php on line 32

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Deprecated: Function eregi() is deprecated in C:\xampplite\htdocs\class\globals.php on line 25

Warning: current() expects parameter 1 to be array, null given in C:\xampplite\htdocs\class\player.php on line 196


Iobox.php​

PHP:
<?php
/*
     Copyright (C) 2007 - 2008  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

class IOBox
{
private $elements, $buttons, $name, $label;
public $target, $icon;

function __construct($name){
	$this->name = $name;
	$buttons = 0;
}
public function addMsg($msg){
	$this->elements[]= '<p style="margin: 5px">'.$msg.'</p>';
}
public function addSelect($name,$options){
	$code = '<select id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'">';
	foreach (array_keys($options) as $option){
		$code.= '<option value="'.$option.'">'.$options[$option].'</option>';
	}
	$code.= '</select> <label for="'.$this->name.'__'.$name.'">- '.ucfirst($name).'</label>';
	$this->elements[] = $code;
}
public function addCaptcha(){
	global $cfg;
	if(!$cfg['use_captcha']) return;
	if (isset($_POST['ajax']))
		$img = 'doimg.php?'.time();
	else
		$img = '../doimg.php?'.time();
	$_SESSION['RandomText'] = substr(str_shuffle(strtolower('qwertyuipasdfhjklzxcvnm12345789')), 0, 6);
	$this->elements[]= '<img width="250px" height="40px" src="'.$img.'" alt="Verification Image"/>';
	$this->elements[]= '<input id="captcha" name="'.$this->name.'__captcha" type="text" maxlength="10" style="text-transform: uppercase"/> <label for="captcha">- Verification</label>';
}
public function addInput($name, $type = 'text', $value = '', $length = 100, $readonly = false){
	if ($readonly) $readonly = ' readonly="readonly"';
	else $readonly = '';
	$this->elements[]= '<input id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'" type="'.$type.'" maxlength="'.$length.'" value="'.$value.'"'.$readonly.'/> <label for="'.$this->name.'__'.$name.'">- '.ucfirst($name).'</label>';
}
public function addCheckBox($name, $check = false){
	if ($check) $check = ' checked="checked"';
	else $check = '';
	$this->elements[]= '<input type="checkbox" id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'"'.$check.'> <label for="'.$this->name.'__'.$name.'">'.ucfirst($name).'</label>';
}
public function addTextbox($name,$value = '',$cols = 40,$rows = 10){
	$this->elements[]= '<textarea name="'.$this->name.'__'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>';
}
public function addSubmit($text){
	$this->buttons[]= '<input style="width: 100px; height: 25px;" type="submit" name="'.$this->name.'__'.$this->name.'" value="'.$text.'"/>';
}
public function addReload($text){
	$this->buttons[]= '<input style="width: 100px; height: 25px;" onclick="ajax(\'form\',\''.htmlspecialchars($_SERVER['PHP_SELF']).'\',\'\',true)" type="button" name="'.$this->name.'__'.$this->name.'" value="'.$text.'"/>';
}
public function addRefresh($text){
	$this->buttons[]= '<input onclick="location.reload(false)" type="button" style="width: 100px; height: 25px;" value="'.$text.'"/>';
}
public function addClose($text){
	$this->buttons[]= '<input style="width: 100px; height: 25px;" onclick="document.getElementById(\'iobox\').style[\'visibility\'] = \'hidden\'" type="button" value="'.$text.'"/>';
}
public function addCode($code){
	$this->elements[]= $code;
}
public function addLabel($code){
	$this->label = '<legend>'.$code.'</legend>';
}
public function getCode(){
	if (isset($_POST['ajax']))
		$code = '<table cellspacing="10px" onmouseup="Cookies.create(\'iobox_x\',document.getElementById(\'iobox\').style.left,1);Cookies.create(\'iobox_y\',document.getElementById(\'iobox\').style.top,1);" style="visibility:hidden" id="iobox" class="draggable"><tr><td><fieldset>'.$this->label.'<form id="'.$this->name.'" action="javascript:ajax(\'form\',\''.htmlspecialchars($this->target).'\',getParams(document.getElementById(\''.$this->name.'\')),true)" method="post">';
	else
		$code = '<div id="iobox" class="iobox"><fieldset>'.$this->label.'<form id="'.$this->name.'" action="'.htmlspecialchars($this->target).'" method="post">';
	foreach ($this->elements as $element)
		$code.= $element."<br/><div style=\"margin-top: 5px;\"></div>\r\n";
	$code.= '<hr style="margin: 10px 2px 2px 2px; padding: 0;"/> | ';
	foreach ($this->buttons as $button)
		$code.= $button." | \r\n";
	$code.= '</form></fieldset></td></tr></table>';
	return $code;
}
public function show(){
	echo $this->getCode();
}
}

class Form
{
public $attrs;
public function __construct($name){
		foreach( array_keys($_POST) as $key){
			if (eregi('^'.$name.'__',$key)){
				$p = explode('__', $key);
				$this->attrs[$p[1]] = trim($_POST[$key]);
			}
		}
}
public function getBool($attr){
	return $this->attrs[$attr] === 'on';
}
public function exists(){
	if (isset($this->attrs)) return true;
	else return false;
}
public function validated(){
	global $cfg;
	if (!$cfg['use_captcha']) return true;
	if (strtolower($this->attrs['captcha']) === $_SESSION['RandomText'] && !empty($_SESSION['RandomText'])){
		$_SESSION['RandomText'] = null;
		return true;
	}else return false;
}
}


Character_create.php​

PHP:
<?php
/*
    Copyright (C) 2007 - 2008  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include ("../include.inc.php");

//retrieve post data
$form = new Form('character');
//check if any data was submited
if ($form->exists()){
	//load account if loged in
	$account = new Account();
	($account->load($_SESSION['account'])) or die('You need to login first. '.$account->getError());
	//create new player object
	$form->attrs['name'] = ucfirst($form->attrs['name']);
	$newplayer = new Player();
	//check for correct parameters
	if ($cfg['temple'][$form->attrs['residence']]['enabled'] && $cfg['vocations'][(int)$form->attrs['vocation']]['enabled'] && ereg("^[01]$",$form->attrs['sex'])){
		//check character number
		if (count($account->players) < $cfg['maxchars']){
			//check for valid name
			if (AAC::ValidPlayerName($form->attrs['name'])){
				$newplayer->setAttr('name',(string)$form->attrs['name']);
				//player name must not exist
				if (!$newplayer->exists()){
					//set attributes for new player
					$newplayer->setAttr('vocation',(int)$form->attrs['vocation']);
					$newplayer->setAttr('account',(int)$_SESSION['account']);
					$newplayer->setAttr('sex',(int)$form->attrs['sex']);
					$newplayer->setAttr('city',(int)$form->attrs['residence']);
					//create character and add it to account
					if ($newplayer->create()){
						$account->logAction('Created character: '.$form->attrs['name']);
						//create new message
						$msg = new IOBox('message');
						$msg->addMsg('Your character was successfuly created.');
						$msg->addRefresh('Finish');
						$msg->show();
					}else{$error = 'Error. '.$newplayer->getError();}
				}else{$error = "This name is already taken.";}
			}else{$error = "<b>Not a valid name:</b><br/><ul><li>First letter capital</li><li>At least 4 characters, at most 25</li><li>No capital letters in midlle of word</li><li>Letters A-Z, -' and spaces</li><li>Monster names not allowed</li></ul>";}
		}else{$error = "You can't have more than $cfg[maxchars] characters on your account";}
	}else{$error = "Invalid parameters.";}
	if (!empty($error)){
		//create new message
		$msg = new IOBox('message');
		$msg->addMsg($error);
		$msg->addReload('<< Back');
		$msg->addClose('OK');
		$msg->show();
	}
}else{
	//make a list of valid vocations
	while ($vocation = current($cfg['vocations'])) {
		if (isset($vocation['enabled']) && $vocation['enabled'])
			$vocations[key($cfg['vocations'])] = $vocation['name'];
		next($cfg['vocations']);
	}
	//make a list of valid spawn places
	while ($spawn = current($cfg['temple'])) {
		if (isset($spawn['enabled']) && $spawn['enabled']){
			$spawns[key($cfg['temple'])] = $spawn['name'];
		}
	    next($cfg['temple']);
	}
	//create new form
	$form = new IOBox('character');
	$form->target = $_SERVER['PHP_SELF'];
	$form->addLabel('Create Character');
	$form->addInput('name');
	$form->addSelect('sex',array(1 => 'Male', 0 => 'Female'));
	$form->addSelect('vocation',$vocations);
	$form->addSelect('residence',$spawns);
	$form->addClose('Cancel');
	$form->addSubmit('Next >>');
	$form->show();
}
?>

Globals.php​

PHP:
<?php
/*
     Copyright (C) 2007 - 2008  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

class AAC
{
	public function ValidPlayerName($name)
	{global $cfg;
		foreach ($cfg['invalid_names'] as $baned_name)
			if (eregi($baned_name,$name))
				return false;
		return 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['dirdata'].'monster/'.$name.'.xml')
		&& !file_exists($cfg['dirdata'].'npc/'.$name.'.xml');
	}
	
	public function ValidPassword($pass)
	{
		return strlen($pass) > 5;
	}
	
	public function ValidAccountNumber($n)
	{
		return is_numeric($n) && $n > 100000 && $n < 100000000;
	}
	
	public function ValidEmail($email)
	{
		return eregi('^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$',$email);
	}
	
	public function ValidGuildName($name)
	{
		return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
	}
	
	public function ValidGuildRank($name)
	{
		return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
	}
	
	public function ValidGuildNick($name)
	{
		return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
	}
	
	public function getExperienceByLevel($lvl)
	{
		return floor(50*($lvl-1)*($lvl*$lvl-5*$lvl+12)/3);
	}
}

function exception_handler($exception) {
	echo '<pre style="position: absolute; top: 0px; left: 0px; background-color: white; color: black; border: 3px solid red;"><b>'.$exception->getMessage(). '<br/>'.basename($exception->getFile()).' on line: '.$exception->getLine().'</b><br/>Script was terminated because something unexpected happened. You can report this, if you think it\'s a bug.';
}

function strToDate($str){
  $pieces = explode('-',$str);
  return mktime(0,0,0,(int)$pieces[1],(int)$pieces[2],(int)$pieces[0]);
}

function getVocLvl($voc){
	global $cfg;
	return floor($cfg['vocations'][$voc]['level']);
}

function getVocExp($voc){
	global $cfg;
	$x = $cfg['vocations'][$voc]['level'];
	return round(50*($x-1)*(pow($x,2)-5*$x+12)/3);
}

function getStyle($seed)
{
	if ($seed % 2 == 0)
		return 'class="color1"';
	else
		return 'class="color2"';
}

function percent_bar($part, $total)
{
	if ($total <= 0) return 'unknown';
	$percent = round($part/$total*100);
	if ($percent >= 10)
		$percent_text = $percent.'%';
	return '<div class="percent_bar" style="width:'.($percent*2).'px">'.$percent_text.'</div>';
}

function deeper_array_search($needle, $haystack, $attribute)
{
	while ($v = current($haystack)){
		if ($v[$attribute] == $needle)
			return key($haystack);
		next($haystack);
	}
	return false;
}
?>

Player.php​

PHP:
<?php
/*
     Copyright (C) 2007 - 2008  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class Player extends SQL
{
private $attrs, $skills, $storage;

public function __construct()
	{
		parent::__construct();
	}
	
public function find($name)
	{
		$player = $this->myRetrieve('players', array('name' => $name));
		if ($player === false) return false;
		$this->load($player['id']);
		return true;
	}

public function load($id)
	{
		//I don't load complete data like items etc, just the stuff I need
		$player = $this->myRetrieve('players', array('id' => $id));
		if ($player === false) return false;
		$group = $this->myRetrieve('groups', array('id' => (int) $player['group_id']));
		if ($group === false)
			$this->attrs['access'] = 0;
		else{
			$this->attrs['group'] = (int) $player['group_id'];
			$this->attrs['access'] = (int) $group['access'];
			$this->attrs['position'] = (string) $group['name'];
		}
		$this->attrs['id'] = (int) $player['id'];
		$this->attrs['name'] = (string) $player['name'];
		$this->attrs['account'] = (int) $player['account_id'];
		$this->attrs['level'] = (int) $player['level'];
		$this->attrs['vocation'] = (int) $player['vocation'];
		$this->attrs['experience'] = (int) $player['experience'];
		$this->attrs['promoted'] = 0;
		$this->attrs['maglevel'] = (int) $player['maglevel'];
		$this->attrs['city'] = (int) $player['town_id'];
		$this->attrs['sex'] = (int) $player['sex'];
		$this->attrs['lastlogin'] = (int) $player['lastlogin'];
		$this->attrs['redskulltime'] = (int) $player['redskulltime'];
		$this->attrs['spawn']['x'] = (int) $player['posx'];
		$this->attrs['spawn']['y'] = (int) $player['posy'];
		$this->attrs['spawn']['z'] = (int) $player['posz'];
		//get skills
		$this->myQuery('SELECT * FROM `player_skills` WHERE `player_id` = '.$this->attrs['id']);
		if ($this->failed()) throw new Exception('Cannot retrieve player skills<br/>'.$this->getError());
		while($a = $this->fetch_array()){
			$this->skills[$a['skillid']]['skill'] = (int)$a['value'];
			$this->skills[$a['skillid']]['tries'] = (int)$a['count'];
		}
		//get storage
		$this->myQuery('SELECT * FROM `player_storage` WHERE `player_id` = '.$this->attrs['id']);
		if ($this->failed()) throw new Exception('Cannot retrieve player storage<br/>'.$this->gerError());
		while($a = $this->fetch_array())
			$this->storage[$a['key']] = (int)$a['value'];
		//get guild stuff
		$this->myQuery("SELECT players.guildnick, guild_ranks.level, guild_ranks.name, guilds.id, guilds.name FROM guild_ranks, players, guilds WHERE guilds.id = guild_ranks.guild_id AND players.rank_id = guild_ranks.id AND players.id = ".$this->attrs['id']);
		if (!$this->failed() && $this->num_rows() == 1){
			$a = $this->fetch_array();
			$this->attrs['guild_nick'] = $a[0];
			$this->attrs['guild_level'] = $a[1];
			$this->attrs['guild_rank'] = $a[2];
			$this->attrs['guild_id'] = $a[3];
			$this->attrs['guild_name'] = $a[4];
		}
		return true;
	}

public function save()
	{
		$d['group_id'] = $this->attrs['group'];
		$d['name'] = $this->attrs['name'];
		$d['account_id'] = $this->attrs['account'];
		$d['level'] = $this->attrs['level'];
		$d['vocation'] = $this->attrs['vocation'];
		$d['experience'] = $this->attrs['experience'];
		$d['maglevel'] = $this->attrs['maglevel'];
		$d['town_id'] = $this->attrs['city'];
		$d['sex'] = $this->attrs['sex'];
		$d['redskulltime'] = (int) $player['redskulltime'];
		
		return $this->myUpdate('players', $d, array('id' => $this->attrs['id']));
	}

public function exists()
	{
		$this->myQuery('SELECT * FROM `players` WHERE `name` = '.$this->quote($this->attrs['name']));
		if ($this->failed()) throw new Exception('Player::exists() cannot determine whether player exists');
		if ($this->num_rows() > 0) return true;
		return false;
	}

public function getAttr($attr)
	{
		return $this->attrs[$attr];
	}

public function isAttr($attr)
	{
		return isset($this->attrs[$attr]);
	}

public function setAttr($attr,$value)
	{
		$this->attrs[$attr] = $value;
	}
	
public function getStorage($id)
	{
		return $this->storage[$id];
	}

public function getDeaths()
	{
		$query = "SELECT * FROM `player_deaths` WHERE (`player_id` = '".$this->escape_string($this->attrs['id'])."') ORDER BY time DESC LIMIT 10";
		$this->myQuery($query);
		if ($this->failed()) throw new Exception('Cannot retrieve deaths! This is only compatible with TFS.'.$this->getError());;
		$i = 0;
		while($a = $this->fetch_array()){
			$list[$i]['killer'] = $a['killed_by'];
			$list[$i]['level'] = $a['level'];
			$list[$i]['date'] = $a['time'];
			$i++;
		}
		return $list;
	}

public function getSkill($n)
	{
		return $this->skills[$n]['skill'];
	}

public function delete()
	{
			return $this->myDelete('players',array('id' => $this->attrs['id']),0)
			&& $this->myDelete('player_items',array('player_id' => $this->attrs['id']),0)
			&& $this->myDelete('player_depotitems',array('player_id' => $this->attrs['id']),0)
			&& $this->myDelete('player_skills',array('player_id' => $this->attrs['id']),0)
			&& $this->myDelete('player_storage',array('player_id' => $this->attrs['id']),0)
			&& $this->myDelete('player_viplist',array('player_id' => $this->attrs['id']),0);
	}

public function create()
	{global $cfg;

		if ($this->exists())
			throw new Exception('Player already exists');

		//make player
		$d['id']			= NULL;
		$d['name']			= $this->attrs['name'];
		$d['account_id']	= $this->attrs['account'];
		$d['vocation']		= $this->attrs['vocation'];
		$d['sex']			= $this->attrs['sex'];
		$d['level']			= getVocLvl($this->attrs['vocation']);
		$d['experience']	= getVocExp($this->attrs['vocation']);
		$d['health']		= $cfg['vocations'][$this->attrs['vocation']]['health'];
		$d['healthmax']		= $cfg['vocations'][$this->attrs['vocation']]['health'];
		$d['looktype']		= $cfg['vocations'][$this->attrs['vocation']]['look'][(int)$this->attrs['sex']];
		$d['maglevel']		= $cfg['vocations'][$this->attrs['vocation']]['maglevel'];
		$d['mana']			= $cfg['vocations'][$this->attrs['vocation']]['mana'];
		$d['manamax']		= $cfg['vocations'][$this->attrs['vocation']]['mana'];
		$d['cap']			= $cfg['vocations'][$this->attrs['vocation']]['cap'];
		$d['town_id']		= $this->attrs['city'];
		$d['posx']			= $cfg['temple'][$this->attrs['city']]['x'];
		$d['posy']			= $cfg['temple'][$this->attrs['city']]['y'];
		$d['posz']			= $cfg['temple'][$this->attrs['city']]['z'];
		
		if (!$this->myInsert('players',$d)) throw new Exception('Player::make() Cannot insert attributes:<br/>'.$this->getError());
		$this->attrs['id'] = $this->insert_id();

		unset($d);

		//make items
		$sid = 100;
		while ($item = current($cfg['vocations'][$this->attrs['vocation']]['equipment'])){
			$sid++;
			$d['player_id']	= $this->attrs['id'];
			$d['pid']		= key($cfg['vocations'][$this->attrs['vocation']]['equipment']);
			$d['sid']		= $sid;
			$d['itemtype']	= $item;
			
			if (!$this->myInsert('player_items',$d)) throw new Exception('Player::make() Cannot insert items:<br/>'.$this->getError());
			unset($d);
			next($cfg['vocations'][$this->attrs['vocation']]['equipment']);
		}

		//make skills only if not created by trigger
		$this->myQuery('SELECT COUNT(player_skills.skillid) as count FROM player_skills WHERE player_id = '.$this->quote($this->attrs['id']));
		$a = $this->fetch_array();
		$i = 0;
		while ($skill = current($cfg['vocations'][(int)$this->attrs['vocation']]['skills'])){
			$skill_id	= key($cfg['vocations'][(int)$this->attrs['vocation']]['skills']);

			if ($a['count'] == 0){
				if (!$this->myInsert('player_skills',array('player_id' => $this->attrs['id'], 'skillid' => $skill_id, 'value' => $skill, 'count' => 0))) 
					throw new Exception('Player::make() Cannot insert skills:<br/>'.$this->getError());
			}else{
				if (!$this->myUpdate('player_skills',array('value' => $skill),array('player_id' => $this->attrs['id'], 'skillid' => $skill_id))) 
					throw new Exception('Player::make() Cannot update skills:<br/>'.$this->getError());
			}

			next($cfg['vocations'][$this->attrs['vocation']]['skills']);
		}
	return $this->load($this->attrs['id']);
	}

public function repair()
	{global $cfg;
		$lvl = $this->attrs['level'];
		$exp = AAC::getExperienceByLevel($lvl);
		if (!$this->myUpdate('players',array(
			'posx' => $cfg['temple'][$this->attrs['city']]['x'],
			'posy' => $cfg['temple'][$this->attrs['city']]['y'],
			'posz' => $cfg['temple'][$this->attrs['city']]['z']
			/*, 'experience' => $exp*/), array('id' => $this->attrs['id']))) throw new Exception($this->getError());
		return $this->load($this->attrs['id']);
	}
}
?>


Ka?da pomoc b?dzie nagradzana reputem, z g?ry dzi?kuj?.
 

Zheyr

Naczelny programista tibia.net.pl
Joined
Aug 10, 2012
Messages
961
Reaction score
114
Odp: Par? b??d?w.

iobox
PHP:
    <?php
    /*
      Copyright (C) 2007 - 2008 Nicaw
     
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
     
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
     
      You should have received a copy of the GNU General Public License along
      with this program; if not, write to the Free Software Foundation, Inc.,
      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
     
    class IOBox
    {
    private $elements, $buttons, $name, $label;
    public $target, $icon;
     
    function __construct($name){
    $this->name = $name;
    $buttons = 0;
    }
    public function addMsg($msg){
    $this->elements[]= '<p style="margin: 5px">'.$msg.'</p>';
    }
    public function addSelect($name,$options){
    $code = '<select id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'">';
    foreach (array_keys($options) as $option){
    $code.= '<option value="'.$option.'">'.$options[$option].'</option>';
    }
    $code.= '</select> <label for="'.$this->name.'__'.$name.'">- '.ucfirst($name).'</label>';
    $this->elements[] = $code;
    }
    public function addCaptcha(){
    global $cfg;
    if(!$cfg['use_captcha']) return;
    if (isset($_POST['ajax']))
    $img = 'doimg.php?'.time();
    else
    $img = '../doimg.php?'.time();
    $_SESSION['RandomText'] = substr(str_shuffle(strtolower('qwertyuipasdfhjklzx cvnm12345789')), 0, 6);
    $this->elements[]= '<img width="250px" height="40px" src="'.$img.'" alt="Verification Image"/>';
    $this->elements[]= '<input id="captcha" name="'.$this->name.'__captcha" type="text" maxlength="10" style="text-transform: uppercase"/> <label for="captcha">- Verification</label>';
    }
    public function addInput($name, $type = 'text', $value = '', $length = 100, $readonly = false){
    if ($readonly) $readonly = ' readonly="readonly"';
    else $readonly = '';
    $this->elements[]= '<input id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'" type="'.$type.'" maxlength="'.$length.'" value="'.$value.'"'.$readonly.'/> <label for="'.$this->name.'__'.$name.'">- '.ucfirst($name).'</label>';
    }
    public function addCheckBox($name, $check = false){
    if ($check) $check = ' checked="checked"';
    else $check = '';
    $this->elements[]= '<input type="checkbox" id="'.$this->name.'__'.$name.'" name="'.$this->name.'__'.$name.'"'.$check.'> <label for="'.$this->name.'__'.$name.'">'.ucfirst($name).'</label>';
    }
    public function addTextbox($name,$value = '',$cols = 40,$rows = 10){
    $this->elements[]= '<textarea name="'.$this->name.'__'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>';
    }
    public function addSubmit($text){
    $this->buttons[]= '<input style="width: 100px; height: 25px;" type="submit" name="'.$this->name.'__'.$this->name.'" value="'.$text.'"/>';
    }
    public function addReload($text){
    $this->buttons[]= '<input style="width: 100px; height: 25px;" onclick="ajax(\'form\',\''.htmlspecialchars($_SERV ER['PHP_SELF']).'\',\'\',true)" type="button" name="'.$this->name.'__'.$this->name.'" value="'.$text.'"/>';
    }
    public function addRefresh($text){
    $this->buttons[]= '<input onclick="location.reload(false)" type="button" style="width: 100px; height: 25px;" value="'.$text.'"/>';
    }
    public function addClose($text){
    $this->buttons[]= '<input style="width: 100px; height: 25px;" onclick="document.getElementById(\'iobox\').style[\'visibility\'] = \'hidden\'" type="button" value="'.$text.'"/>';
    }
    public function addCode($code){
    $this->elements[]= $code;
    }
    public function addLabel($code){
    $this->label = '<legend>'.$code.'</legend>';
    }
    public function getCode(){
    if (isset($_POST['ajax']))
    $code = '<table cellspacing="10px" onmouseup="Cookies.create(\'iobox_x\',document.get ElementById(\'iobox\').style.left,1);Cookies.creat e(\'iobox_y\',document.getElementById(\'iobox\').s tyle.top,1);" style="visibility:hidden" id="iobox" class="draggable"><tr><td><fieldset>'.$this->label.'<form id="'.$this->name.'" action="javascript:ajax(\'form\',\''.htmlspecialch ars($this->target).'\',getParams(document.getElementById(\'' .$this->name.'\')),true)" method="post">';
    else
    $code = '<div id="iobox" class="iobox"><fieldset>'.$this->label.'<form id="'.$this->name.'" action="'.htmlspecialchars($this->target).'" method="post">';
    foreach ($this->elements as $element)
    $code.= $element."<br/><div style=\"margin-top: 5px;\"></div>\r\n";
    $code.= '<hr style="margin: 10px 2px 2px 2px; padding: 0;"/> | ';
    foreach ($this->buttons as $button)
    $code.= $button." | \r\n";
    $code.= '</form></fieldset></td></tr></table>';
    return $code;
    }
    public function show(){
    echo $this->getCode();
    }
    }
     
    class Form
    {
    public $attrs;
    public function __construct($name){
    foreach( array_keys($_POST) as $key){
    if (preg_match('^'.$name.'__',$key)){
    $p = explode('__', $key);
    $this->attrs[$p[1]] = trim($_POST[$key]);
    }
    }
    }
    public function getBool($attr){
    return $this->attrs[$attr] === 'on';
    }
    public function exists(){
    if (isset($this->attrs)) return true;
    else return false;
    }
    public function validated(){
    global $cfg;
    if (!$cfg['use_captcha']) return true;
    if (strtolower($this->attrs['captcha']) === $_SESSION['RandomText'] && !empty($_SESSION['RandomText'])){
    $_SESSION['RandomText'] = null;
    return true;
    }else return false;
    }
    }

character create
PHP:
    <?php
    /*
      Copyright (C) 2007 - 2008 Nicaw
     
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
     
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
     
      You should have received a copy of the GNU General Public License along
      with this program; if not, write to the Free Software Foundation, Inc.,
      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
    include ("../include.inc.php");
     
    //retrieve post data
    $form = new Form('character');
    //check if any data was submited
    if ($form->exists()){
    //load account if loged in
    $account = new Account();
    ($account->load($_SESSION['account'])) or die('You need to login first. '.$account->getError());
    //create new player object
    $form->attrs['name'] = ucfirst($form->attrs['name']);
    $newplayer = new Player();
    //check for correct parameters
    if ($cfg['temple'][$form->attrs['residence']]['enabled'] && $cfg['vocations'][(int)$form->attrs['vocation']]['enabled'] && preg_match("^[01]$",$form->attrs['sex'])){
    //check character number
    if (count($account->players) < $cfg['maxchars']){
    //check for valid name
    if (AAC::ValidPlayerName($form->attrs['name'])){
    $newplayer->setAttr('name',(string)$form->attrs['name']);
    //player name must not exist
    if (!$newplayer->exists()){
    //set attributes for new player
    $newplayer->setAttr('vocation',(int)$form->attrs['vocation']);
    $newplayer->setAttr('account',(int)$_SESSION['account']);
    $newplayer->setAttr('sex',(int)$form->attrs['sex']);
    $newplayer->setAttr('city',(int)$form->attrs['residence']);
    //create character and add it to account
    if ($newplayer->create()){
    $account->logAction('Created character: '.$form->attrs['name']);
    //create new message
    $msg = new IOBox('message');
    $msg->addMsg('Your character was successfuly created.');
    $msg->addRefresh('Finish');
    $msg->show();
    }else{$error = 'Error. '.$newplayer->getError();}
    }else{$error = "This name is already taken.";}
    }else{$error = "<b>Not a valid name:</b><br/><ul><li>First letter capital</li><li>At least 4 characters, at most 25</li><li>No capital letters in midlle of word</li><li>Letters A-Z, -' and spaces</li><li>Monster names not allowed</li></ul>";}
    }else{$error = "You can't have more than $cfg[maxchars] characters on your account";}
    }else{$error = "Invalid parameters.";}
    if (!empty($error)){
    //create new message
    $msg = new IOBox('message');
    $msg->addMsg($error);
    $msg->addReload('<< Back');
    $msg->addClose('OK');
    $msg->show();
    }
    }else{
    //make a list of valid vocations
    while ($vocation = current($cfg['vocations'])) {
    if (isset($vocation['enabled']) && $vocation['enabled'])
    $vocations[key($cfg['vocations'])] = $vocation['name'];
    next($cfg['vocations']);
    }
    //make a list of valid spawn places
    while ($spawn = current($cfg['temple'])) {
    if (isset($spawn['enabled']) && $spawn['enabled']){
    $spawns[key($cfg['temple'])] = $spawn['name'];
    }
    next($cfg['temple']);
    }
    //create new form
    $form = new IOBox('character');
    $form->target = $_SERVER['PHP_SELF'];
    $form->addLabel('Create Character');
    $form->addInput('name');
    $form->addSelect('sex',array(1 => 'Male', 0 => 'Female'));
    $form->addSelect('vocation',$vocations);
    $form->addSelect('residence',$spawns);
    $form->addClose('Cancel');
    $form->addSubmit('Next >>');
    $form->show();
    }
    ?>
globals
PHP:
    <?php
    /*
      Copyright (C) 2007 - 2008 Nicaw
     
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
     
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
     
      You should have received a copy of the GNU General Public License along
      with this program; if not, write to the Free Software Foundation, Inc.,
      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
     
    class AAC
    {
    public function ValidPlayerName($name)
    {global $cfg;
    foreach ($cfg['invalid_names'] as $baned_name)
    if (preg_match($baned_name,$name))
    return false;
    return 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['dirdata'].'monster/'.$name.'.xml')
    && !file_exists($cfg['dirdata'].'npc/'.$name.'.xml');
    }
     
    public function ValidPassword($pass)
    {
    return strlen($pass) > 5;
    }
     
    public function ValidAccountNumber($n)
    {
    return is_numeric($n) && $n > 100000 && $n < 100000000;
    }
     
    public function ValidEmail($email)
    {
    return eregi('^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$',$email);
    }
     
    public function ValidGuildName($name)
    {
    return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
    }
     
    public function ValidGuildRank($name)
    {
    return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
    }
     
    public function ValidGuildNick($name)
    {
    return preg_match("/^[A-Z][a-z]{1,20}([ '-][A-Za-z][a-z]{1,15}){0,3}$/",$name);
    }
     
    public function getExperienceByLevel($lvl)
    {
    return floor(50*($lvl-1)*($lvl*$lvl-5*$lvl+12)/3);
    }
    }
     
    function exception_handler($exception) {
    echo '<pre style="position: absolute; top: 0px; left: 0px; background-color: white; color: black; border: 3px solid red;"><b>'.$exception->getMessage(). '<br/>'.basename($exception->getFile()).' on line: '.$exception->getLine().'</b><br/>Script was terminated because something unexpected happened. You can report this, if you think it\'s a bug.';
    }
     
    function strToDate($str){
    $pieces = explode('-',$str);
    return mktime(0,0,0,(int)$pieces[1],(int)$pieces[2],(int)$pieces[0]);
    }
     
    function getVocLvl($voc){
    global $cfg;
    return floor($cfg['vocations'][$voc]['level']);
    }
     
    function getVocExp($voc){
    global $cfg;
    $x = $cfg['vocations'][$voc]['level'];
    return round(50*($x-1)*(pow($x,2)-5*$x+12)/3);
    }
     
    function getStyle($seed)
    {
    if ($seed % 2 == 0)
    return 'class="color1"';
    else
    return 'class="color2"';
    }
     
    function percent_bar($part, $total)
    {
    if ($total <= 0) return 'unknown';
    $percent = round($part/$total*100);
    if ($percent >= 10)
    $percent_text = $percent.'%';
    return '<div class="percent_bar" style="width:'.($percent*2).'px">'.$percent_text.' </div>';
    }
     
    function deeper_array_search($needle, $haystack, $attribute)
    {
    while ($v = current($haystack)){
    if ($v[$attribute] == $needle)
    return key($haystack);
    next($haystack);
    }
    return false;
    }
    ?>

w players nie wiem co nie bangla, mo?esz przed current() jebn?? @, lecz nie usunie to b??du, jedynie ukryje, wi?c og?lnie nie polecam.
 
Last edited:

Ematerion

Advanced User
Joined
Feb 18, 2013
Messages
176
Reaction score
5
Odp: Par? b??d?w.

Teraz wgl nie ?aduje Acc Makera i pojawia si? tylko:

Code:
Parse error: syntax error, unexpected T_STRING in C:\xampplite\htdocs\class\iobox.php on line 68
 
Last edited:

Kahras

Senior User
Joined
Aug 26, 2011
Messages
2,714
Reaction score
167
Age
25
Odp: Par? b??d?w.

Co do pierwszego to chcesz tlyko zrobic zeby non-stop pokazywalo obrazek ten offline? gdy serv jest off?
 

Ematerion

Advanced User
Joined
Feb 18, 2013
Messages
176
Reaction score
5
Odp: Par? b??d?w.

Og?lnie to szczerze powiedziawszy wgl si? nie znam na php, po prostu wklei?em to co by?o. Chc? ?eby po prostu pokazywa?o, obrazek offline, kiedy srv jest offline i obrazek online, gdy srv jest online.
 

Ematerion

Advanced User
Joined
Feb 18, 2013
Messages
176
Reaction score
5
Odp: Par? b??d?w.

Poradzi?em sobie z poprzednimi b??dami, jednak?e teraz gdy pr?buj? zrobi? posta? pojawia si? ten b??d:

Code:
Fatal error: Call to undefined method SQL::isTable() in C:\xampplite\htdocs\class\player.php on line 273

player.php:

PHP:
<?php
/*
     Copyright (C) 2007 - 2009  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class Player {
    private $attrs, $skills, $storage, $deaths, $guild, $is_online, $sql;

    public function __construct() {
        $this->sql = AAC::$SQL;
    }

    public function find($name) {
        if (empty($name)) throw new PlayerNotFoundException();
        $player = $this->sql->myRetrieve('players', array('name' => $name));
        if ($player === false) throw new PlayerNotFoundException();
        $this->load($player['id']);
        return true;
    }

    private function load_deaths() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
        if($this->sql->isTable('player_killers')) {
            $query = '
SELECT DISTINCT name AS killer_name, id AS killer_id, date, level AS victim_level FROM
((SELECT players.name, players.id, player_killers.kill_id
FROM players, player_killers
WHERE players.id = player_killers.player_id)
UNION
(SELECT name, NULL AS id, kill_id
FROM environment_killers)) AS t1,
(SELECT killers.id AS kill_id, date, level, death_id FROM
killers, player_deaths
WHERE killers.death_id = player_deaths.id
AND player_deaths.player_id = '.$this->sql->quote($this->attrs['id']).'
ORDER BY date DESC, death_id, final_hit DESC
LIMIT 10) AS t2
WHERE t1.kill_id = t2.kill_id
';
            $this->sql->myQuery($query);
            $i = 0;
            while($a = $this->sql->fetch_array()) {
                $this->deaths[$i]['killer_name'] = $a['killer_name'];
                $this->deaths[$i]['killer_id'] = $a['killer_id'];
                $this->deaths[$i]['victim_level'] = $a['victim_level'];
                $this->deaths[$i]['date'] = $a['date'];
                $i++;
            }
        } elseif($this->sql->isTable('player_deaths')) {
            $query = "SELECT * FROM `player_deaths` WHERE (`player_id` = '".$this->sql->quote($this->attrs['id'])."') ORDER BY time DESC LIMIT 10";
            $this->sql->myQuery($query);
            $i = 0;
            while($a = $this->sql->fetch_array()) {
                $killer = new Player();
                try {
                    $killer->find($a['killed_by']);
                    $this->deaths[$i]['killer_name'] = $killer->attrs['name'];
                    $this->deaths[$i]['killer_id'] = $killer->attrs['id'];
                } catch(PlayerNotFoundException $e) {
                    try {
                        $killer->load($death['killed_by']);
                        $this->deaths[$i]['killer_name'] = $killer->attrs['name'];
                        $this->deaths[$i]['killer_id'] = $killer->attrs['id'];
                    } catch(PlayerNotFoundException $e) {
                        $this->deaths[$i]['killer_name'] = $a['killed_by'];
                        $this->deaths[$i]['killer_id'] = null;
                    }
                }

                $this->deaths[$i]['victim_level'] = $a['level'];
                $this->deaths[$i]['date'] = $a['time'];
                $i++;
            }
        } else throw new DatabaseException('Deaths data not found in database or it is not compatible.');

        return true;
    }

    private function load_skills() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
        $this->sql->myQuery('SELECT * FROM `player_skills` WHERE `player_id` = '.$this->sql->quote($this->attrs['id']));
        while($a = $this->sql->fetch_array()) {
            $this->skills[$a['skillid']]['skill'] = (int)$a['value'];
            $this->skills[$a['skillid']]['tries'] = (int)$a['count'];
        }
        return true;
    }

    private function load_storage() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
        $this->sql->myQuery('SELECT * FROM `player_storage` WHERE `player_id` = '.$this->sql->quote($this->attrs['id']));
        while($a = $this->sql->fetch_array())
            $this->storage[$a['key']] = (int)$a['value'];
        return true;
    }

    private function load_guild() {
        if(empty($this->attrs['rank_id']) || $this->attrs['rank_id'] == 0) throw new GuildNotFoundException();
        $this->sql->myQuery("SELECT guild_ranks.level, guild_ranks.name AS rank_name, guilds.id, guilds.name AS guild_name FROM guild_ranks, guilds WHERE guilds.id = guild_ranks.guild_id AND guild_ranks.id = ".$this->sql->quote($this->attrs['rank_id']));
        if ($this->sql->num_rows() == 1) {
            $a = $this->sql->fetch_array();
            $this->guild['guild_nick'] = $this->attrs['guildnick'];
            $this->guild['guild_level'] = $a['level'];
            $this->guild['guild_rank_name'] = $a['rank_name'];
            $this->guild['guild_rank_id'] = $this->attrs['rank_id'];
            $this->guild['guild_id'] = $a['id'];
            $this->guild['guild_name'] = $a['guild_name'];
        }
        return true;
    }

    public function reload() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
        unset($this->skills, $this->storage, $this->deaths, $this->guild);
        load($this->attrs['id']);
        return true;
    }

    public function load($id) {
        if (!is_numeric($id)) throw new PlayerNotFoundException();
        
        //Load player attributes
        $player = $this->sql->myRetrieve('players', array('id' => $id));
        if ($player === false) throw new PlayerNotFoundException();
        try {
            $group = $this->sql->myRetrieve('groups', array('id' => (int) $player['group_id']));
            $this->attrs['access'] = (int) $group['access'];
            $this->attrs['position'] = (string) $group['name'];
        } catch(DatabaseQueryException $e) {
            $this->attrs['access'] = 0;
        }
        if(isset($player['online'])) {
            if((bool) $player['online'] == true) {
                $this->is_online = true;
            } else {
                $this->is_online = false;
            }
        } elseif(isset($player['lastlogin']) && isset($player['lastlogout'])) {
            if($player['lastlogin'] > $player['lastlogout']) {
                $this->is_online = true;
            } else {
                $this->is_online = false;
            }
        } else {
            $this->is_online = false;
        }
        $this->attrs['group'] = (int) $player['group_id'];
        $this->attrs['id'] = (int) $player['id'];
        $this->attrs['name'] = (string) $player['name'];
        $this->attrs['account'] = (int) $player['account_id'];
        $this->attrs['level'] = (int) $player['level'];
        $this->attrs['vocation'] = (int) $player['vocation'];
        $this->attrs['experience'] = (int) $player['experience'];
        $this->attrs['maglevel'] = (int) $player['maglevel'];
        $this->attrs['city'] = (int) $player['town_id'];
        $this->attrs['sex'] = (int) $player['sex'];
        $this->attrs['lastlogin'] = (int) $player['lastlogin'];
        $this->attrs['rank_id'] = (int) $player['rank_id'];
        $this->attrs['guildnick'] = (string) $player['guildnick'];
        $this->attrs['spawn']['x'] = (int) $player['posx'];
        $this->attrs['spawn']['y'] = (int) $player['posy'];
        $this->attrs['spawn']['z'] = (int) $player['posz'];
        $this->attrs['guildnick'] = (string) $player['guildnick'];

        return true;
    }

    public function save() {
    //cannot save player unless it's offline
        if($this->is_online) throw new PlayerIsOnlineException();

        //only save these fields
        $d['group_id'] = $this->attrs['group'];
        $d['name'] = $this->attrs['name'];
        $d['account_id'] = $this->attrs['account'];
        $d['level'] = $this->attrs['level'];
        $d['vocation'] = $this->attrs['vocation'];
        $d['experience'] = $this->attrs['experience'];
        $d['maglevel'] = $this->attrs['maglevel'];
        $d['town_id'] = $this->attrs['city'];
        $d['sex'] = $this->attrs['sex'];
        $d['rank_id'] = $this->attrs['rank_id'];
        $d['guildnick'] = $this->attrs['guildnick'];

        $this->sql->myUpdate('players', $d, array('id' => $this->attrs['id']));
        return true;
    }

    public function save_guild() {
        $d['rank_id'] = $this->attrs['rank_id'];
        $d['guildnick'] = $this->attrs['guildnick'];

        $this->sql->myUpdate('players', $d, array('id' => $this->attrs['id']));

        return true;
    }


    public function setAttr($attr, $val) {
        if(array_key_exists($attr, $this->attrs))
            $this->attrs[$attr] = $val;
        else
            throw new ClassException('Parameter '.$attr.' does not exist.');
    }

    public function isOnline() {
        return $this->is_online;
    }

    static public function exists($name) {
        $SQL = AAC::$SQL;
        $SQL->myQuery('SELECT * FROM `players` WHERE `name` = '.$SQL->quote($name));
        if ($SQL->num_rows() > 0) return true;
        return false;
    }

    public function __get($attr) {
        if(empty($this->attrs['id']))
            throw new ClassException('Attempt to get attribute of player that is not loaded.');
        if($attr == 'attrs') {
            return $this->attrs;
        }elseif($attr == 'skills') {
            if(empty($this->skills)) $this->load_skills();
            return $this->skills;
        }elseif($attr == 'deaths') {
            if(empty($this->deaths)) $this->load_deaths();
            return $this->deaths;
        }elseif($attr == 'storage') {
            if(empty($this->storage)) $this->load_storage();
            return $this->storage;
        }elseif($attr == 'guild') {
            if(empty($this->guild)) $this->load_guild();
            return $this->guild;
        }else {
            throw new ClassException('Undefined property: '.$attr);
        }
    }

    public function delete() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
        try {
            $guild = new Guild();
            $guild->load($this->guild['guild_id']);
            $guild->remove();
        } catch (GuildNotFoundException $e) {}
        $this->sql->myDelete('players',array('id' => $this->attrs['id']),0)
            && $this->sql->myDelete('player_items',array('player_id' => $this->attrs['id']),0)
            && $this->sql->myDelete('player_depotitems',array('player_id' => $this->attrs['id']),0)
            && $this->sql->myDelete('player_skills',array('player_id' => $this->attrs['id']),0)
            && $this->sql->myDelete('player_storage',array('player_id' => $this->attrs['id']),0)
            && $this->sql->myDelete('player_viplist',array('player_id' => $this->attrs['id']),0)
            && $this->sql->myDelete('guilds',array('ownerid' => $this->attrs['id']),0);
    }

    static public function Create($name, $account, $vocation, $sex, $city) {global $cfg;

        $SQL = AAC::$SQL;

        $group_id = $cfg['vocations'][$vocation]['group'];
        if ($SQL->isTable('groups')) {
            $group = $SQL->myRetrieve('groups', array('id' => $group_id));
            if ($group === false) {
                throw new ClassException('Player::Create() Group #'.$group_id.' does not exist. Check your database and config file.', 6);
            }
        }


        $d['id']		= NULL;
        $d['name']		= $name;
        $d['account_id']	= $account;
        $d['group_id']		= $group_id;
        $d['rank_id']		= 0;
        $d['vocation']		= $vocation;
        $d['sex']		= $sex;
        $d['level']		= getVocLvl($vocation);
        $d['experience']	= getVocExp($vocation);
        $d['health']		= $cfg['vocations'][$vocation]['health'];
        $d['healthmax']		= $cfg['vocations'][$vocation]['health'];
        $d['looktype']		= $cfg['vocations'][$vocation]['look'][$sex];
        $d['maglevel']		= $cfg['vocations'][$vocation]['maglevel'];
        $d['mana']		= $cfg['vocations'][$vocation]['mana'];
        $d['manamax']		= $cfg['vocations'][$vocation]['mana'];
        $d['cap']		= $cfg['vocations'][$vocation]['cap'];
        $d['town_id']		= $city;
        $d['posx']		= $cfg['temple'][$city]['x'];
        $d['posy']		= $cfg['temple'][$city]['y'];
        $d['posz']		= $cfg['temple'][$city]['z'];
        $d['conditions']	= '';

        $SQL->myInsert('players',$d);
        $pid = $SQL->insert_id();

        unset($d);

        //make items
        $sid = 100;
        while ($item = current($cfg['vocations'][$vocation]['equipment'])) {
            $sid++;
            $d['player_id']	= $pid;
            $d['pid']		= key($cfg['vocations'][$vocation]['equipment']);
            $d['sid']		= $sid;
            $d['itemtype']	= $item;
            $d['attributes']= '';

            $SQL->myInsert('player_items',$d);
            unset($d);
            next($cfg['vocations'][$vocation]['equipment']);
        }

        //make skills only if not created by trigger
        $SQL->myQuery('SELECT COUNT(player_skills.skillid) as count FROM player_skills WHERE player_id = '.$SQL->quote($pid));
        $a = $SQL->fetch_array();
        $i = 0;
        while ($skill = current($cfg['vocations'][$vocation]['skills'])) {
            $skill_id	= key($cfg['vocations'][$vocation]['skills']);

            if ($a['count'] == 0) {
                $SQL->myInsert('player_skills',array('player_id' => $pid, 'skillid' => $skill_id, 'value' => $skill, 'count' => 0));
            }else {
                $SQL->myUpdate('player_skills',array('value' => $skill),array('player_id' => $pid, 'skillid' => $skill_id));
            }

            next($cfg['vocations'][$vocation]['skills']);
        }
        $player = new Player();
        $player->load($pid);
        return $player;
    }

    public function repair() {global $cfg;
        $lvl = $this->attrs['level'];
        $exp = AAC::getExperienceByLevel($lvl);
        $this->sql->myUpdate('players',array(
            'posx' => $cfg['temple'][$this->attrs['city']]['x'],
            'posy' => $cfg['temple'][$this->attrs['city']]['y'],
            'posz' => $cfg['temple'][$this->attrs['city']]['z']
            ), array('id' => $this->attrs['id']));
    }
}
?>

Dodam, ?e zacz??o si? tak dzia? odk?d doda?em nowe postacie do config.inc.

---------- Tre?? dodana o 11:22 ----------

Kolejny problem :/. Doda?em nowe rzeczy do account.php. Wszystko dzia?a, jednak?e gdy klikam Create Character tabelka pojawia si? za nisko, przez co nie mo?na wpisa? danych do kolumn i zrobi? postaci. Wie kto? mo?e jak to przesun??? To samo tyczy si? innych funkcji, takich jak Delete Character, Change Password itd.

Za pomoc daj? reputa, z g?ry dzi?kuj?.

---------- Tre?? dodana o 19:40 ----------

Pomo?e kto?? Bardzo mi na tym zale?y. Ka?da pomoc b?dzie nagradzana reputem.
 
Last edited:
Status
Not open for further replies.
Top