Updating Dragon Knight Engine

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.

Re: Updating Dragon Knight Engine

Postby Kesstryl » Tue Aug 15, 2017 3:15 pm

I made a fully modded version of my Dragon Knight Updated which installs the mods in the installation process. The install worked great. I have a bug that is very strange which I can't figure out. My login page is blank on my new installed game. On my other modded version which is still installed (and under a different name in my wamp directory) the code works just fine. In the new install it's like the page is not grabbing the template and producing any html. With the exact same code as the working version. I'm banging my head against a wall.

Here's my login page code which is the same for both versions:

Code: Select all
include('lib.php');


if (isset($_GET["do"])) {
   $check = protectcsfr();
   $_GET = array_map('protectarray', $_GET);
    if ($_GET["do"] == "login") { login(); }
   elseif ($_GET["do"] == "nobrute") { nobrute(); }
    elseif ($_GET["do"] == "logout") { logout(); }
}

function login() {
   
    include('config.php');
   @$_SESSION['loginCount'] += 0;
   
    if (isset($_POST["submit"])) {
      $check = protectcsfr();
      $link = opendb();
        $username = protect($_POST['username']);
        $pass = protect($_POST['password']);
      $token = protect($_POST['token']);
      if ($_SESSION['token'] != $token) { die("Invalid request");}
   
      if($_SESSION['loginCount']>=1){
         header("Location: login.php?do=nobrute");
         die();
      }
      $salt = $username;
      $password = hash('sha256', $salt.$pass);
        $query = doquery($link, "SELECT * FROM {{table}} WHERE username='$username' AND password='$password' LIMIT 1", "users") or die(mysqli_error($link));
        if (mysqli_num_rows($query) != 1) {
            $_SESSION['loginCount'] = $_SESSION['loginCount']+1;
      die("Invalid username or password. Please <a href=\"login.php?do=login\">go back </a>and try again."); }
      
        $row = mysqli_fetch_array($query);
        if (isset($_POST["rememberme"])) { $expiretime = time()+604800; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; }
        $random = rand(100, 10000);
      $itsme = hash('sha256', $random);
      $query = doquery($link, "UPDATE {{table}} SET `random`='$itsme' WHERE `username`='$username' LIMIT 1", "users") or die(mysqli_error($link));      
      $hashme = md5($itsme);
      $cookie = ($row["id"]) . " " .$hashme. " " . $rememberme;
        setcookie("dkmod", $cookie, $expiretime, "/", "", 0, true);
      unset($_SESSION['token']);
      $_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
      $_SESSION['me'] = sha1($itsme);
      unset($_SESSION['loginCount']);
        header("Location: index.php");
        die();
       
    }
   
    $page = gettemplate("login");
    $title = "Log In";
    display($page, $title, false, false, false, false);
   
}

function nobrute(){
   if(isset($_POST['verify'])){
        // Process image verification.
         $number = protect($_POST['imagever']);
         if (md5($number) != $_SESSION['image_random_value']) { die("Image verification failed.<br />"); }
         unset($_SESSION['loginCount']);   
         header("Location: login.php?do=login");
         die();
   }
   $page = "Verify that you are human</br></br><form action=\"login.php?do=nobrute\" method=\"post\">Verification:<img src=\"auth.php\" alt=\"Image Verification\" /><br /><br />Copy the text from the above image into the box below. Can't read it? <a href=\"login.php?do=nobrute\">Refresh</a>.<br /><input id=\"imagever\" name=\"imagever\" type=\"text\" /><input type=\"submit\" name=\"verify\" value=\"Submit\" /></form>";
   $title = "Verify Yourself";
   display($page, $title, false, false, false, false);
}
   
function logout() {
   
    setcookie("dkgame", "", time()-100000, "/", "", 0, $httponly);
   setcookie ("dkgame", false);
   unset($_COOKIE["dkgame"]);
   session_destroy();
   header("Location: home.php?do=homepage");
    die();
   
}


