From 222789f8c7ab782f21035bce671b7488c5c8823c Mon Sep 17 00:00:00 2001 From: thekabal Date: Sun, 11 Mar 2018 16:24:44 -0600 Subject: [PATCH] Implement playergateway --- classes/Bases.php | 7 ++----- classes/Character.php | 10 ++-------- classes/PlanetReportCE.php | 23 ++++------------------- classes/Player.php | 7 ++----- classes/Realspace.php | 7 ++----- 5 files changed, 12 insertions(+), 42 deletions(-) diff --git a/classes/Bases.php b/classes/Bases.php index d5efcc43f..839dcf2c5 100644 --- a/classes/Bases.php +++ b/classes/Bases.php @@ -29,11 +29,8 @@ public function buildBase(\PDO $pdo_db, array $langvars, int $planet_id, int $se echo "

"; // Get playerinfo from database - $sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1"; - $stmt = $pdo_db->prepare($sql); - $stmt->bindParam(':email', $_SESSION['username'], \PDO::PARAM_STR); - $stmt->execute(); - $playerinfo = $stmt->fetch(\PDO::FETCH_ASSOC); + $players_gateway = new Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1"; $stmt = $pdo_db->prepare($sql); diff --git a/classes/Character.php b/classes/Character.php index 8d7c6974e..c45d3831b 100644 --- a/classes/Character.php +++ b/classes/Character.php @@ -100,14 +100,8 @@ public function kill(\PDO $pdo_db, int $ship_id, array $langvars, Reg $tkireg, b public function getInsignia(\PDO $pdo_db, string $a_username, array $langvars) : string { // Lookup players score. - $sql = "SELECT score FROM ::prefix::ships WHERE email =:email"; - $stmt = $pdo_db->prepare($sql); - $stmt->bindParam(':email', $a_username, \PDO::PARAM_STR); - $stmt->execute(); - Db::logDbErrors($pdo_db, $sql, __LINE__, __FILE__); - $res = $stmt->fetch(); - $playerinfo = array(); - $playerinfo['score'] = $res['score']; + $players_gateway = new Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($a_username); for ($i = 0; $i < 20; $i++) { diff --git a/classes/PlanetReportCE.php b/classes/PlanetReportCE.php index 8c0a608a3..1d31aa44b 100644 --- a/classes/PlanetReportCE.php +++ b/classes/PlanetReportCE.php @@ -26,16 +26,8 @@ public static function collectCredits(\PDO $pdo_db, $db, array $langvars, array $current_state = "GO"; // Current State $playerinfo = Array(); - // Look up the info for the player that wants to collect the credits. - $sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1"; - $stmt = $pdo_db->prepare($sql); - $sql_test = \Tki\Db::logDbErrors($pdo_db, $sql, __LINE__, __FILE__); - if ($sql_test === true) - { - $stmt->bindParam(':email', $_SESSION['username'], \PDO::PARAM_STR); - $stmt->execute(); - $playerinfo = $stmt->fetch(\PDO::FETCH_ASSOC); - } + $players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); // Set s_p_pair as an array. $s_p_pair = array(); @@ -99,15 +91,8 @@ public static function takeCredits(\PDO $pdo_db, array $langvars, int $planet_id $planetinfo = Array(); // Get playerinfo from database - $sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1"; - $stmt = $pdo_db->prepare($sql); - $sql_test = \Tki\Db::logDbErrors($pdo_db, $sql, __LINE__, __FILE__); - if ($sql_test === true) - { - $stmt->bindParam(':email', $_SESSION['username'], \PDO::PARAM_STR); - $stmt->execute(); - $playerinfo = $stmt->fetch(\PDO::FETCH_ASSOC); - } + $players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); // Get planetinfo from database $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1"; diff --git a/classes/Player.php b/classes/Player.php index 800d8fd64..c91012933 100644 --- a/classes/Player.php +++ b/classes/Player.php @@ -42,11 +42,8 @@ public static function auth(\PDO $pdo_db, string $lang, array $langvars, Reg $tk if ($_SESSION['username'] !== null && $_SESSION['password'] !== null) { - $sql = "SELECT password, ip_address, last_login, ship_id, ship_destroyed, dev_escapepod FROM ::prefix::ships WHERE email=:email LIMIT 1"; - $stmt = $pdo_db->prepare($sql); - $stmt->bindParam(':email', $_SESSION['username'], \PDO::PARAM_STR); - $stmt->execute(); - $playerinfo = $stmt->fetch(); + $players_gateway = new Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); if ($playerinfo !== false) { diff --git a/classes/Realspace.php b/classes/Realspace.php index 6d7f66369..d9d9b4a97 100644 --- a/classes/Realspace.php +++ b/classes/Realspace.php @@ -23,11 +23,8 @@ class Realspace { public static function realSpaceMove(\PDO $pdo_db, array $langvars, int $destination, Reg $tkireg): string { - $sql = "SELECT * FROM ::prefix::ships WHERE email=:email"; - $stmt = $pdo_db->prepare($sql); - $stmt->bindParam(':email', $_SESSION['username'], \PDO::PARAM_STR); - $stmt->execute(); - $playerinfo = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $players_gateway = new Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls + $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); $sql = "SELECT angle1, angle2, distance FROM ::prefix::universe WHERE sector_id=:playersector"; $stmt = $pdo_db->prepare($sql);