diff --git a/classes/CheckDefenses.php b/classes/CheckDefenses.php index 3e22c180b..bf9556dce 100644 --- a/classes/CheckDefenses.php +++ b/classes/CheckDefenses.php @@ -26,8 +26,10 @@ class CheckDefenses { - public static function sectorFighters(\PDO $pdo_db, string $lang, int $sector, string $calledfrom, int $energyscooped): void + public static function sectorFighters(\PDO $pdo_db, string $lang, int $sector, string $calledfrom, int $energyscooped, array $playerinfo, Reg $tkireg, string $title): void { + $total_sec_fighters = 0; + $langvars = \Tki\Translate::load($pdo_db, $lang, array('sector_fighters', 'common', 'global_includes', 'global_funcs', 'footer', 'news')); echo $langvars['l_sf_attacking'] . "
"; $targetfighters = $total_sec_fighters; @@ -125,7 +127,7 @@ public static function sectorFighters(\PDO $pdo_db, string $lang, int $sector, s } else { - $langvars['l_sf_lostfight2'] = str_replace("[lost]", (string) $targetfighters, $langvars['l_sf_lostfight2']); + $langvars['l_sf_lostfight2'] = str_replace("[lost]", $targetfighters, $langvars['l_sf_lostfight2']); echo $langvars['l_sf_lostfight2'] . "
"; $tempplayfighters = $playerfighters - $targetfighters; } @@ -144,7 +146,7 @@ public static function sectorFighters(\PDO $pdo_db, string $lang, int $sector, s else { $playerarmor = $playerarmor - $targetfighters; - $langvars['l_sf_armorbreach2'] = str_replace("[lost]", (string) $targetfighters, $langvars['l_sf_armorbreach2']); + $langvars['l_sf_armorbreach2'] = str_replace("[lost]", $targetfighters, $langvars['l_sf_armorbreach2']); echo $langvars['l_sf_armorbreach2'] . "
"; } } @@ -234,7 +236,7 @@ public static function sectorFighters(\PDO $pdo_db, string $lang, int $sector, s } } - public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): void + public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector, $playerinfo, $tkireg, $title, $calledfrom): void { // Database driven language entries $langvars = \Tki\Translate::load($pdo_db, $lang, array('check_defenses', 'common', 'global_includes', 'global_funcs', 'combat', 'footer', 'news', 'regional')); @@ -305,7 +307,7 @@ public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): v $resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defenses = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id'])); \Tki\Db::logDbErrors($pdo_db, $resx, __LINE__, __FILE__); echo "

" . $title . "

\n"; - \Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, 0); + \Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, 0, $playerinfo, $tkireg, $title); break; case "retreat": @@ -322,7 +324,7 @@ public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): v case "pay": $resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defenses = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id'])); \Tki\Db::logDbErrors($pdo_db, $resx, __LINE__, __FILE__); - $fighterstoll = (int) round($total_sec_fighters * $fighter_price * 0.6); + $fighterstoll = (int) round($total_sec_fighters * $tkireg->fighter_price * 0.6); if ($playerinfo['credits'] < $fighterstoll) { echo $langvars['l_chf_notenoughcreditstoll'] . "
"; @@ -366,7 +368,7 @@ public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): v // Sector defenses detect incoming ship echo "

" . $title . "

\n"; echo $langvars['l_chf_thefightersdetectyou'] . "
"; - \Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, 0); + \Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, 0, $playerinfo, $tkireg, $title); break; } else @@ -380,7 +382,7 @@ public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): v $interface_string = $calledfrom . '?sector=' . $sector . '&destination=' . $destination . '&engage=' . $engage; $resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defenses = ? WHERE ship_id = ?;", array($interface_string, $playerinfo['ship_id'])); \Tki\Db::logDbErrors($pdo_db, $resx, __LINE__, __FILE__); - $fighterstoll = (int) round($total_sec_fighters * $fighter_price * 0.6); + $fighterstoll = (int) round($total_sec_fighters * $tkireg->fighter_price * 0.6); echo "

" . $title . "

\n"; echo "
"; $langvars['l_chf_therearetotalfightersindest'] = str_replace("[chf_total_sec_fighters]", (string) $total_sec_fighters, $langvars['l_chf_therearetotalfightersindest']); @@ -422,7 +424,7 @@ public static function fighters(\PDO $pdo_db, $db, string $lang, int $sector): v } } - public static function mines(\PDO $pdo_db, $db, string $lang, int $sector, string $title): void + public static function mines(\PDO $pdo_db, $db, string $lang, int $sector, string $title, array $playerinfo, $tkireg): void { // Database driven language entries $langvars = \Tki\Translate::load($pdo_db, $lang, array('check_defenses', 'common', 'global_includes', 'combat', 'footer', 'news')); diff --git a/classes/Defense.php b/classes/Defense.php index 063af01b8..a6b5fdc20 100644 --- a/classes/Defense.php +++ b/classes/Defense.php @@ -32,7 +32,7 @@ public static function defenseVsDefense(\PDO $pdo_db, int $ship_id, array $langv $defenses_gateway = new \Tki\Defenses\DefensesGateway($pdo_db); // Build a defense gateway object to handle the SQL calls $defenses_present = $defenses_gateway->selectDefenses($ship_id); - if ($defenses_present !== false) + if (!empty($defenses_present)) { foreach ($defenses_present as $tmp_defense) { diff --git a/classes/Defenses/DefensesGateway.php b/classes/Defenses/DefensesGateway.php index 26dfeeb40..f3764a515 100644 --- a/classes/Defenses/DefensesGateway.php +++ b/classes/Defenses/DefensesGateway.php @@ -33,16 +33,23 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object $this->pdo_db = $pdo_db; } - public function selectDefenses(int $sector_id) + public function selectDefenses(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id = :sector_id"; $stmt = $this->pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $sector_id, \PDO::PARAM_INT); - $stmt->execute(); + $result = $stmt->execute(); \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any - // A little magic here. If it couldn't select a defense in the sector, the following call will return false - which is what we want for "no defenses found". $defense_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $defense_present; // FUTURE: Eventually we want this to return a defense object instead, for now, defensesinfo array or false for no defense found. + + if ($defense_present !== false) + { + return $defense_present; // FUTURE: Eventually we want this to return a defense object instead, for now, defensesinfo array or false for no defense found. + } + else + { + return null; + } } } diff --git a/classes/Footer.php b/classes/Footer.php index 663ccd21f..fddb8a3e7 100644 --- a/classes/Footer.php +++ b/classes/Footer.php @@ -49,7 +49,7 @@ public function display(\PDO $pdo_db, string $lang, Reg $tkireg, Smarty $templat $players_gateway = new Players\PlayersGateway($pdo_db); // Online is the (int) count of the numbers of players currently logged in via SQL select - $online = $players_gateway->selectPlayersLoggedIn($since_stamp, $cur_time_stamp); + $online = (int) $players_gateway->selectPlayersLoggedIn($since_stamp, $cur_time_stamp); } $tkireg->tkitimer->stop(); diff --git a/classes/Links/LinksGateway.php b/classes/Links/LinksGateway.php index 42bfcb90d..41e292b25 100644 --- a/classes/Links/LinksGateway.php +++ b/classes/Links/LinksGateway.php @@ -33,15 +33,22 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object $this->pdo_db = $pdo_db; } - public function selectAllLinkInfoByLinkStart(int $sector_id) + public function selectAllLinkInfoByLinkStart(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::links WHERE link_start = :link_start ORDER BY link_dest ASC"; $stmt = $this->pdo_db->prepare($sql); $stmt->bindParam(':link_start', $sector_id, \PDO::PARAM_INT); $stmt->execute(); - - // A little magic here. If it couldn't select a link, the following call will return false - which is what we want for "no link found". $linksinfo = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $linksinfo; // FUTURE: Eventually we want this to return a link object instead, for now, linkinfo array or false for no link found. + + if ($linksinfo !== false) + { + // A little magic here. If it couldn't select a link, the following call will return false - which is what we want for "no link found". + return $linksinfo; // FUTURE: Eventually we want this to return a link object instead, for now, linkinfo array or false for no link found. + } + else + { + return null; + } } } diff --git a/classes/Ownership.php b/classes/Ownership.php index 5b5d4b48a..4a4fcd5ee 100644 --- a/classes/Ownership.php +++ b/classes/Ownership.php @@ -37,7 +37,7 @@ public static function calc(\PDO $pdo_db, int $sector, Reg $tkireg, array $langv $bases = array(); if ($bases_present === false) { - return "Sector ownership didn't change"; + return $langvars['l_global_sector_owner_nochange']; } foreach ($bases_present as $tmp_base) diff --git a/classes/PlanetProduction.php b/classes/PlanetProduction.php index 938e78467..072acf12a 100644 --- a/classes/PlanetProduction.php +++ b/classes/PlanetProduction.php @@ -160,9 +160,12 @@ public static function productionChange(\PDO $pdo_db, $db, array $langvars, arra if ($planet['prod_ore'] + $planet['prod_organics'] + $planet['prod_goods'] + $planet['prod_energy'] + $planet['prod_fighters'] + $planet['prod_torp'] > 100) { - $temp1 = str_replace("[planet_name]", $planet['name'], $langvars['l_pr_value_reset']); - $temp2 = str_replace("[sector_id]", $planet['sector_id'], $temp1); - echo $temp2 . "
"; + if (!empty($planet['name']) && !empty($planet['sector_id'])) + { + $temp1 = str_replace("[planet_name]", (string) $planet['name'], (string) $langvars['l_pr_value_reset']); + $temp2 = str_replace("[sector_id]", (string) $planet['sector_id'], $temp1); + echo $temp2 . "
"; + } $resa = $db->Execute("UPDATE {$db->prefix}planets SET prod_ore = ? WHERE planet_id = ?;", array($tkireg->default_prod_ore, $planet['planet_id'])); \Tki\Db::logDbErrors($pdo_db, $resa, __LINE__, __FILE__); diff --git a/classes/PlanetReportCE.php b/classes/PlanetReportCE.php index 6c8a30722..901666827 100644 --- a/classes/PlanetReportCE.php +++ b/classes/PlanetReportCE.php @@ -152,11 +152,11 @@ public static function takeCredits(\PDO $pdo_db, array $langvars, int $planet_id $update = $stmt->execute(); \Tki\Db::logDbErrors($pdo_db, $update, __LINE__, __FILE__); - $tempa1 = str_replace("[credits_taken]", number_format($CreditsTaken, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), $langvars['l_pr_took_credits']); - $tempa2 = str_replace("[planet_name]", $planetinfo['name'], $tempa1); + $tempa1 = str_replace("[credits_taken]", number_format($CreditsTaken, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), (string) $langvars['l_pr_took_credits']); + $tempa2 = str_replace("[planet_name]", (string) $planetinfo['name'], $tempa1); echo $tempa2 . "
"; - $tempb1 = str_replace("[ship_name]", $playerinfo['ship_name'], $langvars['l_pr_have_credits_onboard']); + $tempb1 = str_replace("[ship_name]", (string) $playerinfo['ship_name'], (string) $langvars['l_pr_have_credits_onboard']); $tempb2 = str_replace("[new_ship_credits]", number_format($NewShipCredits, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), $tempb1); echo $tempb2 . "
"; $retval = "GO"; @@ -169,7 +169,7 @@ public static function takeCredits(\PDO $pdo_db, array $langvars, int $planet_id } else { - $tempc1 = str_replace("[planet_name]", $planetinfo['name'], $langvars['l_pr_not_enough_turns']); + $tempc1 = str_replace("[planet_name]", (string) $planetinfo['name'], (string) $langvars['l_pr_not_enough_turns']); $tempc2 = str_replace("[sector_id]", $planetinfo['sector_id'], $tempc1); echo "

