From 1e8ccdf24e62b9a51d70bcc869c2a91ca02ed273 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 25 Feb 2025 00:10:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Initial=20PHP8=20port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.php | 44 ++++++++++++++++++++--------------------- config.php | 11 +++++------ cookies.php | 4 ++-- explore.php | 4 ++-- fight.php | 18 ++++++++--------- forum.php | 10 +++++----- heal.php | 2 +- help.php | 2 +- help_items.php | 6 +++--- help_levels.php | 14 ++++++------- help_monsters.php | 4 ++-- help_spells.php | 4 ++-- index.php | 22 ++++++++++----------- install.php | 28 +++++++++++++------------- lib.php | 49 +++++++++++++++++++++++++--------------------- login.php | 4 ++-- towns.php | 42 +++++++++++++++++++-------------------- upgrade_to_110.php | 2 +- upgrade_to_112.php | 2 +- users.php | 24 +++++++++++------------ 20 files changed, 150 insertions(+), 146 deletions(-) diff --git a/admin.php b/admin.php index 77325c4..05b3a42 100644 --- a/admin.php +++ b/admin.php @@ -7,7 +7,7 @@ $userrow = checkcookies(); if ($userrow == false) { die("Please log in to the game before using the control panel."); } if ($userrow["authlevel"] != 1) { die("You must have administrator privileges to use the control panel."); } $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); if (isset($_GET["do"])) { $do = explode(":",$_GET["do"]); @@ -123,11 +123,11 @@ function items() { $query = doquery("SELECT id,name FROM {{table}} ORDER BY id", "items"); $page = "Edit Items
Click an item's name to edit it.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["name"]."
".$row["id"]."".$row["name"]."
No items found.
No items found.
"; admindisplay($page, "Edit Items"); @@ -158,7 +158,7 @@ function edititem($id) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $page = <<Edit Items

@@ -201,11 +201,11 @@ function drops() { $query = doquery("SELECT id,name FROM {{table}} ORDER BY id", "drops"); $page = "Edit Drops
Click an item's name to edit it.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["name"]."
".$row["id"]."".$row["name"]."
No items found.
No items found.
"; admindisplay($page, "Edit Drops"); @@ -235,7 +235,7 @@ function editdrop($id) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "drops"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $page = <<Edit Drops

@@ -273,11 +273,11 @@ function towns() { $query = doquery("SELECT id,name FROM {{table}} ORDER BY id", "towns"); $page = "Edit Towns
Click an town's name to edit it.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["name"]."
".$row["id"]."".$row["name"]."
No towns found.
No towns found.
"; admindisplay($page, "Edit Towns"); @@ -315,7 +315,7 @@ function edittown($id) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "towns"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $page = <<Edit Towns

@@ -344,7 +344,7 @@ function monsters() { global $controlrow; $statquery = doquery("SELECT * FROM {{table}} ORDER BY level DESC LIMIT 1", "monsters"); - $statrow = mysql_fetch_array($statquery); + $statrow = mysqli_fetch_array($statquery); $query = doquery("SELECT id,name FROM {{table}} ORDER BY id", "monsters"); $page = "Edit Monsters
"; @@ -355,11 +355,11 @@ function monsters() { $page .= "Click an monster's name to edit it.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["name"]."
".$row["id"]."".$row["name"]."
No towns found.
No towns found.
"; admindisplay($page, "Edit Monster"); @@ -397,7 +397,7 @@ function editmonster($id) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "monsters"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $page = <<Edit Monsters

@@ -431,11 +431,11 @@ function spells() { $query = doquery("SELECT id,name FROM {{table}} ORDER BY id", "spells"); $page = "Edit Spells
Click an spell's name to edit it.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["name"]."
".$row["id"]."".$row["name"]."
No spells found.
No spells found.
"; admindisplay($page, "Edit Spells"); @@ -465,7 +465,7 @@ function editspell($id) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "spells"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $page = <<Edit Spells

@@ -495,7 +495,7 @@ END; function levels() { $query = doquery("SELECT id FROM {{table}} ORDER BY id DESC LIMIT 1", "levels"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); $options = ""; for($i=2; $i<$row["id"]; $i++) { @@ -589,7 +589,7 @@ END; $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "levels"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); global $controlrow; $class1name = $controlrow["class1name"]; $class2name = $controlrow["class2name"]; @@ -647,11 +647,11 @@ function users() { $query = doquery("SELECT id,username FROM {{table}} ORDER BY id", "users"); $page = "Edit Users
Click a username to edit the account.

\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; } else { $page .= "\n"; $count = 1; } } - if (mysql_num_rows($query) == 0) { $page .= "\n"; } + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } $page .= "
".$row["id"]."".$row["username"]."
".$row["id"]."".$row["username"]."
No spells found.
No spells found.
"; admindisplay($page, "Edit Users"); @@ -776,7 +776,7 @@ END; } $query = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "users"); - $row = mysql_fetch_array($query); + $row = mysqli_fetch_array($query); global $controlrow; $diff1name = $controlrow["diff1name"]; $diff2name = $controlrow["diff2name"]; diff --git a/config.php b/config.php index b1d2606..9313d37 100644 --- a/config.php +++ b/config.php @@ -2,10 +2,9 @@ $dbsettings = Array( "server" => "localhost", // MySQL server name. (Default: localhost) - "user" => "", // MySQL username. - "pass" => "", // MySQL password. - "name" => "", // MySQL database name. + "user" => "dragonknight", // MySQL username. + "pass" => "dragonknight", // MySQL password. + "name" => "dragonknight", // MySQL database name. "prefix" => "dk", // Prefix for table names. (Default: dk) - "secretword" => ""); // Secret word used when hashing information for cookies. - -?> \ No newline at end of file + "secretword" => "koboldkipu"); // Secret word used when hashing information for cookies. +?> diff --git a/cookies.php b/cookies.php index 1ffc5df..569cfbd 100644 --- a/cookies.php +++ b/cookies.php @@ -12,8 +12,8 @@ function checkcookies() { // {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME} $theuser = explode(" ",$_COOKIE["dkgame"]); $query = doquery("SELECT * FROM {{table}} WHERE username='$theuser[1]'", "users"); - if (mysql_num_rows($query) != 1) { die("Invalid cookie data (Error 1). Please clear cookies and log in again."); } - $row = mysql_fetch_array($query); + if (mysqli_num_rows($query) != 1) { die("Invalid cookie data (Error 1). Please clear cookies and log in again."); } + $row = mysqli_fetch_array($query); if ($row["id"] != $theuser[0]) { die("Invalid cookie data (Error 2). Please clear cookies and log in again."); } if (md5($row["password"] . "--" . $dbsettings["secretword"]) !== $theuser[2]) { die("Invalid cookie data (Error 3). Please clear cookies and log in again."); } diff --git a/explore.php b/explore.php index 252ee96..1560fd5 100644 --- a/explore.php +++ b/explore.php @@ -14,8 +14,8 @@ function move() { if (isset($_POST["west"])) { $longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } } $townquery = doquery("SELECT id FROM {{table}} WHERE latitude='$latitude' AND longitude='$longitude' LIMIT 1", "towns"); - if (mysql_num_rows($townquery) > 0) { - $townrow = mysql_fetch_array($townquery); + if (mysqli_num_rows($townquery) > 0) { + $townrow = mysqli_fetch_array($townquery); include('towns.php'); travelto($townrow["id"], false); die(); diff --git a/fight.php b/fight.php index b51f22b..0ce4f7c 100644 --- a/fight.php +++ b/fight.php @@ -10,7 +10,7 @@ function fight() { // One big long function that determines the outcome of the f $pagearray["magiclist"] = ""; $userspells = explode(",",$userrow["spells"]); $spellquery = doquery("SELECT id,name FROM {{table}}", "spells"); - while ($spellrow = mysql_fetch_array($spellquery)) { + while ($spellrow = mysqli_fetch_array($spellquery)) { $spell = false; foreach ($userspells as $a => $b) { if ($b == $spellrow["id"]) { $spell = true; } @@ -38,7 +38,7 @@ function fight() { // One big long function that determines the outcome of the f // Pick a monster. $monsterquery = doquery("SELECT * FROM {{table}} WHERE level>='$minlevel' AND level<='$maxlevel' ORDER BY RAND() LIMIT 1", "monsters"); - $monsterrow = mysql_fetch_array($monsterquery); + $monsterrow = mysqli_fetch_array($monsterquery); $userrow["currentmonster"] = $monsterrow["id"]; $userrow["currentmonsterhp"] = rand((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]); if ($userrow["difficulty"] == 2) { $userrow["currentmonsterhp"] = ceil($userrow["currentmonsterhp"] * $controlrow["diff2mod"]); } @@ -56,7 +56,7 @@ function fight() { // One big long function that determines the outcome of the f // Next, get the monster statistics. $monsterquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["currentmonster"]."' LIMIT 1", "monsters"); - $monsterrow = mysql_fetch_array($monsterquery); + $monsterrow = mysqli_fetch_array($monsterquery); $pagearray["monstername"] = $monsterrow["name"]; // Do run stuff. @@ -185,7 +185,7 @@ function fight() { // One big long function that determines the outcome of the f if ($pickedspell == 0) { display("You must select a spell first. Please go back and try again.", "Error"); die(); } $newspellquery = doquery("SELECT * FROM {{table}} WHERE id='$pickedspell' LIMIT 1", "spells"); - $newspellrow = mysql_fetch_array($newspellquery); + $newspellrow = mysqli_fetch_array($newspellquery); $spell = false; foreach($userspells as $a => $b) { if ($b == $pickedspell) { $spell = true; } @@ -359,7 +359,7 @@ function victory() { if ($userrow["currentfight"] == 0) { header("Location: index.php"); die(); } $monsterquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["currentmonster"]."' LIMIT 1", "monsters"); - $monsterrow = mysql_fetch_array($monsterquery); + $monsterrow = mysqli_fetch_array($monsterquery); $exp = rand((($monsterrow["maxexp"]/6)*5),$monsterrow["maxexp"]); if ($exp < 1) { $exp = 1; } @@ -375,7 +375,7 @@ function victory() { if ($userrow["gold"] + $gold < 16777215) { $newgold = $userrow["gold"] + $gold; $warngold = ""; } else { $newgold = $userrow["gold"]; $gold = 0; $warngold = "You have maxed out your experience points."; } $levelquery = doquery("SELECT * FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels"); - if (mysql_num_rows($levelquery) == 1) { $levelrow = mysql_fetch_array($levelquery); } + if (mysqli_num_rows($levelquery) == 1) { $levelrow = mysqli_fetch_array($levelquery); } if ($userrow["level"] < 100) { if ($newexp >= $levelrow[$userrow["charclass"]."_exp"]) { @@ -411,7 +411,7 @@ function victory() { if (rand(1,30) == 1) { $dropquery = doquery("SELECT * FROM {{table}} WHERE mlevel <= '".$monsterrow["level"]."' ORDER BY RAND() LIMIT 1", "drops"); - $droprow = mysql_fetch_array($dropquery); + $droprow = mysqli_fetch_array($dropquery); $dropcode = "dropcode='".$droprow["id"]."',"; $page .= "This monster has dropped an item. Click here to reveal and equip the item, or you may also move on and continue exploring."; } else { @@ -437,7 +437,7 @@ function drop() { if ($userrow["dropcode"] == 0) { header("Location: index.php"); die(); } $dropquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["dropcode"]."' LIMIT 1", "drops"); - $droprow = mysql_fetch_array($dropquery); + $droprow = mysqli_fetch_array($dropquery); if (isset($_POST["submit"])) { @@ -448,7 +448,7 @@ function drop() { if ($userrow["slot".$slot."id"] != 0) { $slotquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["slot".$slot."id"]."' LIMIT 1", "drops"); - $slotrow = mysql_fetch_array($slotquery); + $slotrow = mysqli_fetch_array($slotquery); $old1 = explode(",",$slotrow["attribute1"]); if ($slotrow["attribute2"] != "X") { $old2 = explode(",",$slotrow["attribute2"]); } else { $old2 = array(0=>"maxhp",1=>0); } diff --git a/forum.php b/forum.php index a7554df..8523e99 100644 --- a/forum.php +++ b/forum.php @@ -6,7 +6,7 @@ $link = opendb(); $userrow = checkcookies(); if ($userrow == false) { display("The forum is for registered players only.", "Forum"); die(); } $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); // Close game. if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); } @@ -30,10 +30,10 @@ function donothing($start=0) { $query = doquery("SELECT * FROM {{table}} WHERE parent='0' ORDER BY newpostdate DESC LIMIT 20", "forum"); $page = "
\n"; $count = 1; - if (mysql_num_rows($query) == 0) { + if (mysqli_num_rows($query) == 0) { $page .= "\n"; } else { - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; @@ -53,10 +53,10 @@ function showthread($id, $start) { $query = doquery("SELECT * FROM {{table}} WHERE id='$id' OR parent='$id' ORDER BY id LIMIT $start,15", "forum"); $query2 = doquery("SELECT title FROM {{table}} WHERE id='$id' LIMIT 1", "forum"); - $row2 = mysql_fetch_array($query2); + $row2 = mysqli_fetch_array($query2); $page = "
New Thread
ThreadRepliesLast Post
No threads in forum.
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
\n"; $count = 1; - while ($row = mysql_fetch_array($query)) { + while ($row = mysqli_fetch_array($query)) { if ($count == 1) { $page .= "\n"; $count = 2; diff --git a/heal.php b/heal.php index 24ae715..740eb48 100644 --- a/heal.php +++ b/heal.php @@ -6,7 +6,7 @@ function healspells($id) { $userspells = explode(",",$userrow["spells"]); $spellquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "spells"); - $spellrow = mysql_fetch_array($spellquery); + $spellrow = mysqli_fetch_array($spellquery); // All the various ways to error out. $spell = false; diff --git a/help.php b/help.php index 25d52fb..da21196 100644 --- a/help.php +++ b/help.php @@ -2,7 +2,7 @@ include('lib.php'); $link = opendb(); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); ob_start("ob_gzhandler"); ?> diff --git a/help_items.php b/help_items.php index 1dac7eb..f981b6a 100644 --- a/help_items.php +++ b/help_items.php @@ -2,7 +2,7 @@ include('lib.php'); $link = opendb(); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); ob_start("ob_gzhandler"); ?> @@ -81,7 +81,7 @@ a:hover { @@ -83,10 +83,10 @@ $count = 1; $itemsquery = doquery("SELECT id,1_exp,1_hp,1_mp,1_tp,1_strength,1_dexterity,1_spells FROM {{table}} ORDER BY id", "levels"); $spellsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "spells"); $spells = array(); -while ($spellsrow = mysql_fetch_array($spellsquery)) { +while ($spellsrow = mysqli_fetch_array($spellsquery)) { $spells[$spellsrow["id"]] = $spellsrow; } -while ($itemsrow = mysql_fetch_array($itemsquery)) { +while ($itemsrow = mysqli_fetch_array($itemsquery)) { if ($count == 1) { $color = "bgcolor=\"#ffffff\""; $count = 2; } else { $color = ""; $count = 1; } if ($itemsrow["1_spells"] != 0) { $spell = $spells[$itemsrow["1_spells"]]["name"]; } else { $spell = "None"; } if ($itemsrow["id"] != 100) { echo "\n"; } @@ -102,10 +102,10 @@ $count = 1; $itemsquery = doquery("SELECT id,2_exp,2_hp,2_mp,2_tp,2_strength,2_dexterity,2_spells FROM {{table}} ORDER BY id", "levels"); $spellsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "spells"); $spells = array(); -while ($spellsrow = mysql_fetch_array($spellsquery)) { +while ($spellsrow = mysqli_fetch_array($spellsquery)) { $spells[$spellsrow["id"]] = $spellsrow; } -while ($itemsrow = mysql_fetch_array($itemsquery)) { +while ($itemsrow = mysqli_fetch_array($itemsquery)) { if ($count == 1) { $color = "bgcolor=\"#ffffff\""; $count = 2; } else { $color = ""; $count = 1; } if ($itemsrow["2_spells"] != 0) { $spell = $spells[$itemsrow["2_spells"]]["name"]; } else { $spell = "None"; } if ($itemsrow["id"] != 100) { echo "\n"; } @@ -121,10 +121,10 @@ $count = 1; $itemsquery = doquery("SELECT id,3_exp,3_hp,3_mp,3_tp,3_strength,3_dexterity,3_spells FROM {{table}} ORDER BY id", "levels"); $spellsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "spells"); $spells = array(); -while ($spellsrow = mysql_fetch_array($spellsquery)) { +while ($spellsrow = mysqli_fetch_array($spellsquery)) { $spells[$spellsrow["id"]] = $spellsrow; } -while ($itemsrow = mysql_fetch_array($itemsquery)) { +while ($itemsrow = mysqli_fetch_array($itemsquery)) { if ($count == 1) { $color = "bgcolor=\"#ffffff\""; $count = 2; } else { $color = ""; $count = 1; } if ($itemsrow["3_spells"] != 0) { $spell = $spells[$itemsrow["3_spells"]]["name"]; } else { $spell = "None"; } if ($itemsrow["id"] != 100) { echo "\n"; } diff --git a/help_monsters.php b/help_monsters.php index ac15f54..9b23c3a 100644 --- a/help_monsters.php +++ b/help_monsters.php @@ -2,7 +2,7 @@ include('lib.php'); $link = opendb(); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); ob_start("ob_gzhandler"); ?> @@ -81,7 +81,7 @@ a:hover { None"; } elseif ($itemsrow["immune"] == 1) { $immune = "Hurt"; } else { $immune = "Hurt & Sleep"; } echo "\n"; diff --git a/help_spells.php b/help_spells.php index 42866a2..39d783f 100644 --- a/help_spells.php +++ b/help_spells.php @@ -2,7 +2,7 @@ include('lib.php'); $link = opendb(); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); -$controlrow = mysql_fetch_array($controlquery); +$controlrow = mysqli_fetch_array($controlquery); ob_start("ob_gzhandler"); ?> @@ -81,7 +81,7 @@ a:hover {
Forum :: ".$row2["title"]."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."
".$itemsrow["id"]."".number_format($itemsrow["1_exp"])."".$itemsrow["1_hp"]."".$itemsrow["1_mp"]."".$itemsrow["1_tp"]."".$itemsrow["1_strength"]."".$itemsrow["1_dexterity"]."$spell
".$itemsrow["id"]."".number_format($itemsrow["2_exp"])."".$itemsrow["2_hp"]."".$itemsrow["2_mp"]."".$itemsrow["2_tp"]."".$itemsrow["2_strength"]."".$itemsrow["2_dexterity"]."$spell
".$itemsrow["id"]."".number_format($itemsrow["3_exp"])."".$itemsrow["3_hp"]."".$itemsrow["3_mp"]."".$itemsrow["3_tp"]."".$itemsrow["3_strength"]."".$itemsrow["3_dexterity"]."$spell
".$itemsrow["name"]."".$itemsrow["maxhp"]."".$itemsrow["maxdam"]."".$itemsrow["armor"]."".$itemsrow["level"]."".$itemsrow["maxexp"]."".$itemsrow["maxgold"]."$immune
Latest News
\n"; $townrow["news"] .= "[".prettydate($newsrow["postdate"])."]
".nl2br($newsrow["content"]); $townrow["news"] .= "
\n"; @@ -96,8 +96,8 @@ function dotown() { // Spit out the main town page. if ($controlrow["showonline"] == 1) { $onlinequery = doquery("SELECT * FROM {{table}} WHERE UNIX_TIMESTAMP(onlinetime) >= '".(time()-600)."' ORDER BY charname", "users"); $townrow["whosonline"] = "
Who's Online
\n"; - $townrow["whosonline"] .= "There are " . mysql_num_rows($onlinequery) . " user(s) online within the last 10 minutes: "; - while ($onlinerow = mysql_fetch_array($onlinequery)) { $townrow["whosonline"] .= "".$onlinerow["charname"]."" . ", "; } + $townrow["whosonline"] .= "There are " . mysqli_num_rows($onlinequery) . " user(s) online within the last 10 minutes: "; + while ($onlinerow = mysqli_fetch_array($onlinequery)) { $townrow["whosonline"] .= "".$onlinerow["charname"]."" . ", "; } $townrow["whosonline"] = rtrim($townrow["whosonline"], ", "); $townrow["whosonline"] .= "
\n"; } else { $townrow["whosonline"] = ""; } @@ -157,7 +157,7 @@ function showchar() { } else { $userrow["plusgold"] = ""; } $levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels"); - $levelrow = mysql_fetch_array($levelquery); + $levelrow = mysqli_fetch_array($levelquery); if ($userrow["level"] < 99) { $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); } else { $userrow["nextlevel"] = "None"; } if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; } @@ -171,7 +171,7 @@ function showchar() { $spellquery = doquery("SELECT id,name FROM {{table}}","spells"); $userspells = explode(",",$userrow["spells"]); $userrow["magiclist"] = ""; - while ($spellrow = mysql_fetch_array($spellquery)) { + while ($spellrow = mysqli_fetch_array($spellquery)) { $spell = false; foreach($userspells as $a => $b) { if ($b == $spellrow["id"]) { $spell = true; } @@ -199,7 +199,7 @@ function onlinechar($id) { global $controlrow; $userquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "users"); - if (mysql_num_rows($userquery) == 1) { $userrow = mysql_fetch_array($userquery); } else { display("No such user.", "Error"); } + if (mysqli_num_rows($userquery) == 1) { $userrow = mysqli_fetch_array($userquery); } else { display("No such user.", "Error"); } // Format various userrow stuffs. $userrow["experience"] = number_format($userrow["experience"]); @@ -216,7 +216,7 @@ function onlinechar($id) { } else { $userrow["plusgold"] = ""; } $levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels"); - $levelrow = mysql_fetch_array($levelquery); + $levelrow = mysqli_fetch_array($levelquery); $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; } @@ -264,7 +264,7 @@ function babblebox() { $babblebox = array("content"=>""); $bg = 1; $babblequery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 20", "babble"); - while ($babblerow = mysql_fetch_array($babblequery)) { + while ($babblerow = mysqli_fetch_array($babblequery)) { if ($bg == 1) { $new = "
[".$babblerow["author"]."] ".$babblerow["babble"]."
\n"; $bg = 2; } else { $new = "
[".$babblerow["author"]."] ".stripslashes($babblerow["babble"])."
\n"; $bg = 1; } $babblebox["content"] = $new . $babblebox["content"]; diff --git a/install.php b/install.php index d956bfc..1ca787f 100644 --- a/install.php +++ b/install.php @@ -20,7 +20,7 @@ function dobatch ($p_query) { foreach ($query_split as $command_line) { $command_line = trim($command_line); if ($command_line != '') { - $query_result = mysql_query($command_line); + $query_result = mysqli_query(opendb(), $command_line); if ($query_result == 0) { break; }; @@ -83,7 +83,7 @@ CREATE TABLE `$babble` ( `author` varchar(30) NOT NULL default '', `babble` varchar(120) NOT NULL default '', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Babble Box table created.
"; } else { echo "Error creating Babble Box table."; } unset($query); @@ -113,7 +113,7 @@ CREATE TABLE `$control` ( `showbabble` tinyint(3) unsigned NOT NULL default '0', `showonline` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Control table created.
"; } else { echo "Error creating Control table."; } @@ -134,7 +134,7 @@ CREATE TABLE `$drops` ( `attribute1` varchar(30) NOT NULL default '', `attribute2` varchar(30) NOT NULL default '', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Drops table created.
"; } else { echo "Error creating Drops table."; } unset($query); @@ -189,7 +189,7 @@ CREATE TABLE `$forum` ( `title` varchar(100) NOT NULL default '', `content` text NOT NULL, PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Forum table created.
"; } else { echo "Error creating Forum table."; } unset($query); @@ -203,7 +203,7 @@ CREATE TABLE `$items` ( `attribute` smallint(5) unsigned NOT NULL default '0', `special` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Items table created.
"; } else { echo "Error creating Items table."; } unset($query); @@ -273,7 +273,7 @@ CREATE TABLE `$levels` ( `3_dexterity` smallint(5) unsigned NOT NULL default '0', `3_spells` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Levels table created.
"; } else { echo "Error creating Levels table."; } unset($query); @@ -397,7 +397,7 @@ CREATE TABLE `$monsters` ( `maxgold` smallint(5) unsigned NOT NULL default '0', `immune` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Monsters table created.
"; } else { echo "Error creating Monsters table."; } unset($query); @@ -566,7 +566,7 @@ CREATE TABLE `$news` ( `postdate` datetime NOT NULL default '0000-00-00 00:00:00', `content` text NOT NULL, PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "News table created.
"; } else { echo "Error creating News table."; } unset($query); @@ -585,7 +585,7 @@ CREATE TABLE `$spells` ( `attribute` smallint(5) unsigned NOT NULL default '0', `type` smallint(5) unsigned NOT NULL default '0', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Spells table created.
"; } else { echo "Error creating Spells table."; } unset($query); @@ -627,7 +627,7 @@ CREATE TABLE `$towns` ( `travelpoints` smallint(5) unsigned NOT NULL default '0', `itemslist` text NOT NULL, PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Towns table created.
"; } else { echo "Error creating Towns table."; } unset($query); @@ -701,7 +701,7 @@ CREATE TABLE `$users` ( `spells` varchar(50) NOT NULL default '0', `towns` varchar(50) NOT NULL default '0', PRIMARY KEY (`id`) -) TYPE=MyISAM; +); END; if (dobatch($query) == 1) { echo "Users table created.
"; } else { echo "Error creating Users table."; } unset($query); @@ -759,7 +759,7 @@ function fourth() { // Final page: insert new user row, congratulate the person global $dbsettings; $users = $dbsettings["prefix"] . "_users"; - $query = mysql_query("INSERT INTO $users SET id='1',username='$username',password='$password',email='$email1',verify='1',charname='$charname',charclass='$charclass',regdate=NOW(),onlinetime=NOW(),authlevel='1'") or die(mysql_error()); + $query = mysqli_query(opendb(), "INSERT INTO $users SET id='1',username='$username',password='$password',email='$email1',verify='1',charname='$charname',charclass='$charclass',regdate=NOW(),onlinetime=NOW(),authlevel='1'") or die(mysql_error()); $page = << @@ -809,4 +809,4 @@ END; } -?> \ No newline at end of file +?> \ No newline at end of file diff --git a/lib.php b/lib.php index 32af9f5..b7b33b5 100644 --- a/lib.php +++ b/lib.php @@ -5,15 +5,6 @@ $numqueries = 0; $version = "1.1.11"; $build = ""; -// Handling for servers with magic_quotes turned on. -// Example from php.net. -if (get_magic_quotes_gpc()) { - - $_POST = array_map('stripslashes_deep', $_POST); - $_GET = array_map('stripslashes_deep', $_GET); - $_COOKIE = array_map('stripslashes_deep', $_COOKIE); - -} $_POST = array_map('addslashes_deep', $_POST); $_POST = array_map('html_deep', $_POST); $_GET = array_map('addslashes_deep', $_GET); @@ -49,23 +40,37 @@ function html_deep($value) { } function opendb() { // Open database connection. - include('config.php'); extract($dbsettings); - $link = mysql_connect($server, $user, $pass) or die(mysql_error()); - mysql_select_db($name) or die(mysql_error()); - return $link; + // Créer une connexion à la base de données + $link = mysqli_connect($server, $user, $pass, $name); + + // Vérifier la connexion + if (!$link) { + die("Connection failed: " . mysqli_connect_error()); + } + + return $link; } function doquery($query, $table) { // Something of a tiny little database abstraction layer. - include('config.php'); global $numqueries; - $sqlquery = mysql_query(str_replace("{{table}}", $dbsettings["prefix"] . "_" . $table, $query)) or die(mysql_error()); + + // Remplacer {{table}} par le préfixe de la table + $query = str_replace("{{table}}", $dbsettings["prefix"] . "_" . $table, $query); + + // Exécuter la requête + $sqlquery = mysqli_query(opendb(), $query); + + // Vérifier les erreurs de requête + if (!$sqlquery) { + die("Query failed: " . mysqli_error(opendb())); + } + $numqueries++; return $sqlquery; - } function gettemplate($templatename) { // SQL query for the template. @@ -127,7 +132,7 @@ function admindisplay($content, $title) { // Finalize page and output to browser global $numqueries, $userrow, $controlrow, $starttime, $version, $build; if (!isset($controlrow)) { $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); - $controlrow = mysql_fetch_array($controlquery); + $controlrow = mysqli_fetch_array($controlquery); } $template = gettemplate("admin"); @@ -158,7 +163,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, global $numqueries, $userrow, $controlrow, $version, $build; if (!isset($controlrow)) { $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); - $controlrow = mysql_fetch_array($controlquery); + $controlrow = mysqli_fetch_array($controlquery); } if ($badstart == false) { global $starttime; } else { $starttime = $badstart; } @@ -182,12 +187,12 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, // Get userrow again, in case something has been updated. $userquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["id"]."' LIMIT 1", "users"); unset($userrow); - $userrow = mysql_fetch_array($userquery); + $userrow = mysqli_fetch_array($userquery); // Current town name. if ($userrow["currentaction"] == "In Town") { $townquery = doquery("SELECT * FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns"); - $townrow = mysql_fetch_array($townquery); + $townrow = mysqli_fetch_array($townquery); $userrow["currenttown"] = "Welcome to ".$townrow["name"].".

"; } else { $userrow["currenttown"] = ""; @@ -234,7 +239,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, $spellquery = doquery("SELECT id,name,type FROM {{table}}","spells"); $userspells = explode(",",$userrow["spells"]); $userrow["magiclist"] = ""; - while ($spellrow = mysql_fetch_array($spellquery)) { + while ($spellrow = mysqli_fetch_array($spellquery)) { $spell = false; foreach($userspells as $a => $b) { if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; } @@ -249,7 +254,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, $townslist = explode(",",$userrow["towns"]); $townquery2 = doquery("SELECT * FROM {{table}} ORDER BY id", "towns"); $userrow["townslist"] = ""; - while ($townrow2 = mysql_fetch_array($townquery2)) { + while ($townrow2 = mysqli_fetch_array($townquery2)) { $town = false; foreach($townslist as $a => $b) { if ($b == $townrow2["id"]) { $town = true; } diff --git a/login.php b/login.php index d056fb9..f6650f0 100644 --- a/login.php +++ b/login.php @@ -14,8 +14,8 @@ function login() { if (isset($_POST["submit"])) { $query = doquery("SELECT * FROM {{table}} WHERE username='".$_POST["username"]."' AND password='".md5($_POST["password"])."' LIMIT 1", "users"); - if (mysql_num_rows($query) != 1) { die("Invalid username or password. Please go back and try again."); } - $row = mysql_fetch_array($query); + if (mysqli_num_rows($query) != 1) { die("Invalid username or password. Please go back and try again."); } + $row = mysqli_fetch_array($query); if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; } $cookie = $row["id"] . " " . $row["username"] . " " . md5($row["password"] . "--" . $dbsettings["secretword"]) . " " . $rememberme; setcookie("dkgame", $cookie, $expiretime, "/", "", 0); diff --git a/towns.php b/towns.php index 8481e79..0f670cf 100644 --- a/towns.php +++ b/towns.php @@ -5,8 +5,8 @@ function inn() { // Staying at the inn resets all expendable stats to their max global $userrow, $numqueries; $townquery = doquery("SELECT name,innprice FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns"); - if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } - $townrow = mysql_fetch_array($townquery); + if (mysqli_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } + $townrow = mysqli_fetch_array($townquery); if ($userrow["gold"] < $townrow["innprice"]) { display("You do not have enough gold to stay at this Inn tonight.

You may return to town, or use the direction buttons on the left to start exploring.", "Inn"); die(); } @@ -41,8 +41,8 @@ function buy() { // Displays a list of available items for purchase. global $userrow, $numqueries; $townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns"); - if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } - $townrow = mysql_fetch_array($townquery); + if (mysqli_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } + $townrow = mysqli_fetch_array($townquery); $itemslist = explode(",",$townrow["itemslist"]); $querystring = ""; @@ -54,7 +54,7 @@ function buy() { // Displays a list of available items for purchase. $itemsquery = doquery("SELECT * FROM {{table}} WHERE $querystring ORDER BY id", "items"); $page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.

Click an item name to purchase it.

The following items are available at this town:

\n"; $page .= "\n"; - while ($itemsrow = mysql_fetch_array($itemsquery)) { + while ($itemsrow = mysqli_fetch_array($itemsquery)) { if ($itemsrow["type"] == 1) { $attrib = "Attack Power:"; } else { $attrib = "Defense Power:"; } $page .= ""; } @@ -80,20 +80,20 @@ function buy2($id) { // Confirm user's intent to purchase item. global $userrow, $numqueries; $townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns"); - if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } - $townrow = mysql_fetch_array($townquery); + if (mysqli_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } + $townrow = mysqli_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items"); - $itemsrow = mysql_fetch_array($itemsquery); + $itemsrow = mysqli_fetch_array($itemsquery); if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.

You may return to town, store, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); } if ($itemsrow["type"] == 1) { if ($userrow["weaponid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); $page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?

"; } else { $page = "You are buying the ".$itemsrow["name"].", is that ok?

"; @@ -101,7 +101,7 @@ function buy2($id) { // Confirm user's intent to purchase item. } elseif ($itemsrow["type"] == 2) { if ($userrow["armorid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); $page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?

"; } else { $page = "You are buying the ".$itemsrow["name"].", is that ok?

"; @@ -109,7 +109,7 @@ function buy2($id) { // Confirm user's intent to purchase item. } elseif ($itemsrow["type"] == 3) { if ($userrow["shieldid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); $page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?

"; } else { $page = "You are buying the ".$itemsrow["name"].", is that ok?

"; @@ -128,13 +128,13 @@ function buy3($id) { // Update user profile with new item & stats. global $userrow; $townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns"); - if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } - $townrow = mysql_fetch_array($townquery); + if (mysqli_num_rows($townquery) != 1) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } + $townrow = mysqli_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { display("Cheat attempt detected.

Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items"); - $itemsrow = mysql_fetch_array($itemsquery); + $itemsrow = mysqli_fetch_array($itemsquery); if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.

You may return to town, store, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); } @@ -143,7 +143,7 @@ function buy3($id) { // Update user profile with new item & stats. // Check if they already have an item in the slot. if ($userrow["weaponid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); } else { $itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X"); } @@ -186,7 +186,7 @@ function buy3($id) { // Update user profile with new item & stats. // Check if they already have an item in the slot. if ($userrow["armorid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); } else { $itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X"); } @@ -229,7 +229,7 @@ function buy3($id) { // Update user profile with new item & stats. // Check if they already have an item in the slot. if ($userrow["shieldid"] != 0) { $itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items"); - $itemsrow2 = mysql_fetch_array($itemsquery2); + $itemsrow2 = mysqli_fetch_array($itemsquery2); } else { $itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X"); } @@ -284,7 +284,7 @@ function maps() { // List maps the user can buy. $page .= "
"; if ($itemsrow["type"] == 1) { $page .= "\"weapon\"
\n"; $townquery = doquery("SELECT * FROM {{table}} ORDER BY id", "towns"); - while ($townrow = mysql_fetch_array($townquery)) { + while ($townrow = mysqli_fetch_array($townquery)) { if ($townrow["latitude"] >= 0) { $latitude = $townrow["latitude"] . "N,"; } else { $latitude = ($townrow["latitude"]*-1) . "S,"; } if ($townrow["longitude"] >= 0) { $longitude = $townrow["longitude"] . "E"; } else { $longitude = ($townrow["longitude"]*-1) . "W"; } @@ -313,7 +313,7 @@ function maps2($id) { // Confirm user's intent to purchase map. global $userrow, $numqueries; $townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns"); - $townrow = mysql_fetch_array($townquery); + $townrow = mysqli_fetch_array($townquery); if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.

You may return to town, store, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); } @@ -330,7 +330,7 @@ function maps3($id) { // Add new map to user's profile. global $userrow, $numqueries; $townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns"); - $townrow = mysql_fetch_array($townquery); + $townrow = mysqli_fetch_array($townquery); if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.

You may return to town, store, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); } @@ -350,7 +350,7 @@ function travelto($id, $usepoints=true) { // Send a user to a town from the Trav if ($userrow["currentaction"] == "Fighting") { header("Location: index.php?do=fight"); die(); } $townquery = doquery("SELECT name,travelpoints,latitude,longitude FROM {{table}} WHERE id='$id' LIMIT 1", "towns"); - $townrow = mysql_fetch_array($townquery); + $townrow = mysqli_fetch_array($townquery); if ($usepoints==true) { if ($userrow["currenttp"] < $townrow["travelpoints"]) { diff --git a/upgrade_to_110.php b/upgrade_to_110.php index d0f1c3f..e535847 100644 --- a/upgrade_to_110.php +++ b/upgrade_to_110.php @@ -63,7 +63,7 @@ unset($query); $query = mysql_query("SELECT * FROM $users ORDER BY id") or die(mysql_error()); $errors = 0; $errorlist = ""; -while ($row = mysql_fetch_array($query)) { +while ($row = mysqli_fetch_array($query)) { $id = $row["id"]; $oldspells = explode(",",$row["spells"]); $newspells = "0,"; diff --git a/upgrade_to_112.php b/upgrade_to_112.php index ed59beb..d041880 100644 --- a/upgrade_to_112.php +++ b/upgrade_to_112.php @@ -331,7 +331,7 @@ $levels["3"] = array( $errors = 0; $errorlist = ""; $mainquery = mysql_query("SELECT id,level,charclass,spells FROM $users ORDER BY id"); -while ($mainrow = mysql_fetch_array($mainquery)) { +while ($mainrow = mysqli_fetch_array($mainquery)) { $level = $mainrow["level"]; $charclass = $mainrow["charclass"]; $newspell = $levels[$charclass][$level]; diff --git a/users.php b/users.php index 4f2826b..aadde92 100644 --- a/users.php +++ b/users.php @@ -16,7 +16,7 @@ if (isset($_GET["do"])) { function register() { // Register a new account. $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); - $controlrow = mysql_fetch_array($controlquery); + $controlrow = mysqli_fetch_array($controlquery); if (isset($_POST["submit"])) { @@ -28,20 +28,20 @@ function register() { // Register a new account. if ($username == "") { $errors++; $errorlist .= "Username field is required.
"; } if (preg_match("/[^A-z0-9_\-]/", $username)==1) { $errors++; $errorlist .= "Username must be alphanumeric.
"; } // Thanks to "Carlos Pires" from php.net! $usernamequery = doquery("SELECT username FROM {{table}} WHERE username='$username' LIMIT 1","users"); - if (mysql_num_rows($usernamequery) > 0) { $errors++; $errorlist .= "Username already taken - unique username required.
"; } + if (mysqli_num_rows($usernamequery) > 0) { $errors++; $errorlist .= "Username already taken - unique username required.
"; } // Process charname. if ($charname == "") { $errors++; $errorlist .= "Character Name field is required.
"; } if (preg_match("/[^A-z0-9_\-]/", $charname)==1) { $errors++; $errorlist .= "Character Name must be alphanumeric.
"; } // Thanks to "Carlos Pires" from php.net! $characternamequery = doquery("SELECT charname FROM {{table}} WHERE charname='$charname' LIMIT 1","users"); - if (mysql_num_rows($characternamequery) > 0) { $errors++; $errorlist .= "Character Name already taken - unique Character Name required.
"; } + if (mysqli_num_rows($characternamequery) > 0) { $errors++; $errorlist .= "Character Name already taken - unique Character Name required.
"; } // Process email address. if ($email1 == "" || $email2 == "") { $errors++; $errorlist .= "Email fields are required.
"; } if ($email1 != $email2) { $errors++; $errorlist .= "Emails don't match.
"; } if (! is_email($email1)) { $errors++; $errorlist .= "Email isn't valid.
"; } $emailquery = doquery("SELECT email FROM {{table}} WHERE email='$email1' LIMIT 1","users"); - if (mysql_num_rows($emailquery) > 0) { $errors++; $errorlist .= "Email already taken - unique email address required.
"; } + if (mysqli_num_rows($emailquery) > 0) { $errors++; $errorlist .= "Email already taken - unique email address required.
"; } // Process password. if (trim($password1) == "") { $errors++; $errorlist .= "Password field is required.
"; } @@ -100,8 +100,8 @@ function verify() { if (isset($_POST["submit"])) { extract($_POST); $userquery = doquery("SELECT username,email,verify FROM {{table}} WHERE username='$username' LIMIT 1","users"); - if (mysql_num_rows($userquery) != 1) { die("No account with that username."); } - $userrow = mysql_fetch_array($userquery); + if (mysqli_num_rows($userquery) != 1) { die("No account with that username."); } + $userrow = mysqli_fetch_array($userquery); if ($userrow["verify"] == 1) { die("Your account is already verified."); } if ($userrow["email"] != $email) { die("Incorrect email address."); } if ($userrow["verify"] != $verify) { die("Incorrect verification code."); } @@ -120,7 +120,7 @@ function lostpassword() { if (isset($_POST["submit"])) { extract($_POST); $userquery = doquery("SELECT email FROM {{table}} WHERE email='$email' LIMIT 1","users"); - if (mysql_num_rows($userquery) != 1) { die("No account with that email address."); } + if (mysqli_num_rows($userquery) != 1) { die("No account with that email address."); } $newpass = ""; for ($i=0; $i<8; $i++) { $newpass .= chr(rand(65,90)); @@ -145,8 +145,8 @@ function changepassword() { if (isset($_POST["submit"])) { extract($_POST); $userquery = doquery("SELECT * FROM {{table}} WHERE username='$username' LIMIT 1","users"); - if (mysql_num_rows($userquery) != 1) { die("No account with that username."); } - $userrow = mysql_fetch_array($userquery); + if (mysqli_num_rows($userquery) != 1) { die("No account with that username."); } + $userrow = mysqli_fetch_array($userquery); if ($userrow["password"] != md5($oldpass)) { die("The old password you provided was incorrect."); } if (preg_match("/[^A-z0-9_\-]/", $newpass1)==1) { die("New password must be alphanumeric."); } // Thanks to "Carlos Pires" from php.net! if ($newpass1 != $newpass2) { die("New passwords don't match."); } @@ -165,7 +165,7 @@ function changepassword() { function sendpassemail($emailaddress, $password) { $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); - $controlrow = mysql_fetch_array($controlquery); + $controlrow = mysqli_fetch_array($controlquery); extract($controlrow); $email = <<