Scrutinizer GitHub App not installed

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

Install GitHub App

Completed
Push — master ( 8d8584...432c27 )
by Dan
31s queued 20s
created
lib/Default/SmrScoutDrones.class.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
 			$return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover());
81 81
 			return $return;
82 82
 		}
83
-		$damage =& $this->getModifiedDamage();
83
+		$damage = & $this->getModifiedDamage();
84 84
 		$damage['Launched'] = ICeil($this->getNumberOfSDs() * $this->getModifiedForceAccuracyAgainstPlayer($forces, $targetPlayer) / 100);
85 85
 		$damage['MaxDamage'] = ICeil($damage['Launched'] * $damage['MaxDamage']);
86 86
 		$damage['Shield'] = ICeil($damage['Launched'] * $damage['Shield']);
Please login to merge, or discard this patch.
tools/npc/chess.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
 
11 11
 	debug('Script started');
12 12
 	define('SCRIPT_ID', $db->getInsertID());
13
-	$db->query('UPDATE npc_logs SET script_id='.SCRIPT_ID.' WHERE log_id='.SCRIPT_ID);
13
+	$db->query('UPDATE npc_logs SET script_id=' . SCRIPT_ID . ' WHERE log_id=' . SCRIPT_ID);
14 14
 
15 15
 	define('NPC_SCRIPT', true);
16 16
 
17 17
 	$descriptorSpec = array(
18
-		0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
18
+		0 => array("pipe", "r"), // stdin is a pipe that the child will read from
19 19
 		1 => array("pipe", "w")  // stdout is a pipe that the child will write to
20 20
 	);
21 21
 	$engine = proc_open(UCI_CHESS_ENGINE, $descriptorSpec, $pipes);
22
-	$toEngine =& $pipes[0];
23
-	$fromEngine =& $pipes[1];
22
+	$toEngine = & $pipes[0];
23
+	$fromEngine = & $pipes[1];
24 24
 
