db = &$db;
}
private function Msg($text, $err)
{
global $html;
if($err == 0) echo(' '.$text.'
');
else echo(' '.$text.'
');
}
public function Register($acc_name, $pass, $email, $tbc)
{
global $Config;
$this->db->select_db($Config['Mangos']['DatabaseRealmd']);
$find = $this->db->query('SELECT `id` FROM `account` WHERE `username` = "'.$acc_name.'"');
if($find->num_rows == 0)
{
$sha_pass = sha1(strtoupper($acc_name).':'.strtoupper($pass));
$sql = $this->db->query('INSERT INTO `account` ( `id` , `username` , `sha_pass_hash` , `gmlevel` , `sessionkey` , `v` , `s` , `email` , `joindate` , `last_ip` , `failed_logins` , `locked` , `last_login` , `online` , `tbc` , `mutetime` , `locale` ) '.
' VALUES (NULL , "'.$acc_name.'", "'.$sha_pass.'", 0, NULL , NULL , NULL , "'.$email.'", CURRENT_TIMESTAMP , "'.$_SERVER['REMOTE_ADDR'].'", 0, 0, "0000-00-00 00:00:00", 0, "'.$tbc.'", 0, 0)');
$this->Msg('Účet založen úspěšně', 0);
echo('');
} else
{
$this->Msg('Zadané jmnéno účtu již existuje', 1);
}
}
public function Login($username, $pass)
{
global $Config;
$this->db->select_db($Config['Mangos']['DatabaseRealmd']);
$sha_pass = sha1(strtoupper($username).':'.strtoupper($pass));
$sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$username.'" AND `sha_pass_hash`="'.$sha_pass.'"');
if($sql->num_rows == 1)
{
$row = $sql->fetch_assoc();
$_SESSION['UserId'] = $row['id'];
$_SESSION['UserName'] = $username;
$this->Msg('Přihlášení úspěšné', 0);
} else
{
$this->Msg('Přihlášení neúspěšné', 1);
}
}
public function Logout()
{
$_SESSION['UserId'] = 0;
$_SESSION['UserName'] = '';
$this->Msg('Odhlášení úspěšné', 0);
}
public function Check()
{
if(!array_key_exists('Time', $_SESSION)) $_SESSION['Time'] = time();
if(!array_key_exists('UserId', $_SESSION)) $_SESSION['UserId'] = 0;
if($_SESSION['Time'] < (time() - 60 * $this->SessionTimeout)) $this->Logout();
$_SESSION['Time'] = time();
return($_SESSION['UserId'] != 0);
}
public function LoginForm()
{
global $html;
echo('
');
}
public function GetPlayerLvl($guid, $RealmId)
{
global $Config, $System;
$Realm = new Realm($System, $RealmId);
$DbResult = $Realm->CharactersDatabase->query('SELECT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, " ", '.($Config['Mangos']['CharacterDataOffset']['Level'] + 1).'), " ", -1) AS UNSIGNED) AS `level` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;');
$row = $DbResult->fetch_assoc();
return($row['level']);
}
public function GetGmLvl()
{
global $Config;
$this->db->select_db($Config['Mangos']['DatabaseRealmd']);
$row = $this->db->query('SELECT `gmlevel` FROM `account` WHERE `id` = "'.$_SESSION['UserId'].'" LIMIT 1;')->fetch_assoc();
return($row['gmlevel']);
}
public function GetPlayerClass($Id)
{
$Class = array(1 => 'warrior', 2 => 'paladin', 3 => 'hunter', 4 => 'rogue', 5 => 'priest', 6 => 'death knight', 7 => 'shaman', 8 => 'mage', 9 => 'warlock', 11 => 'druid');
if(array_key_exists($Id, $Class)) $Result = $Class[$Id];
else $Result = 'unknown';
return($Result);
}
public function GetPlayerRace($Id)
{
$Race = array(1 => 'human', 2 => 'orc', 4 => 'dwarf', 4 => 'nightelf', 5 => 'undead', 6 => 'tauren', 7 => 'gnome', 8 => 'troll', 9 => 'goblin', 10 => 'bloodelf', 11 => 'draenei');
if(array_key_exists($Id, $Race)) $Result = $Race[$Id];
else $Result = 'unknown';
return($Result);
}
public function ResetXP($guid)
{
global $System, $Config;
if($this->CharInAcc($guid, 0))
{
if(!$this->IsOnline($guid))
{
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
$row = $Realm->CharactersDatabase->query('SELECT `data` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_assoc();
$data = explode(' ', $row['data']);
$data[$Config['Mangos']['CharacterDataOffset']['Exp']] = 0;
$data = implode(' ', $data);
$Realm->CharactersDatabase->query('UPDATE `characters` SET `data` = "'.$data.'" WHERE `guid` ="'.$guid.'" LIMIT 1');
$this->Msg('Postavě resetováno XP.', 0);
} else $this->Msg('Postava musí být offline.', 1);
} else $this->Msg('Tato postava není vaše.', 1);
}
public function ResetPosition($guid)
{
global $System, $Config;
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
if($this->CharInAcc($guid, 0))
{
if(!$this->IsOnline($guid))
{
$row = $Realm->CharactersDatabase->query('SELECT * FROM `character_homebind` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_array();
$home_char_map = $row['map'];
$home_char_position_x = $row['position_x'];
$home_char_position_y = $row['position_y'];
$home_char_position_z = $row['position_z'];
if(isset($home_char_map) and isset($home_char_position_x) and isset($home_char_position_y) and isset($home_char_position_z))
{
$Realm->CharactersDatabase->query('UPDATE `characters` SET '.
'`map` = "'.$home_char_map.'" , '.
'`position_x` ="'.$home_char_position_x.'" , '.
'`position_y` = "'.$home_char_position_y.'" , '.
'`position_z` = "'.$home_char_position_z.'" '.
' WHERE `guid` ='.$guid.' LIMIT 1;');
$this->Msg('Postava teleportována.', 0);
}
} else $this->Msg('Postava musí být offline.', 1);
} else $this->Msg('Tato postava není vaše.', 1);
}
public function PlayerJail($guid)
{
global $System, $Config;
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
// .go xyz -90.54 41.35 -31.71
// .go xyz -91.01 100.46 -31.71
// .go xyz -119.16 71.82 -31.71
$defined_positions = array
(
'x1' => '-90.54',
'y1' => '41.35',
'z1' => '-31.71',
'o1' => '1.4623',
'x2' => '-91.01',
'y2' => '100.46',
'z2' => '-31.71',
'o3' => '4.6282',
'x3' => '-119.16',
'y3' => '71.82',
'z3' => '-31.71',
'o3' => '6.2116',
);
$rand_place = rand(1, 3);
if(!$this->IsOnline($guid))
{
$Realm->CharactersDatabase->query('UPDATE `characters` SET `map` = 35 ,'.
'`orientation` = "'.$defined_positions['o'.$rand_place].'" ,'.
'`position_x` ="'.$defined_positions['x'.$rand_place].'" ,'.
'`position_y` = "'.$defined_positions['y'.$rand_place].'" ,'.
'`position_z` = "'.$defined_positions['z'.$rand_place].'"'.
' WHERE `guid` ="'.$guid.'" LIMIT 1;');
$Realm->CharactersDatabase->query('INSERT INTO `character_aura` (`guid`, `caster_guid`, `spell`, `effect_index`, `amount`, `maxduration`, `remaintime`, `remaincharges`) VALUES '.
'('.$guid.', '.$guid.', 23775, 0, 1, -1, -1, -1), '.
'('.$guid.', '.$guid.', 36558, 0, 1, -1, -1, -1);');
$this->Msg('Postava ve vězení.', 0);
} else $this->Msg('Postava musí být offline.', 1);
}
public function IsOnline($guid)
{
global $System, $Config;
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
$row = $Realm->CharactersDatabase->query('SELECT `online` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
if($row['online'] == 1) return(true);
else return(false);
}
public function CharInAcc($char, $acc)
{
global $Config, $System;
if($this->Check())
{
if($acc == 0)
{
$acc = $_SESSION['UserId'];
}
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
if($Realm->CharactersDatabase->query('SELECT `guid` FROM `characters` WHERE `characters`.`guid`="'.$char.'" AND `account`="'.$acc.'" LIMIT 1;')->num_rows == 1)
{
return(true);
} else
{
return false;
}
} else
{
$this->Msg('Nejste přihlášen', 1);
die;
}
}
public function CharNameToGuid($name)
{
global $System, $Config;
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
$row = $Realm->CharactersDatabase->query('SELECT `guid` FROM `characters` WHERE `name` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
if($row['guid'] != '')
{
return($row['guid']);
} else
{
return('Nenalezen');
}
}
public function GuidToCharName($guid)
{
global $Config;
$Realm = new Realm($System, $_COOKIE['RealmIndex']);
$row = $Realm->CharactersDatabase->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
if($row['name'] != '')
{
return($row['name']);
} else
{
return('Nenalezen');
}
}
public function AccNameToGuid($name)
{
global $Config;
$this->db->select_db($Config['Mangos']['DatabaseRealmd']);
$row = $this->db->query('SELECT `id` FROM `account` WHERE `username` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
//return($row['id']);
if($row['id'] != '')
{
return($row['id']);
} else
{
return('Nenalezen');
}
}
public function MoveChar($acc1_name, $acc1_pass, $acc2_name, $char_name)
{
global $Config;
$this->db->select_db($Config['Mangos']['DatabaseRealmd']);
$sha_pass = sha1(strtoupper($acc1_name).':'.strtoupper($acc1_pass));
$sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$acc1_name.'" AND `sha_pass_hash`="'.$sha_pass.'"');
if($sql->num_rows == 1)
{
$acc1_guid = $this->AccNameToGuid($acc1_name);
$acc2_guid = $this->AccNameToGuid($acc2_name);
$char_guid = $this->CharNameToGuid($char_name);
if($this->CharInAcc($char_guid, $acc1_guid))
{
$this->db->query('UPDATE `characters` SET `account` = "'.$acc2_guid.'" WHERE `guid` ="'.$char_guid.'" LIMIT 1');
$this->Msg('Postava přemístěna.', 0);
} else
{
$this->Msg('Tato postava není vaše.', 1);
}
}
}
public function CharsOnAcc($accid)
{
global $Config, $System, $html;
$DbResult = $System->Database->query('SELECT Name,Id FROM Realm WHERE Enabled=1');
while($DbRealm = $DbResult->fetch_array())
{
echo(''.$DbRealm['Name'].'
');
echo('
Jméno |
Úroveň |
Rasa |
Třída |
Nahráno |
');
$Realm = new Realm($System, $DbRealm['Id']);
$sql = $Realm->CharactersDatabase->query('SELECT `guid`,`name`,`race`,`totaltime`,`class`, mid(lpad( hex( CAST(substring_index(substring_index(data, " ", '.($Config['Mangos']['CharacterDataOffset']['Gender'] + 1).'), " ",-1) AS unsigned) ), 8, 0), 4, 1) AS gender FROM `characters` WHERE `account`='.$accid.' ORDER BY `totaltime` DESC LIMIT 0, 10');
while($row = $sql->fetch_array())
{
$gender = ($row['gender'] == 0) ? '0' : '1';
echo(''.
''.$row['name'].' | '.
''.$this->GetPlayerLvl($row['guid'], $DbRealm['Id']).' | '.
' | '.
' | '.
''.round($row['totaltime'] / 3600).' h | '.
'
');
}
echo('
');
}
}
}
?>