<?php include "Query.php"; $username = $_POST["uname"]; $password = $_POST["pwd"]; $q = new Query("SELECT * FROM player WHERE uname='{$username}' AND password='******';"); $q->execute(); //$result = $q->getResult(); $count = $q->numRows(); //echo $username; //echo $password; //echo $count; if ($count == 1) { //session_register("username"); //session_register("password"); // Update online bit status if login success $q = new Query("UPDATE player SET online=1"); $q->execute(); header("location:login_success.php?uname=" . $username); } else { header("location:login_failure.php"); }
<?php $uname = $_GET["uname"]; include "../lib/Query.php"; $counter = new Query("Select * FROM statistics"); $counter->execute(); $userTotal = $counter->numRows(); $leaderboardLimit = 10; if ($userTotal < $leaderboardLimit) { $leaderboardLimit = $userTotal; } $query = new Query("Select * FROM statistics ORDER BY points DESC, wins DESC, uname ASC LIMIT {$leaderboardLimit}"); $query->execute(); $query->getResult(); echo '<html> <body> <h3>Hello ' . $uname . ', this is the Leaderboard page. </h3> <table border="1"> <tr> <td>Ranking</td> <td>Username</td> <td>Wins</td> <td>Losses</td> <td>Ties</td> <td>Total Games</td> <td>Points</td> </tr>'; for ($i = 0; $i < $leaderboardLimit; $i++) { $row = $query->getRow($i); $username = $row[0]; $wins = $row[1];
//check to see if user was placed by another request $query = new Query("SELECT * FROM player WHERE ingame = 2 AND uname='{$uname}';"); $query->execute(); if ($query->numRows() == 1) { //get the gstate table and send it back $query = new Query("SELECT opponent FROM player WHERE uname='{$uname}';"); $query->execute(); $row = $query->getRow(0); $opponent = stripslashes($row[0]); echo $opponent . '_gstate'; exit; } } //if we didnt find anything reply accordingly //and reset ingame=0 if ($query->numRows() == 0) { $query = new Query("UPDATE player SET ingame=0 WHERE uname='{$uname}';"); $query->execute(); echo 0; exit; } $row = $query->getRow(0); $opponent = stripslashes($row[0]); //match the two players $query = new Query("UPDATE player SET opponent='{$opponent}' WHERE uname='{$uname}';"); $query->execute(); $query = new Query("UPDATE player SET opponent='{$uname}' WHERE uname='{$opponent}';"); $query->execute(); //set the two players ingame status to ingame $query = new Query("UPDATE player SET ingame=2 WHERE uname='{$uname}' OR uname='{$opponent}';"); $query->execute();
<?php /*pollMove_2.php created by Tim Bouvier 11/26/2013 Checks gamestate and returns a json object with gamestate.*/ include '../lib/Query.php'; $winning_game = ""; $req_uname = $_GET["uname"]; $tbl = $_GET["tbl"]; $query = new Query("SELECT * FROM " . $tbl . ";"); //execute it and convert it to json eventually $query->execute(); //initialize gamestate array for ($i = 0; $i < $query->numRows(); $i++) { $row = $query->getRow($i); $coordinates[$i] = stripslashes($row[1]); } if ($coordinates[0] == $coordinates[1] && $coordinates[1] == $coordinates[2] && $coordinates[1] != "") { $winning_game = $coordinates[1]; } if ($coordinates[3] == $coordinates[4] && $coordinates[4] == $coordinates[5] && $coordinates[4] != "") { $winning_game = $coordinates[4]; } if ($coordinates[6] == $coordinates[7] && $coordinates[7] == $coordinates[8] && $coordinates[7] != "") { $winning_game = $coordinates[7]; } if ($coordinates[0] == $coordinates[3] && $coordinates[3] == $coordinates[6] && $coordinates[3] != "") { $winning_game = $coordinates[3]; } if ($coordinates[1] == $coordinates[4] && $coordinates[4] == $coordinates[7] && $coordinates[4] != "") { $winning_game = $coordinates[4];
<?php /* makeMove_2.php created by Tim Bouvier on 11/27/2013 accepts client requests to make a move on the board and validates or denies them. */ include "../lib/Query.php"; $uname = $_GET["uname"]; $coordinate = $_GET["coordinate"]; $tbl = $_GET["tbl"]; $ret = 0; //check if its their turn $turn = new Query("SELECT * FROM player WHERE uname='{$uname}' AND turn=1;"); $turn->execute(); if ($turn->numRows() == 0) { echo 0; exit; } //check if spot is valid $query = new Query("SELECT uname FROM " . $tbl . " WHERE coordinate={$coordinate};"); $query->execute(); $row = $query->getRow(0); $res = stripslashes($row[0]); if ($res == "") { //valid so now update the spot to the requesting user $update_row = new Query("UPDATE " . $tbl . " SET uname='{$uname}' WHERE coordinate={$coordinate};"); $update_row->execute(); //set their turn to inactive $turn_inactive = new Query("UPDATE player SET turn=0 WHERE uname='{$uname}';"); $turn_inactive->execute(); //get opponents uname
/** * Reset the last query to the first result * * This needs to be used if the query has been 'looped through' * until the end and you wish to loop through again * @access public */ public function reset() { $this->check(); if (Query::numRows($this->last_query)) { mysql_data_seek($this->last_query, 0); $this->internal_pointer = 0; } }