25 25
 	function readFromEngine($block = true) {
26 26
 		global $fromEngine;
27 27
 		stream_set_blocking($fromEngine, $block == true ? 1 : 0);
28
-		while(($s = fgets($fromEngine)) !== false) {
28
+		while (($s = fgets($fromEngine)) !== false) {
29 29
 			debug('<-- ' . trim($s));
30 30
 			stream_set_blocking($fromEngine, 0);
31 31
 		}
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		global $toEngine;
35 35
 		debug('--> ' . $s);
36 36
 		fputs($toEngine, $s . EOL);
37
-		if($read === true) {
37
+		if ($read === true) {
38 38
 			readFromEngine($block);
39 39
 		}
40 40
 	}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	writeToEngine('isready');
46 46
 	writeToEngine('ucinewgame', false);
47 47
 
48
-	while(true) {
48
+	while (true) {
49 49
 		//Redefine MICRO_TIME and TIME, the rest of the game expects them to be the single point in time that the script is executing, with it being redefined for each page load - unfortunately NPCs are one consistent script so we have to do a hack and redefine it (or change every instance of the TIME constant).
50 50
 		runkit_constant_redefine('MICRO_TIME', microtime(true));
51 51
 		runkit_constant_redefine('TIME', IFloor(MICRO_TIME));
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 			writeToEngine('position fen ' . $chessGame->getFENString(), false);
56 56
 			writeToEngine('go ' . ($chessGame->getCurrentTurnColour() == ChessGame::PLAYER_WHITE ? 'w' : 'b') . 'time ' . UCI_TIME_PER_MOVE_MS, true, false);
57 57
 			stream_set_blocking($fromEngine, 1);
58
-			while(stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) {
58
+			while (stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) {
59 59
 				debug('<-- ' . $move);
60
-				if(stripos($move, 'Seg') === 0) {
60
+				if (stripos($move, 'Seg') === 0) {
61 61
 					// Segfault
62 62
 					debug('UCI engine segfaulted?');
63 63
 					exit;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 	fclose($fromEngine);
79 79
 	proc_close($engine);
80 80
 }
81
-catch(Throwable $e) {
81
+catch (Throwable $e) {
82 82
 	logException($e);
83 83
 	exit;
84 84
 }
85 85
 function debug($message, $debugObject = null) {
86
-	global $account,$var,$db;
87
-	echo date('Y-m-d H:i:s - ').$message.($debugObject!==null?EOL.var_export($debugObject,true):'').EOL;
88
-	$db->query('INSERT INTO npc_logs (script_id, npc_id, time, message, debug_info, var) VALUES ('.(defined('SCRIPT_ID')?SCRIPT_ID:0).', '.(is_object($account)?$account->getAccountID():0).',NOW(),'.$db->escapeString($message).','.$db->escapeString(var_export($debugObject,true)).','.$db->escapeString(var_export($var,true)).')');
86
+	global $account, $var, $db;
87
+	echo date('Y-m-d H:i:s - ') . $message . ($debugObject !== null ?EOL.var_export($debugObject, true) : '') . EOL;
88
+	$db->query('INSERT INTO npc_logs (script_id, npc_id, time, message, debug_info, var) VALUES (' . (defined('SCRIPT_ID') ?SCRIPT_ID:0) . ', ' . (is_object($account) ? $account->getAccountID() : 0) . ',NOW(),' . $db->escapeString($message) . ',' . $db->escapeString(var_export($debugObject, true)) . ',' . $db->escapeString(var_export($var, true)) . ')');
89 89
 }
Please login to merge, or discard this patch.
lib/Default/Routes/RouteGenerator.class.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -72,24 +72,24 @@  discard block
 block discarded – undo
72 72
 		$routes = array();
73 73
 		foreach ($distances as $currentSectorId => $d) {
74 74
 			$raceID = $sectors[$currentSectorId]->getPort()->getRaceID();
75
-			if (isset($races[$raceID])===false) {
76
-				echo 'Error with Race ID: '.$sectors[$currentSectorId]->getPort()->getRaceID();
75
+			if (isset($races[$raceID]) === false) {
76
+				echo 'Error with Race ID: ' . $sectors[$currentSectorId]->getPort()->getRaceID();
77 77
 				continue;
78 78
 			}
79
-			if($races[$raceID]===false)
79
+			if ($races[$raceID] === false)
80 80
 				continue;
81 81
 			$rl = array();
82 82
 			foreach ($d as $targetSectorId => $distance) {
83 83
 				if (!$races[$sectors[$targetSectorId]->getPort()->getRaceID()])
84 84
 					continue;
85
-				if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort)
85
+				if ($routesForPort !== -1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort)
86 86
 					continue;
87 87
 
88
-				if ($goods[GOOD_NOTHING]===true)
88
+				if ($goods[GOOD_NOTHING] === true)
89 89
 					$rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $raceID, $sectors[$targetSectorId]->getPort()->getRaceID(), 0, 0, $distance, GOOD_NOTHING);
90 90
 
91 91
 				foreach (\Globals::getGoods() as $goodId => $value) {
92
-					if ($goods[$goodId]===true) {
92
+					if ($goods[$goodId] === true) {
93 93
 						if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS &&
94 94
 						    $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) {
95 95
 							$rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $raceID, $sectors[$targetSectorId]->getPort()->getRaceID(), $sectors[$currentSectorId]->getPort()->getGoodDistance($goodId), $sectors[$targetSectorId]->getPort()->getGoodDistance($goodId), $distance, $goodId);
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
 	public static function generateOneWayRoutes(array $sectors, array $distances, array $goods, array $races, int $routesForPort) : array {
106 106
 		self::initialize();
107 107
 		foreach ($distances as $currentSectorId => $d) {
108
-			if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()]===false)
108
+			if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()] === false)
109 109
 				continue;
110 110
 			foreach ($d as $targetSectorId => $distance) {
111
-				if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()]===false)
111
+				if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()] === false)
112 112
 					continue;
113
-				if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort)
113
+				if ($routesForPort !== -1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort)
114 114
 					continue;
115 115
 
116 116
 				foreach (\Globals::getGoods() as $goodId => $value) {
117
-					if ($goods[$goodId]===true) {
117
+					if ($goods[$goodId] === true) {
118 118
 						if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS &&
119 119
 						    $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) {
120 120
 							$owr = new OneWayRoute($currentSectorId, $targetSectorId, $sectors[$currentSectorId]->getPort()->getRaceID(), $sectors[$targetSectorId]->getPort()->getRaceID(), $sectors[$currentSectorId]->getPort()->getGoodDistance($goodId), $sectors[$targetSectorId]->getPort()->getGoodDistance($goodId), $distance, $goodId);
@@ -160,18 +160,18 @@  discard block
 block discarded – undo
160 160
 		$i = 0;
161 161
 		krsort(self::$expRoutes, SORT_NUMERIC);
162 162
 		foreach (self::$expRoutes as $multi => $routesByMulti) {
163
-			if(count($routesByMulti)+$i < $trimToBestXRoutes) {
163
+			if (count($routesByMulti) + $i < $trimToBestXRoutes) {
164 164
 				$i += count($routesByMulti);
165 165
 			}
166
-			else if($i > $trimToBestXRoutes) {
166
+			else if ($i > $trimToBestXRoutes) {
167 167
 				unset(self::$expRoutes[$multi]);
168 168
 			}
169 169
 			else {
170
-				foreach($routesByMulti as $key => $value) {
170
+				foreach ($routesByMulti as $key => $value) {
171 171
 					$i++;
172
-					if($i < $trimToBestXRoutes)
172
+					if ($i < $trimToBestXRoutes)
173 173
 						continue;
174
-					if($i === $trimToBestXRoutes) {
174
+					if ($i === $trimToBestXRoutes) {
175 175
 						self::$dontAddWorseThan[self::EXP_ROUTE] = $multi;
176 176
 						continue;
177 177
 					}
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
 		$i = 0;
184 184
 		krsort(self::$moneyRoutes, SORT_NUMERIC);
185 185
 		foreach (self::$moneyRoutes as $multi => $routesByMulti) {
186
-			if(count($routesByMulti)+$i < $trimToBestXRoutes) {
186
+			if (count($routesByMulti) + $i < $trimToBestXRoutes) {
187 187
 				$i += count($routesByMulti);
188 188
 			}
189
-			else if($i > $trimToBestXRoutes) {
189
+			else if ($i > $trimToBestXRoutes) {
190 190
 				unset(self::$moneyRoutes[$multi]);
191 191
 				continue;
192 192
 			}
193 193
 			else {
194
-				foreach($routesByMulti as $key => $value) {
194
+				foreach ($routesByMulti as $key => $value) {
195 195
 					$i++;
196
-					if($i < $trimToBestXRoutes)
196
+					if ($i < $trimToBestXRoutes)
197 197
 						continue;
198
-					if($i === $trimToBestXRoutes) {
198
+					if ($i === $trimToBestXRoutes) {
199 199
 						self::$dontAddWorseThan[self::MONEY_ROUTE] = $multi;
200 200
 						continue;
201 201
 					}
Please login to merge, or discard this patch.
lib/Default/AbstractSmrAccount.class.php 1 patch
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -10,23 +10,23 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Default/DummyShip.class.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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() {
Please login to merge, or discard this patch.
lib/Default/SmrPlayer.class.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
tools/npc/npc.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Default/ChessGame.class.php 1 patch
Spacing   +148 added lines, -149 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
675 674
 				$castlingType = $moveInfo['Castling'] === false ? null : $moveInfo['Castling']['Type'];
@@ -679,37 +678,37 @@  discard block
 block discarded – undo
679 678
 								(' . $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($castlingType, true, true) . ',' . $this->db->escapeBoolean($moveInfo['EnPassant']) . ',' . ($moveInfo['PawnPromotion'] == false ? 'NULL' : $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID'])) . ');');
680 679
 
681 680
 
682
-				$currentPlayer->increaseHOF(1, array($chessType,'Moves','Total Taken'), HOF_PUBLIC);
683
-				if($moveInfo['PieceTaken'] != null) {
681
+				$currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Total Taken'), HOF_PUBLIC);
682
+				if ($moveInfo['PieceTaken'] != null) {
684 683
 					$this->db->query('DELETE FROM chess_game_pieces
685 684
 									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) . ';');
686 685
 
687 686
 					$pieceTakenSymbol = $moveInfo['PieceTaken']->getPieceSymbol();
688
-					$currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken','Total'), HOF_PUBLIC);
689
-					$otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken','Total'), HOF_PUBLIC);
690
-					$currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC);
691
-					$otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC);
687
+					$currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', 'Total'), HOF_PUBLIC);
688
+					$otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', 'Total'), HOF_PUBLIC);
689
+					$currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC);
690
+					$otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC);
692 691
 				}
693 692
 				$this->db->query('UPDATE chess_game_pieces
694 693
 							SET x=' . $this->db->escapeNumber($toX) . ', y=' . $this->db->escapeNumber($toY) .
695 694
 								($moveInfo['PawnPromotion'] !== false ? ', piece_id=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID']) . ', piece_no=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceNo']) : '') . '
696 695
 							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) . ';');
697
-				if($moveInfo['Castling'] !== false) {
696
+				if ($moveInfo['Castling'] !== false) {
698 697
 					$this->db->query('UPDATE chess_game_pieces
699 698
 								SET x=' . $this->db->escapeNumber($moveInfo['Castling']['ToX']) . '
700 699
 								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) . ';');
701 700
 				}
702 701
 				$return = 0;
703
-				if($checking == 'MATE') {
702
+				if ($checking == 'MATE') {
704 703
 					$this->setWinner($forAccountID);
705 704
 					$return = 1;
706 705
 					SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'You have just lost [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].');
707 706
 				}
708 707
 				else {
709 708
 					SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'It is now your turn in [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].');
710
-					if($checking == 'CHECK') {
711
-						$currentPlayer->increaseHOF(1, array($chessType,'Moves','Check Given'), HOF_PUBLIC);
712
-						$otherPlayer->increaseHOF(1, array($chessType,'Moves','Check Received'), HOF_PUBLIC);
709
+					if ($checking == 'CHECK') {
710
+						$currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Given'), HOF_PUBLIC);
711
+						$otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Received'), HOF_PUBLIC);
713 712
 					}
714 713
 				}
715 714
 				$currentPlayer->saveHOF();
@@ -748,10 +747,10 @@  discard block
 block discarded – undo
748 747
 	}
749 748
 
750 749
 	public function getColourID($colour) {
751
-		if($colour == self::PLAYER_WHITE) {
750
+		if ($colour == self::PLAYER_WHITE) {
752 751
 			return $this->getWhiteID();
753 752
 		}
754
-		if($colour == self::PLAYER_BLACK) {
753
+		if ($colour == self::PLAYER_BLACK) {
755 754
 			return $this->getBlackID();
756 755
 		}
757 756
 	}
@@ -761,10 +760,10 @@  discard block
 block discarded – undo
761 760
 	}
762 761
 
763 762
 	public function getColourForAccountID($accountID) {
764
-		if($accountID == $this->getWhiteID()) {
763
+		if ($accountID == $this->getWhiteID()) {
765 764
 			return self::PLAYER_WHITE;
766 765
 		}
767
-		if($accountID == $this->getBlackID()) {
766
+		if ($accountID == $this->getBlackID()) {
768 767
 			return self::PLAYER_BLACK;
769 768
 		}
770 769
 		return false;
@@ -792,8 +791,8 @@  discard block
 block discarded – undo
792 791
 		$winningPlayer = $this->getColourPlayer($winnerColour);
793 792
 		$losingPlayer = $this->getColourPlayer(self::getOtherColour($winnerColour));
794 793
 		$chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess';
795
-		$winningPlayer->increaseHOF(1, array($chessType,'Games','Won'), HOF_PUBLIC);
796
-		$losingPlayer->increaseHOF(1, array($chessType,'Games','Lost'), HOF_PUBLIC);
794
+		$winningPlayer->increaseHOF(1, array($chessType, 'Games', 'Won'), HOF_PUBLIC);
795
+		$losingPlayer->increaseHOF(1, array($chessType, 'Games', 'Lost'), HOF_PUBLIC);
797 796
 		return array('Winner' => $winningPlayer, 'Loser' => $losingPlayer);
798 797
 	}
799 798
 
@@ -834,21 +833,21 @@  discard block
 block discarded – undo
834 833
 	}
835 834
 
836 835
 	public static function getOtherColour($colour) {
837
-		if($colour == self::PLAYER_WHITE) {
836
+		if ($colour == self::PLAYER_WHITE) {
838 837
 			return self::PLAYER_BLACK;
839 838
 		}
840
-		if($colour == self::PLAYER_BLACK) {
839
+		if ($colour == self::PLAYER_BLACK) {
841 840
 			return self::PLAYER_WHITE;
842 841
 		}
843 842
 		return false;
844 843
 	}
845 844
 
846 845
 	public function resign($accountID) {
847
-		if($this->hasEnded() || !$this->getColourForAccountID($accountID)) {
846
+		if ($this->hasEnded() || !$this->getColourForAccountID($accountID)) {
848 847
 			return false;
849 848
 		}
850 849
 		// If only 1 person has moved then just end the game.
851
-		if(count($this->getMoves()) < 2) {
850
+		if (count($this->getMoves()) < 2) {
852 851
 			$this->endDate = TIME;
853 852
 			$this->db->query('UPDATE chess_game
854 853
 							SET end_time=' . $this->db->escapeNumber(TIME) . '
@@ -860,17 +859,17 @@  discard block
 block discarded – undo
860 859
 			$winnerAccountID = $this->getColourID(self::getOtherColour($loserColour));
861 860
 			$results = $this->setWinner($winnerAccountID);
862 861
 			$chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess';
863
-			$results['Loser']->increaseHOF(1, array($chessType,'Games','Resigned'), HOF_PUBLIC);
862
+			$results['Loser']->increaseHOF(1, array($chessType, 'Games', 'Resigned'), HOF_PUBLIC);
864 863
 			SmrPlayer::sendMessageFromCasino($results['Winner']->getGameID(), $results['Winner']->getPlayerID(), '[player=' . $results['Loser']->getPlayerID() . '] just resigned against you in [chess=' . $this->getChessGameID() . '].');
865 864
 			return 0;
866 865
 		}
867 866
 	}
868 867
 
869 868
 	public function getPlayGameHREF() {
870
-		return SmrSession::getNewHREF(create_container('skeleton.php','chess_play.php',array('ChessGameID' => $this->chessGameID)));
869
+		return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_play.php', array('ChessGameID' => $this->chessGameID)));
871 870
 	}
872 871
 
873 872
 	public function getResignHREF() {
874
-		return SmrSession::getNewHREF(create_container('skeleton.php','chess_resign_processing.php',array('ChessGameID' => $this->chessGameID)));
873
+		return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_resign_processing.php', array('ChessGameID' => $this->chessGameID)));
875 874
 	}
876 875
 }
Please login to merge, or discard this patch.