smrealms /
smr
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | $db = Smr\Database::getInstance(); |
||||
| 4 | $session = Smr\Session::getInstance(); |
||||
| 5 | $var = $session->getCurrentVar(); |
||||
| 6 | $account = $session->getAccount(); |
||||
| 7 | |||||
| 8 | $account_id = $var['account_id']; |
||||
| 9 | $curr_account = SmrAccount::getAccount($account_id); |
||||
| 10 | |||||
| 11 | // request |
||||
| 12 | $donation = Request::getInt('donation'); |
||||
| 13 | $smr_credit = Request::has('smr_credit'); |
||||
| 14 | $rewardCredits = Request::getInt('grant_credits'); |
||||
| 15 | $choise = Request::get('choise', ''); // no radio button selected by default |
||||
| 16 | $reason_pre_select = Request::getInt('reason_pre_select'); |
||||
| 17 | $reason_msg = Request::get('reason_msg'); |
||||
| 18 | $veteran_status = Request::get('veteran_status') == 'TRUE'; |
||||
| 19 | $logging_status = Request::get('logging_status') == 'TRUE'; |
||||
| 20 | $except = Request::get('exception_add'); |
||||
| 21 | $points = Request::getInt('points'); |
||||
| 22 | $names = Request::getArray('player_name', []); // missing when no games joined |
||||
| 23 | $delete = Request::getArray('delete', []); // missing when no games joined |
||||
| 24 | |||||
| 25 | $actions = []; |
||||
| 26 | |||||
| 27 | if (!empty($donation)) { |
||||
| 28 | // add entry to account donated table |
||||
| 29 | $db->query('INSERT INTO account_donated (account_id, time, amount) VALUES (' . $db->escapeNumber($account_id) . ', ' . $db->escapeNumber(Smr\Epoch::time()) . ' , ' . $db->escapeNumber($donation) . ')'); |
||||
| 30 | |||||
| 31 | // add the credits to the players account - if requested |
||||
| 32 | if (!empty($smr_credit)) { |
||||
| 33 | $curr_account->increaseSmrCredits($donation * CREDITS_PER_DOLLAR); |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | $actions[] = 'added $' . $donation; |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | if (!empty($rewardCredits)) { |
||||
| 40 | $curr_account->increaseSmrRewardCredits($rewardCredits); |
||||
| 41 | $actions[] = 'added ' . $rewardCredits . ' reward credits'; |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | if (Request::has('special_close')) { |
||||
| 45 | $specialClose = Request::get('special_close'); |
||||
| 46 | // Make sure the special closing reason exists |
||||
| 47 | $db->query('SELECT reason_id FROM closing_reason WHERE reason=' . $db->escapeString($specialClose)); |
||||
| 48 | if ($db->nextRecord()) { |
||||
| 49 | $reasonID = $db->getInt('reason_id'); |
||||
| 50 | } else { |
||||
| 51 | $db->query('INSERT INTO closing_reason (reason) VALUES(' . $db->escapeString($specialClose) . ')'); |
||||
| 52 | $reasonID = $db->getInsertID(); |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | $closeByRequestNote = Request::get('close_by_request_note'); |
||||
| 56 | if (empty($closeByRequestNote)) { |
||||
| 57 | $closeByRequestNote = $specialClose; |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | $curr_account->banAccount(0, $account, $reasonID, $closeByRequestNote); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 61 | $actions[] = 'added ' . $specialClose . ' ban'; |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | if ($choise == 'reopen') { |
||||
| 65 | //do we have points |
||||
| 66 | $curr_account->removePoints($points); |
||||
| 67 | $curr_account->unbanAccount($account); |
||||
| 68 | $actions[] = 'reopened account and removed ' . $points . ' points'; |
||||
| 69 | } elseif ($points > 0) { |
||||
| 70 | if ($choise == 'individual') { |
||||
| 71 | $db->query('INSERT INTO closing_reason (reason) VALUES(' . $db->escapeString($reason_msg) . ')'); |
||||
| 72 | $reason_id = $db->getInsertID(); |
||||
| 73 | } else { |
||||
| 74 | $reason_id = $reason_pre_select; |
||||
| 75 | } |
||||
| 76 | |||||
| 77 | $suspicion = Request::get('suspicion'); |
||||
| 78 | $bannedDays = $curr_account->addPoints($points, $account, $reason_id, $suspicion); |
||||
|
0 ignored issues
–
show
It seems like
$reason_id can also be of type string; however, parameter $reasonID of AbstractSmrAccount::addPoints() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 79 | $actions[] = 'added ' . $points . ' ban points'; |
||||
| 80 | |||||
| 81 | if ($bannedDays !== false) { |
||||
| 82 | if ($bannedDays > 0) { |
||||
| 83 | $expire_msg = 'for ' . $bannedDays . ' days'; |
||||
| 84 | } else { |
||||
| 85 | $expire_msg = 'indefinitely'; |
||||
| 86 | } |
||||
| 87 | $actions[] = 'closed ' . $expire_msg; |
||||
| 88 | } |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | if (Request::has('mailban')) { |
||||
| 92 | $mailban = Request::get('mailban'); |
||||
| 93 | if ($mailban == 'remove') { |
||||
| 94 | $curr_account->setMailBanned(Smr\Epoch::time()); |
||||
| 95 | $actions[] = 'removed mailban'; |
||||
| 96 | } elseif ($mailban == 'add_days') { |
||||
| 97 | $days = Request::getInt('mailban_days'); |
||||
| 98 | $curr_account->increaseMailBanned($days * 86400); |
||||
| 99 | $actions[] = 'mail banned for ' . $days . ' days'; |
||||
| 100 | } |
||||
| 101 | } |
||||
| 102 | |||||
| 103 | if ($veteran_status != $curr_account->isVeteranForced()) { |
||||
| 104 | $db->query('UPDATE account SET veteran = ' . $db->escapeString($veteran_status) . ' WHERE account_id = ' . $db->escapeNumber($account_id)); |
||||
|
0 ignored issues
–
show
$veteran_status of type boolean is incompatible with the type null|string expected by parameter $string of Smr\Database::escapeString().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 105 | $actions[] = 'set the veteran status to ' . $db->escapeString($veteran_status); |
||||
| 106 | } |
||||
| 107 | |||||
| 108 | if ($logging_status != $curr_account->isLoggingEnabled()) { |
||||
| 109 | $curr_account->setLoggingEnabled($logging_status); |
||||
| 110 | $actions[] = 'set the logging status to ' . $logging_status; |
||||
| 111 | } |
||||
| 112 | |||||
| 113 | if ($except != 'Add An Exception' && $except != '') { |
||||
| 114 | $db->query('INSERT INTO account_exceptions (account_id, reason) VALUES (' . $db->escapeNumber($account_id) . ', ' . $db->escapeString($except) . ')'); |
||||
| 115 | $actions[] = 'added the exception ' . $except; |
||||
| 116 | } |
||||
| 117 | |||||
| 118 | if (!empty($names)) { |
||||
| 119 | foreach ($names as $game_id => $new_name) { |
||||
| 120 | if (!empty($new_name)) { |
||||
| 121 | $db->query('SELECT account_id FROM player WHERE game_id = ' . $db->escapeNumber($game_id) . ' AND player_name = ' . $db->escapeString($new_name)); |
||||
| 122 | if (!$db->nextRecord()) { |
||||
| 123 | $editPlayer = SmrPlayer::getPlayer($account_id, $game_id); |
||||
| 124 | $editPlayer->setPlayerName($new_name); |
||||
| 125 | $editPlayer->update(); |
||||
| 126 | |||||
| 127 | $actions[] = 'changed player name to ' . $editPlayer->getDisplayName(); |
||||
| 128 | |||||
| 129 | //insert news message |
||||
| 130 | $news = 'Please be advised that player ' . $editPlayer->getPlayerID() . ' has had their name changed to ' . $editPlayer->getBBLink(); |
||||
| 131 | |||||
| 132 | $db->query('INSERT INTO news (time, news_message, game_id, type, killer_id) VALUES (' . $db->escapeNumber(Smr\Epoch::time()) . ',' . $db->escapeString($news) . ',' . $db->escapeNumber($game_id) . ', \'admin\', ' . $db->escapeNumber($account_id) . ')'); |
||||
| 133 | } elseif ($db->getInt('account_id') != $account_id) { |
||||
| 134 | $actions[] = 'have NOT changed player name to ' . htmlentities($new_name) . ' (already taken)'; |
||||
| 135 | } |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | } |
||||
| 139 | } |
||||
| 140 | |||||
| 141 | if (!empty($delete)) { |
||||
| 142 | foreach ($delete as $game_id => $value) { |
||||
| 143 | if ($value == 'TRUE') { |
||||
| 144 | // Check for bank transactions into the alliance account |
||||
| 145 | $db->query('SELECT * FROM alliance_bank_transactions WHERE payee_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id) . ' LIMIT 1'); |
||||
| 146 | if ($db->getNumRows() != 0) { |
||||
| 147 | // Can't delete |
||||
| 148 | $actions[] = 'player has made alliance transaction'; |
||||
| 149 | continue; |
||||
| 150 | } |
||||
| 151 | |||||
| 152 | $sql = 'account_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id); |
||||
| 153 | |||||
| 154 | // Check anon accounts for transactions |
||||
| 155 | $db->query('SELECT * FROM anon_bank_transactions WHERE ' . $sql . ' LIMIT 1'); |
||||
| 156 | if ($db->getNumRows() != 0) { |
||||
| 157 | // Can't delete |
||||
| 158 | $actions[] = 'player has made anonymous transaction'; |
||||
| 159 | continue; |
||||
| 160 | } |
||||
| 161 | |||||
| 162 | $db->query('DELETE FROM alliance_thread |
||||
| 163 | WHERE sender_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
||||
| 164 | $db->query('DELETE FROM bounty WHERE ' . $sql); |
||||
| 165 | $db->query('DELETE FROM galactic_post_applications WHERE ' . $sql); |
||||
| 166 | $db->query('DELETE FROM galactic_post_article |
||||
| 167 | WHERE writer_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
||||
| 168 | $db->query('DELETE FROM galactic_post_writer WHERE ' . $sql); |
||||
| 169 | $db->query('DELETE FROM message WHERE ' . $sql); |
||||
| 170 | $db->query('DELETE FROM message_notify |
||||
| 171 | WHERE (from_id=' . $db->escapeNumber($account_id) . ' OR to_id=' . $db->escapeNumber($account_id) . ') AND game_id=' . $db->escapeNumber($game_id)); |
||||
| 172 | $db->query('UPDATE planet SET owner_id=0,planet_name=\'\',password=\'\',shields=0,drones=0,credits=0,bonds=0 |
||||
| 173 | WHERE owner_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
||||
| 174 | $db->query('DELETE FROM player_attacks_planet WHERE ' . $sql); |
||||
| 175 | $db->query('DELETE FROM player_attacks_port WHERE ' . $sql); |
||||
| 176 | $db->query('DELETE FROM player_has_alliance_role WHERE ' . $sql); |
||||
| 177 | $db->query('DELETE FROM player_has_drinks WHERE ' . $sql); |
||||
| 178 | $db->query('DELETE FROM player_has_relation WHERE ' . $sql); |
||||
| 179 | $db->query('DELETE FROM player_has_ticker WHERE ' . $sql); |
||||
| 180 | $db->query('DELETE FROM player_has_ticket WHERE ' . $sql); |
||||
| 181 | $db->query('DELETE FROM player_has_unread_messages WHERE ' . $sql); |
||||
| 182 | $db->query('DELETE FROM player_plotted_course WHERE ' . $sql); |
||||
| 183 | $db->query('DELETE FROM player_read_thread WHERE ' . $sql); |
||||
| 184 | $db->query('DELETE FROM player_visited_port WHERE ' . $sql); |
||||
| 185 | $db->query('DELETE FROM player_visited_sector WHERE ' . $sql); |
||||
| 186 | $db->query('DELETE FROM player_votes_pact WHERE ' . $sql); |
||||
| 187 | $db->query('DELETE FROM player_votes_relation WHERE ' . $sql); |
||||
| 188 | $db->query('DELETE FROM ship_has_cargo WHERE ' . $sql); |
||||
| 189 | $db->query('DELETE FROM ship_has_hardware WHERE ' . $sql); |
||||
| 190 | $db->query('DELETE FROM ship_has_illusion WHERE ' . $sql); |
||||
| 191 | $db->query('DELETE FROM ship_has_weapon WHERE ' . $sql); |
||||
| 192 | $db->query('DELETE FROM ship_is_cloaked WHERE ' . $sql); |
||||
| 193 | $db->query('DELETE FROM player WHERE ' . $sql); |
||||
| 194 | |||||
| 195 | $db->query('UPDATE active_session SET game_id=0 WHERE ' . $sql . ' LIMIT 1'); |
||||
| 196 | |||||
| 197 | $actions[] = 'deleted player from game ' . $game_id; |
||||
| 198 | } |
||||
| 199 | } |
||||
| 200 | |||||
| 201 | } |
||||
| 202 | |||||
| 203 | //get his login name |
||||
| 204 | $container = Page::create('skeleton.php', 'account_edit_search.php'); |
||||
| 205 | $container['msg'] = 'You ' . join(' and ', $actions) . ' for the account of ' . $curr_account->getLogin() . '.'; |
||||
| 206 | |||||
| 207 | // Update the selected account in case it has been changed |
||||
| 208 | $curr_account->update(); |
||||
| 209 | $container->go(); |
||||
| 210 |