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.
<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]
2. Zak?adanie konta:
Podczas zak?adania konta oraz postaci wyskakuj? nast?puj?ce b??dy:
Ka?da pomoc b?dzie nagradzana reputem, z g?ry dzi?kuj?.
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?.