Restore forum functionality, remove forum settings from control

This commit is contained in:
Sky Johnson 2024-12-12 12:34:35 -06:00
parent b4d188de16
commit 7e9ce285e0
7 changed files with 85 additions and 87 deletions

View File

@ -47,13 +47,12 @@ function main() {
if ($gamename == "") { $errors++; $errorlist .= "Game name is required.<br>"; }
if (($gamesize % 5) != 0) { $errors++; $errorlist .= "Map size must be divisible by five.<br>"; }
if (!is_numeric($gamesize)) { $errors++; $errorlist .= "Map size must be a number.<br>"; }
if ($forumtype == 2 && $forumaddress == "") { $errors++; $errorlist .= "You must specify a forum address when using the External setting.<br>"; }
if ($class1name == "") { $errors++; $errorlist .= "Class 1 name is required.<br>"; }
if ($class2name == "") { $errors++; $errorlist .= "Class 2 name is required.<br>"; }
if ($class3name == "") { $errors++; $errorlist .= "Class 3 name is required.<br>"; }
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("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Main Settings");
@ -72,9 +71,6 @@ These options control several major settings for the overall game engine.<br><br
<tr><td width="20%">Game URL:</td><td><input type="text" name="gameurl" size="50" maxlength="100" value="{{gameurl}}" /><br><span class="small">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.</span></td></tr>
<tr><td width="20%">Admin Email:</td><td><input type="text" name="adminemail" size="30" maxlength="100" value="{{adminemail}}" /><br><span class="small">Please specify your email address. This gets used when the game has to send an email to users.</span></td></tr>
<tr><td width="20%">Map Size:</td><td><input type="text" name="gamesize" size="3" maxlength="3" value="{{gamesize}}" /><br><span class="small">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.</span></td></tr>
<tr><td width="20%">Forum Type:</td><td><select name="forumtype"><option value="0" {{selecttype0}}>Disabled</option><option value="1" {{selecttype1}}>Internal</option><option value="2" {{selecttype2}}>External</option></select><br><span class="small">'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.</span></td></tr>
<tr><td width="20%">External Forum:</td><td><input type="text" name="forumaddress" size="30" maxlength="200" value="{{forumaddress}}" /><br><span class="small">If the above value is set to 'External,' please specify the complete URL to your forums here.</span></td></tr>
<tr><td width="20%">Page Compression:</td><td><select name="compression"><option value="0" {{selectcomp0}}>Disabled</option><option value="1" {{selectcomp1}}>Enabled</option></select><br><span class="small">Enable page compression if it is supported by your server, and this will greatly reduce the amount of bandwidth required by the game.</span></td></tr>
<tr><td width="20%">Email Verification:</td><td><select name="verifyemail"><option value="0" {{selectverify0}}>Disabled</option><option value="1" {{selectverify1}}>Enabled</option></select><br><span class="small">Make users verify their email address for added security.</span></td></tr>
<tr><td width="20%">Show News:</td><td><select name="shownews"><option value="0" {{selectnews0}}>No</option><option value="1" {{selectnews1}}>Yes</option></select><br><span class="small">Toggle display of the Latest News box in towns.</td></tr>
<tr><td width="20%">Show Who's Online:</td><td><select name="showonline"><option value="0" {{selectonline0}}>No</option><option value="1" {{selectonline1}}>Yes</option></select><br><span class="small">Toggle display of the Who's Online box in towns.</span></td></tr>
@ -87,11 +83,6 @@ These options control several major settings for the overall game engine.<br><br
</form>
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"] = ""; }

View File

@ -1,102 +1,111 @@
<?php // forum.php :: Internal forums script for the game.
<?php
include('lib.php');
include('cookies.php');
$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);
// forum.php :: Internal forums script for the game.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
$controlrow = get_control_row();
// Login (or verify) if not logged in.
if (($userrow = checkcookies()) === false) {
if (isset($_GET['do']) && $_GET['do'] === 'verify') {
header("Location: users.php?do=verify");
exit;
}
header("Location: login.php?do=login");
exit;
}
// Close game.
if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); }
if ((bool) $controlrow["gameopen"] === false) {
display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
exit;
}
// Force verify if the user isn't verified yet.
if ($controlrow["verifyemail"] == 1 && $userrow["verify"] != 1) { header("Location: users.php?do=verify"); die(); }
if ((bool) $controlrow["verifyemail"] && (bool) $userrow["verify"] === false) {
header("Location: users.php?do=verify");
exit;
}
// Block user if he/she has been banned.
if ($userrow["authlevel"] == 2) { die("Your account has been blocked. Please try back later."); }
if ($userrow["authlevel"] === 2) {
exit("Your account has been blocked.");
}
if (isset($_GET["do"])) {
$do = explode(":",$_GET["do"]);
$do = explode(':', $_GET['do'] ?? '');
match ($do[0]) {
'thread' => 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 = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><th colspan=\"3\" style=\"background-color:#dddddd;\"><center><a href=\"forum.php?do=new\">New Thread</a></center></th></tr><tr><th width=\"50%\" style=\"background-color:#dddddd;\">Thread</th><th width=\"10%\" style=\"background-color:#dddddd;\">Replies</th><th style=\"background-color:#dddddd;\">Last Post</th></tr>\n";
$count = 1;
if (mysql_num_rows($query) == 0) {
$page .= "<tr><td style=\"background-color:#ffffff;\" colspan=\"3\"><b>No threads in forum.</b></td></tr>\n";
} else {
while ($row = mysql_fetch_array($query)) {
if ($count == 1) {
$hasRows = false;
while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
$hasRows = true;
$page .= "<tr><td style=\"background-color:#ffffff;\"><a href=\"forum.php?do=thread:".$row["id"].":0\">".$row["title"]."</a></td><td style=\"background-color:#ffffff;\">".$row["replies"]."</td><td style=\"background-color:#ffffff;\">".$row["newpostdate"]."</td></tr>\n";
$count = 2;
} else {
$page .= "<tr><td style=\"background-color:#eeeeee;\"><a href=\"forum.php?do=thread:".$row["id"].":0\">".$row["title"]."</a></td><td style=\"background-color:#eeeeee;\">".$row["replies"]."</td><td style=\"background-color:#eeeeee;\">".$row["newpostdate"]."</td></tr>\n";
$count = 1;
}
}
if (!$hasRows) {
$page .= "<tr><td style=\"background-color:#ffffff;\" colspan=\"3\"><b>No threads in forum.</b></td></tr>\n";
}
$page .= "</table></td></tr></table>";
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 = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><td colspan=\"2\" style=\"background-color:#dddddd;\"><b><a href=\"forum.php\">Forum</a> :: ".$row2["title"]."</b></td></tr>\n";
$count = 1;
while ($row = mysql_fetch_array($query)) {
if ($count == 1) {
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><td colspan=\"2\" style=\"background-color:#dddddd;\"><b><a href=\"forum.php\">Forum</a> :: ".$title['title']."</b></td></tr>\n";
while ($row = $posts->fetchArray(SQLITE3_ASSOC)) {
$page .= "<tr><td width=\"25%\" style=\"background-color:#ffffff; vertical-align:top;\"><span class=\"small\"><b>".$row["author"]."</b><br><br>".prettyforumdate($row["postdate"])."</td><td style=\"background-color:#ffffff; vertical-align:top;\">".nl2br($row["content"])."</td></tr>\n";
$count = 2;
} else {
$page .= "<tr><td width=\"25%\" style=\"background-color:#eeeeee; vertical-align:top;\"><span class=\"small\"><b>".$row["author"]."</b><br><br>".prettyforumdate($row["postdate"])."</td><td style=\"background-color:#eeeeee; vertical-align:top;\">".nl2br($row["content"])."</td></tr>\n";
$count = 1;
}
}
$page .= "</table></td></tr></table><br>";
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"forum.php?do=reply\" method=\"post\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$row2["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"forum.php?do=reply\" method=\"post\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$title["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
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 = "<table width=\"100%\"><tr><td><b>Make A New Post:</b><br><br/ ><form action=\"forum.php?do=new\" method=\"post\">Title:<br><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"50\" /><br><br>Message:<br><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
display($page, "Forum");
}
?>

View File

@ -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 '',

View File

@ -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'] ?? '');

View File

@ -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);

View File

@ -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"] = "<a href=\"forum.php\">Forum</a><br>"; }
elseif ($controlrow["forumtype"] == 2) { $userrow["forumslink"] = "<a href=\"".$controlrow["forumaddress"]."\">Forum</a><br>"; }
$userrow["forumslink"] = "<a href=\"forum.php\">Forum</a><br>";
// Format various userrow stuffs...
if ($userrow["latitude"] < 0) { $userrow["latitude"] = $userrow["latitude"] * -1 . "S"; } else { $userrow["latitude"] .= "N"; }

View File

@ -4,9 +4,9 @@ $template = <<<THEVERYENDOFYOU
<table width="100%">
<tr><td colspan="2">Use the form below to change your password. All fields are required. New passwords must be 10 alphanumeric characters or less.</td></tr>
<tr><td width="20%">Username:</td><td><input type="text" name="username" size="30" maxlength="30" /></td></tr>
<tr><td>Old Password:</td><td><input type="password" name="oldpass" size="20" /></td></tr>
<tr><td>New Password:</td><td><input type="password" name="newpass1" size="20" maxlength="10" /></td></tr>
<tr><td>Verify New Password:</td><td><input type="password" name="newpass2" size="20" maxlength="10" /><br><br><br></td></tr>
<tr><td>Old Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td>New Password:</td><td><input type="password" name="new_password" /></td></tr>
<tr><td>Verify New Password:</td><td><input type="password" name="new_password2" /><br><br><br></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>