From 7e9ce285e0ba9da18adeaae91a30ddd1c81a7b9f Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 12 Dec 2024 12:34:35 -0600 Subject: [PATCH] Restore forum functionality, remove forum settings from control --- public/admin.php | 11 +-- public/forum.php | 145 +++++++++++++++++++---------------- public/install.php | 2 - public/login.php | 2 + public/users.php | 2 +- src/lib.php | 4 +- templates/changepassword.php | 6 +- 7 files changed, 85 insertions(+), 87 deletions(-) diff --git a/public/admin.php b/public/admin.php index a5a2f77..cab4872 100644 --- a/public/admin.php +++ b/public/admin.php @@ -47,13 +47,12 @@ function main() { if ($gamename == "") { $errors++; $errorlist .= "Game name is required.
"; } if (($gamesize % 5) != 0) { $errors++; $errorlist .= "Map size must be divisible by five.
"; } if (!is_numeric($gamesize)) { $errors++; $errorlist .= "Map size must be a number.
"; } - if ($forumtype == 2 && $forumaddress == "") { $errors++; $errorlist .= "You must specify a forum address when using the External setting.
"; } if ($class1name == "") { $errors++; $errorlist .= "Class 1 name is required.
"; } if ($class2name == "") { $errors++; $errorlist .= "Class 2 name is required.
"; } if ($class3name == "") { $errors++; $errorlist .= "Class 3 name is required.
"; } if ($errors == 0) { - $query = doquery("UPDATE {{table}} SET gamename='$gamename',gamesize='$gamesize',forumtype='$forumtype',forumaddress='$forumaddress',compression='$compression',class1name='$class1name',class2name='$class2name',class3name='$class3name',diff1name='$diff1name',diff2name='$diff2name',diff3name='$diff3name',diff2mod='$diff2mod',diff3mod='$diff3mod',gameopen='$gameopen',verifyemail='$verifyemail',gameurl='$gameurl',adminemail='$adminemail',shownews='$shownews',showonline='$showonline',showbabble='$showbabble' WHERE id='1' LIMIT 1", "control"); + $query = doquery("UPDATE {{table}} SET gamename='$gamename',gamesize='$gamesize',class1name='$class1name',class2name='$class2name',class3name='$class3name',gameopen='$gameopen',verifyemail='$verifyemail',gameurl='$gameurl',adminemail='$adminemail',shownews='$shownews',showonline='$showonline',showbabble='$showbabble' WHERE id='1' LIMIT 1", "control"); admindisplay("Settings updated.","Main Settings"); } else { admindisplay("Errors:
$errorlist

Please go back and try again.", "Main Settings"); @@ -72,9 +71,6 @@ These options control several major settings for the overall game engine.

Game URL:
Please specify the full URL to your game installation ("http://www.server.com/dkpath/index.php"). This gets used in the registration email sent to users. If you leave this field blank or incorrect, users may not be able to register correctly. Admin Email:
Please specify your email address. This gets used when the game has to send an email to users. Map Size:
Default is 250. This is the size of each map quadrant. Note that monster levels increase every 5 spaces, so you should ensure that you have at least (map size / 5) monster levels total, otherwise there will be parts of the map without any monsters, or some monsters won't ever get used. Ex: with a map size of 250, you should have 50 monster levels total. -Forum Type:
'Disabled' removes the forum link. 'Internal' uses the built-in (and very stripped-down) forum program included with Dragon Knight, if you don't have your own forums software already installed. 'External' uses the address provided below and links to your own forums software. -External Forum:
If the above value is set to 'External,' please specify the complete URL to your forums here. -Page Compression:
Enable page compression if it is supported by your server, and this will greatly reduce the amount of bandwidth required by the game. Email Verification:
Make users verify their email address for added security. Show News:
Toggle display of the Latest News box in towns. Show Who's Online:
Toggle display of the Who's Online box in towns. @@ -87,11 +83,6 @@ These options control several major settings for the overall game engine.

END; - if ($controlrow["forumtype"] == 0) { $controlrow["selecttype0"] = "selected=\"selected\" "; } else { $controlrow["selecttype0"] = ""; } - if ($controlrow["forumtype"] == 1) { $controlrow["selecttype1"] = "selected=\"selected\" "; } else { $controlrow["selecttype1"] = ""; } - if ($controlrow["forumtype"] == 2) { $controlrow["selecttype2"] = "selected=\"selected\" "; } else { $controlrow["selecttype2"] = ""; } - if ($controlrow["compression"] == 0) { $controlrow["selectcomp0"] = "selected=\"selected\" "; } else { $controlrow["selectcomp0"] = ""; } - if ($controlrow["compression"] == 1) { $controlrow["selectcomp1"] = "selected=\"selected\" "; } else { $controlrow["selectcomp1"] = ""; } if ($controlrow["verifyemail"] == 0) { $controlrow["selectverify0"] = "selected=\"selected\" "; } else { $controlrow["selectverify0"] = ""; } if ($controlrow["verifyemail"] == 1) { $controlrow["selectverify1"] = "selected=\"selected\" "; } else { $controlrow["selectverify1"] = ""; } if ($controlrow["shownews"] == 0) { $controlrow["selectnews0"] = "selected=\"selected\" "; } else { $controlrow["selectnews0"] = ""; } diff --git a/public/forum.php b/public/forum.php index 0cdf8dd..98d801b 100644 --- a/public/forum.php +++ b/public/forum.php @@ -1,102 +1,111 @@ - showthread($do[1], $do[2]), + 'new' => newthread(), + 'reply' => reply(), + 'list' => donothing($do[1]), + default => donothing() +}; - if ($do[0] == "thread") { showthread($do[1], $do[2]); } - elseif ($do[0] == "new") { newthread(); } - elseif ($do[0] == "reply") { reply(); } - elseif ($do[0] == "list") { donothing($do[1]); } - -} else { donothing(0); } - -function donothing($start=0) { - - $query = doquery("SELECT * FROM {{table}} WHERE parent='0' ORDER BY newpostdate DESC LIMIT 20", "forum"); +function donothing($start = 0) +{ + $query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]); $page = "
\n"; - $count = 1; - if (mysql_num_rows($query) == 0) { - $page .= "\n"; - } else { - while ($row = mysql_fetch_array($query)) { - if ($count == 1) { - $page .= "\n"; - $count = 2; - } else { - $page .= "\n"; - $count = 1; - } - } + + $hasRows = false; + + while ($row = $query->fetchArray(SQLITE3_ASSOC)) { + $hasRows = true; + $page .= "\n"; } + + if (!$hasRows) { + $page .= "\n"; + } + $page .= "
New Thread
ThreadRepliesLast Post
No threads in forum.
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
No threads in forum.
"; display($page, "Forum"); - } -function showthread($id, $start) { +function showthread($id, $start) +{ + $posts = db()->query('SELECT * FROM forum WHERE id=? OR parent=? ORDER BY id LIMIT 15 OFFSET ?;', [$id, $id, $start * 15]); + $title = db()->query('SELECT title FROM forum WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC); - $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); - $page = " - - - + + +
\n"; - $count = 1; - while ($row = mysql_fetch_array($query)) { - if ($count == 1) { - $page .= "\n"; - $count = 2; - } else { - $page .= "\n"; - $count = 1; - } + $page = "
Forum :: ".$row2["title"]."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."
\n"; + while ($row = $posts->fetchArray(SQLITE3_ASSOC)) { + $page .= "\n"; } $page .= "
Forum :: ".$title['title']."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."