" . $tempc2 . "

"; $retval = "BREAK-TURNS"; diff --git a/classes/Planets/PlanetsGateway.php b/classes/Planets/PlanetsGateway.php index 7fada3057..42b568742 100644 --- a/classes/Planets/PlanetsGateway.php +++ b/classes/Planets/PlanetsGateway.php @@ -33,7 +33,7 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object $this->pdo_db = $pdo_db; } - public function selectPlanetInfo(int $sector_id) + public function selectPlanetInfo(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::planets WHERE sector_id = :sector_id"; $stmt = $this->pdo_db->prepare($sql); @@ -46,20 +46,26 @@ public function selectPlanetInfo(int $sector_id) return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. } - public function selectAllPlanetInfo(int $sector_id) + public function selectAllPlanetInfo(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::planets WHERE sector_id = :sector_id"; $stmt = $this->pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $sector_id, \PDO::PARAM_INT); $stmt->execute(); \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any - // A little magic here. If it couldn't select a planet in the sector, the following call will return false - which is what we want for "no planet found". $planetinfo = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. + if ($planetinfo !== false) + { + return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. + } + else + { + return null; + } } - public function selectPlanetInfoByPlanet(int $planet_id) + public function selectPlanetInfoByPlanet(int $planet_id): ?array { $sql = "SELECT * FROM ::prefix::planets WHERE planet_id = :planet_id"; $stmt = $this->pdo_db->prepare($sql); @@ -72,16 +78,23 @@ public function selectPlanetInfoByPlanet(int $planet_id) return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. } - public function selectAllPlanetInfoByOwner(int $ship_id) + public function selectAllPlanetInfoByOwner(int $ship_id): ?array { $sql = "SELECT * FROM ::prefix::planets WHERE owner = :owner"; $stmt = $this->pdo_db->prepare($sql); $stmt->bindParam(':owner', $ship_id, \PDO::PARAM_INT); $stmt->execute(); \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any - // A little magic here. If it couldn't select a planet in the sector, the following call will return false - which is what we want for "no planet found". $planetinfo = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. + + if ($planetinfo !== false) + { + return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found. + } + else + { + return null; + } } } diff --git a/classes/Players/PlayersGateway.php b/classes/Players/PlayersGateway.php index edefaa7b3..b098d9e0e 100644 --- a/classes/Players/PlayersGateway.php +++ b/classes/Players/PlayersGateway.php @@ -33,7 +33,7 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object $this->pdo_db = $pdo_db; } - public function selectPlayersLoggedIn(string $since_stamp, string $cur_time_stamp): int + public function selectPlayersLoggedIn(string $since_stamp, string $cur_time_stamp): ?int { // SQL call that selected the number (count) of logged in ships (should be players) // where last login time is between the since_stamp, and the current timestamp ($cur_time_stamp) @@ -41,13 +41,19 @@ public function selectPlayersLoggedIn(string $since_stamp, string $cur_time_stam $sql = "SELECT COUNT(*) AS loggedin FROM ::prefix::ships " . "WHERE ::prefix::ships.last_login BETWEEN timestamp '" . $since_stamp . "' AND timestamp '" . $cur_time_stamp . "' AND email NOT LIKE '%@kabal'"; - $stmt = $this->pdo_db->query($sql); // Query the pdo DB using this SQL call + $result = $this->pdo_db->query($sql); // Query the pdo DB using this SQL call \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any - // Future: Correctly handle a false condition, which will not work for fetchObject - $row = $stmt->fetchObject(); // Fetch the associated object from the select - $online = $row->loggedin; // Set online variable to the loggedin count from SQL - return (int) $online; + if ($result !== false) + { + $row = $result->fetchObject(); // Fetch the associated object from the select + $online = $row->loggedin; // Set online variable to the loggedin count from SQL + return (int) $online; + } + else + { + return null; + } } public function selectPlayerInfo(string $email): array diff --git a/classes/Scheduler/SchedulerGateway.php b/classes/Scheduler/SchedulerGateway.php index 57958127a..d1beef707 100644 --- a/classes/Scheduler/SchedulerGateway.php +++ b/classes/Scheduler/SchedulerGateway.php @@ -40,15 +40,17 @@ public function selectSchedulerLastRun(): ?int { // SQL call that selects the last run of the scheduler, and only one record $sql = "SELECT last_run FROM ::prefix::scheduler LIMIT 1"; - $stmt = $this->pdo_db->query($sql); // Query the pdo DB using this SQL call + $result = $this->pdo_db->query($sql); // Query the pdo DB using this SQL call - // Future: Handle a bad return (aka false) as it is causing problems for the fetchObject call - $row = $stmt->fetchObject(); - \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any - - if (is_object($row) && (property_exists($row, 'last_run'))) + if ($result !== false) { - return (int) $row->last_run; // Return the int value of the last scheduler run + $row = $result->fetchObject(); + \Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any + + if (is_object($row) && (property_exists($row, 'last_run'))) + { + return (int) $row->last_run; // Return the int value of the last scheduler run + } } } diff --git a/classes/Smarty.php b/classes/Smarty.php index f028168ca..0a584e5b4 100644 --- a/classes/Smarty.php +++ b/classes/Smarty.php @@ -126,13 +126,17 @@ public function addVariables(string $nodeName, $variables): void } } - public function getVariables(string $nodeName) + public function getVariables(string $nodeName): ?mixed { if ($this->smarty !== null) { $temp_variable = $this->smarty->getTemplateVars($nodeName); return $temp_variable; } + else + { + return null; + } } public function test(): void diff --git a/classes/Zones/ZonesGateway.php b/classes/Zones/ZonesGateway.php index 440fad382..54654a543 100644 --- a/classes/Zones/ZonesGateway.php +++ b/classes/Zones/ZonesGateway.php @@ -33,7 +33,7 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object $this->pdo_db = $pdo_db; } - public function selectZoneInfo(int $sector_id) + public function selectZoneInfo(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::zones WHERE sector_id = :sector_id"; $stmt = $this->pdo_db->prepare($sql); @@ -46,7 +46,7 @@ public function selectZoneInfo(int $sector_id) return $zoneinfo; // FUTURE: Eventually we want this to return a zone object instead, for now, zoneinfo array or false for no zone found. } - public function selectZoneInfoByZone(int $zone) + public function selectZoneInfoByZone(int $zone): ?array { $sql = "SELECT * FROM ::prefix::zones WHERE zone_id = :zone_id LIMIT 1"; $stmt = $this->pdo_db->prepare($sql); @@ -59,7 +59,7 @@ public function selectZoneInfoByZone(int $zone) return $zoneinfo; // FUTURE: Eventually we want this to return a zone object instead, for now, zoneinfo array or false for no zone found. } - public function selectMatchingZoneInfo(int $sector_id) + public function selectMatchingZoneInfo(int $sector_id): ?array { $sql = "SELECT * FROM ::prefix::zones, ::prefix::universe WHERE ::prefix::universe.sector_id = :sector_id AND ::prefix::zones.zone_id = ::prefix::universe.zone_id"; $stmt = $this->pdo_db->prepare($sql); diff --git a/genesis.php b/genesis.php index b0d1357ef..148ac8554 100644 --- a/genesis.php +++ b/genesis.php @@ -50,7 +50,11 @@ // Get planetinfo from database $planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls $planetinfo = $planets_gateway->selectPlanetInfo($playerinfo['sector']); -$num_planets = count($planetinfo); +$num_planets = 0; +if (!empty($planetinfo)) +{ + $num_planets = count($planetinfo); +} // Generate Planetname $planetname = substr($playerinfo['character_name'], 0, 1) . substr($playerinfo['ship_name'], 0, 1) . "-" . $playerinfo['sector'] . "-" . ($num_planets + 1); diff --git a/languages/english.ini b/languages/english.ini index 01264f6d5..5748658bf 100644 --- a/languages/english.ini +++ b/languages/english.ini @@ -623,6 +623,7 @@ l_global_nzone = "Zone is a neutral zone."; l_global_team = "Zone now belongs to team"; l_global_player = "Zone now belongs to player"; l_global_click_first = "You need to Click on the ship first."; +l_global_sector_owner_nochange = "Sector ownership didn't change."; [global_includes] l_insignia_0 = "New recruit"; diff --git a/main.php b/main.php index b72d7a299..29f6af3ff 100644 --- a/main.php +++ b/main.php @@ -90,7 +90,7 @@ $links_gateway = new \Tki\Links\LinksGateway($pdo_db); // Build a links gateway object to handle the SQL calls $link_present = $links_gateway->selectAllLinkInfoByLinkStart($playerinfo['sector']); -if ($link_present !== false) +if (!empty($link_present)) { foreach ($link_present as $tmp_link) { @@ -106,7 +106,7 @@ // Get planetinfo from database $planets_gateway = new Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls $planetinfo = $planets_gateway->selectAllPlanetInfo($playerinfo['sector']); -if ($planetinfo !== false) +if (!empty($planetinfo)) { foreach ($planetinfo as $tmp_planet) { diff --git a/mines.php b/mines.php index 35ef15eb3..40913f04f 100644 --- a/mines.php +++ b/mines.php @@ -60,7 +60,7 @@ $defenses_gateway = new \Tki\Defenses\DefensesGateway($pdo_db); // Build a defense gateway object to handle the SQL calls $defenses_present = $defenses_gateway->selectDefenses($playerinfo['sector']); -if ($defenses_present !== false) +if (!empty($defenses_present)) { foreach ($link_present as $tmp_link) { @@ -83,7 +83,7 @@ $defenses = array(); // Do we have a valid recordset? -if ($defenses_present) +if (!empty($defenses_present)) { foreach ($defenses_present as $tmp_defense) { diff --git a/modify_defenses.php b/modify_defenses.php index 4447affab..a1f21ed98 100644 --- a/modify_defenses.php +++ b/modify_defenses.php @@ -140,7 +140,7 @@ $total_sector_fighters = $ttl['totalfighters']; $calledfrom = "modify_defenses.php"; $energyscooped = 0; - Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, $energyscooped); + Tki\CheckDefenses::sectorFighters($pdo_db, $lang, $sector, $calledfrom, $energyscooped, $playerinfo, $tkireg, $title); } else { @@ -183,7 +183,7 @@ die(); } - $quantity = (int) preg_replace('/[^0-9]/', '', $quantity); + $quantity = (string) preg_replace('/[^0-9]/', '', (string) $quantity); if ($quantity < 0) { $quantity = 0; diff --git a/move.php b/move.php index dfa484877..b9e042239 100644 --- a/move.php +++ b/move.php @@ -81,7 +81,7 @@ if ($flag == 1) { $calledfrom = "move.php"; - Tki\CheckDefenses::fighters($pdo_db, $db, $lang, $sector); + Tki\CheckDefenses::fighters($pdo_db, $db, $lang, $sector, $playerinfo, $tkireg, $title, $calledfrom); $cur_time_stamp = date("Y-m-d H:i:s"); Tki\LogMove::writeLog($pdo_db, $playerinfo['ship_id'], $sector); @@ -99,7 +99,7 @@ } // Enter code for checking dangers in new sector - Tki\CheckDefenses::mines($pdo_db, $db, $lang, $sector, $title); + Tki\CheckDefenses::mines($pdo_db, $db, $lang, $sector, $title, $playerinfo, $tkireg); header("Location: main.php"); } else diff --git a/planet.php b/planet.php index 18fb9bd95..06531265a 100644 --- a/planet.php +++ b/planet.php @@ -78,9 +78,8 @@ // Get planetinfo from database $planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls $planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id); -$num_planets = count($planetinfo); -if (!$planetinfo) +if (!empty($planetinfo)) { echo $langvars['l_planet2_invalid_planet'] . "

"; Tki\Text::gotoMain($pdo_db, $lang); @@ -89,7 +88,7 @@ $admin_log = new Tki\AdminLog(); -if ($planetinfo) // If there is a planet in the sector show appropriate menu +if (!empty($planetinfo)) // If there is a planet in the sector show appropriate menu { if ($playerinfo['sector'] != $planetinfo['sector_id']) { diff --git a/planet2.php b/planet2.php index 599ce9e2f..c2337bf20 100644 --- a/planet2.php +++ b/planet2.php @@ -177,7 +177,7 @@ $planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id); // Check to see if it returned valid planet info. -if ($planetinfo === false) +if (!empty($planetinfo)) { echo $langvars['l_planet2_invalid_planet'] . "

"; Tki\Text::gotoMain($pdo_db, $lang); diff --git a/planet3.php b/planet3.php index e451fdd83..927eb36d5 100644 --- a/planet3.php +++ b/planet3.php @@ -81,7 +81,7 @@ $planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id); // Check to see if it returned valid planet info. -if ($planetinfo === false) +if (!empty($planetinfo)) { echo $langvars['l_planet2_invalid_planet'] . "

"; Tki\Text::gotoMain($pdo_db, $lang); diff --git a/preset.php b/preset.php index 8113bcfc7..4d8a40e45 100644 --- a/preset.php +++ b/preset.php @@ -77,8 +77,8 @@ if ($preset === false) { $change = 0; - $result = str_replace("[preset]", $_POST['preset'][$index], $langvars['l_pre_exceed']); - $result = str_replace("[max_sectors]", $tkireg->max_sectors, $result); + $result = str_replace("[preset]", (string) $_POST['preset'][$index], (string) $langvars['l_pre_exceed']); + $result = str_replace("[max_sectors]", (string) $tkireg->max_sectors, $result); $result = htmlentities($result, ENT_QUOTES | ENT_HTML5, 'UTF-8'); echo $result . "
\n"; } @@ -111,7 +111,7 @@ $stmt->bindParam(':preset_id', $new_id, PDO::PARAM_INT); $stmt->execute(); - $preset_result_echo = str_replace("[preset]", "$preset_list[$key]", $langvars['l_pre_set_loop']); + $preset_result_echo = str_replace("[preset]", "$preset_list[$key]", (string) $langvars['l_pre_set_loop']); $preset_result_echo = str_replace("[num]", (string) ($key + 1), $preset_result_echo); echo $preset_result_echo . "
"; } diff --git a/rsmove.php b/rsmove.php index 17c60694e..9207b2282 100644 --- a/rsmove.php +++ b/rsmove.php @@ -184,7 +184,7 @@ { $sector = $destination; $calledfrom = "rsmove.php"; - Tki\CheckDefenses::fighters($pdo_db, $db, $lang, $sector); + Tki\CheckDefenses::fighters($pdo_db, $db, $lang, $sector, $playerinfo, $tkireg, $title, $calledfrom); // Output: // You are now in sector X. You used Y turns, and gained Z energy units. @@ -200,7 +200,7 @@ $langvars['l_rs_ready'] = str_replace("[triptime]", number_format($triptime, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), $langvars['l_rs_ready']); $langvars['l_rs_ready'] = str_replace("[energy]", number_format($energyscooped, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), $langvars['l_rs_ready']); echo $langvars['l_rs_ready'] . "

"; - Tki\CheckDefenses::mines($pdo_db, $db, $lang, $sector, $title); + Tki\CheckDefenses::mines($pdo_db, $db, $lang, $sector, $title, $playerinfo, $tkireg); } } } diff --git a/team.php b/team.php index 589787c8d..5133808dc 100644 --- a/team.php +++ b/team.php @@ -38,7 +38,7 @@ $players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']); -$planet_id = (int) preg_replace('/[^0-9]/', '', $_GET['planet_id']); +$planet_id = (int) preg_replace('/[^0-9]/', '', (string) $_GET['planet_id']); // Get planetinfo from database $planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls diff --git a/teams.php b/teams.php index c56747658..8cc54ba61 100644 --- a/teams.php +++ b/teams.php @@ -57,7 +57,7 @@ $confirmleave = null; if (array_key_exists('confirmleave', $_REQUEST) === true) { - $confirmleave = (string) preg_replace('/[^0-9]/', '', $_REQUEST['confirmleave']); + $confirmleave = (string) preg_replace('/[^0-9]/', '', (string) $_REQUEST['confirmleave']); $confirmleave = (int) $confirmleave; } diff --git a/zoneedit.php b/zoneedit.php index 0a7253806..4599b1d55 100644 --- a/zoneedit.php +++ b/zoneedit.php @@ -112,7 +112,7 @@ $zones_gateway = new \Tki\Zones\ZonesGateway($pdo_db); // Build a zone gateway object to handle the SQL calls $zoneinfo = $zones_gateway->selectZoneInfo($zone); -if (!$zoneinfo) +if (!empty($zoneinfo)) { echo "

" . $langvars['l_zi_nexist'] . "

"; Tki\Text::gotoMain($pdo_db, $lang); diff --git a/zoneinfo.php b/zoneinfo.php index adc14bf2b..1db21bb8e 100644 --- a/zoneinfo.php +++ b/zoneinfo.php @@ -48,7 +48,7 @@ $zoneinfo = $zones_gateway->selectZoneInfoByZone($zone); $ownerinfo = array(); -if (!$zoneinfo) +if (!empty($zoneinfo)) { echo $langvars['l_zi_nexist']; }