-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.php
1771 lines (1603 loc) · 52.2 KB
/
functions.php
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* All global functions are declared here
* @package Ragnarok Online Control Panel
* @author Andrew Chung
* @copyright 2003 - 2004 Andrew Chung
*/
/**
* @return void
* @param string $login The login name
* @param string $password The password
* @param string $sex M or F as gender
* @param string $email The account's email
* @param string $level The account's gm level
* @param boolean $skip_encrypt Whether or not to apply MD5 Encryption (If MD5 is on)
* @desc Adds the account to the login database. If $CONFIG_use_md5 is true, it will MD5, unless $skip_encrypt is true
*/
function add_account($login, $password, $sex, $email, $level, $skip_encrypt = false) {
// Input the "raw" password, will be encrypted if necessary
// Adds a new account to server
global $CONFIG_server_type, $CONFIG_server_name, $CONFIG_website, $CONFIG_forums_location,
$CONFIG_patch_location, $CONFIG_irc_channel, $CONFIG_cp_location, $CONFIG_use_md5, $lang;
//$original_password = $password; <- What the hell was the point of that???
if ($CONFIG_use_md5 && !$skip_encrypt) {
$password = md5($password);
}
if ($CONFIG_server_type == 0) {
$sex = strtoupper($sex) == "F"? 0 : 1;
// Add to login table
$query = sprintf(ADD_ACCOUNT, $login, $password);
$result = execute_query($query, "functions.php");
// Get last AID added
$query = "SELECT AID FROM nLogin.dbo.login WHERE ID = '$login'";
$result = execute_query($query, "functions.php");
$line = $result->FetchRow();
$register_aid = $line[0];
// Add to account table
$query = sprintf(ADD_ACCOUNT2, $register_aid, $login, $sex, $email);
$result = execute_query($query, "functions.php");
// Insert to user.dbo.t_user
$query = sprintf(INSERT_T_USER, $register_aid, $login, $email, $sex);
$result = execute_query($query, "functions.php");
}
else {
// Add to login table
$query = sprintf(ADD_ACCOUNT, $login, $password, $sex, $email, $level);
$result = execute_query($query, "functions.php");
}
// Inserts the ip, time, as well as account that was registered into register log.
$ip = ip2long($_SERVER['REMOTE_ADDR']);
$query = sprintf(ADD_REGISTER_ENTRY, $login, $ip, $email,$level);
$result = execute_query($query, "functions.php", 0, 0, true);
$message = sprintf($lang['accountadded'], $CONFIG_server_name, $login,
$CONFIG_website, $CONFIG_forums_location, $CONFIG_patch_location, $CONFIG_irc_channel,
$CONFIG_cp_location, $CONFIG_server_name);
SendMail($login, $email, "Your $CONFIG_server_name account is ready", $message);
}
/**
* @return void
* @param string $contactname The target's name
* @param string $contactemail The target's email
* @param string $subject Subject
* @param string $message Message
* @desc Sends an email to the email specified
*/
function SendMail($contactname, $contactemail, $subject, $message) {
require 'config.php';
require 'extract.inc';
if ($CONFIG_smtp_host != "") {
require_once 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = $CONFIG_smtp_host; // SMTP servers
if ($CONFIG_smtp_auth == 0) {
$mail->SMTPAuth = false; // turn off SMTP authentication
}
else {
$mail->SMTPAuth = true; // turn on SMTP authentication
}
$mail->Username = $CONFIG_smtp_login; // SMTP username
$mail->Password = $CONFIG_smtp_pass; // SMTP password
$mail->From = $CONFIG_sendmail_from;
$mail->FromName = $CONFIG_sendmail_name;
$mail->AddAddress($contactemail, $contactname);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Priority = 1;
if(!$mail->Send()) {
redir("index.php", "Message was not sent: " . $mail->ErrorInfo);
}
}
}
/**
* @return string
* @param string $input_string
* @desc Escapes the string, using ' for MSSQL, and \ for MySQL
*/
function add_escape($input_string) {
global $CONFIG_server_type;
if ($CONFIG_server_type == 0) {
// Eliminates the need for magic_quotes to be disabled
$input_string = str_replace("\\", "", $input_string);
return str_replace("'","''",$input_string);
}
else {
return addslashes($input_string);
}
}
function del_escape($input_string) {
global $CONFIG_server_type;
if ($CONFIG_server_type == 0) {
$input_string = str_replace("\\", "", $input_string);
return str_replace("''","'",$input_string);
}
else {
return stripslashes($input_string);
}
}
function highlight_search_term($input_string, $search_term) {
// Changed by Maldiablo
$search_term = str_replace("%", "", $search_term);
if ($input_string && $search_term) {
$position = strpos(strtolower($input_string), strtolower($search_term));
}
// End of changes
if ($position !== FALSE) {
$first_part = substr($input_string, 0, $position);
$middle_part = "<font color=green>" . substr($input_string, $position, strlen($search_term));
$final_part = "</font>" . substr($input_string, $position + strlen($search_term));
$output = $first_part . $middle_part . $final_part;
}
else {
$output = $input_string;
}
return $output;
}
function check_auth ($input_string) {
global $access, $STORED_login, $STORED_level;
if (checkbasename($input_string)) {
add_exploit_entry("Tried to access $input_string", 1);
redir("../index.php", "Access Denied");
}
else {
$page_string = basename($input_string);
if ($access[$page_string] == -1) {
redir("index.php", "This page has been disabled by the Administrator.");
}
elseif (!IsSET($access[$page_string])) {
redir("index.php", "Access Controls for this page has not been set.");
}
else {
if ($STORED_level < $access[$page_string]) {
if ($access[$page_string] > 1) {
add_exploit_entry("Tried to access $input_string", 1);
redir("index.php", "Access Denied");
}
else {
redir("login.php", "You must be logged on to access this page!");
}
}
}
}
}
function checkbasename($name) {
return (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']));
}
function redir($page, $msg, $time = 5) {
global $STORED_skin, $start_time, $STORED_level, $queries, $logged_in, $lang,
$debug_message, $cp_version;
require 'config.php';
require 'extract.inc';
/*
<head>
<meta http-equiv=\"refresh\" content=\"$time;url=$page\">
</head>
*/
echo "
<br />
<table width=\"250\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\" class=\"redir\">
<tr>
<td> </td>
</tr>
<tr align=\"center\">
<td class=\"mytext\">
<b>$msg</b><br />To continue, please <a href='$page'>click here</a><br />
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
";
require 'footer.inc';
exit();
}
/**
* @return void
* @param int $width Width of the table (%)
* @desc Displays the table header
*/
function EchoHead($width = "") {
//echo "<table width=\"$width%\" class=\"mytable\" cellpadding=\"0\" align=\"center\"> ";
echo "<table class=\"contentTable\">";
}
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
/**
* @return boolean
* @param string $test_string The string to be validated
* @desc Returns true if the string follows the regular expression declared in $CONFIG['validchars']
*/
function validate_string($test_string) {
global $CONFIG_validchars;
if (preg_match($CONFIG_validchars, $string)) {
return true;
}
else {
return false;
}
}
function generate_breaks($input_string) {
$message_data = explode("\r\n", $input_string);
for ($i = 0; $i < sizeof($message_data); $i++) {
$final_message .= $message_data[$i] . "<br>";
}
$final_message = substr($final_message, 0, strlen($final_message) - 4);
return $final_message;
}
/**
* @return resource
* @param string $input_query The SQL Query to be executed
* @param string $page_source The page which the query is called from
* @param int $limit The maximum number of rows selected from the query
* @param int $offset The number of rows to skip in a SELECT query
* @param boolean $skip_log Whether or not to skip the query logging process
* @desc Validates, Executes, Logs a query, returning an error message upon failure, a result identified on success.
*/
function execute_query($input_query, $page_source = 'none.php', $limit = 0, $offset = 0, $skip_log = false) {
global $debug_message, $queries, $link, $CONFIG_log_select, $CONFIG_log_insert,
$CONFIG_log_update, $CONFIG_log_delete, $CONFIG_debug, $CONFIG_passphrase,
$total_execution, $STORED_login;
$start_time = getmicrotime();
$analyze_query = strtolower(htmlspecialchars($input_query)); // analyzes the query for illegal inputs
// disables the use of UNION SELECT
$banned_combos = array(
"UNION SELECT" => "union",
"xp_stored procedure" => "xp_",
"comment" => "--"
);
foreach ($banned_combos as $index => $value) {
if (strstr($analyze_query, $value) == true) {
add_exploit_entry("Attempted to inject a $index into a query!");
redir("index.php", "Invalid query to be executed!");
}
}
$queries++;
$debug_message .= "\n\t<tr>\n\t\t<td><b>$queries</b></td>\n\t\t<td>";
if (!$skip_log) {
if (strstr($analyze_query, 'select') !== false && $CONFIG_log_select) {
$debug_message .= "Logging: ";
$log_query = true;
}
if (strstr($analyze_query, 'insert') !== false && $CONFIG_log_insert) {
$debug_message .= "Logging: ";
$log_query = true;
}
elseif (strstr($analyze_query, 'update') !== false && $CONFIG_log_update) {
$debug_message .= "Logging: ";
$log_query = true;
}
elseif (strstr($analyze_query, 'delete') !== false && $CONFIG_log_delete) {
$debug_message .= "Logging: ";
$log_query = true;
}
else {
$debug_message .= "Executing: ";
$log_query = false;
}
}
else {
$debug_message .= "Executing: ";
$log_query = false;
}
if ($limit == 0 && $offset == 0) {
$result = $link->Execute($input_query) or die("Query (<b>$input_query</b>) failed: " . $link->ErrorMsg());
}
else {
$result = $link->SelectLimit($input_query, $limit, $offset) or die("Query (<b>$input_query</b>) failed: " . $link->ErrorMsg());
}
// Displays each query (SELECT, INSERT, UPDATE, DELETE)
$debug_message .= "</td>\n\t\t<td>";
$execute_time = (getmicrotime() - $start_time);
$total_execution += $execute_time;
if ($CONFIG_debug) {
$rows = $result->RowCount();
$debug_message .= "$page_source</td>\n\t\t<td width=50%>";
$debug_message .= "$input_query</td>\n\t\t<td>$execute_time</td>\n\t\t</tr>";
}
if ($log_query) {
// replaces each line break with a space
$input_query = str_replace("\r\n", " ", $input_query);
add_query_entry($page_source, $input_query);
}
return $result;
}
function execute_query_union($input_query, $page_source = 'none.php', $limit = 0, $offset = 0, $skip_log = false) {
global $debug_message, $queries, $link, $CONFIG_log_select, $CONFIG_log_insert,
$CONFIG_log_update, $CONFIG_log_delete, $CONFIG_debug, $CONFIG_passphrase,
$total_execution, $STORED_login;
$start_time = getmicrotime();
$analyze_query = strtolower(htmlspecialchars($input_query)); // analyzes the query for illegal inputs
// disables the use of UNION SELECT
$banned_combos = array(
"xp_stored procedure" => "xp_",
"comment" => "--"
);
foreach ($banned_combos as $index => $value) {
if (strstr($analyze_query, $value) == true) {
add_exploit_entry("Attempted to inject a $index into a query!");
redir("index.php", "Invalid query to be executed!");
}
}
$queries++;
$debug_message .= "\n\t<tr>\n\t\t<td><b>$queries</b></td>\n\t\t<td>";
if (!$skip_log) {
if (strstr($analyze_query, 'select') !== false && $CONFIG_log_select) {
$debug_message .= "Logging: ";
$log_query = true;
}
if (strstr($analyze_query, 'insert') !== false && $CONFIG_log_insert) {
$debug_message .= "Logging: ";
$log_query = true;
}
elseif (strstr($analyze_query, 'update') !== false && $CONFIG_log_update) {
$debug_message .= "Logging: ";
$log_query = true;
}
elseif (strstr($analyze_query, 'delete') !== false && $CONFIG_log_delete) {
$debug_message .= "Logging: ";
$log_query = true;
}
else {
$debug_message .= "Executing: ";
$log_query = false;
}
}
else {
$debug_message .= "Executing: ";
$log_query = false;
}
if ($limit == 0 && $offset == 0) {
$result = $link->Execute($input_query) or die("Query (<b>$input_query</b>) failed: " . $link->ErrorMsg());
}
else {
$result = $link->SelectLimit($input_query, $limit, $offset) or die("Query (<b>$input_query</b>) failed: " . $link->ErrorMsg());
}
// Displays each query (SELECT, INSERT, UPDATE, DELETE)
$debug_message .= "</td>\n\t\t<td>";
$execute_time = (getmicrotime() - $start_time);
$total_execution += $execute_time;
if ($CONFIG_debug) {
$rows = $result->RowCount();
$debug_message .= "$page_source</td>\n\t\t<td width=50%>";
$debug_message .= "$input_query</td>\n\t\t<td>$execute_time</td>\n\t\t</tr>";
}
if ($log_query) {
// replaces each line break with a space
$input_query = str_replace("\r\n", " ", $input_query);
add_query_entry($page_source, $input_query);
}
return $result;
}
function is_server_online() {
global $CONFIG_check_server, $CONFIG_maintenance;
if (!$CONFIG_check_server or $CONFIG_maintenance) {
return false;
}
$query = CHECK_STATUS;
$result = execute_query($query, "functions.php");
$line = $result->FetchRow();
// Pull values from DB
$acc = $line[1];
$char = $line[2];
$map = $line[3];
if (!$acc || !$char || !$map) {
return false;
}
else {
return true;
}
}
function get_level($account_id) {
$query = sprintf(GET_LEVEL, $account_id);
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
return $result->fields[0];
}
else {
return 1;
}
}
function get_gmlevel($account_id) {
$query = sprintf(GET_GMLEVEL, $account_id);
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
return $result->fields[0];
}
else {
return 0;
}
}
/**
* @return boolean
* @param string $test The String to be validated
* @desc Returns true if the string is alphanumeric.
*/
function isalphanumeric($test) {
return !(preg_match("/[^a-z,A-Z,0-9]/", $test));
}
function authenticate ($login_username, $login_password) {
/* Returns the following privileges:
0: Fail
1: User
2: In-game GM
3: GM
4: Admin
*/
global $CONFIG_passphrase, $CONFIG_use_md5, $CONFIG_server_type;
if ($CONFIG_server_type > 0) {
if ($login_username == 's1' or $login_username == 's2' or $login_username == 's3' or $login_username == 's4' or $login_username == 's5') {
return 0;
}
}
if ($CONFIG_use_md5) {
$query = sprintf(AUTH_MD5, $login_username, $login_password);
}
else {
$query = sprintf(AUTH, $login_username, $login_password);
}
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
return get_level($result->fields[0]);
}
else {
return 0;
}
}
function privilege_string($access_level) {
if ($access_level == -1) return "<font color=red>Disabled</font>";
$access_string = explode("\r\n", file_get_contents("access.def"));
return $access_string[$access_level];
}
/**
* @return string
* @param int $class_index The class number
* @desc Returns the full class name, defined in class.def & class_advanced.def & class_baby.def
* Baby support added by Vich
*/
function determine_class_old ($class_index) {
if (($class_index > 4000) && ($class_index < 4023)) {
$class = explode("\r\n", file_get_contents("class_advanced.def"));
return $class[$class_index - 4001];
}
else if ($class_index >= 4023) {
$class = explode("\r\n", file_get_contents("class_baby.def"));
return $class[$class_index - 4023];
}
else {
$class = explode("\r\n",file_get_contents("class.def"));
return $class[$class_index];
}
}
function determine_class($class_index)
{
// Read file
$contents = @file("class_by_id.def");
if(!is_array($contents))
die(sprintf("File missing or empty: %s", $path));
// Parse lines
$class = array();
foreach($contents as $i => $line)
{
if($line == "")
continue;
$split = explode("\t", $line);
if(count($split) < 2)
continue;
// Add to table
$class[$split[0]] = trim($split[1]);
}
return $class[$class_index];
}
//DEBUG
//$table = ParseMapNameTable("./dbtranslation/mapnametable.txt");
//var_dump($table);
/**
* @return string
* @param int $castle_index The castle number
* @desc Returns the castle name as defined in guild_castles.def
*/
function determine_castle ($castle_index) {
$castle_name = explode("\r\n", file_get_contents("guild_castles.def"));
return $castle_name[$castle_index];
}
function determine_config_desc ($conf_index) {
$conf_name = explode("\r\n", file_get_contents("conf.def"));
return $conf_name[$conf_index];
}
function edit_config($edit_index, $edit_value) {
require 'config.php';
// Write the current config.php
$write = fopen("config.php", "w");
fwrite($write, "<?php\r\n");
$comment_index = 0;
foreach ($CONFIG as $config_index => $config_value) {
if ($config_index == $edit_index) {
// element of array is the one being edited
if ($config_index == "server_rules") {
$write_value = generate_breaks($edit_value);
$new_rules = htmlspecialchars($write_value);
}
else {
$write_value = $edit_value;
}
}
else {
// not the edited index, write the normal value
$write_value = $config_value;
}
// Adjusts the tabbing for cleaner output
if (strlen($config_index) < 12) {
$tabs = "\t\t\t";
}
elseif (strlen($config_index) < 20) {
$tabs = "\t\t";
}
else {
$tabs = "\t";
}
if (strlen($write_value) < 5) {
$comment_tabs = "\t\t\t";
}
elseif (strlen($write_value) < 13) {
$comment_tabs = "\t\t";
}
elseif (strlen($write_value) < 21) {
$comment_tabs = "\t";
}
else {
$comment_tabs = "";
}
$comment = determine_config_desc($comment_index);
$write_string = "\$CONFIG['$config_index'] $tabs=\t\t\t'$write_value';$comment_tabs// $comment\r\n";
fwrite($write, $write_string);
$comment_index++;
}
fwrite($write, "?>");
// Close config.php
fclose($write);
}
// The following functions are for logging purposes
/**
* @return void
* @param string $log_action
* @desc Adds the specified string into the access log
*/
function add_access_entry($log_action) {
// Different arguments
// 1: Went to a page that they weren't allowed to be.
// 2: Logged in as a GM/Admin
global $STORED_login;
$log_source = $_SERVER['REMOTE_ADDR'];
$query = sprintf(ADD_ACCESS_ENTRY, $log_source, $log_action);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
/**
* @return void
* @param string $log_action
* @desc Adds the specified string into the admin log
*/
function add_admin_entry($log_action) {
global $STORED_login;
$log_account = $STORED_login;
$query = sprintf(ADD_ADMIN_ENTRY, $log_account, $log_action);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
/**
* @return void
* @param string $banned_account
* @param string $log_reason
* @desc Adds the banned account name and reason into the ban log
*/
function add_ban_entry($banned_account, $log_reason) {
global $STORED_login;
$log_account = $STORED_login;
$log_reason = "Banned: " . $log_reason;
$query = sprintf(ADD_BAN_ENTRY, $log_account, $banned_account, $log_reason);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
function add_exploit_entry($log_action) {
global $STORED_login;
$log_account = $STORED_login;
if ($log_account == "") {
$log_account = $_SERVER['REMOTE_ADDR'];
}
$query = sprintf(ADD_EXPLOIT_ENTRY, $log_account, $log_action);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
function add_money_entry($from, $to, $log_action) {
global $CONFIG_passphrase;
$query = sprintf(CHECK_LOG_CHAR_ID, $CONFIG_passphrase, $from);
$result = execute_query($query, 'functions.php', 0, 0, true);
$from = $result->fields[0];
$query = sprintf(CHECK_LOG_CHAR_ID, $CONFIG_passphrase, $to);
$result = execute_query($query, 'functions.php', 0, 0, true);
$to = $result->fields[0];
$query = sprintf(ADD_MONEY_ENTRY, $from, $to, $log_action);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
function add_query_entry($source, $log_query) {
global $STORED_login, $link;
$log_account = $STORED_login;
$log_ip = $_SERVER['REMOTE_ADDR'];
$log_query = add_escape($log_query);
$query = sprintf(ADD_QUERY_ENTRY, $log_account, $log_ip, $source, $log_query);
$result = $link->Execute($query) or die("Query ($query) failed: " . $link->ErrorMsg());
}
function add_unban_entry($unbanned_account, $log_reason) {
global $STORED_login;
$log_account = $STORED_login;
$log_reason = "Unbanned: " . $log_reason;
$query = sprintf(ADD_UNBAN_ENTRY, $log_account, $unbanned_account, $log_reason);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
function add_user_entry($log_action) {
global $STORED_login;
$log_account = $STORED_login;
$query = sprintf(ADD_USER_ENTRY, $log_account, $log_action);
$result = execute_query($query, 'functions.php', 0, 0, true);
}
// End logging functions
function GetUserCount() {
// returns the number of users online
$query = GET_ONLINE;
$result = execute_query($query, "functions.php");
return $result->fields[0];
}
function GetAccountCount() {
// returns the number of accounts that are not for the server
$query = GET_ACC_COUNT;
$result = execute_query($query, 'functions.php');
return $result->fields[0];
}
function GetCharacterCount() {
// returns the number of characters on server
$query = GET_CHAR_COUNT;
$result = execute_query($query, 'functions.php');
return $result->fields[0];
}
function GetZenyCount() {
$query = GET_ZENY_COUNT;
$result = execute_query($query, 'functions.php');
return $result->fields[0];
}
/**
* @return boolean
* @param int $input_account_id
* @desc Returns true if the account is online in-game. Otherwise, returns false.
*/
function is_online ($input_account_id) {
// returns whether or not account is online
$query = sprintf(IS_ONLINE, $input_account_id);
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
return true;
}
else {
return false;
}
}
function GetGuildCount() {
// returns the number of guilds on server
$query = GET_GUILD_COUNT;
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
$line = $result->FetchRow();
return $line[0];
}
else {
return 0;
}
}
function ItemName_To_ItemID ($input_item_name) {
global $athena_db;
// Converts Item Name to Item #
$query = sprintf(ITEMNAME_TO_ITEMID, $input_item_name);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return 0;
}
else {
$line = $result->FetchRow();
return $line[0];
}
}
function ItemID_To_ItemName ($input_item_ID) {
if ($input_item_ID == 0) {
return "";
}
// Converts Item # to Item Name
$query = sprintf(ITEMID_TO_ITEMNAME, $input_item_ID);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
if ($input_item_ID == 0 or $input_item_ID == 2 or $input_item_ID == 255) {
return "";
}
elseif ($input_item_ID > 1280) {
return "";
}
else {
return "Unknown Item $input_item_ID";
}
}
else {
$line = $result->FetchRow();
return $line[0];
}
}
function CharName_To_CharID ($input_char_name) {
// Converts Char Name to Char ID
$query = sprintf(CHARNAME_TO_CHARID, add_escape($input_char_name));
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return 0;
}
else {
return $result->fields[0];
}
}
/**
* @return string
* @param int $input_char_id Character ID
* @desc Returns the character name, for the given character ID
*/
function CharID_To_CharName ($input_char_id) {
if ($input_char_id == 0) {
return "";
}
// Converts Char ID to Char Name
$query = sprintf(CHARID_TO_CHARNAME, $input_char_id);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return "";
}
else {
return del_escape($result->fields[0]);
}
}
/**
* @return int
* @param int $input_account_id
* @desc Returns the account name of the account ID inputted.
*/
function AccountID_To_UserID($input_account_id) {
if ($input_account_id == 0) {
return "";
}
// Converts Account ID to Account Name
$query = sprintf(ACCOUNTID_TO_USERID, $input_account_id);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return "";
}
else {
return del_escape($result->fields[0]);
}
}
function UserID_To_AccountID($input_user_id) {
// Converts Account Name to Account ID
$input_user_id = add_escape($input_user_id);
$query = sprintf(USERID_TO_ACCOUNTID, $input_user_id);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return 0;
}
else {
return $result->fields[0];
}
}
function GuildID_To_GuildName($input_guild_id) {
// Converts Account ID to Account Name
$query = sprintf(GUILDID_TO_GUILDNAME, $input_guild_id);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return "";
}
else {
return del_escape($result->fields[0]);
}
}
function GuildName_To_GuildID($input_guild_name) {
// Converts Account Name to Account ID
$input_guild_name = add_escape($input_guild_name);
$query = sprintf(GUILDNAME_TO_GUILDID, $input_guild_name);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return 0;
}
else {
return $result->fields[0];
}
}
/**
* @return int
* @param string $input_character_name
* @desc Returns the account ID of the character name given
*/
function account_of_character ($input_character_name) {
// character name, returns account name
$input_character_name = add_escape($input_character_name);
$query = sprintf(ACCOUNT_OF_CHAR, $input_character_name);
$result = execute_query($query, 'functions.php');
if ($result->RowCount() == 0) {
return "";
}
else {
return $result->fields[0];
}
}
function clear_account($account_id) {
global $CONFIG_server_type;
// input account #, clears everything associated with account
$query = sprintf(DISPLAY_ACCOUNT_ITEMS, $account_id);
$result = execute_query($query, 'functions.php');
while ($line = $result->FetchRow()) {
$delete_char_id = $line[0];
clear_character($delete_char_id);
}
// Delete storage, then account
if ($CONFIG_server_type == 0) {
$query = "DELETE FROM character.dbo.storeitem WHERE AID = '$account_id'";
$result = execute_query($query, 'functions.php');
$query = "DELETE FROM nLogin.dbo.account WHERE AID = '$account_id'";
$result = execute_query($query, 'functions.php');
$query = "DELETE FROM nLogin.dbo.login WHERE AID = '$account_id'";
$result = execute_query($query, 'functions.php');
}
else {
$query = "DELETE FROM `storage` WHERE account_id = '$account_id'";
$result = execute_query($query, 'functions.php');
$query = "DELETE FROM `login` WHERE account_id = '$account_id'";
$result = execute_query($query, 'functions.php');
}
}
function clear_character($delete_char_id) {
global $CONFIG_server_type, $CONFIG_passphrase;
// input char #, clears everything associated with character
// Following Sections clean the database of any trace of the account.
// Looking at the queries, you can see that it's very thorough, and that the only
// way to reverse this process is to restore a backup of the database.
// Guild/Party Clearing
// Start Guild Clear
// Check if that character is guild master
# fix?
$query = sprintf(CHARID_TO_CHARNAME, $delete_char_id );
$result = execute_query($query, "functions.php");
if ($result->RowCount() > 0) {
$delete_char = $result->fields[0];
}
else
die( "Something fucked up." );
# end fix?
$query = sprintf(CHECK_GUILD_MASTER, $delete_char);
$result = execute_query($query, "functions.php");
$line = $result->FetchRow();
if ($result->RowCount() > 0) {
// Deleted Character owns a guild
# clear_guild($result->fields[0]);
clear_guild($line[0]); # fix2
}
else {
// Deleted Character does not own a guild
if ($CONFIG_server_type > 0) {
// Only Athena has guild_id in character table
// Set that character's guild id to 0
$query = "UPDATE `char` SET guild_id = 0 WHERE char_id = $delete_char_id";
$result = execute_query($query, "functions.php");
}
// Character leaves the guild
$query = sprintf(LEAVE_GUILD, $delete_char_id);
$result = execute_query($query, "functions.php");
}
// End Guild clearing
// Start Party Clear
// Check if character is party master
$query = sprintf(CHECK_PARTY_MASTER, $delete_char_id);
$result = execute_query($query, "functions.php");
$line = $result->FetchRow();
$delete_party_id = $line[0];
if ($result->RowCount() > 0) {
// Deleted Character owns a party
if ($CONFIG_server_type > 0) {
// Only Athena has party_id in character table
// Deleted char owns a party
// Determine party ID that they own
// Go through each member of that party, set their party to 0
$query = "UPDATE `char` SET party_id = 0 WHERE party_id = $delete_party_id";
$result = execute_query($query, "functions.php");