public static function collectCredits(\PDO $pdo_db, \ADODB_mysqli $db, array $langvars, array $planetarray, Reg $tkireg) { $request = Request::createFromGlobals(); $CS = "GO"; // Current State // Look up the info for the player that wants to collect the credits. $result1 = $db->SelectLimit("SELECT * FROM {$db->prefix}ships WHERE email = ?", 1, -1, array('email' => $_SESSION['username'])); \Tki\Db::LogDbErrors($pdo_db, $result1, __LINE__, __FILE__); $playerinfo = $result1->fields; // Set s_p_pair as an array. $s_p_pair = array(); // Create an array of sector -> planet pairs $temp_count = count($planetarray); for ($i = 0; $i < $temp_count; $i++) { $res = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id = ?;", array($planetarray[$i])); \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__); // Only add to array if the player owns the planet. if ($res->fields['owner'] == $playerinfo['ship_id'] && $res->fields['sector_id'] < $tkireg->max_sectors) { $s_p_pair[$i] = array($res->fields['sector_id'], $planetarray[$i]); } else { $hack_id = 20100401; $ip = $request->query->get('REMOTE_ADDR'); $planet_id = $res->fields['planet_id']; $sector_id = $res->fields['sector_id']; \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$sector_id}|{$playerinfo['ship_id']}"); break; } } // Sort the array so that it is in order of sectors, lowest number first, not closest sort($s_p_pair); reset($s_p_pair); // Run through the list of sector planet pairs realspace moving to each sector and then performing the transfer. // Based on the way realspace works we don't need a sub loop -- might add a subloop to clean things up later. $temp_count2 = count($s_p_pair); for ($i = 0; $i < $temp_count2 && $CS == "GO"; $i++) { echo "<br>"; $CS = \Tki\Realspace\realSpaceMove($pdo_db, $langvars, $s_p_pair[$i][0], $tkireg); if ($CS == "HOSTILE") { $CS = "GO"; } elseif ($CS == "GO") { $CS = self::takeCredits($pdo_db, $db, $langvars, $s_p_pair[$i][1]); } else { echo "<br>" . $langvars['l_pr_low_turns'] . "<br>"; } echo "<br>"; } if ($CS != "GO" && $CS != "HOSTILE") { echo "<br>" . $langvars['l_pr_low_turns'] . "<br>"; } echo "<br>"; echo str_replace("[here]", "<a href='planet_report.php?preptype=1'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_status']); echo "<br><br>"; }
public static function productionChange(\PDO $pdo_db, \ADODB_mysqli $db, array $langvars, array $prodpercentarray, Reg $tkireg) { // Declare default production values from the config.php file // // We need to track what the player_id is and what team they belong to if they belong to a team, // these two values are not passed in as arrays // ship_id = the owner of the planet ($ship_id = $prodpercentarray['ship_id']) // team_id = the team creators ship_id ($team_id = $prodpercentarray['team_id']) // // First we generate a list of values based on the commodity // (ore, organics, goods, energy, fighters, torps, team, sells) // // Second we generate a second list of values based on the planet_id // Because team and ship_id are not arrays we do not pass them through the second list command. // When we write the ore production percent we also clear the selling and team values out of the db // When we pass through the team array we set the value to $team we grabbed out of the array. // in the sells and team the prodpercent = the planet_id. // // We run through the database checking to see if any planet production is greater than 100, or possibly negative // if so we set the planet to the default values and report it to the player. // // There has got to be a better way, but at this time I am not sure how to do it. // Off the top of my head if we could sort the data passed in, in order of planets we could check before we do the writes // This would save us from having to run through the database a second time checking our work. // This should patch the game from being hacked with planet Hack. $request = Request::createFromGlobals(); $result = $db->Execute("SELECT ship_id, team FROM {$db->prefix}ships WHERE email = ?;", array($_SESSION['username'])); \Tki\Db::LogDbErrors($pdo_db, $result, __LINE__, __FILE__); $ship_id = $result->fields['ship_id']; $planet_hack = false; $hack_id = 0x0; $hack_count = array(0, 0, 0); echo str_replace("[here]", "<a href='planet_report.php?preptype=2'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_prod']); echo "<br><br>"; while (list($commod_type, $valarray) = each($prodpercentarray)) { if ($commod_type != "team_id" && $commod_type != "ship_id") { while (list($planet_id, $prodpercent) = each($valarray)) { if ($commod_type == "prod_ore" || $commod_type == "prod_organics" || $commod_type == "prod_goods" || $commod_type == "prod_energy" || $commod_type == "prod_fighters" || $commod_type == "prod_torp") { $res = $db->Execute("SELECT COUNT(*) AS owned_planet FROM {$db->prefix}planets WHERE planet_id = ? AND owner = ?;", array($planet_id, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__); if ($res->fields['owned_planet'] == 0) { $ip = $request->query->get('REMOTE_ADDR'); $planet_hack = true; $hack_id = 0x18582; $hack_count[0]++; \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$ship_id}|commod_type={$commod_type}"); } $resx = $db->Execute("UPDATE {$db->prefix}planets SET {$commod_type} = ? WHERE planet_id = ? AND owner = ?;", array($prodpercent, $planet_id, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); $resy = $db->Execute("UPDATE {$db->prefix}planets SET sells='N' WHERE planet_id = ? AND owner = ?;", array($planet_id, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $resy, __LINE__, __FILE__); $resz = $db->Execute("UPDATE {$db->prefix}planets SET team=0 WHERE planet_id = ? AND owner = ?;", array($planet_id, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $resz, __LINE__, __FILE__); } elseif ($commod_type == "sells") { $resx = $db->Execute("UPDATE {$db->prefix}planets SET sells='Y' WHERE planet_id = ? AND owner = ?;", array($prodpercent, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); } elseif ($commod_type == "team") { // Compare entered team_id and one in the db, if different then use one from db $res = $db->Execute("SELECT {$db->prefix}ships.team as owner FROM {$db->prefix}ships, {$db->prefix}planets WHERE ( {$db->prefix}ships.ship_id = {$db->prefix}planets.owner ) AND ( {$db->prefix}planets.planet_id = ?);", array($prodpercent)); \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__); if ($res) { $team_id = $res->fields['owner']; } else { $team_id = 0; } $resx = $db->Execute("UPDATE {$db->prefix}planets SET team = ? WHERE planet_id = ? AND owner = ?;", array($team_id, $prodpercent, $ship_id)); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); if (array_key_exists("team_id", $prodpercentarray) === true && $prodpercentarray['team_id'] != $team_id) { // They are different so send admin a log $ip = $request->query->get('REMOTE_ADDR'); $planet_hack = true; $hack_id = 0x18531; $hack_count[1]++; \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$prodpercent}|{$ship_id}|{$prodpercentarray['team_id']} not {$team_id}"); } } else { $ip = $request->query->get('REMOTE_ADDR'); $planet_hack = true; $hack_id = 0x18598; $hack_count[2]++; \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$ship_id}|commod_type={$commod_type}"); } } } } if ($planet_hack) { $serial_data = serialize($prodpercentarray); \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT + 1000, "{$ship_id}|{$serial_data}"); printf("<font color=\"red\"><strong>Your Cheat has been logged to the admin (%08x) [%02X:%02X:%02X].</strong></font><br>\n", (int) $hack_id, (int) $hack_count[0], (int) $hack_count[1], (int) $hack_count[2]); } echo "<br>"; echo $langvars['l_pr_prod_updated'] . "<br><br>"; echo $langvars['l_pr_checking_values'] . "<br><br>"; $res = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE owner = ? ORDER BY sector_id;", array($ship_id)); \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__); $i = 0; $planet = array(); $planets = array(); if ($res) { while (!$res->EOF) { $planets[$i] = $res->fields; $i++; $res->MoveNext(); } foreach ($planets as $planet) { if (empty($planet['name'])) { $planet['name'] = $langvars['l_unnamed']; } if ($planet['prod_ore'] < 0) { $planet['prod_ore'] = 110; } if ($planet['prod_organics'] < 0) { $planet['prod_organics'] = 110; } if ($planet['prod_goods'] < 0) { $planet['prod_goods'] = 110; } if ($planet['prod_energy'] < 0) { $planet['prod_energy'] = 110; } if ($planet['prod_fighters'] < 0) { $planet['prod_fighters'] = 110; } if ($planet['prod_torp'] < 0) { $planet['prod_torp'] = 110; } 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 . "<br>"; $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__); $resb = $db->Execute("UPDATE {$db->prefix}planets SET prod_organics = ? WHERE planet_id = ?;", array($tkireg->default_prod_organics, $planet['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resb, __LINE__, __FILE__); $resc = $db->Execute("UPDATE {$db->prefix}planets SET prod_goods = ? WHERE planet_id = ?;", array($tkireg->default_prod_goods, $planet['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resc, __LINE__, __FILE__); $resd = $db->Execute("UPDATE {$db->prefix}planets SET prod_energy = ? WHERE planet_id = ?;", array($tkireg->default_prod_energy, $planet['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resd, __LINE__, __FILE__); $rese = $db->Execute("UPDATE {$db->prefix}planets SET prod_fighters = ? WHERE planet_id = ?;", array($tkireg->default_prod_fighters, $planet['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $rese, __LINE__, __FILE__); $resf = $db->Execute("UPDATE {$db->prefix}planets SET prod_torp = ? WHERE planet_id = ?;", array($tkireg->default_prod_torp, $planet['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resf, __LINE__, __FILE__); } } } }
public static function buildBase(\PDO $pdo_db, array $langvars, int $planet_id, int $sector_id, Reg $tkireg) { $request = Request::createFromGlobals(); echo "<br>"; echo str_replace("[here]", "<a href='planet_report.php?preptype=1'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_status']); echo "<br><br>"; // Get playerinfo from database $sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':email', $_SESSION['username']); $stmt->execute(); $playerinfo = $stmt->fetch(\PDO::FETCH_ASSOC); $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':planet_id', $planet_id); $stmt->execute(); $planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC); // Error out and return if the Player isn't the owner of the Planet // Verify player owns the planet which is to have the base created on. if ($planetinfo['owner'] != $playerinfo['ship_id']) { echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_make_base_failed'] . "</div>\n"; echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_invalid_info'] . "</div>\n"; return (bool) false; } if (!is_numeric($planet_id) || !is_numeric($sector_id)) { $ip = $request->query->get('REMOTE_ADDR'); $hack_id = 0x1337; \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$sector_id}|{$playerinfo['ship_id']}"); echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_make_base_failed'] . "</div>\n"; return (bool) false; } // Build a base \Tki\Realspace\realSpaceMove($pdo_db, $langvars, $sector_id, $tkireg); echo "<br>"; echo str_replace("[here]", "<a href='planet.php?planet_id={$planet_id}'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_planet']); echo "<br><br>"; if ($planetinfo['ore'] >= $tkireg->base_ore && $planetinfo['organics'] >= $tkireg->base_organics && $planetinfo['goods'] >= $tkireg->base_goods && $planetinfo['credits'] >= $tkireg->base_credits) { // Create The Base $stmt = $pdo_db->prepare("UPDATE ::prefix::planets SET base='Y', ore = :planetore - :baseore, organics = :planetorg - :baseorg, goods = :planetgoods - :basegoods, credits = :planetcredits - :basecredits WHERE planet_id = :planet_id"); $stmt->bindParam(':planetore', $planetinfo['ore']); $stmt->bindParam(':baseore', $tkireg->base_ore); $stmt->bindParam(':planetorg', $planetinfo['organics']); $stmt->bindParam(':baseorg', $tkireg->base_organics); $stmt->bindParam(':planetgoods', $planetinfo['goods']); $stmt->bindParam(':basegoods', $tkireg->base_goods); $stmt->bindParam(':planetcredits', $planetinfo['credits']); $stmt->bindParam(':basecredits', $tkireg->base_credits); $stmt->bindParam(':planet_id', $planet_id); $result = $stmt->execute(); \Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__); // Update User Turns $stmt = $pdo_db->prepare("UPDATE ::prefix::ships SET turns = turns - 1, turns_used = turns_used + 1 WHERE ship_id = :ship_id"); $stmt->bindParam(':ship_id', $playerinfo['ship_id']); $result = $stmt->execute(); \Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__); // Refresh Planet Info $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':planet_id', $planet_id); $stmt->execute(); $planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC); // Notify User Of Base Results echo $langvars['l_planet_bbuild'] . "<br><br>"; // Calc Ownership and Notify User Of Results $ownership = \Tki\Ownership::calc($pdo_db, $playerinfo['sector'], $tkireg->min_bases_to_own, $langvars); if ($ownership !== null) { echo $ownership . "<p>"; } return $planetinfo; } }
public static function traderouteCheckCompatible(\ADODB_mysqli $db, \PDO $pdo_db, string $lang, $type1, $type2, $move, $circuit, $src, $dest, array $playerinfo, Reg $tkireg, Smarty $template) { $langvars = \Tki\Translate::load($pdo_db, $lang, array('traderoutes', 'common', 'global_includes', 'global_funcs', 'footer', 'regional')); // Check circuit compatibility (we only use types 1 and 2 so block anything else) if ($circuit != "1" && $circuit != "2") { \Tki\AdminLog::writeLog($pdo_db, LOG_RAW, "{$playerinfo['ship_id']}|Tried to use an invalid circuit_type of '{$circuit}', This is normally a result from using an external page and should be banned."); self::traderouteDie($pdo_db, $lang, $tkireg, "Invalid Circuit type!<br>*** Possible Exploit has been reported to the admin. ***", $template); } // Check warp links compatibility if ($move == 'warp') { $query = $db->Execute("SELECT link_id FROM {$db->prefix}links WHERE link_start = ? AND link_dest = ?;", array($src['sector_id'], $dest['sector_id'])); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); if ($query->EOF) { $langvars['l_tdr_nowlink1'] = str_replace("[tdr_src_sector_id]", $src['sector_id'], $langvars['l_tdr_nowlink1']); $langvars['l_tdr_nowlink1'] = str_replace("[tdr_dest_sector_id]", $dest['sector_id'], $langvars['l_tdr_nowlink1']); self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_nowlink1'], $template); } if ($circuit == '2') { $query = $db->Execute("SELECT link_id FROM {$db->prefix}links WHERE link_start = ? AND link_dest = ?;", array($dest['sector_id'], $src['sector_id'])); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); if ($query->EOF) { $langvars['l_tdr_nowlink2'] = str_replace("[tdr_src_sector_id]", $src['sector_id'], $langvars['l_tdr_nowlink2']); $langvars['l_tdr_nowlink2'] = str_replace("[tdr_dest_sector_id]", $dest['sector_id'], $langvars['l_tdr_nowlink2']); self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_nowlink2'], $template); } } } // Check ports compatibility if ($type1 == 'port') { if ($src['port_type'] == 'special') { if ($type2 != 'planet' && $type2 != 'team_planet') { self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_sportissrc'], $template); } if ($dest['owner'] != $playerinfo['ship_id'] && ($dest['team'] == 0 || $dest['team'] != $playerinfo['team'])) { self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_notownplanet'], $template); } } else { if ($type2 == 'planet') { self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_planetisdest'], $template); } if ($src['port_type'] == $dest['port_type']) { self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_samecom'], $template); } } } else { if (array_key_exists('port_type', $dest) === true && $dest['port_type'] == 'special') { self::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_sportcom'], $template); } } }
public static function planetCombat(\PDO $pdo_db, \ADODB_mysqli $db, string $lang, array $langvars, Reg $tkireg, Smarty $template, array $playerinfo, $ownerinfo, $planetinfo) { if ($playerinfo['turns'] < 1) { echo $langvars['l_cmb_atleastoneturn'] . "<br><br>"; \Tki\Text::gotomain($pdo_db, $lang); \Tki\Footer::display($pdo_db, $lang, $tkireg, $template); die; } // Planetary defense system calculation $planetbeams = \Tki\CalcLevels::planetBeams($pdo_db, $ownerinfo, $tkireg->base_defense, $planetinfo); $planetfighters = $planetinfo['fighters']; $planetshields = \Tki\CalcLevels::planetShields($pdo_db, $ownerinfo, $tkireg->base_defense, $planetinfo); $planettorps = \Tki\CalcLevels::planetTorps($pdo_db, $ownerinfo, $planetinfo, $tkireg); // Attacking ship calculations $attackerbeams = \Tki\CalcLevels::beams($playerinfo['beams'], $tkireg); $attackerfighters = $playerinfo['ship_fighters']; $attackershields = \Tki\CalcLevels::shields($playerinfo['shields'], $tkireg); $attackertorps = round(pow($tkireg->level_factor, $playerinfo['torp_launchers'])) * 2; $attackerarmor = $playerinfo['armor_pts']; // Now modify player beams, shields and torpedos on available materiel $tkireg->start_energy = $playerinfo['ship_energy']; // Beams if ($attackerbeams > $playerinfo['ship_energy']) { $attackerbeams = $playerinfo['ship_energy']; } $playerinfo['ship_energy'] = $playerinfo['ship_energy'] - $attackerbeams; // Shields if ($attackershields > $playerinfo['ship_energy']) { $attackershields = $playerinfo['ship_energy']; } $playerinfo['ship_energy'] = $playerinfo['ship_energy'] - $attackershields; // Torpedos if ($attackertorps > $playerinfo['torps']) { $attackertorps = $playerinfo['torps']; } $playerinfo['torps'] = $playerinfo['torps'] - $attackertorps; // Setup torp damage rate for both Planet and Ship $planettorpdamage = $tkireg->torp_dmg_rate * $planettorps; $attackertorpdamage = $tkireg->torp_dmg_rate * $attackertorps; echo "\n <center>\n <hr>\n <table width='75%' border='0'>\n <tr align='center'>\n <td width='9%' height='27'></td>\n <td width='12%' height='27'><font color='white'>" . $langvars['l_cmb_beams'] . "</font></td>\n <td width='17%' height='27'><font color='white'>" . $langvars['l_cmb_fighters'] . "</font></td>\n <td width='18%' height='27'><font color='white'>" . $langvars['l_cmb_shields'] . "</font></td>\n <td width='11%' height='27'><font color='white'>" . $langvars['l_cmb_torps'] . "</font></td>\n <td width='22%' height='27'><font color='white'>" . $langvars['l_cmb_torpdamage'] . "</font></td>\n <td width='11%' height='27'><font color='white'>" . $langvars['l_cmb_armor'] . "</font></td>\n </tr>\n <tr align='center'>\n <td width='9%'> <font color='red'>" . $langvars['l_cmb_you'] . "</td>\n <td width='12%'><font color='red'><strong>" . $attackerbeams . "</strong></font></td>\n <td width='17%'><font color='red'><strong>" . $attackerfighters . "</strong></font></td>\n <td width='18%'><font color='red'><strong>" . $attackershields . "</strong></font></td>\n <td width='11%'><font color='red'><strong>" . $attackertorps . "</strong></font></td>\n <td width='22%'><font color='red'><strong>" . $attackertorpdamage . "</strong></font></td>\n <td width='11%'><font color='red'><strong>" . $attackerarmor . "</strong></font></td>\n </tr>\n <tr align='center'>\n <td width='9%'> <font color='#6098F8'>" . $langvars['l_cmb_planet'] . "</font></td>\n <td width='12%'><font color='#6098F8'><strong>" . $planetbeams . "</strong></font></td>\n <td width='17%'><font color='#6098F8'><strong>" . $planetfighters . "</strong></font></td>\n <td width='18%'><font color='#6098F8'><strong>" . $planetshields . "</strong></font></td>\n <td width='11%'><font color='#6098F8'><strong>" . $planettorps . "</strong></font></td>\n <td width='22%'><font color='#6098F8'><strong>" . $planettorpdamage . "</strong></font></td>\n <td width='11%'><font color='#6098F8'><strong>N/A</strong></font></td>\n </tr>\n </table>\n <hr>\n </center>\n "; // Begin actual combat calculations echo "<br><center><strong><font size='+2'>" . $langvars['l_cmb_combatflow'] . "</font></strong><br><br>\n"; echo "<table width='75%' border='0'><tr align='center'><td><font color='red'>" . $langvars['l_cmb_you'] . "</font></td><td><font color='#6098F8'>" . $langvars['l_cmb_defender'] . "</font></td>\n"; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_attackingplanet'] . " " . $playerinfo['sector'] . "</strong></font></td><td></td>"; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youfireyourbeams'] . "</strong></font></td><td></td>\n"; if ($planetfighters > 0 && $attackerbeams > 0) { if ($attackerbeams > $planetfighters) { $langvars['l_cmb_defenselost'] = str_replace("[cmb_planetfighters]", $planetfighters, $langvars['l_cmb_defenselost']); echo "<tr align='center'><td></td><td><font color='#6098F8'><strong>" . $langvars['l_cmb_defenselost'] . "</strong></font>"; $attackerbeams = $attackerbeams - $planetfighters; $planetfighters = 0; } else { $langvars['l_cmb_defenselost2'] = str_replace("[cmb_attackerbeams]", $attackerbeams, $langvars['l_cmb_defenselost2']); $planetfighters = $planetfighters - $attackerbeams; echo "<tr align='center'><td></td><td><font color='#6098F8'><strong>" . $langvars['l_cmb_defenselost2'] . "</strong></font>"; $attackerbeams = 0; } } if ($attackerfighters > 0 && $planetbeams > 0) { // If there are more beams on the planet than attacker has fighters if ($planetbeams > round($attackerfighters / 2)) { // Half the attacker fighters $temp = round($attackerfighters / 2); // Attacker loses half his fighters $lost = $attackerfighters - $temp; // Set attacker fighters to 1/2 it's original value $attackerfighters = $temp; // Subtract half the attacker fighters from available planetary beams $planetbeams = $planetbeams - $lost; $langvars['l_cmb_planetarybeams'] = str_replace("[cmb_temp]", $temp, $langvars['l_cmb_planetarybeams']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_planetarybeams'] . "</strong></font><td></td>"; } else { $langvars['l_cmb_planetarybeams2'] = str_replace("[cmb_planetbeams]", $planetbeams, $langvars['l_cmb_planetarybeams2']); $attackerfighters = $attackerfighters - $planetbeams; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_planetarybeams2'] . "</strong></font><td></td>"; $planetbeams = 0; } } if ($attackerbeams > 0) { if ($attackerbeams > $planetshields) { $attackerbeams = $attackerbeams - $planetshields; $planetshields = 0; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyedplanetshields'] . "</font></strong><td></td>"; } else { $langvars['l_cmb_beamsexhausted'] = str_replace("[cmb_attackerbeams]", $attackerbeams, $langvars['l_cmb_beamsexhausted']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_beamsexhausted'] . "</font></strong><td></td>"; $planetshields = $planetshields - $attackerbeams; $attackerbeams = 0; } } if ($planetbeams > 0) { if ($planetbeams > $attackershields) { $planetbeams = $planetbeams - $attackershields; $attackershields = 0; echo "<tr align='center'><td></td><td><font color='#6098F8'><strong>" . $langvars['l_cmb_breachedyourshields'] . "</font></strong></td>"; } else { $attackershields = $attackershields - $planetbeams; $langvars['l_cmb_destroyedyourshields'] = str_replace("[cmb_planetbeams]", $planetbeams, $langvars['l_cmb_destroyedyourshields']); echo "<tr align='center'><td></td><font color='#6098F8'><strong>" . $langvars['l_cmb_destroyedyourshields'] . "</font></strong></td>"; $planetbeams = 0; } } if ($planetbeams > 0) { if ($planetbeams > $attackerarmor) { $attackerarmor = 0; echo "<tr align='center'><td></td><td><font color='#6098F8'><strong>" . $langvars['l_cmb_breachedyourarmor'] . "</strong></font></td>"; } else { $attackerarmor = $attackerarmor - $planetbeams; $langvars['l_cmb_destroyedyourarmor'] = str_replace("[cmb_planetbeams]", $planetbeams, $langvars['l_cmb_destroyedyourarmor']); echo "<tr align='center'><td></td><td><font color='#6098F8'><strong>" . $langvars['l_cmb_destroyedyourarmor'] . "</font></strong></td>"; } } echo "<tr align='center'><td><font color='YELLOW'><strong>" . $langvars['l_cmb_torpedoexchangephase'] . "</strong></font></td><td><strong><font color='YELLOW'>" . $langvars['l_cmb_torpedoexchangephase'] . "</strong></font></td><br>"; if ($planetfighters > 0 && $attackertorpdamage > 0) { if ($attackertorpdamage > $planetfighters) { $langvars['l_cmb_nofightersleft'] = str_replace("[cmb_planetfighters]", $planetfighters, $langvars['l_cmb_nofightersleft']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_nofightersleft'] . "</font></strong></td><td></td>"; $attackertorpdamage = $attackertorpdamage - $planetfighters; $planetfighters = 0; } else { $planetfighters = $planetfighters - $attackertorpdamage; $langvars['l_cmb_youdestroyfighters'] = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $langvars['l_cmb_youdestroyfighters']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyfighters'] . "</font></strong></td><td></td>"; $attackertorpdamage = 0; } } if ($attackerfighters > 0 && $planettorpdamage > 0) { if ($planettorpdamage > round($attackerfighters / 2)) { $temp = round($attackerfighters / 2); $lost = $attackerfighters - $temp; $attackerfighters = $temp; $planettorpdamage = $planettorpdamage - $lost; $langvars['l_cmb_planettorpsdestroy'] = str_replace("[cmb_temp]", $temp, $langvars['l_cmb_planettorpsdestroy']); echo "<tr align='center'><td></td><td><font color='red'><strong>" . $langvars['l_cmb_planettorpsdestroy'] . "</strong></font></td>"; } else { $attackerfighters = $attackerfighters - $planettorpdamage; $langvars['l_cmb_planettorpsdestroy2'] = str_replace("[cmb_planettorpdamage]", $planettorpdamage, $langvars['l_cmb_planettorpsdestroy2']); echo "<tr align='center'><td></td><td><font color='red'><strong>" . $langvars['l_cmb_planettorpsdestroy2'] . "</strong></font></td>"; $planettorpdamage = 0; } } if ($planettorpdamage > 0) { if ($planettorpdamage > $attackerarmor) { $attackerarmor = 0; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_torpsbreachedyourarmor'] . "</strong></font></td><td></td>"; } else { $attackerarmor = $attackerarmor - $planettorpdamage; $langvars['l_cmb_planettorpsdestroy3'] = str_replace("[cmb_planettorpdamage]", $planettorpdamage, $langvars['l_cmb_planettorpsdestroy3']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_planettorpsdestroy3'] . "</strong></font></td><td></td>"; } } if ($attackertorpdamage > 0 && $planetfighters > 0) { $planetfighters = $planetfighters - $attackertorpdamage; if ($planetfighters < 0) { $planetfighters = 0; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyedallfighters'] . "</strong></font></td><td></td>"; } else { $langvars['l_cmb_youdestroyplanetfighters'] = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $langvars['l_cmb_youdestroyplanetfighters']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyplanetfighters'] . "</strong></font></td><td></td>"; } } echo "<tr align='center'><td><font color='YELLOW'><strong>" . $langvars['l_cmb_fightercombatphase'] . "</strong></font></td><td><strong><font color='YELLOW'>" . $langvars['l_cmb_fightercombatphase'] . "</strong></font></td><br>"; if ($attackerfighters > 0 && $planetfighters > 0) { if ($attackerfighters > $planetfighters) { echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyedallfighters2'] . "</strong></font></td><td></td>"; $tempplanetfighters = 0; } else { $langvars['l_cmb_youdestroyplanetfighters2'] = str_replace("[cmb_attackerfighters]", $attackerfighters, $langvars['l_cmb_youdestroyplanetfighters2']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youdestroyplanetfighters2'] . "</strong></font></td><td></td>"; $tempplanetfighters = $planetfighters - $attackerfighters; } if ($planetfighters > $attackerfighters) { echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_allyourfightersdestroyed'] . "</strong></font></td><td></td>"; $tempplayfighters = 0; } else { $tempplayfighters = $attackerfighters - $planetfighters; $langvars['l_cmb_fightertofighterlost'] = str_replace("[cmb_planetfighters]", $planetfighters, $langvars['l_cmb_fightertofighterlost']); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_fightertofighterlost'] . "</strong></font></td><td></td>"; } $attackerfighters = $tempplayfighters; $planetfighters = $tempplanetfighters; } if ($attackerfighters > 0 && $planetshields > 0) { if ($attackerfighters > $planetshields) { $attackerfighters = $attackerfighters - round($planetshields / 2); echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_youbreachedplanetshields'] . "</strong></font></td><td></td>"; $planetshields = 0; } else { $langvars['l_cmb_shieldsremainup'] = str_replace("[cmb_attackerfighters]", $attackerfighters, $langvars['l_cmb_shieldsremainup']); echo "<tr align='center'><td></td><font color='#6098F8'><strong>" . $langvars['l_cmb_shieldsremainup'] . "</strong></font></td>"; $planetshields = $planetshields - $attackerfighters; } } if ($planetfighters > 0) { if ($planetfighters > $attackerarmor) { $attackerarmor = 0; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_fighterswarm'] . "</strong></font></td><td></td>"; } else { $attackerarmor = $attackerarmor - $planetfighters; echo "<tr align='center'><td><font color='red'><strong>" . $langvars['l_cmb_swarmandrepel'] . "</strong></font></td><td></td>"; } } echo "</table></center>\n"; // Send each docked ship in sequence to attack agressor $result4 = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE planet_id = ? AND on_planet = 'Y'", array($planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $result4, __LINE__, __FILE__); $shipsonplanet = $result4->RecordCount(); if ($shipsonplanet > 0) { $langvars['l_cmb_shipdock'] = str_replace("[cmb_shipsonplanet]", $shipsonplanet, $langvars['l_cmb_shipdock']); echo "<br><br><center>" . $langvars['l_cmb_shipdock'] . "<br>" . $langvars['l_cmb_engshiptoshipcombat'] . "</center><br><br>\n"; while (!$result4->EOF) { $onplanet = $result4->fields; if ($attackerfighters < 0) { $attackerfighters = 0; } if ($attackertorps < 0) { $attackertorps = 0; } if ($attackershields < 0) { $attackershields = 0; } if ($attackerbeams < 0) { $attackerbeams = 0; } if ($attackerarmor < 1) { break; } echo "<br>-" . $onplanet['ship_name'] . " " . $langvars['l_cmb_approachattackvector'] . "-<br>"; \Tki\Combat::shipToShip($pdo_db, $db, $langvars, $onplanet['ship_id'], $tkireg, $playerinfo, $attackerbeams, $attackerfighters, $attackershields, $attackertorps, $attackerarmor, $attackertorpdamage); $result4->MoveNext(); } } else { echo "<br><br><center>" . $langvars['l_cmb_noshipsdocked'] . "</center><br><br>\n"; } if ($attackerarmor < 1) { $free_ore = round($playerinfo['ship_ore'] / 2); $free_organics = round($playerinfo['ship_organics'] / 2); $free_goods = round($playerinfo['ship_goods'] / 2); $ship_value = $tkireg->upgrade_cost * (round(pow($tkireg->upgrade_factor, $playerinfo['hull'])) + round(pow($tkireg->upgrade_factor, $playerinfo['engines'])) + round(pow($tkireg->upgrade_factor, $playerinfo['power'])) + round(pow($tkireg->upgrade_factor, $playerinfo['computer'])) + round(pow($tkireg->upgrade_factor, $playerinfo['sensors'])) + round(pow($tkireg->upgrade_factor, $playerinfo['beams'])) + round(pow($tkireg->upgrade_factor, $playerinfo['torp_launchers'])) + round(pow($tkireg->upgrade_factor, $playerinfo['shields'])) + round(pow($tkireg->upgrade_factor, $playerinfo['armor'])) + round(pow($tkireg->upgrade_factor, $playerinfo['cloak']))); $ship_salvage_rate = random_int(0, 10); $ship_salvage = $ship_value * $ship_salvage_rate / 100; echo "<br><center><font size='+2' COLOR='red'><strong>" . $langvars['l_cmb_yourshipdestroyed'] . "</font></strong></center><br>"; if ($playerinfo['dev_escapepod'] == "Y") { echo "<center><font color='white'>" . $langvars['l_cmb_escapepod'] . "</font></center><br><br>"; $resx = $db->Execute("UPDATE {$db->prefix}ships SET hull=0,engines=0,power=0,sensors=0,computer=0,beams=0,torp_launchers=0,torps=0,armor=0,armor_pts=100,cloak=0,shields=0,sector=0,ship_organics=0,ship_ore=0,ship_goods=0,ship_energy = ?,ship_colonists=0,ship_fighters=100,dev_warpedit=0,dev_genesis=0,dev_beacon=0,dev_emerwarp=0,dev_escapepod='N',dev_fuelscoop='N',dev_minedeflector=0,on_planet='N',dev_lssd='N' WHERE ship_id = ?;", array($tkireg->start_energy, $playerinfo['ship_id'])); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); \Tki\Bounty::collect($pdo_db, $langvars, $planetinfo['owner'], $playerinfo['ship_id']); } else { \Tki\Character::kill($pdo_db, $playerinfo['ship_id'], $langvars, $tkireg, false); \Tki\Bounty::collect($pdo_db, $langvars, $planetinfo['owner'], $playerinfo['ship_id']); } } else { $free_ore = 0; $free_goods = 0; $free_organics = 0; $ship_salvage_rate = 0; $ship_salvage = 0; $planetrating = $ownerinfo['hull'] + $ownerinfo['engines'] + $ownerinfo['computer'] + $ownerinfo['beams'] + $ownerinfo['torp_launchers'] + $ownerinfo['shields'] + $ownerinfo['armor']; if ($ownerinfo['rating'] != 0) { $rating_change = $ownerinfo['rating'] / abs($ownerinfo['rating']) * $planetrating * 10; } else { $rating_change = -100; } echo "<center><br><strong><font size='+2'>" . $langvars['l_cmb_finalcombatstats'] . "</font></strong><br><br>"; $fighters_lost = $playerinfo['ship_fighters'] - $attackerfighters; $langvars['l_cmb_youlostfighters'] = str_replace("[cmb_fighters_lost]", $fighters_lost, $langvars['l_cmb_youlostfighters']); $langvars['l_cmb_youlostfighters'] = str_replace("[cmb_playerinfo_ship_fighters]", $playerinfo['ship_fighters'], $langvars['l_cmb_youlostfighters']); echo $langvars['l_cmb_youlostfighters'] . "<br>"; $armor_lost = $playerinfo['armor_pts'] - $attackerarmor; $langvars['l_cmb_youlostarmorpoints'] = str_replace("[cmb_armor_lost]", $armor_lost, $langvars['l_cmb_youlostarmorpoints']); $langvars['l_cmb_youlostarmorpoints'] = str_replace("[cmb_playerinfo_armor_pts]", $playerinfo['armor_pts'], $langvars['l_cmb_youlostarmorpoints']); $langvars['l_cmb_youlostarmorpoints'] = str_replace("[cmb_attackerarmor]", $attackerarmor, $langvars['l_cmb_youlostarmorpoints']); echo $langvars['l_cmb_youlostarmorpoints'] . "<br>"; $energy = $playerinfo['ship_energy']; $energy_lost = $tkireg->start_energy - $playerinfo['ship_energy']; $langvars['l_cmb_energyused'] = str_replace("[cmb_energy_lost]", $energy_lost, $langvars['l_cmb_energyused']); $langvars['l_cmb_energyused'] = str_replace("[cmb_playerinfo_ship_energy]", $tkireg->start_energy, $langvars['l_cmb_energyused']); echo $langvars['l_cmb_energyused'] . "<br></center>"; $resx = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy = ?, ship_fighters = ship_fighters - ?, torps = torps - ?, armor_pts = armor_pts - ?, rating = rating - ? WHERE ship_id = ?;", array($energy, $fighters_lost, $attackertorps, $armor_lost, $rating_change, $playerinfo['ship_id'])); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); } $result4 = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE planet_id = ? AND on_planet = 'Y';", array($planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $result4, __LINE__, __FILE__); $shipsonplanet = $result4->RecordCount(); if ($planetshields < 1 && $planetfighters < 1 && $attackerarmor > 0 && $shipsonplanet == 0) { echo "<br><br><center><font color='GREEN'><strong>" . $langvars['l_cmb_planetdefeated'] . "</strong></font></center><br><br>"; // Patch to stop players dumping credits for other players. $self_tech = \Tki\CalcLevels::avgTech($playerinfo); $target_tech = round(\Tki\CalcLevels::avgTech($ownerinfo)); $roll = random_int(0, (int) $target_tech); if ($roll > $self_tech) { // Reset Planet Assets. $sql = "UPDATE {$db->prefix}planets "; $sql .= "SET organics = '0', ore = '0', goods = '0', energy = '0', colonists = '2', credits = '0', fighters = '0', torps = '0', team = '0', base = 'N', sells = 'N', prod_organics = '20', prod_ore = '20', prod_goods = '20', prod_energy = '20', prod_fighters = '10', prod_torp = '10' "; $sql .= "WHERE planet_id = ? LIMIT 1;"; $resx = $db->Execute($sql, array($planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); echo "<div style='text-align:center; font-size:18px; color:#f00;'>The planet become unstable due to not being looked after, and all life and assets have been destroyed.</div>\n"; } if ($tkireg->min_value_capture != 0) { $playerscore = \Tki\Score::updateScore($pdo_db, $playerinfo['ship_id'], $tkireg, $playerinfo); $playerscore *= $playerscore; $planetscore = $planetinfo['organics'] * $tkireg->organics_price + $planetinfo['ore'] * $tkireg->ore_price + $planetinfo['goods'] * $tkireg->goods_price + $planetinfo['energy'] * $tkireg->energy_price + $planetinfo['fighters'] * $tkireg->fighter_price + $planetinfo['torps'] * $tkireg->torpedo_price + $planetinfo['colonists'] * $tkireg->colonist_price + $planetinfo['credits']; $planetscore = $planetscore * $tkireg->min_value_capture / 100; if ($playerscore < $planetscore) { echo "<center>" . $langvars['l_cmb_citizenswanttodie'] . "</center><br><br>"; $resx = $db->Execute("DELETE FROM {$db->prefix}planets WHERE planet_id = ?;", array($planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $resx, __LINE__, __FILE__); \Tki\PlayerLog::WriteLog($pdo_db, $ownerinfo['ship_id'], LOG_PLANET_DEFEATED_D, "{$planetinfo['name']}|{$playerinfo['sector']}|{$playerinfo['character_name']}"); \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETDEL, "{$playerinfo['character_name']}|{$ownerinfo['character_name']}|{$playerinfo['sector']}"); \Tki\Score::updateScore($pdo_db, $ownerinfo['ship_id'], $tkireg, $playerinfo); } else { $langvars['l_cmb_youmaycapture'] = str_replace("[capture]", "<a href='planet.php?planet_id=" . $planetinfo['planet_id'] . "&command=capture'>" . $langvars['l_planet_capture1'] . "</a>", $langvars['l_cmb_youmaycapture']); echo "<center><font color=red>" . $langvars['l_cmb_youmaycapture'] . "</font></center><br><br>"; \Tki\PlayerLog::WriteLog($pdo_db, $ownerinfo['ship_id'], LOG_PLANET_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|{$playerinfo['character_name']}"); \Tki\Score::updateScore($pdo_db, $ownerinfo['ship_id'], $tkireg, $playerinfo); $update7a = $db->Execute("UPDATE {$db->prefix}planets SET owner=0, fighters=0, torps=torps-?, base='N', defeated='Y' WHERE planet_id = ?;", array($planettorps, $planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $update7a, __LINE__, __FILE__); } } else { $langvars['l_cmb_youmaycapture'] = str_replace("[capture]", "<a href='planet.php?planet_id=" . $planetinfo['planet_id'] . "&command=capture'>" . $langvars['l_planet_capture1'] . "</a>", $langvars['l_cmb_youmaycapture']); echo "<center>" . $langvars['l_cmb_youmaycapture'] . "</center><br><br>"; \Tki\PlayerLog::WriteLog($pdo_db, $ownerinfo['ship_id'], LOG_PLANET_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|{$playerinfo['character_name']}"); \Tki\Score::updateScore($pdo_db, $ownerinfo['ship_id'], $tkireg, $playerinfo); $update7a = $db->Execute("UPDATE {$db->prefix}planets SET owner=0,fighters=0, torps=torps-?, base='N', defeated='Y' WHERE planet_id = ?;", array($planettorps, $planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $update7a, __LINE__, __FILE__); } \Tki\Ownership::calc($pdo_db, $planetinfo['sector_id'], $tkireg->min_bases_to_own, $langvars); } else { echo "<br><br><center><font color='#6098F8'><strong>" . $langvars['l_cmb_planetnotdefeated'] . "</strong></font></center><br><br>"; $fighters_lost = $planetinfo['fighters'] - $planetfighters; $langvars['l_cmb_fighterloststat'] = str_replace("[cmb_fighters_lost]", $fighters_lost, $langvars['l_cmb_fighterloststat']); $langvars['l_cmb_fighterloststat'] = str_replace("[cmb_planetinfo_fighters]", $planetinfo['fighters'], $langvars['l_cmb_fighterloststat']); $langvars['l_cmb_fighterloststat'] = str_replace("[cmb_planetfighters]", $planetfighters, $langvars['l_cmb_fighterloststat']); $energy = $planetinfo['energy']; \Tki\PlayerLog::WriteLog($pdo_db, $ownerinfo['ship_id'], LOG_PLANET_NOT_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|{$playerinfo['character_name']}|{$free_ore}|{$free_organics}|{$free_goods}|{$ship_salvage_rate}|{$ship_salvage}"); \Tki\Score::updateScore($pdo_db, $ownerinfo['ship_id'], $tkireg, $playerinfo); $update7b = $db->Execute("UPDATE {$db->prefix}planets SET energy = ?, fighters = fighters - ?, torps = torps - ?, ore = ore + ?, goods = goods + ?, organics = organics + ?, credits = credits + ? WHERE planet_id = ?;", array($energy, $fighters_lost, $planettorps, $free_ore, $free_goods, $free_organics, $ship_salvage, $planetinfo['planet_id'])); \Tki\Db::LogDbErrors($pdo_db, $update7b, __LINE__, __FILE__); } $update = $db->Execute("UPDATE {$db->prefix}ships SET turns = turns - 1, turns_used = turns_used + 1 WHERE ship_id = ?", array($playerinfo['ship_id'])); \Tki\Db::LogDbErrors($pdo_db, $update, __LINE__, __FILE__); }
public static function logDbErrors(\PDO $pdo_db, $query, int $served_line, string $served_page) { $request = Request::createFromGlobals(); // Convert the content of SCRIPT_NAME (in case it has been tainted) to the correct html entities $safe_script_name = htmlentities($request->server->get('SCRIPT_NAME'), ENT_HTML5, 'UTF-8'); $db_log = false; $error = null; $db_error = null; if ($pdo_db instanceof \PDO) { $error = $pdo_db->errorInfo()[1]; $db_error = $pdo_db->errorInfo()[2]; $db_log = true; // We need to create a method for disabling db logging on PDO } if ($error === null || $error == '') { return (bool) true; } else { if ($served_line > 0) { $served_line--; // Unless it is line 1 of the file, it is generally one lower than where it is reported. } $text_error = 'A Database error occurred in ' . $served_page . ' on line ' . $served_line . ' (called from: ' . $safe_script_name . ' the error message was: ' . $db_error . ' and the query was ' . $query; if (self::isActive($pdo_db)) { if ($db_log) { AdminLog::writeLog($pdo_db, LOG_RAW, $text_error); } } return (string) $db_error; } }
public static function traderouteCreate(\ADODB_mysqli $db, \PDO $pdo_db, string $lang, Reg $tkireg, Smarty $template, array $playerinfo, $num_traderoutes, $ptype1, $ptype2, $port_id1, $port_id2, int $planet_id1, int $planet_id2, $team_planet_id1, $team_planet_id2, $move_type, $circuit_type, $editing) { $langvars = \Tki\Translate::load($pdo_db, $lang, array('traderoutes', 'common', 'global_includes', 'global_funcs', 'footer', 'regional')); $src_id = null; $dest_id = null; $src_type = null; $dest_type = null; if ($num_traderoutes >= $tkireg->max_traderoutes_player && empty($editing)) { // Dont let them exceed max traderoutes \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_maxtdr'], $template); } // Database sanity check for source if ($ptype1 == 'port') { // Check for valid Source Port if ($port_id1 >= $tkireg->max_sectors) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invalidspoint'], $template); } $query = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id = ?;", array($port_id1)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); if (!$query || $query->EOF) { $langvars['l_tdr_errnotvalidport'] = str_replace("[tdr_port_id]", $port_id1, $langvars['l_tdr_errnotvalidport']); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnotvalidport'], $template); } // OK we definitely have a port here $source = $query->fields; if ($source['port_type'] == 'none') { $langvars['l_tdr_errnoport'] = str_replace("[tdr_port_id]", $port_id1, $langvars['l_tdr_errnoport']); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnoport'], $template); } } else { $query = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id = ?;", array($planet_id1)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); $source = $query->fields; if (!$query || $query->EOF) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnosrc'], $template); } // Check for valid Source Planet if ($source['sector_id'] >= $tkireg->max_sectors) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invalidsrc'], $template); } if ($source['owner'] != $playerinfo['ship_id']) { if (($playerinfo['team'] == 0 || $playerinfo['team'] != $source['team']) && $source['sells'] == 'N') { // $langvars['l_tdr_errnotownnotsell'] = str_replace("[tdr_source_name]", $source[name], $langvars['l_tdr_errnotownnotsell']); // $langvars['l_tdr_errnotownnotsell'] = str_replace("[tdr_source_sector_id]", $source[sector_id], $langvars['l_tdr_errnotownnotsell']); // \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnotownnotsell'], $template); // Check for valid Owned Source Planet \Tki\AdminLog::writeLog($pdo_db, 902, "{$playerinfo['ship_id']}|Tried to find someones planet: {$planet_id1} as source."); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invalidsrc'], $template); } } } // OK we have $source, *probably* now lets see if we have ever been there // Attempting to fix the map the universe via traderoute bug $pl1query = $db->Execute("SELECT * FROM {$db->prefix}movement_log WHERE sector_id = ? AND ship_id = ?;", array($source['sector_id'], $playerinfo['ship_id'])); \Tki\Db::LogDbErrors($pdo_db, $pl1query, __LINE__, __FILE__); $num_res1 = $pl1query->numRows(); if ($num_res1 == 0) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, "You cannot create a traderoute from a sector you have not visited!", $template); } // Note: shouldnt we, more realistically, require a ship to be *IN* the source sector to create the traderoute? // Database sanity check for dest if ($ptype2 == 'port') { // Check for valid Dest Port if ($port_id2 >= $tkireg->max_sectors) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invaliddport'], $template); } $query = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id = ?;", array($port_id2)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); if (!$query || $query->EOF) { $langvars['l_tdr_errnotvaliddestport'] = str_replace("[tdr_port_id]", $port_id2, $langvars['l_tdr_errnotvaliddestport']); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnotvaliddestport'], $template); } $destination = $query->fields; if ($destination['port_type'] == 'none') { $langvars['l_tdr_errnoport2'] = str_replace("[tdr_port_id]", $port_id2, $langvars['l_tdr_errnoport2']); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnoport2'], $template); } } else { $query = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id = ?;", array($planet_id2)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); $destination = $query->fields; if (!$query || $query->EOF) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnodestplanet'], $template); } // Check for valid Dest Planet if ($destination['sector_id'] >= $tkireg->max_sectors) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invaliddplanet'], $template); } if ($destination['owner'] != $playerinfo['ship_id'] && $destination['sells'] == 'N') { // $langvars['l_tdr_errnotownnotsell2'] = str_replace("[tdr_dest_name]", $destination['name'], $langvars['l_tdr_errnotownnotsell2']); // $langvars['l_tdr_errnotownnotsell2'] = str_replace("[tdr_dest_sector_id]", $destination['sector_id'], $langvars['l_tdr_errnotownnotsell2']); // \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_errnotownnotsell2'], $template); // Check for valid Owned Source Planet \Tki\AdminLog::writeLog($pdo_db, 902, "{$playerinfo['ship_id']}|Tried to find someones planet: {$planet_id2} as dest."); \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, $langvars['l_tdr_invaliddplanet'], $template); } } // OK now we have $destination lets see if we've been there. $pl2query = $db->Execute("SELECT * FROM {$db->prefix}movement_log WHERE sector_id = ? AND ship_id = ?;", array($destination['sector_id'], $playerinfo['ship_id'])); \Tki\Db::LogDbErrors($pdo_db, $pl2query, __LINE__, __FILE__); $num_res2 = $pl2query->numRows(); if ($num_res2 == 0) { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, "You cannot create a traderoute into a sector you have not visited!", $template); } // Check destination - we cannot trade INTO a special port if (array_key_exists('port_type', $destination) === true && $destination['port_type'] == 'special') { \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, "You cannot create a traderoute into a special port!", $template); } // Check traderoute for src => dest \Tki\Traderoute2::traderouteCheckCompatible($db, $pdo_db, $lang, $ptype1, $ptype2, $move_type, $circuit_type, $source, $destination, $playerinfo, $tkireg, $template); if ($ptype1 == 'port') { $src_id = $port_id1; } elseif ($ptype1 == 'planet') { $src_id = $planet_id1; } elseif ($ptype1 == 'team_planet') { $src_id = $team_planet_id1; } if ($ptype2 == 'port') { $dest_id = $port_id2; } elseif ($ptype2 == 'planet') { $dest_id = $planet_id2; } elseif ($ptype2 == 'team_planet') { $dest_id = $team_planet_id2; } if ($ptype1 == 'port') { $src_type = 'P'; } elseif ($ptype1 == 'planet') { $src_type = 'L'; } elseif ($ptype1 == 'team_planet') { $src_type = 'C'; } if ($ptype2 == 'port') { $dest_type = 'P'; } elseif ($ptype2 == 'planet') { $dest_type = 'L'; } elseif ($ptype2 == 'team_planet') { $dest_type = 'C'; } if ($move_type == 'realspace') { $mtype = 'R'; } else { $mtype = 'W'; } if (empty($editing)) { $query = $db->Execute("INSERT INTO {$db->prefix}traderoutes VALUES(NULL, ?, ?, ?, ?, ?, ?, ?);", array($src_id, $dest_id, $src_type, $dest_type, $mtype, $playerinfo['ship_id'], $circuit_type)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); echo "<p>" . $langvars['l_tdr_newtdrcreated']; } else { $query = $db->Execute("UPDATE {$db->prefix}traderoutes SET source_id = ?, dest_id = ?, source_type = ?, dest_type = ?, move_type = ?, owner = ?, circuit = ? WHERE traderoute_id = ?;", array($src_id, $dest_id, $src_type, $dest_type, $mtype, $playerinfo['ship_id'], $circuit_type, $editing)); \Tki\Db::LogDbErrors($pdo_db, $query, __LINE__, __FILE__); echo "<p>" . $langvars['l_tdr_modified']; } $langvars['l_tdr_returnmenu'] = str_replace("[here]", "<a href='traderoute.php'>" . $langvars['l_here'] . "</a>", $langvars['l_tdr_returnmenu']); echo " " . $langvars['l_tdr_returnmenu']; \Tki\Traderoute2::traderouteDie($pdo_db, $lang, $tkireg, null, $template); }