diff --git a/admin/Default/account_edit_processing.php b/admin/Default/account_edit_processing.php index 0b0e75133..37c6619ef 100644 --- a/admin/Default/account_edit_processing.php +++ b/admin/Default/account_edit_processing.php @@ -139,16 +139,18 @@ if (!empty($delete)) { foreach ($delete as $game_id => $value) { if ($value == 'TRUE') { + $deletePlayer = SmrPlayer::getPlayerByAccountID($account_id, $game_id); + $playerID = $deletePlayer->getPlayerID(); + $sql = $deletePlayer->getSQL(); + // Check for bank transactions into the alliance account - $db->query('SELECT * FROM alliance_bank_transactions WHERE payee_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id) . ' LIMIT 1'); + $db->query('SELECT * FROM alliance_bank_transactions WHERE payee_player_id=' . $db->escapeNumber($playerID) . ' AND game_id=' . $db->escapeNumber($game_id) . ' LIMIT 1'); if ($db->getNumRows() != 0) { // Can't delete $actions[] = 'player has made alliance transaction'; continue; } - $sql = 'account_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id); - // Check anon accounts for transactions $db->query('SELECT * FROM anon_bank_transactions WHERE ' . $sql . ' LIMIT 1'); if ($db->getNumRows() != 0) { @@ -157,18 +159,17 @@ continue; } - $db->query('DELETE FROM alliance_thread - WHERE sender_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); + $db->query('DELETE FROM alliance_thread WHERE ' . $sql); $db->query('DELETE FROM bounty WHERE ' . $sql); $db->query('DELETE FROM galactic_post_applications WHERE ' . $sql); - $db->query('DELETE FROM galactic_post_article - WHERE writer_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); + $db->query('DELETE FROM galactic_post_article WHERE ' . $sql); $db->query('DELETE FROM galactic_post_writer WHERE ' . $sql); $db->query('DELETE FROM message WHERE ' . $sql); $db->query('DELETE FROM message_notify - WHERE (from_id=' . $db->escapeNumber($account_id) . ' OR to_id=' . $db->escapeNumber($account_id) . ') AND game_id=' . $db->escapeNumber($game_id)); - $db->query('UPDATE planet SET owner_id=0,planet_name=\'\',password=\'\',shields=0,drones=0,credits=0,bonds=0 - WHERE owner_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); + WHERE (from_player_id=' . $db->escapeNumber($playerID) . ' OR to_player_id=' . $db->escapeNumber($playerID) . ') AND game_id=' . $db->escapeNumber($game_id)); + $db->query('UPDATE planet SET owner_player_id=0,planet_name=\'\',password=\'\',shields=0,drones=0,credits=0,bonds=0 + WHERE ' . $sql); + $db->query('DELETE FROM player_attacks_planet WHERE ' . $sql); $db->query('DELETE FROM player_attacks_port WHERE ' . $sql); $db->query('DELETE FROM player_has_alliance_role WHERE ' . $sql); diff --git a/admin/Default/admin_message_send.php b/admin/Default/admin_message_send.php index 9dcffddb7..570eacbee 100644 --- a/admin/Default/admin_message_send.php +++ b/admin/Default/admin_message_send.php @@ -11,16 +11,16 @@ if ($gameID != 20000) { $game = SmrGame::getGame($gameID); - $gamePlayers = [['AccountID' => 0, 'Name' => 'All Players (' . $game->getName() . ')']]; - $db->query('SELECT account_id,player_id,player_name FROM player WHERE game_id = ' . $db->escapeNumber($gameID) . ' ORDER BY player_name'); + $gamePlayers = [['PlayerID' => 0, 'Name' => 'All Players (' . $game->getName() . ')']]; + $db->query('SELECT player_id,player_name FROM player WHERE game_id = ' . $db->escapeNumber($gameID) . ' ORDER BY player_name'); while ($db->nextRecord()) { $gamePlayers[] = [ - 'AccountID' => $db->getInt('account_id'), + 'PlayerID' => $db->getInt('player_id'), 'Name' => $db->getField('player_name') . ' (' . $db->getInt('player_id') . ')', ]; } $template->assign('GamePlayers', $gamePlayers); - $template->assign('SelectedAccountID', $var['account_id'] ?? 0); + $template->assign('SelectedPlayerID', $var['player_id'] ?? 0); } if (isset($var['preview'])) { $template->assign('Preview', $var['preview']); diff --git a/admin/Default/admin_message_send_processing.php b/admin/Default/admin_message_send_processing.php index 0da84cc14..a4f3a1b01 100644 --- a/admin/Default/admin_message_send_processing.php +++ b/admin/Default/admin_message_send_processing.php @@ -5,7 +5,7 @@ $expire = Request::getFloat('expire'); $game_id = $var['SendGameID']; if ($game_id != ALL_GAMES_ID) { - $account_id = Request::getInt('account_id'); + $playerID = Request::getInt('player_id'); } if (Request::get('action') == 'Preview message') { @@ -14,7 +14,7 @@ $container['preview'] = $message; $container['expire'] = $expire; if ($game_id != ALL_GAMES_ID) { - $container['account_id'] = $account_id; + $container['player_id'] = $playerID; } forward($container); } @@ -29,20 +29,20 @@ $receivers = []; if ($game_id != ALL_GAMES_ID) { - if ($account_id == 0) { + if ($playerID == 0) { // Send to all players in the requested game - $db->query('SELECT account_id FROM player WHERE game_id = ' . $db->escapeNumber($game_id)); + $db->query('SELECT player_id FROM player WHERE game_id = ' . $db->escapeNumber($game_id)); while ($db->nextRecord()) { - $receivers[] = [$game_id, $db->getInt('account_id')]; + $receivers[] = [$game_id, $db->getInt('player_id')]; } } else { - $receivers[] = [$game_id, $account_id]; + $receivers[] = [$game_id, $player_id]; } } else { //send to all players in games that haven't ended yet - $db->query('SELECT game_id,account_id FROM player JOIN game USING(game_id) WHERE end_time > ' . $db->escapeNumber(TIME)); + $db->query('SELECT game_id, player_id FROM player JOIN game USING(game_id) WHERE end_time > ' . $db->escapeNumber(TIME)); while ($db->nextRecord()) { - $receivers[] = [$db->getInt('game_id'), $db->getInt('account_id')]; + $receivers[] = [$db->getInt('game_id'), $db->getInt('player_id')]; } } // Send the messages diff --git a/admin/Default/anon_acc_view.php b/admin/Default/anon_acc_view.php index a2a21159a..2a41886e5 100644 --- a/admin/Default/anon_acc_view.php +++ b/admin/Default/anon_acc_view.php @@ -11,7 +11,7 @@ $db->query('SELECT * FROM anon_bank_transactions - JOIN player USING(account_id, game_id) + JOIN player USING(player_id, game_id) WHERE anon_id = '.$db->escapeNumber($anonID) . ' AND game_id = '.$db->escapeNumber($gameID) . ' ORDER BY transaction_id'); diff --git a/admin/Default/box_reply.php b/admin/Default/box_reply.php index 3f42cbaa6..1fbe5361a 100644 --- a/admin/Default/box_reply.php +++ b/admin/Default/box_reply.php @@ -6,11 +6,11 @@ $container = create_container('box_reply_processing.php'); transfer('game_id'); -transfer('sender_id'); +transfer('sender_account_id'); transfer('box_type_id'); $template->assign('BoxReplyFormHref', SmrSession::getNewHREF($container)); -$template->assign('Sender', SmrPlayer::getPlayer($var['sender_id'], $var['game_id'])); -$template->assign('SenderAccount', SmrAccount::getAccount($var['sender_id'])); +$template->assign('Sender', SmrPlayer::getPlayer($var['sender_account_id'], $var['game_id'])); +$template->assign('SenderAccount', SmrAccount::getAccount($var['sender_account_id'])); if (isset($var['Preview'])) { $template->assign('Preview', $var['Preview']); } diff --git a/admin/Default/box_reply_processing.php b/admin/Default/box_reply_processing.php index c49e7d24d..f8f7dc302 100644 --- a/admin/Default/box_reply_processing.php +++ b/admin/Default/box_reply_processing.php @@ -8,7 +8,7 @@ $container['BanPoints'] = $banPoints; $container['RewardCredits'] = $rewardCredits; transfer('game_id'); - transfer('sender_id'); + transfer('sender_account_id'); transfer('box_type_id'); $container['Preview'] = $message; forward($container); @@ -19,7 +19,7 @@ //do we have points? if ($banPoints > 0) { $suspicion = 'Inappropriate Actions'; - $senderAccount = SmrAccount::getAccount($var['sender_id']); + $senderAccount = SmrAccount::getAccount($var['sender_account_id']); $senderAccount->addPoints($banPoints, $account, BAN_REASON_BAD_BEHAVIOR, $suspicion); } diff --git a/admin/Default/box_view.php b/admin/Default/box_view.php index 3985dfdd9..f5a79f895 100644 --- a/admin/Default/box_view.php +++ b/admin/Default/box_view.php @@ -41,17 +41,17 @@ 'ID' => $messageID ); - $senderID = $db->getInt('sender_id'); - if ($senderID == 0) { + $senderAccountID = $db->getInt('sender_account_id'); + if ($senderAccountID == 0) { $senderName = 'User not logged in'; } else { - $senderAccount = SmrAccount::getAccount($senderID); - $senderName = $senderAccount->getLogin() . ' (' . $senderID . ')'; + $senderAccount = SmrAccount::getAccount($senderAccountID); + $senderName = $senderAccount->getLogin() . ' (' . $senderAccountID . ')'; if ($validGame) { - $senderPlayer = SmrPlayer::getPlayer($senderID, $gameID); + $senderPlayer = SmrPlayer::getPlayerByAccountID($senderAccountID, $gameID); $senderName .= ' a.k.a ' . $senderPlayer->getDisplayName(); $container = create_container('skeleton.php', 'box_reply.php'); - $container['sender_id'] = $senderID; + $container['sender_account_id'] = $senderAccountID; $container['game_id'] = $gameID; transfer('box_type_id'); $messages[$messageID]['ReplyHREF'] = SmrSession::getNewHREF($container); diff --git a/admin/Default/log_anonymous_account.php b/admin/Default/log_anonymous_account.php index c7ebc26aa..080db65fd 100644 --- a/admin/Default/log_anonymous_account.php +++ b/admin/Default/log_anonymous_account.php @@ -10,14 +10,14 @@ // get all anon bank transactions that are logged in an array $db->query('SELECT * FROM anon_bank_transactions - JOIN account USING(account_id) + JOIN player USING(player_id) WHERE account_id IN ('.$db->escapeArray($log_account_ids) . ') ORDER BY game_id DESC, anon_id ASC'); $anon_logs = []; while ($db->nextRecord()) { $transaction = strtolower($db->getField('transaction')); $anon_logs[$db->getInt('game_id')][$db->getInt('anon_id')][] = [ - 'login' => $db->getField('login'), + 'player_name' => $db->getField('player_name'), 'amount' => number_format($db->getInt('amount')), 'date' => date(DATE_FULL_SHORT, $db->getInt('time')), 'type' => $transaction, diff --git a/admin/Default/manage_draft_leaders.php b/admin/Default/manage_draft_leaders.php index 90f7ef99f..b9cb357a5 100644 --- a/admin/Default/manage_draft_leaders.php +++ b/admin/Default/manage_draft_leaders.php @@ -21,10 +21,10 @@ // Get the list of current draft leaders for the selected game $currentLeaders = array(); - $db->query('SELECT account_id, home_sector_id FROM draft_leaders WHERE game_id=' . $db->escapeNumber($selectedGameID)); + $db->query('SELECT player_id, home_sector_id FROM draft_leaders WHERE game_id=' . $db->escapeNumber($selectedGameID)); while ($db->nextRecord()) { $homeSectorID = $db->getInt('home_sector_id'); - $leader = SmrPlayer::getPlayer($db->getInt('account_id'), $selectedGameID); + $leader = SmrPlayer::getPlayer($db->getInt('player_id'), $selectedGameID); $currentLeaders[] = [ 'Name' => $leader->getDisplayName(), 'HomeSectorID' => $homeSectorID === 0 ? 'None' : $homeSectorID, diff --git a/admin/Default/manage_draft_leaders_processing.php b/admin/Default/manage_draft_leaders_processing.php index ec4a33aed..e1cd5cb34 100644 --- a/admin/Default/manage_draft_leaders_processing.php +++ b/admin/Default/manage_draft_leaders_processing.php @@ -7,12 +7,12 @@ SmrSession::updateVar('processing_msg', null); // Get the POST variables -$playerId = Request::getInt('player_id'); +$playerID = Request::getInt('player_id'); $homeSectorID = Request::getInt('home_sector_id'); $action = Request::get('submit'); try { - $selectedPlayer = SmrPlayer::getPlayerByPlayerID($playerId, $gameId); + $selectedPlayer = SmrPlayer::getPlayer($playerID, $gameId); } catch (PlayerNotFoundException $e) { $msg = "ERROR: " . $e->getMessage(); SmrSession::updateVar('processing_msg', $msg); @@ -20,14 +20,13 @@ } $name = $selectedPlayer->getDisplayName(); -$accountId = $selectedPlayer->getAccountID(); $game = $selectedPlayer->getGame()->getDisplayName(); if ($action == "Assign") { if ($selectedPlayer->isDraftLeader()) { $msg = "ERROR: $name is already a draft leader in game $game!"; } else { - $db->query('INSERT INTO draft_leaders (account_id, game_id, home_sector_id) VALUES (' . $db->escapeNumber($accountId) . ', ' . $db->escapeNumber($gameId) . ', ' . $db->escapeNumber($homeSectorID) . ')'); + $db->query('INSERT INTO draft_leaders (player_id, game_id, home_sector_id) VALUES (' . $db->escapeNumber($playerID) . ', ' . $db->escapeNumber($gameId) . ', ' . $db->escapeNumber($homeSectorID) . ')'); } } elseif ($action == "Remove") { if (!$selectedPlayer->isDraftLeader()) { diff --git a/admin/Default/manage_post_editors_processing.php b/admin/Default/manage_post_editors_processing.php index 07b19d221..b1b442493 100644 --- a/admin/Default/manage_post_editors_processing.php +++ b/admin/Default/manage_post_editors_processing.php @@ -11,7 +11,7 @@ $action = Request::get('submit'); try { - $selected_player = SmrPlayer::getPlayerByPlayerID($player_id, $game_id); + $selected_player = SmrPlayer::getPlayer($player_id, $game_id); } catch (PlayerNotFoundException $e) { $msg = "ERROR: " . $e->getMessage(); SmrSession::updateVar('processing_msg', $msg); @@ -19,14 +19,13 @@ } $name = $selected_player->getDisplayName(); -$account_id = $selected_player->getAccountID(); $game = $selected_player->getGame()->getDisplayName(); if ($action == "Assign") { if ($selected_player->isGPEditor()) { $msg = "ERROR: $name is already an editor in game $game!"; } else { - $db->query('INSERT INTO galactic_post_writer (account_id, game_id) VALUES (' . $db->escapeNumber($account_id) . ', ' . $db->escapeNumber($game_id) . ')'); + $db->query('INSERT INTO galactic_post_writer (player_id, game_id) VALUES (' . $db->escapeNumber($player_id) . ', ' . $db->escapeNumber($game_id) . ')'); } } elseif ($action == "Remove") { if (!$selected_player->isGPEditor()) { diff --git a/admin/Default/notify_reply.php b/admin/Default/notify_reply.php index ca9abbffa..a2444363a 100644 --- a/admin/Default/notify_reply.php +++ b/admin/Default/notify_reply.php @@ -5,11 +5,11 @@ $container = create_container('notify_reply_processing.php'); transfer('game_id'); -transfer('offended'); -transfer('offender'); +transfer('offended_player_id'); +transfer('offender_player_id'); $template->assign('NotifyReplyFormHref', SmrSession::getNewHREF($container)); -$offender = getMessagePlayer($var['offender'], $var['game_id']); -$offended = getMessagePlayer($var['offended'], $var['game_id']); +$offender = getMessagePlayer($var['offender_player_id'], $var['game_id']); +$offended = getMessagePlayer($var['offended_player_id'], $var['game_id']); if (is_object($offender)) { $template->assign('OffenderAccount', $offender->getAccount()); } diff --git a/admin/Default/notify_reply_processing.php b/admin/Default/notify_reply_processing.php index 6b3cfb1f0..6935bba43 100644 --- a/admin/Default/notify_reply_processing.php +++ b/admin/Default/notify_reply_processing.php @@ -5,10 +5,9 @@ $offendedBanPoints = Request::getInt('offendedBanPoints'); if (Request::get('action') == 'Preview messages') { $container = create_container('skeleton.php', 'notify_reply.php'); - transfer('offender'); - transfer('offended'); + transfer('offender_player_id'); + transfer('offended_player_id'); transfer('game_id'); - transfer('sender_id'); $container['PreviewOffender'] = $offenderReply; $container['OffenderBanPoints'] = $offenderBanPoints; $container['PreviewOffended'] = $offendedReply; @@ -18,24 +17,24 @@ if ($offenderReply != '') { - SmrPlayer::sendMessageFromAdmin($var['game_id'], $var['offender'], $offenderReply); + SmrPlayer::sendMessageFromAdmin($var['game_id'], $var['offender_player_id'], $offenderReply); //do we have points? if ($offenderBanPoints > 0) { $suspicion = 'Inappropriate In-Game Message'; - $offenderAccount = SmrAccount::getAccount($var['offender']); + $offenderAccount = SmrPlayer::getPlayer($var['offender_player_id'], $var['game_id'])->getAccount(); $offenderAccount->addPoints($offenderBanPoints, $account, BAN_REASON_BAD_BEHAVIOR, $suspicion); } } if ($offendedReply != '') { //next message - SmrPlayer::sendMessageFromAdmin($var['game_id'], $var['offended'], $offendedReply); + SmrPlayer::sendMessageFromAdmin($var['game_id'], $var['offended_player_id'], $offendedReply); //do we have points? if ($offendedBanPoints > 0) { $suspicion = 'Inappropriate In-Game Message'; - $offenderAccount = SmrAccount::getAccount($var['offended']); + $offenderAccount = SmrPlayer::getPlayer($var['offended_player_id'], $var['game_id'])->getAccount(); $offenderAccount->addPoints($offendedBanPoints, $account, BAN_REASON_BAD_BEHAVIOR, $suspicion); } } diff --git a/admin/Default/notify_view.php b/admin/Default/notify_view.php index a685a654f..e67bc78e3 100644 --- a/admin/Default/notify_view.php +++ b/admin/Default/notify_view.php @@ -10,12 +10,12 @@ $messages = []; while ($db->nextRecord()) { $gameID = $db->getInt('game_id'); - $sender = getMessagePlayer($db->getInt('from_id'), $gameID); - $receiver = getMessagePlayer($db->getInt('to_id'), $gameID); + $sender = getMessagePlayer($db->getInt('from_player_id'), $gameID); + $receiver = getMessagePlayer($db->getInt('to_player_id'), $gameID); $container = create_container('skeleton.php', 'notify_reply.php'); - $container['offender'] = $db->getInt('from_id'); - $container['offended'] = $db->getInt('to_id'); + $container['offender_player_id'] = $db->getInt('from_player_id'); + $container['offended_player_'] = $db->getInt('to_player_id'); $container['game_id'] = $gameID; $offender = $sender; diff --git a/admin/Default/npc_manage.php b/admin/Default/npc_manage.php index fdd123bab..7904e9421 100644 --- a/admin/Default/npc_manage.php +++ b/admin/Default/npc_manage.php @@ -53,8 +53,9 @@ // Get the existing NPC players for the selected game $db->query('SELECT * FROM player WHERE game_id=' . $db->escapeNumber($selectedGameID) . ' AND npc=' . $db->escapeBoolean(true)); while ($db->nextRecord()) { + $playerID = $db->getInt('player_id'); $accountID = $db->getInt('account_id'); - $npcs[$accountID]['player'] = SmrPlayer::getPlayer($accountID, $selectedGameID, false, $db); + $npcs[$accountID]['player'] = SmrPlayer::getPlayer($playerID, $selectedGameID, false, $db); } $template->assign('Npcs', $npcs); diff --git a/admin/Default/npc_manage_processing.php b/admin/Default/npc_manage_processing.php index 90ec93b8a..120e7f979 100644 --- a/admin/Default/npc_manage_processing.php +++ b/admin/Default/npc_manage_processing.php @@ -26,7 +26,7 @@ $alliance = SmrAlliance::getAllianceByName($allianceName, $gameID); if (is_null($alliance)) { $alliance = SmrAlliance::createAlliance($gameID, $allianceName); - $alliance->setLeaderID($npcPlayer->getAccountID()); + $alliance->setLeaderPlayerID($npcPlayer->getPlayerID()); $alliance->update(); $alliance->createDefaultRoles(); } diff --git a/admin/Default/ship_check.php b/admin/Default/ship_check.php index cc9dfda26..5d8bec41f 100644 --- a/admin/Default/ship_check.php +++ b/admin/Default/ship_check.php @@ -2,18 +2,12 @@ $template->assign('PageTopic', 'Ship Integrity Check'); -$db->query('SELECT * FROM ship_type_support_hardware, player, ship_has_hardware, hardware_type ' . - 'WHERE ship_type_support_hardware.ship_type_id = player.ship_type_id AND ' . - 'player.account_id = ship_has_hardware.account_id AND ' . - 'player.game_id = ship_has_hardware.game_id AND ' . - 'ship_type_support_hardware.hardware_type_id = ship_has_hardware.hardware_type_id AND ' . - 'ship_has_hardware.hardware_type_id = hardware_type.hardware_type_id AND ' . - 'amount > max_amount'); +$db->query('SELECT * FROM ship_type_support_hardware JOIN hardware_type USING (hardware_type_id) JOIN ship_has_hardware USING (hardware_type_id) JOIN player USING (player_id, game_id, ship_type_id) WHERE amount > max_amount'); $excessHardware = []; while ($db->nextRecord()) { $container = create_container('ship_check_processing.php'); - $container['account_id'] = $db->getInt('account_id'); + $container['player_id'] = $db->getInt('player_id'); $container['hardware'] = $db->getInt('hardware_type_id'); $container['game_id'] = $db->getInt('game_id'); $container['max_amount'] = $db->getInt('max_amount'); diff --git a/admin/Default/ship_check_processing.php b/admin/Default/ship_check_processing.php index a1b60a852..54cb5d8fe 100644 --- a/admin/Default/ship_check_processing.php +++ b/admin/Default/ship_check_processing.php @@ -4,13 +4,13 @@ $game_id = $var['game_id']; $hardware_id = $var['hardware']; $max_amount = $var['max_amount']; -$account_id = $var['account_id']; +$player_id = $var['player_id']; //update it so they arent cheating $db->query('UPDATE ship_has_hardware ' . 'SET amount = ' . $db->escapeNumber($max_amount) . ' ' . 'WHERE game_id = ' . $db->escapeNumber($game_id) . ' AND ' . - 'account_id = ' . $db->escapeNumber($account_id) . ' AND ' . + 'player_id = ' . $db->escapeNumber($player_id) . ' AND ' . 'hardware_type_id = ' . $db->escapeNumber($hardware_id)); //now erdirect back to page diff --git a/db/patches/V1_6_66_01__player_index.sql b/db/patches/V1_6_66_01__player_index.sql new file mode 100644 index 000000000..751ae11e2 --- /dev/null +++ b/db/patches/V1_6_66_01__player_index.sql @@ -0,0 +1,19 @@ +-- Make player_id the index of player-related tables, not index_id +ALTER TABLE player_attacks_planet RENAME COLUMN account_id TO player_id; +UPDATE player_attacks_planet SET player_id = (SELECT player_id FROM account JOIN player USING (account_id) WHERE game_id = player_attacks_planet.game_id AND account_id = player_attacks_planet.player_id); + +ALTER TABLE player_attacks_port RENAME COLUMN account_id TO player_id; +UPDATE player_attacks_port SET player_id = (SELECT player_id FROM account JOIN player USING (account_id) WHERE game_id = player_attacks_port.game_id AND account_id = player_attacks_port.player_id); + +ALTER TABLE player_can_fed RENAME COLUMN account_id TO player_id; +UPDATE player_can_fed SET player_id = (SELECT player_id FROM account JOIN player USING (account_id) WHERE game_id = player_can_fed.game_id AND account_id = player_can_fed.player_id); + +ALTER TABLE player_has_alliance_role RENAME COLUMN account_id TO player_id; +UPDATE player_has_alliance_role SET player_id = (SELECT player_id FROM account JOIN player USING (account_id) WHERE game_id = player_has_alliance_role.game_id AND account_id = player_has_alliance_role.player_id); + +alliance_thread sender_id -> player_id +galactic_post_article writer_id -> player_id +planet owner_id -> player_id +sector_has_forces owner_id -> player_id +alliance_bank_transactions payee_id -> player_id +anon_bank owner_id -> player_id diff --git a/engine/Default/alliance_create_processing.php b/engine/Default/alliance_create_processing.php index 996d01dfe..ccd996b8c 100644 --- a/engine/Default/alliance_create_processing.php +++ b/engine/Default/alliance_create_processing.php @@ -35,7 +35,7 @@ $alliance = SmrAlliance::createAlliance($player->getGameID(), $name); $alliance->setRecruitType($recruitType, $password); $alliance->setAllianceDescription($description); -$alliance->setLeaderID($player->getAccountID()); +$alliance->setLeaderPlayerID($player->getPlayerID()); $alliance->createDefaultRoles($perms); $alliance->update(); diff --git a/engine/Default/alliance_forces.php b/engine/Default/alliance_forces.php index dc846f4d4..63b1a6539 100644 --- a/engine/Default/alliance_forces.php +++ b/engine/Default/alliance_forces.php @@ -12,9 +12,9 @@ sum(mines) as tot_mines, sum(combat_drones) as tot_cds, sum(scout_drones) as tot_sds -FROM sector_has_forces JOIN player ON player.game_id=sector_has_forces.game_id AND sector_has_forces.owner_id=player.account_id -WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . ' -AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' +FROM sector_has_forces JOIN player USING (game_id, player_id) +WHERE game_id=' . $db->escapeNumber($alliance->getGameID()) . ' +AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' AND expire_time >= ' . $db->escapeNumber(TIME)); $hardwareTypes = Globals::getHardwareTypes(); @@ -37,14 +37,14 @@ $db->query(' SELECT sector_has_forces.* FROM player -JOIN sector_has_forces ON player.game_id = sector_has_forces.game_id AND player.account_id = sector_has_forces.owner_id -WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . ' -AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' +JOIN sector_has_forces USING (game_id, player_id) +WHERE game_id=' . $db->escapeNumber($alliance->getGameID()) . ' +AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' AND expire_time >= ' . $db->escapeNumber(TIME) . ' ORDER BY sector_id ASC'); $forces = array(); while ($db->nextRecord()) { - $forces[] = SmrForce::getForce($player->getGameID(), $db->getInt('sector_id'), $db->getInt('owner_id'), false, $db); + $forces[] = SmrForce::getForce($player->getGameID(), $db->getInt('sector_id'), $db->getInt('player_id'), false, $db); } $template->assign('Forces', $forces); diff --git a/engine/Default/alliance_invite_accept_processing.php b/engine/Default/alliance_invite_accept_processing.php index 5674f4cde..53066fd8f 100644 --- a/engine/Default/alliance_invite_accept_processing.php +++ b/engine/Default/alliance_invite_accept_processing.php @@ -2,7 +2,7 @@ // Check that the invitation is registered in the database try { - $invite = SmrInvitation::get($var['alliance_id'], $player->getGameID(), $player->getAccountID()); + $invite = SmrInvitation::get($var['alliance_id'], $player->getGameID(), $player->getPlayerID()); } catch (InvitationNotFoundException $e) { create_error('Your invitation to join this alliance has expired or been canceled!'); } diff --git a/engine/Default/alliance_invite_player.php b/engine/Default/alliance_invite_player.php index 907cf6588..240ebc9e2 100644 --- a/engine/Default/alliance_invite_player.php +++ b/engine/Default/alliance_invite_player.php @@ -13,7 +13,7 @@ $container['invite'] = $invite; $invited = $invite->getReceiver(); - $pendingInvites[$invited->getAccountID()] = array( + $pendingInvites[$invited->getPlayerID()] = array( 'invited' => $invited->getDisplayName(true), 'invited_by' => $invite->getSender()->getDisplayName(), 'expires' => format_time($invite->getExpires() - TIME, true), @@ -26,14 +26,14 @@ // List those who joined the game most recently first. $invitePlayers = array(); if ($alliance->getNumMembers() < $game->getAllianceMaxPlayers()) { - $db->query('SELECT account_id FROM player + $db->query('SELECT * FROM player WHERE game_id = '.$db->escapeNumber($player->getGameID()) . ' AND alliance_id != '.$db->escapeNumber($alliance->getAllianceID()) . ' AND npc = '.$db->escapeBoolean(false) . ' ORDER BY player_id DESC'); while ($db->nextRecord()) { - $invitePlayer = SmrPlayer::getPlayer($db->getInt('account_id'), $player->getGameID()); - if (array_key_exists($invitePlayer->getAccountID(), $pendingInvites)) { + $invitePlayer = SmrPlayer::getPlayer($db->getInt('player_id'), $player->getGameID(), false, $db); + if (array_key_exists($invitePlayer->getPlayerID(), $pendingInvites)) { // Don't display players we've already invited continue; } diff --git a/engine/Default/alliance_invite_player_processing.php b/engine/Default/alliance_invite_player_processing.php index 09e9d9528..13545365a 100644 --- a/engine/Default/alliance_invite_player_processing.php +++ b/engine/Default/alliance_invite_player_processing.php @@ -1,6 +1,6 @@ query('SELECT 1 FROM message_blacklist - WHERE account_id='.$db->escapeNumber($receiverID) . ' - AND blacklisted_id='.$db->escapeNumber($player->getAccountID())); + WHERE player_id='.$db->escapeNumber($receiverPlayerID) . ' + AND blacklisted_player_id='.$db->escapeNumber($player->getPlayerID())); if ($db->nextRecord() || $account->isMailBanned()) { $addMessage = ''; } @@ -25,7 +25,7 @@ $msg .= '
' . $addMessage; } -$player->sendAllianceInvitation($receiverID, $msg, $expires); +$player->sendAllianceInvitation($receiverPlayerID, $msg, $expires); $container = create_container('skeleton.php', 'alliance_invite_player.php'); forward($container); diff --git a/engine/Default/alliance_leadership_processing.php b/engine/Default/alliance_leadership_processing.php index 3d20e1c78..3b09f0128 100644 --- a/engine/Default/alliance_leadership_processing.php +++ b/engine/Default/alliance_leadership_processing.php @@ -1,15 +1,15 @@ getAlliance(); -$alliance->setLeaderID($leader_id); +$alliance->setLeaderPlayerID($leaderPlayerID); $alliance->update(); $db->query('UPDATE player_has_alliance_role SET role_id = ' . $db->escapeNumber(ALLIANCE_ROLE_NEW_MEMBER) . ' WHERE ' . $player->getSQL() . ' AND alliance_id=' . $db->escapeNumber($player->getAllianceID())); -$db->query('UPDATE player_has_alliance_role SET role_id = ' . $db->escapeNumber(ALLIANCE_ROLE_LEADER) . ' WHERE account_id = ' . $db->escapeNumber($leader_id) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND alliance_id=' . $db->escapeNumber($player->getAllianceID())); +$db->query('UPDATE player_has_alliance_role SET role_id = ' . $db->escapeNumber(ALLIANCE_ROLE_LEADER) . ' WHERE player_id = ' . $db->escapeNumber($leaderPlayerID) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND alliance_id=' . $db->escapeNumber($player->getAllianceID())); // Notify the new leader $playerMessage = 'You are now the leader of ' . $alliance->getAllianceBBLink() . '!'; -$player->sendMessageFromAllianceCommand($leader_id, $playerMessage); +$player->sendMessageFromAllianceCommand($leaderPlayerID, $playerMessage); forward(create_container('skeleton.php', 'alliance_roster.php')); diff --git a/engine/Default/alliance_list.php b/engine/Default/alliance_list.php index 0745f7f41..85465b94c 100644 --- a/engine/Default/alliance_list.php +++ b/engine/Default/alliance_list.php @@ -12,14 +12,14 @@ // get list of alliances $db->query('SELECT -count(account_id) as alliance_member_count, +count(*) as alliance_member_count, sum(experience) as alliance_xp, floor(avg(experience)) as alliance_avg, alliance_name, alliance_id FROM player JOIN alliance USING (game_id, alliance_id) -WHERE leader_id > 0 +WHERE leader_player_id > 0 AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' GROUP BY alliance_id ORDER BY alliance_name ASC' diff --git a/engine/Default/alliance_message.php b/engine/Default/alliance_message.php index 3d79c821c..9cdaa601b 100644 --- a/engine/Default/alliance_message.php +++ b/engine/Default/alliance_message.php @@ -23,7 +23,7 @@ $query = 'SELECT alliance_only, topic, thread_id, max(time) as sendtime, - min(sender_id) as sender_id, + min(sender_player_id) as sender_player_id, count(reply_id) as num_replies FROM alliance_thread_topic JOIN alliance_thread USING(game_id,alliance_id,thread_id) @@ -62,16 +62,16 @@ $threads[$i]['Unread'] = $db2->getNumRows() == 0; // Determine the thread author display name - $sender_id = $db->getInt('sender_id'); - if ($sender_id == ACCOUNT_ID_PLANET) { + $senderPlayerID = $db->getInt('sender_player_id'); + if ($senderPlayer == PLAYER_ID_PLANET) { $playerName = 'Planet Reporter'; - } elseif ($sender_id == ACCOUNT_ID_BANK_REPORTER) { + } elseif ($senderPlayerID == PLAYER_ID_BANK_REPORTER) { $playerName = 'Bank Reporter'; - } elseif ($sender_id == ACCOUNT_ID_ADMIN) { + } elseif ($senderPlayerID == PLAYER_ID_ADMIN) { $playerName = 'Game Admins'; } else { try { - $author = SmrPlayer::getPlayer($sender_id, $player->getGameID()); + $author = SmrPlayer::getPlayer($senderPlayerID, $player->getGameID()); $playerName = $author->getLinkedDisplayName(false); } catch (PlayerNotFoundException $e) { $playerName = 'Unknown'; // default @@ -81,7 +81,7 @@ $db2->query('SELECT * FROM player_has_alliance_role JOIN alliance_has_roles USING(game_id,alliance_id,role_id) WHERE ' . $player->getSQL() . ' AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' LIMIT 1'); $db2->nextRecord(); - $threads[$i]['CanDelete'] = $player->getAccountID() == $sender_id || $db2->getBoolean('mb_messages'); + $threads[$i]['CanDelete'] = $player->getPlayerID() == $senderPlayerID || $db2->getBoolean('mb_messages'); if ($threads[$i]['CanDelete']) { $container['thread_id'] = $threadID; $threads[$i]['DeleteHref'] = SmrSession::getNewHREF($container); diff --git a/engine/Default/alliance_message_add_processing.php b/engine/Default/alliance_message_add_processing.php index dc6a7bdaf..2d92093be 100644 --- a/engine/Default/alliance_message_add_processing.php +++ b/engine/Default/alliance_message_add_processing.php @@ -78,11 +78,11 @@ } // and the body -$db->query('INSERT INTO alliance_thread (game_id, alliance_id, thread_id, reply_id, text, sender_id, time) - VALUES(' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($thread_id) . ', ' . $db->escapeNumber($reply_id) . ', ' . $db->escapeString($body) . ', ' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeNumber(TIME) . ')'); +$db->query('INSERT INTO alliance_thread (game_id, alliance_id, thread_id, reply_id, text, sender_player_id, time) + VALUES(' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($thread_id) . ', ' . $db->escapeNumber($reply_id) . ', ' . $db->escapeString($body) . ', ' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeNumber(TIME) . ')'); $db->query('REPLACE INTO player_read_thread - (account_id, game_id, alliance_id, thread_id, time) - VALUES(' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($thread_id) . ', ' . $db->escapeNumber(TIME + 2) . ')'); + (player_id, game_id, alliance_id, thread_id, time) + VALUES(' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($thread_id) . ', ' . $db->escapeNumber(TIME + 2) . ')'); $container = create_container('skeleton.php'); $container['alliance_id'] = $alliance_id; diff --git a/engine/Default/alliance_message_view.php b/engine/Default/alliance_message_view.php index 620c2e474..2c1963d30 100644 --- a/engine/Default/alliance_message_view.php +++ b/engine/Default/alliance_message_view.php @@ -42,22 +42,25 @@ $thread = array(); $thread['AllianceEyesOnly'] = is_array($var['alliance_eyes']) && $var['alliance_eyes'][$thread_index]; //for report type (system sent) messages -$players[ACCOUNT_ID_PLANET] = 'Planet Reporter'; -$players[ACCOUNT_ID_BANK_REPORTER] = 'Bank Reporter'; -$db->query('SELECT account_id +$players = [ + PLAYER_ID_PLANET => 'Planet Reporter', + PLAYER_ID_BANK_REPORTER => 'Bank Reporter', +]; +$db->query('SELECT * FROM player JOIN alliance_thread USING (game_id) WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND alliance_thread.alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND alliance_thread.thread_id = ' . $db->escapeNumber($thread_id)); while ($db->nextRecord()) { - $players[$db->getInt('account_id')] = SmrPlayer::getPlayer($db->getInt('account_id'), $player->getGameID())->getLinkedDisplayName(false); + $threadPlayer = SmrPlayer::getPlayer($db->getInt('player_id'), $player->getGameID(), false, $db); + $players[$db->getInt('player_id')] = $threadPlayer->getLinkedDisplayName(false); } $db->query('SELECT mb_messages FROM player_has_alliance_role JOIN alliance_has_roles USING(game_id,alliance_id,role_id) WHERE ' . $player->getSQL() . ' AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' LIMIT 1'); $db->requireRecord(); $thread['CanDelete'] = $db->getBoolean('mb_messages'); -$db->query('SELECT text, sender_id, time, reply_id +$db->query('SELECT text, sender_player_id, time, reply_id FROM alliance_thread WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . ' @@ -69,7 +72,7 @@ $container = create_container('alliance_message_delete_processing.php', '', $var); $container['thread_id'] = $thread_id; while ($db->nextRecord()) { - $thread['Replies'][$db->getInt('reply_id')] = array('Sender' => $players[$db->getInt('sender_id')], 'Message' => $db->getField('text'), 'SendTime' => $db->getInt('time')); + $thread['Replies'][$db->getInt('reply_id')] = array('Sender' => $players[$db->getInt('sender_player_id')], 'Message' => $db->getField('text'), 'SendTime' => $db->getInt('time')); if ($thread['CanDelete']) { $container['reply_id'] = $db->getInt('reply_id'); $thread['Replies'][$db->getInt('reply_id')]['DeleteHref'] = SmrSession::getNewHREF($container); diff --git a/engine/Default/alliance_mod.php b/engine/Default/alliance_mod.php index 95b83e3af..1265cc04e 100644 --- a/engine/Default/alliance_mod.php +++ b/engine/Default/alliance_mod.php @@ -9,7 +9,7 @@ Globals::canAccessPage('AllianceMOTD', $player, array('AllianceID' => $alliance->getAllianceID())); $template->assign('PageTopic', $alliance->getAllianceDisplayName(false, true)); -Menu::alliance($alliance->getAllianceID(), $alliance->getLeaderID()); +Menu::alliance($alliance->getAllianceID(), $alliance->getLeaderPlayerID()); // Check to see if an alliance op is scheduled // Display it for 1 hour past start time (late arrivals, etc.) diff --git a/engine/Default/alliance_op_response_processing.php b/engine/Default/alliance_op_response_processing.php index eaf13b753..332995a99 100644 --- a/engine/Default/alliance_op_response_processing.php +++ b/engine/Default/alliance_op_response_processing.php @@ -2,6 +2,6 @@ $response = strtoupper(Request::get('op_response')); -$db->query('REPLACE INTO alliance_has_op_response (alliance_id, game_id, account_id, response) VALUES (' . $db->escapeNumber($player->getAllianceID()) . ',' . $db->escapeNumber($player->getGameID()) . ',' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeString($response) . ')'); +$db->query('REPLACE INTO alliance_has_op_response (alliance_id, game_id, player_id, response) VALUES (' . $db->escapeNumber($player->getAllianceID()) . ',' . $db->escapeNumber($player->getGameID()) . ',' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeString($response) . ')'); forward(create_container('skeleton.php', 'alliance_mod.php')); diff --git a/engine/Default/alliance_remove_member.php b/engine/Default/alliance_remove_member.php index 7521bef81..fb722eec3 100644 --- a/engine/Default/alliance_remove_member.php +++ b/engine/Default/alliance_remove_member.php @@ -4,15 +4,10 @@ Menu::alliance($alliance->getAllianceID(), $alliance->getLeaderID()); $db->query(' -SELECT -account_id, -player_id, -player_name, -last_cpl_action -FROM player +SELECT * FROM player WHERE game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' -AND account_id != ' . $db->escapeNumber($player->getAccountID()) . ' +AND player_id != ' . $db->escapeNumber($player->getPlayerID()) . ' ORDER BY last_cpl_action DESC '); @@ -21,14 +16,17 @@ $members = []; while ($db->nextRecord()) { + $alliancePlayer = SmrPlayer::getPlayer($db->getInt('player_id'), $player->getGameID(), false, $db); + // get the amount of time since last_active - $diff = 864000 + max(-864000, $db->getInt('last_cpl_action') - TIME); - $lastActive = get_colored_text_range($diff, 864000, date(DATE_FULL_SHORT, $db->getInt('last_cpl_action'))); + $last_cpl_action = $alliancePlayer->getLastCPLAction(); + $diff = 864000 + max(-864000, $last_cpl_action - TIME); + $lastActive = get_colored_text_range($diff, 864000, date(DATE_FULL_SHORT, $last_cpl_action)); $members[] = [ 'last_active' => $lastActive, - 'display_name' => htmlentities($db->getField('player_name')) . ' (' . $db->getInt('player_id') . ')', - 'account_id' => $db->getInt('account_id'), + 'display_name' => $alliancePlayer->getDisplayName(), + 'ccount_id' => $alliancePlayer->getPlayerID(), ]; } $template->assign('Members', $members); diff --git a/engine/Default/alliance_remove_member_processing.php b/engine/Default/alliance_remove_member_processing.php index 59b764802..976fa93d4 100644 --- a/engine/Default/alliance_remove_member_processing.php +++ b/engine/Default/alliance_remove_member_processing.php @@ -1,20 +1,20 @@ getAlliance()->getLeaderID(), $accountIDs)) { +if (in_array($player->getAlliance()->getLeaderPlayerID(), $playerIDs)) { create_error('You can\'t kick the leader!'); } -if (in_array($player->getAccountID(), $accountIDs)) { +if (in_array($player->getPlayerID(), $playerIDs)) { create_error('You can\'t kick yourself!'); } -foreach ($accountIDs as $accountID) { - $currPlayer = SmrPlayer::getPlayer($accountID, $player->getGameID()); +foreach ($playerIDs as $playerID) { + $currPlayer = SmrPlayer::getPlayer($playerID, $player->getGameID()); if (!$player->sameAlliance($currPlayer)) { throw new Exception('Cannot kick someone from another alliance!'); } diff --git a/engine/Default/alliance_roles_save_processing.php b/engine/Default/alliance_roles_save_processing.php index c499cc4ee..b5650f81f 100644 --- a/engine/Default/alliance_roles_save_processing.php +++ b/engine/Default/alliance_roles_save_processing.php @@ -1,8 +1,9 @@ $roleID) { + +foreach (Request::getIntArray('role', []) as $playerID => $roleID) { $db->query('REPLACE INTO player_has_alliance_role - (account_id, game_id, role_id, alliance_id) - VALUES (' . $db->escapeNumber($accountID) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($roleID) . ',' . $db->escapeNumber($var['alliance_id']) . ')'); + (player_id, game_id, role_id, alliance_id) + VALUES (' . $db->escapeNumber($playerID) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($roleID) . ',' . $db->escapeNumber($var['alliance_id']) . ')'); } $container = create_container('skeleton.php', 'alliance_roster.php'); diff --git a/engine/Default/alliance_roster.php b/engine/Default/alliance_roster.php index 74436dbe1..130e75dc6 100644 --- a/engine/Default/alliance_roster.php +++ b/engine/Default/alliance_roster.php @@ -50,7 +50,7 @@ $template->assign('AllianceExp', $db->getInt('alliance_xp')); $template->assign('AllianceAverageExp', $db->getInt('alliance_avg')); -if ($account->getAccountID() == $alliance->getLeaderID() || $account->hasPermission(PERMISSION_EDIT_ALLIANCE_DESCRIPTION)) { +if ($player->getPlayerID() == $alliance->getLeaderPlayerID() || $account->hasPermission(PERMISSION_EDIT_ALLIANCE_DESCRIPTION)) { $container = create_container('skeleton.php', 'alliance_stat.php'); $container['alliance_id'] = $alliance->getAllianceID(); $template->assign('EditAllianceDescriptionHREF', SmrSession::getNewHREF($container)); @@ -66,7 +66,7 @@ if ($alliance->getAllianceID() == $player->getAllianceID()) { // Alliance members get to see active/inactive status of members - $template->assign('ActiveIDs', $alliance->getActiveIDs()); + $template->assign('ActivePlayerIDs', $alliance->getActivePlayerIDs()); $container = create_container('skeleton.php', 'alliance_roster.php'); if ($showRoles) { $container['action'] = 'Hide Alliance Roles'; diff --git a/engine/Default/alliance_set_op_processing.php b/engine/Default/alliance_set_op_processing.php index 521eae8cd..ec5f3350e 100644 --- a/engine/Default/alliance_set_op_processing.php +++ b/engine/Default/alliance_set_op_processing.php @@ -11,7 +11,7 @@ function error_on_page($error) { $db->query('DELETE FROM alliance_has_op_response WHERE alliance_id=' . $db->escapeNumber($player->getAllianceID()) . ' AND game_id=' . $db->escapeNumber($player->getGameID())); // Delete the announcement from alliance members message boxes - $db->query('DELETE FROM message WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND sender_id=' . $db->escapeNumber(ACCOUNT_ID_OP_ANNOUNCE) . ' AND account_id IN (' . $db->escapeArray($player->getAlliance()->getMemberIDs()) . ')'); + $db->query('DELETE FROM message WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND sender_id=' . $db->escapeNumber(PLAYER_ID_OP_ANNOUNCE) . ' AND player_id IN (' . $db->escapeArray($player->getAlliance()->getMemberPlayerIDs()) . ')'); // NOTE: for simplicity we don't touch `player_has_unread_messages` here, // so they may get an errant alliance message icon if logged in. @@ -33,8 +33,8 @@ function error_on_page($error) { // Send an alliance message that expires at the time of the op. // Since the message is procedural, don't exclude this player. $message = $player->getBBLink() . ' has scheduled an operation for ' . date(DATE_FULL_SHORT, $time) . '. Navigate to your Alliance console to respond!'; - foreach ($player->getAlliance()->getMemberIDs() as $memberAccountID) { - $player->sendMessageFromOpAnnounce($memberAccountID, $message, $time); + foreach ($player->getAlliance()->getMemberPlayerIDs() as $memberPlayerID) { + $player->sendMessageFromOpAnnounce($memberPlayerID, $message, $time); } } diff --git a/engine/Default/alliance_share_maps_processing.php b/engine/Default/alliance_share_maps_processing.php index 09d1be747..b54288dbf 100644 --- a/engine/Default/alliance_share_maps_processing.php +++ b/engine/Default/alliance_share_maps_processing.php @@ -1,19 +1,9 @@ query('SELECT * FROM player - WHERE alliance_id = ' . $db->escapeNumber($player->getAllianceID()) . ' - AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' - AND account_id != ' . $db->escapeNumber($player->getAccountID())); -while ($db->nextRecord()) { - // an array for later use - $alliance_ids[] = $db->getInt('account_id'); -} +$memberPlayerIDs = $player->getAlliance()->getMemberPlayerIDs(); // end here if we are alone in the alliance -if (empty($alliance_ids)) { +if (empty($memberPlayerIDs)) { create_error('Who exactly are you sharing maps with?'); } @@ -28,7 +18,7 @@ // delete all visited sectors from the table of all our alliance mates $db->query('DELETE FROM player_visited_sector - WHERE account_id IN (' . $db->escapeArray($alliance_ids) . ') + WHERE player_id IN (' . $db->escapeArray($memberPlayerIDs) . ') AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND sector_id NOT IN (' . $db->escapeArray($unvisitedSectors) . ')'); @@ -38,8 +28,8 @@ // get a list of all visited ports $db->query('SELECT sector_id FROM player_visited_port WHERE ' . $player->getSQL()); while ($db->nextRecord()) { - $cachedPort = SmrPort::getCachedPort($player->getGameID(), $db->getInt('sector_id'), $player->getAccountID()); - $cachedPort->addCachePorts($alliance_ids); + $cachedPort = SmrPort::getCachedPort($player->getGameID(), $db->getInt('sector_id'), $player->getPlayerID()); + $cachedPort->addCachePorts($memberPlayerIDs); } forward(create_container('skeleton.php', 'alliance_roster.php')); diff --git a/engine/Default/alliance_stat.php b/engine/Default/alliance_stat.php index 9a1cac19b..f3801274a 100644 --- a/engine/Default/alliance_stat.php +++ b/engine/Default/alliance_stat.php @@ -6,7 +6,7 @@ $alliance = SmrAlliance::getAlliance($alliance_id, $player->getGameID()); $template->assign('PageTopic', $alliance->getAllianceDisplayName(false, true)); -Menu::alliance($alliance_id, $alliance->getLeaderID()); +Menu::alliance($alliance_id, $alliance->getLeaderPlayerID()); $container = create_container('alliance_stat_processing.php'); $container['alliance_id'] = $alliance_id; diff --git a/engine/Default/bank_alliance.php b/engine/Default/bank_alliance.php index 92cc7c017..4a61c0b2d 100644 --- a/engine/Default/bank_alliance.php +++ b/engine/Default/bank_alliance.php @@ -37,7 +37,7 @@ $template->assign('AlliedAllianceBanks', $alliedAllianceBanks); $db->query('SELECT transaction, sum(amount) as total FROM alliance_bank_transactions - WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND payee_id = ' . $db->escapeNumber($player->getAccountID()) . ' + WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND ' . $player->getSQL() . ' GROUP BY transaction'); $playerTrans = array('Deposit' => 0, 'Payment' => 0); while ($db->nextRecord()) { @@ -61,8 +61,7 @@ } elseif ($withdrawalPerDay == ALLIANCE_BANK_UNLIMITED) { $template->assign('UnlimitedWithdrawal', true); } else { - $db->query('SELECT sum(amount) as total FROM alliance_bank_transactions WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' - AND payee_id = ' . $db->escapeNumber($player->getAccountID()) . ' AND transaction = \'Payment\' AND exempt = 0 AND time > ' . $db->escapeNumber(TIME - 86400)); + $db->query('SELECT sum(amount) as total FROM alliance_bank_transactions WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND ' . $player->getSQL() . ' AND transaction = \'Payment\' AND exempt = 0 AND time > ' . $db->escapeNumber(TIME - 86400)); if ($db->nextRecord()) { $totalWithdrawn = $db->getInt('total'); } @@ -87,12 +86,10 @@ $minValue = max(1, $maxValue - 5); } -$query = 'SELECT time, transaction_id, transaction, amount, exempt, reason, payee_id - FROM alliance_bank_transactions +$query = 'SELECT * FROM alliance_bank_transactions WHERE game_id=' . $db->escapeNumber($alliance->getGameID()) . ' AND alliance_id=' . $db->escapeNumber($alliance->getAllianceID()); - if ($maxValue > 0 && $minValue > 0) { $query .= ' AND transaction_id>=' . $db->escapeNumber($minValue) . ' AND transaction_id<=' . $db->escapeNumber($maxValue) . ' @@ -109,7 +106,7 @@ while ($db->nextRecord()) { $bankTransactions[$db->getInt('transaction_id')] = array( 'Time' => $db->getInt('time'), - 'Player' => SmrPlayer::getPlayer($db->getInt('payee_id'), $player->getGameID()), + 'Player' => SmrPlayer::getPlayer($db->getInt('player_id'), $player->getGameID()), 'Reason' => $db->getField('reason'), 'TransactionType' => $db->getField('transaction'), 'Withdrawal' => $db->getField('transaction') == 'Payment' ? $db->getInt('amount') : '', diff --git a/engine/Default/bank_alliance_processing.php b/engine/Default/bank_alliance_processing.php index 6cc9af4e9..f7363d046 100644 --- a/engine/Default/bank_alliance_processing.php +++ b/engine/Default/bank_alliance_processing.php @@ -46,7 +46,7 @@ $withdrawalPerDay = $db->getInt('with_per_day'); if ($db->getBoolean('positive_balance')) { $db->query('SELECT transaction, sum(amount) as total FROM alliance_bank_transactions - WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND payee_id = ' . $db->escapeNumber($player->getAccountID()) . ' + WHERE alliance_id = ' . $db->escapeNumber($alliance->getAllianceID()) . ' AND ' . $player->getSQL() . ' GROUP BY transaction'); $playerTrans = array('Deposit' => 0, 'Payment' => 0); while ($db->nextRecord()) { @@ -59,8 +59,7 @@ } elseif ($withdrawalPerDay >= 0) { $db->query('SELECT sum(amount) as total FROM alliance_bank_transactions WHERE alliance_id = ' . $db->escapeNumber($alliance_id) . ' - AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' - AND payee_id = ' . $db->escapeNumber($player->getAccountID()) . ' + AND ' . $player->getSQL() . ' AND transaction = \'Payment\' AND exempt = 0 AND time > ' . $db->escapeNumber(TIME - 86400)); @@ -92,8 +91,8 @@ // save log $requestExempt = Request::has('requestExempt') ? 1 : 0; $db->query('INSERT INTO alliance_bank_transactions - (alliance_id, game_id, transaction_id, time, payee_id, reason, transaction, amount, request_exempt) - VALUES(' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($next_id) . ', ' . $db->escapeNumber(TIME) . ', ' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeString($message) . ', ' . $db->escapeString($action) . ', ' . $db->escapeNumber($amount) . ', ' . $db->escapeNumber($requestExempt) . ')'); + (alliance_id, game_id, transaction_id, time, player_id, reason, transaction, amount, request_exempt) + VALUES(' . $db->escapeNumber($alliance_id) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($next_id) . ', ' . $db->escapeNumber(TIME) . ', ' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeString($message) . ', ' . $db->escapeString($action) . ', ' . $db->escapeNumber($amount) . ', ' . $db->escapeNumber($requestExempt) . ')'); // update player credits $player->update(); diff --git a/engine/Default/bank_anon.php b/engine/Default/bank_anon.php index ffb7be150..664a21f3b 100644 --- a/engine/Default/bank_anon.php +++ b/engine/Default/bank_anon.php @@ -13,9 +13,7 @@ $template->assign('Message', $var['message'] ?? ''); -$db->query('SELECT * FROM anon_bank - WHERE owner_id=' . $db->escapeNumber($player->getAccountID()) . ' - AND game_id=' . $db->escapeNumber($player->getGameID())); +$db->query('SELECT * FROM anon_bank WHERE ' . $player->getSQL()); $ownedAnon = []; $db2 = new SmrMySqlDatabase(); diff --git a/engine/Default/bank_anon_create_processing.php b/engine/Default/bank_anon_create_processing.php index b15ea7b0c..1296b1a7e 100644 --- a/engine/Default/bank_anon_create_processing.php +++ b/engine/Default/bank_anon_create_processing.php @@ -10,7 +10,7 @@ if ($db->nextRecord()) { $new_acc = $db->getInt('MAX(anon_id)') + 1; } -$db->query('INSERT INTO anon_bank (game_id, anon_id, owner_id, password, amount) VALUES (' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($new_acc) . ', ' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeString($password) . ', 0)'); +$db->query('INSERT INTO anon_bank (game_id, anon_id, player_id, password, amount) VALUES (' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($new_acc) . ', ' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeString($password) . ', 0)'); $container = create_container('skeleton.php', 'bank_anon.php'); $container['message'] = '

Account #' . $new_acc . ' has been opened for you.

'; diff --git a/engine/Default/bank_anon_detail.php b/engine/Default/bank_anon_detail.php index b1e6cf759..dc3e7bdcb 100644 --- a/engine/Default/bank_anon_detail.php +++ b/engine/Default/bank_anon_detail.php @@ -70,7 +70,7 @@ $transactions = []; while ($db->nextRecord()) { - $transactionPlayer = SmrPlayer::getPlayer($db->getInt('account_id'), $player->getGameID(), false, $db); + $transactionPlayer = SmrPlayer::getPlayer($db->getInt('player_id'), $player->getGameID(), false, $db); $transaction = $db->getField('transaction'); $amount = number_format($db->getInt('amount')); $transactions[$db->getInt('transaction_id')] = [ diff --git a/engine/Default/bank_anon_detail_processing.php b/engine/Default/bank_anon_detail_processing.php index 16f99fabc..50781cd53 100644 --- a/engine/Default/bank_anon_detail_processing.php +++ b/engine/Default/bank_anon_detail_processing.php @@ -42,8 +42,8 @@ $player->update(); // Log the bank transaction -$db->query('INSERT INTO anon_bank_transactions (account_id, game_id, anon_id, transaction_id, transaction, amount, time) - VALUES (' . $db->escapeNumber($player->getAccountID()) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($account_num) . ', ' . $db->escapeNumber($trans_id) . ', ' . $db->escapeString($action) . ', ' . $db->escapeNumber($amount) . ', ' . $db->escapeNumber(TIME) . ')'); +$db->query('INSERT INTO anon_bank_transactions (player_id, game_id, anon_id, transaction_id, transaction, amount, time) + VALUES (' . $db->escapeNumber($player->getPlayerID()) . ', ' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($account_num) . ', ' . $db->escapeNumber($trans_id) . ', ' . $db->escapeString($action) . ', ' . $db->escapeNumber($amount) . ', ' . $db->escapeNumber(TIME) . ')'); // Log the player action $player->log(LOG_TYPE_BANK, $action . ' of ' . $amount . ' credits in anonymous account #' . $account_num); diff --git a/engine/Default/bank_report.php b/engine/Default/bank_report.php index da51b27f5..d33bafe0e 100644 --- a/engine/Default/bank_report.php +++ b/engine/Default/bank_report.php @@ -14,36 +14,36 @@ $trans = array(); while ($db->nextRecord()) { $transType = ($db->getField('transaction') == 'Payment') ? WITHDRAW : DEPOSIT; - $payeeId = ($db->getInt('exempt')) ? 0 : $db->getInt('payee_id'); + $playerID = ($db->getInt('exempt')) ? 0 : $db->getInt('player_id'); // initialize payee if necessary - if (!isset($trans[$payeeId])) { - $trans[$payeeId] = array(WITHDRAW => 0, DEPOSIT => 0); + if (!isset($trans[$playerID])) { + $trans[$playerID] = array(WITHDRAW => 0, DEPOSIT => 0); } - $trans[$payeeId][$transType] += $db->getInt('amount'); + $trans[$playerID][$transType] += $db->getInt('amount'); } //ordering $playerIDs = array_keys($trans); -foreach ($trans as $accId => $transArray) { - $totals[$accId] = $transArray[DEPOSIT] - $transArray[WITHDRAW]; +foreach ($trans as $playerID => $transArray) { + $totals[$playerID] = $transArray[DEPOSIT] - $transArray[WITHDRAW]; } arsort($totals, SORT_NUMERIC); -$db->query('SELECT * FROM player WHERE account_id IN (' . $db->escapeArray($playerIDs) . ') AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' ORDER BY player_name'); +$db->query('SELECT * FROM player WHERE player_id IN (' . $db->escapeArray($playerIDs) . ') AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' ORDER BY player_name'); $players[0] = 'Alliance Funds'; while ($db->nextRecord()) { - $players[$db->getInt('account_id')] = htmlentities($db->getField('player_name')); + $players[$db->getInt('player_id')] = htmlentities($db->getField('player_name')); } //format it this way so its easy to send to the alliance MB if requested. $text = ''; $text .= ''; $balance = 0; -foreach ($totals as $accId => $total) { +foreach ($totals as $playerID => $total) { $balance += $total; $text .= ''; - $text .= ''; - $text .= ''; - $text .= ''; + $text .= ''; + $text .= ''; + $text .= ''; $text .= '
PlayerDepositsWithdrawalsTotal
' . $players[$accId] . '' . number_format($trans[$accId][DEPOSIT]) . '-' . number_format($trans[$accId][WITHDRAW]) . '' . $players[$playerID] . '' . number_format($trans[$playerID][DEPOSIT]) . '-' . number_format($trans[$playerID][WITHDRAW]) . '