1 | <?php
|
---|
2 |
|
---|
3 | class Player
|
---|
4 | {
|
---|
5 | var $SessionTimeout = 30;
|
---|
6 |
|
---|
7 | private $db;
|
---|
8 |
|
---|
9 | function __construct($db)
|
---|
10 | {
|
---|
11 | $this->db = &$db;
|
---|
12 | }
|
---|
13 |
|
---|
14 | private function Msg($text, $err)
|
---|
15 | {
|
---|
16 | global $html;
|
---|
17 |
|
---|
18 | if($err == 0) echo('<img src="'.$html->Link('/imgs/inc/on.gif').'"> <font color="#234303" size="4">'.$text.'</font><br />');
|
---|
19 | else echo('<img src="'.$html->Link('/imgs/inc/off.gif').'"> <font color="#990000" size="4\">'.$text.'</font><br />');
|
---|
20 | }
|
---|
21 |
|
---|
22 | public function Register($acc_name, $pass, $email, $tbc)
|
---|
23 | {
|
---|
24 | global $Config;
|
---|
25 |
|
---|
26 | $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
|
---|
27 |
|
---|
28 | $find = $this->db->query('SELECT `id` FROM `account` WHERE `username` = "'.$acc_name.'"');
|
---|
29 | if($find->num_rows == 0)
|
---|
30 | {
|
---|
31 | $sha_pass = sha1(strtoupper($acc_name).':'.strtoupper($pass));
|
---|
32 | $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` ) '.
|
---|
33 | ' 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)');
|
---|
34 | $this->Msg('Účet založen úspěšně', 0);
|
---|
35 | echo('<meta http-equiv="refresh" content="0;'.$html->Link('/ucet/').'">');
|
---|
36 | } else
|
---|
37 | {
|
---|
38 | $this->Msg('Zadané jmnéno účtu již existuje', 1);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public function Login($username, $pass)
|
---|
43 | {
|
---|
44 | global $Config;
|
---|
45 |
|
---|
46 | $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
|
---|
47 |
|
---|
48 | $sha_pass = sha1(strtoupper($username).':'.strtoupper($pass));
|
---|
49 | $sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$username.'" AND `sha_pass_hash`="'.$sha_pass.'"');
|
---|
50 | if($sql->num_rows == 1)
|
---|
51 | {
|
---|
52 | $row = $sql->fetch_assoc();
|
---|
53 | $_SESSION['UserId'] = $row['id'];
|
---|
54 | $_SESSION['UserName'] = $username;
|
---|
55 | $this->Msg('Přihlášení úspěšné', 0);
|
---|
56 | } else
|
---|
57 | {
|
---|
58 | $this->Msg('Přihlášení neúspěšné', 1);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public function Logout()
|
---|
63 | {
|
---|
64 | $_SESSION['UserId'] = 0;
|
---|
65 | $_SESSION['UserName'] = '';
|
---|
66 | $this->Msg('Odhlášení úspěšné', 0);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public function Check()
|
---|
70 | {
|
---|
71 | if(!array_key_exists('Time', $_SESSION)) $_SESSION['Time'] = time();
|
---|
72 | if(!array_key_exists('UserId', $_SESSION)) $_SESSION['UserId'] = 0;
|
---|
73 | if($_SESSION['Time'] < (time() - 60 * $this->SessionTimeout)) $this->Logout();
|
---|
74 | $_SESSION['Time'] = time();
|
---|
75 | return($_SESSION['UserId'] != 0);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public function LoginForm()
|
---|
79 | {
|
---|
80 | global $html;
|
---|
81 |
|
---|
82 | echo('<form method="post" action="'.$html->Link('/ucet/').'">'.
|
---|
83 | '<table>'.
|
---|
84 | '<tr>'.
|
---|
85 | '<td><b>Jméno : </b></td><td><input type="text" name="user" class="textinput"></td>
|
---|
86 | </tr>
|
---|
87 | <tr>
|
---|
88 | <td><b>Heslo : </b></td><td><input type="password" name="pass" autocomplete="off" class="textinput"></td>
|
---|
89 | </tr>
|
---|
90 | <tr>
|
---|
91 | <td colspan="2" align="right"><input type="submit" value="Příhlásit" name="login"></td>
|
---|
92 | </tr>
|
---|
93 | </table>
|
---|
94 | </form>
|
---|
95 | <div align="left">
|
---|
96 | <a href="'.$html->Link('/registrace/').'">Registrace</a><br />'. //<a href="'.$html->Link('/ucet/obnova-hesla/').'">Obnova hesla</a>
|
---|
97 | '</div>');
|
---|
98 | }
|
---|
99 |
|
---|
100 | public function GetPlayerLvl($guid, $RealmId)
|
---|
101 | {
|
---|
102 | global $Config, $System;
|
---|
103 |
|
---|
104 | $Realm = new Realm($System, $RealmId);
|
---|
105 | $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;');
|
---|
106 | $row = $DbResult->fetch_assoc();
|
---|
107 | return($row['level']);
|
---|
108 | }
|
---|
109 |
|
---|
110 | public function GetGmLvl()
|
---|
111 | {
|
---|
112 | global $Config;
|
---|
113 |
|
---|
114 | $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
|
---|
115 | $row = $this->db->query('SELECT `gmlevel` FROM `account` WHERE `id` = "'.$_SESSION['UserId'].'" LIMIT 1;')->fetch_assoc();
|
---|
116 | return($row['gmlevel']);
|
---|
117 | }
|
---|
118 |
|
---|
119 | public function GetPlayerClass($Id)
|
---|
120 | {
|
---|
121 | $Class = array(1 => 'warrior', 2 => 'paladin', 3 => 'hunter', 4 => 'rogue', 5 => 'priest', 6 => 'death knight', 7 => 'shaman', 8 => 'mage', 9 => 'warlock', 11 => 'druid');
|
---|
122 | if(array_key_exists($Id, $Class)) $Result = $Class[$Id];
|
---|
123 | else $Result = 'unknown';
|
---|
124 | return($Result);
|
---|
125 | }
|
---|
126 |
|
---|
127 | public function GetPlayerRace($Id)
|
---|
128 | {
|
---|
129 | $Race = array(1 => 'human', 2 => 'orc', 4 => 'dwarf', 4 => 'nightelf', 5 => 'undead', 6 => 'tauren', 7 => 'gnome', 8 => 'troll', 9 => 'goblin', 10 => 'bloodelf', 11 => 'draenei');
|
---|
130 | if(array_key_exists($Id, $Race)) $Result = $Race[$Id];
|
---|
131 | else $Result = 'unknown';
|
---|
132 | return($Result);
|
---|
133 | }
|
---|
134 |
|
---|
135 | public function ResetXP($guid)
|
---|
136 | {
|
---|
137 | global $System, $Config;
|
---|
138 |
|
---|
139 | if($this->CharInAcc($guid, 0))
|
---|
140 | {
|
---|
141 | if(!$this->IsOnline($guid))
|
---|
142 | {
|
---|
143 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
144 | $row = $Realm->CharactersDatabase->query('SELECT `data` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1')->fetch_assoc();
|
---|
145 | $data = explode(' ', $row['data']);
|
---|
146 | $data[$Config['Mangos']['CharacterDataOffset']['Exp']] = 0;
|
---|
147 | $data = implode(' ', $data);
|
---|
148 | $Realm->CharactersDatabase->query('UPDATE `characters` SET `data` = "'.$data.'" WHERE `guid` ="'.$guid.'" LIMIT 1');
|
---|
149 | $this->Msg('Postavě resetováno XP.', 0);
|
---|
150 | } else $this->Msg('Postava musí být offline.', 1);
|
---|
151 | } else $this->Msg('Tato postava není vaše.', 1);
|
---|
152 | }
|
---|
153 |
|
---|
154 | public function ResetPosition($guid)
|
---|
155 | {
|
---|
156 | global $System, $Config;
|
---|
157 |
|
---|
158 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
159 | if($this->CharInAcc($guid, 0))
|
---|
160 | {
|
---|
161 | if(!$this->IsOnline($guid))
|
---|
162 | {
|
---|
163 | $row = $Realm->CharactersDatabase->query('SELECT * FROM `character_homebind` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_array();
|
---|
164 | $home_char_map = $row['map'];
|
---|
165 | $home_char_position_x = $row['position_x'];
|
---|
166 | $home_char_position_y = $row['position_y'];
|
---|
167 | $home_char_position_z = $row['position_z'];
|
---|
168 | if(isset($home_char_map) and isset($home_char_position_x) and isset($home_char_position_y) and isset($home_char_position_z))
|
---|
169 | {
|
---|
170 | $Realm->CharactersDatabase->query('UPDATE `characters` SET '.
|
---|
171 | '`map` = "'.$home_char_map.'" , '.
|
---|
172 | '`position_x` ="'.$home_char_position_x.'" , '.
|
---|
173 | '`position_y` = "'.$home_char_position_y.'" , '.
|
---|
174 | '`position_z` = "'.$home_char_position_z.'" '.
|
---|
175 | ' WHERE `guid` ='.$guid.' LIMIT 1;');
|
---|
176 | $this->Msg('Postava teleportována.', 0);
|
---|
177 | }
|
---|
178 | } else $this->Msg('Postava musí být offline.', 1);
|
---|
179 | } else $this->Msg('Tato postava není vaše.', 1);
|
---|
180 | }
|
---|
181 |
|
---|
182 | public function PlayerJail($guid)
|
---|
183 | {
|
---|
184 | global $System, $Config;
|
---|
185 |
|
---|
186 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
187 | // .go xyz -90.54 41.35 -31.71
|
---|
188 | // .go xyz -91.01 100.46 -31.71
|
---|
189 | // .go xyz -119.16 71.82 -31.71
|
---|
190 | $defined_positions = array
|
---|
191 | (
|
---|
192 | 'x1' => '-90.54',
|
---|
193 | 'y1' => '41.35',
|
---|
194 | 'z1' => '-31.71',
|
---|
195 | 'o1' => '1.4623',
|
---|
196 |
|
---|
197 | 'x2' => '-91.01',
|
---|
198 | 'y2' => '100.46',
|
---|
199 | 'z2' => '-31.71',
|
---|
200 | 'o3' => '4.6282',
|
---|
201 |
|
---|
202 | 'x3' => '-119.16',
|
---|
203 | 'y3' => '71.82',
|
---|
204 | 'z3' => '-31.71',
|
---|
205 | 'o3' => '6.2116',
|
---|
206 | );
|
---|
207 | $rand_place = rand(1, 3);
|
---|
208 | if(!$this->IsOnline($guid))
|
---|
209 | {
|
---|
210 | $Realm->CharactersDatabase->query('UPDATE `characters` SET `map` = 35 ,'.
|
---|
211 | '`orientation` = "'.$defined_positions['o'.$rand_place].'" ,'.
|
---|
212 | '`position_x` ="'.$defined_positions['x'.$rand_place].'" ,'.
|
---|
213 | '`position_y` = "'.$defined_positions['y'.$rand_place].'" ,'.
|
---|
214 | '`position_z` = "'.$defined_positions['z'.$rand_place].'"'.
|
---|
215 | ' WHERE `guid` ="'.$guid.'" LIMIT 1;');
|
---|
216 | $Realm->CharactersDatabase->query('INSERT INTO `character_aura` (`guid`, `caster_guid`, `spell`, `effect_index`, `amount`, `maxduration`, `remaintime`, `remaincharges`) VALUES '.
|
---|
217 | '('.$guid.', '.$guid.', 23775, 0, 1, -1, -1, -1), '.
|
---|
218 | '('.$guid.', '.$guid.', 36558, 0, 1, -1, -1, -1);');
|
---|
219 | $this->Msg('Postava ve vězení.', 0);
|
---|
220 | } else $this->Msg('Postava musí být offline.', 1);
|
---|
221 | }
|
---|
222 |
|
---|
223 | public function IsOnline($guid)
|
---|
224 | {
|
---|
225 | global $System, $Config;
|
---|
226 |
|
---|
227 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
228 | $row = $Realm->CharactersDatabase->query('SELECT `online` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
|
---|
229 | if($row['online'] == 1) return(true);
|
---|
230 | else return(false);
|
---|
231 | }
|
---|
232 |
|
---|
233 | public function CharInAcc($char, $acc)
|
---|
234 | {
|
---|
235 | global $Config, $System;
|
---|
236 |
|
---|
237 | if($this->Check())
|
---|
238 | {
|
---|
239 | if($acc == 0)
|
---|
240 | {
|
---|
241 | $acc = $_SESSION['UserId'];
|
---|
242 | }
|
---|
243 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
244 | if($Realm->CharactersDatabase->query('SELECT `guid` FROM `characters` WHERE `characters`.`guid`="'.$char.'" AND `account`="'.$acc.'" LIMIT 1;')->num_rows == 1)
|
---|
245 | {
|
---|
246 | return(true);
|
---|
247 | } else
|
---|
248 | {
|
---|
249 | return false;
|
---|
250 | }
|
---|
251 | } else
|
---|
252 | {
|
---|
253 | $this->Msg('Nejste přihlášen', 1);
|
---|
254 | die;
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | public function CharNameToGuid($name)
|
---|
259 | {
|
---|
260 | global $System, $Config;
|
---|
261 |
|
---|
262 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
263 | $row = $Realm->CharactersDatabase->query('SELECT `guid` FROM `characters` WHERE `name` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
|
---|
264 | if($row['guid'] != '')
|
---|
265 | {
|
---|
266 | return($row['guid']);
|
---|
267 | } else
|
---|
268 | {
|
---|
269 | return('Nenalezen');
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | public function GuidToCharName($guid)
|
---|
274 | {
|
---|
275 | global $Config;
|
---|
276 |
|
---|
277 | $Realm = new Realm($System, $_COOKIE['RealmIndex']);
|
---|
278 | $row = $Realm->CharactersDatabase->query('SELECT `name` FROM `characters` WHERE `guid` = "'.$guid.'" LIMIT 1;')->fetch_assoc();
|
---|
279 | if($row['name'] != '')
|
---|
280 | {
|
---|
281 | return($row['name']);
|
---|
282 | } else
|
---|
283 | {
|
---|
284 | return('Nenalezen');
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | public function AccNameToGuid($name)
|
---|
289 | {
|
---|
290 | global $Config;
|
---|
291 |
|
---|
292 | $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
|
---|
293 | $row = $this->db->query('SELECT `id` FROM `account` WHERE `username` LIKE "'.$name.'" LIMIT 1;')->fetch_assoc();
|
---|
294 | //return($row['id']);
|
---|
295 | if($row['id'] != '')
|
---|
296 | {
|
---|
297 | return($row['id']);
|
---|
298 | } else
|
---|
299 | {
|
---|
300 | return('Nenalezen');
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | public function MoveChar($acc1_name, $acc1_pass, $acc2_name, $char_name)
|
---|
305 | {
|
---|
306 | global $Config;
|
---|
307 |
|
---|
308 | $this->db->select_db($Config['Mangos']['DatabaseRealmd']);
|
---|
309 | $sha_pass = sha1(strtoupper($acc1_name).':'.strtoupper($acc1_pass));
|
---|
310 | $sql = $this->db->query('SELECT `id` FROM `account` WHERE `username`="'.$acc1_name.'" AND `sha_pass_hash`="'.$sha_pass.'"');
|
---|
311 | if($sql->num_rows == 1)
|
---|
312 | {
|
---|
313 | $acc1_guid = $this->AccNameToGuid($acc1_name);
|
---|
314 | $acc2_guid = $this->AccNameToGuid($acc2_name);
|
---|
315 | $char_guid = $this->CharNameToGuid($char_name);
|
---|
316 | if($this->CharInAcc($char_guid, $acc1_guid))
|
---|
317 | {
|
---|
318 | $this->db->query('UPDATE `characters` SET `account` = "'.$acc2_guid.'" WHERE `guid` ="'.$char_guid.'" LIMIT 1');
|
---|
319 | $this->Msg('Postava přemístěna.', 0);
|
---|
320 | } else
|
---|
321 | {
|
---|
322 | $this->Msg('Tato postava není vaše.', 1);
|
---|
323 | }
|
---|
324 | }
|
---|
325 | }
|
---|
326 |
|
---|
327 | public function CharsOnAcc($accid)
|
---|
328 | {
|
---|
329 | global $Config, $System, $html;
|
---|
330 |
|
---|
331 | $DbResult = $System->Database->query('SELECT Name,Id FROM Realm WHERE Enabled=1');
|
---|
332 | while($DbRealm = $DbResult->fetch_array())
|
---|
333 | {
|
---|
334 | echo('<div>'.$DbRealm['Name'].'</div>');
|
---|
335 | echo('<table class="BaseTable">
|
---|
336 | <tr>
|
---|
337 | <th>Jméno</th>
|
---|
338 | <th>Úroveň</th>
|
---|
339 | <th>Rasa</th>
|
---|
340 | <th>Třída</th>
|
---|
341 | <th>Nahráno</th>
|
---|
342 | </tr>');
|
---|
343 | $Realm = new Realm($System, $DbRealm['Id']);
|
---|
344 | $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');
|
---|
345 | while($row = $sql->fetch_array())
|
---|
346 | {
|
---|
347 | $gender = ($row['gender'] == 0) ? '0' : '1';
|
---|
348 | echo('<tr>'.
|
---|
349 | '<td>'.$row['name'].'</td>'.
|
---|
350 | '<td>'.$this->GetPlayerLvl($row['guid'], $DbRealm['Id']).'</td>'.
|
---|
351 | '<td><img src="'.$html->Link('/imgs/icons/'.$row['race'].'-'.$gender.'.gif').'" alt="rasa" /></td>'.
|
---|
352 | '<td><img src="'.$html->Link('/imgs/icons/'.$row['class'].'.gif').'" alt="trida" /></td>'.
|
---|
353 | '<td>'.round($row['totaltime'] / 3600).' h</td>'.
|
---|
354 | '</tr>');
|
---|
355 | }
|
---|
356 | echo('</table>');
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | ?>
|
---|