"; }
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.
"; }
// 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.
"; }
// 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.
"; }
// Process password.
if (preg_match("/[^A-z0-9_\-]/", $password1)==1) { $errors++; $errorlist .= "Password must be alphanumeric.
"; } // Thanks to "Carlos Pires" from php.net!
if ($password1 != $password2) { $errors++; $errorlist .= "Passwords don't match.
"; }
$password = md5($password1);
if ($errors == 0) {
if ($controlrow["verifyemail"] == 1) {
$verifycode = "";
for ($i=0; $i<8; $i++) {
$verifycode .= chr(rand(65,90));
}
} else {
$verifycode='1';
}
$query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email1',charname='$charname',charclass='$charclass',difficulty='$difficulty'", "users") or die(mysql_error());
if ($controlrow["verifyemail"] == 1) {
if (sendregmail($email1, $verifycode) == true) {
$page = "Your account was created successfully.
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, please visit the Verification Page to enter your code and start playing.";
} else {
$page = "Your account was created successfully.
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.
You may now continue to the Login Page and continue playing ".$controlrow["gamename"]."!";
}
} else {
$page = "The following error(s) occurred when your account was being made:
$errorlist
Please go back and try again.";
}
} else {
$page = gettemplate("register");
if ($controlrow["verifyemail"] == 1) {
$controlrow["verifytext"] = "
A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address.";
} else {
$controlrow["verifytext"] = "";
}
$page = parsetemplate($page, $controlrow);
}
$topnav = "";
display($page, "Register", false, false, false);
}
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 ($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."); }
// If we've made it this far, should be safe to update their account.
$updatequery = doquery("UPDATE {{table}} SET verify='1' WHERE username='$username' LIMIT 1","users");
display("Your account was verified successfully.
You may now continue to the Login Page and start playing the game.
Thanks for playing!","Verify Email",false,false,false);
}
$page = gettemplate("verify");
$topnav = "";
display($page, "Verify Email", false, false, false);
}
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."); }
$newpass = "";
for ($i=0; $i<8; $i++) {
$newpass .= chr(rand(65,90));
}
$md5newpass = md5($newpass);
$updatequery = doquery("UPDATE {{table}} SET password='$md5newpass' WHERE email='$email' LIMIT 1","users");
if (sendpassemail($email,$newpass) == true) {
display("Your new password was emailed to the address you provided.
Once you receive it, you may Log In and continue playing.
Thank you.","Lost Password",false,false,false);
} else {
display("There was an error sending your new password.
Please check with the game administrator for more information.
We apologize for the inconvience.","Lost Password",false,false,false);
}
die();
}
$page = gettemplate("lostpassword");
$topnav = "";
display($page, "Lost Password", false, false, false);
}
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 ($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."); }
$realnewpass = md5($newpass1);
$updatequery = doquery("UPDATE {{table}} SET password='$realnewpass' WHERE username='$username' LIMIT 1","users");
if (isset($_COOKIE["dkgame"])) { setcookie("dkgame", "", time()-100000, "/", "", 0); }
display("Your password was changed successfully.
You have been logged out of the game to avoid cookie errors.
Please log back in to continue playing.","Change Password",false,false,false);
die();
}
$page = gettemplate("changepassword");
$topnav = "";
display($page, "Change Password", false, false, false);
}
function sendpassemail($emailaddress, $password) {
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
$controlrow = mysql_fetch_array($controlquery);
extract($controlrow);
$email = <<';
}
$rp = $controlrow["adminemail"];
$org = '$gameurl';
$mailer = 'PHP';
$head = '';
$head .= "Content-Type: text/plain \r\n";
$head .= "Date: ". date('r'). " \r\n";
$head .= "Return-Path: $rp \r\n";
$head .= "From: $from \r\n";
$head .= "Sender: $from \r\n";
$head .= "Reply-To: $from \r\n";
$head .= "Organization: $org \r\n";
$head .= "X-Sender: $from \r\n";
$head .= "X-Priority: 3 \r\n";
$head .= "X-Mailer: $mailer \r\n";
$body = str_replace("\r\n", "\n", $body);
$body = str_replace("\n", "\r\n", $body);
return mail($to, $title, $body, $head);
}
?>