Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Failed Conditions
Pull Request — master (#1038)
by Dan
11:47
created

src/engine/Default/preferences_processing.php (2 issues)

1
<?php declare(strict_types=1);
2
3
$db = Smr\Database::getInstance();
4
$session = Smr\Session::getInstance();
5
$account = $session->getAccount();
6
7
$container = Page::create('skeleton.php');
8
if ($session->hasGame()) {
9
	$container['body'] = 'current_sector.php';
10
	$player = $session->getPlayer();
11
} else {
12
	$container['body'] = 'game_play.php';
13
}
14
$action = Request::get('action');
15
16
if ($action == 'Save and resend validation code') {
17
	$email = Request::get('email');
18
19
	$account->changeEmail($email);
20
21
	// overwrite container
22
	$container['body'] = 'validate.php';
23
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your email address, you will now need to revalidate with the code sent to the new email address.';
24
} elseif ($action == 'Change Password') {
25
	$new_password = Request::get('new_password');
26
	$old_password = Request::get('old_password');
27
	$retype_password = Request::get('retype_password');
28
29
	if (empty($new_password)) {
30
		create_error('You must enter a non empty password!');
31
	}
32
33
	if (!$account->checkPassword($old_password)) {
34
		create_error('Your current password is wrong!');
35
	}
36
37
	if ($new_password != $retype_password) {
38
		create_error('The passwords you entered don\'t match!');
39
	}
40
41
	if ($new_password == $account->getLogin()) {
42
		create_error('Your chosen password is invalid!');
43
	}
44
45
	$account->setPassword($new_password);
46
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your password.';
47
} elseif ($action == 'Change Name') {
48
	$HoF_name = trim(Request::get('HoF_name'));
49
50
	$limited_char = 0;
51
	for ($i = 0; $i < strlen($HoF_name); $i++) {
52
		// disallow certain ascii chars
53
		if (ord($HoF_name[$i]) < 32 || ord($HoF_name[$i]) > 127) {
54
			create_error('Your Hall Of Fame name contains invalid characters!');
55
		}
56
57
		// numbers 48..57
58
		// Letters 65..90
59
		// letters 97..122
60
		if (!((ord($HoF_name[$i]) >= 48 && ord($HoF_name[$i]) <= 57) ||
61
			(ord($HoF_name[$i]) >= 65 && ord($HoF_name[$i]) <= 90) ||
62
			(ord($HoF_name[$i]) >= 97 && ord($HoF_name[$i]) <= 122))) {
63
			$limited_char += 1;
64
		}
65
	}
66
67
	if ($limited_char > 4) {
68
		create_error('You cannot use a name with more than 4 special characters.');
69
	}
70
71
	//disallow blank names
72
	if (empty($HoF_name) || $HoF_name == '') {
73
		create_error('You Hall of Fame name must contain characters!');
74
	}
75
76
	//no duplicates
77
	$db->query('SELECT * FROM account WHERE hof_name = ' . $db->escapeString($HoF_name) . ' AND account_id != ' . $db->escapeNumber($account->getAccountID()) . ' LIMIT 1');
78
	if ($db->nextRecord()) {
79
		create_error('Someone is already using that name!');
80
	}
81
82
	// set the HoF name in account stat
83
	$account->setHofName($HoF_name);
84
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your hall of fame name.';
85
} elseif ($action == 'Change Discord ID') {
86
	$discordId = trim(Request::get('discord_id'));
87
88
	if (empty($discordId)) {
89
		$account->setDiscordId(null);
0 ignored issues
show
null of type null is incompatible with the type string expected by parameter $id of AbstractSmrAccount::setDiscordId(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
		$account->setDiscordId(/** @scrutinizer ignore-type */ null);
Loading history...
90
		$container['msg'] = '<span class="green">SUCCESS: </span>You have deleted your Discord User ID.';
91
92
	} else {
93
		// no duplicates
94
		$db->query('SELECT * FROM account WHERE discord_id =' . $db->escapeString($discordId) . ' AND account_id != ' . $db->escapeNumber($account->getAccountID()) . ' LIMIT 1');
95
		if ($db->nextRecord()) {
96
			create_error('Someone is already using that Discord User ID!');
97
		}
98
99
		$account->setDiscordId($discordId);
100
		$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your Discord User ID.';
101
	}
102
} elseif ($action == 'Change IRC Nick') {
103
	$ircNick = trim(Request::get('irc_nick'));
104
105
	for ($i = 0; $i < strlen($ircNick); $i++) {
106
		// disallow certain ascii chars (and whitespace!)
107
		if (ord($ircNick[$i]) < 33 || ord($ircNick[$i]) > 127) {
108
			create_error('Your IRC Nick contains invalid characters!');
109
		}
110
	}
111
112
	// here you can delete your registered irc nick
113
	if (empty($ircNick) || $ircNick == '') {
114
		$account->setIrcNick(null);
0 ignored issues
show
null of type null is incompatible with the type string expected by parameter $nick of AbstractSmrAccount::setIrcNick(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
		$account->setIrcNick(/** @scrutinizer ignore-type */ null);
Loading history...
115
		$container['msg'] = '<span class="green">SUCCESS: </span>You have deleted your irc nick.';
116
	} else {
117
118
		// no duplicates
119
		$db->query('SELECT * FROM account WHERE irc_nick = ' . $db->escapeString($ircNick) . ' AND account_id != ' . $db->escapeNumber($account->getAccountID()) . ' LIMIT 1');
120
		if ($db->nextRecord()) {
121
			create_error('Someone is already using that nick!');
122
		}
123
124
		// save irc nick in db and set message
125
		$account->setIrcNick($ircNick);
126
		$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your irc nick.';
127
128
	}
129
130
} elseif ($action == 'Yes') {
131
	$var = $session->getCurrentVar();
132
	$account_id = $var['account_id'];
133
	$amount = $var['amount'];
134
135
	// create his account
136
	$his_account = SmrAccount::getAccount($account_id);
137
138
	// take from us
139
	$account->decreaseSmrCredits($amount);
140
	// add to him
141
	$his_account->increaseSmrCredits($amount);
142
	$container['msg'] = '<span class="green">SUCCESS: </span>You have sent SMR credits.';
143
} elseif ($action == 'Change Timezone') {
144
	$timez = Request::getInt('timez');
145
146
	$db->query('UPDATE account SET offset = ' . $db->escapeNumber($timez) . ' WHERE account_id = ' . $db->escapeNumber($account->getAccountID()));
147
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your time offset.';
148
} elseif ($action == 'Change Date Formats') {
149
	$account->setShortDateFormat(Request::get('dateformat'));
150
	$account->setShortTimeFormat(Request::get('timeformat'));
151
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your date formats.';
152
} elseif ($action == 'Change Images') {
153
	$account->setDisplayShipImages(Request::get('images') == 'Yes');
154
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your ship images preferences.';
155
} elseif ($action == 'Change Centering') {
156
	$account->setCenterGalaxyMapOnPlayer(Request::get('centergalmap') == 'Yes');
157
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your centering galaxy map preferences.';
158
} elseif ($action == 'Change Size') {
159
	$fontsize = Request::getInt('fontsize');
160
	if ($fontsize < 50) {
161
		create_error('Minimum font size is 50%');
162
	}
163
	$account->setFontSize($fontsize);
164
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your font size.';
165
} elseif ($action == 'Change CSS Options') {
166
	$account->setCssLink(Request::get('csslink'));
167
	$cssTemplateAndColor = Request::get('template');
168
	if ($cssTemplateAndColor == 'None') {
169
		$account->setDefaultCSSEnabled(false);
170
	} else {
171
		$account->setDefaultCSSEnabled(true);
172
		list($cssTemplate, $cssColourScheme) = explode(' - ', $cssTemplateAndColor);
173
		$account->setTemplate($cssTemplate);
174
		$account->setColourScheme($cssColourScheme);
175
	}
176
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your CSS options.';
177
} elseif ($action == 'Change Kamikaze Setting') {
178
	$player->setCombatDronesKamikazeOnMines(Request::get('kamikaze') == 'Yes');
179
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your combat drones options.';
180
} elseif ($action == 'Change Message Setting') {
181
	$player->setForceDropMessages(Request::get('forceDropMessages') == 'Yes');
182
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your message options.';
183
} elseif ($action == 'Save Hotkeys') {
184
	foreach (AbstractSmrAccount::getDefaultHotkeys() as $hotkey => $binding) {
185
		$account->setHotkey($hotkey, explode(' ', Request::get($hotkey)));
186
	}
187
	$container['msg'] = '<span class="green">SUCCESS: </span>You have saved your hotkeys.';
188
} elseif ($action == 'change_name') {
189
	// trim input now
190
	$player_name = trim(Request::get('PlayerName'));
191
192
	if ($player->getPlayerName() == $player_name) {
193
		create_error('Your player already has that name!');
194
	}
195
196
	$limited_char = 0;
197
	for ($i = 0; $i < strlen($player_name); $i++) {
198
		// disallow certain ascii chars
199
		if (ord($player_name[$i]) < 32 || ord($player_name[$i]) > 127) {
200
			create_error('The player name contains invalid characters!');
201
		}
202
203
		// numbers 48..57
204
		// Letters 65..90
205
		// letters 97..122
206
		if (!((ord($player_name[$i]) >= 48 && ord($player_name[$i]) <= 57) ||
207
			(ord($player_name[$i]) >= 65 && ord($player_name[$i]) <= 90) ||
208
			(ord($player_name[$i]) >= 97 && ord($player_name[$i]) <= 122))) {
209
			$limited_char += 1;
210
		}
211
	}
212
213
	if ($limited_char > 4) {
214
		create_error('You cannot use a name with more than 4 special characters.');
215
	}
216
217
	if (empty($player_name)) {
218
		create_error('You must enter a player name!');
219
	}
220
221
	// Check if name is in use.
222
	// The player_name field has case-insensitive collation, so check against ID
223
	// to allow player to change the case of their name.
224
	$db->query('SELECT 1 FROM player WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND player_name=' . $db->escapeString($player_name) . ' AND player_id != ' . $db->escapeNumber($player->getPlayerID()) . ' LIMIT 1');
225
	if ($db->getNumRows()) {
226
		create_error('Name is already being used in this game!');
227
	}
228
229
	if ($player->isNameChanged()) {
230
		if ($account->getTotalSmrCredits() < CREDITS_PER_NAME_CHANGE) {
231
			create_error('You do not have enough credits to change your name.');
232
		}
233
		$account->decreaseTotalSmrCredits(CREDITS_PER_NAME_CHANGE);
234
	}
235
236
	$old_name = $player->getDisplayName();
237
238
	$player->setPlayerNameByPlayer($player_name);
239
240
	$news = 'Please be advised that ' . $old_name . ' has changed their name to ' . $player->getBBLink();
241
	$db->query('INSERT INTO news (time, news_message, game_id, type, killer_id) VALUES (' . $db->escapeNumber(Smr\Epoch::time()) . ',' . $db->escapeString($news) . ',' . $db->escapeNumber($player->getGameID()) . ', \'admin\', ' . $db->escapeNumber($player->getAccountID()) . ')');
242
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your player name.';
243
} elseif ($action == 'change_race') {
244
	if (!$player->canChangeRace()) {
245
		throw new Exception('Player is not allowed to change their race!');
246
	}
247
	$newRaceID = Request::getInt('race_id');
248
	if (!in_array($newRaceID, $player->getGame()->getPlayableRaceIDs())) {
249
		throw new Exception('Invalid race ID selected!');
250
	}
251
	if ($newRaceID == $player->getRaceID()) {
252
		create_error('You are already the ' . $player->getRaceName() . ' race!');
253
	}
254
255
	// Modify the player
256
	$oldRaceID = $player->getRaceID();
257
	$player->setRaceID($newRaceID);
258
	$player->setSectorID($player->getHome());
259
	$player->setLandedOnPlanet(false);
260
	$player->getSector()->markVisited($player);
261
	$player->getShip()->getPod($player->hasNewbieStatus()); // just to reset
262
	$player->getShip()->giveStarterShip();
263
	$player->setNewbieTurns(max(1, $player->getNewbieTurns()));
264
	$player->setExperience(0);
265
	$player->setRaceChanged(true);
266
267
	// Reset relations
268
	$db->query('DELETE FROM player_has_relation WHERE ' . $player->getSQL());
269
	$player->giveStartingRelations();
270
271
	$news = 'Please be advised that ' . $player->getBBLink() . ' has changed their race from [race=' . $oldRaceID . '] to [race=' . $player->getRaceID() . ']';
272
	$db->query('INSERT INTO news (time, news_message, game_id, type, killer_id) VALUES (' . $db->escapeNumber(Smr\Epoch::time()) . ',' . $db->escapeString($news) . ',' . $db->escapeNumber($player->getGameID()) . ', \'admin\', ' . $db->escapeNumber($player->getAccountID()) . ')');
273
	$container['msg'] = '<span class="green">SUCCESS: </span>You have changed your player race.';
274
} elseif ($action == 'Update Colours') {
275
	$friendlyColour = Request::get('friendly_color');
276
	$neutralColour = Request::get('neutral_color');
277
	$enemyColour = Request::get('enemy_color');
278
279
	if (strlen($friendlyColour) == 6) {
280
		$account->setFriendlyColour($friendlyColour);
281
	}
282
	if (strlen($neutralColour) == 6) {
283
		$account->setNeutralColour($neutralColour);
284
	}
285
	if (strlen($enemyColour) == 6) {
286
		$account->setEnemyColour($enemyColour);
287
	}
288
}
289
290
// Update the account in case it has changed
291
$account->update();
292
293
$container->go();
294