"; - $page .= "
Reply To This Thread:

"; + $page .= "
Reply To This Thread:

"; display($page, "Forum"); - } -function reply() { - +function reply() +{ global $userrow; - extract($_POST); - $query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["username"]."',parent='$parent',replies='0',title='$title',content='$content'", "forum"); - $query2 = doquery("UPDATE {{table}} SET newpostdate=NOW(),replies=replies+1 WHERE id='$parent' LIMIT 1", "forum"); - header("Location: forum.php?do=thread:$parent:0"); - die(); + $p = $_POST['parent'] ?? 0; + $t = trim($_POST['title'] ?? ''); + $c = trim($_POST['content'] ?? ''); + + db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [$userrow['username'], $t, $c, $p]); + db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$p]); + redirect("forum.php?do=thread:$p:0"); } -function newthread() { - +function newthread() +{ global $userrow; if (isset($_POST["submit"])) { extract($_POST); - $query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["username"]."',parent='0',replies='0',title='$title',content='$content'", "forum"); - header("Location: forum.php"); - die(); + $t = trim($_POST['title'] ?? ''); + $c = trim($_POST['content'] ?? ''); + db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [$userrow['username'], $t, $c]); + redirect('forum.php'); } $page = "
Make A New Post:

Title:


Message:


"; display($page, "Forum"); - } - -?> diff --git a/public/install.php b/public/install.php index e2ef74b..deebaec 100644 --- a/public/install.php +++ b/public/install.php @@ -73,8 +73,6 @@ function second() `gameopen` INTEGER NOT NULL DEFAULT 0, `gameurl` TEXT NOT NULL DEFAULT '', `adminemail` TEXT NOT NULL DEFAULT '', - `forumtype` INTEGER NOT NULL DEFAULT 0, - `forumaddress` TEXT NOT NULL DEFAULT '', `class1name` TEXT NOT NULL DEFAULT '', `class2name` TEXT NOT NULL DEFAULT '', `class3name` TEXT NOT NULL DEFAULT '', diff --git a/public/login.php b/public/login.php index c57fd39..c586429 100644 --- a/public/login.php +++ b/public/login.php @@ -13,6 +13,8 @@ match ($_GET['do'] ?? 'login') { function login() { + if (checkcookies() !== false) redirect('index.php'); + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $u = trim($_POST['username'] ?? ''); diff --git a/public/users.php b/public/users.php index 7a89a48..a70e627 100644 --- a/public/users.php +++ b/public/users.php @@ -167,7 +167,7 @@ function changepassword() } $realnewpass = password_hash($np, PASSWORD_ARGON2ID); - db()->query('UPDATE users SET password=? WHERE username=?;', [$u]); + db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]); set_cookie('dkgame', '', -3600); diff --git a/src/lib.php b/src/lib.php index a919b9d..c9789cf 100644 --- a/src/lib.php +++ b/src/lib.php @@ -132,9 +132,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, $userrow["currenttown"] = ""; } - if ($controlrow["forumtype"] == 0) { $userrow["forumslink"] = ""; } - elseif ($controlrow["forumtype"] == 1) { $userrow["forumslink"] = "Forum
"; } - elseif ($controlrow["forumtype"] == 2) { $userrow["forumslink"] = "Forum
"; } + $userrow["forumslink"] = "Forum
"; // Format various userrow stuffs... if ($userrow["latitude"] < 0) { $userrow["latitude"] = $userrow["latitude"] * -1 . "S"; } else { $userrow["latitude"] .= "N"; } diff --git a/templates/changepassword.php b/templates/changepassword.php index b23cba8..7852c84 100644 --- a/templates/changepassword.php +++ b/templates/changepassword.php @@ -4,9 +4,9 @@ $template = <<
Use the form below to change your password. All fields are required. New passwords must be 10 alphanumeric characters or less.
Username:
Old Password:
New Password:
Verify New Password:


Old Password:
New Password:
Verify New Password: