source: trunk/inc/player.php@ 510

Last change on this file since 510 was 510, checked in by barny, 16 years ago
File size: 15.7 KB
Line 
1<?php
2
3class Player {
4 var $SessionTimeout = 30;
5 private $db;
6 // -- done
7 function __construct ($db)
8 {
9 $this -> db = &$db;
10 }
11 // -- done
12 private function Msg($text,$err)
13 {
14 if ($err == 0)
15 {
16 echo "<img src=\"imgs/inc/on.gif\">&nbsp;<font color=\"#234303\" size=\"4\">".$text."</font><br />";
17 }
18 else
19 {
20 echo "<img src=\"imgs/inc/off.gif\">&nbsp;<font color=\"#990000\" size=\"4\">".$text."</font><br />";
21 }
22 }
23 // -- err
24 public function Register ($acc_name , $pass , $email , $tbc)
25 { include("inc/db.php");
26 $this -> db -> select_db($db_realmd);
27 $find = $this -> db -> query("SELECT `id` FROM `account` WHERE `username` = '".$acc_name."';");
28 if ($find -> num_rows == 0)
29 {
30 $sha_pass = sha1(strtoupper($acc_name).":".strtoupper($pass));
31 $sql = $this -> db -> query("
32 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 ");
35 $this -> Msg ("Účet založen úspěšně",0);
36 echo "<meta http-equiv=\"refresh\" content=\"0;?page=acc\">";
37 }
38 else
39 {
40 $this -> Msg ("Zadané jmnéno účtu již existuje",1);
41 $this -> Recall(3);
42 }
43
44 }
45 // -- done
46 public function Login ($username,$pass)
47 {
48 include("inc/db.php");
49 $this -> db -> select_db($db_realmd);
50 $sha_pass = sha1(strtoupper($username).":".strtoupper($pass));
51 $sql = $this -> db -> query("SELECT `id` FROM `account` WHERE `account`.`username`='".$username."' AND `account`.`sha_pass_hash`='".$sha_pass."'");
52 if ($sql -> num_rows == 1)
53 {
54 $row = $sql -> fetch_array();
55 $_SESSION["UserId"] = $row["id"];
56 $_SESSION["UserName"] = $username;
57 $this -> Msg ("Přihlášení úspěšné",0);
58 $this -> Recall(1);
59 }
60 else
61 {
62 $this -> Msg ("Přihlášení neúspěšné",1);
63 $this -> Recall(3);
64 }
65 }
66 // -- done
67 public function Logout ()
68 {
69 $_SESSION["UserId"] = 0;
70 $_SESSION["UserName"] = "";
71 $this -> Msg ("Odhlášení úspěšné",0);
72 $this -> Recall(1);
73 }
74 // -- done
75 public function Check ()
76 {
77 if(!array_key_exists("Time", $_SESSION)) $_SESSION['Time'] = time();
78 if(!array_key_exists("UserId", $_SESSION)) $_SESSION['UserId'] = 0;
79 if($_SESSION["Time"] < (time() - 60 * $this -> SessionTimeout))
80 {
81 $this -> Logout();
82 }
83 $_SESSION["Time"] = time();
84 return($_SESSION["UserId"] != 0);
85 }
86 // -- done
87 public function LoginForm()
88 {
89 echo "
90 <form method=\"post\" action=\"?page=acc\">
91 <table>
92 <tr>
93 <td><b>Jméno : </b></td><td><input type=\"text\" name=\"user\"></td>
94 </tr>
95 <tr>
96 <td><b>Heslo : </b></td><td><input type=\"password\" name=\"pass\" autocomplete=\"off\"></td>
97 </tr>
98 <tr>
99 <td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Příhlásit\" name=\"login\"></td>
100 </tr>
101 </table>
102 </form>
103 <div align=\"left\">
104 <a href=\"?page=register\">Registrace</a><br /><a href=\"?page=lostpass\">Obnova hesla</a>
105 </div>
106 ";
107 }
108 // --
109 public function GetPlayerLvl ($guid)
110 {
111 include("inc/db.php");
112 // $this -> NumCheck($guid);
113 $this -> db -> select_db($db_characters);
114 $row = $this -> db -> query("SELECT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', 34), ' ', -1) AS UNSIGNED) AS `level` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
115 return $row["level"];
116 }
117 // -- done
118 public function GetGmLvl ()
119 {
120 include("inc/db.php");
121 // $this -> NumCheck($guid);
122 $this -> db -> select_db($db_realmd);
123 $row = $this -> db -> query("SELECT `gmlevel` FROM `account` WHERE `id` = '".$_SESSION["UserId"]."' LIMIT 1;") -> fetch_array();
124 return $row["gmlevel"];
125 }
126 // -- done
127 public function GetPlayerClass($id)
128 {
129 switch ($id)
130 {
131 case 1:
132 return("warrior");
133 break;
134 case 2:
135 return("paladin");
136 break;
137 case 3:
138 return("hunter");
139 break;
140 case 4:
141 return("rogue");
142 break;
143 case 5:
144 return("priest");
145 break;
146 case 7:
147 return("shaman");
148 break;
149 case 8:
150 return("mage");
151 break;
152 case 9:
153 return("warlock");
154 break;
155 case 11:
156 return("druid");
157 break;
158 default:
159 return("unknown");
160 }
161 }
162 // -- done
163 public function GetPlayerRace($id)
164 {
165 switch ($id)
166 {
167 case 1:
168 return("human");
169 break;
170 case 2:
171 return("orc");
172 break;
173 case 3:
174 return("dwarf");
175 break;
176 case 4:
177 return("nightelf");
178 break;
179 case 5:
180 return("undead");
181 break;
182 case 6:
183 return("tauren");
184 break;
185 case 7:
186 return("gnome");
187 break;
188 case 8:
189 return("troll");
190 break;
191 case 9:
192 return("goblin");
193 break;
194 case 10:
195 return("bloodelf");
196 break;
197 case 11:
198 return("draenei");
199 break;
200 default:
201 return("unknown");
202 }
203 }
204 // -- done
205 public function ResetXP ($guid)
206 {
207 if ($this -> CharInAcc($guid,0))
208 {
209 if (!$this -> IsOnline($guid))
210 {
211 include("inc/db.php");
212 $this -> db -> select_db($db_characters);
213 $row = $this -> db -> query("SELECT `data` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
214 $data = explode(" ",$row["data"]);
215 $data[926] = 0;
216 $this -> db -> query("UPDATE `characters` SET `data` = '".implode(" ",$data)."' WHERE `guid` ='".$guid."' LIMIT 1");
217 $this -> Msg ("Postavě resetováno XP.",0);
218 }
219 else
220 {$this -> Msg ("Postava musí být offline.",1);}
221 }
222 else
223 {$this -> Msg ("Tato postava není vaše.",1);}
224 }
225 // -- done
226 public function ResetPosition ($guid)
227 {
228 if ($this -> CharInAcc($guid,0))
229 {
230 if (!$this -> IsOnline($guid))
231 {
232 include("inc/db.php");
233 $this -> db -> select_db($db_characters);
234 $row = $this -> db -> query("SELECT * FROM `character_homebind` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
235 $home_char_map = $row["map"];
236 $home_char_position_x = $row["position_x"];
237 $home_char_position_y = $row["position_y"];
238 $home_char_position_z = $row["position_z"];
239 if (isset($home_char_map) AND isset ($home_char_position_x) AND isset ($home_char_position_y) AND isset ($home_char_position_z))
240 {
241 $this -> db -> query("UPDATE `characters` SET
242 `map` = '".$home_char_map."' ,
243 `position_x` ='".$home_char_position_x."' ,
244 `position_y` = '".$home_char_position_y."' ,
245 `position_z` = '".$home_char_position_z."'
246 WHERE `guid` ='".$guid."' LIMIT 1;");
247 $this -> Msg ("Postava teleportována.",0);
248 }
249 }
250 else
251 {$this -> Msg ("Postava musí být offline.",1);}
252 }
253 else
254 {$this -> Msg ("Tato postava není vaše.",1);}
255 }
256 public function PlayerJail ($guid)
257 {
258 // .go xyz -90.54 41.35 -31.71
259 // .go xyz -91.01 100.46 -31.71
260 // .go xyz -119.16 71.82 -31.71
261 $defined_positions = array (
262 "x1" => "-90.54",
263 "y1" => "41.35",
264 "z1" => "-31.71",
265 "o1" => "1.4623",
266
267 "x2" => "-91.01",
268 "y2" => "100.46",
269 "z2" => "-31.71",
270 "o3" => "4.6282",
271
272 "x3" => "-119.16",
273 "y3" => "71.82",
274 "z3" => "-31.71",
275 "o3" => "6.2116",
276 );
277 $rand_place = rand (1,3);
278 if (!$this -> IsOnline($guid))
279 {
280 include("inc/db.php");
281 $this -> db -> select_db($db_characters);
282 $this -> db -> query("UPDATE `characters` SET
283 `map` = '35' ,
284 `orientation` = '".$defined_positions["o".$rand_place]."' ,
285 `position_x` ='".$defined_positions["x".$rand_place]."' ,
286 `position_y` = '".$defined_positions["y".$rand_place]."' ,
287 `position_z` = '".$defined_positions["z".$rand_place]."'
288 WHERE `guid` ='".$guid."' LIMIT 1;");
289 $this -> db -> query("INSERT INTO `character_aura` (`guid`, `caster_guid`, `spell`, `effect_index`, `amount`, `maxduration`, `remaintime`, `remaincharges`) VALUES
290 (".$guid.", ".$guid.", 23775, 0, 1, -1, -1, -1),
291 (".$guid.", ".$guid.", 36558, 0, 1, -1, -1, -1);");
292
293 $this -> Msg ("Postava ve vězení.",0);
294
295 }
296 else
297 {$this -> Msg ("Postava musí být offline.",1);}
298
299
300 }
301 // -- done
302 public function IsOnline ($guid)
303 {
304 include("inc/db.php");
305 $this -> db -> select_db($db_characters);
306 $row = $this -> db -> query("SELECT `online` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
307 if ($row["online"] == 1)
308 {return true;}
309 else
310 {return false;}
311 }
312 // --
313 public function CharInAcc ($char,$acc)
314 {
315 if ($this -> Check())
316 {
317 include("inc/db.php");
318 if ($acc == 0)
319 {$acc = $_SESSION["UserId"];}
320 $this -> db -> select_db($db_characters);
321 if ($this -> db -> query("SELECT `guid` FROM `characters` WHERE `characters`.`guid`='".$char."' AND `characters`.`account`='".$acc."' LIMIT 1;") -> num_rows == 1)
322 {return true;}
323 else
324 {return false;}
325 }
326 else
327 {
328 $this -> Msg ("Nejste přihlášen",1);
329 die;
330 }
331 }
332 // --
333 public function CharNameToGuid ($name)
334 {
335 include("inc/db.php");
336 $this -> db -> select_db($db_characters);
337 $row = $this -> db -> query("SELECT `guid` FROM `characters` WHERE `name` LIKE '".$name."' LIMIT 1;") -> fetch_array();
338 if ($row["guid"] != "")
339 {
340 return $row["guid"];
341 }
342 else
343 {
344 return "Nenalezen";
345 }
346
347 }
348 // --
349 public function GuidToCharName ($guid)
350 {
351 include("inc/db.php");
352 $this -> db -> select_db($db_characters);
353 $row = $this -> db -> query("SELECT `name` FROM `characters` WHERE `guid` = '".$guid."' LIMIT 1;") -> fetch_array();
354 if ($row["name"] != "")
355 {
356 return $row["name"];
357 }
358 else
359 {
360 return "Nenalezen";
361 }
362
363 }
364 // --
365 public function AccNameToGuid ($name)
366 {
367 include("inc/db.php");
368 $this -> db -> select_db($db_realmd);
369 $row = $this -> db -> query("SELECT `id` FROM `account` WHERE `username` LIKE '".$name."' LIMIT 1;") -> fetch_array();
370 return $row["id"];
371 if ($row["id"] != "")
372 {
373 return $row["id"];
374 }
375 else
376 {
377 return "Nenalezen";
378 }
379 }
380 // --
381 public function MoveChar($acc1_name,$acc1_pass,$acc2_name,$char_name)
382 {
383 include("inc/db.php");
384 $this -> db -> select_db($db_realmd);
385 $sha_pass = sha1(strtoupper($acc1_name).":".strtoupper($acc1_pass));
386 $sql = $this -> db -> query("SELECT `id` FROM `account` WHERE `account`.`username`='".$acc1_name."' AND `account`.`sha_pass_hash`='".$sha_pass."'");
387 if ($sql -> num_rows == 1)
388 {
389 $acc1_guid = $this -> AccNameToGuid($acc1_name);
390 $acc2_guid = $this -> AccNameToGuid($acc2_name);
391 $char_guid = $this -> CharNameToGuid($char_name);
392 if ($this -> CharInAcc($char_guid,$acc1_guid))
393 {
394 $this -> db -> select_db("realm1_characters");
395 $this -> db -> query("UPDATE `characters` SET `account` = '".$acc2_guid."' WHERE `guid` ='".$char_guid."' LIMIT 1;");
396 $this -> Msg ("Postava přemístěna.",0);
397 }
398 else
399 {
400 $this -> Msg ("Tato postava není vaše.",1);
401 }
402 }
403 }
404 // --
405 public function Recall($time)
406 {
407 if (isset($_SERVER["HTTP_REFERER"]))
408 {
409 $link = parse_url($_SERVER["HTTP_REFERER"]);
410 if ($link["host"] == "wow.zdechov.net" OR $link["host"] == "localhost")
411 {
412 echo "<meta http-equiv=\"refresh\" content=\"".$time.";?".$link["query"]."\">";
413 }
414 else
415 {
416 echo "<meta http-equiv=\"refresh\" content=\"".$time.";\">";
417 }
418 }
419 }
420 // --
421 // done
422 public function CharsOnAcc ($accid)
423 {
424 include("inc/db.php");
425 echo "
426 <table>
427 <tr>
428 <th align=\"center\">Jméno</th>
429 <th align=\"center\">Úroveň</th>
430 <th align=\"center\">Rasa</th>
431 <th align=\"center\">Class</th>
432 <th align=\"center\">Nahráno</th>
433 </tr>
434 ";
435 $this -> db -> select_db($db_characters);
436 $sql = $this -> db -> query("SELECT `guid`,`name`,`race`,`totaltime`,`class`,mid(lpad( hex( CAST(substring_index(substring_index(data,' ',37),' ',-1) as unsigned) ),8,'0'),4,1) AS gender FROM `characters` WHERE `characters`.`account`='".$accid."' ORDER BY `totaltime` DESC LIMIT 0,10;");
437 while ($row = $sql -> fetch_array())
438 {
439 $gender = ($row["gender"] == 0)?"m":"f";
440 echo "
441 <tr>
442 <td align=\"center\">".$row["name"]."</td>
443 <td align=\"center\">".$this -> GetPlayerLvl($row["guid"])."</td>
444 <td align=\"center\"><img src=\"imgs/icons/".$this -> GetPlayerRace($row["race"])."-".$gender.".gif\"></td>
445 <td align=\"center\"><img src=\"imgs/icons/".$this -> GetPlayerClass($row["class"]).".gif\"></td>
446 <td align=\"center\">".round($row["totaltime"]/3600)." h</td>
447 </tr>
448 ";
449 }
450 echo "</table>";
451 }
452 // --
453 // prihlaseni se ke generaci signatury
454 public function SignatureOn ($guid)
455 {
456 $this -> db -> select_db($db_webu);
457 }
458 // lol
459 private function NumCheck ($number)
460 {
461 if (!is_numeric($number))
462 {
463 die("Input Error");
464 }
465 }
466}
467?>
Note: See TracBrowser for help on using the repository browser.