forked from renderse7en/dragon-scourge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.php
669 lines (509 loc) · 30.2 KB
/
users.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
<?php // users.php :: Functions for creating/editing/viewing user accounts and statistics.
// Dragon Scourge
//
// Program authors: Jamin Blount
// Copyright (C) 2007 by renderse7en
// Script Version 1.0 Beta 5 Build 20
// You may not distribute this program in any manner, modified or
// otherwise, without the express, written consent from
// renderse7en.
//
// You may make modifications, but only for your own use and
// within the confines of the Dragon Scourge License Agreement
// (see our website for that).
include("lib.php");
include("globals.php");
if(isset($_GET["do"])) {
$do = explode(":",$_GET["do"]);
switch ($do[0]) {
case "register": register(); break;
case "profile": profile(); break;
case "characters": characters(); break;
case "charnew": charnew(); break;
case "charedit": charedit(); break;
case "settings": settings(); break;
case "levelup": levelup(); break;
case "levelspell": levelspell(); break;
default: donothing();
}
} else {
donothing();
}
function donothing() {
die(header("Location: index.php"));
}
function register() {
if(isset($_POST["submit"])) {
extract($_POST);
global $controlrow;
$errors = 0; $errorlist = "";
// Process username.
if (trim($username) == "") { $errors++; $errorlist .= "Username field is required.<br />"; }
if (preg_match("/[^A-z0-9_\-]/", $username)==1) { $errors++; $errorlist .= "Username must be alphanumeric.<br />"; } // Thanks to "Carlos Pires" from php.net!
$usernamequery = doquery("SELECT username FROM <<accounts>> WHERE username='$username' LIMIT 1");
if (mysql_num_rows($usernamequery) > 0) { $errors++; $errorlist .= "Username already taken - unique username required.<br />"; }
// Process password.
if (trim($password1) == "") { $errors++; $errorlist .= "Password fields is required.<br />"; }
if ($password1 != $password2) { $errors++; $errorlist .= "Passwords don't match.<br />"; }
$password = md5($password1);
// Process email address.
if (trim($email1) == "") { $errors++; $errorlist .= "Email field is required.<br />"; }
if ($email1 != $email2) { $errors++; $errorlist .= "Emails don't match.<br />"; }
if (! is_email($email1)) { $errors++; $errorlist .= "Email isn't valid.<br />"; }
$emailquery = doquery("SELECT emailaddress FROM <<accounts>> WHERE emailaddress='$email1' LIMIT 1");
if (mysql_num_rows($emailquery) > 0) { $errors++; $errorlist .= "Email already taken - unique email address required.<br />"; }
// Process other stuff.
if ($imageformat != ".png" && $imageformat != ".gif") { $errors++; $errorlist .= "Invalid input for image format selection.<br />"; }
if (!is_numeric($minimap)) { $errors++; $errorlist .= "Invalid input for minimap selection.<br />"; }
if ($errors == 0) {
if ($controlrow["verifyemail"] == 1) {
$verifycode = "";
for ($i=0; $i<8; $i++) {
$verifycode .= chr(rand(65,90));
}
$verifycode = md5($verifycode);
} else {
$verifycode='1';
}
// Now update.
$query = doquery("INSERT INTO <<accounts>> SET id='',regdate=NOW(),regip='".$_SERVER["REMOTE_ADDR"]."',verifycode='$verifycode',username='$username',password='$password',emailaddress='$email1',language='English',imageformat='$imageformat', minimap='$minimap'") or die(mysql_error());
// Send confirmation email if necessary.
if ($controlrow["verifyemail"] == 1) {
if (sendregmail($email1, $verifycode) == true) {
$page = "Your account was created successfully.<br /><br />You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, click the verification link it contains to activate your account, and start playing.";
} else {
$page = "Your account was created successfully.<br /><br />However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem.";
}
} else {
$page = "Your account was created succesfully.<br /><br />You may now continue to the <a href=\"login.php?do=login\">Login Page</a> and continue playing ".$controlrow["gamename"]."!";
}
} else {
// Die gracefully on errors.
$page = "The following error(s) occurred when your account was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=register\">go back</a> and try again.";
}
display("Register", $page, false);
}
$row["imageformat"] = "<option value=\".png\">PNG</option><option value=\".gif\">GIF</option>";
$row["minimap"] = "<option value=\"1\">Yes</option><option value=\"0\">No</option>";
display("Register", parsetemplate(gettemplate("users_register1"), $row), false);
}
function sendregmail($emailaddress, $vercode) {
global $controlrow;
extract($controlrow);
$verurl = $gameurl . "verify.php?code=$vercode";
$email = <<<END
You or someone using your email address recently signed up for an account on the $gamename server, located at $gameurl.
This email is sent to verify your registration email. In order to begin using your account, you must verify your email address.
Please click on the link below or copy/paste it into your browser to activate your account. You will not be able to play the game until your account is activated.
Verification URL:
$verurl
If you were not the person who signed up for the game, please disregard this message. You will not be emailed again.
END;
$status = mymail($emailaddress, "$gamename Account Verification", $email);
return $status;
}
function profile() {
global $userrow;
$newuserrow = $userrow;
$template = "users_profile";
// Setup for viewing other people's profiles.
if(isset($_GET["uid"])) {
if (!is_numeric($_GET["uid"])) { err("Invalid UID."); }
$newuserrow = dorow(doquery("SELECT * FROM <<users>> WHERE id='".$_GET["uid"]."' LIMIT 1"));
if ($newuserrow == false) { err("No such UID."); }
$template = "users_onlinechar";
}
if ($newuserrow["guild"] != 0) {
$newuserrow["newcharname"] = "[<span style=\"color: ".$newuserrow["tagcolor"].";\">".$newuserrow["guildtag"]."</span>]<span style=\"color: ".$newuserrow["namecolor"].";\">".$newuserrow["charname"]."</span>";
} else {
$newuserrow["newcharname"] = $newuserrow["charname"];
}
if ($newuserrow["charpicture"] != "") {
$newuserrow["profcharpicture"] = "<img src=\"".$newuserrow["charpicture"]."\" alt=\"".$newuserrow["charname"]."\" />";
} else {
$newuserrow["profcharpicture"] = "<img src=\"images/users/nopicture.gif\" alt=\"".$newuserrow["charname"]."\" />";
}
$newuserrow["formatexperience"] = number_format($newuserrow["experience"]);
$newuserrow["formatgold"] = number_format($newuserrow["gold"]);
if ($newuserrow["expbonus"] == 0) { $newuserrow["expbonus"] = ""; } else { if ($newuserrow["expbonus"]>0) { $expsign="+"; } else { $expsign=""; } $newuserrow["expbonus"] = "($expsign".$newuserrow["expbonus"]."%)"; }
if ($newuserrow["goldbonus"] == 0) { $newuserrow["goldbonus"] = ""; } else { if ($newuserrow["goldbonus"]>0) { $goldsign="+"; } else { $goldsign=""; }$newuserrow["goldbonus"] = "($goldsign".$newuserrow["goldbonus"]."%)"; }
// Next level.
$leveltotal = 15;
$leveladd = 15;
$i = 2;
while ($i < ($newuserrow["level"] + 1)) {
$levelstart = $leveltotal;
if ($i < 4) {
$leveladd = ceil($leveladd * 2.0);
} elseif ($i < 13) {
$leveladd = floor($leveladd * 1.45);
} elseif ($i < 40) {
$leveladd = floor($leveladd * 1.20);
} elseif ($i < 60) {
$leveladd = 150000;
} elseif ($i < 80) {
$leveladd = 200000;
} elseif ($i < 100) {
$leveladd = 300000;
} elseif ($i >= 100) {
$leveladd = 500000;
}
$leveltotal = $levelstart + $leveladd;
$i++;
}
$newuserrow["formatnextlvl"] = number_format($leveltotal);
// Level points.
if ($newuserrow["levelup"] != 0 || $newuserrow["levelspell"] != 0) { $newuserrow["levelpointscharnotice"] = "You have Level/Spell Points available."; } else { $newuserrow["levelpointscharnotice"] = ""; }
// Class.
$class = dorow(doquery("SELECT * FROM <<classes>> WHERE id='".$newuserrow["charclass"]."' LIMIT 1"));
$newuserrow["charclass"] = $class["name"];
display("Extended Profile",parsetemplate(gettemplate($template),$newuserrow));
}
function settings() {
global $acctrow;
if (isset($_POST["submit"])) {
extract($_POST);
$errors = 0;
$errorlist = "";
// Process password.
if (trim($password1) != "") {
if (md5($oldpassword) != $acctrow["password"]) { $errors++; $errorlist .= "Incorrect old password.<br />"; }
if ($password1 != $password2) { $errors++; $errorlist .= "New passwords don't match.<br />"; }
$password = "password='".md5($password1)."',";
$newpass = true;
} else { $password = ""; }
// Process email address.
if (trim($email) == "") { $errors++; $errorlist .= "Email field is required.<br />"; }
if (! is_email($email)) { $errors++; $errorlist .= "Email isn't valid.<br />"; }
$emailquery = doquery("SELECT emailaddress FROM <<accounts>> WHERE emailaddress='$email' AND id != '".$acctrow["id"]."' LIMIT 1");
if (mysql_num_rows($emailquery) > 0) { $errors++; $errorlist .= "Email already taken - unique email address required.<br />"; }
// Process other stuff.
if ($imageformat != ".png" && $imageformat != ".gif") { $errors++; $errorlist .= "Invalid input for image format selection.<br />"; }
if (!is_numeric($minimap)) { $errors++; $errorlist .= "Invalid input for minimap selection.<br />"; }
if ($errors == 0) {
$query = doquery("UPDATE <<accounts>> SET $password emailaddress='$email', imageformat='$imageformat', minimap='$minimap' WHERE id='".$acctrow["id"]."' LIMIT 1");
if (isset($newpass)) {
setcookie("scourge", "", (time()-3600), "/", "", 0);
$page = "Your information was updated successfully. Because you changed your password, you have been logged out to avoid cookie errors.<br /><br />Please use the Log In link above to log back into the game and continue playing.";
unset($GLOBALS["acctrow"]);
display("Account Settings", $page, false);
} else {
$page = "Your information was updated successfully. You may now continue <a href=\"index.php\">playing</a>.";
display("Account Settings", $page);
}
} else {
err("The following error(s) occurred when your account was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=settings\">go back</a> and try again.");
}
}
$row["emailaddress"] = $acctrow["emailaddress"];
$row["language"] = "<option value=\"English\">English</option>";
if ($acctrow["imageformat"] == ".png") {
$row["imageformat"] = "<option value=\".png\" selected=\"selected\">PNG</option><option value=\".gif\">GIF</option>";
} else {
$row["imageformat"] = "<option value=\".png\">PNG</option><option value=\".gif\" selected=\"selected\">GIF</option>";
}
if ($acctrow["minimap"] == 0) {
$row["minimap"] = "<option value=\"1\">Yes</option><option value=\"0\" selected=\"selected=\">No</option>";
} else {
$row["minimap"] = "<option value=\"1\">Yes</option><option value=\"0\">No</option>";
}
display("Account Settings", parsetemplate(gettemplate("users_settings"), $row));
}
function characters() {
global $acctrow, $userrow, $controlrow;
if (isset($_POST["submit"])) {
// Change the active character for the account.
if (!is_numeric($_POST["makeactive"])) { err("Invalid UID."); }
$newuserrow = dorow(doquery("SELECT * FROM <<users>> WHERE id='".$_POST["makeactive"]."' LIMIT 1"));
if ($newuserrow == false) { err("No such UID."); }
if ($newuserrow["account"] != $acctrow["id"]) { err("You don't own that UID."); }
$setnewchar = doquery("UPDATE <<accounts>> SET activechar='".$_POST["makeactive"]."' WHERE id='".$acctrow["id"]."' LIMIT 1");
die(header("Location: users.php?do=characters"));
}
if ($userrow != false) {
// Pagerow setup.
$row["characters"] = $acctrow["characters"];
$row["remaining"] = 4 - $acctrow["characters"];
$row["activecharname"] = $userrow["charname"];
$row["selectcharlist"] = "";
$row["fullcharlist"] = "";
if($row["characters"] < 4) {
$row["newcharlink"] = "<a href=\"users.php?do=charnew\">Click here to create a new character.</a><br />";
} else { $row["newcharlink"] = ""; }
// Grab characters.
$charrow = dorow(doquery("SELECT *, DATE_FORMAT(birthdate, '%m.%d.%Y') AS fregdate FROM <<users>> WHERE account='".$acctrow["id"]."' ORDER BY birthdate"), "id");
foreach($charrow as $a=>$b) {
if ($b["id"] == $acctrow["activechar"]) {
$row["selectcharlist"] .= "<option value=\"".$b["id"]."\" selected=\"selected\">".$b["charname"]." (Default)</option>";
$b["isdefault"] = "<span class=\"red\">(Default)</span>";
} else {
$row["selectcharlist"] .= "<option value=\"".$b["id"]."\">".$b["charname"]."</option>";
$b["isdefault"] = "";
}
if ($b["charpicture"] != "") {
$b["avatar"] = "<img src=\"".$b["charpicture"]."\" alt=\"".$b["charname"]."\" />";
} else {
$b["avatar"] = "<img src=\"images/users/nopicture.gif\" alt=\"".$b["charname"]."\" />";
}
if ($controlrow["showsigbot"] == 1) {
$sigboturl = $controlrow["gameurl"] . "sigbot/" . $userrow["id"] . ".png";
$b["sigboturl"] = "SigBot URL: <a href=\"$sigboturl\" target=\"_new\">$sigboturl</a><br />";
} else {
$b["sigboturl"] = "";
}
$row["fullcharlist"] .= parsetemplate(gettemplate("users_charlistrow"), $b);
}
display("Characters", parsetemplate(gettemplate("users_charlist"), $row));
} else {
display("Characters", gettemplate("users_charlistnew"));
}
}
function charnew() {
global $controlrow, $acctrow;
if ($acctrow["characters"] >= 4) { err("You are not allowed to make any more new characters."); }
if (isset($_POST["submit"])) {
extract($_POST);
$errors = 0;
$errorlist = "";
// Process charname.
if (trim($charname) == "") { $errors++; $errorlist .= "Character Name field is required.<br />"; }
if (preg_match("/[^A-z\ 0-9_\-]/", $charname)==1) { $errors++; $errorlist .= "Character names can only contain letters, numbers, spaces and hyphens.<br />"; } // Thanks to "Carlos Pires" from php.net!
$characternamequery = doquery("SELECT charname FROM <<users>> WHERE charname='$charname' LIMIT 1");
if (mysql_num_rows($characternamequery) > 0) { $errors++; $errorlist .= "Character Name already taken - unique Character Name required.<br />"; }
// Upload new charpicture, if required.
if ($_FILES["intavatar"]["error"] != 4) {
$allowed = array(".gif",".jpg",".png");
$type = substr($_FILES["intavatar"]["name"],-4);
// Errors.
if (!in_array(strtolower($type),$allowed)) { die("Unallowed filetype for avatar."); }
if ($_FILES["intavatar"]["size"] > $controlrow["avatarmaxsize"]) { die("Avatar filesize too big."); }
$imagesize = getimagesize($_FILES["intavatar"]["tmp_name"]);
if (($imagesize[0]>50) || ($imagesize[1]>50)) { die("Avatar dimensions too big."); }
// Move file and finish.
$randomext = "";
for($i=0; $i<8; $i++) { $randomext .= rand(0,9); }
$uploadfile = $controlrow["avatarpath"] . $acctrow["username"] . $randomext . $type;
if (!move_uploaded_file($_FILES["intavatar"]["tmp_name"], $uploadfile)) { die("Unable to upload avatar."); }
$newcharpicture = $controlrow["avatarurl"] . $acctrow["username"] . $randomext . $type;
}
// Process everything else important.
if (!is_numeric($charclass)) { $errors++; $errorlist .= "Invalid character class.<br />"; }
if (!is_numeric($difficulty)) { $errors++; $errorlist .= "Invalid character class.<br />"; }
// Get bonuses and multipliers from classes/difficulties tables.
$expbonus = 0;
$goldbonus = 0;
$classes = dorow(doquery("SELECT * FROM <<classes>> WHERE id='$charclass' LIMIT 1"));
if ($classes != false) {
$expbonus += $classes["expbonus"];
$goldbonus += $classes["goldbonus"];
} else { $errors++; $errorlist .= "Invalid character class"; }
$difficulties = dorow(doquery("SELECT * FROM <<difficulties>> WHERE id='$difficulty' LIMIT 1"));
if ($difficulties != false) {
$expbonus += $difficulties["expbonus"];
$goldbonus += $difficulties["goldbonus"];
$difficulty = $difficulties["multiplier"];
$deathpenalty = $difficulties["deathpenalty"];
} else { $errors++; $errorlist .= "Invalid character class"; }
if ($errors == 0) {
// Now everything's cool. Create new character row.
$query = doquery("INSERT INTO <<users>> SET id='', account='".$acctrow["id"]."', birthdate=NOW(), lastip='".$_SERVER["REMOTE_ADDR"]."', onlinetime=NOW(), charname='$charname', charpicture='$newcharpicture', charclass='$charclass', difficulty='$difficulty', deathpenalty='$deathpenalty', expbonus='$expbonus', goldbonus='$goldbonus'");
// Update account row.
$default = "";
if (isset($setdefault)) { $default = "activechar='".mysql_insert_id()."', "; }
if ($acctrow["characters"] == 0) { $default = "activechar='".mysql_insert_id()."', "; }
$query2 = doquery("UPDATE <<accounts>> SET $default characters=characters+1 WHERE id='".$acctrow["id"]."' LIMIT 1");
// And we're finished.
die(header("Location: users.php?do=characters"));
} else {
// Die gracefully on errors.
if ($acctrow["characters"] != 0) {
err("The following error(s) occurred when your character was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=charnew\">go back</a> and try again.");
} else {
die("The following error(s) occurred when your character was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=charnew\">go back</a> and try again.");
}
}
}
$classes = dorow(doquery("SELECT * FROM <<classes>> ORDER BY id"));
$row["charclass"] = "";
$row["classdesc"] = "";
$count = 1;
foreach($classes as $a=>$b) {
$row["charclass"] .= "<option value=\"".$b["id"]."\">".$b["name"]."</option>";
$row["classdesc"] .= "<div id=\"t$count\" class=\"tip\">".$b["description"]."</div><a href=\"#\" onmouseout=\"popUp(event,'t$count')\" onmouseover=\"popUp(event,'t$count')\" onclick=\"return false\">".$b["name"]."</a> | ";
$count++;
}
$row["classdesc"] = rtrim($row["classdesc"], " |");
$difficulty = dorow(doquery("SELECT * FROM <<difficulties>> ORDER BY id"));
$row["difficulty"] = "";
foreach($difficulty as $a=>$b) {
$row["difficulty"] .= "<option value=\"".$b["id"]."\">".$b["name"]."</option>";
}
if ($acctrow["characters"] == 0) { $row["defaultenabled"] = "disabled=\"disabled\""; } else { $row["defaultenabled"] = ""; }
$row["maxsize"] = round($controlrow["avatarmaxsize"] / 1000, 1);
display("Characters", parsetemplate(gettemplate("users_charnew"), $row), false);
}
function charedit() {
global $controlrow, $acctrow;
// Change the active character for the account.
if (!is_numeric($_GET["uid"])) { err("Invalid UID."); }
$newuserrow = dorow(doquery("SELECT * FROM <<users>> WHERE id='".$_GET["uid"]."' LIMIT 1"));
if ($newuserrow == false) { err("No such UID."); }
if ($newuserrow["account"] != $acctrow["id"]) { err("You don't own that UID."); }
if (isset($_POST["submit"])) {
extract($_POST);
// Upload new charpicture, if required.
if ($_FILES["intavatar"]["error"] != 4) {
$allowed = array(".gif",".jpg",".png");
$type = substr($_FILES["intavatar"]["name"],-4);
// Errors.
if (!in_array(strtolower($type),$allowed)) { err("Unallowed filetype for avatar."); }
if ($_FILES["intavatar"]["size"] > $controlrow["avatarmaxsize"]) { err("Avatar filesize too big."); }
$imagesize = getimagesize($_FILES["intavatar"]["tmp_name"]);
if (($imagesize[0]>50) || ($imagesize[1]>50)) { err("Avatar dimensions too big."); }
// Move file and finish.
$randomext = "";
for($i=0; $i<8; $i++) { $randomext .= rand(0,9); }
$uploadfile = $controlrow["avatarpath"] . $acctrow["username"] . $randomext . $type;
if (!move_uploaded_file($_FILES["intavatar"]["tmp_name"], $uploadfile)) { err("Unable to upload avatar."); }
$newcharpicture = $controlrow["avatarurl"] . $acctrow["username"] . $randomext . $type;
if ($newuserrow["charpicture"] != "") {
$oldav = ltrim($newuserrow["charpicture"], $controlrow["avatarurl"]);
unlink($controlrow["avatarpath"] . $oldav);
}
}
// Now everything's cool.
$query = doquery("UPDATE <<users>> SET charpicture='$newcharpicture' WHERE id='".$newuserrow["id"]."' LIMIT 1");
die(header("Location: users.php?do=characters"));
} elseif (isset($_POST["delete"])) {
if ($acctrow["characters"] == 1) { err("You only have one character on your account. If you wish to delete this character, please make a new one first before trying to delete this one."); }
display("Characters", parsetemplate(gettemplate("users_chardelete"), $newuserrow));
} elseif (isset($_POST["ultrakill"])) {
// First we delete the char.
$query = doquery("DELETE FROM <<users>> WHERE id='".$newuserrow["id"]."'");
// Then we gotta update acctrow accordingly.
$query2 = dorow(doquery("SELECT * FROM <<users>> WHERE account='".$acctrow["id"]."' ORDER BY id LIMIT 1"));
$query3 = doquery("UPDATE <<accounts>> SET characters=characters-1, activechar='".$query2["id"]."' WHERE id='".$acctrow["id"]."' LIMIT 1");
die(header("Location: users.php?do=characters"));
} elseif (isset($_POST["wimpout"])) {
die(header("Location: users.php?do=characters"));
}
$newuserrow["maxsize"] = round($controlrow["avatarmaxsize"] / 1000, 1);
display("Characters", parsetemplate(gettemplate("users_charedit"), $newuserrow));
}
function levelup() {
global $userrow;
if ($userrow["levelup"] == 0) { err("You do not currently have any Level Points to spend."); }
$classrow = dorow(doquery("SELECT * FROM <<classes>> WHERE id='".$userrow["charclass"]."' LIMIT 1"));
if (isset($_POST["submit"])) {
unset($_POST["submit"]);
// Check to make sure they didn't mess with the input names.
foreach($_POST as $a=>$b) {
if (!is_numeric($a)) { err("Invalid input format."); }
}
// Loop through and add points where appropriate.
// Note that we loop through the number of points in $userrow, rather than the number of fields.
// This is to ensure that people don't edit the source to just add more fields.
$total = $userrow["levelup"];
for($i=0; $i<$total; $i++) {
switch($_POST[$i]) {
case "str":
$userrow["strength"]++;
$userrow["physattack"] += (1 * $classrow["damageperstrength"]);
$userrow["levelup"]--;
break;
case "dex":
$userrow["dexterity"]++;
$userrow["physdefense"] += (1 * $classrow["defenseperdex"]);
$userrow["levelup"]--;
break;
case "lif":
$userrow["life"]++;
$userrow["maxhp"] += (1 * $classrow["hpperlife"]);
$userrow["currenthp"] += (1 * $classrow["hpperlife"]);
$userrow["levelup"]--;
break;
case "enr":
$userrow["energy"]++;
$userrow["maxmp"] += (1 * $classrow["mpperenergy"]);
$userrow["currentmp"] += (1 * $classrow["mpperenergy"]);
$userrow["levelup"]--;
break;
default:
break;
}
}
// Round down any fractions.
$userrow["physattack"] = floor($userrow["physattack"]);
$userrow["physdefense"] = floor($userrow["physdefense"]);
$userrow["maxhp"] = floor($userrow["maxhp"]);
$userrow["maxmp"] = floor($userrow["maxmp"]);
// Finish.
updateuserrow();
display("Level Points", parsetemplate(gettemplate("users_levelup2"), $userrow));
} else {
$row["dropdowns"] = "";
for($i=0; $i<$userrow["levelup"]; $i++) {
$row["dropdowns"] .= "<div style=\"padding-bottom: 5px;\"><select name=\"$i\"><option value=\"0\">Pick One</option><option value=\"str\">Strength</option><option value=\"dex\">Dexterity</option><option value=\"lif\">Life</option><option value=\"enr\">Energy</option></select></div>\n";
}
$row["classname"] = $classrow["name"];
$row["damageperstrength"] = $classrow["damageperstrength"];
$row["defenseperdex"] = $classrow["defenseperdex"];
$row["hpperlife"] = $classrow["hpperlife"];
$row["mpperenergy"] = $classrow["mpperenergy"];
$row["levelup"] = $userrow["levelup"];
display("Level Points", parsetemplate(gettemplate("users_levelup1"), $row));
}
}
function levelspell() {
global $userrow, $spells;
if ($userrow["levelspell"] == 0) { err("You do not currently have any Spell Points to spend."); }
if (isset($_POST["submit"])) {
unset($_POST["submit"]);
// Check to make sure they didn't mess with the input names.
foreach($_POST as $a=>$b) {
$a = ltrim($a,"spelot");
if (!is_numeric($a)) { err("Invalid input format."); }
}
// Loop through and add points where appropriate.
// Note that we loop through the number of points in $userrow, rather than the number of fields.
// This is to ensure that people don't edit the source to just add more fields.
$total = $userrow["levelspell"];
for($i=0; $i<$total; $i++) {
if ($_POST["spell".$i] != 0) {
if (!isset($spells[$_POST["spell".$i]])) { err("That spell doesn't exist."); }
if ($_POST["slot".$i] == 0) { err("You didn't select a valid slot for one of your spells."); }
$userrow["spell".$_POST["slot".$i]."id"] = $_POST["spell".$i];
$userrow["spell".$_POST["slot".$i]."name"] = $spells[$_POST["spell".$i]]["name"];
$userrow["levelspell"]--;
}
}
// Finish.
updateuserrow();
display("Spell Points", parsetemplate(gettemplate("users_levelspell2"), $userrow));
} else {
if ($userrow["levelspell"] != 0) {
$row["spelldropdowns"] = "";
for ($j=0; $j<$userrow["levelspell"]; $j++) {
$row["spelldropdowns"] .= "<select name=\"spell$j\"><option value=\"0\">Pick One</option>\n";
foreach($spells as $a=>$b) {
if (($b["minlevel"] <= $userrow["level"]) && ($b["classonly"] == $userrow["charclass"] ^ $b["classexclude"] != $userrow["charclass"])) {
$row["spelldropdowns"] .= "<option value=\"".$b["id"]."\">".$b["name"]."</option>\n";
}
}
$row["spelldropdowns"] .= "</select> goes in <select name=\"slot$j\"><option value=\"0\">Pick One</option>\n";
for ($k=1; $k<11; $k++) {
if ($userrow["spell".$k."id"] != 0) {
$row["spelldropdowns"] .= "<option value=\"$k\">Slot $k: ".$userrow["spell".$k."name"]."</option>";
} else {
$row["spelldropdowns"] .= "<option value=\"$k\">Slot $k: Empty</option>";
}
}
$row["spelldropdowns"] .= "</select><br />";
}
$row["spelldropdowns"] .= "<br />";
}
$row["levelspell"] = $userrow["levelspell"];
display("Spell Points", parsetemplate(gettemplate("users_levelspell1"), $row));
}
}
?>