here's my template page, again nothing is different:

Code: Select all
//this code protects users from csfr attacks on this page, do not remove unless you can implement better csfr protection.
if (!isset($_SESSION['token'])) {
    $token = sha1(uniqid(rand(), TRUE));
    $_SESSION['token'] = $token;
   }else
   {
    $token = $_SESSION['token'];
   }

$token = $_SESSION['token'];

$template = <<<THEVERYENDOFYOU
<form action="login.php?do=login" method="post">
<table width="75%">
<tr><td width="30%">Username:</td><td><input type="text" size="30" name="username" /></td></tr>
<tr><td>Password:</td><td><input type="password" size="30" name="password" /></td></tr>
<tr><td>Remember me?</td><td><input type="checkbox" name="rememberme" value="yes" /> Yes</td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Log In" /></td></tr>
<tr><td colspan="2">Checking the "Remember Me" option will store your login information in a cookie so you don't have to enter it next time you get online.<br /><br />Want to play? You gotta <a href="users.php?do=register">register your own character.</a><br /><br />You may also <a href="users.php?do=lostpassword">request a new password</a> if you've lost yours.</td></tr>
<tr><td><input type="hidden" name="token" value="{$token}" />   </td></tr>
</table>
</form>
THEVERYENDOFYOU;


I'm using Chrome as my browser. I can explain what different parts the the code do if needed, and the lib.php file which is included basically defines how templates are used, again nothing is changed between both versions.

Is there a possible explanation that anyone can think of as to why my old version works perfectly and the new installed version is producing a blank login page?
Play my open beta text based RPG Dragon Lord at http://dragonlordrpg.com
User avatar
Kesstryl
 
Posts: 201
Joined: Sat Sep 22, 2012 12:27 am
Location: Gallifrey
Has thanked: 38 times
Been thanked: 3 times

Re: Updating Dragon Knight Engine

Postby hallsofvallhalla » Tue Aug 15, 2017 3:48 pm

Nothing in the console? What about if you record on the network tab? Anything failing?
User avatar
hallsofvallhalla
Site Admin
 
Posts: 11998
Images: 13
Joined: Wed Apr 22, 2009 6:29 pm
Location: mobile, al
Has thanked: 11 times
Been thanked: 164 times
Blog: View Blog (3)

Re: Updating Dragon Knight Engine

Postby Kesstryl » Tue Aug 15, 2017 6:15 pm

Nothing is showing up in the php error logs, and my Apache log is showing this

[Tue Aug 15 17:06:29.478102 2017] [mpm_winnt:notice] [pid 4152:tid 804] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Tue Aug 15 17:06:31.563760 2017] [mpm_winnt:notice] [pid 7496:tid 716] AH00364: Child: All worker threads have exited.
[Tue Aug 15 17:06:33.544078 2017] [mpm_winnt:notice] [pid 4152:tid 804] AH00430: Parent: Child process 7496 exited successfully.
[Tue Aug 15 17:06:40.538169 2017] [mpm_winnt:notice] [pid 29640:tid 724] AH00455: Apache/2.4.9 (Win32) PHP/5.6.18 configured -- resuming normal operations
[Tue Aug 15 17:06:40.538169 2017] [mpm_winnt:notice] [pid 29640:tid 724] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:13:13
[Tue Aug 15 17:06:40.538169 2017] [core:notice] [pid 29640:tid 724] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9'
[Tue Aug 15 17:06:40.541171 2017] [mpm_winnt:notice] [pid 29640:tid 724] AH00418: Parent: Created child process 26824
[Tue Aug 15 17:06:41.118652 2017] [mpm_winnt:notice] [pid 26824:tid 728] AH00354: Child: Starting 64 worker threads.
[Tue Aug 15 17:07:01.281385 2017] [mpm_winnt:notice] [pid 29640:tid 724] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Tue Aug 15 17:07:03.282218 2017] [mpm_winnt:notice] [pid 26824:tid 728] AH00364: Child: All worker threads have exited.
[Tue Aug 15 17:07:03.301730 2017] [mpm_winnt:notice] [pid 29640:tid 724] AH00430: Parent: Child process 26824 exited successfully.
[Tue Aug 15 17:07:06.038975 2017] [mpm_winnt:notice] [pid 19384:tid 772] AH00455: Apache/2.4.9 (Win32) PHP/5.6.18 configured -- resuming normal operations
[Tue Aug 15 17:07:06.038975 2017] [mpm_winnt:notice] [pid 19384:tid 772] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:13:13
[Tue Aug 15 17:07:06.038975 2017] [core:notice] [pid 19384:tid 772] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9'
[Tue Aug 15 17:07:06.040977 2017] [mpm_winnt:notice] [pid 19384:tid 772] AH00418: Parent: Created child process 28612
[Tue Aug 15 17:07:06.788474 2017] [mpm_winnt:notice] [pid 28612:tid 720] AH00354: Child: Starting 64 worker threads.

