We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -10,23 +10,23 @@ discard block |
||
10 | 10 | protected const USER_RANKINGS_SCORE = array( |
11 | 11 | // [Stat, a, b] |
12 | 12 | // Used as: pow(Stat * a, USER_RANKINGS_EACH_STAT_POW) * b |
13 | - array(array('Trade','Experience','Total'),.1,0.5), |
|
14 | - array(array('Trade','Money','Profit'),0.00005,0.5), |
|
15 | - array(array('Killing','Kills'),1000,1) |
|
13 | + array(array('Trade', 'Experience', 'Total'), .1, 0.5), |
|
14 | + array(array('Trade', 'Money', 'Profit'), 0.00005, 0.5), |
|
15 | + array(array('Killing', 'Kills'), 1000, 1) |
|
16 | 16 | ); |
17 | 17 | |
18 | 18 | protected static $CACHE_ACCOUNTS = array(); |
19 | 19 | protected const DEFAULT_HOTKEYS = array( |
20 | - 'MoveUp' => array('w','up'), |
|
21 | - 'ScanUp' => array('shift+w','shift+up'), |
|
22 | - 'MoveLeft' => array('a','left'), |
|
23 | - 'ScanLeft' => array('shift+a','shift+left'), |
|
24 | - 'MoveRight' => array('d','right'), |
|
25 | - 'ScanRight' => array('shift+d','shift+right'), |
|
26 | - 'MoveDown' => array('s','down'), |
|
27 | - 'ScanDown' => array('shift+s','shift+down'), |
|
28 | - 'MoveWarp' => array('e','0'), |
|
29 | - 'ScanWarp' => array('shift+e','shift+0'), |
|
20 | + 'MoveUp' => array('w', 'up'), |
|
21 | + 'ScanUp' => array('shift+w', 'shift+up'), |
|
22 | + 'MoveLeft' => array('a', 'left'), |
|
23 | + 'ScanLeft' => array('shift+a', 'shift+left'), |
|
24 | + 'MoveRight' => array('d', 'right'), |
|
25 | + 'ScanRight' => array('shift+d', 'shift+right'), |
|
26 | + 'MoveDown' => array('s', 'down'), |
|
27 | + 'ScanDown' => array('shift+s', 'shift+down'), |
|
28 | + 'MoveWarp' => array('e', '0'), |
|
29 | + 'ScanWarp' => array('shift+e', 'shift+0'), |
|
30 | 30 | 'ScanCurrent' => array('shift+1'), |
31 | 31 | 'CurrentSector' => array('1'), |
32 | 32 | 'LocalMap' => array('2'), |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | protected $oldAccountIDs = array(); |
68 | 68 | protected $maxRankAchieved; |
69 | 69 | protected $referrerID; |
70 | - protected $credits; // SMR credits |
|
70 | + protected $credits; // SMR credits |
|
71 | 71 | protected $rewardCredits; // SMR reward credits |
72 | 72 | protected $dateShort; |
73 | 73 | protected $timeShort; |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | return self::DEFAULT_HOTKEYS; |
89 | 89 | } |
90 | 90 | |
91 | - public static function getAccount($accountID,$forceUpdate = false) { |
|
92 | - if($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
91 | + public static function getAccount($accountID, $forceUpdate = false) { |
|
92 | + if ($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
93 | 93 | self::$CACHE_ACCOUNTS[$accountID] = new SmrAccount($accountID); |
94 | 94 | } |
95 | 95 | return self::$CACHE_ACCOUNTS[$accountID]; |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | public static function getAccountByName($login, $forceUpdate = false) { |
99 | 99 | if (empty($login)) { return null; } |
100 | 100 | $db = new SmrMySqlDatabase(); |
101 | - $db->query('SELECT account_id FROM account WHERE login = '.$db->escapeString($login).' LIMIT 1'); |
|
102 | - if($db->nextRecord()) |
|
101 | + $db->query('SELECT account_id FROM account WHERE login = ' . $db->escapeString($login) . ' LIMIT 1'); |
|
102 | + if ($db->nextRecord()) |
|
103 | 103 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
104 | 104 | $return = null; |
105 | 105 | return $return; |
106 | 106 | } |
107 | 107 | |
108 | - public static function getAccountByEmail($email, $forceUpdate=false) { |
|
108 | + public static function getAccountByEmail($email, $forceUpdate = false) { |
|
109 | 109 | if (empty($email)) { return null; } |
110 | 110 | $db = new SmrMySqlDatabase(); |
111 | - $db->query('SELECT account_id FROM account WHERE email = '.$db->escapeString($email).' LIMIT 1'); |
|
111 | + $db->query('SELECT account_id FROM account WHERE email = ' . $db->escapeString($email) . ' LIMIT 1'); |
|
112 | 112 | if ($db->nextRecord()) { |
113 | 113 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
114 | 114 | } else { |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - public static function getAccountByDiscordId($id, $forceUpdate=false) { |
|
119 | + public static function getAccountByDiscordId($id, $forceUpdate = false) { |
|
120 | 120 | if (empty($id)) { return null; } |
121 | 121 | $db = new SmrMySqlDatabase(); |
122 | - $db->query('SELECT account_id FROM account where discord_id = '.$db->escapeString($id).' LIMIT 1'); |
|
122 | + $db->query('SELECT account_id FROM account where discord_id = ' . $db->escapeString($id) . ' LIMIT 1'); |
|
123 | 123 | if ($db->nextRecord()) { |
124 | 124 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
125 | 125 | } else { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | public static function getAccountByIrcNick($nick, $forceUpdate = false) { |
131 | 131 | if (empty($nick)) { return null; } |
132 | 132 | $db = new SmrMySqlDatabase(); |
133 | - $db->query('SELECT account_id FROM account WHERE irc_nick = '.$db->escapeString($nick).' LIMIT 1'); |
|
133 | + $db->query('SELECT account_id FROM account WHERE irc_nick = ' . $db->escapeString($nick) . ' LIMIT 1'); |
|
134 | 134 | if ($db->nextRecord()) { |
135 | 135 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
136 | 136 | } else { |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate=false) { |
|
141 | + public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate = false) { |
|
142 | 142 | if (!$social->isValid()) { return null; } |
143 | 143 | $db = new SmrMySqlDatabase(); |
144 | 144 | $db->query('SELECT account_id FROM account JOIN account_auth USING(account_id) |
145 | - WHERE login_type = '.$db->escapeString($social->getLoginType()).' |
|
146 | - AND auth_key = '.$db->escapeString($social->getUserID()).' LIMIT 1'); |
|
145 | + WHERE login_type = '.$db->escapeString($social->getLoginType()) . ' |
|
146 | + AND auth_key = '.$db->escapeString($social->getUserID()) . ' LIMIT 1'); |
|
147 | 147 | if ($db->nextRecord()) { |
148 | 148 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
149 | 149 | } else { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | public static function createAccount($login, $password, $email, $timez, $referral) { |
155 | - if($referral!=0) { |
|
155 | + if ($referral != 0) { |
|
156 | 156 | // Will throw if referral account doesn't exist |
157 | 157 | SmrAccount::getAccount($referral); |
158 | 158 | } |
@@ -160,60 +160,60 @@ discard block |
||
160 | 160 | $passwordHash = password_hash($password, PASSWORD_DEFAULT); |
161 | 161 | $db->query('INSERT INTO account (login, password, email, validation_code, last_login, offset,referral_id,hof_name) VALUES(' . |
162 | 162 | $db->escapeString($login) . ', ' . $db->escapeString($passwordHash) . ', ' . $db->escapeString($email) . ', ' . |
163 | - $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral).','.$db->escapeString($login).')'); |
|
163 | + $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral) . ',' . $db->escapeString($login) . ')'); |
|
164 | 164 | return self::getAccountByName($login); |
165 | 165 | } |
166 | 166 | |
167 | 167 | public static function getUserScoreCaseStatement($db) { |
168 | 168 | $userRankingTypes = array(); |
169 | 169 | $case = 'FLOOR(SUM(CASE type '; |
170 | - foreach(self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
171 | - $userRankingType = $db->escapeArray($userRankingScore[0],false,false,':',false); |
|
170 | + foreach (self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
171 | + $userRankingType = $db->escapeArray($userRankingScore[0], false, false, ':', false); |
|
172 | 172 | $userRankingTypes[] = $userRankingType; |
173 | - $case.= ' WHEN '.$db->escapeString($userRankingType).' THEN POW(amount*'.$userRankingScore[1].','.SmrAccount::USER_RANKINGS_EACH_STAT_POW.')*'.$userRankingScore[2]; |
|
173 | + $case .= ' WHEN ' . $db->escapeString($userRankingType) . ' THEN POW(amount*' . $userRankingScore[1] . ',' . SmrAccount::USER_RANKINGS_EACH_STAT_POW . ')*' . $userRankingScore[2]; |
|
174 | 174 | } |
175 | 175 | $case .= ' END))'; |
176 | - return array('CASE'=>$case,'IN'=>$db->escapeArray($userRankingTypes)); |
|
176 | + return array('CASE'=>$case, 'IN'=>$db->escapeArray($userRankingTypes)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | protected function __construct($accountID) { |
180 | 180 | $this->db = new SmrMySqlDatabase(); |
181 | 181 | $this->SQL = 'account_id = ' . $this->db->escapeNumber($accountID); |
182 | - $this->db->query('SELECT * FROM account WHERE '.$this->SQL.' LIMIT 1'); |
|
182 | + $this->db->query('SELECT * FROM account WHERE ' . $this->SQL . ' LIMIT 1'); |
|
183 | 183 | |
184 | 184 | if ($this->db->nextRecord()) { |
185 | 185 | $row = $this->db->getRow(); |
186 | - $this->account_id = $row['account_id']; |
|
186 | + $this->account_id = $row['account_id']; |
|
187 | 187 | |
188 | 188 | $this->login = $row['login']; |
189 | - $this->passwordHash = $row['password']; |
|
189 | + $this->passwordHash = $row['password']; |
|
190 | 190 | $this->email = $row['email']; |
191 | - $this->validated = $this->db->getBoolean('validated'); |
|
191 | + $this->validated = $this->db->getBoolean('validated'); |
|
192 | 192 | |
193 | - $this->last_login = $row['last_login']; |
|
194 | - $this->validation_code = $row['validation_code']; |
|
195 | - $this->veteranForced = $this->db->getBoolean('veteran'); |
|
196 | - $this->logging = $this->db->getBoolean('logging'); |
|
193 | + $this->last_login = $row['last_login']; |
|
194 | + $this->validation_code = $row['validation_code']; |
|
195 | + $this->veteranForced = $this->db->getBoolean('veteran'); |
|
196 | + $this->logging = $this->db->getBoolean('logging'); |
|
197 | 197 | $this->offset = $row['offset']; |
198 | 198 | $this->images = $row['images']; |
199 | - $this->fontSize = $row['fontsize']; |
|
199 | + $this->fontSize = $row['fontsize']; |
|
200 | 200 | |
201 | - $this->passwordReset = $row['password_reset']; |
|
202 | - $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
203 | - $this->mailBanned = (int)$row['mail_banned']; |
|
201 | + $this->passwordReset = $row['password_reset']; |
|
202 | + $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
203 | + $this->mailBanned = (int)$row['mail_banned']; |
|
204 | 204 | |
205 | - $this->friendlyColour = $row['friendly_colour']; |
|
206 | - $this->neutralColour = $row['neutral_colour']; |
|
207 | - $this->enemyColour = $row['enemy_colour']; |
|
205 | + $this->friendlyColour = $row['friendly_colour']; |
|
206 | + $this->neutralColour = $row['neutral_colour']; |
|
207 | + $this->enemyColour = $row['enemy_colour']; |
|
208 | 208 | |
209 | - $this->cssLink = $row['css_link']; |
|
210 | - $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
211 | - $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
209 | + $this->cssLink = $row['css_link']; |
|
210 | + $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
211 | + $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
212 | 212 | |
213 | 213 | $this->messageNotifications = $this->db->getObject('message_notifications'); |
214 | 214 | $this->hotkeys = $this->db->getObject('hotkeys'); |
215 | - foreach(self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
216 | - if(!isset($this->hotkeys[$hotkey])) { |
|
215 | + foreach (self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
216 | + if (!isset($this->hotkeys[$hotkey])) { |
|
217 | 217 | $this->hotkeys[$hotkey] = $binding; |
218 | 218 | } |
219 | 219 | } |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | $this->oldAccountIDs[$databaseName] = $row[$oldColumn]; |
223 | 223 | } |
224 | 224 | |
225 | - $this->referrerID = $row['referral_id']; |
|
226 | - $this->maxRankAchieved = $row['max_rank_achieved']; |
|
225 | + $this->referrerID = $row['referral_id']; |
|
226 | + $this->maxRankAchieved = $row['max_rank_achieved']; |
|
227 | 227 | |
228 | 228 | $this->hofName = $row['hof_name']; |
229 | 229 | $this->discordId = $row['discord_id']; |
@@ -233,19 +233,19 @@ discard block |
||
233 | 233 | $this->timeShort = $row['time_short']; |
234 | 234 | |
235 | 235 | $this->template = $row['template']; |
236 | - $this->colourScheme = $row['colour_scheme']; |
|
236 | + $this->colourScheme = $row['colour_scheme']; |
|
237 | 237 | |
238 | - if(empty($this->hofName)) |
|
239 | - $this->hofName=$this->login; |
|
238 | + if (empty($this->hofName)) |
|
239 | + $this->hofName = $this->login; |
|
240 | 240 | } |
241 | 241 | else { |
242 | - throw new AccountNotFoundException('Account ID '.$accountID.' does not exist!'); |
|
242 | + throw new AccountNotFoundException('Account ID ' . $accountID . ' does not exist!'); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | 246 | public function isDisabled() { |
247 | 247 | $this->db->query('SELECT * FROM account_is_closed JOIN closing_reason USING(reason_id) ' . |
248 | - 'WHERE '.$this->SQL.' LIMIT 1'); |
|
248 | + 'WHERE ' . $this->SQL . ' LIMIT 1'); |
|
249 | 249 | if ($this->db->nextRecord()) { |
250 | 250 | // get the expire time |
251 | 251 | $expireTime = $this->db->getInt('expires'); |
@@ -267,64 +267,64 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | public function update() { |
270 | - $this->db->query('UPDATE account SET email = '.$this->db->escapeString($this->email). |
|
271 | - ', validation_code = '.$this->db->escapeString($this->validation_code). |
|
272 | - ', validated = '.$this->db->escapeBoolean($this->validated). |
|
273 | - ', password = '.$this->db->escapeString($this->passwordHash). |
|
274 | - ', images = '.$this->db->escapeString($this->images). |
|
275 | - ', password_reset = '.$this->db->escapeString($this->passwordReset). |
|
276 | - ', use_ajax='.$this->db->escapeBoolean($this->useAJAX). |
|
277 | - ', mail_banned='.$this->db->escapeNumber($this->mailBanned). |
|
278 | - ', max_rank_achieved='.$this->db->escapeNumber($this->maxRankAchieved). |
|
279 | - ', default_css_enabled='.$this->db->escapeBoolean($this->defaultCSSEnabled). |
|
280 | - ', center_galaxy_map_on_player='.$this->db->escapeBoolean($this->centerGalaxyMapOnPlayer). |
|
281 | - ', message_notifications='.$this->db->escapeObject($this->messageNotifications). |
|
282 | - ', hotkeys='.$this->db->escapeObject($this->hotkeys). |
|
283 | - ', last_login = '.$this->db->escapeNumber($this->last_login). |
|
284 | - ', logging = '.$this->db->escapeBoolean($this->logging). |
|
285 | - ', time_short = ' . $this->db->escapeString($this->timeShort). |
|
286 | - ', date_short = ' . $this->db->escapeString($this->dateShort). |
|
287 | - ', discord_id = ' . $this->db->escapeString($this->discordId, true, true). |
|
288 | - ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true). |
|
289 | - ', hof_name = ' . $this->db->escapeString($this->hofName). |
|
290 | - ', colour_scheme = ' . $this->db->escapeString($this->colourScheme). |
|
291 | - ', fontsize = ' . $this->db->escapeNumber($this->fontSize). |
|
292 | - ', css_link = ' . $this->db->escapeString($this->cssLink,true,true). |
|
293 | - ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true). |
|
294 | - ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true). |
|
295 | - ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true). |
|
296 | - ' WHERE '.$this->SQL.' LIMIT 1'); |
|
270 | + $this->db->query('UPDATE account SET email = ' . $this->db->escapeString($this->email) . |
|
271 | + ', validation_code = ' . $this->db->escapeString($this->validation_code) . |
|
272 | + ', validated = ' . $this->db->escapeBoolean($this->validated) . |
|
273 | + ', password = ' . $this->db->escapeString($this->passwordHash) . |
|
274 | + ', images = ' . $this->db->escapeString($this->images) . |
|
275 | + ', password_reset = ' . $this->db->escapeString($this->passwordReset) . |
|
276 | + ', use_ajax=' . $this->db->escapeBoolean($this->useAJAX) . |
|
277 | + ', mail_banned=' . $this->db->escapeNumber($this->mailBanned) . |
|
278 | + ', max_rank_achieved=' . $this->db->escapeNumber($this->maxRankAchieved) . |
|
279 | + ', default_css_enabled=' . $this->db->escapeBoolean($this->defaultCSSEnabled) . |
|
280 | + ', center_galaxy_map_on_player=' . $this->db->escapeBoolean($this->centerGalaxyMapOnPlayer) . |
|
281 | + ', message_notifications=' . $this->db->escapeObject($this->messageNotifications) . |
|
282 | + ', hotkeys=' . $this->db->escapeObject($this->hotkeys) . |
|
283 | + ', last_login = ' . $this->db->escapeNumber($this->last_login) . |
|
284 | + ', logging = ' . $this->db->escapeBoolean($this->logging) . |
|
285 | + ', time_short = ' . $this->db->escapeString($this->timeShort) . |
|
286 | + ', date_short = ' . $this->db->escapeString($this->dateShort) . |
|
287 | + ', discord_id = ' . $this->db->escapeString($this->discordId, true, true) . |
|
288 | + ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true) . |
|
289 | + ', hof_name = ' . $this->db->escapeString($this->hofName) . |
|
290 | + ', colour_scheme = ' . $this->db->escapeString($this->colourScheme) . |
|
291 | + ', fontsize = ' . $this->db->escapeNumber($this->fontSize) . |
|
292 | + ', css_link = ' . $this->db->escapeString($this->cssLink, true, true) . |
|
293 | + ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true) . |
|
294 | + ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true) . |
|
295 | + ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true) . |
|
296 | + ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
297 | 297 | $this->hasChanged = false; |
298 | 298 | } |
299 | 299 | |
300 | 300 | public function updateIP() { |
301 | 301 | $curr_ip = getIpAddress(); |
302 | - $this->log(LOG_TYPE_LOGIN, 'logged in from '.$curr_ip); |
|
302 | + $this->log(LOG_TYPE_LOGIN, 'logged in from ' . $curr_ip); |
|
303 | 303 | |
304 | 304 | // more than 50 elements in it? |
305 | 305 | |
306 | - $this->db->query('SELECT time,ip FROM account_has_ip WHERE '.$this->SQL.' ORDER BY time ASC'); |
|
306 | + $this->db->query('SELECT time,ip FROM account_has_ip WHERE ' . $this->SQL . ' ORDER BY time ASC'); |
|
307 | 307 | if ($this->db->getNumRows() > 50 && $this->db->nextRecord()) { |
308 | 308 | $delete_time = $this->db->getInt('time'); |
309 | 309 | $delete_ip = $this->db->getField('ip'); |
310 | 310 | |
311 | 311 | $this->db->query('DELETE FROM account_has_ip |
312 | - WHERE '.$this->SQL.' AND |
|
313 | - time = '.$this->db->escapeNumber($delete_time).' AND |
|
312 | + WHERE '.$this->SQL . ' AND |
|
313 | + time = '.$this->db->escapeNumber($delete_time) . ' AND |
|
314 | 314 | ip = '.$this->db->escapeString($delete_ip)); |
315 | 315 | } |
316 | - list($fi,$se,$th,$fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
316 | + list($fi, $se, $th, $fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
317 | 317 | if ($curr_ip != 'unknown' && $curr_ip != 'unknown...' && $curr_ip != 'unknown, unknown') { |
318 | - $curr_ip = $fi.'.'.$se.'.'.$th.'.'.$fo; |
|
318 | + $curr_ip = $fi . '.' . $se . '.' . $th . '.' . $fo; |
|
319 | 319 | $host = gethostbyaddr($curr_ip); |
320 | 320 | } else $host = 'unknown'; |
321 | 321 | |
322 | 322 | // save...first make sure there isn't one for these keys (someone could double click and get error) |
323 | - $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES ('.$this->db->escapeNumber($this->account_id).', '.$this->db->escapeNumber(TIME).', '.$this->db->escapeString($curr_ip).', '.$this->db->escapeString($host).')'); |
|
323 | + $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES (' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeString($curr_ip) . ', ' . $this->db->escapeString($host) . ')'); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | public function updateLastLogin() { |
327 | - if($this->last_login == TIME) |
|
327 | + if ($this->last_login == TIME) |
|
328 | 328 | return; |
329 | 329 | $this->last_login = TIME; |
330 | 330 | $this->hasChanged = true; |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | public function setLoggingEnabled($bool) { |
339 | - if($this->logging==$bool) |
|
339 | + if ($this->logging == $bool) |
|
340 | 340 | return; |
341 | - $this->logging=$bool; |
|
341 | + $this->logging = $bool; |
|
342 | 342 | $this->hasChanged = true; |
343 | 343 | $this->update(); |
344 | 344 | } |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | public function isNPC() { |
361 | - if(!isset($this->npc)) { |
|
362 | - $this->db->query('SELECT login FROM npc_logins WHERE login = '.$this->db->escapeString($this->getLogin()).' LIMIT 1;'); |
|
361 | + if (!isset($this->npc)) { |
|
362 | + $this->db->query('SELECT login FROM npc_logins WHERE login = ' . $this->db->escapeString($this->getLogin()) . ' LIMIT 1;'); |
|
363 | 363 | $this->npc = $this->db->nextRecord(); |
364 | 364 | } |
365 | 365 | return $this->npc; |
366 | 366 | } |
367 | 367 | |
368 | 368 | protected function getHOFData() { |
369 | - if(!isset($this->HOF)) { |
|
369 | + if (!isset($this->HOF)) { |
|
370 | 370 | //Get Player HOF |
371 | 371 | $this->db->query('SELECT type,sum(amount) as amount FROM player_hof WHERE ' . $this->SQL . ' AND game_id IN (SELECT game_id FROM game WHERE ignore_stats = \'FALSE\') GROUP BY type'); |
372 | 372 | $this->HOF = array(); |
373 | - while($this->db->nextRecord()) { |
|
374 | - $hof =& $this->HOF; |
|
375 | - $typeList = explode(':',$this->db->getField('type')); |
|
376 | - foreach($typeList as $type) { |
|
377 | - if(!isset($hof[$type])) { |
|
373 | + while ($this->db->nextRecord()) { |
|
374 | + $hof = & $this->HOF; |
|
375 | + $typeList = explode(':', $this->db->getField('type')); |
|
376 | + foreach ($typeList as $type) { |
|
377 | + if (!isset($hof[$type])) { |
|
378 | 378 | $hof[$type] = array(); |
379 | 379 | } |
380 | - $hof =& $hof[$type]; |
|
380 | + $hof = & $hof[$type]; |
|
381 | 381 | } |
382 | 382 | $hof = $this->db->getFloat('amount'); |
383 | 383 | } |
@@ -386,11 +386,11 @@ discard block |
||
386 | 386 | |
387 | 387 | public function getHOF(array $typeList = null) { |
388 | 388 | $this->getHOFData(); |
389 | - if($typeList==null) |
|
389 | + if ($typeList == null) |
|
390 | 390 | return $this->HOF; |
391 | - $hof=$this->HOF; |
|
392 | - foreach($typeList as $type) { |
|
393 | - if(!isset($hof[$type])) |
|
391 | + $hof = $this->HOF; |
|
392 | + foreach ($typeList as $type) { |
|
393 | + if (!isset($hof[$type])) |
|
394 | 394 | return 0; |
395 | 395 | $hof = $hof[$type]; |
396 | 396 | } |
@@ -399,58 +399,58 @@ discard block |
||
399 | 399 | |
400 | 400 | public function getRankName() { |
401 | 401 | $rankings = Globals::getUserRanking(); |
402 | - if(isset($rankings[$this->getRank()])) |
|
402 | + if (isset($rankings[$this->getRank()])) |
|
403 | 403 | return $rankings[$this->getRank()]; |
404 | 404 | else |
405 | 405 | return end($rankings); |
406 | 406 | } |
407 | 407 | |
408 | 408 | public function getScore() { |
409 | - if(!isset($this->score)) { |
|
410 | - $score=0; |
|
411 | - foreach($this->getIndividualScores() as $each) { |
|
412 | - $score+=$each['Score']; |
|
409 | + if (!isset($this->score)) { |
|
410 | + $score = 0; |
|
411 | + foreach ($this->getIndividualScores() as $each) { |
|
412 | + $score += $each['Score']; |
|
413 | 413 | } |
414 | - $this->score=round($score); |
|
414 | + $this->score = round($score); |
|
415 | 415 | } |
416 | 416 | return $this->score; |
417 | 417 | } |
418 | 418 | |
419 | 419 | public function getIndividualScores(SmrPlayer $player = null) { |
420 | - $gameID=0; |
|
421 | - if($player!=null) |
|
420 | + $gameID = 0; |
|
421 | + if ($player != null) |
|
422 | 422 | $gameID = $player->getGameID(); |
423 | - if(!isset($this->individualScores[$gameID])) { |
|
423 | + if (!isset($this->individualScores[$gameID])) { |
|
424 | 424 | $this->individualScores[$gameID] = array(); |
425 | - foreach(self::USER_RANKINGS_SCORE as $statScore) { |
|
426 | - if($player==null) |
|
425 | + foreach (self::USER_RANKINGS_SCORE as $statScore) { |
|
426 | + if ($player == null) |
|
427 | 427 | $stat = $this->getHOF($statScore[0]); |
428 | 428 | else |
429 | 429 | $stat = $player->getHOF($statScore[0]); |
430 | - $this->individualScores[$gameID][]=array('Stat'=>$statScore[0],'Score'=>pow($stat*$statScore[1],self::USER_RANKINGS_EACH_STAT_POW)*$statScore[2]); |
|
430 | + $this->individualScores[$gameID][] = array('Stat'=>$statScore[0], 'Score'=>pow($stat * $statScore[1], self::USER_RANKINGS_EACH_STAT_POW) * $statScore[2]); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | return $this->individualScores[$gameID]; |
434 | 434 | } |
435 | 435 | |
436 | 436 | public function getRank() : int { |
437 | - $rank = ICeil(pow($this->getScore(),self::USER_RANKINGS_TOTAL_SCORE_POW)/self::USER_RANKINGS_RANK_BOUNDARY); |
|
438 | - if($rank<1) |
|
439 | - $rank=1; |
|
440 | - if($rank > $this->maxRankAchieved) |
|
437 | + $rank = ICeil(pow($this->getScore(), self::USER_RANKINGS_TOTAL_SCORE_POW) / self::USER_RANKINGS_RANK_BOUNDARY); |
|
438 | + if ($rank < 1) |
|
439 | + $rank = 1; |
|
440 | + if ($rank > $this->maxRankAchieved) |
|
441 | 441 | $this->updateMaxRankAchieved($rank); |
442 | 442 | return $rank; |
443 | 443 | } |
444 | 444 | |
445 | 445 | protected function updateMaxRankAchieved($rank) { |
446 | - if($rank <= $this->maxRankAchieved) |
|
446 | + if ($rank <= $this->maxRankAchieved) |
|
447 | 447 | throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
448 | 448 | $delta = $rank - $this->maxRankAchieved; |
449 | - if($this->hasReferrer()) { |
|
449 | + if ($this->hasReferrer()) { |
|
450 | 450 | $this->getReferrer()->increaseSmrRewardCredits($delta * CREDITS_PER_DOLLAR); |
451 | 451 | } |
452 | - $this->maxRankAchieved+=$delta; |
|
453 | - $this->hasChanged=true; |
|
452 | + $this->maxRankAchieved += $delta; |
|
453 | + $this->hasChanged = true; |
|
454 | 454 | $this->update(); |
455 | 455 | } |
456 | 456 | |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | public function hasReferrer() { |
462 | - return $this->referrerID>0; |
|
462 | + return $this->referrerID > 0; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | public function getReferrer() { |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | if ($this->isLoggingEnabled()) { |
471 | 471 | $this->db->query('INSERT INTO account_has_logs ' . |
472 | 472 | '(account_id, microtime, log_type_id, message, sector_id) ' . |
473 | - 'VALUES('.$this->db->escapeNumber($this->account_id).', '. $this->db->escapeMicrotime(MICRO_TIME) . ', '.$this->db->escapeNumber($log_type_id).', ' . $this->db->escapeString($msg) . ', '.$this->db->escapeNumber($sector_id).')'); |
|
473 | + 'VALUES(' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeMicrotime(MICRO_TIME) . ', ' . $this->db->escapeNumber($log_type_id) . ', ' . $this->db->escapeString($msg) . ', ' . $this->db->escapeNumber($sector_id) . ')'); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | 477 | protected function getSmrCreditsData() { |
478 | - if(!isset($this->credits)||!isset($this->rewardCredits)) { |
|
478 | + if (!isset($this->credits) || !isset($this->rewardCredits)) { |
|
479 | 479 | $this->credits = 0; |
480 | 480 | $this->rewardCredits = 0; |
481 | - $this->db->query('SELECT * FROM account_has_credits WHERE '.$this->SQL.' LIMIT 1'); |
|
481 | + $this->db->query('SELECT * FROM account_has_credits WHERE ' . $this->SQL . ' LIMIT 1'); |
|
482 | 482 | if ($this->db->nextRecord()) { |
483 | 483 | $this->credits = $this->db->getInt('credits_left'); |
484 | 484 | $this->rewardCredits = $this->db->getInt('reward_credits'); |
@@ -491,26 +491,26 @@ discard block |
||
491 | 491 | } |
492 | 492 | |
493 | 493 | public function decreaseTotalSmrCredits($totalCredits) { |
494 | - if($totalCredits==0) |
|
494 | + if ($totalCredits == 0) |
|
495 | 495 | return; |
496 | - if($totalCredits<0) |
|
496 | + if ($totalCredits < 0) |
|
497 | 497 | throw new Exception('You cannot use negative total credits'); |
498 | - if($totalCredits>$this->getTotalSmrCredits()) |
|
498 | + if ($totalCredits > $this->getTotalSmrCredits()) |
|
499 | 499 | throw new Exception('You do not have that many credits in total to use'); |
500 | 500 | |
501 | - $rewardCredits=$this->rewardCredits; |
|
502 | - $credits=$this->credits; |
|
503 | - $rewardCredits-=$totalCredits; |
|
504 | - if($rewardCredits<0) { |
|
505 | - $credits+=$rewardCredits; |
|
506 | - $rewardCredits=0; |
|
501 | + $rewardCredits = $this->rewardCredits; |
|
502 | + $credits = $this->credits; |
|
503 | + $rewardCredits -= $totalCredits; |
|
504 | + if ($rewardCredits < 0) { |
|
505 | + $credits += $rewardCredits; |
|
506 | + $rewardCredits = 0; |
|
507 | 507 | } |
508 | - if($this->credits==0 && $this->rewardCredits==0) |
|
509 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
508 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
509 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ',' . $this->db->escapeNumber($rewardCredits) . ')'); |
|
510 | 510 | else |
511 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
512 | - $this->credits=$credits; |
|
513 | - $this->rewardCredits=$rewardCredits; |
|
511 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ', reward_credits=' . $this->db->escapeNumber($rewardCredits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
512 | + $this->credits = $credits; |
|
513 | + $this->rewardCredits = $rewardCredits; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | public function getSmrCredits() { |
@@ -524,49 +524,49 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | public function setSmrCredits($credits) { |
527 | - if($this->getSmrCredits()==$credits) |
|
527 | + if ($this->getSmrCredits() == $credits) |
|
528 | 528 | return; |
529 | - if($this->credits==0 && $this->rewardCredits==0) |
|
530 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
529 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
530 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
531 | 531 | else |
532 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
533 | - $this->credits=$credits; |
|
532 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
533 | + $this->credits = $credits; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | public function increaseSmrCredits($credits) { |
537 | - if($credits==0) |
|
537 | + if ($credits == 0) |
|
538 | 538 | return; |
539 | - if($credits<0) |
|
539 | + if ($credits < 0) |
|
540 | 540 | throw new Exception('You cannot gain negative credits'); |
541 | - $this->setSmrCredits($this->getSmrCredits()+$credits); |
|
541 | + $this->setSmrCredits($this->getSmrCredits() + $credits); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | public function decreaseSmrCredits($credits) { |
545 | - if($credits==0) |
|
545 | + if ($credits == 0) |
|
546 | 546 | return; |
547 | - if($credits<0) |
|
547 | + if ($credits < 0) |
|
548 | 548 | throw new Exception('You cannot use negative credits'); |
549 | - if($credits>$this->getSmrCredits()) |
|
549 | + if ($credits > $this->getSmrCredits()) |
|
550 | 550 | throw new Exception('You cannot use more credits than you have'); |
551 | - $this->setSmrCredits($this->getSmrCredits()-$credits); |
|
551 | + $this->setSmrCredits($this->getSmrCredits() - $credits); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | public function setSmrRewardCredits($credits) { |
555 | - if($this->getSmrRewardCredits()==$credits) |
|
555 | + if ($this->getSmrRewardCredits() == $credits) |
|
556 | 556 | return; |
557 | - if($this->credits==0 && $this->rewardCredits==0) |
|
558 | - $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
557 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
558 | + $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
559 | 559 | else |
560 | - $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
561 | - $this->rewardCredits=$credits; |
|
560 | + $this->db->query('UPDATE account_has_credits SET reward_credits=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
561 | + $this->rewardCredits = $credits; |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | public function increaseSmrRewardCredits($credits) { |
565 | - if($credits==0) |
|
565 | + if ($credits == 0) |
|
566 | 566 | return; |
567 | - if($credits<0) |
|
567 | + if ($credits < 0) |
|
568 | 568 | throw new Exception('You cannot gain negative reward credits'); |
569 | - $this->setSmrRewardCredits($this->getSmrRewardCredits()+$credits); |
|
569 | + $this->setSmrRewardCredits($this->getSmrRewardCredits() + $credits); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | public function sendMessageToBox($boxTypeID, $message) { |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | self::doMessageSendingToBox($this->getAccountID(), $boxTypeID, $message); |
575 | 575 | } |
576 | 576 | |
577 | - public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID=0) { |
|
577 | + public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID = 0) { |
|
578 | 578 | $db = new SmrMySqlDatabase(); |
579 | 579 | // send him the message |
580 | 580 | $db->query('INSERT INTO message_boxes |
@@ -597,13 +597,13 @@ discard block |
||
597 | 597 | } |
598 | 598 | |
599 | 599 | public function getOldAccountID($dbName) { |
600 | - return isset($this->oldAccountIDs[$dbName])?$this->oldAccountIDs[$dbName]:0; |
|
600 | + return isset($this->oldAccountIDs[$dbName]) ? $this->oldAccountIDs[$dbName] : 0; |
|
601 | 601 | } |
602 | 602 | |
603 | - public function hasOldAccountID($dbName=false) { |
|
604 | - if($dbName===false) |
|
605 | - return count($this->getOldAccountIDs())!=0; |
|
606 | - return $this->getOldAccountID($dbName)!=0; |
|
603 | + public function hasOldAccountID($dbName = false) { |
|
604 | + if ($dbName === false) |
|
605 | + return count($this->getOldAccountIDs()) != 0; |
|
606 | + return $this->getOldAccountID($dbName) != 0; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | public function getLogin() { |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | } |
616 | 616 | |
617 | 617 | public function setEmail($email) { |
618 | - if($this->email==$email) { |
|
618 | + if ($this->email == $email) { |
|
619 | 619 | return; |
620 | 620 | } |
621 | 621 | $this->email = $email; |
@@ -632,14 +632,14 @@ discard block |
||
632 | 632 | |
633 | 633 | // check if the host got a MX or at least an A entry |
634 | 634 | if (!checkdnsrr($host, 'MX') && !checkdnsrr($host, 'A')) { |
635 | - create_error('This is not a valid email address! The domain '.$host.' does not exist.'); |
|
635 | + create_error('This is not a valid email address! The domain ' . $host . ' does not exist.'); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | if (strstr($email, ' ')) { |
639 | 639 | create_error('The email is invalid! It cannot contain any spaces.'); |
640 | 640 | } |
641 | 641 | |
642 | - $this->db->query('SELECT 1 FROM account WHERE email = '.$this->db->escapeString($email).' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
642 | + $this->db->query('SELECT 1 FROM account WHERE email = ' . $this->db->escapeString($email) . ' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
643 | 643 | if ($this->db->getNumRows() > 0) { |
644 | 644 | create_error('This email address is already registered.'); |
645 | 645 | } |
@@ -650,12 +650,12 @@ discard block |
||
650 | 650 | |
651 | 651 | // remember when we sent validation code |
652 | 652 | $this->db->query('REPLACE INTO notification (notification_type, account_id, time) |
653 | - VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()).', ' . $this->db->escapeNumber(TIME) . ')'); |
|
653 | + VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ')'); |
|
654 | 654 | |
655 | 655 | $emailMessage = |
656 | - 'You changed your email address registered with SMR and need to revalidate now!'.EOL.EOL. |
|
657 | - ' Your new validation code is: '.$this->getValidationCode().EOL.EOL. |
|
658 | - 'The Space Merchant Realms server is on the web at '.URL; |
|
656 | + 'You changed your email address registered with SMR and need to revalidate now!' . EOL . EOL . |
|
657 | + ' Your new validation code is: ' . $this->getValidationCode() . EOL . EOL . |
|
658 | + 'The Space Merchant Realms server is on the web at ' . URL; |
|
659 | 659 | |
660 | 660 | $mail = setupMailer(); |
661 | 661 | $mail->Subject = 'Your validation code!'; |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | } |
682 | 682 | |
683 | 683 | public function setFontSize($size) { |
684 | - if($this->fontSize==$size) |
|
684 | + if ($this->fontSize == $size) |
|
685 | 685 | return; |
686 | 686 | $this->fontSize = $size; |
687 | 687 | $this->hasChanged = true; |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | |
696 | 696 | // sets the extra CSS file linked in preferences |
697 | 697 | public function setCssLink($link) { |
698 | - if($this->cssLink==$link) |
|
698 | + if ($this->cssLink == $link) |
|
699 | 699 | return; |
700 | 700 | $this->cssLink = $link; |
701 | 701 | $this->hasChanged = true; |
@@ -707,11 +707,11 @@ discard block |
||
707 | 707 | } |
708 | 708 | |
709 | 709 | public function setTemplate($template) { |
710 | - if($this->template==$template) |
|
710 | + if ($this->template == $template) |
|
711 | 711 | return; |
712 | - if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) |
|
713 | - throw new Exception('Template not allowed: '.$template); |
|
714 | - $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE '.$this->SQL.' LIMIT 1'); |
|
712 | + if (!in_array($template, array_keys(Globals::getAvailableTemplates()))) |
|
713 | + throw new Exception('Template not allowed: ' . $template); |
|
714 | + $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
715 | 715 | $this->template = $template; |
716 | 716 | $colourSchemes = Globals::getAvailableColourSchemes($template); |
717 | 717 | $this->setColourScheme($colourSchemes[0]); |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | public function setColourScheme($colourScheme) { |
725 | - if($this->colourScheme==$colourScheme) |
|
725 | + if ($this->colourScheme == $colourScheme) |
|
726 | 726 | return; |
727 | - if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | - throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
727 | + if (!in_array($colourScheme, array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | + throw new Exception('Colour scheme not allowed: ' . $colourScheme); |
|
729 | 729 | $this->colourScheme = $colourScheme; |
730 | 730 | $this->hasChanged = true; |
731 | 731 | $this->update(); |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | * The Hall Of Fame name is not html-escaped in the database, so to display |
746 | 746 | * it correctly we must escape html entities. |
747 | 747 | */ |
748 | - public function getHofDisplayName($linked=false) { |
|
748 | + public function getHofDisplayName($linked = false) { |
|
749 | 749 | $hofDisplayName = htmlspecialchars($this->getHofName()); |
750 | 750 | if ($linked) { |
751 | 751 | return '<a href="' . $this->getPersonalHofHREF() . '">' . $hofDisplayName . '</a>'; |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | } |
760 | 760 | |
761 | 761 | public function setHofName($name) { |
762 | - if($this->hofName==$name) |
|
762 | + if ($this->hofName == $name) |
|
763 | 763 | return; |
764 | 764 | $this->hofName = $name; |
765 | 765 | $this->hasChanged = true; |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | } |
772 | 772 | |
773 | 773 | public function setIrcNick($nick) { |
774 | - if($this->ircNick==$nick) |
|
774 | + if ($this->ircNick == $nick) |
|
775 | 775 | return; |
776 | 776 | $this->ircNick = $nick; |
777 | 777 | $this->hasChanged = true; |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | } |
793 | 793 | |
794 | 794 | public function getReferralLink() { |
795 | - return URL . '/login_create.php?ref='.$this->getAccountID(); |
|
795 | + return URL . '/login_create.php?ref=' . $this->getAccountID(); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | public function getShortDateFormat() { |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | } |
801 | 801 | |
802 | 802 | public function setShortDateFormat($format) { |
803 | - if($this->dateShort==$format) |
|
803 | + if ($this->dateShort == $format) |
|
804 | 804 | return; |
805 | 805 | $this->dateShort = $format; |
806 | 806 | $this->hasChanged = true; |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | } |
813 | 813 | |
814 | 814 | public function setShortTimeFormat($format) { |
815 | - if($this->timeShort==$format) |
|
815 | + if ($this->timeShort == $format) |
|
816 | 816 | return; |
817 | 817 | $this->timeShort = $format; |
818 | 818 | $this->hasChanged = true; |
@@ -824,15 +824,15 @@ discard block |
||
824 | 824 | } |
825 | 825 | |
826 | 826 | protected function setValidationCode($code) { |
827 | - if($this->validation_code == $code) |
|
827 | + if ($this->validation_code == $code) |
|
828 | 828 | return; |
829 | - $this->validation_code=$code; |
|
830 | - $this->hasChanged=true; |
|
829 | + $this->validation_code = $code; |
|
830 | + $this->hasChanged = true; |
|
831 | 831 | $this->update(); |
832 | 832 | } |
833 | 833 | |
834 | 834 | public function setValidated($bool) { |
835 | - if($this->validated == $bool) |
|
835 | + if ($this->validated == $bool) |
|
836 | 836 | return; |
837 | 837 | $this->validated = $bool; |
838 | 838 | $this->hasChanged = true; |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | } |
845 | 845 | |
846 | 846 | public function isLoggedIn() { |
847 | - $this->db->query('SELECT 1 FROM active_session WHERE account_id = '.$this->db->escapeNumber($this->getAccountID()).' LIMIT 1'); |
|
847 | + $this->db->query('SELECT 1 FROM active_session WHERE account_id = ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
848 | 848 | return $this->db->nextRecord(); |
849 | 849 | } |
850 | 850 | |
@@ -885,15 +885,15 @@ discard block |
||
885 | 885 | $this->update(); |
886 | 886 | } |
887 | 887 | |
888 | - public function addAuthMethod($loginType,$authKey) { |
|
889 | - $this->db->query('SELECT account_id FROM account_auth WHERE login_type='.$this->db->escapeString($loginType).' AND auth_key = '.$this->db->escapeString($authKey).';'); |
|
890 | - if($this->db->nextRecord()) { |
|
891 | - if($this->db->getInt('account_id')!=$this->getAccountID()) { |
|
888 | + public function addAuthMethod($loginType, $authKey) { |
|
889 | + $this->db->query('SELECT account_id FROM account_auth WHERE login_type=' . $this->db->escapeString($loginType) . ' AND auth_key = ' . $this->db->escapeString($authKey) . ';'); |
|
890 | + if ($this->db->nextRecord()) { |
|
891 | + if ($this->db->getInt('account_id') != $this->getAccountID()) { |
|
892 | 892 | throw new Exception('Another account already uses this form of auth.'); |
893 | 893 | } |
894 | 894 | return true; |
895 | 895 | } |
896 | - $this->db->query('INSERT INTO account_auth values ('.$this->db->escapeNumber($this->getAccountID()).','.$this->db->escapeString($loginType).','.$this->db->escapeString($authKey).');'); |
|
896 | + $this->db->query('INSERT INTO account_auth values (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeString($loginType) . ',' . $this->db->escapeString($authKey) . ');'); |
|
897 | 897 | return true; |
898 | 898 | } |
899 | 899 | |
@@ -906,10 +906,10 @@ discard block |
||
906 | 906 | } |
907 | 907 | |
908 | 908 | protected function setPasswordReset($passwordReset) { |
909 | - if($this->passwordReset == $passwordReset) |
|
909 | + if ($this->passwordReset == $passwordReset) |
|
910 | 910 | return; |
911 | - $this->passwordReset=$passwordReset; |
|
912 | - $this->hasChanged=true; |
|
911 | + $this->passwordReset = $passwordReset; |
|
912 | + $this->hasChanged = true; |
|
913 | 913 | $this->update(); |
914 | 914 | } |
915 | 915 | |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | } |
919 | 919 | |
920 | 920 | public function setDisplayShipImages($yesNo) { |
921 | - if($this->images == $yesNo) |
|
921 | + if ($this->images == $yesNo) |
|
922 | 922 | return; |
923 | 923 | $this->images = $yesNo; |
924 | 924 | $this->hasChanged = true; |
@@ -930,10 +930,10 @@ discard block |
||
930 | 930 | } |
931 | 931 | |
932 | 932 | public function setUseAJAX($bool) { |
933 | - if($this->useAJAX == $bool) |
|
933 | + if ($this->useAJAX == $bool) |
|
934 | 934 | return; |
935 | - $this->useAJAX=$bool; |
|
936 | - $this->hasChanged=true; |
|
935 | + $this->useAJAX = $bool; |
|
936 | + $this->hasChanged = true; |
|
937 | 937 | $this->update(); |
938 | 938 | } |
939 | 939 | |
@@ -942,16 +942,16 @@ discard block |
||
942 | 942 | } |
943 | 943 | |
944 | 944 | public function setDefaultCSSEnabled($bool) { |
945 | - if($this->defaultCSSEnabled == $bool) |
|
945 | + if ($this->defaultCSSEnabled == $bool) |
|
946 | 946 | return; |
947 | - $this->defaultCSSEnabled=$bool; |
|
948 | - $this->hasChanged=true; |
|
947 | + $this->defaultCSSEnabled = $bool; |
|
948 | + $this->hasChanged = true; |
|
949 | 949 | $this->update(); |
950 | 950 | } |
951 | 951 | |
952 | 952 | public function getHotkeys($hotkeyType = false) { |
953 | - if($hotkeyType!==false) { |
|
954 | - if(isset($this->hotkeys[$hotkeyType])) { |
|
953 | + if ($hotkeyType !== false) { |
|
954 | + if (isset($this->hotkeys[$hotkeyType])) { |
|
955 | 955 | return $this->hotkeys[$hotkeyType]; |
956 | 956 | } |
957 | 957 | else { |
@@ -961,42 +961,42 @@ discard block |
||
961 | 961 | return $this->hotkeys; |
962 | 962 | } |
963 | 963 | |
964 | - public function setHotkey($hotkeyType,$binding) { |
|
965 | - if($this->getHotkeys($hotkeyType) == $binding) |
|
964 | + public function setHotkey($hotkeyType, $binding) { |
|
965 | + if ($this->getHotkeys($hotkeyType) == $binding) |
|
966 | 966 | return; |
967 | 967 | $this->hotkeys[$hotkeyType] = $binding; |
968 | - $this->hasChanged=true; |
|
968 | + $this->hasChanged = true; |
|
969 | 969 | $this->update(); |
970 | 970 | } |
971 | 971 | |
972 | 972 | public function isReceivingMessageNotifications($messageTypeID) { |
973 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]>0:false; |
|
973 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] > 0 : false; |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | public function getMessageNotifications($messageTypeID) { |
977 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]:0; |
|
977 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] : 0; |
|
978 | 978 | } |
979 | 979 | |
980 | - public function setMessageNotifications($messageTypeID,$num) { |
|
981 | - if($this->getMessageNotifications($messageTypeID) == $num) |
|
980 | + public function setMessageNotifications($messageTypeID, $num) { |
|
981 | + if ($this->getMessageNotifications($messageTypeID) == $num) |
|
982 | 982 | return; |
983 | - $this->messageNotifications[$messageTypeID]=$num; |
|
984 | - $this->hasChanged=true; |
|
983 | + $this->messageNotifications[$messageTypeID] = $num; |
|
984 | + $this->hasChanged = true; |
|
985 | 985 | $this->update(); |
986 | 986 | } |
987 | 987 | |
988 | - public function increaseMessageNotifications($messageTypeID,$num) { |
|
989 | - if($num==0) |
|
988 | + public function increaseMessageNotifications($messageTypeID, $num) { |
|
989 | + if ($num == 0) |
|
990 | 990 | return; |
991 | - if($num<0) |
|
991 | + if ($num < 0) |
|
992 | 992 | throw new Exception('You cannot increase by a negative amount'); |
993 | 993 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) + $num); |
994 | 994 | } |
995 | 995 | |
996 | - public function decreaseMessageNotifications($messageTypeID,$num) { |
|
997 | - if($num==0) |
|
996 | + public function decreaseMessageNotifications($messageTypeID, $num) { |
|
997 | + if ($num == 0) |
|
998 | 998 | return; |
999 | - if($num<0) |
|
999 | + if ($num < 0) |
|
1000 | 1000 | throw new Exception('You cannot decrease by a negative amount'); |
1001 | 1001 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) - $num); |
1002 | 1002 | } |
@@ -1006,10 +1006,10 @@ discard block |
||
1006 | 1006 | } |
1007 | 1007 | |
1008 | 1008 | public function setCenterGalaxyMapOnPlayer($bool) { |
1009 | - if($this->centerGalaxyMapOnPlayer == $bool) |
|
1009 | + if ($this->centerGalaxyMapOnPlayer == $bool) |
|
1010 | 1010 | return; |
1011 | - $this->centerGalaxyMapOnPlayer=$bool; |
|
1012 | - $this->hasChanged=true; |
|
1011 | + $this->centerGalaxyMapOnPlayer = $bool; |
|
1012 | + $this->hasChanged = true; |
|
1013 | 1013 | $this->update(); |
1014 | 1014 | } |
1015 | 1015 | |
@@ -1018,26 +1018,26 @@ discard block |
||
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | public function isMailBanned() { |
1021 | - return $this->mailBanned>TIME; |
|
1021 | + return $this->mailBanned > TIME; |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | public function setMailBanned($time) { |
1025 | - if($this->mailBanned == $time) |
|
1025 | + if ($this->mailBanned == $time) |
|
1026 | 1026 | return; |
1027 | - $this->mailBanned=$time; |
|
1028 | - $this->hasChanged=true; |
|
1027 | + $this->mailBanned = $time; |
|
1028 | + $this->hasChanged = true; |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | public function increaseMailBanned($increaseTime) { |
1032 | - $time = max(TIME,$this->getMailBanned()); |
|
1033 | - $this->setMailBanned($time+$increaseTime); |
|
1032 | + $time = max(TIME, $this->getMailBanned()); |
|
1033 | + $this->setMailBanned($time + $increaseTime); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | public function getPermissions() { |
1037 | - if(!isset($this->permissions)) { |
|
1037 | + if (!isset($this->permissions)) { |
|
1038 | 1038 | $this->permissions = array(); |
1039 | 1039 | $this->db->query('SELECT permission_id FROM account_has_permission WHERE ' . $this->SQL); |
1040 | - while($this->db->nextRecord()) { |
|
1040 | + while ($this->db->nextRecord()) { |
|
1041 | 1041 | $this->permissions[$this->db->getInt('permission_id')] = true; |
1042 | 1042 | } |
1043 | 1043 | } |
@@ -1046,28 +1046,28 @@ discard block |
||
1046 | 1046 | |
1047 | 1047 | public function hasPermission($permissionID = false) { |
1048 | 1048 | $permissions = $this->getPermissions(); |
1049 | - if($permissionID === false) { |
|
1049 | + if ($permissionID === false) { |
|
1050 | 1050 | return count($permissions) > 0; |
1051 | 1051 | } |
1052 | 1052 | return isset($permissions[$permissionID]) ? $permissions[$permissionID] : false; |
1053 | 1053 | } |
1054 | 1054 | |
1055 | 1055 | public function getPoints() { |
1056 | - if(!isset($this->points)) { |
|
1057 | - $this->points=0; |
|
1056 | + if (!isset($this->points)) { |
|
1057 | + $this->points = 0; |
|
1058 | 1058 | $this->db->lockTable('account_has_points'); |
1059 | - $this->db->query('SELECT * FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1060 | - if($this->db->nextRecord()) { |
|
1061 | - $this->points=$this->db->getInt('points'); |
|
1059 | + $this->db->query('SELECT * FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1060 | + if ($this->db->nextRecord()) { |
|
1061 | + $this->points = $this->db->getInt('points'); |
|
1062 | 1062 | $lastUpdate = $this->db->getInt('last_update'); |
1063 | 1063 | //we are gonna check for reducing points... |
1064 | - if($this->points>0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1065 | - $removePoints=0; |
|
1066 | - while($lastUpdate < TIME - (7 * 86400)) { |
|
1064 | + if ($this->points > 0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1065 | + $removePoints = 0; |
|
1066 | + while ($lastUpdate < TIME - (7 * 86400)) { |
|
1067 | 1067 | $removePoints++; |
1068 | 1068 | $lastUpdate += (7 * 86400); |
1069 | 1069 | } |
1070 | - $this->removePoints($removePoints,$lastUpdate); |
|
1070 | + $this->removePoints($removePoints, $lastUpdate); |
|
1071 | 1071 | } |
1072 | 1072 | } |
1073 | 1073 | $this->db->unlock(); |
@@ -1075,30 +1075,30 @@ discard block |
||
1075 | 1075 | return $this->points; |
1076 | 1076 | } |
1077 | 1077 | |
1078 | - public function setPoints($numPoints,$lastUpdate=false) { |
|
1079 | - $numPoints = max($numPoints,0); |
|
1080 | - if($this->getPoints()==$numPoints) |
|
1078 | + public function setPoints($numPoints, $lastUpdate = false) { |
|
1079 | + $numPoints = max($numPoints, 0); |
|
1080 | + if ($this->getPoints() == $numPoints) |
|
1081 | 1081 | return; |
1082 | - if ($this->points==0) |
|
1083 | - $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES ('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($numPoints).', '.$this->db->escapeNumber($lastUpdate?$lastUpdate:TIME).')'); |
|
1084 | - else if($numPoints<=0) |
|
1085 | - $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1082 | + if ($this->points == 0) |
|
1083 | + $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($numPoints) . ', ' . $this->db->escapeNumber($lastUpdate ? $lastUpdate : TIME) . ')'); |
|
1084 | + else if ($numPoints <= 0) |
|
1085 | + $this->db->query('DELETE FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1086 | 1086 | else |
1087 | - $this->db->query('UPDATE account_has_points SET points = '.$this->db->escapeNumber($numPoints).($lastUpdate ? ', last_update = '.$this->db->escapeNumber(TIME) : '').' WHERE '.$this->SQL.' LIMIT 1'); |
|
1088 | - $this->points=$numPoints; |
|
1087 | + $this->db->query('UPDATE account_has_points SET points = ' . $this->db->escapeNumber($numPoints) . ($lastUpdate ? ', last_update = ' . $this->db->escapeNumber(TIME) : '') . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1088 | + $this->points = $numPoints; |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | - public function removePoints($numPoints,$lastUpdate=false) { |
|
1092 | - if($numPoints>0) |
|
1093 | - $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1091 | + public function removePoints($numPoints, $lastUpdate = false) { |
|
1092 | + if ($numPoints > 0) |
|
1093 | + $this->setPoints($this->getPoints() - $numPoints, $lastUpdate); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | - public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) { |
|
1096 | + public function addPoints($numPoints, SmrAccount $admin, $reasonID, $suspicion) { |
|
1097 | 1097 | //do we have points |
1098 | - $this->setPoints($this->getPoints() + $numPoints,TIME); |
|
1098 | + $this->setPoints($this->getPoints() + $numPoints, TIME); |
|
1099 | 1099 | $totalPoints = $this->getPoints(); |
1100 | 1100 | if ($totalPoints < 10) |
1101 | - return false;//leave scripts its only a warning |
|
1101 | + return false; //leave scripts its only a warning |
|
1102 | 1102 | elseif ($totalPoints < 20) |
1103 | 1103 | $days = 2; |
1104 | 1104 | elseif ($totalPoints < 30) |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | elseif ($totalPoints < 50) |
1107 | 1107 | $days = 7; |
1108 | 1108 | elseif ($totalPoints < 75) |
1109 | - $days = 15 ; |
|
1109 | + $days = 15; |
|
1110 | 1110 | elseif ($totalPoints < 100) |
1111 | 1111 | $days = 30; |
1112 | 1112 | elseif ($totalPoints < 125) |
@@ -1120,13 +1120,13 @@ discard block |
||
1120 | 1120 | else |
1121 | 1121 | $days = 0; //Forever/indefinite |
1122 | 1122 | |
1123 | - if($days==0) { |
|
1123 | + if ($days == 0) { |
|
1124 | 1124 | $expireTime = 0; |
1125 | 1125 | } |
1126 | 1126 | else { |
1127 | 1127 | $expireTime = TIME + $days * 86400; |
1128 | 1128 | } |
1129 | - $this->banAccount($expireTime,$admin,$reasonID,$suspicion); |
|
1129 | + $this->banAccount($expireTime, $admin, $reasonID, $suspicion); |
|
1130 | 1130 | |
1131 | 1131 | return $days; |
1132 | 1132 | } |
@@ -1153,12 +1153,12 @@ discard block |
||
1153 | 1153 | $this->hasChanged = true; |
1154 | 1154 | } |
1155 | 1155 | |
1156 | - public function banAccount($expireTime,SmrAccount $admin,$reasonID,$suspicion,$removeExceptions = false) { |
|
1156 | + public function banAccount($expireTime, SmrAccount $admin, $reasonID, $suspicion, $removeExceptions = false) { |
|
1157 | 1157 | $this->db->query('REPLACE INTO account_is_closed |
1158 | 1158 | (account_id, reason_id, suspicion, expires) |
1159 | - VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($reasonID).', '.$this->db->escapeString($suspicion).', '.$this->db->escapeNumber($expireTime).')'); |
|
1159 | + VALUES('.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($reasonID) . ', ' . $this->db->escapeString($suspicion) . ', ' . $this->db->escapeNumber($expireTime) . ')'); |
|
1160 | 1160 | $this->db->lockTable('active_session'); |
1161 | - $this->db->query('DELETE FROM active_session WHERE '.$this->SQL.' LIMIT 1'); |
|
1161 | + $this->db->query('DELETE FROM active_session WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1162 | 1162 | $this->db->unlock(); |
1163 | 1163 | |
1164 | 1164 | $this->db->query('INSERT INTO account_has_closing_history |
@@ -1178,38 +1178,38 @@ discard block |
||
1178 | 1178 | $player->update(); |
1179 | 1179 | } |
1180 | 1180 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account closed by ' . $admin->getLogin() . '.'); |
1181 | - if($removeExceptions!==false) |
|
1181 | + if ($removeExceptions !== false) |
|
1182 | 1182 | $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
1183 | 1183 | } |
1184 | 1184 | |
1185 | - public function unbanAccount(SmrAccount $admin = null,$currException=false) { |
|
1185 | + public function unbanAccount(SmrAccount $admin = null, $currException = false) { |
|
1186 | 1186 | $adminID = 0; |
1187 | - if($admin!==null) |
|
1187 | + if ($admin !== null) |
|
1188 | 1188 | $adminID = $admin->getAccountID(); |
1189 | 1189 | $this->db->query('DELETE FROM account_is_closed WHERE ' . $this->SQL . ' LIMIT 1'); |
1190 | 1190 | $this->db->query('INSERT INTO account_has_closing_history |
1191 | 1191 | (account_id, time, admin_id, action) |
1192 | 1192 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($adminID) . ', ' . $this->db->escapeString('Opened') . ')'); |
1193 | 1193 | $this->db->query('UPDATE player SET last_turn_update = GREATEST(' . $this->db->escapeNumber(TIME) . ', last_turn_update) WHERE ' . $this->SQL); |
1194 | - if($admin!==null) |
|
1194 | + if ($admin !== null) |
|
1195 | 1195 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
1196 | 1196 | else |
1197 | 1197 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
1198 | - if($currException!==false) |
|
1198 | + if ($currException !== false) |
|
1199 | 1199 | $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
1200 | 1200 | VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeString($currException) . ')'); |
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | public function getToggleAJAXHREF() { |
1204 | 1204 | global $var; |
1205 | - return SmrSession::getNewHREF(create_container('skeleton.php','toggle_processing.php',array('toggle'=>'AJAX','referrer'=>$var['body']))); |
|
1205 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'toggle_processing.php', array('toggle'=>'AJAX', 'referrer'=>$var['body']))); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | public function getUserRankingHREF() { |
1209 | - return SmrSession::getNewHREF(create_container('skeleton.php','rankings_view.php')); |
|
1209 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'rankings_view.php')); |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | public function getPersonalHofHREF() { |
1213 | - return SmrSession::getNewHREF(create_container('skeleton.php','hall_of_fame_player_detail.php',array('account_id' => $this->getAccountID()))); |
|
1213 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'hall_of_fame_player_detail.php', array('account_id' => $this->getAccountID()))); |
|
1214 | 1214 | } |
1215 | 1215 | } |
@@ -99,8 +99,9 @@ discard block |
||
99 | 99 | if (empty($login)) { return null; } |
100 | 100 | $db = new SmrMySqlDatabase(); |
101 | 101 | $db->query('SELECT account_id FROM account WHERE login = '.$db->escapeString($login).' LIMIT 1'); |
102 | - if($db->nextRecord()) |
|
103 | - return self::getAccount($db->getInt('account_id'), $forceUpdate); |
|
102 | + if($db->nextRecord()) { |
|
103 | + return self::getAccount($db->getInt('account_id'), $forceUpdate); |
|
104 | + } |
|
104 | 105 | $return = null; |
105 | 106 | return $return; |
106 | 107 | } |
@@ -235,10 +236,10 @@ discard block |
||
235 | 236 | $this->template = $row['template']; |
236 | 237 | $this->colourScheme = $row['colour_scheme']; |
237 | 238 | |
238 | - if(empty($this->hofName)) |
|
239 | - $this->hofName=$this->login; |
|
240 | - } |
|
241 | - else { |
|
239 | + if(empty($this->hofName)) { |
|
240 | + $this->hofName=$this->login; |
|
241 | + } |
|
242 | + } else { |
|
242 | 243 | throw new AccountNotFoundException('Account ID '.$accountID.' does not exist!'); |
243 | 244 | } |
244 | 245 | } |
@@ -260,8 +261,7 @@ discard block |
||
260 | 261 | 'Reason' => $this->db->getField('reason'), |
261 | 262 | 'ReasonID' => $this->db->getInt('reason_id') |
262 | 263 | ); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | } |
@@ -317,15 +317,18 @@ discard block |
||
317 | 317 | if ($curr_ip != 'unknown' && $curr_ip != 'unknown...' && $curr_ip != 'unknown, unknown') { |
318 | 318 | $curr_ip = $fi.'.'.$se.'.'.$th.'.'.$fo; |
319 | 319 | $host = gethostbyaddr($curr_ip); |
320 | - } else $host = 'unknown'; |
|
320 | + } else { |
|
321 | + $host = 'unknown'; |
|
322 | + } |
|
321 | 323 | |
322 | 324 | // save...first make sure there isn't one for these keys (someone could double click and get error) |
323 | 325 | $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES ('.$this->db->escapeNumber($this->account_id).', '.$this->db->escapeNumber(TIME).', '.$this->db->escapeString($curr_ip).', '.$this->db->escapeString($host).')'); |
324 | 326 | } |
325 | 327 | |
326 | 328 | public function updateLastLogin() { |
327 | - if($this->last_login == TIME) |
|
328 | - return; |
|
329 | + if($this->last_login == TIME) { |
|
330 | + return; |
|
331 | + } |
|
329 | 332 | $this->last_login = TIME; |
330 | 333 | $this->hasChanged = true; |
331 | 334 | $this->update(); |
@@ -336,8 +339,9 @@ discard block |
||
336 | 339 | } |
337 | 340 | |
338 | 341 | public function setLoggingEnabled($bool) { |
339 | - if($this->logging==$bool) |
|
340 | - return; |
|
342 | + if($this->logging==$bool) { |
|
343 | + return; |
|
344 | + } |
|
341 | 345 | $this->logging=$bool; |
342 | 346 | $this->hasChanged = true; |
343 | 347 | $this->update(); |
@@ -386,12 +390,14 @@ discard block |
||
386 | 390 | |
387 | 391 | public function getHOF(array $typeList = null) { |
388 | 392 | $this->getHOFData(); |
389 | - if($typeList==null) |
|
390 | - return $this->HOF; |
|
393 | + if($typeList==null) { |
|
394 | + return $this->HOF; |
|
395 | + } |
|
391 | 396 | $hof=$this->HOF; |
392 | 397 | foreach($typeList as $type) { |
393 | - if(!isset($hof[$type])) |
|
394 | - return 0; |
|
398 | + if(!isset($hof[$type])) { |
|
399 | + return 0; |
|
400 | + } |
|
395 | 401 | $hof = $hof[$type]; |
396 | 402 | } |
397 | 403 | return $hof; |
@@ -399,10 +405,11 @@ discard block |
||
399 | 405 | |
400 | 406 | public function getRankName() { |
401 | 407 | $rankings = Globals::getUserRanking(); |
402 | - if(isset($rankings[$this->getRank()])) |
|
403 | - return $rankings[$this->getRank()]; |
|
404 | - else |
|
405 | - return end($rankings); |
|
408 | + if(isset($rankings[$this->getRank()])) { |
|
409 | + return $rankings[$this->getRank()]; |
|
410 | + } else { |
|
411 | + return end($rankings); |
|
412 | + } |
|
406 | 413 | } |
407 | 414 | |
408 | 415 | public function getScore() { |
@@ -418,15 +425,17 @@ discard block |
||
418 | 425 | |
419 | 426 | public function getIndividualScores(SmrPlayer $player = null) { |
420 | 427 | $gameID=0; |
421 | - if($player!=null) |
|
422 | - $gameID = $player->getGameID(); |
|
428 | + if($player!=null) { |
|
429 | + $gameID = $player->getGameID(); |
|
430 | + } |
|
423 | 431 | if(!isset($this->individualScores[$gameID])) { |
424 | 432 | $this->individualScores[$gameID] = array(); |
425 | 433 | foreach(self::USER_RANKINGS_SCORE as $statScore) { |
426 | - if($player==null) |
|
427 | - $stat = $this->getHOF($statScore[0]); |
|
428 | - else |
|
429 | - $stat = $player->getHOF($statScore[0]); |
|
434 | + if($player==null) { |
|
435 | + $stat = $this->getHOF($statScore[0]); |
|
436 | + } else { |
|
437 | + $stat = $player->getHOF($statScore[0]); |
|
438 | + } |
|
430 | 439 | $this->individualScores[$gameID][]=array('Stat'=>$statScore[0],'Score'=>pow($stat*$statScore[1],self::USER_RANKINGS_EACH_STAT_POW)*$statScore[2]); |
431 | 440 | } |
432 | 441 | } |
@@ -435,16 +444,19 @@ discard block |
||
435 | 444 | |
436 | 445 | public function getRank() : int { |
437 | 446 | $rank = ICeil(pow($this->getScore(),self::USER_RANKINGS_TOTAL_SCORE_POW)/self::USER_RANKINGS_RANK_BOUNDARY); |
438 | - if($rank<1) |
|
439 | - $rank=1; |
|
440 | - if($rank > $this->maxRankAchieved) |
|
441 | - $this->updateMaxRankAchieved($rank); |
|
447 | + if($rank<1) { |
|
448 | + $rank=1; |
|
449 | + } |
|
450 | + if($rank > $this->maxRankAchieved) { |
|
451 | + $this->updateMaxRankAchieved($rank); |
|
452 | + } |
|
442 | 453 | return $rank; |
443 | 454 | } |
444 | 455 | |
445 | 456 | protected function updateMaxRankAchieved($rank) { |
446 | - if($rank <= $this->maxRankAchieved) |
|
447 | - throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
|
457 | + if($rank <= $this->maxRankAchieved) { |
|
458 | + throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
|
459 | + } |
|
448 | 460 | $delta = $rank - $this->maxRankAchieved; |
449 | 461 | if($this->hasReferrer()) { |
450 | 462 | $this->getReferrer()->increaseSmrRewardCredits($delta * CREDITS_PER_DOLLAR); |
@@ -491,12 +503,15 @@ discard block |
||
491 | 503 | } |
492 | 504 | |
493 | 505 | public function decreaseTotalSmrCredits($totalCredits) { |
494 | - if($totalCredits==0) |
|
495 | - return; |
|
496 | - if($totalCredits<0) |
|
497 | - throw new Exception('You cannot use negative total credits'); |
|
498 | - if($totalCredits>$this->getTotalSmrCredits()) |
|
499 | - throw new Exception('You do not have that many credits in total to use'); |
|
506 | + if($totalCredits==0) { |
|
507 | + return; |
|
508 | + } |
|
509 | + if($totalCredits<0) { |
|
510 | + throw new Exception('You cannot use negative total credits'); |
|
511 | + } |
|
512 | + if($totalCredits>$this->getTotalSmrCredits()) { |
|
513 | + throw new Exception('You do not have that many credits in total to use'); |
|
514 | + } |
|
500 | 515 | |
501 | 516 | $rewardCredits=$this->rewardCredits; |
502 | 517 | $credits=$this->credits; |
@@ -505,10 +520,11 @@ discard block |
||
505 | 520 | $credits+=$rewardCredits; |
506 | 521 | $rewardCredits=0; |
507 | 522 | } |
508 | - if($this->credits==0 && $this->rewardCredits==0) |
|
509 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
510 | - else |
|
511 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
523 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
524 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
525 | + } else { |
|
526 | + $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
527 | + } |
|
512 | 528 | $this->credits=$credits; |
513 | 529 | $this->rewardCredits=$rewardCredits; |
514 | 530 | } |
@@ -524,48 +540,59 @@ discard block |
||
524 | 540 | } |
525 | 541 | |
526 | 542 | public function setSmrCredits($credits) { |
527 | - if($this->getSmrCredits()==$credits) |
|
528 | - return; |
|
529 | - if($this->credits==0 && $this->rewardCredits==0) |
|
530 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
531 | - else |
|
532 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
543 | + if($this->getSmrCredits()==$credits) { |
|
544 | + return; |
|
545 | + } |
|
546 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
547 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
548 | + } else { |
|
549 | + $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
550 | + } |
|
533 | 551 | $this->credits=$credits; |
534 | 552 | } |
535 | 553 | |
536 | 554 | public function increaseSmrCredits($credits) { |
537 | - if($credits==0) |
|
538 | - return; |
|
539 | - if($credits<0) |
|
540 | - throw new Exception('You cannot gain negative credits'); |
|
555 | + if($credits==0) { |
|
556 | + return; |
|
557 | + } |
|
558 | + if($credits<0) { |
|
559 | + throw new Exception('You cannot gain negative credits'); |
|
560 | + } |
|
541 | 561 | $this->setSmrCredits($this->getSmrCredits()+$credits); |
542 | 562 | } |
543 | 563 | |
544 | 564 | public function decreaseSmrCredits($credits) { |
545 | - if($credits==0) |
|
546 | - return; |
|
547 | - if($credits<0) |
|
548 | - throw new Exception('You cannot use negative credits'); |
|
549 | - if($credits>$this->getSmrCredits()) |
|
550 | - throw new Exception('You cannot use more credits than you have'); |
|
565 | + if($credits==0) { |
|
566 | + return; |
|
567 | + } |
|
568 | + if($credits<0) { |
|
569 | + throw new Exception('You cannot use negative credits'); |
|
570 | + } |
|
571 | + if($credits>$this->getSmrCredits()) { |
|
572 | + throw new Exception('You cannot use more credits than you have'); |
|
573 | + } |
|
551 | 574 | $this->setSmrCredits($this->getSmrCredits()-$credits); |
552 | 575 | } |
553 | 576 | |
554 | 577 | public function setSmrRewardCredits($credits) { |
555 | - if($this->getSmrRewardCredits()==$credits) |
|
556 | - return; |
|
557 | - if($this->credits==0 && $this->rewardCredits==0) |
|
558 | - $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
559 | - else |
|
560 | - $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
578 | + if($this->getSmrRewardCredits()==$credits) { |
|
579 | + return; |
|
580 | + } |
|
581 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
582 | + $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
583 | + } else { |
|
584 | + $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
585 | + } |
|
561 | 586 | $this->rewardCredits=$credits; |
562 | 587 | } |
563 | 588 | |
564 | 589 | public function increaseSmrRewardCredits($credits) { |
565 | - if($credits==0) |
|
566 | - return; |
|
567 | - if($credits<0) |
|
568 | - throw new Exception('You cannot gain negative reward credits'); |
|
590 | + if($credits==0) { |
|
591 | + return; |
|
592 | + } |
|
593 | + if($credits<0) { |
|
594 | + throw new Exception('You cannot gain negative reward credits'); |
|
595 | + } |
|
569 | 596 | $this->setSmrRewardCredits($this->getSmrRewardCredits()+$credits); |
570 | 597 | } |
571 | 598 | |
@@ -601,8 +628,9 @@ discard block |
||
601 | 628 | } |
602 | 629 | |
603 | 630 | public function hasOldAccountID($dbName=false) { |
604 | - if($dbName===false) |
|
605 | - return count($this->getOldAccountIDs())!=0; |
|
631 | + if($dbName===false) { |
|
632 | + return count($this->getOldAccountIDs())!=0; |
|
633 | + } |
|
606 | 634 | return $this->getOldAccountID($dbName)!=0; |
607 | 635 | } |
608 | 636 | |
@@ -681,8 +709,9 @@ discard block |
||
681 | 709 | } |
682 | 710 | |
683 | 711 | public function setFontSize($size) { |
684 | - if($this->fontSize==$size) |
|
685 | - return; |
|
712 | + if($this->fontSize==$size) { |
|
713 | + return; |
|
714 | + } |
|
686 | 715 | $this->fontSize = $size; |
687 | 716 | $this->hasChanged = true; |
688 | 717 | $this->update(); |
@@ -695,8 +724,9 @@ discard block |
||
695 | 724 | |
696 | 725 | // sets the extra CSS file linked in preferences |
697 | 726 | public function setCssLink($link) { |
698 | - if($this->cssLink==$link) |
|
699 | - return; |
|
727 | + if($this->cssLink==$link) { |
|
728 | + return; |
|
729 | + } |
|
700 | 730 | $this->cssLink = $link; |
701 | 731 | $this->hasChanged = true; |
702 | 732 | $this->update(); |
@@ -707,10 +737,12 @@ discard block |
||
707 | 737 | } |
708 | 738 | |
709 | 739 | public function setTemplate($template) { |
710 | - if($this->template==$template) |
|
711 | - return; |
|
712 | - if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) |
|
713 | - throw new Exception('Template not allowed: '.$template); |
|
740 | + if($this->template==$template) { |
|
741 | + return; |
|
742 | + } |
|
743 | + if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) { |
|
744 | + throw new Exception('Template not allowed: '.$template); |
|
745 | + } |
|
714 | 746 | $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE '.$this->SQL.' LIMIT 1'); |
715 | 747 | $this->template = $template; |
716 | 748 | $colourSchemes = Globals::getAvailableColourSchemes($template); |
@@ -722,10 +754,12 @@ discard block |
||
722 | 754 | } |
723 | 755 | |
724 | 756 | public function setColourScheme($colourScheme) { |
725 | - if($this->colourScheme==$colourScheme) |
|
726 | - return; |
|
727 | - if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | - throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
757 | + if($this->colourScheme==$colourScheme) { |
|
758 | + return; |
|
759 | + } |
|
760 | + if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) { |
|
761 | + throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
762 | + } |
|
729 | 763 | $this->colourScheme = $colourScheme; |
730 | 764 | $this->hasChanged = true; |
731 | 765 | $this->update(); |
@@ -759,8 +793,9 @@ discard block |
||
759 | 793 | } |
760 | 794 | |
761 | 795 | public function setHofName($name) { |
762 | - if($this->hofName==$name) |
|
763 | - return; |
|
796 | + if($this->hofName==$name) { |
|
797 | + return; |
|
798 | + } |
|
764 | 799 | $this->hofName = $name; |
765 | 800 | $this->hasChanged = true; |
766 | 801 | $this->update(); |
@@ -771,8 +806,9 @@ discard block |
||
771 | 806 | } |
772 | 807 | |
773 | 808 | public function setIrcNick($nick) { |
774 | - if($this->ircNick==$nick) |
|
775 | - return; |
|
809 | + if($this->ircNick==$nick) { |
|
810 | + return; |
|
811 | + } |
|
776 | 812 | $this->ircNick = $nick; |
777 | 813 | $this->hasChanged = true; |
778 | 814 | $this->update(); |
@@ -800,8 +836,9 @@ discard block |
||
800 | 836 | } |
801 | 837 | |
802 | 838 | public function setShortDateFormat($format) { |
803 | - if($this->dateShort==$format) |
|
804 | - return; |
|
839 | + if($this->dateShort==$format) { |
|
840 | + return; |
|
841 | + } |
|
805 | 842 | $this->dateShort = $format; |
806 | 843 | $this->hasChanged = true; |
807 | 844 | $this->update(); |
@@ -812,8 +849,9 @@ discard block |
||
812 | 849 | } |
813 | 850 | |
814 | 851 | public function setShortTimeFormat($format) { |
815 | - if($this->timeShort==$format) |
|
816 | - return; |
|
852 | + if($this->timeShort==$format) { |
|
853 | + return; |
|
854 | + } |
|
817 | 855 | $this->timeShort = $format; |
818 | 856 | $this->hasChanged = true; |
819 | 857 | $this->update(); |
@@ -824,16 +862,18 @@ discard block |
||
824 | 862 | } |
825 | 863 | |
826 | 864 | protected function setValidationCode($code) { |
827 | - if($this->validation_code == $code) |
|
828 | - return; |
|
865 | + if($this->validation_code == $code) { |
|
866 | + return; |
|
867 | + } |
|
829 | 868 | $this->validation_code=$code; |
830 | 869 | $this->hasChanged=true; |
831 | 870 | $this->update(); |
832 | 871 | } |
833 | 872 | |
834 | 873 | public function setValidated($bool) { |
835 | - if($this->validated == $bool) |
|
836 | - return; |
|
874 | + if($this->validated == $bool) { |
|
875 | + return; |
|
876 | + } |
|
837 | 877 | $this->validated = $bool; |
838 | 878 | $this->hasChanged = true; |
839 | 879 | $this->update(); |
@@ -906,8 +946,9 @@ discard block |
||
906 | 946 | } |
907 | 947 | |
908 | 948 | protected function setPasswordReset($passwordReset) { |
909 | - if($this->passwordReset == $passwordReset) |
|
910 | - return; |
|
949 | + if($this->passwordReset == $passwordReset) { |
|
950 | + return; |
|
951 | + } |
|
911 | 952 | $this->passwordReset=$passwordReset; |
912 | 953 | $this->hasChanged=true; |
913 | 954 | $this->update(); |
@@ -918,8 +959,9 @@ discard block |
||
918 | 959 | } |
919 | 960 | |
920 | 961 | public function setDisplayShipImages($yesNo) { |
921 | - if($this->images == $yesNo) |
|
922 | - return; |
|
962 | + if($this->images == $yesNo) { |
|
963 | + return; |
|
964 | + } |
|
923 | 965 | $this->images = $yesNo; |
924 | 966 | $this->hasChanged = true; |
925 | 967 | $this->update(); |
@@ -930,8 +972,9 @@ discard block |
||
930 | 972 | } |
931 | 973 | |
932 | 974 | public function setUseAJAX($bool) { |
933 | - if($this->useAJAX == $bool) |
|
934 | - return; |
|
975 | + if($this->useAJAX == $bool) { |
|
976 | + return; |
|
977 | + } |
|
935 | 978 | $this->useAJAX=$bool; |
936 | 979 | $this->hasChanged=true; |
937 | 980 | $this->update(); |
@@ -942,8 +985,9 @@ discard block |
||
942 | 985 | } |
943 | 986 | |
944 | 987 | public function setDefaultCSSEnabled($bool) { |
945 | - if($this->defaultCSSEnabled == $bool) |
|
946 | - return; |
|
988 | + if($this->defaultCSSEnabled == $bool) { |
|
989 | + return; |
|
990 | + } |
|
947 | 991 | $this->defaultCSSEnabled=$bool; |
948 | 992 | $this->hasChanged=true; |
949 | 993 | $this->update(); |
@@ -953,8 +997,7 @@ discard block |
||
953 | 997 | if($hotkeyType!==false) { |
954 | 998 | if(isset($this->hotkeys[$hotkeyType])) { |
955 | 999 | return $this->hotkeys[$hotkeyType]; |
956 | - } |
|
957 | - else { |
|
1000 | + } else { |
|
958 | 1001 | return array(); |
959 | 1002 | } |
960 | 1003 | } |
@@ -962,8 +1005,9 @@ discard block |
||
962 | 1005 | } |
963 | 1006 | |
964 | 1007 | public function setHotkey($hotkeyType,$binding) { |
965 | - if($this->getHotkeys($hotkeyType) == $binding) |
|
966 | - return; |
|
1008 | + if($this->getHotkeys($hotkeyType) == $binding) { |
|
1009 | + return; |
|
1010 | + } |
|
967 | 1011 | $this->hotkeys[$hotkeyType] = $binding; |
968 | 1012 | $this->hasChanged=true; |
969 | 1013 | $this->update(); |
@@ -978,26 +1022,31 @@ discard block |
||
978 | 1022 | } |
979 | 1023 | |
980 | 1024 | public function setMessageNotifications($messageTypeID,$num) { |
981 | - if($this->getMessageNotifications($messageTypeID) == $num) |
|
982 | - return; |
|
1025 | + if($this->getMessageNotifications($messageTypeID) == $num) { |
|
1026 | + return; |
|
1027 | + } |
|
983 | 1028 | $this->messageNotifications[$messageTypeID]=$num; |
984 | 1029 | $this->hasChanged=true; |
985 | 1030 | $this->update(); |
986 | 1031 | } |
987 | 1032 | |
988 | 1033 | public function increaseMessageNotifications($messageTypeID,$num) { |
989 | - if($num==0) |
|
990 | - return; |
|
991 | - if($num<0) |
|
992 | - throw new Exception('You cannot increase by a negative amount'); |
|
1034 | + if($num==0) { |
|
1035 | + return; |
|
1036 | + } |
|
1037 | + if($num<0) { |
|
1038 | + throw new Exception('You cannot increase by a negative amount'); |
|
1039 | + } |
|
993 | 1040 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) + $num); |
994 | 1041 | } |
995 | 1042 | |
996 | 1043 | public function decreaseMessageNotifications($messageTypeID,$num) { |
997 | - if($num==0) |
|
998 | - return; |
|
999 | - if($num<0) |
|
1000 | - throw new Exception('You cannot decrease by a negative amount'); |
|
1044 | + if($num==0) { |
|
1045 | + return; |
|
1046 | + } |
|
1047 | + if($num<0) { |
|
1048 | + throw new Exception('You cannot decrease by a negative amount'); |
|
1049 | + } |
|
1001 | 1050 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) - $num); |
1002 | 1051 | } |
1003 | 1052 | |
@@ -1006,8 +1055,9 @@ discard block |
||
1006 | 1055 | } |
1007 | 1056 | |
1008 | 1057 | public function setCenterGalaxyMapOnPlayer($bool) { |
1009 | - if($this->centerGalaxyMapOnPlayer == $bool) |
|
1010 | - return; |
|
1058 | + if($this->centerGalaxyMapOnPlayer == $bool) { |
|
1059 | + return; |
|
1060 | + } |
|
1011 | 1061 | $this->centerGalaxyMapOnPlayer=$bool; |
1012 | 1062 | $this->hasChanged=true; |
1013 | 1063 | $this->update(); |
@@ -1022,8 +1072,9 @@ discard block |
||
1022 | 1072 | } |
1023 | 1073 | |
1024 | 1074 | public function setMailBanned($time) { |
1025 | - if($this->mailBanned == $time) |
|
1026 | - return; |
|
1075 | + if($this->mailBanned == $time) { |
|
1076 | + return; |
|
1077 | + } |
|
1027 | 1078 | $this->mailBanned=$time; |
1028 | 1079 | $this->hasChanged=true; |
1029 | 1080 | } |
@@ -1077,53 +1128,59 @@ discard block |
||
1077 | 1128 | |
1078 | 1129 | public function setPoints($numPoints,$lastUpdate=false) { |
1079 | 1130 | $numPoints = max($numPoints,0); |
1080 | - if($this->getPoints()==$numPoints) |
|
1081 | - return; |
|
1082 | - if ($this->points==0) |
|
1083 | - $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES ('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($numPoints).', '.$this->db->escapeNumber($lastUpdate?$lastUpdate:TIME).')'); |
|
1084 | - else if($numPoints<=0) |
|
1085 | - $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1086 | - else |
|
1087 | - $this->db->query('UPDATE account_has_points SET points = '.$this->db->escapeNumber($numPoints).($lastUpdate ? ', last_update = '.$this->db->escapeNumber(TIME) : '').' WHERE '.$this->SQL.' LIMIT 1'); |
|
1131 | + if($this->getPoints()==$numPoints) { |
|
1132 | + return; |
|
1133 | + } |
|
1134 | + if ($this->points==0) { |
|
1135 | + $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES ('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($numPoints).', '.$this->db->escapeNumber($lastUpdate?$lastUpdate:TIME).')'); |
|
1136 | + } else if($numPoints<=0) { |
|
1137 | + $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1138 | + } else { |
|
1139 | + $this->db->query('UPDATE account_has_points SET points = '.$this->db->escapeNumber($numPoints).($lastUpdate ? ', last_update = '.$this->db->escapeNumber(TIME) : '').' WHERE '.$this->SQL.' LIMIT 1'); |
|
1140 | + } |
|
1088 | 1141 | $this->points=$numPoints; |
1089 | 1142 | } |
1090 | 1143 | |
1091 | 1144 | public function removePoints($numPoints,$lastUpdate=false) { |
1092 | - if($numPoints>0) |
|
1093 | - $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1145 | + if($numPoints>0) { |
|
1146 | + $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1147 | + } |
|
1094 | 1148 | } |
1095 | 1149 | |
1096 | 1150 | public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) { |
1097 | 1151 | //do we have points |
1098 | 1152 | $this->setPoints($this->getPoints() + $numPoints,TIME); |
1099 | 1153 | $totalPoints = $this->getPoints(); |
1100 | - if ($totalPoints < 10) |
|
1101 | - return false;//leave scripts its only a warning |
|
1102 | - elseif ($totalPoints < 20) |
|
1103 | - $days = 2; |
|
1104 | - elseif ($totalPoints < 30) |
|
1105 | - $days = 4; |
|
1106 | - elseif ($totalPoints < 50) |
|
1107 | - $days = 7; |
|
1108 | - elseif ($totalPoints < 75) |
|
1109 | - $days = 15 ; |
|
1110 | - elseif ($totalPoints < 100) |
|
1111 | - $days = 30; |
|
1112 | - elseif ($totalPoints < 125) |
|
1113 | - $days = 60; |
|
1114 | - elseif ($totalPoints < 150) |
|
1115 | - $days = 120; |
|
1116 | - elseif ($totalPoints < 175) |
|
1117 | - $days = 240; |
|
1118 | - elseif ($totalPoints < 200) |
|
1119 | - $days = 480; |
|
1120 | - else |
|
1121 | - $days = 0; //Forever/indefinite |
|
1154 | + if ($totalPoints < 10) { |
|
1155 | + return false; |
|
1156 | + } |
|
1157 | + //leave scripts its only a warning |
|
1158 | + elseif ($totalPoints < 20) { |
|
1159 | + $days = 2; |
|
1160 | + } elseif ($totalPoints < 30) { |
|
1161 | + $days = 4; |
|
1162 | + } elseif ($totalPoints < 50) { |
|
1163 | + $days = 7; |
|
1164 | + } elseif ($totalPoints < 75) { |
|
1165 | + $days = 15 ; |
|
1166 | + } elseif ($totalPoints < 100) { |
|
1167 | + $days = 30; |
|
1168 | + } elseif ($totalPoints < 125) { |
|
1169 | + $days = 60; |
|
1170 | + } elseif ($totalPoints < 150) { |
|
1171 | + $days = 120; |
|
1172 | + } elseif ($totalPoints < 175) { |
|
1173 | + $days = 240; |
|
1174 | + } elseif ($totalPoints < 200) { |
|
1175 | + $days = 480; |
|
1176 | + } else { |
|
1177 | + $days = 0; |
|
1178 | + } |
|
1179 | + //Forever/indefinite |
|
1122 | 1180 | |
1123 | 1181 | if($days==0) { |
1124 | 1182 | $expireTime = 0; |
1125 | - } |
|
1126 | - else { |
|
1183 | + } else { |
|
1127 | 1184 | $expireTime = TIME + $days * 86400; |
1128 | 1185 | } |
1129 | 1186 | $this->banAccount($expireTime,$admin,$reasonID,$suspicion); |
@@ -1178,26 +1235,30 @@ discard block |
||
1178 | 1235 | $player->update(); |
1179 | 1236 | } |
1180 | 1237 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account closed by ' . $admin->getLogin() . '.'); |
1181 | - if($removeExceptions!==false) |
|
1182 | - $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
|
1238 | + if($removeExceptions!==false) { |
|
1239 | + $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
|
1240 | + } |
|
1183 | 1241 | } |
1184 | 1242 | |
1185 | 1243 | public function unbanAccount(SmrAccount $admin = null,$currException=false) { |
1186 | 1244 | $adminID = 0; |
1187 | - if($admin!==null) |
|
1188 | - $adminID = $admin->getAccountID(); |
|
1245 | + if($admin!==null) { |
|
1246 | + $adminID = $admin->getAccountID(); |
|
1247 | + } |
|
1189 | 1248 | $this->db->query('DELETE FROM account_is_closed WHERE ' . $this->SQL . ' LIMIT 1'); |
1190 | 1249 | $this->db->query('INSERT INTO account_has_closing_history |
1191 | 1250 | (account_id, time, admin_id, action) |
1192 | 1251 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($adminID) . ', ' . $this->db->escapeString('Opened') . ')'); |
1193 | 1252 | $this->db->query('UPDATE player SET last_turn_update = GREATEST(' . $this->db->escapeNumber(TIME) . ', last_turn_update) WHERE ' . $this->SQL); |
1194 | - if($admin!==null) |
|
1195 | - $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
|
1196 | - else |
|
1197 | - $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
|
1198 | - if($currException!==false) |
|
1199 | - $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
|
1253 | + if($admin!==null) { |
|
1254 | + $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
|
1255 | + } else { |
|
1256 | + $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
|
1257 | + } |
|
1258 | + if($currException!==false) { |
|
1259 | + $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
|
1200 | 1260 | VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeString($currException) . ')'); |
1261 | + } |
|
1201 | 1262 | } |
1202 | 1263 | |
1203 | 1264 | public function getToggleAJAXHREF() { |
@@ -12,17 +12,19 @@ discard block |
||
12 | 12 | |
13 | 13 | |
14 | 14 | protected static function initialiseDatabase() { |
15 | - if (self::$db == null) |
|
16 | - self::$db = new SmrMySqlDatabase(); |
|
15 | + if (self::$db == null) { |
|
16 | + self::$db = new SmrMySqlDatabase(); |
|
17 | + } |
|
17 | 18 | } |
18 | 19 | |
19 | 20 | public static function getWeapon($weaponTypeID, $forceUpdate = false, $db = null) { |
20 | 21 | if ($forceUpdate || !isset(self::$CACHE_WEAPONS[$weaponTypeID])) { |
21 | 22 | $w = new SmrWeapon($weaponTypeID, $db); |
22 | - if ($w->exists()) |
|
23 | - self::$CACHE_WEAPONS[$weaponTypeID] = $w; |
|
24 | - else |
|
25 | - self::$CACHE_WEAPONS[$weaponTypeID] = false; |
|
23 | + if ($w->exists()) { |
|
24 | + self::$CACHE_WEAPONS[$weaponTypeID] = $w; |
|
25 | + } else { |
|
26 | + self::$CACHE_WEAPONS[$weaponTypeID] = false; |
|
27 | + } |
|
26 | 28 | } |
27 | 29 | return self::$CACHE_WEAPONS[$weaponTypeID]; |
28 | 30 | } |
@@ -151,8 +153,9 @@ discard block |
||
151 | 153 | $weaponShip = $weaponPlayer->getShip(); |
152 | 154 | $targetShip = $targetPlayer->getShip(); |
153 | 155 | $mrDiff = $targetShip->getMR() - $weaponShip->getMR(); |
154 | - if ($mrDiff > 0) |
|
155 | - $modifiedAccuracy -= $this->getBaseAccuracy() * ($mrDiff / MR_FACTOR) / 100; |
|
156 | + if ($mrDiff > 0) { |
|
157 | + $modifiedAccuracy -= $this->getBaseAccuracy() * ($mrDiff / MR_FACTOR) / 100; |
|
158 | + } |
|
156 | 159 | |
157 | 160 | return $modifiedAccuracy; |
158 | 161 | } |
@@ -190,22 +193,28 @@ discard block |
||
190 | 193 | } |
191 | 194 | |
192 | 195 | public function &getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
193 | - if (!$this->canShootForces()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
196 | + if (!$this->canShootForces()) { |
|
197 | + // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
194 | 198 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
199 | + } |
|
195 | 200 | $damage =& $this->getModifiedDamage(); |
196 | 201 | return $damage; |
197 | 202 | } |
198 | 203 | |
199 | 204 | public function &getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
200 | - if (!$this->canShootPorts()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
205 | + if (!$this->canShootPorts()) { |
|
206 | + // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
201 | 207 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
208 | + } |
|
202 | 209 | $damage =& $this->getModifiedDamage(); |
203 | 210 | return $damage; |
204 | 211 | } |
205 | 212 | |
206 | 213 | public function &getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet) { |
207 | - if (!$this->canShootPlanets()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
214 | + if (!$this->canShootPlanets()) { |
|
215 | + // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
208 | 216 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
217 | + } |
|
209 | 218 | $damage =& $this->getModifiedDamage(); |
210 | 219 | |
211 | 220 | $planetMod = self::PLANET_DAMAGE_MOD; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $this->cargo_left = $this->getCargoHolds(); |
18 | 18 | } |
19 | 19 | protected function doFullUNO() { |
20 | - foreach($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
20 | + foreach ($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
21 | 21 | $this->hardware[$hardwareTypeID] = $max; |
22 | 22 | $this->oldHardware[$hardwareTypeID] = $max; |
23 | 23 | } |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function getIllusionShip() { |
50 | - if(!isset($this->illusionShip)) { |
|
51 | - $this->illusionShip=false; |
|
50 | + if (!isset($this->illusionShip)) { |
|
51 | + $this->illusionShip = false; |
|
52 | 52 | } |
53 | 53 | return $this->illusionShip; |
54 | 54 | } |
@@ -58,20 +58,20 @@ discard block |
||
58 | 58 | $db = new SmrMySqlDatabase(); |
59 | 59 | $db->query('REPLACE INTO cached_dummys ' . |
60 | 60 | '(type, id, info) ' . |
61 | - 'VALUES (\'DummyShip\', '.$db->escapeString($this->getPlayer()->getPlayerName()).', '.$db->escapeString($cache).')'); |
|
61 | + 'VALUES (\'DummyShip\', ' . $db->escapeString($this->getPlayer()->getPlayerName()) . ', ' . $db->escapeString($cache) . ')'); |
|
62 | 62 | unserialize($cache); |
63 | 63 | } |
64 | 64 | |
65 | 65 | public static function getCachedDummyShip(AbstractSmrPlayer $player) { |
66 | - if(!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
66 | + if (!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
67 | 67 | $db = new SmrMySqlDatabase(); |
68 | 68 | $db->query('SELECT info FROM cached_dummys |
69 | 69 | WHERE type = \'DummyShip\' |
70 | 70 | AND id = ' . $db->escapeString($player->getPlayerName()) . ' LIMIT 1'); |
71 | - if($db->nextRecord()) { |
|
71 | + if ($db->nextRecord()) { |
|
72 | 72 | $return = unserialize($db->getField('info')); |
73 | 73 | $return->regenerate($player); |
74 | - self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] =& $return; |
|
74 | + self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = & $return; |
|
75 | 75 | } |
76 | 76 | else { |
77 | 77 | self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = new DummyShip($player); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $db->query('SELECT id FROM cached_dummys |
86 | 86 | WHERE type = \'DummyShip\''); |
87 | 87 | $dummyNames = array(); |
88 | - while($db->nextRecord()) { |
|
88 | + while ($db->nextRecord()) { |
|
89 | 89 | $dummyNames[] = $db->getField('id'); |
90 | 90 | } |
91 | 91 | return $dummyNames; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | |
96 | 96 | public function __sleep() { |
97 | - return array('gameID','weapons'); |
|
97 | + return array('gameID', 'weapons'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | public function __wakeup() { |
@@ -34,10 +34,11 @@ discard block |
||
34 | 34 | // determine ship |
35 | 35 | $db = new SmrMySqlDatabase(); |
36 | 36 | $db->query('SELECT * FROM ship_type WHERE ship_type_id = ' . $db->escapeNumber($shipTypeID) . ' LIMIT 1'); //TODO add game type id |
37 | - if ($db->nextRecord()) |
|
38 | - self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID] = self::buildBaseShip($db); |
|
39 | - else |
|
40 | - self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID] = false; |
|
37 | + if ($db->nextRecord()) { |
|
38 | + self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID] = self::buildBaseShip($db); |
|
39 | + } else { |
|
40 | + self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID] = false; |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | return self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID]; |
43 | 44 | } |
@@ -168,10 +169,11 @@ discard block |
||
168 | 169 | |
169 | 170 | public function checkForExcessHardware() { |
170 | 171 | //check hardware to see if anything needs to be removed |
171 | - if (is_array($hardware = $this->getHardware())) |
|
172 | - foreach ($hardware as $hardwareTypeID => $amount) { |
|
172 | + if (is_array($hardware = $this->getHardware())) { |
|
173 | + foreach ($hardware as $hardwareTypeID => $amount) { |
|
173 | 174 | if ($amount > ($max = $this->getMaxHardware($hardwareTypeID))) { |
174 | 175 | $this->setHardware($hardwareTypeID, $max, true); |
176 | + } |
|
175 | 177 | } |
176 | 178 | } |
177 | 179 | } |
@@ -188,9 +190,10 @@ discard block |
||
188 | 190 | |
189 | 191 | public function getPowerUsed() { |
190 | 192 | $power = 0; |
191 | - if ($this->getNumWeapons() > 0) |
|
192 | - foreach ($this->weapons as $weapon) |
|
193 | + if ($this->getNumWeapons() > 0) { |
|
194 | + foreach ($this->weapons as $weapon) |
|
193 | 195 | $power += $weapon->getPowerLevel(); |
196 | + } |
|
194 | 197 | return $power; |
195 | 198 | } |
196 | 199 | |
@@ -211,17 +214,19 @@ discard block |
||
211 | 214 | } |
212 | 215 | |
213 | 216 | public function getDisplayAttackRating(AbstractSmrPlayer $player) { |
214 | - if ($this->hasActiveIllusion()) |
|
215 | - return $this->getIllusionAttack(); |
|
216 | - else |
|
217 | - return $this->getAttackRating(); |
|
217 | + if ($this->hasActiveIllusion()) { |
|
218 | + return $this->getIllusionAttack(); |
|
219 | + } else { |
|
220 | + return $this->getAttackRating(); |
|
221 | + } |
|
218 | 222 | } |
219 | 223 | |
220 | 224 | public function getDisplayDefenseRating() { |
221 | - if ($this->hasActiveIllusion()) |
|
222 | - return $this->getIllusionDefense(); |
|
223 | - else |
|
224 | - return $this->getDefenseRating(); |
|
225 | + if ($this->hasActiveIllusion()) { |
|
226 | + return $this->getIllusionDefense(); |
|
227 | + } else { |
|
228 | + return $this->getDefenseRating(); |
|
229 | + } |
|
225 | 230 | } |
226 | 231 | |
227 | 232 | public function getAttackRating() : int { |
@@ -267,8 +272,7 @@ discard block |
||
267 | 272 | if ($replacement < 0) { |
268 | 273 | // Shift everything up by one and put the selected weapon at the bottom |
269 | 274 | array_push($this->weapons, array_shift($this->weapons)); |
270 | - } |
|
271 | - else { |
|
275 | + } else { |
|
272 | 276 | // Swap the selected weapon with the one above it |
273 | 277 | $temp = $this->weapons[$replacement]; |
274 | 278 | $this->weapons[$replacement] = $this->weapons[$orderID]; |
@@ -282,8 +286,7 @@ discard block |
||
282 | 286 | if ($replacement >= count($this->weapons)) { |
283 | 287 | // Shift everything down by one and put the selected weapon at the top |
284 | 288 | array_unshift($this->weapons, array_pop($this->weapons)); |
285 | - } |
|
286 | - else { |
|
289 | + } else { |
|
287 | 290 | // Swap the selected weapon with the one below it |
288 | 291 | $temp = $this->weapons[$replacement]; |
289 | 292 | $this->weapons[$replacement] = $this->weapons[$orderID]; |
@@ -342,8 +345,7 @@ discard block |
||
342 | 345 | $this->setArmour(150, true); |
343 | 346 | $this->setCargoHolds(40); |
344 | 347 | $this->setShipTypeID(SHIP_TYPE_NEWBIE_MERCHANT_VESSEL); |
345 | - } |
|
346 | - else { |
|
348 | + } else { |
|
347 | 349 | $this->setShields(50, true); |
348 | 350 | $this->setArmour(50, true); |
349 | 351 | $this->setCargoHolds(5); |
@@ -363,8 +365,9 @@ discard block |
||
363 | 365 | |
364 | 366 | |
365 | 367 | public function hasActiveIllusion() { |
366 | - if (!$this->hasIllusion()) |
|
367 | - return false; |
|
368 | + if (!$this->hasIllusion()) { |
|
369 | + return false; |
|
370 | + } |
|
368 | 371 | return $this->getIllusionShip() !== false; |
369 | 372 | |
370 | 373 | } |
@@ -498,14 +501,16 @@ discard block |
||
498 | 501 | } |
499 | 502 | |
500 | 503 | public function getHardware($hardwareTypeID = false) { |
501 | - if ($hardwareTypeID === false) |
|
502 | - return $this->hardware; |
|
504 | + if ($hardwareTypeID === false) { |
|
505 | + return $this->hardware; |
|
506 | + } |
|
503 | 507 | return isset($this->hardware[$hardwareTypeID]) ? $this->hardware[$hardwareTypeID] : 0; |
504 | 508 | } |
505 | 509 | |
506 | 510 | public function setHardware($hardwareTypeID, $amount) { |
507 | - if ($this->getHardware($hardwareTypeID) == $amount) |
|
508 | - return; |
|
511 | + if ($this->getHardware($hardwareTypeID) == $amount) { |
|
512 | + return; |
|
513 | + } |
|
509 | 514 | $this->hardware[$hardwareTypeID] = $amount; |
510 | 515 | $this->hasChangedHardware[$hardwareTypeID] = true; |
511 | 516 | } |
@@ -515,14 +520,16 @@ discard block |
||
515 | 520 | } |
516 | 521 | |
517 | 522 | public function getOldHardware($hardwareTypeID = false) { |
518 | - if ($hardwareTypeID === false) |
|
519 | - return $this->oldHardware; |
|
523 | + if ($hardwareTypeID === false) { |
|
524 | + return $this->oldHardware; |
|
525 | + } |
|
520 | 526 | return isset($this->oldHardware[$hardwareTypeID]) ? $this->oldHardware[$hardwareTypeID] : 0; |
521 | 527 | } |
522 | 528 | |
523 | 529 | public function setOldHardware($hardwareTypeID, $amount) { |
524 | - if ($this->getOldHardware($hardwareTypeID) == $amount) |
|
525 | - return; |
|
530 | + if ($this->getOldHardware($hardwareTypeID) == $amount) { |
|
531 | + return; |
|
532 | + } |
|
526 | 533 | $this->oldHardware[$hardwareTypeID] = $amount; |
527 | 534 | $this->hasChangedHardware[$hardwareTypeID] = true; |
528 | 535 | } |
@@ -532,8 +539,9 @@ discard block |
||
532 | 539 | } |
533 | 540 | |
534 | 541 | public function getMaxHardware($hardwareTypeID = false) { |
535 | - if ($hardwareTypeID === false) |
|
536 | - return $this->baseShip['MaxHardware']; |
|
542 | + if ($hardwareTypeID === false) { |
|
543 | + return $this->baseShip['MaxHardware']; |
|
544 | + } |
|
537 | 545 | return $this->baseShip['MaxHardware'][$hardwareTypeID]; |
538 | 546 | } |
539 | 547 | |
@@ -542,8 +550,9 @@ discard block |
||
542 | 550 | } |
543 | 551 | |
544 | 552 | public function setShields($amount, $updateOldAmount = false) { |
545 | - if ($updateOldAmount && !$this->hasLostShields()) |
|
546 | - $this->setOldHardware(HARDWARE_SHIELDS, $amount); |
|
553 | + if ($updateOldAmount && !$this->hasLostShields()) { |
|
554 | + $this->setOldHardware(HARDWARE_SHIELDS, $amount); |
|
555 | + } |
|
547 | 556 | $this->setHardware(HARDWARE_SHIELDS, $amount); |
548 | 557 | } |
549 | 558 | |
@@ -584,8 +593,9 @@ discard block |
||
584 | 593 | } |
585 | 594 | |
586 | 595 | public function setArmour($amount, $updateOldAmount = false) { |
587 | - if ($updateOldAmount && !$this->hasLostArmour()) |
|
588 | - $this->setOldHardware(HARDWARE_ARMOUR, $amount); |
|
596 | + if ($updateOldAmount && !$this->hasLostArmour()) { |
|
597 | + $this->setOldHardware(HARDWARE_ARMOUR, $amount); |
|
598 | + } |
|
589 | 599 | $this->setHardware(HARDWARE_ARMOUR, $amount); |
590 | 600 | } |
591 | 601 | |
@@ -654,8 +664,9 @@ discard block |
||
654 | 664 | } |
655 | 665 | |
656 | 666 | public function setCDs($amount, $updateOldAmount = false) { |
657 | - if ($updateOldAmount && !$this->hasLostCDs()) |
|
658 | - $this->setOldHardware(HARDWARE_COMBAT, $amount); |
|
667 | + if ($updateOldAmount && !$this->hasLostCDs()) { |
|
668 | + $this->setOldHardware(HARDWARE_COMBAT, $amount); |
|
669 | + } |
|
659 | 670 | $this->setHardware(HARDWARE_COMBAT, $amount); |
660 | 671 | } |
661 | 672 | |
@@ -737,8 +748,9 @@ discard block |
||
737 | 748 | |
738 | 749 | public function getCargo($goodID = false) { |
739 | 750 | if ($goodID !== false) { |
740 | - if (isset($this->cargo[$goodID])) |
|
741 | - return $this->cargo[$goodID]; |
|
751 | + if (isset($this->cargo[$goodID])) { |
|
752 | + return $this->cargo[$goodID]; |
|
753 | + } |
|
742 | 754 | $cargo = 0; |
743 | 755 | return $cargo; |
744 | 756 | } |
@@ -746,16 +758,19 @@ discard block |
||
746 | 758 | } |
747 | 759 | |
748 | 760 | public function hasCargo($goodID = false) { |
749 | - if ($goodID !== false) |
|
750 | - return $this->getCargo($goodID) > 0; |
|
751 | - if (is_array($cargo = $this->getCargo())) |
|
752 | - return array_sum($cargo) > 0; |
|
761 | + if ($goodID !== false) { |
|
762 | + return $this->getCargo($goodID) > 0; |
|
763 | + } |
|
764 | + if (is_array($cargo = $this->getCargo())) { |
|
765 | + return array_sum($cargo) > 0; |
|
766 | + } |
|
753 | 767 | return false; |
754 | 768 | } |
755 | 769 | |
756 | 770 | public function setCargo($goodID, $amount) { |
757 | - if ($this->getCargo($goodID) == $amount) |
|
758 | - return; |
|
771 | + if ($this->getCargo($goodID) == $amount) { |
|
772 | + return; |
|
773 | + } |
|
759 | 774 | $this->cargo[$goodID] = $amount; |
760 | 775 | $this->hasChangedCargo = true; |
761 | 776 | // Sort cargo by goodID to make sure it shows up in the correct order |
@@ -764,14 +779,16 @@ discard block |
||
764 | 779 | } |
765 | 780 | |
766 | 781 | public function decreaseCargo($goodID, $amount) { |
767 | - if ($amount < 0) |
|
768 | - throw new Exception('Trying to decrease negative cargo.'); |
|
782 | + if ($amount < 0) { |
|
783 | + throw new Exception('Trying to decrease negative cargo.'); |
|
784 | + } |
|
769 | 785 | $this->setCargo($goodID, $this->getCargo($goodID) - $amount); |
770 | 786 | } |
771 | 787 | |
772 | 788 | public function increaseCargo($goodID, $amount) { |
773 | - if ($amount < 0) |
|
774 | - throw new Exception('Trying to increase negative cargo.'); |
|
789 | + if ($amount < 0) { |
|
790 | + throw new Exception('Trying to increase negative cargo.'); |
|
791 | + } |
|
775 | 792 | $this->setCargo($goodID, $this->getCargo($goodID) + $amount); |
776 | 793 | } |
777 | 794 | |
@@ -801,8 +818,9 @@ discard block |
||
801 | 818 | $this->setOldShields($this->getShields()); |
802 | 819 | $this->setOldCDs($this->getCDs()); |
803 | 820 | $this->setOldArmour($this->getArmour()); |
804 | - if (isset($var['UnderAttack'])) |
|
805 | - return $var['UnderAttack']; |
|
821 | + if (isset($var['UnderAttack'])) { |
|
822 | + return $var['UnderAttack']; |
|
823 | + } |
|
806 | 824 | if ($underAttack && !USING_AJAX) { |
807 | 825 | SmrSession::updateVar('UnderAttack', $underAttack); //Remember we are under attack for AJAX |
808 | 826 | } |
@@ -881,8 +899,9 @@ discard block |
||
881 | 899 | $results['DeadBeforeShot'] = false; |
882 | 900 | foreach ($this->weapons as $orderID => $weapon) { |
883 | 901 | $results['Weapons'][$orderID] =& $weapon->shootPlayer($thisPlayer, $targetPlayers[array_rand($targetPlayers)]); |
884 | - if ($results['Weapons'][$orderID]['Hit']) |
|
885 | - $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
902 | + if ($results['Weapons'][$orderID]['Hit']) { |
|
903 | + $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
904 | + } |
|
886 | 905 | } |
887 | 906 | if ($this->hasCDs()) { |
888 | 907 | $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs()); |
@@ -944,8 +963,9 @@ discard block |
||
944 | 963 | $results['DeadBeforeShot'] = false; |
945 | 964 | foreach ($this->weapons as $orderID => $weapon) { |
946 | 965 | $results['Weapons'][$orderID] =& $weapon->shootPort($thisPlayer, $port); |
947 | - if ($results['Weapons'][$orderID]['Hit']) |
|
948 | - $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
966 | + if ($results['Weapons'][$orderID]['Hit']) { |
|
967 | + $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
968 | + } |
|
949 | 969 | } |
950 | 970 | if ($this->hasCDs()) { |
951 | 971 | $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs()); |
@@ -981,8 +1001,9 @@ discard block |
||
981 | 1001 | $results['DeadBeforeShot'] = false; |
982 | 1002 | foreach ($this->weapons as $orderID => $weapon) { |
983 | 1003 | $results['Weapons'][$orderID] =& $weapon->shootPlanet($thisPlayer, $planet, $delayed); |
984 | - if ($results['Weapons'][$orderID]['Hit']) |
|
985 | - $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
1004 | + if ($results['Weapons'][$orderID]['Hit']) { |
|
1005 | + $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
|
1006 | + } |
|
986 | 1007 | } |
987 | 1008 | if ($this->hasCDs()) { |
988 | 1009 | $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs()); |
@@ -1007,8 +1028,9 @@ discard block |
||
1007 | 1028 | $cdDamage = $this->doCDDamage(min($damage['MaxDamage'], $damage['Armour'])); |
1008 | 1029 | $damage['Armour'] -= $cdDamage; |
1009 | 1030 | $damage['MaxDamage'] -= $cdDamage; |
1010 | - if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) |
|
1011 | - $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1031 | + if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) { |
|
1032 | + $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1033 | + } |
|
1012 | 1034 | } |
1013 | 1035 | } |
1014 | 1036 | $return = array( |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | JOIN chess_game ON account_id = black_id OR account_id = white_id |
34 | 34 | WHERE end_time > ' . TIME . ' OR end_time IS NULL;'); |
35 | 35 | $games = array(); |
36 | - while($db->nextRecord()) { |
|
36 | + while ($db->nextRecord()) { |
|
37 | 37 | $game = self::getChessGame($db->getInt('chess_game_id'), $forceUpdate); |
38 | - if($game->getCurrentTurnAccount()->isNPC()) { |
|
38 | + if ($game->getCurrentTurnAccount()->isNPC()) { |
|
39 | 39 | $games[] = $game; |
40 | 40 | } |
41 | 41 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $db = new SmrMySqlDatabase(); |
47 | 47 | $db->query('SELECT chess_game_id FROM chess_game WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND (black_id = ' . $db->escapeNumber($player->getAccountID()) . ' OR white_id = ' . $db->escapeNumber($player->getAccountID()) . ') AND (end_time > ' . TIME . ' OR end_time IS NULL);'); |
48 | 48 | $games = array(); |
49 | - while($db->nextRecord()) { |
|
49 | + while ($db->nextRecord()) { |
|
50 | 50 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
51 | 51 | } |
52 | 52 | return $games; |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | $db = new SmrMySqlDatabase(); |
57 | 57 | $db->query('SELECT chess_game_id FROM chess_game WHERE black_id = ' . $db->escapeNumber($accountID) . ' OR white_id = ' . $db->escapeNumber($accountID) . ';'); |
58 | 58 | $games = array(); |
59 | - while($db->nextRecord()) { |
|
59 | + while ($db->nextRecord()) { |
|
60 | 60 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
61 | 61 | } |
62 | 62 | return $games; |
63 | 63 | } |
64 | 64 | |
65 | - public static function getChessGame($chessGameID,$forceUpdate = false) { |
|
66 | - if($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
65 | + public static function getChessGame($chessGameID, $forceUpdate = false) { |
|
66 | + if ($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
67 | 67 | self::$CACHE_CHESS_GAMES[$chessGameID] = new ChessGame($chessGameID); |
68 | 68 | } |
69 | 69 | return self::$CACHE_CHESS_GAMES[$chessGameID]; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $this->db->query('SELECT * |
75 | 75 | FROM chess_game |
76 | 76 | WHERE chess_game_id=' . $this->db->escapeNumber($chessGameID) . ' LIMIT 1;'); |
77 | - if($this->db->nextRecord()) { |
|
77 | + if ($this->db->nextRecord()) { |
|
78 | 78 | $this->chessGameID = $chessGameID; |
79 | 79 | $this->gameID = $this->db->getInt('game_id'); |
80 | 80 | $this->startDate = $this->db->getInt('start_time'); |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | public static function isPlayerChecked(array &$board, array &$hasMoved, $colour) { |
97 | - foreach($board as &$row) { |
|
98 | - foreach($row as &$p) { |
|
99 | - if($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
97 | + foreach ($board as &$row) { |
|
98 | + foreach ($row as &$p) { |
|
99 | + if ($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
100 | 100 | return true; |
101 | 101 | } |
102 | 102 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'King' => false |
121 | 121 | ) |
122 | 122 | ), |
123 | - ChessPiece::PAWN => array(-1,-1) |
|
123 | + ChessPiece::PAWN => array(-1, -1) |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | $this->resetHasMoved(); |
144 | 144 | |
145 | 145 | try { |
146 | - while($db->nextRecord()) { |
|
147 | - if($debugInfo === true) { |
|
146 | + while ($db->nextRecord()) { |
|
147 | + if ($debugInfo === true) { |
|
148 | 148 | echo 'x=', $db->getInt('start_x'), ', y=', $db->getInt('start_y'), ', endX=', $db->getInt('end_x'), ', endY=', $db->getInt('end_y'), ', forAccountID=', $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID(), EOL; |
149 | 149 | } |
150 | - if(0 != $this->tryMove($db->getInt('start_x'), $db->getInt('start_y'), $db->getInt('end_x'), $db->getInt('end_y'), $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID())) { |
|
150 | + if (0 != $this->tryMove($db->getInt('start_x'), $db->getInt('start_y'), $db->getInt('end_x'), $db->getInt('end_y'), $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID())) { |
|
151 | 151 | break; |
152 | 152 | } |
153 | 153 | } |
154 | 154 | } |
155 | - catch(Exception $e) { |
|
156 | - if($debugInfo === true) { |
|
155 | + catch (Exception $e) { |
|
156 | + if ($debugInfo === true) { |
|
157 | 157 | echo $e->getMessage() . EOL . $e->getTraceAsString() . EOL; |
158 | 158 | } |
159 | 159 | // We probably tried an invalid move - move on. |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | public function getBoard() { |
164 | - if($this->board == null) { |
|
164 | + if ($this->board == null) { |
|
165 | 165 | $this->db->query('SELECT * FROM chess_game_pieces WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ';'); |
166 | 166 | $pieces = array(); |
167 | - while($this->db->nextRecord()) { |
|
167 | + while ($this->db->nextRecord()) { |
|
168 | 168 | $accountID = $this->db->getInt('account_id'); |
169 | 169 | $pieces[] = new ChessPiece($this->chessGameID, $accountID, $this->getColourForAccountID($accountID), $this->db->getInt('piece_id'), $this->db->getInt('x'), $this->db->getInt('y'), $this->db->getInt('piece_no')); |
170 | 170 | } |
@@ -179,20 +179,20 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | public function getMoves() { |
182 | - if($this->moves == null) { |
|
182 | + if ($this->moves == null) { |
|
183 | 183 | $this->db->query('SELECT * FROM chess_game_moves WHERE chess_game_id = ' . $this->db->escapeNumber($this->chessGameID) . ' ORDER BY move_id;'); |
184 | 184 | $this->moves = array(); |
185 | 185 | $mate = false; |
186 | - while($this->db->nextRecord()) { |
|
186 | + while ($this->db->nextRecord()) { |
|
187 | 187 | $pieceTakenID = $this->db->getField('piece_taken') == null ? null : $this->db->getInt('piece_taken'); |
188 | 188 | $this->moves[] = $this->createMove($this->db->getInt('piece_id'), $this->db->getInt('start_x'), $this->db->getInt('start_y'), $this->db->getInt('end_x'), $this->db->getInt('end_y'), $pieceTakenID, $this->db->getField('checked'), $this->db->getInt('move_id') % 2 == 1 ? self::PLAYER_WHITE : self::PLAYER_BLACK, $this->db->getField('castling'), $this->db->getBoolean('en_passant'), $this->db->getInt('promote_piece_id')); |
189 | 189 | $mate = $this->db->getField('checked') == 'MATE'; |
190 | 190 | } |
191 | - if(!$mate && $this->hasEnded()) { |
|
192 | - if($this->getWinner() != 0) { |
|
191 | + if (!$mate && $this->hasEnded()) { |
|
192 | + if ($this->getWinner() != 0) { |
|
193 | 193 | $this->moves[] = ($this->getWinner() == $this->getWhiteID() ? 'Black' : 'White') . ' Resigned.'; |
194 | 194 | } |
195 | - else if(count($this->moves) < 2) { |
|
195 | + else if (count($this->moves) < 2) { |
|
196 | 196 | $this->moves[] = 'Game Cancelled.'; |
197 | 197 | } |
198 | 198 | else { |
@@ -205,30 +205,30 @@ discard block |
||
205 | 205 | |
206 | 206 | public function getFENString() { |
207 | 207 | $fen = ''; |
208 | - $board =& $this->getBoard(); |
|
208 | + $board = & $this->getBoard(); |
|
209 | 209 | $blanks = 0; |
210 | - for($y=0; $y < 8; $y++) { |
|
211 | - if($y > 0) { |
|
210 | + for ($y = 0; $y < 8; $y++) { |
|
211 | + if ($y > 0) { |
|
212 | 212 | $fen .= '/'; |
213 | 213 | } |
214 | - for($x=0; $x < 8; $x++) { |
|
215 | - if($board[$y][$x] == null) { |
|
214 | + for ($x = 0; $x < 8; $x++) { |
|
215 | + if ($board[$y][$x] == null) { |
|
216 | 216 | $blanks++; |
217 | 217 | } |
218 | 218 | else { |
219 | - if($blanks > 0) { |
|
219 | + if ($blanks > 0) { |
|
220 | 220 | $fen .= $blanks; |
221 | 221 | $blanks = 0; |
222 | 222 | } |
223 | 223 | $fen .= $board[$y][$x]->getPieceLetter(); |
224 | 224 | } |
225 | 225 | } |
226 | - if($blanks > 0) { |
|
226 | + if ($blanks > 0) { |
|
227 | 227 | $fen .= $blanks; |
228 | 228 | $blanks = 0; |
229 | 229 | } |
230 | 230 | } |
231 | - switch($this->getCurrentTurnColour()) { |
|
231 | + switch ($this->getCurrentTurnColour()) { |
|
232 | 232 | case self::PLAYER_WHITE: |
233 | 233 | $fen .= ' w '; |
234 | 234 | break; |
@@ -239,30 +239,30 @@ discard block |
||
239 | 239 | |
240 | 240 | // Castling |
241 | 241 | $castling = ''; |
242 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
243 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
242 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
243 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
244 | 244 | $castling .= 'K'; |
245 | 245 | } |
246 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
246 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
247 | 247 | $castling .= 'Q'; |
248 | 248 | } |
249 | 249 | } |
250 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
251 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
250 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
251 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
252 | 252 | $castling .= 'k'; |
253 | 253 | } |
254 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
254 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
255 | 255 | $castling .= 'q'; |
256 | 256 | } |
257 | 257 | } |
258 | - if($castling == '') { |
|
258 | + if ($castling == '') { |
|
259 | 259 | $castling = '-'; |
260 | 260 | } |
261 | 261 | $fen .= $castling . ' '; |
262 | 262 | |
263 | - if($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
263 | + if ($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
264 | 264 | $fen .= chr(ord('a') + $this->hasMoved[ChessPiece::PAWN][0]); |
265 | - switch($this->hasMoved[ChessPiece::PAWN][1]) { |
|
265 | + switch ($this->hasMoved[ChessPiece::PAWN][1]) { |
|
266 | 266 | case 3: |
267 | 267 | $fen .= '6'; |
268 | 268 | break; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | else { |
275 | 275 | $fen .= '-'; |
276 | 276 | } |
277 | - $fen .= ' 0 ' . floor(count($this->moves)/2); |
|
277 | + $fen .= ' 0 ' . floor(count($this->moves) / 2); |
|
278 | 278 | |
279 | 279 | return $fen; |
280 | 280 | } |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | private static function parsePieces(array $pieces) { |
283 | 283 | $board = array(); |
284 | 284 | $row = array(); |
285 | - for($i=0;$i<8;$i++) { |
|
285 | + for ($i = 0; $i < 8; $i++) { |
|
286 | 286 | $row[] = null; |
287 | 287 | } |
288 | - for($i=0;$i<8;$i++) { |
|
288 | + for ($i = 0; $i < 8; $i++) { |
|
289 | 289 | $board[] = $row; |
290 | 290 | } |
291 | - foreach($pieces as $piece) { |
|
292 | - if($board[$piece->getY()][$piece->getX()] != null) { |
|
291 | + foreach ($pieces as $piece) { |
|
292 | + if ($board[$piece->getY()][$piece->getX()] != null) { |
|
293 | 293 | throw new Exception('Two pieces found in the same tile.'); |
294 | 294 | } |
295 | 295 | $board[$piece->getY()][$piece->getX()] = $piece; |
@@ -300,8 +300,7 @@ discard block |
||
300 | 300 | public static function getStandardGame($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
301 | 301 | $white = $whitePlayer->getAccountID(); |
302 | 302 | $black = $blackPlayer->getAccountID(); |
303 | - return array |
|
304 | - ( |
|
303 | + return array( |
|
305 | 304 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::ROOK, 0, 0), |
306 | 305 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::KNIGHT, 1, 0), |
307 | 306 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::BISHOP, 2, 0), |
@@ -341,7 +340,7 @@ discard block |
||
341 | 340 | } |
342 | 341 | |
343 | 342 | public static function insertNewGame($startDate, $endDate, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
344 | - if($startDate == null) { |
|
343 | + if ($startDate == null) { |
|
345 | 344 | throw new Exception('Start date cannot be null.'); |
346 | 345 | } |
347 | 346 | |
@@ -359,7 +358,7 @@ discard block |
||
359 | 358 | private static function insertPieces($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
360 | 359 | $db = new SmrMySqlDatabase(); |
361 | 360 | $pieces = self::getStandardGame($chessGameID, $whitePlayer, $blackPlayer); |
362 | - foreach($pieces as $p) { |
|
361 | + foreach ($pieces as $p) { |
|
363 | 362 | $db->query('INSERT INTO chess_game_pieces' . |
364 | 363 | '(chess_game_id,account_id,piece_id,x,y)' . |
365 | 364 | 'values' . |
@@ -371,63 +370,63 @@ discard block |
||
371 | 370 | // This move will be set as the most recent move |
372 | 371 | $this->lastMove = [ |
373 | 372 | 'From' => ['X' => $startX, 'Y' => $startY], |
374 | - 'To' => ['X' => $endX, 'Y' => $endY], |
|
373 | + 'To' => ['X' => $endX, 'Y' => $endY], |
|
375 | 374 | ]; |
376 | 375 | |
377 | 376 | $otherPlayerColour = self::getOtherColour($playerColour); |
378 | - if($pieceID == ChessPiece::KING) { |
|
377 | + if ($pieceID == ChessPiece::KING) { |
|
379 | 378 | $this->hasMoved[$playerColour][ChessPiece::KING] = true; |
380 | 379 | } |
381 | 380 | // Check if the piece moving is a rook and mark it as moved to stop castling. |
382 | - if($pieceID == ChessPiece::ROOK && ($startX == 0 || $startX == 7) && ($startY == ($playerColour == self::PLAYER_WHITE ? 7 : 0))) { |
|
383 | - $this->hasMoved[$playerColour][ChessPiece::ROOK][$startX==0?'Queen':'King'] = true; |
|
381 | + if ($pieceID == ChessPiece::ROOK && ($startX == 0 || $startX == 7) && ($startY == ($playerColour == self::PLAYER_WHITE ? 7 : 0))) { |
|
382 | + $this->hasMoved[$playerColour][ChessPiece::ROOK][$startX == 0 ? 'Queen' : 'King'] = true; |
|
384 | 383 | } |
385 | 384 | // Check if we've taken a rook and marked them as moved, if they've already moved this does nothing, but if they were taken before moving this stops an issue with trying to castle with a non-existent castle. |
386 | - if($pieceTaken == ChessPiece::ROOK && ($endX == 0 || $endX == 7) && $endY == ($otherPlayerColour == self::PLAYER_WHITE ? 7 : 0)) { |
|
387 | - $this->hasMoved[$otherPlayerColour][ChessPiece::ROOK][$endX==0?'Queen':'King'] = true; |
|
385 | + if ($pieceTaken == ChessPiece::ROOK && ($endX == 0 || $endX == 7) && $endY == ($otherPlayerColour == self::PLAYER_WHITE ? 7 : 0)) { |
|
386 | + $this->hasMoved[$otherPlayerColour][ChessPiece::ROOK][$endX == 0 ? 'Queen' : 'King'] = true; |
|
388 | 387 | } |
389 | - if($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
388 | + if ($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
390 | 389 | $this->hasMoved[ChessPiece::PAWN] = array($endX, $endY); |
391 | 390 | } |
392 | 391 | else { |
393 | - $this->hasMoved[ChessPiece::PAWN] = array(-1,-1); |
|
392 | + $this->hasMoved[ChessPiece::PAWN] = array(-1, -1); |
|
394 | 393 | } |
395 | 394 | return ($castling == 'Queen' ? '0-0-0' : ($castling == 'King' ? '0-0' : '')) |
396 | 395 | . ChessPiece::getSymbolForPiece($pieceID, $playerColour) |
397 | - . chr(ord('a')+$startX) |
|
398 | - . (8-$startY) |
|
396 | + . chr(ord('a') + $startX) |
|
397 | + . (8 - $startY) |
|
399 | 398 | . ' ' |
400 | 399 | . ($pieceTaken == null ? '' : ChessPiece::getSymbolForPiece($pieceTaken, $otherPlayerColour)) |
401 | - . chr(ord('a')+$endX) |
|
402 | - . (8-$endY) |
|
400 | + . chr(ord('a') + $endX) |
|
401 | + . (8 - $endY) |
|
403 | 402 | . ($promotionPieceID == null ? '' : ChessPiece::getSymbolForPiece($promotionPieceID, $playerColour)) |
404 | 403 | . ' ' |
405 | - . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++') ) |
|
404 | + . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++')) |
|
406 | 405 | . ($enPassant ? ' e.p.' : ''); |
407 | 406 | } |
408 | 407 | |
409 | 408 | public function isCheckmated($colour) { |
410 | 409 | $king = null; |
411 | - foreach($this->board as $row) { |
|
412 | - foreach($row as $piece) { |
|
413 | - if($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
410 | + foreach ($this->board as $row) { |
|
411 | + foreach ($row as $piece) { |
|
412 | + if ($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
414 | 413 | $king = $piece; |
415 | 414 | break; |
416 | 415 | } |
417 | 416 | } |
418 | 417 | } |
419 | - if($king == null) { |
|
418 | + if ($king == null) { |
|
420 | 419 | throw new Exception('Could not find the king: game id = ' . $this->chessGameID); |
421 | 420 | } |
422 | - if(!self::isPlayerChecked($this->board, $this->getHasMoved(), $colour)) { |
|
421 | + if (!self::isPlayerChecked($this->board, $this->getHasMoved(), $colour)) { |
|
423 | 422 | return false; |
424 | 423 | } |
425 | - foreach($this->board as $row) { |
|
426 | - foreach($row as $piece) { |
|
427 | - if($piece != null && $piece->colour == $colour) { |
|
424 | + foreach ($this->board as $row) { |
|
425 | + foreach ($row as $piece) { |
|
426 | + if ($piece != null && $piece->colour == $colour) { |
|
428 | 427 | $moves = $piece->getPossibleMoves($this->board, $this->getHasMoved()); |
429 | 428 | //There are moves we can make, we are clearly not checkmated. |
430 | - if(count($moves) > 0) { |
|
429 | + if (count($moves) > 0) { |
|
431 | 430 | return false; |
432 | 431 | } |
433 | 432 | } |
@@ -438,15 +437,15 @@ discard block |
||
438 | 437 | |
439 | 438 | public static function isCastling($x, $toX) { |
440 | 439 | $movement = $toX - $x; |
441 | - if(abs($movement) == 2) { |
|
440 | + if (abs($movement) == 2) { |
|
442 | 441 | //To the left. |
443 | - if($movement == -2) { |
|
442 | + if ($movement == -2) { |
|
444 | 443 | return array('Type' => 'Queen', |
445 | 444 | 'X' => 0, |
446 | 445 | 'ToX' => 3 |
447 | 446 | ); |
448 | 447 | } //To the right |
449 | - else if($movement == 2) { |
|
448 | + else if ($movement == 2) { |
|
450 | 449 | return array('Type' => 'King', |
451 | 450 | 'X' => 7, |
452 | 451 | 'ToX' => 5 |
@@ -457,36 +456,36 @@ discard block |
||
457 | 456 | } |
458 | 457 | |
459 | 458 | public static function movePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $pawnPromotionPiece = ChessPiece::QUEEN) { |
460 | - if(!self::isValidCoord($x, $y, $board)) { |
|
459 | + if (!self::isValidCoord($x, $y, $board)) { |
|
461 | 460 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
462 | 461 | } |
463 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
462 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
464 | 463 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
465 | 464 | } |
466 | 465 | $pieceTaken = $board[$toY][$toX]; |
467 | 466 | $board[$toY][$toX] = $board[$y][$x]; |
468 | - $p =& $board[$toY][$toX]; |
|
467 | + $p = & $board[$toY][$toX]; |
|
469 | 468 | $board[$y][$x] = null; |
470 | - if($p == null) { |
|
469 | + if ($p == null) { |
|
471 | 470 | throw new Exception('Trying to move non-existent piece: ' . var_export($board, true)); |
472 | 471 | } |
473 | 472 | $p->setX($toX); |
474 | 473 | $p->setY($toY); |
475 | 474 | |
476 | 475 | $oldPawnMovement = $hasMoved[ChessPiece::PAWN]; |
477 | - $nextPawnMovement = array(-1,-1); |
|
476 | + $nextPawnMovement = array(-1, -1); |
|
478 | 477 | $castling = false; |
479 | 478 | $enPassant = false; |
480 | 479 | $rookMoved = false; |
481 | 480 | $rookTaken = false; |
482 | 481 | $pawnPromotion = false; |
483 | - if($p->pieceID == ChessPiece::KING) { |
|
482 | + if ($p->pieceID == ChessPiece::KING) { |
|
484 | 483 | //Castling? |
485 | 484 | $castling = self::isCastling($x, $toX); |
486 | - if($castling !== false) { |
|
485 | + if ($castling !== false) { |
|
487 | 486 | $hasMoved[$p->colour][ChessPiece::KING] = true; |
488 | 487 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = true; |
489 | - if($board[$y][$castling['X']] == null) { |
|
488 | + if ($board[$y][$castling['X']] == null) { |
|
490 | 489 | throw new Exception('Cannot castle with non-existent castle.'); |
491 | 490 | } |
492 | 491 | $board[$toY][$castling['ToX']] = $board[$y][$castling['X']]; |
@@ -494,37 +493,37 @@ discard block |
||
494 | 493 | $board[$y][$castling['X']] = null; |
495 | 494 | } |
496 | 495 | } |
497 | - else if($p->pieceID == ChessPiece::PAWN) { |
|
498 | - if($toY == 0 || $toY == 7) { |
|
496 | + else if ($p->pieceID == ChessPiece::PAWN) { |
|
497 | + if ($toY == 0 || $toY == 7) { |
|
499 | 498 | $pawnPromotion = $p->promote($pawnPromotionPiece, $board); |
500 | 499 | } |
501 | 500 | //Double move to track? |
502 | - else if(($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
501 | + else if (($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
503 | 502 | $nextPawnMovement = array($toX, $toY); |
504 | 503 | } |
505 | 504 | //En passant? |
506 | - else if($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
505 | + else if ($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
507 | 506 | ($hasMoved[ChessPiece::PAWN][1] == 3 && $toY == 2 || $hasMoved[ChessPiece::PAWN][1] == 4 && $toY == 5)) { |
508 | 507 | $enPassant = true; |
509 | 508 | $pieceTaken = $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]]; |
510 | - if($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
509 | + if ($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
511 | 510 | throw new Exception('Cannot en passant a non-existent pawn.'); |
512 | 511 | } |
513 | 512 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = null; |
514 | 513 | } |
515 | 514 | } |
516 | - else if($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
515 | + else if ($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
517 | 516 | //Rook moved? |
518 | - if($hasMoved[$p->colour][ChessPiece::ROOK][$x==0?'Queen':'King'] === false) { |
|
517 | + if ($hasMoved[$p->colour][ChessPiece::ROOK][$x == 0 ? 'Queen' : 'King'] === false) { |
|
519 | 518 | // We set rook moved in here as it's used for move info. |
520 | - $rookMoved = $x==0?'Queen':'King'; |
|
519 | + $rookMoved = $x == 0 ? 'Queen' : 'King'; |
|
521 | 520 | $hasMoved[$p->colour][ChessPiece::ROOK][$rookMoved] = true; |
522 | 521 | } |
523 | 522 | } |
524 | 523 | // Check if we've taken a rook and marked them as moved, if they've already moved this does nothing, but if they were taken before moving this stops an issue with trying to castle with a non-existent castle. |
525 | - if($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
526 | - if($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX==0?'Queen':'King'] === false) { |
|
527 | - $rookTaken = $toX==0?'Queen':'King'; |
|
524 | + if ($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
525 | + if ($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX == 0 ? 'Queen' : 'King'] === false) { |
|
526 | + $rookTaken = $toX == 0 ? 'Queen' : 'King'; |
|
528 | 527 | $hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$rookTaken] = true; |
529 | 528 | } |
530 | 529 | } |
@@ -541,18 +540,18 @@ discard block |
||
541 | 540 | } |
542 | 541 | |
543 | 542 | public static function undoMovePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $moveInfo) { |
544 | - if(!self::isValidCoord($x, $y, $board)) { |
|
543 | + if (!self::isValidCoord($x, $y, $board)) { |
|
545 | 544 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
546 | 545 | } |
547 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
546 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
548 | 547 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
549 | 548 | } |
550 | - if($board[$y][$x] != null) { |
|
549 | + if ($board[$y][$x] != null) { |
|
551 | 550 | throw new Exception('Undoing move onto another piece? x=' . $x . ', y=' . $y); |
552 | 551 | } |
553 | 552 | $board[$y][$x] = $board[$toY][$toX]; |
554 | - $p =& $board[$y][$x]; |
|
555 | - if($p == null) { |
|
553 | + $p = & $board[$y][$x]; |
|
554 | + if ($p == null) { |
|
556 | 555 | throw new Exception('Trying to undo move of a non-existent piece: ' . var_export($board, true)); |
557 | 556 | } |
558 | 557 | $board[$toY][$toX] = $moveInfo['PieceTaken']; |
@@ -561,12 +560,12 @@ discard block |
||
561 | 560 | |
562 | 561 | $hasMoved[ChessPiece::PAWN] = $moveInfo['OldPawnMovement']; |
563 | 562 | //Castling |
564 | - if($p->pieceID == ChessPiece::KING) { |
|
563 | + if ($p->pieceID == ChessPiece::KING) { |
|
565 | 564 | $castling = self::isCastling($x, $toX); |
566 | - if($castling !== false) { |
|
565 | + if ($castling !== false) { |
|
567 | 566 | $hasMoved[$p->colour][ChessPiece::KING] = false; |
568 | 567 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = false; |
569 | - if($board[$toY][$castling['ToX']] == null) { |
|
568 | + if ($board[$toY][$castling['ToX']] == null) { |
|
570 | 569 | throw new Exception('Cannot undo castle with non-existent castle.'); |
571 | 570 | } |
572 | 571 | $board[$y][$castling['X']] = $board[$toY][$castling['ToX']]; |
@@ -574,25 +573,25 @@ discard block |
||
574 | 573 | $board[$toY][$castling['ToX']] = null; |
575 | 574 | } |
576 | 575 | } |
577 | - else if($moveInfo['EnPassant'] === true) { |
|
576 | + else if ($moveInfo['EnPassant'] === true) { |
|
578 | 577 | $board[$toY][$toX] = null; |
579 | 578 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = $moveInfo['PieceTaken']; |
580 | 579 | } |
581 | - else if($moveInfo['RookMoved'] !== false) { |
|
580 | + else if ($moveInfo['RookMoved'] !== false) { |
|
582 | 581 | $hasMoved[$p->colour][ChessPiece::ROOK][$moveInfo['RookMoved']] = false; |
583 | 582 | } |
584 | - if($moveInfo['RookTaken'] !== false) { |
|
583 | + if ($moveInfo['RookTaken'] !== false) { |
|
585 | 584 | $hasMoved[$moveInfo['PieceTaken']->colour][ChessPiece::ROOK][$moveInfo['RookTaken']] = false; |
586 | 585 | } |
587 | 586 | } |
588 | 587 | |
589 | 588 | public function tryAlgebraicMove($move) { |
590 | - if(strlen($move) != 4 && strlen($move) != 5) { |
|
589 | + if (strlen($move) != 4 && strlen($move) != 5) { |
|
591 | 590 | throw new Exception('Move of length "' . strlen($move) . '" is not valid, full move: ' . $move); |
592 | 591 | } |
593 | 592 | $aVal = ord('a'); |
594 | 593 | $hVal = ord('h'); |
595 | - if(ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
594 | + if (ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
596 | 595 | || ord($move[0]) > $hVal || ord($move[2]) > $hVal |
597 | 596 | || $move[1] < 1 || $move[3] < 1 |
598 | 597 | || $move[1] > 8 || $move[3] > 8) { |
@@ -603,73 +602,73 @@ discard block |
||
603 | 602 | $toX = ord($move[2]) - $aVal; |
604 | 603 | $toY = 8 - $move[3]; |
605 | 604 | $pawnPromotionPiece = null; |
606 | - if(isset($move[4])) { |
|
605 | + if (isset($move[4])) { |
|
607 | 606 | $pawnPromotionPiece = ChessPiece::getPieceForLetter($move[4]); |
608 | 607 | } |
609 | 608 | return $this->tryMove($x, $y, $toX, $toY, $this->getCurrentTurnAccountID(), $pawnPromotionPiece); |
610 | 609 | } |
611 | 610 | |
612 | 611 | public function tryMove($x, $y, $toX, $toY, $forAccountID, $pawnPromotionPiece) { |
613 | - if($this->hasEnded()) { |
|
612 | + if ($this->hasEnded()) { |
|
614 | 613 | return 5; |
615 | 614 | } |
616 | - if($this->getCurrentTurnAccountID() != $forAccountID) { |
|
615 | + if ($this->getCurrentTurnAccountID() != $forAccountID) { |
|
617 | 616 | return 4; |
618 | 617 | } |
619 | 618 | $lastTurnPlayer = $this->getCurrentTurnPlayer(); |
620 | 619 | $this->getBoard(); |
621 | 620 | $p = $this->board[$y][$x]; |
622 | - if($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
621 | + if ($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
623 | 622 | return 2; |
624 | 623 | } |
625 | 624 | |
626 | 625 | $moves = $p->getPossibleMoves($this->board, $this->getHasMoved(), $forAccountID); |
627 | - foreach($moves as $move) { |
|
628 | - if($move[0]==$toX && $move[1]==$toY) { |
|
626 | + foreach ($moves as $move) { |
|
627 | + if ($move[0] == $toX && $move[1] == $toY) { |
|
629 | 628 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
630 | 629 | $currentPlayer = $this->getCurrentTurnPlayer(); |
631 | 630 | |
632 | 631 | $moveInfo = ChessGame::movePiece($this->board, $this->getHasMoved(), $x, $y, $toX, $toY, $pawnPromotionPiece); |
633 | 632 | |
634 | 633 | //We have taken the move, we should refresh $p |
635 | - $p =& $this->board[$toY][$toX]; |
|
634 | + $p = & $this->board[$toY][$toX]; |
|
636 | 635 | |
637 | 636 | $pieceTakenID = null; |
638 | - if($moveInfo['PieceTaken'] != null) { |
|
637 | + if ($moveInfo['PieceTaken'] != null) { |
|
639 | 638 | $pieceTakenID = $moveInfo['PieceTaken']->pieceID; |
640 | - if($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
639 | + if ($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
641 | 640 | throw new Exception('King was taken.'); |
642 | 641 | } |
643 | 642 | } |
644 | 643 | |
645 | 644 | $pieceID = $p->pieceID; |
646 | 645 | $pieceNo = $p->pieceNo; |
647 | - if($moveInfo['PawnPromotion'] !== false) { |
|
646 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
648 | 647 | $p->pieceID = $moveInfo['PawnPromotion']['PieceID']; |
649 | 648 | $p->pieceNo = $moveInfo['PawnPromotion']['PieceNo']; |
650 | 649 | } |
651 | 650 | |
652 | 651 | $checking = null; |
653 | - if($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
652 | + if ($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
654 | 653 | $checking = 'CHECK'; |
655 | 654 | } |
656 | - if($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
655 | + if ($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
657 | 656 | $checking = 'MATE'; |
658 | 657 | } |
659 | - if($this->moves!=null) { |
|
658 | + if ($this->moves != null) { |
|
660 | 659 | $this->moves[] = $this->createMove($pieceID, $x, $y, $toX, $toY, $pieceTakenID, $checking, $this->getCurrentTurnColour(), $moveInfo['Castling']['Type'], $moveInfo['EnPassant'], $moveInfo['PawnPromotion'] === false ? null : $moveInfo['PawnPromotion']['PieceID']); |
661 | 660 | } |
662 | - if(self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
661 | + if (self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
663 | 662 | return 3; |
664 | 663 | } |
665 | 664 | |
666 | 665 | $otherPlayer = $this->getCurrentTurnPlayer(); |
667 | - if($moveInfo['PawnPromotion'] !== false) { |
|
666 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
668 | 667 | $piecePromotedSymbol = $p->getPieceSymbol(); |
669 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted','Total'), HOF_PUBLIC); |
|
670 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted','Total'), HOF_PUBLIC); |
|
671 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
672 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
668 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
669 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
670 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
671 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
673 | 672 | } |
674 | 673 | $this->db->query('INSERT INTO chess_game_moves |
675 | 674 | (chess_game_id,piece_id,start_x,start_y,end_x,end_y,checked,piece_taken,castling,en_passant,promote_piece_id) |
@@ -677,37 +676,37 @@ discard block |
||
677 | 676 | (' . $this->db->escapeNumber($p->chessGameID) . ',' . $this->db->escapeNumber($pieceID) . ',' . $this->db->escapeNumber($x) . ',' . $this->db->escapeNumber($y) . ',' . $this->db->escapeNumber($toX) . ',' . $this->db->escapeNumber($toY) . ',' . $this->db->escapeString($checking, true, true) . ',' . ($moveInfo['PieceTaken'] == null ? 'NULL' : $this->db->escapeNumber($moveInfo['PieceTaken']->pieceID)) . ',' . $this->db->escapeString($moveInfo['Castling']['Type'], true, true) . ',' . $this->db->escapeBoolean($moveInfo['EnPassant']) . ',' . ($moveInfo['PawnPromotion'] == false ? 'NULL' : $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID'])) . ');'); |
678 | 677 | |
679 | 678 | |
680 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Total Taken'), HOF_PUBLIC); |
|
681 | - if($moveInfo['PieceTaken'] != null) { |
|
679 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Total Taken'), HOF_PUBLIC); |
|
680 | + if ($moveInfo['PieceTaken'] != null) { |
|
682 | 681 | $this->db->query('DELETE FROM chess_game_pieces |
683 | 682 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($moveInfo['PieceTaken']->accountID) . ' AND piece_id=' . $this->db->escapeNumber($moveInfo['PieceTaken']->pieceID) . ' AND piece_no=' . $this->db->escapeNumber($moveInfo['PieceTaken']->pieceNo) . ';'); |
684 | 683 | |
685 | 684 | $pieceTakenSymbol = $moveInfo['PieceTaken']->getPieceSymbol(); |
686 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken','Total'), HOF_PUBLIC); |
|
687 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken','Total'), HOF_PUBLIC); |
|
688 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC); |
|
689 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC); |
|
685 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', 'Total'), HOF_PUBLIC); |
|
686 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', 'Total'), HOF_PUBLIC); |
|
687 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
688 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
690 | 689 | } |
691 | 690 | $this->db->query('UPDATE chess_game_pieces |
692 | 691 | SET x=' . $this->db->escapeNumber($toX) . ', y=' . $this->db->escapeNumber($toY) . |
693 | 692 | ($moveInfo['PawnPromotion'] !== false ? ', piece_id=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID']) . ', piece_no=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceNo']) : '') . ' |
694 | 693 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($p->accountID) . ' AND piece_id=' . $this->db->escapeNumber($pieceID) . ' AND piece_no=' . $this->db->escapeNumber($pieceNo) . ';'); |
695 | - if($moveInfo['Castling'] !== false) { |
|
694 | + if ($moveInfo['Castling'] !== false) { |
|
696 | 695 | $this->db->query('UPDATE chess_game_pieces |
697 | 696 | SET x=' . $this->db->escapeNumber($moveInfo['Castling']['ToX']) . ' |
698 | 697 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($p->accountID) . ' AND x = ' . $this->db->escapeNumber($moveInfo['Castling']['X']) . ' AND y = ' . $this->db->escapeNumber($y) . ';'); |
699 | 698 | } |
700 | 699 | $return = 0; |
701 | - if($checking == 'MATE') { |
|
700 | + if ($checking == 'MATE') { |
|
702 | 701 | $this->setWinner($forAccountID); |
703 | 702 | $return = 1; |
704 | 703 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'You have just lost [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
705 | 704 | } |
706 | 705 | else { |
707 | 706 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'It is now your turn in [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
708 | - if($checking == 'CHECK') { |
|
709 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Check Given'), HOF_PUBLIC); |
|
710 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Check Received'), HOF_PUBLIC); |
|
707 | + if ($checking == 'CHECK') { |
|
708 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Given'), HOF_PUBLIC); |
|
709 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Received'), HOF_PUBLIC); |
|
711 | 710 | } |
712 | 711 | } |
713 | 712 | $currentPlayer->saveHOF(); |
@@ -746,10 +745,10 @@ discard block |
||
746 | 745 | } |
747 | 746 | |
748 | 747 | public function getColourID($colour) { |
749 | - if($colour == self::PLAYER_WHITE) { |
|
748 | + if ($colour == self::PLAYER_WHITE) { |
|
750 | 749 | return $this->getWhiteID(); |
751 | 750 | } |
752 | - if($colour == self::PLAYER_BLACK) { |
|
751 | + if ($colour == self::PLAYER_BLACK) { |
|
753 | 752 | return $this->getBlackID(); |
754 | 753 | } |
755 | 754 | } |
@@ -759,10 +758,10 @@ discard block |
||
759 | 758 | } |
760 | 759 | |
761 | 760 | public function getColourForAccountID($accountID) { |
762 | - if($accountID == $this->getWhiteID()) { |
|
761 | + if ($accountID == $this->getWhiteID()) { |
|
763 | 762 | return self::PLAYER_WHITE; |
764 | 763 | } |
765 | - if($accountID == $this->getBlackID()) { |
|
764 | + if ($accountID == $this->getBlackID()) { |
|
766 | 765 | return self::PLAYER_BLACK; |
767 | 766 | } |
768 | 767 | return false; |
@@ -790,8 +789,8 @@ discard block |
||
790 | 789 | $winningPlayer = $this->getColourPlayer($winnerColour); |
791 | 790 | $losingPlayer = $this->getColourPlayer(self::getOtherColour($winnerColour)); |
792 | 791 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
793 | - $winningPlayer->increaseHOF(1, array($chessType,'Games','Won'), HOF_PUBLIC); |
|
794 | - $losingPlayer->increaseHOF(1, array($chessType,'Games','Lost'), HOF_PUBLIC); |
|
792 | + $winningPlayer->increaseHOF(1, array($chessType, 'Games', 'Won'), HOF_PUBLIC); |
|
793 | + $losingPlayer->increaseHOF(1, array($chessType, 'Games', 'Lost'), HOF_PUBLIC); |
|
795 | 794 | return array('Winner' => $winningPlayer, 'Loser' => $losingPlayer); |
796 | 795 | } |
797 | 796 | |
@@ -832,21 +831,21 @@ discard block |
||
832 | 831 | } |
833 | 832 | |
834 | 833 | public static function getOtherColour($colour) { |
835 | - if($colour == self::PLAYER_WHITE) { |
|
834 | + if ($colour == self::PLAYER_WHITE) { |
|
836 | 835 | return self::PLAYER_BLACK; |
837 | 836 | } |
838 | - if($colour == self::PLAYER_BLACK) { |
|
837 | + if ($colour == self::PLAYER_BLACK) { |
|
839 | 838 | return self::PLAYER_WHITE; |
840 | 839 | } |
841 | 840 | return false; |
842 | 841 | } |
843 | 842 | |
844 | 843 | public function resign($accountID) { |
845 | - if($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
844 | + if ($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
846 | 845 | return false; |
847 | 846 | } |
848 | 847 | // If only 1 person has moved then just end the game. |
849 | - if(count($this->getMoves()) < 2) { |
|
848 | + if (count($this->getMoves()) < 2) { |
|
850 | 849 | $this->endDate = TIME; |
851 | 850 | $this->db->query('UPDATE chess_game |
852 | 851 | SET end_time=' . $this->db->escapeNumber(TIME) . ' |
@@ -858,17 +857,17 @@ discard block |
||
858 | 857 | $winnerAccountID = $this->getColourID(self::getOtherColour($loserColour)); |
859 | 858 | $results = $this->setWinner($winnerAccountID); |
860 | 859 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
861 | - $results['Loser']->increaseHOF(1, array($chessType,'Games','Resigned'), HOF_PUBLIC); |
|
860 | + $results['Loser']->increaseHOF(1, array($chessType, 'Games', 'Resigned'), HOF_PUBLIC); |
|
862 | 861 | SmrPlayer::sendMessageFromCasino($results['Winner']->getGameID(), $results['Winner']->getPlayerID(), '[player=' . $results['Loser']->getPlayerID() . '] just resigned against you in [chess=' . $this->getChessGameID() . '].'); |
863 | 862 | return 0; |
864 | 863 | } |
865 | 864 | } |
866 | 865 | |
867 | 866 | public function getPlayGameHREF() { |
868 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_play.php',array('ChessGameID' => $this->chessGameID))); |
|
867 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_play.php', array('ChessGameID' => $this->chessGameID))); |
|
869 | 868 | } |
870 | 869 | |
871 | 870 | public function getResignHREF() { |
872 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_resign_processing.php',array('ChessGameID' => $this->chessGameID))); |
|
871 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_resign_processing.php', array('ChessGameID' => $this->chessGameID))); |
|
873 | 872 | } |
874 | 873 | } |
@@ -126,15 +126,13 @@ discard block |
||
126 | 126 | $this->links['Right'] = $db->getInt('link_right'); |
127 | 127 | } |
128 | 128 | $this->warp = $db->getInt('warp'); |
129 | - } |
|
130 | - else if ($create) { |
|
129 | + } else if ($create) { |
|
131 | 130 | $this->battles = 0; |
132 | 131 | $this->links = array(); |
133 | 132 | $this->warp = 0; |
134 | 133 | $this->isNew = true; |
135 | 134 | return; |
136 | - } |
|
137 | - else { |
|
135 | + } else { |
|
138 | 136 | throw new SectorNotFoundException('No sector ' . $sectorID . ' in game ' . $gameID); |
139 | 137 | } |
140 | 138 | } |
@@ -167,52 +165,59 @@ discard block |
||
167 | 165 | } |
168 | 166 | |
169 | 167 | public function markVisited(AbstractSmrPlayer $player) { |
170 | - if ($this->hasPort()) |
|
171 | - $this->getPort()->addCachePort($player->getAccountID()); |
|
168 | + if ($this->hasPort()) { |
|
169 | + $this->getPort()->addCachePort($player->getAccountID()); |
|
170 | + } |
|
172 | 171 | |
173 | 172 | //now delete the entry from visited |
174 | - if (!$this->isVisited($player)) |
|
175 | - $this->db->query('DELETE FROM player_visited_sector WHERE ' . $this->SQL . ' |
|
173 | + if (!$this->isVisited($player)) { |
|
174 | + $this->db->query('DELETE FROM player_visited_sector WHERE ' . $this->SQL . ' |
|
176 | 175 | AND account_id = ' . $this->db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); |
176 | + } |
|
177 | 177 | $this->visited[$player->getAccountID()] = true; |
178 | 178 | } |
179 | 179 | |
180 | 180 | public function hasWeaponShop() { |
181 | 181 | foreach ($this->getLocations() as $location) { |
182 | - if ($location->isWeaponSold()) |
|
183 | - return true; |
|
182 | + if ($location->isWeaponSold()) { |
|
183 | + return true; |
|
184 | + } |
|
184 | 185 | } |
185 | 186 | return false; |
186 | 187 | } |
187 | 188 | |
188 | 189 | public function hasHQ() { |
189 | 190 | foreach ($this->getLocations() as $location) { |
190 | - if ($location->isHQ()) |
|
191 | - return true; |
|
191 | + if ($location->isHQ()) { |
|
192 | + return true; |
|
193 | + } |
|
192 | 194 | } |
193 | 195 | return false; |
194 | 196 | } |
195 | 197 | |
196 | 198 | public function hasUG() { |
197 | 199 | foreach ($this->getLocations() as $location) { |
198 | - if ($location->isUG()) |
|
199 | - return true; |
|
200 | + if ($location->isUG()) { |
|
201 | + return true; |
|
202 | + } |
|
200 | 203 | } |
201 | 204 | return false; |
202 | 205 | } |
203 | 206 | |
204 | 207 | public function hasShipShop() { |
205 | 208 | foreach ($this->getLocations() as $location) { |
206 | - if ($location->isShipSold()) |
|
207 | - return true; |
|
209 | + if ($location->isShipSold()) { |
|
210 | + return true; |
|
211 | + } |
|
208 | 212 | } |
209 | 213 | return false; |
210 | 214 | } |
211 | 215 | |
212 | 216 | public function offersFederalProtection() { |
213 | 217 | foreach ($this->getLocations() as $location) { |
214 | - if ($location->isFed()) |
|
215 | - return true; |
|
218 | + if ($location->isFed()) { |
|
219 | + return true; |
|
220 | + } |
|
216 | 221 | } |
217 | 222 | return false; |
218 | 223 | } |
@@ -220,32 +225,36 @@ discard block |
||
220 | 225 | public function getFedRaceIDs() { |
221 | 226 | $raceIDs = array(); |
222 | 227 | foreach ($this->getLocations() as $location) { |
223 | - if ($location->isFed()) |
|
224 | - $raceIDs[$location->getRaceID()] = $location->getRaceID(); |
|
228 | + if ($location->isFed()) { |
|
229 | + $raceIDs[$location->getRaceID()] = $location->getRaceID(); |
|
230 | + } |
|
225 | 231 | } |
226 | 232 | return $raceIDs; |
227 | 233 | } |
228 | 234 | |
229 | 235 | public function hasBar() { |
230 | 236 | foreach ($this->getLocations() as $location) { |
231 | - if ($location->isBar()) |
|
232 | - return true; |
|
237 | + if ($location->isBar()) { |
|
238 | + return true; |
|
239 | + } |
|
233 | 240 | } |
234 | 241 | return false; |
235 | 242 | } |
236 | 243 | |
237 | 244 | public function hasHardwareShop() { |
238 | 245 | foreach ($this->getLocations() as $location) { |
239 | - if ($location->isHardwareSold()) |
|
240 | - return true; |
|
246 | + if ($location->isHardwareSold()) { |
|
247 | + return true; |
|
248 | + } |
|
241 | 249 | } |
242 | 250 | return false; |
243 | 251 | } |
244 | 252 | |
245 | 253 | public function hasBank() { |
246 | 254 | foreach ($this->getLocations() as $location) { |
247 | - if ($location->isBank()) |
|
248 | - return true; |
|
255 | + if ($location->isBank()) { |
|
256 | + return true; |
|
257 | + } |
|
249 | 258 | } |
250 | 259 | return false; |
251 | 260 | } |
@@ -322,8 +331,9 @@ discard block |
||
322 | 331 | } |
323 | 332 | |
324 | 333 | public function setGalaxyID($galaxyID) { |
325 | - if ($this->galaxyID == $galaxyID) |
|
326 | - return; |
|
334 | + if ($this->galaxyID == $galaxyID) { |
|
335 | + return; |
|
336 | + } |
|
327 | 337 | $this->galaxyID = $galaxyID; |
328 | 338 | $this->hasChanged = true; |
329 | 339 | } |
@@ -334,18 +344,21 @@ discard block |
||
334 | 344 | |
335 | 345 | public function getNumberOfLinks() { |
336 | 346 | $num = 0; |
337 | - if (!is_array($this->getLinks())) |
|
338 | - return $num; |
|
339 | - foreach ($this->getLinks() as $link) |
|
340 | - if ($link !== 0) |
|
347 | + if (!is_array($this->getLinks())) { |
|
348 | + return $num; |
|
349 | + } |
|
350 | + foreach ($this->getLinks() as $link) { |
|
351 | + if ($link !== 0) |
|
341 | 352 | $num++; |
353 | + } |
|
342 | 354 | return $num; |
343 | 355 | } |
344 | 356 | |
345 | 357 | public function getNumberOfConnections() { |
346 | 358 | $links = $this->getNumberOfLinks(); |
347 | - if ($this->hasWarp()) |
|
348 | - $links++; |
|
359 | + if ($this->hasWarp()) { |
|
360 | + $links++; |
|
361 | + } |
|
349 | 362 | return $links; |
350 | 363 | } |
351 | 364 | |
@@ -354,30 +367,35 @@ discard block |
||
354 | 367 | } |
355 | 368 | |
356 | 369 | public function getNeighbourID($dir) { |
357 | - if ($this->hasLink($dir)) |
|
358 | - return $this->getLink($dir); |
|
370 | + if ($this->hasLink($dir)) { |
|
371 | + return $this->getLink($dir); |
|
372 | + } |
|
359 | 373 | $galaxy = $this->getGalaxy(); |
360 | 374 | $neighbour = $this->getSectorID(); |
361 | 375 | switch ($dir) { |
362 | 376 | case 'Up': |
363 | 377 | $neighbour -= $galaxy->getWidth(); |
364 | - if ($neighbour < $galaxy->getStartSector()) |
|
365 | - $neighbour += $galaxy->getSize(); |
|
378 | + if ($neighbour < $galaxy->getStartSector()) { |
|
379 | + $neighbour += $galaxy->getSize(); |
|
380 | + } |
|
366 | 381 | break; |
367 | 382 | case 'Down': |
368 | 383 | $neighbour += $galaxy->getWidth(); |
369 | - if ($neighbour > $galaxy->getEndSector()) |
|
370 | - $neighbour -= $galaxy->getSize(); |
|
384 | + if ($neighbour > $galaxy->getEndSector()) { |
|
385 | + $neighbour -= $galaxy->getSize(); |
|
386 | + } |
|
371 | 387 | break; |
372 | 388 | case 'Left': |
373 | 389 | $neighbour -= 1; |
374 | - if ((1 + $neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) |
|
375 | - $neighbour += $galaxy->getWidth(); |
|
390 | + if ((1 + $neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) { |
|
391 | + $neighbour += $galaxy->getWidth(); |
|
392 | + } |
|
376 | 393 | break; |
377 | 394 | case 'Right': |
378 | 395 | $neighbour += 1; |
379 | - if (($neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) |
|
380 | - $neighbour -= $galaxy->getWidth(); |
|
396 | + if (($neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) { |
|
397 | + $neighbour -= $galaxy->getWidth(); |
|
398 | + } |
|
381 | 399 | break; |
382 | 400 | default: |
383 | 401 | throw new Exception($dir . ': is not a valid direction'); |
@@ -386,13 +404,16 @@ discard block |
||
386 | 404 | } |
387 | 405 | |
388 | 406 | public function getSectorDirection($sectorID) { |
389 | - if ($sectorID == $this->getSectorID()) |
|
390 | - return 'Current'; |
|
407 | + if ($sectorID == $this->getSectorID()) { |
|
408 | + return 'Current'; |
|
409 | + } |
|
391 | 410 | $dir = array_search($sectorID, $this->getLinks()); |
392 | - if ($dir !== false) |
|
393 | - return $dir; |
|
394 | - if ($sectorID == $this->getWarp()) |
|
395 | - return 'Warp'; |
|
411 | + if ($dir !== false) { |
|
412 | + return $dir; |
|
413 | + } |
|
414 | + if ($sectorID == $this->getWarp()) { |
|
415 | + return 'Warp'; |
|
416 | + } |
|
396 | 417 | return 'None'; |
397 | 418 | } |
398 | 419 | |
@@ -417,8 +438,9 @@ discard block |
||
417 | 438 | } |
418 | 439 | |
419 | 440 | public function getLinkSector($name) { |
420 | - if ($this->hasLink($name)) |
|
421 | - return SmrSector::getSector($this->getGameID(), $this->getLink($name)); |
|
441 | + if ($this->hasLink($name)) { |
|
442 | + return SmrSector::getSector($this->getGameID(), $this->getLink($name)); |
|
443 | + } |
|
422 | 444 | return false; |
423 | 445 | } |
424 | 446 | |
@@ -426,12 +448,14 @@ discard block |
||
426 | 448 | * Cannot be used for Warps |
427 | 449 | */ |
428 | 450 | public function setLink($name, $linkID) { |
429 | - if ($this->getLink($name) == $linkID) |
|
430 | - return; |
|
431 | - if ($linkID == 0) |
|
432 | - unset($this->links[$name]); |
|
433 | - else |
|
434 | - $this->links[$name] = $linkID; |
|
451 | + if ($this->getLink($name) == $linkID) { |
|
452 | + return; |
|
453 | + } |
|
454 | + if ($linkID == 0) { |
|
455 | + unset($this->links[$name]); |
|
456 | + } else { |
|
457 | + $this->links[$name] = $linkID; |
|
458 | + } |
|
435 | 459 | $this->hasChanged = true; |
436 | 460 | } |
437 | 461 | |
@@ -439,8 +463,9 @@ discard block |
||
439 | 463 | * Cannot be used for Warps |
440 | 464 | */ |
441 | 465 | public function setLinkSector($dir, SmrSector $linkSector) { |
442 | - if ($this->getLink($dir) == $linkSector->getSectorID() || $linkSector->equals($this)) |
|
443 | - return; |
|
466 | + if ($this->getLink($dir) == $linkSector->getSectorID() || $linkSector->equals($this)) { |
|
467 | + return; |
|
468 | + } |
|
444 | 469 | $this->setLink($dir, $linkSector->getSectorID()); |
445 | 470 | $linkSector->setLink(self::oppositeDir($dir), $this->getSectorID()); |
446 | 471 | $this->hasChanged = true; |
@@ -464,8 +489,7 @@ discard block |
||
464 | 489 | public function toggleLink($dir) { |
465 | 490 | if ($this->hasLink($dir)) { |
466 | 491 | $this->disableLink($dir); |
467 | - } |
|
468 | - else { |
|
492 | + } else { |
|
469 | 493 | $this->enableLink($dir); |
470 | 494 | } |
471 | 495 | } |
@@ -629,21 +653,25 @@ discard block |
||
629 | 653 | $locations = SmrLocation::getSectorLocations($this->getGameID(), $this->getSectorID()); |
630 | 654 | $hasAction = false; |
631 | 655 | foreach ($locations as $location) { |
632 | - if ($location->hasAction()) |
|
633 | - $hasAction = true; |
|
656 | + if ($location->hasAction()) { |
|
657 | + $hasAction = true; |
|
658 | + } |
|
634 | 659 | } |
635 | 660 | return $hasAction; |
636 | 661 | } |
637 | 662 | |
638 | 663 | public function hasLocation($locationTypeID = false) { |
639 | 664 | $locations = $this->getLocations(); |
640 | - if (count($locations) == 0) |
|
641 | - return false; |
|
642 | - if ($locationTypeID == false) |
|
643 | - return true; |
|
665 | + if (count($locations) == 0) { |
|
666 | + return false; |
|
667 | + } |
|
668 | + if ($locationTypeID == false) { |
|
669 | + return true; |
|
670 | + } |
|
644 | 671 | foreach ($locations as $location) { |
645 | - if ($location->getTypeID() == $locationTypeID) |
|
646 | - return true; |
|
672 | + if ($location->getTypeID() == $locationTypeID) { |
|
673 | + return true; |
|
674 | + } |
|
647 | 675 | } |
648 | 676 | return false; |
649 | 677 | } |
@@ -703,11 +731,13 @@ discard block |
||
703 | 731 | } |
704 | 732 | |
705 | 733 | public function hasEnemyForces(AbstractSmrPlayer $player = null) { |
706 | - if ($player == null || !$this->hasForces()) |
|
707 | - return false; |
|
734 | + if ($player == null || !$this->hasForces()) { |
|
735 | + return false; |
|
736 | + } |
|
708 | 737 | foreach ($this->getForces() as $force) { |
709 | - if (!$player->forceNAPAlliance($force->getOwner())) |
|
710 | - return true; |
|
738 | + if (!$player->forceNAPAlliance($force->getOwner())) { |
|
739 | + return true; |
|
740 | + } |
|
711 | 741 | } |
712 | 742 | return false; |
713 | 743 | } |
@@ -715,8 +745,9 @@ discard block |
||
715 | 745 | public function getEnemyForces(AbstractSmrPlayer $player) { |
716 | 746 | $enemyForces = array(); |
717 | 747 | foreach ($this->getForces() as $force) { |
718 | - if (!$player->forceNAPAlliance($force->getOwner())) |
|
719 | - $enemyForces[] = $force; |
|
748 | + if (!$player->forceNAPAlliance($force->getOwner())) { |
|
749 | + $enemyForces[] = $force; |
|
750 | + } |
|
720 | 751 | } |
721 | 752 | return $enemyForces; |
722 | 753 | } |
@@ -734,11 +765,13 @@ discard block |
||
734 | 765 | } |
735 | 766 | |
736 | 767 | public function hasFriendlyForces(AbstractSmrPlayer $player = null) { |
737 | - if ($player == null || !$this->hasForces()) |
|
738 | - return false; |
|
768 | + if ($player == null || !$this->hasForces()) { |
|
769 | + return false; |
|
770 | + } |
|
739 | 771 | foreach ($this->getForces() as $force) { |
740 | - if ($player->forceNAPAlliance($force->getOwner())) |
|
741 | - return true; |
|
772 | + if ($player->forceNAPAlliance($force->getOwner())) { |
|
773 | + return true; |
|
774 | + } |
|
742 | 775 | } |
743 | 776 | return false; |
744 | 777 | } |
@@ -746,8 +779,9 @@ discard block |
||
746 | 779 | public function getFriendlyForces(AbstractSmrPlayer $player) { |
747 | 780 | $friendlyForces = array(); |
748 | 781 | foreach ($this->getForces() as $force) { |
749 | - if ($player->forceNAPAlliance($force->getOwner())) |
|
750 | - $friendlyForces[] = $force; |
|
782 | + if ($player->forceNAPAlliance($force->getOwner())) { |
|
783 | + $friendlyForces[] = $force; |
|
784 | + } |
|
751 | 785 | } |
752 | 786 | return $friendlyForces; |
753 | 787 | } |
@@ -775,8 +809,9 @@ discard block |
||
775 | 809 | } |
776 | 810 | |
777 | 811 | public function hasEnemyTraders(AbstractSmrPlayer $player = null) { |
778 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
779 | - return false; |
|
812 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
813 | + return false; |
|
814 | + } |
|
780 | 815 | $otherPlayers = $this->getOtherTraders($player); |
781 | 816 | foreach ($otherPlayers as $otherPlayer) { |
782 | 817 | if (!$player->traderNAPAlliance($otherPlayer) |
@@ -789,12 +824,14 @@ discard block |
||
789 | 824 | } |
790 | 825 | |
791 | 826 | public function hasFriendlyTraders(AbstractSmrPlayer $player = null) { |
792 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
793 | - return false; |
|
827 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
828 | + return false; |
|
829 | + } |
|
794 | 830 | $otherPlayers = $this->getOtherTraders($player); |
795 | 831 | foreach ($otherPlayers as $otherPlayer) { |
796 | - if ($player->traderNAPAlliance($otherPlayer)) |
|
797 | - return true; |
|
832 | + if ($player->traderNAPAlliance($otherPlayer)) { |
|
833 | + return true; |
|
834 | + } |
|
798 | 835 | } |
799 | 836 | return false; |
800 | 837 | } |
@@ -816,8 +853,9 @@ discard block |
||
816 | 853 | } |
817 | 854 | |
818 | 855 | public function hasProtectedTraders(AbstractSmrPlayer $player = null) { |
819 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
820 | - return false; |
|
856 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
857 | + return false; |
|
858 | + } |
|
821 | 859 | $otherPlayers = $this->getOtherTraders($player); |
822 | 860 | foreach ($otherPlayers as $otherPlayer) { |
823 | 861 | if (!$player->traderNAPAlliance($otherPlayer) |
@@ -853,8 +891,9 @@ discard block |
||
853 | 891 | $planetOwner = $defendingPlanet->getOwner(); |
854 | 892 | foreach ($alliancePlayers as $accountID => $player) { |
855 | 893 | if ($player->canFight()) { |
856 | - if ($attackingPlayer->traderAttackPlanetAlliance($player) && !$planetOwner->planetNAPAlliance($player)) |
|
857 | - $fightingPlayers[$accountID] = $alliancePlayers[$accountID]; |
|
894 | + if ($attackingPlayer->traderAttackPlanetAlliance($player) && !$planetOwner->planetNAPAlliance($player)) { |
|
895 | + $fightingPlayers[$accountID] = $alliancePlayers[$accountID]; |
|
896 | + } |
|
858 | 897 | } |
859 | 898 | } |
860 | 899 | } |
@@ -862,8 +901,9 @@ discard block |
||
862 | 901 | } |
863 | 902 | |
864 | 903 | public function getFightingTraders(AbstractSmrPlayer $attackingPlayer, AbstractSmrPlayer $defendingPlayer, $checkForCloak = false) { |
865 | - if ($attackingPlayer->traderNAPAlliance($defendingPlayer)) |
|
866 | - throw new Exception('These traders are NAPed.'); |
|
904 | + if ($attackingPlayer->traderNAPAlliance($defendingPlayer)) { |
|
905 | + throw new Exception('These traders are NAPed.'); |
|
906 | + } |
|
867 | 907 | $fightingPlayers = array('Attackers' => array(), 'Defenders' => array()); |
868 | 908 | $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(), $this->getSectorID(), array($attackingPlayer->getAllianceID(), $defendingPlayer->getAllianceID())); |
869 | 909 | $attackers = array(); |
@@ -923,8 +963,9 @@ discard block |
||
923 | 963 | } |
924 | 964 | |
925 | 965 | public function setBattles($amount) { |
926 | - if ($this->battles == $amount) |
|
927 | - return; |
|
966 | + if ($this->battles == $amount) { |
|
967 | + return; |
|
968 | + } |
|
928 | 969 | $this->battles = $amount; |
929 | 970 | $this->hasChanged = true; |
930 | 971 | } |
@@ -946,8 +987,9 @@ discard block |
||
946 | 987 | } |
947 | 988 | |
948 | 989 | public function isVisited(AbstractSmrPlayer $player = null) { |
949 | - if ($player === null) |
|
950 | - return true; |
|
990 | + if ($player === null) { |
|
991 | + return true; |
|
992 | + } |
|
951 | 993 | if (!isset($this->visited[$player->getAccountID()])) { |
952 | 994 | $this->db->query('SELECT sector_id FROM player_visited_sector WHERE ' . $this->SQL . ' AND account_id=' . $this->db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); |
953 | 995 | $this->visited[$player->getAccountID()] = !$this->db->nextRecord(); |
@@ -988,10 +1030,12 @@ discard block |
||
988 | 1030 | return $x->contains($this); |
989 | 1031 | } |
990 | 1032 | |
991 | - if (is_array($x) && $x['Type'] == 'Good') //Check if it's possible for port to have X, hacky but nice performance gains |
|
1033 | + if (is_array($x) && $x['Type'] == 'Good') { |
|
1034 | + //Check if it's possible for port to have X, hacky but nice performance gains |
|
992 | 1035 | if ($this->hasPort()) |
993 | 1036 | if ($this->getPort()->hasX($x)) |
994 | 1037 | return true; |
1038 | + } |
|
995 | 1039 | |
996 | 1040 | //Check if it's possible for location to have X, hacky but nice performance gains |
997 | 1041 | if ($x instanceof SmrWeapon || (is_array($x) && ($x['Type'] == 'Ship' || $x['Type'] == 'Hardware')) || (is_string($x) && ($x == 'Bank' || $x == 'Bar' || $x == 'Fed' || $x == 'SafeFed' || $x == 'HQ' || $x == 'UG' || $x == 'Hardware' || $x == 'Ship' || $x == 'Weapon'))) { |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | /** |
208 | 208 | * Insert a new player into the database. Returns the new player object. |
209 | 209 | */ |
210 | - public static function createPlayer($accountID, $gameID, $playerName, $raceID, $isNewbie, $npc=false) { |
|
210 | + public static function createPlayer($accountID, $gameID, $playerName, $raceID, $isNewbie, $npc = false) { |
|
211 | 211 | // Put the player in a sector with an HQ |
212 | 212 | $startSectorID = self::getHome($gameID, $raceID); |
213 | 213 | |
@@ -1163,13 +1163,13 @@ discard block |
||
1163 | 1163 | $this->db->query('SELECT type,amount FROM player_hof WHERE ' . $this->SQL); |
1164 | 1164 | $this->HOF = array(); |
1165 | 1165 | while ($this->db->nextRecord()) { |
1166 | - $hof =& $this->HOF; |
|
1166 | + $hof = & $this->HOF; |
|
1167 | 1167 | $typeList = explode(':', $this->db->getField('type')); |
1168 | 1168 | foreach ($typeList as $type) { |
1169 | 1169 | if (!isset($hof[$type])) { |
1170 | 1170 | $hof[$type] = array(); |
1171 | 1171 | } |
1172 | - $hof =& $hof[$type]; |
|
1172 | + $hof = & $hof[$type]; |
|
1173 | 1173 | } |
1174 | 1174 | $hof = $this->db->getFloat('amount'); |
1175 | 1175 | } |
@@ -1611,7 +1611,7 @@ discard block |
||
1611 | 1611 | create_error('The saved sector must be in the box!'); |
1612 | 1612 | } |
1613 | 1613 | |
1614 | - $storedDestinations =& $this->getStoredDestinations(); |
|
1614 | + $storedDestinations = & $this->getStoredDestinations(); |
|
1615 | 1615 | foreach ($storedDestinations as &$sd) { |
1616 | 1616 | if ($sd['SectorID'] == $sectorID) { |
1617 | 1617 | $sd['OffsetTop'] = $offsetTop; |
@@ -58,8 +58,9 @@ discard block |
||
58 | 58 | public static function getSectorPlayersByAlliances($gameID, $sectorID, array $allianceIDs, $forceUpdate = false) { |
59 | 59 | $players = self::getSectorPlayers($gameID, $sectorID, $forceUpdate); // Don't use & as we do an unset |
60 | 60 | foreach ($players as $accountID => $player) { |
61 | - if (!in_array($player->getAllianceID(), $allianceIDs)) |
|
62 | - unset($players[$accountID]); |
|
61 | + if (!in_array($player->getAllianceID(), $allianceIDs)) { |
|
62 | + unset($players[$accountID]); |
|
63 | + } |
|
63 | 64 | } |
64 | 65 | return $players; |
65 | 66 | } |
@@ -198,8 +199,7 @@ discard block |
||
198 | 199 | $this->newbieWarning = $db->getBoolean('newbie_warning'); |
199 | 200 | $this->nameChanged = $db->getBoolean('name_changed'); |
200 | 201 | $this->combatDronesKamikazeOnMines = $db->getBoolean('combat_drones_kamikaze_on_mines'); |
201 | - } |
|
202 | - else { |
|
202 | + } else { |
|
203 | 203 | throw new PlayerNotFoundException('Invalid accountID: ' . $accountID . ' OR gameID:' . $gameID); |
204 | 204 | } |
205 | 205 | } |
@@ -285,22 +285,25 @@ discard block |
||
285 | 285 | protected function setZoom($zoom) { |
286 | 286 | // Set the zoom level between [1, 9] |
287 | 287 | $zoom = max(1, min(9, $zoom)); |
288 | - if ($this->zoom == $zoom) |
|
289 | - return; |
|
288 | + if ($this->zoom == $zoom) { |
|
289 | + return; |
|
290 | + } |
|
290 | 291 | $this->zoom = $zoom; |
291 | 292 | $this->hasChanged = true; |
292 | 293 | // $this->db->query('UPDATE player SET zoom = ' . $zoom . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
293 | 294 | } |
294 | 295 | |
295 | 296 | public function increaseZoom($zoom) { |
296 | - if ($zoom < 0) |
|
297 | - throw new Exception('Trying to increase negative zoom.'); |
|
297 | + if ($zoom < 0) { |
|
298 | + throw new Exception('Trying to increase negative zoom.'); |
|
299 | + } |
|
298 | 300 | $this->setZoom($this->getZoom() + $zoom); |
299 | 301 | } |
300 | 302 | |
301 | 303 | public function decreaseZoom($zoom) { |
302 | - if ($zoom < 0) |
|
303 | - throw new Exception('Trying to decrease negative zoom.'); |
|
304 | + if ($zoom < 0) { |
|
305 | + throw new Exception('Trying to decrease negative zoom.'); |
|
306 | + } |
|
304 | 307 | $this->setZoom($this->getZoom() - $zoom); |
305 | 308 | } |
306 | 309 | |
@@ -315,8 +318,9 @@ discard block |
||
315 | 318 | } |
316 | 319 | |
317 | 320 | public function setLastSectorID($lastSectorID) { |
318 | - if ($this->lastSectorID == $lastSectorID) |
|
319 | - return; |
|
321 | + if ($this->lastSectorID == $lastSectorID) { |
|
322 | + return; |
|
323 | + } |
|
320 | 324 | $this->lastSectorID = $lastSectorID; |
321 | 325 | $this->hasChanged = true; |
322 | 326 | // $this->db->query('UPDATE player SET last_sector_id = '.$this->lastSectorID.' WHERE '.$this->SQL.' LIMIT 1'); |
@@ -329,11 +333,9 @@ discard block |
||
329 | 333 | $kickedBy->sendMessage($this->getAccountID(), MSG_PLAYER, 'You were kicked out of the alliance!', false); |
330 | 334 | $this->actionTaken('PlayerKicked', array('Alliance' => $alliance, 'Player' => $kickedBy)); |
331 | 335 | $kickedBy->actionTaken('KickPlayer', array('Alliance' => $alliance, 'Player' => $this)); |
332 | - } |
|
333 | - else if ($this->isAllianceLeader()) { |
|
336 | + } else if ($this->isAllianceLeader()) { |
|
334 | 337 | $this->actionTaken('DisbandAlliance', array('Alliance' => $alliance)); |
335 | - } |
|
336 | - else { |
|
338 | + } else { |
|
337 | 339 | $this->actionTaken('LeaveAlliance', array('Alliance' => $alliance)); |
338 | 340 | if ($alliance->getLeaderID() != 0 && $alliance->getLeaderID() != ACCOUNT_ID_NHL) { |
339 | 341 | $this->sendMessage($alliance->getLeaderID(), MSG_PLAYER, 'I left your alliance!', false); |
@@ -361,7 +363,9 @@ discard block |
||
361 | 363 | try { |
362 | 364 | $this->sendMessage($alliance->getLeaderID(), MSG_PLAYER, 'I joined your alliance!', false); |
363 | 365 | } catch (AccountNotFoundException $e) { |
364 | - if ($alliance->getLeaderID() != ACCOUNT_ID_NHL) throw $e; |
|
366 | + if ($alliance->getLeaderID() != ACCOUNT_ID_NHL) { |
|
367 | + throw $e; |
|
368 | + } |
|
365 | 369 | } |
366 | 370 | |
367 | 371 | $roleID = ALLIANCE_ROLE_NEW_MEMBER; |
@@ -381,8 +385,9 @@ discard block |
||
381 | 385 | } |
382 | 386 | |
383 | 387 | private function setAllianceJoinable($time) { |
384 | - if ($this->allianceJoinable == $time) |
|
385 | - return; |
|
388 | + if ($this->allianceJoinable == $time) { |
|
389 | + return; |
|
390 | + } |
|
386 | 391 | $this->allianceJoinable = $time; |
387 | 392 | $this->hasChanged = true; |
388 | 393 | } |
@@ -392,8 +397,9 @@ discard block |
||
392 | 397 | } |
393 | 398 | |
394 | 399 | public function setAttackColour($colour) { |
395 | - if ($this->attackColour == $colour) |
|
396 | - return; |
|
400 | + if ($this->attackColour == $colour) { |
|
401 | + return; |
|
402 | + } |
|
397 | 403 | $this->attackColour = $colour; |
398 | 404 | $this->hasChanged = true; |
399 | 405 | // $this->db->query('UPDATE player SET attack_warning = ' . $this->db->escapeString($this->attackColour) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
@@ -404,28 +410,35 @@ discard block |
||
404 | 410 | } |
405 | 411 | |
406 | 412 | public function increaseBank($credits) { |
407 | - if ($credits < 0) |
|
408 | - throw new Exception('Trying to increase negative credits.'); |
|
409 | - if ($credits == 0) |
|
410 | - return; |
|
413 | + if ($credits < 0) { |
|
414 | + throw new Exception('Trying to increase negative credits.'); |
|
415 | + } |
|
416 | + if ($credits == 0) { |
|
417 | + return; |
|
418 | + } |
|
411 | 419 | $credits += $this->bank; |
412 | 420 | $this->setBank($credits); |
413 | 421 | } |
414 | 422 | public function decreaseBank($credits) { |
415 | - if ($credits < 0) |
|
416 | - throw new Exception('Trying to decrease negative credits.'); |
|
417 | - if ($credits == 0) |
|
418 | - return; |
|
423 | + if ($credits < 0) { |
|
424 | + throw new Exception('Trying to decrease negative credits.'); |
|
425 | + } |
|
426 | + if ($credits == 0) { |
|
427 | + return; |
|
428 | + } |
|
419 | 429 | $credits = $this->bank - $credits; |
420 | 430 | $this->setBank($credits); |
421 | 431 | } |
422 | 432 | public function setBank($credits) { |
423 | - if ($this->bank == $credits) |
|
424 | - return; |
|
425 | - if ($credits < 0) |
|
426 | - throw new Exception('Trying to set negative credits.'); |
|
427 | - if ($credits > MAX_MONEY) |
|
428 | - throw new Exception('Trying to set more than max credits.'); |
|
433 | + if ($this->bank == $credits) { |
|
434 | + return; |
|
435 | + } |
|
436 | + if ($credits < 0) { |
|
437 | + throw new Exception('Trying to set negative credits.'); |
|
438 | + } |
|
439 | + if ($credits > MAX_MONEY) { |
|
440 | + throw new Exception('Trying to set more than max credits.'); |
|
441 | + } |
|
429 | 442 | $this->bank = $credits; |
430 | 443 | $this->hasChanged = true; |
431 | 444 | // $this->db->query('UPDATE player SET bank = '.$this->bank.' WHERE '.$this->SQL.' LIMIT 1'); |
@@ -436,8 +449,9 @@ discard block |
||
436 | 449 | } |
437 | 450 | |
438 | 451 | private function setLastNewsUpdate($time) { |
439 | - if ($this->lastNewsUpdate == $time) |
|
440 | - return; |
|
452 | + if ($this->lastNewsUpdate == $time) { |
|
453 | + return; |
|
454 | + } |
|
441 | 455 | $this->lastNewsUpdate = $time; |
442 | 456 | $this->hasChanged = true; |
443 | 457 | // $this->db->query('UPDATE player SET last_news_update = ' . $time . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
@@ -484,7 +498,9 @@ discard block |
||
484 | 498 | |
485 | 499 | public function updateTurns() { |
486 | 500 | // is account validated? |
487 | - if (!$this->getAccount()->isValidated()) return; |
|
501 | + if (!$this->getAccount()->isValidated()) { |
|
502 | + return; |
|
503 | + } |
|
488 | 504 | |
489 | 505 | // how many turns would he get right now? |
490 | 506 | $extraTurns = $this->getTurnsGained(TIME); |
@@ -503,8 +519,9 @@ discard block |
||
503 | 519 | } |
504 | 520 | |
505 | 521 | public function setIgnoreGlobals($bool) { |
506 | - if ($this->ignoreGlobals == $bool) |
|
507 | - return; |
|
522 | + if ($this->ignoreGlobals == $bool) { |
|
523 | + return; |
|
524 | + } |
|
508 | 525 | $this->ignoreGlobals = $bool; |
509 | 526 | $this->hasChanged = true; |
510 | 527 | // $this->db->query('UPDATE player SET ignore_globals = '.$this->db->escapeBoolean($bool).' WHERE '.$this->SQL.' LIMIT 1'); |
@@ -516,8 +533,9 @@ discard block |
||
516 | 533 | } |
517 | 534 | |
518 | 535 | public function setLastPort($lastPort) { |
519 | - if ($this->lastPort == $lastPort) |
|
520 | - return; |
|
536 | + if ($this->lastPort == $lastPort) { |
|
537 | + return; |
|
538 | + } |
|
521 | 539 | $this->lastPort = $lastPort; |
522 | 540 | $this->hasChanged = true; |
523 | 541 | // $this->db->query('UPDATE player SET last_port = ' . $this->lastPort . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
@@ -528,8 +546,9 @@ discard block |
||
528 | 546 | } |
529 | 547 | |
530 | 548 | public function setDisplayMissions($bool) { |
531 | - if ($this->displayMissions == $bool) |
|
532 | - return; |
|
549 | + if ($this->displayMissions == $bool) { |
|
550 | + return; |
|
551 | + } |
|
533 | 552 | $this->displayMissions = $bool; |
534 | 553 | $this->hasChanged = true; |
535 | 554 | } |
@@ -544,8 +563,9 @@ discard block |
||
544 | 563 | * which does not acquire a sector lock. |
545 | 564 | */ |
546 | 565 | public function setDisplayWeapons($bool) { |
547 | - if ($this->displayWeapons == $bool) |
|
548 | - return; |
|
566 | + if ($this->displayWeapons == $bool) { |
|
567 | + return; |
|
568 | + } |
|
549 | 569 | $this->displayWeapons = $bool; |
550 | 570 | $this->db->query('UPDATE player SET display_weapons=' . $this->db->escapeBoolean($this->displayWeapons) . ' WHERE ' . $this->SQL); |
551 | 571 | } |
@@ -555,8 +575,9 @@ discard block |
||
555 | 575 | } |
556 | 576 | |
557 | 577 | public function setForceDropMessages($bool) { |
558 | - if ($this->forceDropMessages == $bool) |
|
559 | - return; |
|
578 | + if ($this->forceDropMessages == $bool) { |
|
579 | + return; |
|
580 | + } |
|
560 | 581 | $this->forceDropMessages = $bool; |
561 | 582 | $this->hasChanged = true; |
562 | 583 | } |
@@ -588,8 +609,9 @@ discard block |
||
588 | 609 | } |
589 | 610 | |
590 | 611 | public function setLastTurnUpdate($time) { |
591 | - if ($this->lastTurnUpdate == $time) |
|
592 | - return; |
|
612 | + if ($this->lastTurnUpdate == $time) { |
|
613 | + return; |
|
614 | + } |
|
593 | 615 | $this->lastTurnUpdate = $time; |
594 | 616 | $this->hasChanged = true; |
595 | 617 | // $sql = $this->db->query('UPDATE player SET last_turn_update = ' . $this->lastTurnUpdate . ' WHERE '. $this->SQL . ' LIMIT 1'); |
@@ -629,27 +651,33 @@ discard block |
||
629 | 651 | } |
630 | 652 | |
631 | 653 | public function increaseRelations($relations, $raceID) { |
632 | - if ($relations < 0) |
|
633 | - throw new Exception('Trying to increase negative relations.'); |
|
634 | - if ($relations == 0) |
|
635 | - return; |
|
654 | + if ($relations < 0) { |
|
655 | + throw new Exception('Trying to increase negative relations.'); |
|
656 | + } |
|
657 | + if ($relations == 0) { |
|
658 | + return; |
|
659 | + } |
|
636 | 660 | $relations += $this->getPureRelation($raceID); |
637 | 661 | $this->setRelations($relations, $raceID); |
638 | 662 | } |
639 | 663 | public function decreaseRelations($relations, $raceID) { |
640 | - if ($relations < 0) |
|
641 | - throw new Exception('Trying to decrease negative relations.'); |
|
642 | - if ($relations == 0) |
|
643 | - return; |
|
664 | + if ($relations < 0) { |
|
665 | + throw new Exception('Trying to decrease negative relations.'); |
|
666 | + } |
|
667 | + if ($relations == 0) { |
|
668 | + return; |
|
669 | + } |
|
644 | 670 | $relations = $this->getPureRelation($raceID) - $relations; |
645 | 671 | $this->setRelations($relations, $raceID); |
646 | 672 | } |
647 | 673 | public function setRelations($relations, $raceID) { |
648 | 674 | $this->getRelations(); |
649 | - if ($this->pureRelations[$raceID] == $relations) |
|
650 | - return; |
|
651 | - if ($relations < MIN_RELATIONS) |
|
652 | - $relations = MIN_RELATIONS; |
|
675 | + if ($this->pureRelations[$raceID] == $relations) { |
|
676 | + return; |
|
677 | + } |
|
678 | + if ($relations < MIN_RELATIONS) { |
|
679 | + $relations = MIN_RELATIONS; |
|
680 | + } |
|
653 | 681 | $relationsDiff = IRound($relations - $this->pureRelations[$raceID]); |
654 | 682 | $this->pureRelations[$raceID] = $relations; |
655 | 683 | $this->relations[$raceID] += $relationsDiff; |
@@ -684,8 +712,7 @@ discard block |
||
684 | 712 | $this->db->query('SELECT * FROM ship_has_name WHERE ' . $this->SQL . ' LIMIT 1'); |
685 | 713 | if ($this->db->nextRecord()) { |
686 | 714 | $this->customShipName = $this->db->getField('ship_name'); |
687 | - } |
|
688 | - else { |
|
715 | + } else { |
|
689 | 716 | $this->customShipName = false; |
690 | 717 | } |
691 | 718 | } |
@@ -703,8 +730,7 @@ discard block |
||
703 | 730 | $this->knowledge['Nyx'] = $this->db->getInt('nyx'); |
704 | 731 | $this->knowledge['Federation'] = 0; |
705 | 732 | $this->knowledge['Underground'] = 0; |
706 | - } |
|
707 | - else { |
|
733 | + } else { |
|
708 | 734 | $this->knowledge['Erebus'] = 0; |
709 | 735 | $this->knowledge['Aether'] = 0; |
710 | 736 | $this->knowledge['Tartarus'] = 0; |
@@ -713,10 +739,12 @@ discard block |
||
713 | 739 | $this->knowledge['Underground'] = 0; |
714 | 740 | } |
715 | 741 | } |
716 | - if ($knowledgeType === false) |
|
717 | - return $this->knowledge; |
|
718 | - if (isset($this->knowledge[$knowledgeType])) |
|
719 | - return $this->knowledge[$knowledgeType]; |
|
742 | + if ($knowledgeType === false) { |
|
743 | + return $this->knowledge; |
|
744 | + } |
|
745 | + if (isset($this->knowledge[$knowledgeType])) { |
|
746 | + return $this->knowledge[$knowledgeType]; |
|
747 | + } |
|
720 | 748 | return false; |
721 | 749 | } |
722 | 750 | |
@@ -729,9 +757,10 @@ discard block |
||
729 | 757 | $sector->diedHere($this); |
730 | 758 | |
731 | 759 | // if we are in an alliance we increase their deaths |
732 | - if ($this->hasAlliance()) |
|
733 | - $this->db->query('UPDATE alliance SET alliance_deaths = alliance_deaths + 1 |
|
760 | + if ($this->hasAlliance()) { |
|
761 | + $this->db->query('UPDATE alliance SET alliance_deaths = alliance_deaths + 1 |
|
734 | 762 | WHERE game_id = ' . $this->db->escapeNumber($this->getGameID()) . ' AND alliance_id = ' . $this->db->escapeNumber($this->getAllianceID()) . ' LIMIT 1'); |
763 | + } |
|
735 | 764 | |
736 | 765 | // record death stat |
737 | 766 | $this->increaseHOF(1, array('Dying', 'Deaths'), HOF_PUBLIC); |
@@ -744,8 +773,9 @@ discard block |
||
744 | 773 | $newCredits = IRound($this->getShip()->getCost() / 4); |
745 | 774 | $old_speed = $this->getShip()->getSpeed(); |
746 | 775 | |
747 | - if ($newCredits < 100000) |
|
748 | - $newCredits = 100000; |
|
776 | + if ($newCredits < 100000) { |
|
777 | + $newCredits = 100000; |
|
778 | + } |
|
749 | 779 | $this->setCredits($newCredits); |
750 | 780 | |
751 | 781 | $this->setSectorID($this::getHome($this->getGameID(), $this->getRaceID())); |
@@ -820,14 +850,14 @@ discard block |
||
820 | 850 | $relation = $relations[$killer->getRaceID()]; |
821 | 851 | |
822 | 852 | $alignChangePerRelation = 0.1; |
823 | - if ($relation >= RELATIONS_PEACE || $relation <= RELATIONS_WAR) |
|
824 | - $alignChangePerRelation = 0.04; |
|
853 | + if ($relation >= RELATIONS_PEACE || $relation <= RELATIONS_WAR) { |
|
854 | + $alignChangePerRelation = 0.04; |
|
855 | + } |
|
825 | 856 | |
826 | 857 | $return['KillerAlign'] = -$relation * $alignChangePerRelation; //Lose relations when killing a peaceful race |
827 | 858 | if ($return['KillerAlign'] > 0) { |
828 | 859 | $killer->increaseAlignment($return['KillerAlign']); |
829 | - } |
|
830 | - else { |
|
860 | + } else { |
|
831 | 861 | $killer->decreaseAlignment(-$return['KillerAlign']); |
832 | 862 | } |
833 | 863 | // War setting gives them military pay |
@@ -861,8 +891,7 @@ discard block |
||
861 | 891 | // If the podded players alignment makes them deputy or member then set bounty |
862 | 892 | if ($this->getAlignment() >= 100) { |
863 | 893 | $return['BountyGained']['Type'] = 'HQ'; |
864 | - } |
|
865 | - else if ($this->getAlignment() <= 100) { |
|
894 | + } else if ($this->getAlignment() <= 100) { |
|
866 | 895 | $return['BountyGained']['Type'] = 'UG'; |
867 | 896 | } |
868 | 897 | |
@@ -884,16 +913,14 @@ discard block |
||
884 | 913 | |
885 | 914 | if ($return['KillerAlign'] > 0) { |
886 | 915 | $killer->increaseHOF($return['KillerAlign'], array('Killing', 'NPC', 'Alignment', 'Gain'), HOF_PUBLIC); |
887 | - } |
|
888 | - else { |
|
916 | + } else { |
|
889 | 917 | $killer->increaseHOF(-$return['KillerAlign'], array('Killing', 'NPC', 'Alignment', 'Loss'), HOF_PUBLIC); |
890 | 918 | } |
891 | 919 | |
892 | 920 | $killer->increaseHOF($return['BountyGained']['Amount'], array('Killing', 'NPC', 'Money', 'Bounty Gained'), HOF_PUBLIC); |
893 | 921 | |
894 | 922 | $killer->increaseHOF(1, array('Killing', 'NPC Kills'), HOF_PUBLIC); |
895 | - } |
|
896 | - else { |
|
923 | + } else { |
|
897 | 924 | $killer->increaseHOF($return['KillerExp'], array('Killing', 'Experience', 'Gained'), HOF_PUBLIC); |
898 | 925 | $killer->increaseHOF($this->getExperience(), array('Killing', 'Experience', 'Of Traders Killed'), HOF_PUBLIC); |
899 | 926 | |
@@ -905,8 +932,7 @@ discard block |
||
905 | 932 | |
906 | 933 | if ($return['KillerAlign'] > 0) { |
907 | 934 | $killer->increaseHOF($return['KillerAlign'], array('Killing', 'Alignment', 'Gain'), HOF_PUBLIC); |
908 | - } |
|
909 | - else { |
|
935 | + } else { |
|
910 | 936 | $killer->increaseHOF(-$return['KillerAlign'], array('Killing', 'Alignment', 'Loss'), HOF_PUBLIC); |
911 | 937 | } |
912 | 938 | |
@@ -914,8 +940,7 @@ discard block |
||
914 | 940 | |
915 | 941 | if ($this->getShip()->getAttackRatingWithMaxCDs() <= MAX_ATTACK_RATING_NEWBIE && $this->hasNewbieStatus() && !$killer->hasNewbieStatus()) { //Newbie kill |
916 | 942 | $killer->increaseHOF(1, array('Killing', 'Newbie Kills'), HOF_PUBLIC); |
917 | - } |
|
918 | - else { |
|
943 | + } else { |
|
919 | 944 | $killer->increaseKills(1); |
920 | 945 | $killer->increaseHOF(1, array('Killing', 'Kills'), HOF_PUBLIC); |
921 | 946 | |
@@ -1097,20 +1122,21 @@ discard block |
||
1097 | 1122 | $bountyChanged = false; |
1098 | 1123 | $bounty = $this->getBounty($key); |
1099 | 1124 | if ($bounty['New'] === true) { |
1100 | - if ($bounty['Amount'] > 0 || $bounty['SmrCredits'] > 0) |
|
1101 | - $this->db->query('INSERT INTO bounty (account_id,game_id,type,amount,smr_credits,claimer_id,time) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeString($bounty['Type']) . ',' . $this->db->escapeNumber($bounty['Amount']) . ',' . $this->db->escapeNumber($bounty['SmrCredits']) . ',' . $this->db->escapeNumber($bounty['Claimer']) . ',' . $this->db->escapeNumber($bounty['Time']) . ')'); |
|
1102 | - } |
|
1103 | - else { |
|
1104 | - if ($bounty['Amount'] > 0 || $bounty['SmrCredits'] > 0) |
|
1105 | - $this->db->query('UPDATE bounty |
|
1125 | + if ($bounty['Amount'] > 0 || $bounty['SmrCredits'] > 0) { |
|
1126 | + $this->db->query('INSERT INTO bounty (account_id,game_id,type,amount,smr_credits,claimer_id,time) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeString($bounty['Type']) . ',' . $this->db->escapeNumber($bounty['Amount']) . ',' . $this->db->escapeNumber($bounty['SmrCredits']) . ',' . $this->db->escapeNumber($bounty['Claimer']) . ',' . $this->db->escapeNumber($bounty['Time']) . ')'); |
|
1127 | + } |
|
1128 | + } else { |
|
1129 | + if ($bounty['Amount'] > 0 || $bounty['SmrCredits'] > 0) { |
|
1130 | + $this->db->query('UPDATE bounty |
|
1106 | 1131 | SET amount=' . $this->db->escapeNumber($bounty['Amount']) . ', |
1107 | 1132 | smr_credits=' . $this->db->escapeNumber($bounty['SmrCredits']) . ', |
1108 | 1133 | type=' . $this->db->escapeString($bounty['Type']) . ', |
1109 | 1134 | claimer_id=' . $this->db->escapeNumber($bounty['Claimer']) . ', |
1110 | 1135 | time=' . $this->db->escapeNumber($bounty['Time']) . ' |
1111 | 1136 | WHERE bounty_id=' . $this->db->escapeNumber($bounty['ID']) . ' AND ' . $this->SQL . ' LIMIT 1'); |
1112 | - else |
|
1113 | - $this->db->query('DELETE FROM bounty WHERE bounty_id=' . $this->db->escapeNumber($bounty['ID']) . ' AND ' . $this->SQL . ' LIMIT 1'); |
|
1137 | + } else { |
|
1138 | + $this->db->query('DELETE FROM bounty WHERE bounty_id=' . $this->db->escapeNumber($bounty['ID']) . ' AND ' . $this->SQL . ' LIMIT 1'); |
|
1139 | + } |
|
1114 | 1140 | } |
1115 | 1141 | } |
1116 | 1142 | } |
@@ -1118,14 +1144,16 @@ discard block |
||
1118 | 1144 | } |
1119 | 1145 | |
1120 | 1146 | public function saveHOF() { |
1121 | - if ($this->hasHOFChanged !== false) |
|
1122 | - $this->doHOFSave($this->hasHOFChanged); |
|
1147 | + if ($this->hasHOFChanged !== false) { |
|
1148 | + $this->doHOFSave($this->hasHOFChanged); |
|
1149 | + } |
|
1123 | 1150 | if (!empty(self::$hasHOFVisChanged)) { |
1124 | 1151 | foreach (self::$hasHOFVisChanged as $hofType => $changeType) { |
1125 | - if ($changeType == self::HOF_NEW) |
|
1126 | - $this->db->query('INSERT INTO hof_visibility (type, visibility) VALUES (' . $this->db->escapeString($hofType) . ',' . $this->db->escapeString(self::$HOFVis[$hofType]) . ')'); |
|
1127 | - else |
|
1128 | - $this->db->query('UPDATE hof_visibility SET visibility = ' . $this->db->escapeString(self::$HOFVis[$hofType]) . ' WHERE type = ' . $this->db->escapeString($hofType) . ' LIMIT 1'); |
|
1152 | + if ($changeType == self::HOF_NEW) { |
|
1153 | + $this->db->query('INSERT INTO hof_visibility (type, visibility) VALUES (' . $this->db->escapeString($hofType) . ',' . $this->db->escapeString(self::$HOFVis[$hofType]) . ')'); |
|
1154 | + } else { |
|
1155 | + $this->db->query('UPDATE hof_visibility SET visibility = ' . $this->db->escapeString(self::$HOFVis[$hofType]) . ' WHERE type = ' . $this->db->escapeString($hofType) . ' LIMIT 1'); |
|
1156 | + } |
|
1129 | 1157 | unset(self::$hasHOFVisChanged[$hofType]); |
1130 | 1158 | } |
1131 | 1159 | } |
@@ -1136,14 +1164,13 @@ discard block |
||
1136 | 1164 | $tempTypeList[] = $type; |
1137 | 1165 | if (is_array($hofChanged)) { |
1138 | 1166 | $this->doHOFSave($hofChanged, $tempTypeList); |
1139 | - } |
|
1140 | - else { |
|
1167 | + } else { |
|
1141 | 1168 | $amount = $this->getHOF($tempTypeList); |
1142 | 1169 | if ($hofChanged == self::HOF_NEW) { |
1143 | - if ($amount > 0) |
|
1144 | - $this->db->query('INSERT INTO player_hof (account_id,game_id,type,amount) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeArray($tempTypeList, false, true, ':', false) . ',' . $this->db->escapeNumber($amount) . ')'); |
|
1145 | - } |
|
1146 | - else if ($hofChanged == self::HOF_CHANGED) { |
|
1170 | + if ($amount > 0) { |
|
1171 | + $this->db->query('INSERT INTO player_hof (account_id,game_id,type,amount) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeArray($tempTypeList, false, true, ':', false) . ',' . $this->db->escapeNumber($amount) . ')'); |
|
1172 | + } |
|
1173 | + } else if ($hofChanged == self::HOF_CHANGED) { |
|
1147 | 1174 | // if($amount > 0) |
1148 | 1175 | $this->db->query('UPDATE player_hof |
1149 | 1176 | SET amount=' . $this->db->escapeNumber($amount) . ' |
@@ -1254,11 +1281,12 @@ discard block |
||
1254 | 1281 | $this->tickers = array(); |
1255 | 1282 | //get ticker info |
1256 | 1283 | $this->db->query('SELECT type,time,expires,recent FROM player_has_ticker WHERE ' . $this->SQL . ' AND expires > ' . $this->db->escapeNumber(TIME)); |
1257 | - while ($this->db->nextRecord()) |
|
1258 | - $this->tickers[$this->db->getField('type')] = array('Type' => $this->db->getField('type'), |
|
1284 | + while ($this->db->nextRecord()) { |
|
1285 | + $this->tickers[$this->db->getField('type')] = array('Type' => $this->db->getField('type'), |
|
1259 | 1286 | 'Time' => $this->db->getInt('time'), |
1260 | 1287 | 'Expires' => $this->db->getInt('expires'), |
1261 | 1288 | 'Recent' => $this->db->getField('recent')); |
1289 | + } |
|
1262 | 1290 | } |
1263 | 1291 | return $this->tickers; |
1264 | 1292 | } |
@@ -1269,8 +1297,9 @@ discard block |
||
1269 | 1297 | |
1270 | 1298 | public function getTicker($tickerType) { |
1271 | 1299 | $tickers = $this->getTickers(); |
1272 | - if (isset($tickers[$tickerType])) |
|
1273 | - return $tickers[$tickerType]; |
|
1300 | + if (isset($tickers[$tickerType])) { |
|
1301 | + return $tickers[$tickerType]; |
|
1302 | + } |
|
1274 | 1303 | return false; |
1275 | 1304 | } |
1276 | 1305 | |
@@ -1279,9 +1308,15 @@ discard block |
||
1279 | 1308 | } |
1280 | 1309 | |
1281 | 1310 | public function getTurnsLevel() { |
1282 | - if (!$this->hasTurns()) return 'NONE'; |
|
1283 | - if ($this->getTurns() <= 25) return 'LOW'; |
|
1284 | - if ($this->getTurns() <= 75) return 'MEDIUM'; |
|
1311 | + if (!$this->hasTurns()) { |
|
1312 | + return 'NONE'; |
|
1313 | + } |
|
1314 | + if ($this->getTurns() <= 25) { |
|
1315 | + return 'LOW'; |
|
1316 | + } |
|
1317 | + if ($this->getTurns() <= 75) { |
|
1318 | + return 'MEDIUM'; |
|
1319 | + } |
|
1285 | 1320 | return 'HIGH'; |
1286 | 1321 | } |
1287 | 1322 | |
@@ -1359,8 +1394,9 @@ discard block |
||
1359 | 1394 | |
1360 | 1395 | public function sendGlobalMessage($message, $canBeIgnored = true) { |
1361 | 1396 | if ($canBeIgnored) { |
1362 | - if ($this->getAccount()->isMailBanned()) |
|
1363 | - create_error('You are currently banned from sending messages'); |
|
1397 | + if ($this->getAccount()->isMailBanned()) { |
|
1398 | + create_error('You are currently banned from sending messages'); |
|
1399 | + } |
|
1364 | 1400 | } |
1365 | 1401 | $this->sendMessageToBox(BOX_GLOBALS, $message); |
1366 | 1402 | |
@@ -1383,12 +1419,14 @@ discard block |
||
1383 | 1419 | public function sendMessage($receiverID, $messageTypeID, $message, $canBeIgnored = true, $unread = true, $expires = false, $senderDelete = false) { |
1384 | 1420 | //get expire time |
1385 | 1421 | if ($canBeIgnored) { |
1386 | - if ($this->getAccount()->isMailBanned()) |
|
1387 | - create_error('You are currently banned from sending messages'); |
|
1422 | + if ($this->getAccount()->isMailBanned()) { |
|
1423 | + create_error('You are currently banned from sending messages'); |
|
1424 | + } |
|
1388 | 1425 | // Don't send messages to players ignoring us |
1389 | 1426 | $this->db->query('SELECT account_id FROM message_blacklist WHERE account_id=' . $this->db->escapeNumber($receiverID) . ' AND blacklisted_id=' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
1390 | - if ($this->db->nextRecord()) |
|
1391 | - return; |
|
1427 | + if ($this->db->nextRecord()) { |
|
1428 | + return; |
|
1429 | + } |
|
1392 | 1430 | } |
1393 | 1431 | |
1394 | 1432 | $message = word_filter($message); |
@@ -1469,32 +1507,36 @@ discard block |
||
1469 | 1507 | |
1470 | 1508 | public static function sendMessageFromAdmin($gameID, $receiverID, $message, $expires = false) { |
1471 | 1509 | //get expire time |
1472 | - if ($expires === false) |
|
1473 | - $expires = TIME + 86400 * 365; |
|
1510 | + if ($expires === false) { |
|
1511 | + $expires = TIME + 86400 * 365; |
|
1512 | + } |
|
1474 | 1513 | // send him the message |
1475 | 1514 | self::doMessageSending(ACCOUNT_ID_ADMIN, $receiverID, $gameID, MSG_ADMIN, $message, $expires); |
1476 | 1515 | } |
1477 | 1516 | |
1478 | 1517 | public static function sendMessageFromAllianceAmbassador($gameID, $receiverID, $message, $expires = false) { |
1479 | 1518 | //get expire time |
1480 | - if ($expires === false) |
|
1481 | - $expires = TIME + 86400 * 31; |
|
1519 | + if ($expires === false) { |
|
1520 | + $expires = TIME + 86400 * 31; |
|
1521 | + } |
|
1482 | 1522 | // send him the message |
1483 | 1523 | self::doMessageSending(ACCOUNT_ID_ALLIANCE_AMBASSADOR, $receiverID, $gameID, MSG_ALLIANCE, $message, $expires); |
1484 | 1524 | } |
1485 | 1525 | |
1486 | 1526 | public static function sendMessageFromCasino($gameID, $receiverID, $message, $expires = false) { |
1487 | 1527 | //get expire time |
1488 | - if ($expires === false) |
|
1489 | - $expires = TIME + 86400 * 7; |
|
1528 | + if ($expires === false) { |
|
1529 | + $expires = TIME + 86400 * 7; |
|
1530 | + } |
|
1490 | 1531 | // send him the message |
1491 | 1532 | self::doMessageSending(ACCOUNT_ID_CASINO, $receiverID, $gameID, MSG_CASINO, $message, $expires); |
1492 | 1533 | } |
1493 | 1534 | |
1494 | 1535 | public static function sendMessageFromRace($raceID, $gameID, $receiverID, $message, $expires = false) { |
1495 | 1536 | //get expire time |
1496 | - if ($expires === false) |
|
1497 | - $expires = TIME + 86400 * 5; |
|
1537 | + if ($expires === false) { |
|
1538 | + $expires = TIME + 86400 * 5; |
|
1539 | + } |
|
1498 | 1540 | // send him the message |
1499 | 1541 | self::doMessageSending(ACCOUNT_ID_GROUP_RACES + $raceID, $receiverID, $gameID, MSG_POLITICAL, $message, $expires); |
1500 | 1542 | } |
@@ -1537,11 +1579,11 @@ discard block |
||
1537 | 1579 | public function setPlottedCourse(Distance $plottedCourse) { |
1538 | 1580 | $hadPlottedCourse = $this->hasPlottedCourse(); |
1539 | 1581 | $this->plottedCourse = $plottedCourse; |
1540 | - if ($this->plottedCourse->getTotalSectors() > 0) |
|
1541 | - $this->db->query('REPLACE INTO player_plotted_course |
|
1582 | + if ($this->plottedCourse->getTotalSectors() > 0) { |
|
1583 | + $this->db->query('REPLACE INTO player_plotted_course |
|
1542 | 1584 | (account_id, game_id, course) |
1543 | 1585 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeBinary(serialize($this->plottedCourse)) . ')'); |
1544 | - else if ($hadPlottedCourse) { |
|
1586 | + } else if ($hadPlottedCourse) { |
|
1545 | 1587 | $this->deletePlottedCourse(); |
1546 | 1588 | } |
1547 | 1589 | } |
@@ -1551,12 +1593,14 @@ discard block |
||
1551 | 1593 | } |
1552 | 1594 | |
1553 | 1595 | public function isPartOfCourse($sectorOrSectorID) { |
1554 | - if (!$this->hasPlottedCourse()) |
|
1555 | - return false; |
|
1556 | - if ($sectorOrSectorID instanceof SmrSector) |
|
1557 | - $sectorID = $sectorOrSectorID->getSectorID(); |
|
1558 | - else |
|
1559 | - $sectorID = $sectorOrSectorID; |
|
1596 | + if (!$this->hasPlottedCourse()) { |
|
1597 | + return false; |
|
1598 | + } |
|
1599 | + if ($sectorOrSectorID instanceof SmrSector) { |
|
1600 | + $sectorID = $sectorOrSectorID->getSectorID(); |
|
1601 | + } else { |
|
1602 | + $sectorID = $sectorOrSectorID; |
|
1603 | + } |
|
1560 | 1604 | return $this->getPlottedCourse()->isInPath($sectorID); |
1561 | 1605 | } |
1562 | 1606 |
@@ -26,30 +26,30 @@ |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | function getMessagePlayer($accountID, $gameID, $messageType = false) { |
29 | - if ($accountID == ACCOUNT_ID_PORT) |
|
30 | - $return = '<span class="yellow">Port Defenses</span>'; |
|
31 | - else if ($accountID == ACCOUNT_ID_ADMIN) |
|
32 | - $return = '<span class="admin">Administrator</span>'; |
|
33 | - else if ($accountID == ACCOUNT_ID_PLANET) |
|
34 | - $return = '<span class="yellow">Planetary Defenses</span>'; |
|
35 | - else if ($accountID == ACCOUNT_ID_ALLIANCE_AMBASSADOR) |
|
36 | - $return = '<span class="green">Alliance Ambassador</span>'; |
|
37 | - else if ($accountID == ACCOUNT_ID_CASINO) |
|
38 | - $return = '<span class="yellow">Casino</span>'; |
|
39 | - else if ($accountID == ACCOUNT_ID_FED_CLERK) |
|
40 | - $return = '<span class="yellow">Federal Clerk</span>'; |
|
41 | - else if ($accountID == ACCOUNT_ID_OP_ANNOUNCE || $accountID == ACCOUNT_ID_ALLIANCE_COMMAND) |
|
42 | - $return = '<span class="green">Alliance Command</span>'; |
|
43 | - else { |
|
29 | + if ($accountID == ACCOUNT_ID_PORT) { |
|
30 | + $return = '<span class="yellow">Port Defenses</span>'; |
|
31 | + } else if ($accountID == ACCOUNT_ID_ADMIN) { |
|
32 | + $return = '<span class="admin">Administrator</span>'; |
|
33 | + } else if ($accountID == ACCOUNT_ID_PLANET) { |
|
34 | + $return = '<span class="yellow">Planetary Defenses</span>'; |
|
35 | + } else if ($accountID == ACCOUNT_ID_ALLIANCE_AMBASSADOR) { |
|
36 | + $return = '<span class="green">Alliance Ambassador</span>'; |
|
37 | + } else if ($accountID == ACCOUNT_ID_CASINO) { |
|
38 | + $return = '<span class="yellow">Casino</span>'; |
|
39 | + } else if ($accountID == ACCOUNT_ID_FED_CLERK) { |
|
40 | + $return = '<span class="yellow">Federal Clerk</span>'; |
|
41 | + } else if ($accountID == ACCOUNT_ID_OP_ANNOUNCE || $accountID == ACCOUNT_ID_ALLIANCE_COMMAND) { |
|
42 | + $return = '<span class="green">Alliance Command</span>'; |
|
43 | + } else { |
|
44 | 44 | foreach (Globals::getRaces() as $raceID => $raceInfo) { |
45 | 45 | if ($accountID == ACCOUNT_ID_GROUP_RACES + $raceID) { |
46 | 46 | $return = '<span class="yellow">' . $raceInfo['Race Name'] . ' Government</span>'; |
47 | 47 | return $return; |
48 | 48 | } |
49 | 49 | } |
50 | - if (!empty($accountID)) |
|
51 | - $return = SmrPlayer::getPlayer($accountID, $gameID); |
|
52 | - else { |
|
50 | + if (!empty($accountID)) { |
|
51 | + $return = SmrPlayer::getPlayer($accountID, $gameID); |
|
52 | + } else { |
|
53 | 53 | switch ($messageType) { |
54 | 54 | case MSG_ADMIN: |
55 | 55 | $return = '<span class="admin">Administrator</span>'; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | try { |
124 | - $TRADE_ROUTE =& $GLOBALS['TRADE_ROUTE']; |
|
124 | + $TRADE_ROUTE = & $GLOBALS['TRADE_ROUTE']; |
|
125 | 125 | debug('Action #' . $actions); |
126 | 126 | |
127 | 127 | //We have to reload player on each loop |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | if (!isset($TRADE_ROUTE)) { //We only want to change trade route if there isn't already one set. |
143 | - $TRADE_ROUTES =& findRoutes($player); |
|
144 | - $TRADE_ROUTE =& changeRoute($TRADE_ROUTES); |
|
143 | + $TRADE_ROUTES = & findRoutes($player); |
|
144 | + $TRADE_ROUTE = & changeRoute($TRADE_ROUTES); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | if ($player->isDead()) { |
148 | 148 | debug('Some evil person killed us, let\'s move on now.'); |
149 | 149 | $previousContainer = null; //We died, we don't care what we were doing beforehand. |
150 | - $TRADE_ROUTE =& changeRoute($TRADE_ROUTES); //Change route |
|
150 | + $TRADE_ROUTE = & changeRoute($TRADE_ROUTES); //Change route |
|
151 | 151 | processContainer(create_container('death_processing.php')); |
152 | 152 | } |
153 | 153 | if ($player->getNewbieTurns() <= NEWBIE_TURNS_WARNING_LIMIT && $player->getNewbieWarning()) { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } |
240 | 240 | else { |
241 | 241 | //Move to next route or fed. |
242 | - if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { |
|
242 | + if (($TRADE_ROUTE = & changeRoute($TRADE_ROUTES)) === false) { |
|
243 | 243 | debug('Changing Route Failed'); |
244 | 244 | processContainer(plotToFed($player)); |
245 | 245 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | } |
272 | 272 | else { |
273 | 273 | //Move to next route or fed. |
274 | - if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { |
|
274 | + if (($TRADE_ROUTE = & changeRoute($TRADE_ROUTES)) === false) { |
|
275 | 275 | debug('Changing Route Failed'); |
276 | 276 | processContainer(plotToFed($player)); |
277 | 277 | } |
@@ -599,9 +599,9 @@ discard block |
||
599 | 599 | if (count($tradeRoutes) == 0) |
600 | 600 | return $false; |
601 | 601 | $routeKey = array_rand($tradeRoutes); |
602 | - $tradeRoute =& $tradeRoutes[$routeKey]; |
|
602 | + $tradeRoute = & $tradeRoutes[$routeKey]; |
|
603 | 603 | unset($tradeRoutes[$routeKey]); |
604 | - $GLOBALS['TRADE_ROUTE'] =& $tradeRoute; |
|
604 | + $GLOBALS['TRADE_ROUTE'] = & $tradeRoute; |
|
605 | 605 | debug('Switched route', $tradeRoute); |
606 | 606 | return $tradeRoute; |
607 | 607 | } |
@@ -89,12 +89,10 @@ discard block |
||
89 | 89 | |
90 | 90 | try { |
91 | 91 | changeNPCLogin(); |
92 | - } |
|
93 | - catch (ForwardException $e) {} |
|
92 | + } catch (ForwardException $e) {} |
|
94 | 93 | |
95 | 94 | NPCStuff(); |
96 | -} |
|
97 | -catch (Throwable $e) { |
|
95 | +} catch (Throwable $e) { |
|
98 | 96 | logException($e); |
99 | 97 | // Try to shut down cleanly |
100 | 98 | exitNPC(); |
@@ -157,8 +155,7 @@ discard block |
||
157 | 155 | $fedContainer = null; |
158 | 156 | if ($var['url'] == 'shop_ship_processing.php' && ($fedContainer = plotToFed($player, true)) !== true) { //We just bought a ship, we should head back to our trade gal/uno - we use HQ for now as it's both in our gal and a UNO, plus it's safe which is always a bonus |
159 | 157 | processContainer($fedContainer); |
160 | - } |
|
161 | - else if ($player->getShip()->isUnderAttack() === true |
|
158 | + } else if ($player->getShip()->isUnderAttack() === true |
|
162 | 159 | &&($player->hasPlottedCourse() === false || $player->getPlottedCourse()->getEndSector()->offersFederalProtection() === false) |
163 | 160 | &&($fedContainer == null ? $fedContainer = plotToFed($player, true) : $fedContainer) !== true) { //We're under attack and need to plot course to fed. |
164 | 161 | // Get the lock, remove under attack and update. |
@@ -171,20 +168,16 @@ discard block |
||
171 | 168 | debug('Under Attack'); |
172 | 169 | $underAttack = true; |
173 | 170 | processContainer($fedContainer); |
174 | - } |
|
175 | - else if ($player->hasPlottedCourse() === true && $player->getPlottedCourse()->getEndSector()->offersFederalProtection()) { //We have a route to fed to follow, figure it's probably a damned sensible thing to follow. |
|
171 | + } else if ($player->hasPlottedCourse() === true && $player->getPlottedCourse()->getEndSector()->offersFederalProtection()) { //We have a route to fed to follow, figure it's probably a damned sensible thing to follow. |
|
176 | 172 | debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath()); |
177 | 173 | processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath())); |
178 | - } |
|
179 | - else if (($container = canWeUNO($player, true)) !== false) { //We have money and are at a uno, let's uno! |
|
174 | + } else if (($container = canWeUNO($player, true)) !== false) { //We have money and are at a uno, let's uno! |
|
180 | 175 | debug('We\'re UNOing'); |
181 | 176 | processContainer($container); |
182 | - } |
|
183 | - else if ($player->hasPlottedCourse() === true) { //We have a route to follow, figure it's probably a sensible thing to follow. |
|
177 | + } else if ($player->hasPlottedCourse() === true) { //We have a route to follow, figure it's probably a sensible thing to follow. |
|
184 | 178 | debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath()); |
185 | 179 | processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath())); |
186 | - } |
|
187 | - else if ($player->getTurns() < NPC_LOW_TURNS || ($player->getTurns() < $player->getMaxTurns() / 2 && $player->getNewbieTurns() < NPC_LOW_NEWBIE_TURNS) || $underAttack) { //We're low on turns or have been under attack and need to plot course to fed |
|
180 | + } else if ($player->getTurns() < NPC_LOW_TURNS || ($player->getTurns() < $player->getMaxTurns() / 2 && $player->getNewbieTurns() < NPC_LOW_NEWBIE_TURNS) || $underAttack) { //We're low on turns or have been under attack and need to plot course to fed |
|
188 | 181 | if ($player->getTurns() < NPC_LOW_TURNS) { |
189 | 182 | debug('Low Turns:' . $player->getTurns()); |
190 | 183 | } |
@@ -201,16 +194,13 @@ discard block |
||
201 | 194 | } |
202 | 195 | $ship = $player->getShip(); |
203 | 196 | processContainer(plotToFed($player, !$ship->hasMaxShields() || !$ship->hasMaxArmour() || !$ship->hasMaxCargoHolds())); |
204 | - } |
|
205 | - else if (($container = checkForShipUpgrade($player)) !== false) { //We have money and are at a uno, let's uno! |
|
197 | + } else if (($container = checkForShipUpgrade($player)) !== false) { //We have money and are at a uno, let's uno! |
|
206 | 198 | debug('We\'re reshipping!'); |
207 | 199 | processContainer($container); |
208 | - } |
|
209 | - else if (($container = canWeUNO($player, false)) !== false) { //We need to UNO and have enough money to do it properly so let's do it sooner rather than later. |
|
200 | + } else if (($container = canWeUNO($player, false)) !== false) { //We need to UNO and have enough money to do it properly so let's do it sooner rather than later. |
|
210 | 201 | debug('We need to UNO, so off we go!'); |
211 | 202 | processContainer($container); |
212 | - } |
|
213 | - else if ($TRADE_ROUTE instanceof \Routes\Route) { |
|
203 | + } else if ($TRADE_ROUTE instanceof \Routes\Route) { |
|
214 | 204 | debug('Trade Route'); |
215 | 205 | $forwardRoute = $TRADE_ROUTE->getForwardRoute(); |
216 | 206 | $returnRoute = $TRADE_ROUTE->getReturnRoute(); |
@@ -218,8 +208,7 @@ discard block |
||
218 | 208 | if ($forwardRoute->getBuySectorId() == $player->getSectorID()) { |
219 | 209 | $buyRoute = $forwardRoute; |
220 | 210 | $sellRoute = $returnRoute; |
221 | - } |
|
222 | - else if ($returnRoute->getBuySectorId() == $player->getSectorID()) { |
|
211 | + } else if ($returnRoute->getBuySectorId() == $player->getSectorID()) { |
|
223 | 212 | $buyRoute = $returnRoute; |
224 | 213 | $sellRoute = $forwardRoute; |
225 | 214 | } |
@@ -236,30 +225,25 @@ discard block |
||
236 | 225 | //Sell goods |
237 | 226 | debug('Sell Goods'); |
238 | 227 | processContainer(tradeGoods($goodID, $player, $port)); |
239 | - } |
|
240 | - else { |
|
228 | + } else { |
|
241 | 229 | //Move to next route or fed. |
242 | 230 | if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { |
243 | 231 | debug('Changing Route Failed'); |
244 | 232 | processContainer(plotToFed($player)); |
245 | - } |
|
246 | - else { |
|
233 | + } else { |
|
247 | 234 | debug('Route Changed'); |
248 | 235 | continue; |
249 | 236 | } |
250 | 237 | } |
251 | - } |
|
252 | - else if ($ship->hasCargo($buyRoute->getGoodID()) === true) { //We've bought goods, plot to sell |
|
238 | + } else if ($ship->hasCargo($buyRoute->getGoodID()) === true) { //We've bought goods, plot to sell |
|
253 | 239 | debug('Plot To Sell: ' . $buyRoute->getSellSectorId()); |
254 | 240 | processContainer(plotToSector($player, $buyRoute->getSellSectorId())); |
255 | - } |
|
256 | - else { |
|
241 | + } else { |
|
257 | 242 | //Dump goods |
258 | 243 | debug('Dump Goods'); |
259 | 244 | processContainer(dumpCargo($player)); |
260 | 245 | } |
261 | - } |
|
262 | - else { //Buy goods |
|
246 | + } else { //Buy goods |
|
263 | 247 | $goodID = $buyRoute->getGoodID(); |
264 | 248 | |
265 | 249 | $port = $player->getSector()->getPort(); |
@@ -268,26 +252,22 @@ discard block |
||
268 | 252 | if ($tradeable === true && $port->getGoodAmount($goodID) >= $ship->getEmptyHolds()) { //Buy goods |
269 | 253 | debug('Buy Goods'); |
270 | 254 | processContainer(tradeGoods($goodID, $player, $port)); |
271 | - } |
|
272 | - else { |
|
255 | + } else { |
|
273 | 256 | //Move to next route or fed. |
274 | 257 | if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { |
275 | 258 | debug('Changing Route Failed'); |
276 | 259 | processContainer(plotToFed($player)); |
277 | - } |
|
278 | - else { |
|
260 | + } else { |
|
279 | 261 | debug('Route Changed'); |
280 | 262 | continue; |
281 | 263 | } |
282 | 264 | } |
283 | 265 | } |
284 | - } |
|
285 | - else { |
|
266 | + } else { |
|
286 | 267 | debug('Plot To Buy: ' . $forwardRoute->getBuySectorId()); |
287 | 268 | processContainer(plotToSector($player, $forwardRoute->getBuySectorId())); |
288 | 269 | } |
289 | - } |
|
290 | - else { //Something weird is going on.. Let's fed and wait. |
|
270 | + } else { //Something weird is going on.. Let's fed and wait. |
|
291 | 271 | debug('No actual action? Wtf?'); |
292 | 272 | processContainer(plotToFed($player)); |
293 | 273 | } |
@@ -299,8 +279,7 @@ discard block |
||
299 | 279 | processContainer(moveToSector($player,$moveTo)); |
300 | 280 | } |
301 | 281 | */ |
302 | - } |
|
303 | - catch (ForwardException $e) { |
|
282 | + } catch (ForwardException $e) { |
|
304 | 283 | global $lock; |
305 | 284 | if ($lock) { //only save if we have the lock. |
306 | 285 | SmrSector::saveSectors(); |
@@ -308,8 +287,9 @@ discard block |
||
308 | 287 | SmrPlayer::savePlayers(); |
309 | 288 | SmrForce::saveForces(); |
310 | 289 | SmrPort::savePorts(); |
311 | - if (class_exists('WeightedRandom', false)) |
|
312 | - WeightedRandom::saveWeightedRandoms(); |
|
290 | + if (class_exists('WeightedRandom', false)) { |
|
291 | + WeightedRandom::saveWeightedRandoms(); |
|
292 | + } |
|
313 | 293 | release_lock(); |
314 | 294 | } |
315 | 295 | //Clean up the caches as the data may get changed by other players |
@@ -447,11 +427,13 @@ discard block |
||
447 | 427 | } |
448 | 428 | |
449 | 429 | function canWeUNO(AbstractSmrPlayer $player, $oppurtunisticOnly) { |
450 | - if ($player->getCredits() < MINUMUM_RESERVE_CREDITS) |
|
451 | - return false; |
|
430 | + if ($player->getCredits() < MINUMUM_RESERVE_CREDITS) { |
|
431 | + return false; |
|
432 | + } |
|
452 | 433 | $ship = $player->getShip(); |
453 | - if ($ship->hasMaxShields() && $ship->hasMaxArmour() && $ship->hasMaxCargoHolds()) |
|
454 | - return false; |
|
434 | + if ($ship->hasMaxShields() && $ship->hasMaxArmour() && $ship->hasMaxCargoHolds()) { |
|
435 | + return false; |
|
436 | + } |
|
455 | 437 | $sector = $player->getSector(); |
456 | 438 | |
457 | 439 | // We buy armour in preference to shields as it's cheaper. |
@@ -465,8 +447,7 @@ discard block |
||
465 | 447 | $hardwareSold = $location->getHardwareSold(); |
466 | 448 | if ($player->getNewbieTurns() > MIN_NEWBIE_TURNS_TO_BUY_CARGO && !$ship->hasMaxCargoHolds() && isset($hardwareSold[HARDWARE_CARGO]) && ($amount = floor(($player->getCredits() - MINUMUM_RESERVE_CREDITS) / Globals::getHardwareCost(HARDWARE_CARGO))) > 0) { // Buy cargo holds first if we have plenty of newbie turns left. |
467 | 449 | $hardwareID = HARDWARE_CARGO; |
468 | - } |
|
469 | - else { |
|
450 | + } else { |
|
470 | 451 | foreach ($hardwareArray as $hardwareArrayID) { |
471 | 452 | if (!$ship->hasMaxHardware($hardwareArrayID) && isset($hardwareSold[$hardwareArrayID]) && ($amount = floor(($player->getCredits() - MINUMUM_RESERVE_CREDITS) / Globals::getHardwareCost($hardwareArrayID))) > 0) { |
472 | 453 | $hardwareID = $hardwareArrayID; |
@@ -480,11 +461,14 @@ discard block |
||
480 | 461 | } |
481 | 462 | } |
482 | 463 | |
483 | - if ($oppurtunisticOnly === true) |
|
484 | - return false; |
|
464 | + if ($oppurtunisticOnly === true) { |
|
465 | + return false; |
|
466 | + } |
|
485 | 467 | |
486 | - if ($player->getCredits() - $ship->getCostToUNO() < MINUMUM_RESERVE_CREDITS) |
|
487 | - return false; //Only do non-oppurtunistic UNO if we have the money to do it properly! |
|
468 | + if ($player->getCredits() - $ship->getCostToUNO() < MINUMUM_RESERVE_CREDITS) { |
|
469 | + return false; |
|
470 | + } |
|
471 | + //Only do non-oppurtunistic UNO if we have the money to do it properly! |
|
488 | 472 | |
489 | 473 | foreach ($hardwareArray as $hardwareArrayID) { |
490 | 474 | if (!$ship->hasMaxHardware($hardwareArrayID)) { |
@@ -573,8 +557,10 @@ discard block |
||
573 | 557 | |
574 | 558 | function checkForShipUpgrade(AbstractSmrPlayer $player) { |
575 | 559 | foreach (SHIP_UPGRADE_PATH[$player->getRaceID()] as $upgradeShipID) { |
576 | - if ($player->getShipTypeID() == $upgradeShipID) //We can't upgrade, only downgrade. |
|
560 | + if ($player->getShipTypeID() == $upgradeShipID) { |
|
561 | + //We can't upgrade, only downgrade. |
|
577 | 562 | return false; |
563 | + } |
|
578 | 564 | $cost = $player->getShip()->getCostToUpgrade($upgradeShipID); |
579 | 565 | if ($cost <= 0 || $player->getCredits() - $cost > MINUMUM_RESERVE_CREDITS) { |
580 | 566 | return doShipUpgrade($player, $upgradeShipID); |
@@ -596,8 +582,9 @@ discard block |
||
596 | 582 | |
597 | 583 | function &changeRoute(array &$tradeRoutes) { |
598 | 584 | $false = false; |
599 | - if (count($tradeRoutes) == 0) |
|
600 | - return $false; |
|
585 | + if (count($tradeRoutes) == 0) { |
|
586 | + return $false; |
|
587 | + } |
|
601 | 588 | $routeKey = array_rand($tradeRoutes); |
602 | 589 | $tradeRoute =& $tradeRoutes[$routeKey]; |
603 | 590 | unset($tradeRoutes[$routeKey]); |
@@ -611,10 +598,11 @@ discard block |
||
611 | 598 | |
612 | 599 | $tradeGoods = array(GOOD_NOTHING => false); |
613 | 600 | foreach (Globals::getGoods() as $goodID => $good) { |
614 | - if ($player->meetsAlignmentRestriction($good['AlignRestriction'])) |
|
615 | - $tradeGoods[$goodID] = true; |
|
616 | - else |
|
617 | - $tradeGoods[$goodID] = false; |
|
601 | + if ($player->meetsAlignmentRestriction($good['AlignRestriction'])) { |
|
602 | + $tradeGoods[$goodID] = true; |
|
603 | + } else { |
|
604 | + $tradeGoods[$goodID] = false; |
|
605 | + } |
|
618 | 606 | } |
619 | 607 | $tradeRaces = array(); |
620 | 608 | foreach (Globals::getRaces() as $raceID => $race) { |
@@ -638,8 +626,7 @@ discard block |
||
638 | 626 | $routes = unserialize(gzuncompress($db->getField('routes'))); |
639 | 627 | debug('Using Cached Routes: #' . count($routes)); |
640 | 628 | return $routes; |
641 | - } |
|
642 | - else { |
|
629 | + } else { |
|
643 | 630 | debug('Generating Routes'); |
644 | 631 | $allSectors = array(); |
645 | 632 | foreach (SmrGalaxy::getGameGalaxies($player->getGameID()) as $galaxy) { |
@@ -648,10 +635,11 @@ discard block |
||
648 | 635 | |
649 | 636 | $distances = Plotter::calculatePortToPortDistances($allSectors, $maxDistance, $startSectorID, $endSectorID); |
650 | 637 | |
651 | - if ($maxNumberOfPorts == 1) |
|
652 | - $allRoutes = \Routes\RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort); |
|
653 | - else |
|
654 | - $allRoutes = \Routes\RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes); |
|
638 | + if ($maxNumberOfPorts == 1) { |
|
639 | + $allRoutes = \Routes\RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort); |
|
640 | + } else { |
|
641 | + $allRoutes = \Routes\RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes); |
|
642 | + } |
|
655 | 643 | |
656 | 644 | unset($distances); |
657 | 645 |