-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmt2-api.php
More file actions
974 lines (911 loc) · 24.2 KB
/
mt2-api.php
File metadata and controls
974 lines (911 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
<?php
/*
* metin2 database API by xenor (576-772)
* visit our server at http://www.xtreamyt2.org
* please report bugs to me (576-772 on ICQ)
* check http://www.elitepvpers.de
*/
/*##b##*/
if(!defined("MT2API_BUILD")) define("MT2API_BUILD",42);
define("MT2API_VERSION","0.3.1-".MT2API_BUILD);
#! Patches f�r Windows Funktionen unter Linux/FreeBSD
if(!function_exists("parse_ini_string"))
{
function parse_ini_string($string)
{
$tmp = explode("\n",$string);
$return = array();
foreach($tmp as $line)
{
if(trim($line)!="")
{
$key = trim(substr($line,0,strpos($line,"=")));
$val = trim(substr($line,strpos($line,"=")+3));
$val = substr($val,0,strlen($val)-1);
$return[$key] = $val;
}
}
return $return;
}
}
class Mt2
{
#! private
private $mysql_link;
private $debug = false;
private $dry = false;
private $itemproto;
private $account = "account";
private $common = "common";
private $player = "player";
private $db_host = "localhost";
private $db_user = "root";
private $db_passwd = "";
private $from_header = "idontuseaconfigfile@crapcode.lifefight.de";
private $mail_subject = "mt2api-driven server";
private $mail_content = "<html><body>Hallo %username%<br/>Bitte klicke auf den folgenden Link, um deinen Account zu aktivieren: %link%<br/>MfG dein Servername-Team</body></html>";
private $mail_linktxt = "Account aktivieren";
private $mail_hash_paramname = "hash";
private $mail_acc_paramname = "acc_id";
private $mail_activationfilename = "/activate.php";
private $locale;
private $mods = array();
private $verifyMods = false;
private $itemshop;
public function __construct($host="localhost",$user="root",$pw="")#! Konstruiert die API
{
echo "<!--\nMt2 API by xenor\nVisit us at http://www.xtreamyt2.org\nVersion: ".MT2API_VERSION."\nBUILD: ".MT2API_BUILD."\n-->\n";
$this->itemproto = include("itemproto.api.php");
$this->locale = include("locale.api.php");
#! Mods einbinden und erlauben die Mt2-Klasse zu ver�ndern
$cwd = getcwd();#! Liest das aktuelle Verzeichnis aus
if(file_exists($cwd."/mods") && is_dir($cwd."/mods"))#! Falls das Verzeichnis existiert
{
$files = scandir($cwd."/mods");#! Lies jede Datei aus
$api = &$this;
foreach($files as $val)#! F�r alle Dateien...
{
$filename = $cwd."/mods/".$val;#! Dateiname
if(is_file($filename))#! Wenns eine Datei ist
{
include("mods/".$val);#! Binde sie ein
}
}
$api = null;
}
$this->db_host = $host;
$this->db_user = $user;
$this->db_passwd = $pw;
}
public function __init()
{
$this->mysql_link = mysql_connect($this->db_host,$this->db_user,$this->db_passwd);
if($this->mysql_link)
{
return true;
}
else
{
return false;
}
}
#! functions
public function say($a)#! Gibt den Text aus
{
echo str_replace("\n","<br />",str_replace(" "," ",print_r($a,true))),"\r\n";
}
private function log($str)#! Gibt als Log aus
{
if($this->debug === true)
{
$this->say($str);
}
}
private function checkItem($data,&$lager)#! Sub Routine zum erstellen des Inventar-Arrays
{
$lager[$data->pos] = $data->vnum;
//$size = $this->itemproto[$data->vnum]["size"];
$size = $this->select("size","player.item_proto","vnum=".$data->vnum);
$size = $size[0]->size;
if($size > 1)
{
$lager[($data->pos+5)] = $data->vnum;
}
if($size > 2)
{
$lager[($data->pos+10)] = $data->vnum;
}
return $lager;
}
public function getFreePosition($window,$owner_id,$size)#! Gibt die n�chste freie Inventar Position f�r die angegebene Gr��e zur�ck
{
$lager = array();
$sql = "SELECT * FROM ".$this->player.".item WHERE window = '".$window."' AND owner_id = '".$owner_id."'";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0)
{
return "0";
}
while($data = mysql_fetch_object($q))
{
$lager = $this->checkItem($data,$lager);
}
$end=50;
$end-=($size*5);
for($i=0;$i<$end;$i++)
{
if(!isset($lager[$i]))
{
if($size == 1)
{
return $i;
}
elseif($size == 2)
{
if(!isset($lager[($i+5)]))
{
return $i;
}
}
elseif($size == 3)
{
if(!isset($lager[($i+5)]) && !isset($lager[($i+10)]))
{
return $i;
}
}
else
{
throw new Exception('getFreePosition: $size overflow');
}
}
}
return false;
}
private function checkEmailFormat($email)#! �berpr�ft das Format der E-Mail-Adresse
{
if(strpos($email,".") === false) return false;
if(strpos($email,"@") === false) return false;
return true;
}
private function generateValidationHash($email)
{
$hash1 = md5($email);
$hash2 = md5(microtime());
$hash3 = $hash1.$hash2.sha1($hash1.$hash2);
return $hash3;
}
private function sendMail($from,$to,$subject,$content)
{
return mail($to,$subject,$content,'From: '.$from."\r\n".'Content-Type: text/html; charset="UTF-8"');
}
private function encrypt($content,$key)
{
$result = "";
for($i = 0; $i < strlen($content); $i++)
{
$char = $content{$i};
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char) + ord($keychar));
$result .= $char;
}
return base64_encode($result);
}
private function decrypt($content,$key)
{
$result = "";
$content = base64_decode($content);
for($i = 0; $i < strlen($content); $i++)
{
$char = $content{$i};
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char) - ord($keychar));
$result .= $char;
}
return $result;
}
#! public functions
public function setDebug($bool)#! Setzt den Debug-Modus der API auf true oder false
{
if($bool === true || $bool === false)
{
$this->log("Going to debug mode...");
$this->debug = $bool;
return true;
}
else
{
return false;
}
}
public function setDry($bool)#! Setzt den Trockendock-Modus der API auf true oder false
{
if($bool === true || $bool === false)
{
$this->log("Aktiviere Trockendock-Modus...");
$this->dry = $bool;
return true;
}
else
{
return false;
}
}
public function updateGMIP($playerName,$ip)#! Aktualisiert die GM Rechte eines GMs
{
$sql = "UPDATE ".$this->common.".gmlist SET mContactIP = '".$ip."' WHERE mName = ".$playerName." LIMIT 1";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
if(mysql_query($sql))
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
}
public function makeGM($playerID,$ip,$auth,$prefix = "")#! Macht den Charakter mit der gegebenen Player ID zum GM der gegebenen Stufe
{
$sql = "SELECT name, account_id FROM ".$this->player.".player WHERE id = '".$playerID."'";
$q = mysql_query($sql);
$player = mysql_fetch_object($q);
$this->log($player);
if($prefix != "")
{
$sql = "UPDATE ".$this->player.".player SET name = '".$prefix.$player->name."' WHERE id = '".$playerID."' LIMIT 1";
$this->log("MySQL Query: " . $sql); if($this->dry == false) mysql_query($sql);
}
$sql = "SELECT login FROM ".$this->account.".account WHERE id= '".$player->account_id."' LIMIT 1";
$q = mysql_query($sql);
$tmp = mysql_fetch_object($q);
if($tmp == false) die("Datenbankfehler #1");
$login = $tmp->login;
$tmp = null;
$sql = "INSERT INTO ".$this->common.".gmlist (`mID`,`mAccount`,`mName`,`mContactIP`,`mServerIP`,`mAuthority`) VALUES (NULL, '".$login."','".$player->name."','".$ip."','ALL','".$auth."');";
$this->log("MySQL Query: " . $sql);
if($this->dry == false)
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
public function addAccount($a,$check = false)#! F�gt einen Account hinzu und gibt bei Erfolg die Account ID zur�ck
{
$this->log($a);
$fields = "";
$values = "";
foreach($a as $key => $val)
{
if($check === true) $val = mysql_real_escape_string($val);
$fields .= "`".$key."`, ";
if($key == "password")
{
$values .= "PASSWORD('".$val."'), ";
}
else
{
$values .= "'".$val."', ";
}
}
$fields = substr($fields, 0,strlen($fields) - 2);
$values = substr($values, 0,strlen($values) - 2);
$sql = "INSERT INTO ".$this->account.".account (".$fields.") VALUES (".$values.");";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return $hash;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
return mysql_insert_id();
}
public function addItem($accountID,$vnum,$a = array())#! F�gt dem gegebenen Spieler bzw. Account ein Item hinzu und gibt den Erfolg zur�ck
{
if(is_array($vnum))
{
$vnum = array_rand($vnum);
}
$accountID = intval($accountID);
$a["owner_id"] = $accountID;
$a["vnum"] = $vnum;
if(empty($a["window"]))
{
$a["window"] = "MALL";
}
if(empty($a["count"])) $a["count"] = "1";
$sql = "SELECT type FROM ".$this->player.".item_proto WHERE vnum = '".$vnum."'";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 1)
{
$size = $this->itemproto[$vnum]["size"];
$pos = $this->getFreePosition($a["window"],$a["owner_id"],$size);
if($pos === false)
{
throw new Exception($this->locale->ERR_SAFEBOX_FULL);
return false;
}
$a["pos"] = $pos;
$fields = "";
$values = "";
foreach($a as $key => $val)
{
$fields .= "`".$key."`, ";
$values .= "'".$val."', ";
}
$fields = substr($fields, 0,strlen($fields) - 2);
$values = substr($values, 0,strlen($values) - 2);
$sql = "INSERT INTO ".$this->player.".item (".$fields.") VALUES (".$values.");";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
return true;
}
else
{
throw new Exception($this->locale->ERR_ITEM_NOT_FOUND);
return false;
}
return true;
}
public function isBanned($accountID)#! Gibt zur�ck ob der gegebene Account gebannt ist
{
$sql = "SELECT * FROM ".$this->account.".account WHERE id = '".$account_id."'";
$q = mysql_query($sql);
if(mysql_num_rows($q))
{
throw new Exception($this->locale->ERR_ACCOUNT_NOT_FOUND);
return false; #! Account nicht gefunden
}
$data = mysql_fetch_object($q);
if($data["status"] == "OK") return false;
if($data["status"] == "BLOCK") return true;
}
public function banAccount($accountID)#! Bannt den gegebenen Account und gibt den Erfolg zur�ck
{
$sql = "UPDATEUPDATE ".$this->account.".account SET status = 'BLOCK' WHERE id = '".$accountID."'";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
else
{
#! Erfolgreich gebannt
return true;
}
}
public function unbanAccount($accountID)#! Entbannt den gegebenen Account und gibt den Erfolg zur�ck
{
$sql = "UPDATE ".$this->account.".account SET status = 'OK' WHERE id = '".$accountID."'";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
else
{
#! Erfolreich entbannt
return true;
}
}
public function debugCharacter($playerID,$a)#! Entbuggt den Charakter mit der gegebenen ID, es muss ein array mit den daten �bergeben werden
{
$x = $a["x"];
$y = $a["y"];
$map = $a["map"];
$sql = "UPDATE ".$this->player.".player SET x = '".$x."', y = '".$y."', map_index = '".$map."', exit_x = '".$x."', exit_y = '".$y."', exit_map_index = '".$map."' WHERE id = '".$playerID."'";
$this->log("MySQL Query: ".$sql);
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
else
{
return true;#! Erfolgreich entbuggt
}
}
public function loadConfigString($str)
{
$tmp = parse_ini_string($str);#! Parst den String als config
foreach($tmp as $key => $val)
{
$this->$key = $val;#! Setzt den Key in der Config
}
}
public function loadConfigFile($configFileName = "config.xml")#! L�dt die in einem Config-File gespeicherten
{
$rootnode = simplexml_load_file($configFileName);
foreach($rootnode->children() as $key => $val)
{
if($key == "option")
{
$this->log("found option: ".$val->name." => ".$val->value);
}
elseif($key == "itemshop")
{
$this->log("found itemshop; parsing...");
$itemshop = &$val;
unset($val);
$cat_id = 0;
foreach($itemshop->children() as $category)
{
$cat_id++;
$cat_name = (string)$category->attributes()->name[0];
$items = array();
foreach($category->children() as $item)
{
$key = $item->attributes();
$key = (int)(string)$key->id[0];
$items[$key] = (object) array(
"id" => (string)$key,
"name" => (string)$item->{'name'},
"picture" => (string)$item->{'picture'},
"vnum" => (string)$item->{'vnum'},
"money" => (string)$item->{'money'},
"desc" => (string)$item->{'desc'},
);
}
$this->itemshop[$cat_id] = (object) array(
"name" => $cat_name,
"items" => $items,
);
}
}
}
@mysql_close($this->mysql_link);#! Schlie�t die aktuelle Datenbankverbindung
$this->mysql_link = mysql_connect(
$this->db_host,
$this->db_user,
$this->db_passwd
);#! �ffnet die Verbindung neu, da Daten ge�ndert wurden
return true;
}
public function checkForUpdates()#! Sucht nach Updates und gibt den Erfolg zur�ck
{
$build = constant("MT2API_BUILD");
$content = file_get_contents("http://crapcode.lifefight.de/mt2-api/LATEST");
$cmd = explode("\n",$content);
$newbuild = $cmd[0];
if($newbuild == $build)
{
return false;#! der gleiche build
}
elseif($newbuild > $build)
{
$version = $cmd[1];
return intval($newbuild);#! Gibt den neusten Build zur�ck
}
else
{
return false;#! Neuer Build < als der aktuelle
}
}
public function installUpdate($build)#! Updated die API auf die gegebene Version
{
$files = explode("\n",file_get_contents("http://crapcode.lifefight.de/mt2-api/$build/FILES"));
$this->log("Updating from Build #".MT2API_BUILD." to Build #$build<br />\n");
foreach($files as $key => $tmp)
{
$data = explode('!',$tmp);
$md5 = md5_file(getcwd()."/".$data[0]);
$this->log("Local File Hash (".$data[0]."): ".$md5."<br />\n");
if($data[1] != $md5)
{
$this->log("Updating File ".$data[0]."...");
$content = "<?php\n".file_get_contents("http://crapcode.lifefight.de/mt2-api/$build/".$data[0].".raw")."\n?>";
file_put_contents(getcwd()."/".$data[0],$content);#!Updatet die Datei
$this->log("Done.<br />\n");
}
else
{
$this->log("Skipping File ".$data[0].": Same MD5 ($md5)<br />\n");
}
}
$this->log("Update zu Build #".$build." ausgef�hrt.<br />\n");
return true;#! immer true zur�ckgeben
}
public function checkAccountFormat($account)#! Pr�ft ob der Accountname den Anforderungen entspricht
{
if(strlen($account) < 3 || strlen($account) > 20) return false; else return true;
}
public function checkAccountName($account,$check = true)#! Pr�ft ob der Login bereits vergeben ist und gibt den true zur�ck wenn er frei ist
{
if($check == true)
{
$account = mysql_real_escape_string($account);#! Maskiert die Eingabe
}
$sql = "SELECT login FROM ".$this->account.".account WHERE login = '".$account."' LIMIT 1";
if(mysql_num_rows(mysql_query($sql)) == 0)
{
return true;#! Account name ist frei
}
else
{
#! throw new Exception($this->locale->ERR_GIVEN_LOGIN);
return false;
}
}
public function checkPw1($passwd)#! Pr�ft ob das gegebene Passwort den Anforderungen entspricht
{
if(strlen($passwd) < 6)#! k�rzer als 6 zeichen
{
#! throw new Exception($this->locale->ERR_PW_TOO_SHORT);
return false;
}
if(strlen($passwd) > 24)#! l�nger als 16 zeichen
{
#! throw new Exception($this->locale->ERR_PW_TOO_LONG);
return false;
}
return true;#! Passwort entspricht den Anforderungen
}
public function checkPw2($pw1, $pw2)#! Pr�ft ob die Passw�rter �bereinstimmen
{
if($pw1 != $pw2)
{
#! throw new Exception($this->locale->ERR_PWS_NOT_MATCH);
return false;
}
elseif($pw1 == $pw2)
{
return true;#! Passw�rter stimmen �berein
}
}
public function checkEMail($email,$check = true)#! Pr�ft ob die E-Mail-Adresse bereits vergeben ist
{
if(!$this->checkEmailFormat($email))#! �berpr�ft das Format der Adresse
{
return false;
}
if($check == true)
{
$email = mysql_real_escape_string($email);#! Maskiert die Eingabe
}
$sql = "SELECT login FROM ".$this->account.".account WHERE email = '".$email."' LIMIT 1";
if(mysql_num_rows(mysql_query($sql)) == 0)
{
return true;#! E-Mail ist frei
}
else
{
#! throw new Exception($this->locale->ERR_GIVEN_EMAIL);
return false;
}
}
public function sendValidationEmail($email,$accID,$check = true)#! Schickt eine Registrierungs-E-Mail an die gegebene Adresse
{
$hash = $this->generateValidationHash($email);#! Generiert einen neuen Hash
$activate = $this->mail_activationfilename."?".$this->mail_hash_paramname."=".$hash."&".$this->mail_acc_paramname."=".$accID;
$link = '<a href="http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']).$activate.'">'.$this->mail_linktxt.'</a>';
$this->log("Using Hash: $hash<br/>\n");#! Logge das
if($check == true)
{
$accID = intval($accID);#! Maskiert die Eingabe
}
$sql = "SELECT login FROM ".$this->account.".account WHERE id = '".$accID."' LIMIT 1";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0)
{
throw new Exception($this->locale->ERR_ACCOUNT_NOT_FOUND);
}
$data = mysql_fetch_object($q);
$login = $data->login;#! Das war der Login
$this->sendMail(
$this->from_header,
$email,
$this->mail_subject,
str_replace("%link%",$link,str_replace("%username%",$login,$this->mail_content))
);#! Sendet die Mail
$sql = "UPDATE ".$this->account.".account SET activation_hash = '".$hash."' WHERE id = '".$accID."'";
if($this->dry == false)#! Schreibt den Hash in die Datenbank
{
$q = mysql_query($sql);
if($q)
{
return $hash;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
}
public function checkHash($accID, $hash)#! �berpr�ft den gegebenen Hash
{
$accID = intval($accID);#! Maskiere die AccountID
$sql = "SELECT activation_hash FROM ".$this->account.".account WHERE id = '".$accID."' LIMIT 1";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0)
{
throw new Exception($this->locale->ERR_ACCOUNT_NOT_FOUND);
return false;
}
$data = mysql_fetch_object($q);
if($data->activation_hash == $hash)
{
return true;#! Wenn die Hashs �bereinstimmen
}
else
{
throw new Exception($this->locale->ERR_WRONG_HASH);
return false;
}
}
public function activateAccount($accID,$check = true)#! Aktiviert den gegebenen Account
{
if($check == true)
{
$accID = intval($accID);#! Maskiert die Eingabe
}
$sql = "UPDATE ".$this->account.".account SET status = 'OK' WHERE id = '".$accID."'";
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
}
public function deactivateAccount($accID,$check = true)#! Deaktiviert den gegebenen Account
{
if($check == true)
{
$accID = intval($accID);#! Maskiert die Eingabe
}
$sql = "UPDATE ".$this->account.".account SET status = 'NOTAVAIL' WHERE id = '".$accID."'";
if($this->dry == false)
{
$q = mysql_query($sql);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
}
public function checkLoginData($login,$passwd)#! �berpr�ft ob der Account existiert und so
{
$login = mysql_real_escape_string($login);
$passwd = mysql_real_escape_string($passwd);
$sql = "SELECT * FROM ".$this->account.".account WHERE login = '".$login."' AND password = PASSWORD('".$passwd."') LIMIT 1";
$q = mysql_query($sql);
if(mysql_num_rows($q) == 0)
{
#!throw new Exception($this->locale->ERR_WRONG_USER_PW);
return false;
}
else
{
return mysql_fetch_object($q);
}
}
public function getData($accID)#!Liefert die Accountdaten der angegebenen ID
{
$sql = "SELECT * FROM ".$this->account.".account WHERE id = '".intval($accID)."'";
$q = mysql_query($sql);
if(mysql_num_rows($q) != 1) return false;
return mysql_fetch_object($q);
}
public function __call($name,$args)#!Intern: checkt ob ein Modul diesen Methodennamen benutzt
{
foreach($this->mods as $key => $val)
{
if(method_exists($val,$name))#! Pr�ft ob die Funktion in den Mods existiert
{
return $val->$name($args);#! Ruft die Funktion auf
}
}
$this->log("Die Funktion $name wurde nicht gefunden. Erweitere die API doch einfach! Gug bei e*pvp wie man Mods schreibt!");
return null;
}
public function registerModule($mod,$data)#!Intern: registriert ein Modul bei der API
{
/*if($this->verifyMods === true)#! Sollen Mods verifiziert werden?
{
$realmd5 = sha1(md5(gettype($mod)));#! Errechne den MD5-Hash
if($data->hash == $realmd5)
{
$this->mods[] = &$mod;#! Installiere die Mod
return true;
}
else
{
throw new Exception("Die Verifizierung des Moduls ".getclass($mod)." schlug fehl.");
return false;
}
}
else*/
{
$this->mods[] = &$mod;#! Installiere die Mod
return true;
}
}
public function getHighscore()#! Liefert den Server highscore sortiert bei level und exp
{
$return = array();
$sql = "SELECT name, level, exp FROM ".$this->player.".player ORDER BY level DESC, exp DESC";
$q = mysql_query($sql);#! Zieht den Highscore vom Server
$i = 0;
while($data = mysql_fetch_object($q))
{
$i++;#! Platz wird um eins erh�ht
$return[$i] = (object) array(
"place" => $i,
"name" => $data->name,
"level" => $data->level,
"exp" => $data->exp,
);
}
return $return;
}
public function update($accID,$table,$a)#! Updatet den angegeben User
{
$str = "UPDATE ".$table." SET ";
foreach($a as $key => $val)
{
$str .= "`".$key."` = ".$val.", ";
}
$str = substr($str,0,strlen($str)-2)." WHERE id = '".intval($accID)."'";
$this->log("mysql:".$str);
if($this->dry == false)
{
$q = mysql_query($str);
if($q)
{
return true;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
}
public function select_raw($sql)
{
$q = mysql_query($sql);
if($q)
{
$ret = array();
while($data = mysql_fetch_object($q))
{
$ret[] = $data;
}
return $ret;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
public function select($fields,$table,$where="")#!Select $fields aus $table, $where
{
$sql = "SELECT $fields FROM $table";
if(!empty($where))
{
$sql .= " WHERE $where";
}
$q = mysql_query($sql);
if($q)
{
$ret = array();
while($data = mysql_fetch_object($q))
{
$ret[] = $data;
}
return $ret;
}
else
{
throw new Exception($this->locale->ERR_MYSQL.": ".mysql_error());
return false;
}
}
public function isIE()#! Gibt zur�ck ob der Besucher der Webseite den Internet Explorer benutzt
{
if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE") !== false)
{
return true;
}
else
{
return false;
}
}
public function itemshop_getCats()#! Gibt ein Array der Itemshop Kategorien zur�ck
{
$cats = array();
foreach($this->itemshop as $key => $val)
{
$cats[$key] = $val->name;
}
return $cats;
}
public function itemshop_getItems($cat)#! Gibt ein Array mit allen Items der Kategorie zur�ck
{
if(isset($this->itemshop[$cat]))
{
return $this->itemshop[$cat]->items;
}
else
{
return array();
}
}
public function itemshop_itemdata($cat,$id)
{
return $this->itemshop[$cat]->items[$id];
}
public function itemshop_get()#!Gibt den Itemshop zur�ck; F�r Profis
{
return $this->itemshop;
}
}
?>