|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Smr\Pages\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Smr\Database; |
|
6
|
|
|
use Smr\Epoch; |
|
7
|
|
|
use Smr\Exceptions\UserError; |
|
8
|
|
|
use Smr\Page\AccountPageProcessor; |
|
9
|
|
|
use Smr\Request; |
|
10
|
|
|
use SmrAccount; |
|
11
|
|
|
use SmrPlayer; |
|
12
|
|
|
|
|
13
|
|
|
class AccountEditProcessor extends AccountPageProcessor { |
|
14
|
|
|
|
|
15
|
|
|
public function __construct( |
|
16
|
|
|
private readonly int $editAccountID |
|
17
|
|
|
) {} |
|
18
|
|
|
|
|
19
|
|
|
public function build(SmrAccount $account): never { |
|
20
|
|
|
$db = Database::getInstance(); |
|
21
|
|
|
|
|
22
|
|
|
$account_id = $this->editAccountID; |
|
23
|
|
|
$curr_account = SmrAccount::getAccount($account_id); |
|
24
|
|
|
|
|
25
|
|
|
// request |
|
26
|
|
|
$donation = Request::getInt('donation'); |
|
27
|
|
|
$smr_credit = Request::has('smr_credit'); |
|
28
|
|
|
$rewardCredits = Request::getInt('grant_credits'); |
|
29
|
|
|
$choise = Request::get('choise', ''); // no radio button selected by default |
|
30
|
|
|
$reason_pre_select = Request::getInt('reason_pre_select'); |
|
31
|
|
|
$reason_msg = Request::get('reason_msg'); |
|
32
|
|
|
$veteran_status = Request::get('veteran_status') == 'TRUE'; |
|
33
|
|
|
$logging_status = Request::get('logging_status') == 'TRUE'; |
|
34
|
|
|
$except = Request::get('exception_add', ''); // missing if account already has an exception |
|
35
|
|
|
$points = Request::getInt('points'); |
|
36
|
|
|
$names = Request::getArray('player_name', []); // missing when no games joined |
|
37
|
|
|
$delete = Request::getArray('delete', []); // missing when no games joined |
|
38
|
|
|
|
|
39
|
|
|
$actions = []; |
|
40
|
|
|
|
|
41
|
|
|
if (!empty($donation)) { |
|
42
|
|
|
// add entry to account donated table |
|
43
|
|
|
$db->insert('account_donated', [ |
|
44
|
|
|
'account_id' => $db->escapeNumber($account_id), |
|
45
|
|
|
'time' => $db->escapeNumber(Epoch::time()), |
|
46
|
|
|
'amount' => $db->escapeNumber($donation), |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
// add the credits to the players account - if requested |
|
50
|
|
|
if (!empty($smr_credit)) { |
|
51
|
|
|
$curr_account->increaseSmrCredits($donation * CREDITS_PER_DOLLAR); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$actions[] = 'added $' . $donation; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (!empty($rewardCredits)) { |
|
58
|
|
|
$curr_account->increaseSmrRewardCredits($rewardCredits); |
|
59
|
|
|
$actions[] = 'added ' . $rewardCredits . ' reward credits'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (Request::has('special_close')) { |
|
63
|
|
|
$specialClose = Request::get('special_close'); |
|
64
|
|
|
// Make sure the special closing reason exists |
|
65
|
|
|
$dbResult = $db->read('SELECT reason_id FROM closing_reason WHERE reason=' . $db->escapeString($specialClose)); |
|
66
|
|
|
if ($dbResult->hasRecord()) { |
|
67
|
|
|
$reasonID = $dbResult->record()->getInt('reason_id'); |
|
68
|
|
|
} else { |
|
69
|
|
|
$reasonID = $db->insert('closing_reason', [ |
|
70
|
|
|
'reason' => $db->escapeString($specialClose), |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$closeByRequestNote = Request::get('close_by_request_note'); |
|
75
|
|
|
if (empty($closeByRequestNote)) { |
|
76
|
|
|
$closeByRequestNote = $specialClose; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$curr_account->banAccount(0, $account, $reasonID, $closeByRequestNote); |
|
80
|
|
|
$actions[] = 'added ' . $specialClose . ' ban'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if ($choise == 'reopen') { |
|
84
|
|
|
//do we have points |
|
85
|
|
|
$curr_account->removePoints($points); |
|
86
|
|
|
$curr_account->unbanAccount($account); |
|
87
|
|
|
$actions[] = 'reopened account and removed ' . $points . ' points'; |
|
88
|
|
|
} elseif ($points > 0) { |
|
89
|
|
|
if ($choise == 'individual') { |
|
90
|
|
|
$reason_id = $db->insert('closing_reason', [ |
|
91
|
|
|
'reason' => $db->escapeString($reason_msg), |
|
92
|
|
|
]); |
|
93
|
|
|
} else { |
|
94
|
|
|
$reason_id = $reason_pre_select; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$suspicion = Request::get('suspicion'); |
|
98
|
|
|
$bannedDays = $curr_account->addPoints($points, $account, $reason_id, $suspicion); |
|
99
|
|
|
$actions[] = 'added ' . $points . ' ban points'; |
|
100
|
|
|
|
|
101
|
|
|
if ($bannedDays !== false) { |
|
102
|
|
|
if ($bannedDays > 0) { |
|
103
|
|
|
$expire_msg = 'for ' . $bannedDays . ' days'; |
|
104
|
|
|
} else { |
|
105
|
|
|
$expire_msg = 'indefinitely'; |
|
106
|
|
|
} |
|
107
|
|
|
$actions[] = 'closed ' . $expire_msg; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (Request::has('mailban')) { |
|
112
|
|
|
$mailban = Request::get('mailban'); |
|
113
|
|
|
if ($mailban == 'remove') { |
|
114
|
|
|
$curr_account->setMailBanned(Epoch::time()); |
|
115
|
|
|
$actions[] = 'removed mailban'; |
|
116
|
|
|
} elseif ($mailban == 'add_days') { |
|
117
|
|
|
$days = Request::getInt('mailban_days'); |
|
118
|
|
|
$curr_account->increaseMailBanned($days * 86400); |
|
119
|
|
|
$actions[] = 'mail banned for ' . $days . ' days'; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if ($veteran_status != $curr_account->isVeteranForced()) { |
|
124
|
|
|
$db->write('UPDATE account SET veteran = ' . $db->escapeBoolean($veteran_status) . ' WHERE account_id = ' . $db->escapeNumber($account_id)); |
|
125
|
|
|
$actions[] = 'set the veteran status to ' . $db->escapeBoolean($veteran_status); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if ($logging_status != $curr_account->isLoggingEnabled()) { |
|
129
|
|
|
$curr_account->setLoggingEnabled($logging_status); |
|
130
|
|
|
$actions[] = 'set the logging status to ' . $logging_status; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if ($except != '') { |
|
134
|
|
|
$db->insert('account_exceptions', [ |
|
135
|
|
|
'account_id' => $db->escapeNumber($account_id), |
|
136
|
|
|
'reason' => $db->escapeString($except), |
|
137
|
|
|
]); |
|
138
|
|
|
$actions[] = 'added the exception ' . $except; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
foreach ($names as $game_id => $new_name) { |
|
142
|
|
|
if (empty($new_name)) { |
|
143
|
|
|
continue; |
|
144
|
|
|
} |
|
145
|
|
|
$editPlayer = SmrPlayer::getPlayer($account_id, $game_id); |
|
146
|
|
|
|
|
147
|
|
|
try { |
|
148
|
|
|
$editPlayer->changePlayerName($new_name); |
|
149
|
|
|
} catch (UserError $err) { |
|
150
|
|
|
$actions[] = 'have NOT changed player name to ' . htmlentities($new_name) . ' ( ' . $err->getMessage() . ')'; |
|
151
|
|
|
continue; |
|
152
|
|
|
} |
|
153
|
|
|
$editPlayer->update(); |
|
154
|
|
|
|
|
155
|
|
|
$actions[] = 'changed player name to ' . $editPlayer->getDisplayName(); |
|
156
|
|
|
|
|
157
|
|
|
//insert news message |
|
158
|
|
|
$news = 'Please be advised that player ' . $editPlayer->getPlayerID() . ' has had their name changed to ' . $editPlayer->getBBLink(); |
|
159
|
|
|
|
|
160
|
|
|
$db->insert('news', [ |
|
161
|
|
|
'time' => $db->escapeNumber(Epoch::time()), |
|
162
|
|
|
'news_message' => $db->escapeString($news), |
|
163
|
|
|
'game_id' => $db->escapeNumber($game_id), |
|
164
|
|
|
'type' => $db->escapeString('admin'), |
|
165
|
|
|
'killer_id' => $db->escapeNumber($account_id), |
|
166
|
|
|
]); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
if (!empty($delete)) { |
|
170
|
|
|
foreach ($delete as $game_id => $value) { |
|
171
|
|
|
if ($value == 'TRUE') { |
|
172
|
|
|
// Check for bank transactions into the alliance account |
|
173
|
|
|
$dbResult = $db->read('SELECT 1 FROM alliance_bank_transactions WHERE payee_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id) . ' LIMIT 1'); |
|
174
|
|
|
if ($dbResult->hasRecord()) { |
|
175
|
|
|
// Can't delete |
|
176
|
|
|
$actions[] = 'player has made alliance transaction'; |
|
177
|
|
|
continue; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$sql = 'account_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id); |
|
181
|
|
|
|
|
182
|
|
|
// Check anon accounts for transactions |
|
183
|
|
|
$dbResult = $db->read('SELECT 1 FROM anon_bank_transactions WHERE ' . $sql . ' LIMIT 1'); |
|
184
|
|
|
if ($dbResult->hasRecord()) { |
|
185
|
|
|
// Can't delete |
|
186
|
|
|
$actions[] = 'player has made anonymous transaction'; |
|
187
|
|
|
continue; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
$db->write('DELETE FROM alliance_thread |
|
191
|
|
|
WHERE sender_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
|
192
|
|
|
$db->write('DELETE FROM bounty WHERE ' . $sql); |
|
193
|
|
|
$db->write('DELETE FROM galactic_post_applications WHERE ' . $sql); |
|
194
|
|
|
$db->write('DELETE FROM galactic_post_article |
|
195
|
|
|
WHERE writer_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
|
196
|
|
|
$db->write('DELETE FROM galactic_post_writer WHERE ' . $sql); |
|
197
|
|
|
$db->write('DELETE FROM message WHERE ' . $sql); |
|
198
|
|
|
$db->write('DELETE FROM message_notify |
|
199
|
|
|
WHERE (from_id=' . $db->escapeNumber($account_id) . ' OR to_id=' . $db->escapeNumber($account_id) . ') AND game_id=' . $db->escapeNumber($game_id)); |
|
200
|
|
|
$db->write('UPDATE planet SET owner_id=0,planet_name=\'\',password=\'\',shields=0,drones=0,credits=0,bonds=0 |
|
201
|
|
|
WHERE owner_id=' . $db->escapeNumber($account_id) . ' AND game_id=' . $db->escapeNumber($game_id)); |
|
202
|
|
|
$db->write('DELETE FROM player_attacks_planet WHERE ' . $sql); |
|
203
|
|
|
$db->write('DELETE FROM player_attacks_port WHERE ' . $sql); |
|
204
|
|
|
$db->write('DELETE FROM player_has_alliance_role WHERE ' . $sql); |
|
205
|
|
|
$db->write('DELETE FROM player_has_drinks WHERE ' . $sql); |
|
206
|
|
|
$db->write('DELETE FROM player_has_relation WHERE ' . $sql); |
|
207
|
|
|
$db->write('DELETE FROM player_has_ticker WHERE ' . $sql); |
|
208
|
|
|
$db->write('DELETE FROM player_has_ticket WHERE ' . $sql); |
|
209
|
|
|
$db->write('DELETE FROM player_has_unread_messages WHERE ' . $sql); |
|
210
|
|
|
$db->write('DELETE FROM player_plotted_course WHERE ' . $sql); |
|
211
|
|
|
$db->write('DELETE FROM player_read_thread WHERE ' . $sql); |
|
212
|
|
|
$db->write('DELETE FROM player_visited_port WHERE ' . $sql); |
|
213
|
|
|
$db->write('DELETE FROM player_visited_sector WHERE ' . $sql); |
|
214
|
|
|
$db->write('DELETE FROM player_votes_pact WHERE ' . $sql); |
|
215
|
|
|
$db->write('DELETE FROM player_votes_relation WHERE ' . $sql); |
|
216
|
|
|
$db->write('DELETE FROM ship_has_cargo WHERE ' . $sql); |
|
217
|
|
|
$db->write('DELETE FROM ship_has_hardware WHERE ' . $sql); |
|
218
|
|
|
$db->write('DELETE FROM ship_has_illusion WHERE ' . $sql); |
|
219
|
|
|
$db->write('DELETE FROM ship_has_weapon WHERE ' . $sql); |
|
220
|
|
|
$db->write('DELETE FROM ship_is_cloaked WHERE ' . $sql); |
|
221
|
|
|
$db->write('DELETE FROM player WHERE ' . $sql); |
|
222
|
|
|
|
|
223
|
|
|
$db->write('UPDATE active_session SET game_id=0 WHERE ' . $sql . ' LIMIT 1'); |
|
224
|
|
|
|
|
225
|
|
|
$actions[] = 'deleted player from game ' . $game_id; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
//get his login name |
|
232
|
|
|
$msg = 'You ' . implode(' and ', $actions) . ' for the account of ' . $curr_account->getLogin() . '.'; |
|
233
|
|
|
$container = new AccountEditSearch(message: $msg); |
|
234
|
|
|
|
|
235
|
|
|
// Update the selected account in case it has been changed |
|
236
|
|
|
$curr_account->update(); |
|
237
|
|
|
$container->go(); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
} |
|
241
|
|
|
|