I used Chrome's developer tools to see what the old login page is showing and the new non-working one. The non-working one is definitely not picking up the template. I have no clue why. Should I post the code from lib.php that pulls the templates together? That is also unchanged between the two, so there's no reason the code should not work, but I have copied and pasted code from the old working version to the new version just in case something odd happened in the copying.
Play my open beta text based RPG Dragon Lord at http://dragonlordrpg.com
User avatar
Kesstryl
 
Posts: 201
Joined: Sat Sep 22, 2012 12:27 am
Location: Gallifrey
Has thanked: 38 times
Been thanked: 3 times

Re: Updating Dragon Knight Engine

Postby hallsofvallhalla » Wed Aug 16, 2017 8:24 am

When you go tot the network tab and hit record then refresh nothing shows up in red?
User avatar
hallsofvallhalla
Site Admin
 
Posts: 11998
Images: 13
Joined: Wed Apr 22, 2009 6:29 pm
Location: mobile, al
Has thanked: 11 times
Been thanked: 164 times
Blog: View Blog (3)

Re: Updating Dragon Knight Engine

Postby Kesstryl » Wed Aug 16, 2017 2:59 pm

I finally installed Xdebug (comes with WAMP) to use with Chrome and Notepad++, and it gave me some header errors. I googled those errors and some of the suggestions were to have compression so I uncommented the ob_start line in the lib.php file, and it's working now. It was uncommitted because it wasn't working before. Who knew code could break so easily when everything is copied and used in a different folder and different database on the very same server.

I can now see that one of my tables didn't get populated in the install process which is what killed everything. Strange that it threw blank pages instead of calling undefined indexes, but now I can make progress on where the install script when wrong with populating the table.
Play my open beta text based RPG Dragon Lord at http://dragonlordrpg.com
User avatar
Kesstryl
 
Posts: 201
Joined: Sat Sep 22, 2012 12:27 am
Location: Gallifrey
Has thanked: 38 times
Been thanked: 3 times

Re: Updating Dragon Knight Engine

Postby Kesstryl » Wed Aug 16, 2017 4:02 pm

Everything is now fixed and working. I have a fully modded version of my Dragon Knight Updated engine with 11 mods that were updated from the old DK mod forum. I think I'll add the bank mod and call the modded version done. It will definitely make a much fuller PBBG game engine with the mods. The mods I included are clans, class images, quests, friends, home page, movable maps, pvp, random bosses, and social titles. There are a ton of other mods still there on the DK mods forum, and I left instructions in the regular Dragon Knight Updated about how to add additional mods for the DK updated engine.
Play my open beta text based RPG Dragon Lord at http://dragonlordrpg.com
User avatar
Kesstryl
 
Posts: 201
Joined: Sat Sep 22, 2012 12:27 am
Location: Gallifrey
Has thanked: 38 times
Been thanked: 3 times

Previous

Return to Beginner Help and Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x