We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function htmliseMessage($message) { |
| 4 | - $message = htmlentities($message,ENT_COMPAT,'utf-8'); |
|
| 5 | - $message = str_replace('<br />','<br />',$message); |
|
| 4 | + $message = htmlentities($message, ENT_COMPAT, 'utf-8'); |
|
| 5 | + $message = str_replace('<br />', '<br />', $message); |
|
| 6 | 6 | return $message; |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | function parseBoolean($check) { |
| 10 | 10 | // Only negative strings are not implicitly converted to the correct bool |
| 11 | - if(is_string($check) && (strcasecmp($check,'NO') == 0 || strcasecmp($check,'FALSE')==0)) |
|
| 11 | + if (is_string($check) && (strcasecmp($check, 'NO') == 0 || strcasecmp($check, 'FALSE') == 0)) |
|
| 12 | 12 | return false; |
| 13 | 13 | return (bool)$check; |
| 14 | 14 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | function smrBBCode($bbParser, $action, $tagName, $default, $tagParams, $tagContent) { |
| 17 | 17 | global $overrideGameID, $disableBBLinks, $player, $account, $var; |
| 18 | 18 | try { |
| 19 | - switch($tagName) { |
|
| 19 | + switch ($tagName) { |
|
| 20 | 20 | case 'combatlog': |
| 21 | 21 | $logID = (is_numeric($default)) ? $default : $tagParams['id']; |
| 22 | 22 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | break; |
| 29 | 29 | case 'player': |
| 30 | 30 | $playerID = $default; |
| 31 | - if(!is_numeric($playerID)) |
|
| 31 | + if (!is_numeric($playerID)) |
|
| 32 | 32 | $playerID = $tagParams['id']; |
| 33 | 33 | $bbPlayer = SmrPlayer::getPlayerByPlayerID($playerID, $overrideGameID); |
| 34 | 34 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 35 | 35 | return true; |
| 36 | 36 | } |
| 37 | 37 | $showAlliance = isset($tagParams['showalliance']) ? parseBoolean($tagParams['showalliance']) : false; |
| 38 | - if($disableBBLinks===false && $overrideGameID==SmrSession::getGameID()) { |
|
| 38 | + if ($disableBBLinks === false && $overrideGameID == SmrSession::getGameID()) { |
|
| 39 | 39 | return $bbPlayer->getLinkedDisplayName($showAlliance); |
| 40 | 40 | } |
| 41 | 41 | return $bbPlayer->getDisplayName($showAlliance); |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | case 'alliance': |
| 44 | 44 | $db = new SmrMySqlDatabase(); |
| 45 | 45 | $allianceID = $default; |
| 46 | - if(!is_numeric($allianceID)) |
|
| 46 | + if (!is_numeric($allianceID)) |
|
| 47 | 47 | $allianceID = $tagParams['id']; |
| 48 | 48 | $alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID); |
| 49 | 49 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 50 | 50 | return true; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if($disableBBLinks===false && $overrideGameID==SmrSession::getGameID()) { |
|
| 53 | + if ($disableBBLinks === false && $overrideGameID == SmrSession::getGameID()) { |
|
| 54 | 54 | $container = create_container('skeleton.php'); |
| 55 | 55 | $container['alliance_id'] = $alliance->getAllianceID(); |
| 56 | 56 | if (is_object($player) && $alliance->getAllianceID() == $player->getAllianceID()) |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | case 'race': |
| 65 | 65 | $raceNameID = $default; |
| 66 | 66 | foreach (Globals::getRaces() as $raceID => $raceInfo) { |
| 67 | - if((is_numeric($raceNameID) && $raceNameID == $raceID) |
|
| 67 | + if ((is_numeric($raceNameID) && $raceNameID == $raceID) |
|
| 68 | 68 | || $raceNameID == $raceInfo['Race Name']) { |
| 69 | 69 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 70 | 70 | return true; |
| 71 | 71 | } |
| 72 | - $linked = $disableBBLinks===false && $overrideGameID==SmrSession::getGameID(); |
|
| 72 | + $linked = $disableBBLinks === false && $overrideGameID == SmrSession::getGameID(); |
|
| 73 | 73 | return AbstractSmrPlayer::getColouredRaceNameOrDefault($raceID, $player, $linked); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | return true; |
| 81 | 81 | } |
| 82 | 82 | if ($timeString != '' && ($time = strtotime($timeString)) !== false) { |
| 83 | - if(is_object($account)) |
|
| 83 | + if (is_object($account)) |
|
| 84 | 84 | $time += $account->getOffset() * 3600; |
| 85 | 85 | return date(DATE_FULL_SHORT, $time); |
| 86 | 86 | } |
| 87 | 87 | break; |
| 88 | 88 | case 'chess': |
| 89 | 89 | $chessGameID = $default; |
| 90 | - $chessGame =& ChessGame::getChessGame($chessGameID); |
|
| 90 | + $chessGame = & ChessGame::getChessGame($chessGameID); |
|
| 91 | 91 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 92 | 92 | return true; |
| 93 | 93 | } |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | // The use of $var here is for a corner case where an admin can check reported messages whilst being in-game. |
| 107 | 107 | // Ugly but working, probably want a better mechanism to check if more BBCode tags get added |
| 108 | - if(is_numeric($sectorID) |
|
| 108 | + if (is_numeric($sectorID) |
|
| 109 | 109 | && SmrSession::hasGame() |
| 110 | 110 | && SmrSector::sectorExists($overrideGameID, $sectorID) |
| 111 | - && $disableBBLinks===false && $overrideGameID==SmrSession::getGameID()) { |
|
| 111 | + && $disableBBLinks === false && $overrideGameID == SmrSession::getGameID()) { |
|
| 112 | 112 | return '<a href="' . Globals::getPlotCourseHREF($player->getSectorID(), $sectorID) . '">' . $sectorTag . '</a>'; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | return str_replace(',', '', html_entity_decode($text)); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | -function bbifyMessage($message, $noLinks=false) { |
|
| 145 | +function bbifyMessage($message, $noLinks = false) { |
|
| 146 | 146 | static $bbParser; |
| 147 | - if(!isset($bbParser)) { |
|
| 147 | + if (!isset($bbParser)) { |
|
| 148 | 148 | $bbParser = new \Nbbc\BBCode(); |
| 149 | 149 | $bbParser->SetEnableSmileys(false); |
| 150 | 150 | $bbParser->RemoveRule('wiki'); |
@@ -160,23 +160,23 @@ discard block |
||
| 160 | 160 | 'end_tag' => \Nbbc\BBCode::BBCODE_PROHIBIT, |
| 161 | 161 | 'content' => \Nbbc\BBCode::BBCODE_PROHIBIT, |
| 162 | 162 | ); |
| 163 | - $bbParser->AddRule('combatlog',$smrRule); |
|
| 164 | - $bbParser->AddRule('player',$smrRule); |
|
| 165 | - $bbParser->AddRule('alliance',$smrRule); |
|
| 166 | - $bbParser->AddRule('race',$smrRule); |
|
| 167 | - $bbParser->AddRule('servertimetouser',$smrRule); |
|
| 168 | - $bbParser->AddRule('chess',$smrRule); |
|
| 169 | - $bbParser->AddRule('sector',$smrRule); |
|
| 170 | - $bbParser->addRule('join_alliance',$smrRule); |
|
| 163 | + $bbParser->AddRule('combatlog', $smrRule); |
|
| 164 | + $bbParser->AddRule('player', $smrRule); |
|
| 165 | + $bbParser->AddRule('alliance', $smrRule); |
|
| 166 | + $bbParser->AddRule('race', $smrRule); |
|
| 167 | + $bbParser->AddRule('servertimetouser', $smrRule); |
|
| 168 | + $bbParser->AddRule('chess', $smrRule); |
|
| 169 | + $bbParser->AddRule('sector', $smrRule); |
|
| 170 | + $bbParser->addRule('join_alliance', $smrRule); |
|
| 171 | 171 | } |
| 172 | 172 | global $disableBBLinks; |
| 173 | - if($noLinks===true) |
|
| 173 | + if ($noLinks === true) |
|
| 174 | 174 | $disableBBLinks = true; |
| 175 | 175 | else |
| 176 | 176 | $disableBBLinks = false; |
| 177 | - if(strpos($message, '[')!==false) { //We have BBCode so let's do a full parse. |
|
| 177 | + if (strpos($message, '[') !== false) { //We have BBCode so let's do a full parse. |
|
| 178 | 178 | $message = $bbParser->parse($message); |
| 179 | - $message = str_replace('<br />','<br />',$message); |
|
| 179 | + $message = str_replace('<br />', '<br />', $message); |
|
| 180 | 180 | } |
| 181 | 181 | else { //Otherwise just convert newlines |
| 182 | 182 | $message = nl2br($message, true); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | global $template; |
| 189 | 189 | $return = '<span class="noWrap">' . implode('</span> | <span class="noWrap">', $menu) . '</span>'; |
| 190 | 190 | $template->unassign('MenuItems'); |
| 191 | - $template->assign('MenuBar',$return); |
|
| 191 | + $template->assign('MenuBar', $return); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function create_table() { |
@@ -200,29 +200,29 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function create_form_name($container, $name) { |
| 203 | - return create_form_parameter($container, 'name="'.$name.'"'); |
|
| 203 | + return create_form_parameter($container, 'name="' . $name . '"'); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function create_form_parameter($container, $param) { |
| 207 | - return '<form '.$param.' method="POST" action="'.SmrSession::getNewHREF($container).'">'; |
|
| 207 | + return '<form ' . $param . ' method="POST" action="' . SmrSession::getNewHREF($container) . '">'; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | -function create_button($container,$text) { |
|
| 211 | - return '<div class="buttonA"><a class="buttonA" href="' . SmrSession::getNewHREF($container). '">' . $text . '</a></div>'; |
|
| 210 | +function create_button($container, $text) { |
|
| 211 | + return '<div class="buttonA"><a class="buttonA" href="' . SmrSession::getNewHREF($container) . '">' . $text . '</a></div>'; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | -function create_form($container,$actions) { |
|
| 214 | +function create_form($container, $actions) { |
|
| 215 | 215 | static $form_id = 0; |
| 216 | 216 | $form = array(); |
| 217 | 217 | $form['form'] = '<form class="standard" id="FORM' . $form_id . '" method="POST" action="' . SmrSession::getNewHREF($container) . '">'; |
| 218 | 218 | |
| 219 | - if(!is_array($actions)) { |
|
| 220 | - $form['submit'] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($actions) . '">'; |
|
| 219 | + if (!is_array($actions)) { |
|
| 220 | + $form['submit'] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($actions) . '">'; |
|
| 221 | 221 | } |
| 222 | 222 | else { |
| 223 | 223 | $form['submit'] = array(); |
| 224 | - foreach($actions as $action) { |
|
| 225 | - $form['submit'][$action[0]] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($action[1]) . '">'; |
|
| 224 | + foreach ($actions as $action) { |
|
| 225 | + $form['submit'][$action[0]] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($action[1]) . '">'; |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | function create_submit($value) { |
| 235 | - return ('<input type="submit" name="action" value="'.htmlspecialchars($value).'" id="InputFields" />'); |
|
| 235 | + return ('<input type="submit" name="action" value="' . htmlspecialchars($value) . '" id="InputFields" />'); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | function create_error($message) { |
| 239 | - $container = create_container('skeleton.php','error.php'); |
|
| 239 | + $container = create_container('skeleton.php', 'error.php'); |
|
| 240 | 240 | $container['message'] = $message; |
| 241 | 241 | if (USING_AJAX) { |
| 242 | 242 | // To avoid the page just not refreshing when an error is encountered |
@@ -253,18 +253,18 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | function resetContainer($new_container) { |
| 256 | - global $sn,$container,$var; |
|
| 256 | + global $sn, $container, $var; |
|
| 257 | 257 | |
| 258 | 258 | // this sn identifies our container later |
| 259 | 259 | |
| 260 | - SmrSession::resetLink($new_container,$sn); |
|
| 260 | + SmrSession::resetLink($new_container, $sn); |
|
| 261 | 261 | |
| 262 | 262 | $var = $new_container; |
| 263 | 263 | $container = $new_container; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | function forward($new_container) { |
| 267 | - if(defined('OVERRIDE_FORWARD')&&OVERRIDE_FORWARD===true) |
|
| 267 | + if (defined('OVERRIDE_FORWARD') && OVERRIDE_FORWARD === true) |
|
| 268 | 268 | return overrideForward($new_container); |
| 269 | 269 | resetContainer($new_container); |
| 270 | 270 | do_voodoo(); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | global $var, $container; |
| 282 | 282 | |
| 283 | 283 | // transfer this value to next container |
| 284 | - if(isset($var[$what])) |
|
| 284 | + if (isset($var[$what])) |
|
| 285 | 285 | $container[$what] = $var[$what]; |
| 286 | 286 | |
| 287 | 287 | } |
@@ -290,42 +290,42 @@ discard block |
||
| 290 | 290 | $container = $extra; |
| 291 | 291 | $container['url'] = $file; |
| 292 | 292 | $container['body'] = $body; |
| 293 | - if($remainingPageLoads) { |
|
| 293 | + if ($remainingPageLoads) { |
|
| 294 | 294 | $container['RemainingPageLoads'] = $remainingPageLoads; |
| 295 | 295 | } |
| 296 | 296 | return $container; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | -function create_link($container, $text, $class=null) { |
|
| 300 | - return '<a'.($class==null?'':' class="'.$class.'"').' href="' . (is_array($container)?SmrSession::getNewHREF($container):$container) . '">' . $text . '</a>'; |
|
| 299 | +function create_link($container, $text, $class = null) { |
|
| 300 | + return '<a' . ($class == null ? '' : ' class="' . $class . '"') . ' href="' . (is_array($container) ?SmrSession::getNewHREF($container) : $container) . '">' . $text . '</a>'; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | function create_submit_link($container, $text) { |
| 304 | 304 | return '<a href="' . SmrSession::getNewHREF($container) . '" class="submitStyle">' . $text . '</a>'; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | -function get_colored_text_range($value, $maxValue, $text = null, $minValue = 0, $type='Game', $return_type = 'Normal') { |
|
| 308 | - if($text == null) { |
|
| 307 | +function get_colored_text_range($value, $maxValue, $text = null, $minValue = 0, $type = 'Game', $return_type = 'Normal') { |
|
| 308 | + if ($text == null) { |
|
| 309 | 309 | $text = number_format($value); |
| 310 | 310 | } |
| 311 | - if($maxValue-$minValue==0) { |
|
| 311 | + if ($maxValue - $minValue == 0) { |
|
| 312 | 312 | return $text; |
| 313 | 313 | } |
| 314 | 314 | else { |
| 315 | - $normalisedValue = round(510*max(0,min($maxValue,$value)-$minValue)/($maxValue-$minValue))-255; |
|
| 315 | + $normalisedValue = round(510 * max(0, min($maxValue, $value) - $minValue) / ($maxValue - $minValue)) - 255; |
|
| 316 | 316 | } |
| 317 | 317 | if ($type == 'Game') { |
| 318 | - if($normalisedValue < 0) { |
|
| 319 | - $r_component='ff'; |
|
| 320 | - $g_component = dechex(255+$normalisedValue); |
|
| 321 | - if(strlen($g_component) == 1) { |
|
| 318 | + if ($normalisedValue < 0) { |
|
| 319 | + $r_component = 'ff'; |
|
| 320 | + $g_component = dechex(255 + $normalisedValue); |
|
| 321 | + if (strlen($g_component) == 1) { |
|
| 322 | 322 | $g_component = '0' . $g_component; |
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | - else if($normalisedValue > 0) { |
|
| 326 | - $g_component='ff'; |
|
| 327 | - $r_component = dechex(255-$normalisedValue); |
|
| 328 | - if(strlen($r_component) == 1) { |
|
| 325 | + else if ($normalisedValue > 0) { |
|
| 326 | + $g_component = 'ff'; |
|
| 327 | + $r_component = dechex(255 - $normalisedValue); |
|
| 328 | + if (strlen($r_component) == 1) { |
|
| 329 | 329 | $r_component = '0' . $r_component; |
| 330 | 330 | } |
| 331 | 331 | } |
@@ -347,25 +347,25 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | -function get_colored_text($value, $text = null, $type='Game', $return_type = 'Normal') { |
|
| 350 | +function get_colored_text($value, $text = null, $type = 'Game', $return_type = 'Normal') { |
|
| 351 | 351 | return get_colored_text_range($value, 300, $text, -300, $type, $return_type); |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | function word_filter($string) { |
| 355 | 355 | static $words; |
| 356 | 356 | |
| 357 | - if(!is_array($words)) { |
|
| 357 | + if (!is_array($words)) { |
|
| 358 | 358 | $db = new SmrMySqlDatabase(); |
| 359 | 359 | $db->query('SELECT word_value, word_replacement FROM word_filter'); |
| 360 | 360 | $words = array(); |
| 361 | - while($db->nextRecord()) { |
|
| 361 | + while ($db->nextRecord()) { |
|
| 362 | 362 | $row = $db->getRow(); |
| 363 | - $words[] = array('word_value' => '/'.str_replace('/','\/',$row['word_value']).'/i','word_replacement'=> $row['word_replacement']); |
|
| 363 | + $words[] = array('word_value' => '/' . str_replace('/', '\/', $row['word_value']) . '/i', 'word_replacement'=> $row['word_replacement']); |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | foreach ($words as $word) { |
| 368 | - $string = preg_replace($word['word_value'],$word['word_replacement'],$string); |
|
| 368 | + $string = preg_replace($word['word_value'], $word['word_replacement'], $string); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | return $string; |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | // choose correct pluralization based on amount |
| 375 | 375 | function pluralise($word, $count = 0) { |
| 376 | - if($count == 1) { |
|
| 376 | + if ($count == 1) { |
|
| 377 | 377 | return $word; |
| 378 | 378 | } |
| 379 | - if(strtolower($word) == 'is') { |
|
| 379 | + if (strtolower($word) == 'is') { |
|
| 380 | 380 | return 'are'; |
| 381 | 381 | } |
| 382 | 382 | return $word . 's'; |
@@ -397,10 +397,10 @@ discard block |
||
| 397 | 397 | // This function is a hack around the old style http forward mechanism |
| 398 | 398 | function do_voodoo() { |
| 399 | 399 | global $lock, $var, $template, $account; |
| 400 | - if(!defined('AJAX_CONTAINER')) { |
|
| 400 | + if (!defined('AJAX_CONTAINER')) { |
|
| 401 | 401 | define('AJAX_CONTAINER', isset($var['AJAX']) && $var['AJAX'] === true); |
| 402 | 402 | } |
| 403 | - if(!AJAX_CONTAINER && USING_AJAX && SmrSession::hasChangedSN()) { |
|
| 403 | + if (!AJAX_CONTAINER && USING_AJAX && SmrSession::hasChangedSN()) { |
|
| 404 | 404 | exit; |
| 405 | 405 | } |
| 406 | 406 | // ob_clean(); |
@@ -409,22 +409,22 @@ discard block |
||
| 409 | 409 | $$key = &$GLOBALS[$key]; |
| 410 | 410 | } |
| 411 | 411 | // create account object |
| 412 | - $account =& SmrAccount::getAccount(SmrSession::$account_id); |
|
| 413 | - $GLOBALS['account'] =& $account; |
|
| 412 | + $account = & SmrAccount::getAccount(SmrSession::$account_id); |
|
| 413 | + $GLOBALS['account'] = & $account; |
|
| 414 | 414 | |
| 415 | - if(!defined('DATE_DATE_SHORT')) define('DATE_DATE_SHORT',$account->getShortDateFormat()); |
|
| 416 | - if(!defined('DATE_TIME_SHORT')) define('DATE_TIME_SHORT',$account->getShortTimeFormat()); |
|
| 417 | - if(!defined('DATE_FULL_SHORT')) define('DATE_FULL_SHORT',DATE_DATE_SHORT.' '.DATE_TIME_SHORT); |
|
| 418 | - if(!defined('DATE_FULL_SHORT_SPLIT')) define('DATE_FULL_SHORT_SPLIT',DATE_DATE_SHORT.'\<b\r /\>'.DATE_TIME_SHORT); |
|
| 415 | + if (!defined('DATE_DATE_SHORT')) define('DATE_DATE_SHORT', $account->getShortDateFormat()); |
|
| 416 | + if (!defined('DATE_TIME_SHORT')) define('DATE_TIME_SHORT', $account->getShortTimeFormat()); |
|
| 417 | + if (!defined('DATE_FULL_SHORT')) define('DATE_FULL_SHORT', DATE_DATE_SHORT . ' ' . DATE_TIME_SHORT); |
|
| 418 | + if (!defined('DATE_FULL_SHORT_SPLIT')) define('DATE_FULL_SHORT_SPLIT', DATE_DATE_SHORT . '\<b\r /\>' . DATE_TIME_SHORT); |
|
| 419 | 419 | |
| 420 | 420 | |
| 421 | 421 | $db = new SmrMySqlDatabase(); |
| 422 | - $GLOBALS['db'] =& $db; |
|
| 422 | + $GLOBALS['db'] = & $db; |
|
| 423 | 423 | |
| 424 | - if($var['url'] == 'game_play_preprocessing.php') { // Would rather not have these here but if we go through the initialisation based on game id when leaving a classic game it breaks. |
|
| 424 | + if ($var['url'] == 'game_play_preprocessing.php') { // Would rather not have these here but if we go through the initialisation based on game id when leaving a classic game it breaks. |
|
| 425 | 425 | SmrSession::clearLinks(); |
| 426 | 426 | if (SmrSession::hasGame()) { |
| 427 | - $account->log(LOG_TYPE_GAME_ENTERING, 'Player left game '.SmrSession::getGameID()); |
|
| 427 | + $account->log(LOG_TYPE_GAME_ENTERING, 'Player left game ' . SmrSession::getGameID()); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | // reset game id |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | $sector_id = $db->getInt('sector_id'); |
| 446 | 446 | |
| 447 | 447 | global $locksFailed; |
| 448 | - if(!USING_AJAX //AJAX should never do anything that requires a lock. |
|
| 448 | + if (!USING_AJAX //AJAX should never do anything that requires a lock. |
|
| 449 | 449 | // && !isset($var['url']) && ($var['body'] == 'current_sector.php' || $var['body'] == 'map_local.php') //Neither should CS or LM and they gets loaded a lot so should reduce lag issues with big groups. |
| 450 | 450 | ) { |
| 451 | - if(!$lock && !isset($locksFailed[$sector_id])) { |
|
| 452 | - if(!acquire_lock($sector_id)) { |
|
| 451 | + if (!$lock && !isset($locksFailed[$sector_id])) { |
|
| 452 | + if (!acquire_lock($sector_id)) { |
|
| 453 | 453 | create_error('Failed to acquire sector lock'); |
| 454 | 454 | } |
| 455 | 455 | //Refetch var info in case it changed between grabbing lock. |
@@ -464,18 +464,18 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | // Now that they've acquire a lock we can move on |
| 467 | - $player =& SmrPlayer::getPlayer(SmrSession::$account_id, SmrSession::getGameID()); |
|
| 468 | - $GLOBALS['player'] =& $player; |
|
| 467 | + $player = & SmrPlayer::getPlayer(SmrSession::$account_id, SmrSession::getGameID()); |
|
| 468 | + $GLOBALS['player'] = & $player; |
|
| 469 | 469 | |
| 470 | - if($player->isDead() && $var['url'] != 'death_processing.php' && !isset($var['override_death'])) { |
|
| 470 | + if ($player->isDead() && $var['url'] != 'death_processing.php' && !isset($var['override_death'])) { |
|
| 471 | 471 | forward(create_container('death_processing.php')); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - $ship =& $player->getShip(); |
|
| 475 | - $GLOBALS['ship'] =& $ship; |
|
| 474 | + $ship = & $player->getShip(); |
|
| 475 | + $GLOBALS['ship'] = & $ship; |
|
| 476 | 476 | |
| 477 | - $sector =& $player->getSector(); |
|
| 478 | - $GLOBALS['sector'] =& $sector; |
|
| 477 | + $sector = & $player->getSector(); |
|
| 478 | + $GLOBALS['sector'] = & $sector; |
|
| 479 | 479 | |
| 480 | 480 | // update turns on that player |
| 481 | 481 | $player->updateTurns(); |
@@ -486,34 +486,34 @@ discard block |
||
| 486 | 486 | forward(create_container('newbie_warning_processing.php')); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if($var['url'] != 'skeleton.php') { |
|
| 489 | + if ($var['url'] != 'skeleton.php') { |
|
| 490 | 490 | require(get_file_loc($var['url'])); |
| 491 | 491 | } |
| 492 | - if($var['body']) { |
|
| 492 | + if ($var['body']) { |
|
| 493 | 493 | $PHP_OUTPUT = ''; |
| 494 | - if ($var['body']=='error.php') { // infinite includes for error pages |
|
| 494 | + if ($var['body'] == 'error.php') { // infinite includes for error pages |
|
| 495 | 495 | require(get_file_loc($var['body'])); |
| 496 | 496 | } |
| 497 | 497 | else { |
| 498 | 498 | require_once(get_file_loc($var['body'])); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - if($PHP_OUTPUT!='') |
|
| 502 | - $template->assign('PHP_OUTPUT',$PHP_OUTPUT); |
|
| 501 | + if ($PHP_OUTPUT != '') |
|
| 502 | + $template->assign('PHP_OUTPUT', $PHP_OUTPUT); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | if (SmrSession::hasGame()) { |
| 506 | 506 | $template->assign('UnderAttack', $ship->removeUnderAttack()); |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if($lock) { //Only save if we have the lock. |
|
| 509 | + if ($lock) { //Only save if we have the lock. |
|
| 510 | 510 | SmrSector::saveSectors(); |
| 511 | 511 | SmrShip::saveShips(); |
| 512 | 512 | SmrPlayer::savePlayers(); |
| 513 | 513 | SmrForce::saveForces(); |
| 514 | 514 | SmrPort::savePorts(); |
| 515 | 515 | SmrPlanet::savePlanets(); |
| 516 | - if(class_exists('WeightedRandom', false)) { |
|
| 516 | + if (class_exists('WeightedRandom', false)) { |
|
| 517 | 517 | WeightedRandom::saveWeightedRandoms(); |
| 518 | 518 | } |
| 519 | 519 | //Update session here to make sure current page $var is up to date before releasing lock. |
@@ -523,17 +523,17 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | //Nothing below this point should require the lock. |
| 525 | 525 | |
| 526 | - $template->assign('TemplateBody',$var['body']); |
|
| 526 | + $template->assign('TemplateBody', $var['body']); |
|
| 527 | 527 | if (SmrSession::hasGame()) { |
| 528 | - $template->assign('ThisSector',$sector); |
|
| 529 | - $template->assign('ThisPlayer',$player); |
|
| 530 | - $template->assign('ThisShip',$ship); |
|
| 528 | + $template->assign('ThisSector', $sector); |
|
| 529 | + $template->assign('ThisPlayer', $player); |
|
| 530 | + $template->assign('ThisShip', $ship); |
|
| 531 | 531 | } |
| 532 | - $template->assign('ThisAccount',$account); |
|
| 533 | - if($account->getCssLink()!=null) { |
|
| 534 | - $template->assign('ExtraCSSLink',$account->getCssLink()); |
|
| 532 | + $template->assign('ThisAccount', $account); |
|
| 533 | + if ($account->getCssLink() != null) { |
|
| 534 | + $template->assign('ExtraCSSLink', $account->getCssLink()); |
|
| 535 | 535 | } |
| 536 | - doSkeletonAssigns($template,$player,$ship,$sector,$db,$account); |
|
| 536 | + doSkeletonAssigns($template, $player, $ship, $sector, $db, $account); |
|
| 537 | 537 | |
| 538 | 538 | // Set ajax refresh time |
| 539 | 539 | $ajaxRefresh = $var['AllowAjax'] ?? true; // hack for bar_gambling_processing.php |
@@ -563,26 +563,26 @@ discard block |
||
| 563 | 563 | function acquire_lock($sector) { |
| 564 | 564 | global $db, $lock, $locksFailed; |
| 565 | 565 | |
| 566 | - if($lock) |
|
| 566 | + if ($lock) |
|
| 567 | 567 | return true; |
| 568 | 568 | |
| 569 | 569 | // Insert ourselves into the queue. |
| 570 | 570 | $db->query('INSERT INTO locks_queue (game_id,account_id,sector_id,timestamp) VALUES(' . $db->escapeNumber(SmrSession::getGameID()) . ',' . $db->escapeNumber(SmrSession::$account_id) . ',' . $db->escapeNumber($sector) . ',' . $db->escapeNumber(TIME) . ')'); |
| 571 | 571 | $lock = $db->getInsertID(); |
| 572 | 572 | |
| 573 | - for($i=0;$i<250;++$i) { |
|
| 574 | - if(time() - TIME >= LOCK_DURATION - LOCK_BUFFER) { |
|
| 573 | + for ($i = 0; $i < 250; ++$i) { |
|
| 574 | + if (time() - TIME >= LOCK_DURATION - LOCK_BUFFER) { |
|
| 575 | 575 | break; |
| 576 | 576 | } |
| 577 | 577 | // If there is someone else before us in the queue we sleep for a while |
| 578 | 578 | $db->query('SELECT COUNT(*) FROM locks_queue WHERE lock_id<' . $db->escapeNumber($lock) . ' AND sector_id=' . $db->escapeNumber($sector) . ' AND game_id=' . $db->escapeNumber(SmrSession::getGameID()) . ' AND timestamp > ' . $db->escapeNumber(TIME - LOCK_DURATION)); |
| 579 | 579 | $locksInQueue = -1; |
| 580 | - if($db->nextRecord() && ($locksInQueue = $db->getInt('COUNT(*)')) > 0) { |
|
| 580 | + if ($db->nextRecord() && ($locksInQueue = $db->getInt('COUNT(*)')) > 0) { |
|
| 581 | 581 | //usleep(100000 + mt_rand(0,50000)); |
| 582 | 582 | |
| 583 | 583 | // We can only have one lock in the queue, anything more means someone is screwing around |
| 584 | 584 | $db->query('SELECT COUNT(*) FROM locks_queue WHERE account_id=' . $db->escapeNumber(SmrSession::$account_id) . ' AND sector_id=' . $db->escapeNumber($sector) . ' AND timestamp > ' . $db->escapeNumber(TIME - LOCK_DURATION)); |
| 585 | - if($db->nextRecord() && $db->getInt('COUNT(*)') > 1) { |
|
| 585 | + if ($db->nextRecord() && $db->getInt('COUNT(*)') > 1) { |
|
| 586 | 586 | release_lock(); |
| 587 | 587 | $locksFailed[$sector] = true; |
| 588 | 588 | create_error('Multiple actions cannot be performed at the same time!'); |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | function release_lock() { |
| 605 | 605 | global $db, $lock; |
| 606 | - if($lock) { |
|
| 606 | + if ($lock) { |
|
| 607 | 607 | $db->query('DELETE from locks_queue WHERE lock_id=' . $db->escapeNumber($lock) . ' OR timestamp<' . $db->escapeNumber(TIME - LOCK_DURATION)); |
| 608 | 608 | } |
| 609 | 609 | |
@@ -612,15 +612,15 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | function doTickerAssigns($template, $player, $db) { |
| 614 | 614 | //any ticker news? |
| 615 | - if($player->hasTickers()) { |
|
| 615 | + if ($player->hasTickers()) { |
|
| 616 | 616 | $ticker = array(); |
| 617 | 617 | $max = TIME - 60; |
| 618 | - if($player->hasTicker('NEWS')) { |
|
| 618 | + if ($player->hasTicker('NEWS')) { |
|
| 619 | 619 | $text = ''; |
| 620 | 620 | //get recent news (5 mins) |
| 621 | 621 | |
| 622 | - $db->query('SELECT time,news_message FROM news WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND time >= '.$max.' ORDER BY time DESC LIMIT 4'); |
|
| 623 | - while($db->nextRecord()) { |
|
| 622 | + $db->query('SELECT time,news_message FROM news WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND time >= ' . $max . ' ORDER BY time DESC LIMIT 4'); |
|
| 623 | + while ($db->nextRecord()) { |
|
| 624 | 624 | $ticker[] = array('Time' => date(DATE_FULL_SHORT, $db->getField('time')), |
| 625 | 625 | 'Message'=>$db->getField('news_message')); |
| 626 | 626 | } |
@@ -631,15 +631,15 @@ discard block |
||
| 631 | 631 | AND game_id=' . $db->escapeNumber($player->getGameID()) . ' |
| 632 | 632 | AND message_type_id=' . $db->escapeNumber(MSG_SCOUT) . ' |
| 633 | 633 | AND send_time>=' . $db->escapeNumber($max) . ' |
| 634 | - AND sender_id NOT IN (SELECT account_id FROM player_has_ticker WHERE type='.$db->escapeString('BLOCK').' AND expires > ' . $db->escapeNumber(TIME) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ') AND receiver_delete = \'FALSE\' |
|
| 634 | + AND sender_id NOT IN (SELECT account_id FROM player_has_ticker WHERE type='.$db->escapeString('BLOCK') . ' AND expires > ' . $db->escapeNumber(TIME) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ') AND receiver_delete = \'FALSE\' |
|
| 635 | 635 | ORDER BY send_time DESC |
| 636 | 636 | LIMIT 4'); |
| 637 | - while($db->nextRecord()) { |
|
| 637 | + while ($db->nextRecord()) { |
|
| 638 | 638 | $ticker[] = array('Time' => date(DATE_FULL_SHORT, $db->getField('send_time')), |
| 639 | 639 | 'Message'=>$db->getField('message_text')); |
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | - $template->assign('Ticker',$ticker); |
|
| 642 | + $template->assign('Ticker', $ticker); |
|
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | $template->assign('CSSColourLink', $account->getCssColourUrl()); |
| 649 | 649 | |
| 650 | 650 | $template->assign('FontSize', $account->getFontSize() - 20); |
| 651 | - $template->assign('timeDisplay',date(DATE_FULL_SHORT_SPLIT,TIME)); |
|
| 651 | + $template->assign('timeDisplay', date(DATE_FULL_SHORT_SPLIT, TIME)); |
|
| 652 | 652 | |
| 653 | 653 | $container = create_container('skeleton.php'); |
| 654 | 654 | |
@@ -657,172 +657,172 @@ discard block |
||
| 657 | 657 | $template->assign('GameName', Globals::getGameName(SmrSession::getGameID())); |
| 658 | 658 | $template->assign('GameID', SmrSession::getGameID()); |
| 659 | 659 | |
| 660 | - $template->assign('PlotCourseLink',Globals::getPlotCourseHREF()); |
|
| 660 | + $template->assign('PlotCourseLink', Globals::getPlotCourseHREF()); |
|
| 661 | 661 | |
| 662 | - $template->assign('TraderLink',Globals::getTraderStatusHREF()); |
|
| 662 | + $template->assign('TraderLink', Globals::getTraderStatusHREF()); |
|
| 663 | 663 | |
| 664 | - $template->assign('PoliticsLink',Globals::getPoliticsHREF()); |
|
| 664 | + $template->assign('PoliticsLink', Globals::getPoliticsHREF()); |
|
| 665 | 665 | |
| 666 | 666 | $container['body'] = 'combat_log_list.php'; |
| 667 | - $template->assign('CombatLogsLink',SmrSession::getNewHREF($container)); |
|
| 667 | + $template->assign('CombatLogsLink', SmrSession::getNewHREF($container)); |
|
| 668 | 668 | |
| 669 | - $template->assign('PlanetLink',Globals::getPlanetListHREF($player->getAllianceID())); |
|
| 669 | + $template->assign('PlanetLink', Globals::getPlanetListHREF($player->getAllianceID())); |
|
| 670 | 670 | |
| 671 | 671 | $container['body'] = 'forces_list.php'; |
| 672 | - $template->assign('ForcesLink',SmrSession::getNewHREF($container)); |
|
| 672 | + $template->assign('ForcesLink', SmrSession::getNewHREF($container)); |
|
| 673 | 673 | |
| 674 | 674 | $container['body'] = 'message_view.php'; |
| 675 | - $template->assign('MessagesLink',SmrSession::getNewHREF($container)); |
|
| 675 | + $template->assign('MessagesLink', SmrSession::getNewHREF($container)); |
|
| 676 | 676 | |
| 677 | 677 | $container['body'] = 'news_read_current.php'; |
| 678 | - $template->assign('ReadNewsLink',SmrSession::getNewHREF($container)); |
|
| 678 | + $template->assign('ReadNewsLink', SmrSession::getNewHREF($container)); |
|
| 679 | 679 | |
| 680 | 680 | $container['body'] = 'galactic_post_current.php'; |
| 681 | - $template->assign('GalacticPostLink',SmrSession::getNewHREF($container)); |
|
| 681 | + $template->assign('GalacticPostLink', SmrSession::getNewHREF($container)); |
|
| 682 | 682 | |
| 683 | 683 | $container['body'] = 'trader_search.php'; |
| 684 | - $template->assign('SearchForTraderLink',SmrSession::getNewHREF($container)); |
|
| 684 | + $template->assign('SearchForTraderLink', SmrSession::getNewHREF($container)); |
|
| 685 | 685 | |
| 686 | 686 | $container['body'] = 'rankings_player_experience.php'; |
| 687 | - $template->assign('RankingsLink',SmrSession::getNewHREF($container)); |
|
| 687 | + $template->assign('RankingsLink', SmrSession::getNewHREF($container)); |
|
| 688 | 688 | |
| 689 | 689 | $container['body'] = 'hall_of_fame_new.php'; |
| 690 | 690 | $container['game_id'] = $player->getGameID(); |
| 691 | - $template->assign('CurrentHallOfFameLink',SmrSession::getNewHREF($container)); |
|
| 691 | + $template->assign('CurrentHallOfFameLink', SmrSession::getNewHREF($container)); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | if (SmrSession::$account_id > 0) { |
| 695 | 695 | $container = create_container('skeleton.php', 'hall_of_fame_new.php'); |
| 696 | - $template->assign('HallOfFameLink',SmrSession::getNewHREF($container)); |
|
| 696 | + $template->assign('HallOfFameLink', SmrSession::getNewHREF($container)); |
|
| 697 | 697 | |
| 698 | - $template->assign('AccountID',SmrSession::$account_id); |
|
| 699 | - $template->assign('PlayGameLink',SmrSession::getNewHREF(create_container('game_play_preprocessing.php'))); |
|
| 698 | + $template->assign('AccountID', SmrSession::$account_id); |
|
| 699 | + $template->assign('PlayGameLink', SmrSession::getNewHREF(create_container('game_play_preprocessing.php'))); |
|
| 700 | 700 | |
| 701 | - $template->assign('LogoutLink',SmrSession::getNewHREF(create_container('logoff.php'))); |
|
| 701 | + $template->assign('LogoutLink', SmrSession::getNewHREF(create_container('logoff.php'))); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | $container = create_container('skeleton.php', 'preferences.php'); |
| 705 | - $template->assign('PreferencesLink',SmrSession::getNewHREF($container)); |
|
| 705 | + $template->assign('PreferencesLink', SmrSession::getNewHREF($container)); |
|
| 706 | 706 | |
| 707 | 707 | $container['body'] = 'admin_tools.php'; |
| 708 | - $template->assign('AdminToolsLink',SmrSession::getNewHREF($container)); |
|
| 708 | + $template->assign('AdminToolsLink', SmrSession::getNewHREF($container)); |
|
| 709 | 709 | |
| 710 | 710 | $container['body'] = 'album_edit.php'; |
| 711 | - $template->assign('EditPhotoLink',SmrSession::getNewHREF($container)); |
|
| 711 | + $template->assign('EditPhotoLink', SmrSession::getNewHREF($container)); |
|
| 712 | 712 | |
| 713 | 713 | $container['body'] = 'bug_report.php'; |
| 714 | - $template->assign('ReportABugLink',SmrSession::getNewHREF($container)); |
|
| 714 | + $template->assign('ReportABugLink', SmrSession::getNewHREF($container)); |
|
| 715 | 715 | |
| 716 | 716 | $container['body'] = 'contact.php'; |
| 717 | - $template->assign('ContactFormLink',SmrSession::getNewHREF($container)); |
|
| 717 | + $template->assign('ContactFormLink', SmrSession::getNewHREF($container)); |
|
| 718 | 718 | |
| 719 | 719 | if (SmrSession::hasGame()) { |
| 720 | 720 | $container['body'] = 'chat_rules.php'; |
| 721 | - $template->assign('IRCLink',SmrSession::getNewHREF($container)); |
|
| 721 | + $template->assign('IRCLink', SmrSession::getNewHREF($container)); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | $container['body'] = 'donation.php'; |
| 725 | - $template->assign('DonateLink',SmrSession::getNewHREF($container)); |
|
| 725 | + $template->assign('DonateLink', SmrSession::getNewHREF($container)); |
|
| 726 | 726 | |
| 727 | 727 | |
| 728 | 728 | |
| 729 | 729 | if (SmrSession::hasGame()) { |
| 730 | 730 | $db->query('SELECT message_type_id,COUNT(*) FROM player_has_unread_messages WHERE account_id=' . $db->escapeNumber($player->getAccountID()) . ' AND game_id=' . $db->escapeNumber($player->getGameID()) . ' GROUP BY message_type_id'); |
| 731 | 731 | |
| 732 | - if($db->getNumRows()) { |
|
| 732 | + if ($db->getNumRows()) { |
|
| 733 | 733 | $messages = array(); |
| 734 | - while($db->nextRecord()) { |
|
| 734 | + while ($db->nextRecord()) { |
|
| 735 | 735 | $messages[$db->getInt('message_type_id')] = $db->getInt('COUNT(*)'); |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - $container = create_container('skeleton.php','message_view.php'); |
|
| 738 | + $container = create_container('skeleton.php', 'message_view.php'); |
|
| 739 | 739 | |
| 740 | - if(isset($messages[MSG_GLOBAL])) { |
|
| 740 | + if (isset($messages[MSG_GLOBAL])) { |
|
| 741 | 741 | $container['folder_id'] = MSG_GLOBAL; |
| 742 | - $template->assign('MessageGlobalLink',SmrSession::getNewHREF($container)); |
|
| 743 | - $template->assign('MessageGlobalNum',$messages[MSG_GLOBAL]); |
|
| 742 | + $template->assign('MessageGlobalLink', SmrSession::getNewHREF($container)); |
|
| 743 | + $template->assign('MessageGlobalNum', $messages[MSG_GLOBAL]); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if(isset($messages[MSG_PLAYER])) { |
|
| 746 | + if (isset($messages[MSG_PLAYER])) { |
|
| 747 | 747 | $container['folder_id'] = MSG_PLAYER; |
| 748 | - $template->assign('MessagePersonalLink',SmrSession::getNewHREF($container)); |
|
| 749 | - $template->assign('MessagePersonalNum',$messages[MSG_PLAYER]); |
|
| 748 | + $template->assign('MessagePersonalLink', SmrSession::getNewHREF($container)); |
|
| 749 | + $template->assign('MessagePersonalNum', $messages[MSG_PLAYER]); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - if(isset($messages[MSG_SCOUT])) { |
|
| 752 | + if (isset($messages[MSG_SCOUT])) { |
|
| 753 | 753 | $container['folder_id'] = MSG_SCOUT; |
| 754 | - $template->assign('MessageScoutLink',SmrSession::getNewHREF($container)); |
|
| 755 | - $template->assign('MessageScoutNum',$messages[MSG_SCOUT]); |
|
| 754 | + $template->assign('MessageScoutLink', SmrSession::getNewHREF($container)); |
|
| 755 | + $template->assign('MessageScoutNum', $messages[MSG_SCOUT]); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - if(isset($messages[MSG_POLITICAL])) { |
|
| 758 | + if (isset($messages[MSG_POLITICAL])) { |
|
| 759 | 759 | $container['folder_id'] = MSG_POLITICAL; |
| 760 | - $template->assign('MessagePoliticalLink',SmrSession::getNewHREF($container)); |
|
| 761 | - $template->assign('MessagePoliticalNum',$messages[MSG_POLITICAL]); |
|
| 760 | + $template->assign('MessagePoliticalLink', SmrSession::getNewHREF($container)); |
|
| 761 | + $template->assign('MessagePoliticalNum', $messages[MSG_POLITICAL]); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - if(isset($messages[MSG_ALLIANCE])) { |
|
| 764 | + if (isset($messages[MSG_ALLIANCE])) { |
|
| 765 | 765 | $container['folder_id'] = MSG_ALLIANCE; |
| 766 | - $template->assign('MessageAllianceLink',SmrSession::getNewHREF($container)); |
|
| 767 | - $template->assign('MessageAllianceNum',$messages[MSG_ALLIANCE]); |
|
| 766 | + $template->assign('MessageAllianceLink', SmrSession::getNewHREF($container)); |
|
| 767 | + $template->assign('MessageAllianceNum', $messages[MSG_ALLIANCE]); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | - if(isset($messages[MSG_ADMIN])) { |
|
| 770 | + if (isset($messages[MSG_ADMIN])) { |
|
| 771 | 771 | $container['folder_id'] = MSG_ADMIN; |
| 772 | - $template->assign('MessageAdminLink',SmrSession::getNewHREF($container)); |
|
| 773 | - $template->assign('MessageAdminNum',$messages[MSG_ADMIN]); |
|
| 772 | + $template->assign('MessageAdminLink', SmrSession::getNewHREF($container)); |
|
| 773 | + $template->assign('MessageAdminNum', $messages[MSG_ADMIN]); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - if(isset($messages[MSG_CASINO])) { |
|
| 776 | + if (isset($messages[MSG_CASINO])) { |
|
| 777 | 777 | $container['folder_id'] = MSG_CASINO; |
| 778 | - $template->assign('MessageCasinoLink',SmrSession::getNewHREF($container)); |
|
| 779 | - $template->assign('MessageCasinoNum',$messages[MSG_CASINO]); |
|
| 778 | + $template->assign('MessageCasinoLink', SmrSession::getNewHREF($container)); |
|
| 779 | + $template->assign('MessageCasinoNum', $messages[MSG_CASINO]); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if(isset($messages[MSG_PLANET])) { |
|
| 782 | + if (isset($messages[MSG_PLANET])) { |
|
| 783 | 783 | $container = create_container('planet_msg_processing.php'); |
| 784 | - $template->assign('MessagePlanetLink',SmrSession::getNewHREF($container)); |
|
| 785 | - $template->assign('MessagePlanetNum',$messages[MSG_PLANET]); |
|
| 784 | + $template->assign('MessagePlanetLink', SmrSession::getNewHREF($container)); |
|
| 785 | + $template->assign('MessagePlanetNum', $messages[MSG_PLANET]); |
|
| 786 | 786 | } |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | $container = create_container('skeleton.php', 'trader_search_result.php'); |
| 790 | - $container['player_id'] = $player->getPlayerID(); |
|
| 791 | - $template->assign('PlayerNameLink',SmrSession::getNewHREF($container)); |
|
| 790 | + $container['player_id'] = $player->getPlayerID(); |
|
| 791 | + $template->assign('PlayerNameLink', SmrSession::getNewHREF($container)); |
|
| 792 | 792 | |
| 793 | - if (is_array(Globals::getHiddenPlayers())&&in_array($player->getAccountID(), Globals::getHiddenPlayers())) $template->assign('PlayerInvisible',true); |
|
| 793 | + if (is_array(Globals::getHiddenPlayers()) && in_array($player->getAccountID(), Globals::getHiddenPlayers())) $template->assign('PlayerInvisible', true); |
|
| 794 | 794 | |
| 795 | 795 | // ******* Hardware ******* |
| 796 | 796 | $container = create_container('skeleton.php', 'configure_hardware.php'); |
| 797 | 797 | |
| 798 | - $template->assign('HardwareLink',SmrSession::getNewHREF($container)); |
|
| 798 | + $template->assign('HardwareLink', SmrSession::getNewHREF($container)); |
|
| 799 | 799 | |
| 800 | 800 | // ******* Forces ******* |
| 801 | - $template->assign('ForceDropLink',SmrSession::getNewHREF(create_container('skeleton.php', 'forces_drop.php'))); |
|
| 801 | + $template->assign('ForceDropLink', SmrSession::getNewHREF(create_container('skeleton.php', 'forces_drop.php'))); |
|
| 802 | 802 | |
| 803 | 803 | if ($ship->hasMines()) { |
| 804 | 804 | $container = create_container('forces_drop_processing.php'); |
| 805 | 805 | $container['owner_id'] = $player->getAccountID(); |
| 806 | 806 | $container['drop_mines'] = 1; |
| 807 | - $template->assign('DropMineLink',SmrSession::getNewHREF($container)); |
|
| 807 | + $template->assign('DropMineLink', SmrSession::getNewHREF($container)); |
|
| 808 | 808 | } |
| 809 | 809 | if ($ship->hasCDs()) { |
| 810 | 810 | $container = create_container('forces_drop_processing.php'); |
| 811 | 811 | $container['owner_id'] = $player->getAccountID(); |
| 812 | 812 | $container['drop_combat_drones'] = 1; |
| 813 | - $template->assign('DropCDLink',SmrSession::getNewHREF($container)); |
|
| 813 | + $template->assign('DropCDLink', SmrSession::getNewHREF($container)); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | if ($ship->hasSDs()) { |
| 817 | 817 | $container = create_container('forces_drop_processing.php'); |
| 818 | 818 | $container['owner_id'] = $player->getAccountID(); |
| 819 | 819 | $container['drop_scout_drones'] = 1; |
| 820 | - $template->assign('DropSDLink',SmrSession::getNewHREF($container)); |
|
| 820 | + $template->assign('DropSDLink', SmrSession::getNewHREF($container)); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | - $template->assign('CargoJettisonLink',SmrSession::getNewHREF(create_container('skeleton.php', 'cargo_dump.php'))); |
|
| 823 | + $template->assign('CargoJettisonLink', SmrSession::getNewHREF(create_container('skeleton.php', 'cargo_dump.php'))); |
|
| 824 | 824 | |
| 825 | - $template->assign('WeaponReorderLink',SmrSession::getNewHREF(create_container('skeleton.php', 'weapon_reorder.php'))); |
|
| 825 | + $template->assign('WeaponReorderLink', SmrSession::getNewHREF(create_container('skeleton.php', 'weapon_reorder.php'))); |
|
| 826 | 826 | |
| 827 | 827 | } |
| 828 | 828 | |
@@ -852,34 +852,34 @@ discard block |
||
| 852 | 852 | $version = create_link($container, 'v' . $db->getField('major_version') . '.' . $db->getField('minor_version') . '.' . $db->getField('patch_level')); |
| 853 | 853 | } |
| 854 | 854 | |
| 855 | - $template->assign('Version',$version); |
|
| 856 | - $template->assign('CurrentYear',date('Y',TIME)); |
|
| 855 | + $template->assign('Version', $version); |
|
| 856 | + $template->assign('CurrentYear', date('Y', TIME)); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | -function format_time($seconds, $short=false) { |
|
| 860 | - $minutes=0; |
|
| 861 | - $hours=0; |
|
| 862 | - $days=0; |
|
| 863 | - $weeks=0; |
|
| 859 | +function format_time($seconds, $short = false) { |
|
| 860 | + $minutes = 0; |
|
| 861 | + $hours = 0; |
|
| 862 | + $days = 0; |
|
| 863 | + $weeks = 0; |
|
| 864 | 864 | $string = ''; |
| 865 | 865 | if ($seconds == 0) { |
| 866 | 866 | $string = '0 seconds'; |
| 867 | 867 | if ($short) $string = '0s'; |
| 868 | 868 | } |
| 869 | 869 | if ($seconds >= 60) { |
| 870 | - $minutes = floor($seconds/60); |
|
| 870 | + $minutes = floor($seconds / 60); |
|
| 871 | 871 | $seconds = $seconds % 60; |
| 872 | 872 | } |
| 873 | 873 | if ($minutes >= 60) { |
| 874 | - $hours = floor($minutes/60); |
|
| 874 | + $hours = floor($minutes / 60); |
|
| 875 | 875 | $minutes = $minutes % 60; |
| 876 | 876 | } |
| 877 | 877 | if ($hours >= 24) { |
| 878 | - $days = floor($hours/24); |
|
| 878 | + $days = floor($hours / 24); |
|
| 879 | 879 | $hours = $hours % 24; |
| 880 | 880 | } |
| 881 | 881 | if ($days >= 7) { |
| 882 | - $weeks = floor($days/7); |
|
| 882 | + $weeks = floor($days / 7); |
|
| 883 | 883 | $days = $days % 7; |
| 884 | 884 | } |
| 885 | 885 | if ($weeks > 0) { |
@@ -941,19 +941,19 @@ discard block |
||
| 941 | 941 | return $string; |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | -function number_colour_format($number,$justSign = false) { |
|
| 944 | +function number_colour_format($number, $justSign = false) { |
|
| 945 | 945 | $formatted = '<span'; |
| 946 | - if($number > 0) |
|
| 946 | + if ($number > 0) |
|
| 947 | 947 | $formatted .= ' class="green">+'; |
| 948 | - else if($number < 0) |
|
| 948 | + else if ($number < 0) |
|
| 949 | 949 | $formatted .= ' class="red">-'; |
| 950 | 950 | else |
| 951 | 951 | $formatted .= '>'; |
| 952 | - if($justSign===false) { |
|
| 952 | + if ($justSign === false) { |
|
| 953 | 953 | $decimalPlaces = 0; |
| 954 | - if(($pos = strpos($number,'.'))!==false) |
|
| 955 | - $decimalPlaces = strlen(substr($number,$pos+1)); |
|
| 956 | - $formatted .= number_format(abs($number),$decimalPlaces); |
|
| 954 | + if (($pos = strpos($number, '.')) !== false) |
|
| 955 | + $decimalPlaces = strlen(substr($number, $pos + 1)); |
|
| 956 | + $formatted .= number_format(abs($number), $decimalPlaces); |
|
| 957 | 957 | } |
| 958 | 958 | $formatted .= '</span>'; |
| 959 | 959 | return $formatted; |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | // Normalize the weights so that their sum is much larger than 1. |
| 975 | 975 | $maxWeight = max($choices); |
| 976 | 976 | foreach ($choices as $key => &$weight) { |
| 977 | - $weight = round($weight * 1000/$maxWeight); |
|
| 977 | + $weight = round($weight * 1000 / $maxWeight); |
|
| 978 | 978 | } unset($weight); |
| 979 | 979 | |
| 980 | 980 | // Generate a random number that is lower than the sum of the weights. |
@@ -998,5 +998,5 @@ discard block |
||
| 998 | 998 | if ($length % 2 != 0) { |
| 999 | 999 | throw new Exception('Length must be a multiple of 2!'); |
| 1000 | 1000 | } |
| 1001 | - return bin2hex(random_bytes($length/2)); |
|
| 1001 | + return bin2hex(random_bytes($length / 2)); |
|
| 1002 | 1002 | } |
@@ -8,8 +8,9 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | function parseBoolean($check) { |
| 10 | 10 | // Only negative strings are not implicitly converted to the correct bool |
| 11 | - if(is_string($check) && (strcasecmp($check,'NO') == 0 || strcasecmp($check,'FALSE')==0)) |
|
| 12 | - return false; |
|
| 11 | + if(is_string($check) && (strcasecmp($check,'NO') == 0 || strcasecmp($check,'FALSE')==0)) { |
|
| 12 | + return false; |
|
| 13 | + } |
|
| 13 | 14 | return (bool)$check; |
| 14 | 15 | } |
| 15 | 16 | |
@@ -28,8 +29,9 @@ discard block |
||
| 28 | 29 | break; |
| 29 | 30 | case 'player': |
| 30 | 31 | $playerID = $default; |
| 31 | - if(!is_numeric($playerID)) |
|
| 32 | - $playerID = $tagParams['id']; |
|
| 32 | + if(!is_numeric($playerID)) { |
|
| 33 | + $playerID = $tagParams['id']; |
|
| 34 | + } |
|
| 33 | 35 | $bbPlayer = SmrPlayer::getPlayerByPlayerID($playerID, $overrideGameID); |
| 34 | 36 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 35 | 37 | return true; |
@@ -43,8 +45,9 @@ discard block |
||
| 43 | 45 | case 'alliance': |
| 44 | 46 | $db = new SmrMySqlDatabase(); |
| 45 | 47 | $allianceID = $default; |
| 46 | - if(!is_numeric($allianceID)) |
|
| 47 | - $allianceID = $tagParams['id']; |
|
| 48 | + if(!is_numeric($allianceID)) { |
|
| 49 | + $allianceID = $tagParams['id']; |
|
| 50 | + } |
|
| 48 | 51 | $alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID); |
| 49 | 52 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 50 | 53 | return true; |
@@ -53,10 +56,11 @@ discard block |
||
| 53 | 56 | if($disableBBLinks===false && $overrideGameID==SmrSession::getGameID()) { |
| 54 | 57 | $container = create_container('skeleton.php'); |
| 55 | 58 | $container['alliance_id'] = $alliance->getAllianceID(); |
| 56 | - if (is_object($player) && $alliance->getAllianceID() == $player->getAllianceID()) |
|
| 57 | - $container['body'] = 'alliance_mod.php'; |
|
| 58 | - else |
|
| 59 | - $container['body'] = 'alliance_roster.php'; |
|
| 59 | + if (is_object($player) && $alliance->getAllianceID() == $player->getAllianceID()) { |
|
| 60 | + $container['body'] = 'alliance_mod.php'; |
|
| 61 | + } else { |
|
| 62 | + $container['body'] = 'alliance_roster.php'; |
|
| 63 | + } |
|
| 60 | 64 | return create_link($container, $alliance->getAllianceName()); |
| 61 | 65 | } |
| 62 | 66 | return $alliance->getAllianceName(); |
@@ -80,8 +84,9 @@ discard block |
||
| 80 | 84 | return true; |
| 81 | 85 | } |
| 82 | 86 | if ($timeString != '' && ($time = strtotime($timeString)) !== false) { |
| 83 | - if(is_object($account)) |
|
| 84 | - $time += $account->getOffset() * 3600; |
|
| 87 | + if(is_object($account)) { |
|
| 88 | + $time += $account->getOffset() * 3600; |
|
| 89 | + } |
|
| 85 | 90 | return date(DATE_FULL_SHORT, $time); |
| 86 | 91 | } |
| 87 | 92 | break; |
@@ -124,8 +129,7 @@ discard block |
||
| 124 | 129 | return '<div class="buttonA"><a class="buttonA" href="' . SmrSession::getNewHREF($container) . '">Join ' . $alliance->getAllianceName() . '</a></div>'; |
| 125 | 130 | break; |
| 126 | 131 | } |
| 127 | - } |
|
| 128 | - catch (Exception $e) { |
|
| 132 | + } catch (Exception $e) { |
|
| 129 | 133 | } |
| 130 | 134 | if ($action == \Nbbc\BBCode::BBCODE_CHECK) { |
| 131 | 135 | return false; |
@@ -170,15 +174,15 @@ discard block |
||
| 170 | 174 | $bbParser->addRule('join_alliance',$smrRule); |
| 171 | 175 | } |
| 172 | 176 | global $disableBBLinks; |
| 173 | - if($noLinks===true) |
|
| 174 | - $disableBBLinks = true; |
|
| 175 | - else |
|
| 176 | - $disableBBLinks = false; |
|
| 177 | + if($noLinks===true) { |
|
| 178 | + $disableBBLinks = true; |
|
| 179 | + } else { |
|
| 180 | + $disableBBLinks = false; |
|
| 181 | + } |
|
| 177 | 182 | if(strpos($message, '[')!==false) { //We have BBCode so let's do a full parse. |
| 178 | 183 | $message = $bbParser->parse($message); |
| 179 | 184 | $message = str_replace('<br />','<br />',$message); |
| 180 | - } |
|
| 181 | - else { //Otherwise just convert newlines |
|
| 185 | + } else { //Otherwise just convert newlines |
|
| 182 | 186 | $message = nl2br($message, true); |
| 183 | 187 | } |
| 184 | 188 | return $message; |
@@ -218,8 +222,7 @@ discard block |
||
| 218 | 222 | |
| 219 | 223 | if(!is_array($actions)) { |
| 220 | 224 | $form['submit'] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($actions) . '">'; |
| 221 | - } |
|
| 222 | - else { |
|
| 225 | + } else { |
|
| 223 | 226 | $form['submit'] = array(); |
| 224 | 227 | foreach($actions as $action) { |
| 225 | 228 | $form['submit'][$action[0]] = '<input class="submit" type="submit" name="action" value="' . htmlspecialchars($action[1]) . '">'; |
@@ -264,8 +267,9 @@ discard block |
||
| 264 | 267 | } |
| 265 | 268 | |
| 266 | 269 | function forward($new_container) { |
| 267 | - if(defined('OVERRIDE_FORWARD')&&OVERRIDE_FORWARD===true) |
|
| 268 | - return overrideForward($new_container); |
|
| 270 | + if(defined('OVERRIDE_FORWARD')&&OVERRIDE_FORWARD===true) { |
|
| 271 | + return overrideForward($new_container); |
|
| 272 | + } |
|
| 269 | 273 | resetContainer($new_container); |
| 270 | 274 | do_voodoo(); |
| 271 | 275 | } |
@@ -281,8 +285,9 @@ discard block |
||
| 281 | 285 | global $var, $container; |
| 282 | 286 | |
| 283 | 287 | // transfer this value to next container |
| 284 | - if(isset($var[$what])) |
|
| 285 | - $container[$what] = $var[$what]; |
|
| 288 | + if(isset($var[$what])) { |
|
| 289 | + $container[$what] = $var[$what]; |
|
| 290 | + } |
|
| 286 | 291 | |
| 287 | 292 | } |
| 288 | 293 | |
@@ -310,8 +315,7 @@ discard block |
||
| 310 | 315 | } |
| 311 | 316 | if($maxValue-$minValue==0) { |
| 312 | 317 | return $text; |
| 313 | - } |
|
| 314 | - else { |
|
| 318 | + } else { |
|
| 315 | 319 | $normalisedValue = round(510*max(0,min($maxValue,$value)-$minValue)/($maxValue-$minValue))-255; |
| 316 | 320 | } |
| 317 | 321 | if ($type == 'Game') { |
@@ -321,28 +325,33 @@ discard block |
||
| 321 | 325 | if(strlen($g_component) == 1) { |
| 322 | 326 | $g_component = '0' . $g_component; |
| 323 | 327 | } |
| 324 | - } |
|
| 325 | - else if($normalisedValue > 0) { |
|
| 328 | + } else if($normalisedValue > 0) { |
|
| 326 | 329 | $g_component='ff'; |
| 327 | 330 | $r_component = dechex(255-$normalisedValue); |
| 328 | 331 | if(strlen($r_component) == 1) { |
| 329 | 332 | $r_component = '0' . $r_component; |
| 330 | 333 | } |
| 331 | - } |
|
| 332 | - else { |
|
| 334 | + } else { |
|
| 333 | 335 | $r_component = 'ff'; |
| 334 | 336 | $g_component = 'ff'; |
| 335 | 337 | } |
| 336 | 338 | $colour = $r_component . $g_component . '00'; |
| 337 | - if ($return_type == 'Colour') return $colour; |
|
| 339 | + if ($return_type == 'Colour') { |
|
| 340 | + return $colour; |
|
| 341 | + } |
|
| 338 | 342 | return '<span style="color:#' . $colour . '">' . $text . '</span>'; |
| 339 | - } |
|
| 340 | - elseif ($type == 'IRC') { |
|
| 343 | + } elseif ($type == 'IRC') { |
|
| 341 | 344 | //IRC color codes |
| 342 | - if ($normalisedValue == 255) $colour = '[k03]'; |
|
| 343 | - elseif ($normalisedValue == -255) $colour = '[k04]'; |
|
| 344 | - else $colour = '[k08]'; |
|
| 345 | - if ($return_type == 'Colour') return $colour; |
|
| 345 | + if ($normalisedValue == 255) { |
|
| 346 | + $colour = '[k03]'; |
|
| 347 | + } elseif ($normalisedValue == -255) { |
|
| 348 | + $colour = '[k04]'; |
|
| 349 | + } else { |
|
| 350 | + $colour = '[k08]'; |
|
| 351 | + } |
|
| 352 | + if ($return_type == 'Colour') { |
|
| 353 | + return $colour; |
|
| 354 | + } |
|
| 346 | 355 | return $colour . $text; |
| 347 | 356 | } |
| 348 | 357 | } |
@@ -412,10 +421,18 @@ discard block |
||
| 412 | 421 | $account =& SmrAccount::getAccount(SmrSession::$account_id); |
| 413 | 422 | $GLOBALS['account'] =& $account; |
| 414 | 423 | |
| 415 | - if(!defined('DATE_DATE_SHORT')) define('DATE_DATE_SHORT',$account->getShortDateFormat()); |
|
| 416 | - if(!defined('DATE_TIME_SHORT')) define('DATE_TIME_SHORT',$account->getShortTimeFormat()); |
|
| 417 | - if(!defined('DATE_FULL_SHORT')) define('DATE_FULL_SHORT',DATE_DATE_SHORT.' '.DATE_TIME_SHORT); |
|
| 418 | - if(!defined('DATE_FULL_SHORT_SPLIT')) define('DATE_FULL_SHORT_SPLIT',DATE_DATE_SHORT.'\<b\r /\>'.DATE_TIME_SHORT); |
|
| 424 | + if(!defined('DATE_DATE_SHORT')) { |
|
| 425 | + define('DATE_DATE_SHORT',$account->getShortDateFormat()); |
|
| 426 | + } |
|
| 427 | + if(!defined('DATE_TIME_SHORT')) { |
|
| 428 | + define('DATE_TIME_SHORT',$account->getShortTimeFormat()); |
|
| 429 | + } |
|
| 430 | + if(!defined('DATE_FULL_SHORT')) { |
|
| 431 | + define('DATE_FULL_SHORT',DATE_DATE_SHORT.' '.DATE_TIME_SHORT); |
|
| 432 | + } |
|
| 433 | + if(!defined('DATE_FULL_SHORT_SPLIT')) { |
|
| 434 | + define('DATE_FULL_SHORT_SPLIT',DATE_DATE_SHORT.'\<b\r /\>'.DATE_TIME_SHORT); |
|
| 435 | + } |
|
| 419 | 436 | |
| 420 | 437 | |
| 421 | 438 | $db = new SmrMySqlDatabase(); |
@@ -482,8 +499,9 @@ discard block |
||
| 482 | 499 | |
| 483 | 500 | if (!$player->isDead() && $player->getNewbieTurns() <= NEWBIE_TURNS_WARNING_LIMIT && |
| 484 | 501 | $player->getNewbieWarning() && |
| 485 | - $var['url'] != 'newbie_warning_processing.php') |
|
| 486 | - forward(create_container('newbie_warning_processing.php')); |
|
| 502 | + $var['url'] != 'newbie_warning_processing.php') { |
|
| 503 | + forward(create_container('newbie_warning_processing.php')); |
|
| 504 | + } |
|
| 487 | 505 | } |
| 488 | 506 | |
| 489 | 507 | if($var['url'] != 'skeleton.php') { |
@@ -493,13 +511,13 @@ discard block |
||
| 493 | 511 | $PHP_OUTPUT = ''; |
| 494 | 512 | if ($var['body']=='error.php') { // infinite includes for error pages |
| 495 | 513 | require(get_file_loc($var['body'])); |
| 496 | - } |
|
| 497 | - else { |
|
| 514 | + } else { |
|
| 498 | 515 | require_once(get_file_loc($var['body'])); |
| 499 | 516 | } |
| 500 | 517 | |
| 501 | - if($PHP_OUTPUT!='') |
|
| 502 | - $template->assign('PHP_OUTPUT',$PHP_OUTPUT); |
|
| 518 | + if($PHP_OUTPUT!='') { |
|
| 519 | + $template->assign('PHP_OUTPUT',$PHP_OUTPUT); |
|
| 520 | + } |
|
| 503 | 521 | } |
| 504 | 522 | |
| 505 | 523 | if (SmrSession::hasGame()) { |
@@ -563,8 +581,9 @@ discard block |
||
| 563 | 581 | function acquire_lock($sector) { |
| 564 | 582 | global $db, $lock, $locksFailed; |
| 565 | 583 | |
| 566 | - if($lock) |
|
| 567 | - return true; |
|
| 584 | + if($lock) { |
|
| 585 | + return true; |
|
| 586 | + } |
|
| 568 | 587 | |
| 569 | 588 | // Insert ourselves into the queue. |
| 570 | 589 | $db->query('INSERT INTO locks_queue (game_id,account_id,sector_id,timestamp) VALUES(' . $db->escapeNumber(SmrSession::getGameID()) . ',' . $db->escapeNumber(SmrSession::$account_id) . ',' . $db->escapeNumber($sector) . ',' . $db->escapeNumber(TIME) . ')'); |
@@ -590,8 +609,7 @@ discard block |
||
| 590 | 609 | |
| 591 | 610 | usleep(25000 * $locksInQueue); |
| 592 | 611 | continue; |
| 593 | - } |
|
| 594 | - else { |
|
| 612 | + } else { |
|
| 595 | 613 | return true; |
| 596 | 614 | } |
| 597 | 615 | } |
@@ -790,7 +808,9 @@ discard block |
||
| 790 | 808 | $container['player_id'] = $player->getPlayerID(); |
| 791 | 809 | $template->assign('PlayerNameLink',SmrSession::getNewHREF($container)); |
| 792 | 810 | |
| 793 | - if (is_array(Globals::getHiddenPlayers())&&in_array($player->getAccountID(), Globals::getHiddenPlayers())) $template->assign('PlayerInvisible',true); |
|
| 811 | + if (is_array(Globals::getHiddenPlayers())&&in_array($player->getAccountID(), Globals::getHiddenPlayers())) { |
|
| 812 | + $template->assign('PlayerInvisible',true); |
|
| 813 | + } |
|
| 794 | 814 | |
| 795 | 815 | // ******* Hardware ******* |
| 796 | 816 | $container = create_container('skeleton.php', 'configure_hardware.php'); |
@@ -864,7 +884,9 @@ discard block |
||
| 864 | 884 | $string = ''; |
| 865 | 885 | if ($seconds == 0) { |
| 866 | 886 | $string = '0 seconds'; |
| 867 | - if ($short) $string = '0s'; |
|
| 887 | + if ($short) { |
|
| 888 | + $string = '0s'; |
|
| 889 | + } |
|
| 868 | 890 | } |
| 869 | 891 | if ($seconds >= 60) { |
| 870 | 892 | $minutes = floor($seconds/60); |
@@ -884,58 +906,85 @@ discard block |
||
| 884 | 906 | } |
| 885 | 907 | if ($weeks > 0) { |
| 886 | 908 | $string .= $weeks; |
| 887 | - if ($short) $string .= 'w'; |
|
| 888 | - else { |
|
| 909 | + if ($short) { |
|
| 910 | + $string .= 'w'; |
|
| 911 | + } else { |
|
| 889 | 912 | $string .= ' week'; |
| 890 | - if ($weeks > 1) $string .= 's'; |
|
| 913 | + if ($weeks > 1) { |
|
| 914 | + $string .= 's'; |
|
| 915 | + } |
|
| 891 | 916 | } |
| 892 | 917 | } |
| 893 | 918 | if ($days > 0) { |
| 894 | 919 | $before = $weeks; |
| 895 | 920 | $after = $hours + $minutes + $seconds; |
| 896 | - if ($before > 0 && $after > 0) $string .= ', '; |
|
| 897 | - elseif ($before > 0 && $after == 0) $string .= ' and '; |
|
| 921 | + if ($before > 0 && $after > 0) { |
|
| 922 | + $string .= ', '; |
|
| 923 | + } elseif ($before > 0 && $after == 0) { |
|
| 924 | + $string .= ' and '; |
|
| 925 | + } |
|
| 898 | 926 | $string .= $days; |
| 899 | - if ($short) $string .= 'd'; |
|
| 900 | - else { |
|
| 927 | + if ($short) { |
|
| 928 | + $string .= 'd'; |
|
| 929 | + } else { |
|
| 901 | 930 | $string .= ' day'; |
| 902 | - if ($days > 1) $string .= 's'; |
|
| 931 | + if ($days > 1) { |
|
| 932 | + $string .= 's'; |
|
| 933 | + } |
|
| 903 | 934 | } |
| 904 | 935 | } |
| 905 | 936 | if ($hours > 0) { |
| 906 | 937 | $before = $weeks + $days; |
| 907 | 938 | $after = $minutes + $seconds; |
| 908 | - if ($before > 0 && $after > 0) $string .= ', '; |
|
| 909 | - elseif ($before > 0 && $after == 0) $string .= ' and '; |
|
| 939 | + if ($before > 0 && $after > 0) { |
|
| 940 | + $string .= ', '; |
|
| 941 | + } elseif ($before > 0 && $after == 0) { |
|
| 942 | + $string .= ' and '; |
|
| 943 | + } |
|
| 910 | 944 | $string .= $hours; |
| 911 | - if ($short) $string .= 'h'; |
|
| 912 | - else { |
|
| 945 | + if ($short) { |
|
| 946 | + $string .= 'h'; |
|
| 947 | + } else { |
|
| 913 | 948 | $string .= ' hour'; |
| 914 | - if ($hours > 1) $string .= 's'; |
|
| 949 | + if ($hours > 1) { |
|
| 950 | + $string .= 's'; |
|
| 951 | + } |
|
| 915 | 952 | } |
| 916 | 953 | } |
| 917 | 954 | if ($minutes > 0) { |
| 918 | 955 | $before = $weeks + $days + $hours; |
| 919 | 956 | $after = $seconds; |
| 920 | - if ($before > 0 && $after > 0) $string .= ', '; |
|
| 921 | - elseif ($before > 0 && $after == 0) $string .= ' and '; |
|
| 957 | + if ($before > 0 && $after > 0) { |
|
| 958 | + $string .= ', '; |
|
| 959 | + } elseif ($before > 0 && $after == 0) { |
|
| 960 | + $string .= ' and '; |
|
| 961 | + } |
|
| 922 | 962 | $string .= $minutes; |
| 923 | - if ($short) $string .= 'm'; |
|
| 924 | - else { |
|
| 963 | + if ($short) { |
|
| 964 | + $string .= 'm'; |
|
| 965 | + } else { |
|
| 925 | 966 | $string .= ' minute'; |
| 926 | - if ($minutes > 1) $string .= 's'; |
|
| 967 | + if ($minutes > 1) { |
|
| 968 | + $string .= 's'; |
|
| 969 | + } |
|
| 927 | 970 | } |
| 928 | 971 | } |
| 929 | 972 | if ($seconds > 0) { |
| 930 | 973 | $before = $weeks + $days + $hours + $minutes; |
| 931 | 974 | $after = 0; |
| 932 | - if ($before > 0 && $after > 0) $string .= ', '; |
|
| 933 | - elseif ($before > 0 && $after == 0) $string .= ' and '; |
|
| 975 | + if ($before > 0 && $after > 0) { |
|
| 976 | + $string .= ', '; |
|
| 977 | + } elseif ($before > 0 && $after == 0) { |
|
| 978 | + $string .= ' and '; |
|
| 979 | + } |
|
| 934 | 980 | $string .= $seconds; |
| 935 | - if ($short) $string .= 's'; |
|
| 936 | - else { |
|
| 981 | + if ($short) { |
|
| 982 | + $string .= 's'; |
|
| 983 | + } else { |
|
| 937 | 984 | $string .= ' second'; |
| 938 | - if ($seconds > 1) $string .= 's'; |
|
| 985 | + if ($seconds > 1) { |
|
| 986 | + $string .= 's'; |
|
| 987 | + } |
|
| 939 | 988 | } |
| 940 | 989 | } |
| 941 | 990 | return $string; |
@@ -943,16 +992,18 @@ discard block |
||
| 943 | 992 | |
| 944 | 993 | function number_colour_format($number,$justSign = false) { |
| 945 | 994 | $formatted = '<span'; |
| 946 | - if($number > 0) |
|
| 947 | - $formatted .= ' class="green">+'; |
|
| 948 | - else if($number < 0) |
|
| 949 | - $formatted .= ' class="red">-'; |
|
| 950 | - else |
|
| 951 | - $formatted .= '>'; |
|
| 995 | + if($number > 0) { |
|
| 996 | + $formatted .= ' class="green">+'; |
|
| 997 | + } else if($number < 0) { |
|
| 998 | + $formatted .= ' class="red">-'; |
|
| 999 | + } else { |
|
| 1000 | + $formatted .= '>'; |
|
| 1001 | + } |
|
| 952 | 1002 | if($justSign===false) { |
| 953 | 1003 | $decimalPlaces = 0; |
| 954 | - if(($pos = strpos($number,'.'))!==false) |
|
| 955 | - $decimalPlaces = strlen(substr($number,$pos+1)); |
|
| 1004 | + if(($pos = strpos($number,'.'))!==false) { |
|
| 1005 | + $decimalPlaces = strlen(substr($number,$pos+1)); |
|
| 1006 | + } |
|
| 956 | 1007 | $formatted .= number_format(abs($number),$decimalPlaces); |
| 957 | 1008 | } |
| 958 | 1009 | $formatted .= '</span>'; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('USING_AJAX')) |
|
| 4 | - define('USING_AJAX',false); |
|
| 3 | +if (!defined('USING_AJAX')) |
|
| 4 | + define('USING_AJAX', false); |
|
| 5 | 5 | class SmrSession { |
| 6 | 6 | const ALWAYS_AVAILABLE = 999999; |
| 7 | 7 | const TIME_BEFORE_EXPIRY = 3600; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | public static $last_accessed; |
| 141 | 141 | |
| 142 | 142 | protected static $previousAjaxReturns; |
| 143 | - protected static $ajaxReturns=array(); |
|
| 143 | + protected static $ajaxReturns = array(); |
|
| 144 | 144 | |
| 145 | 145 | public static function init() { |
| 146 | 146 | // Initialize the db connector here, since `init` is always called |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | else { |
| 154 | 154 | // create a new session id |
| 155 | 155 | do { |
| 156 | - self::$session_id = md5 (uniqid (mt_rand()) ); |
|
| 156 | + self::$session_id = md5(uniqid(mt_rand())); |
|
| 157 | 157 | self::$db->query('SELECT 1 FROM active_session WHERE session_id = ' . self::$db->escapeString(self::$session_id) . ' LIMIT 1'); |
| 158 | - } while(self::$db->nextRecord()); //Make sure we haven't somehow clashed with someone else's session. |
|
| 158 | + } while (self::$db->nextRecord()); //Make sure we haven't somehow clashed with someone else's session. |
|
| 159 | 159 | setcookie('session_id', self::$session_id); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | self::$db->query('DELETE FROM active_session WHERE last_accessed < ' . self::$db->escapeNumber(time() - self::TIME_BEFORE_EXPIRY)); |
| 164 | 164 | self::fetchVarInfo(); |
| 165 | 165 | |
| 166 | - if(!USING_AJAX && isset($_REQUEST['sn']) && isset(self::$var[$_REQUEST['sn']]) && !empty(self::$var[$_REQUEST['sn']])) { |
|
| 166 | + if (!USING_AJAX && isset($_REQUEST['sn']) && isset(self::$var[$_REQUEST['sn']]) && !empty(self::$var[$_REQUEST['sn']])) { |
|
| 167 | 167 | $var = self::$var[$_REQUEST['sn']]; |
| 168 | 168 | $currentPage = $var['url'] == 'skeleton.php' ? $var['body'] : $var['url']; |
| 169 | 169 | $loadDelay = isset(self::URL_LOAD_DELAY[$currentPage]) ? self::URL_LOAD_DELAY[$currentPage] : 0; |
| 170 | 170 | $initialTimeBetweenLoads = microtime(true) - $var['PreviousRequestTime']; |
| 171 | - while(($timeBetweenLoads = microtime(true) - $var['PreviousRequestTime']) < $loadDelay) { |
|
| 172 | - $sleepTime = round(($loadDelay-$timeBetweenLoads)*1000000); |
|
| 171 | + while (($timeBetweenLoads = microtime(true) - $var['PreviousRequestTime']) < $loadDelay) { |
|
| 172 | + $sleepTime = round(($loadDelay - $timeBetweenLoads) * 1000000); |
|
| 173 | 173 | // echo 'Sleeping for: ' . $sleepTime . 'us'; |
| 174 | 174 | usleep($sleepTime); |
| 175 | 175 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | self::$session_id = self::$db->getField('session_id'); |
| 187 | 187 | self::$account_id = self::$db->getInt('account_id'); |
| 188 | 188 | self::$game_id = self::$db->getInt('game_id'); |
| 189 | - self::$last_accessed = self::$db->getInt('last_accessed'); |
|
| 189 | + self::$last_accessed = self::$db->getInt('last_accessed'); |
|
| 190 | 190 | self::$var = @unserialize(@gzuncompress(self::$db->getField('session_var'))); |
| 191 | 191 | self::$commonIDs = array(); |
| 192 | 192 | self::$lastSN = self::$db->getField('last_sn'); |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | if (!empty($ajaxReturns)) { |
| 196 | 196 | self::$previousAjaxReturns = unserialize(gzuncompress($ajaxReturns)); |
| 197 | 197 | } |
| 198 | - if(!is_array(self::$var)) { |
|
| 199 | - self::$account_id = 0; |
|
| 200 | - self::$game_id = 0; |
|
| 201 | - self::$var = array(); |
|
| 198 | + if (!is_array(self::$var)) { |
|
| 199 | + self::$account_id = 0; |
|
| 200 | + self::$game_id = 0; |
|
| 201 | + self::$var = array(); |
|
| 202 | 202 | } |
| 203 | 203 | else { |
| 204 | - foreach(self::$var as $key => &$value) { |
|
| 204 | + foreach (self::$var as $key => &$value) { |
|
| 205 | 205 | if ($value['Expires'] > 0 && $value['Expires'] <= TIME) { // Use 0 for infinity |
| 206 | 206 | //This link is no longer valid |
| 207 | 207 | unset(self::$var[$key]); |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | else { |
| 214 | 214 | --$value['RemainingPageLoads']; |
| 215 | - if(isset($value['CommonID'])) { |
|
| 215 | + if (isset($value['CommonID'])) { |
|
| 216 | 216 | self::$commonIDs[$value['CommonID']] = $key; |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -221,25 +221,25 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | else { |
| 223 | 223 | self::$generate = true; |
| 224 | - self::$account_id = 0; |
|
| 224 | + self::$account_id = 0; |
|
| 225 | 225 | self::$game_id = 0; |
| 226 | - self::$var = array(); |
|
| 227 | - self::$commonIDs = array(); |
|
| 226 | + self::$var = array(); |
|
| 227 | + self::$commonIDs = array(); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | public static function update() { |
| 232 | - foreach(self::$var as $key => &$value) { |
|
| 232 | + foreach (self::$var as $key => &$value) { |
|
| 233 | 233 | if ($value['RemainingPageLoads'] <= 0) { |
| 234 | 234 | //This link was valid this load but will not be in the future, removing it now saves database space and data transfer. |
| 235 | 235 | unset(self::$var[$key]); |
| 236 | 236 | } |
| 237 | 237 | } unset($value); |
| 238 | 238 | $compressed = gzcompress(serialize(self::$var)); |
| 239 | - if(!self::$generate) { |
|
| 239 | + if (!self::$generate) { |
|
| 240 | 240 | self::$db->query('UPDATE active_session SET account_id=' . self::$db->escapeNumber(self::$account_id) . ',game_id=' . self::$db->escapeNumber(self::$game_id) . (!USING_AJAX ? ',last_accessed=' . self::$db->escapeNumber(TIME) : '') . ',session_var=' . self::$db->escapeBinary($compressed) . |
| 241 | - ',last_sn='.self::$db->escapeString(self::$SN). |
|
| 242 | - ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . (USING_AJAX ? ' AND last_sn='.self::$db->escapeString(self::$lastSN) : '') . ' LIMIT 1'); |
|
| 241 | + ',last_sn=' . self::$db->escapeString(self::$SN) . |
|
| 242 | + ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . (USING_AJAX ? ' AND last_sn=' . self::$db->escapeString(self::$lastSN) : '') . ' LIMIT 1'); |
|
| 243 | 243 | } |
| 244 | 244 | else { |
| 245 | 245 | self::$db->query('DELETE FROM active_session WHERE account_id = ' . self::$db->escapeNumber(self::$account_id) . ' AND game_id = ' . self::$db->escapeNumber(self::$game_id)); |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | private static function updateSN() { |
| 286 | - if(!USING_AJAX) |
|
| 287 | - self::$db->query('UPDATE active_session SET last_sn='.self::$db->escapeString(self::$SN). |
|
| 286 | + if (!USING_AJAX) |
|
| 287 | + self::$db->query('UPDATE active_session SET last_sn=' . self::$db->escapeString(self::$SN) . |
|
| 288 | 288 | ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . ' LIMIT 1'); |
| 289 | 289 | } |
| 290 | 290 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * Retrieve the session var for the page given by $sn. |
| 300 | 300 | * If $sn is not specified, use the current page (i.e. self::$SN). |
| 301 | 301 | */ |
| 302 | - public static function retrieveVar($sn=null) { |
|
| 302 | + public static function retrieveVar($sn = null) { |
|
| 303 | 303 | if (is_null($sn)) { |
| 304 | 304 | $sn = self::$SN; |
| 305 | 305 | } |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | self::$SN = $sn; |
| 310 | 310 | SmrSession::updateSN(); |
| 311 | - if(isset(self::$var[$sn]['body']) && isset(self::$var[$sn]['CommonID'])) { |
|
| 311 | + if (isset(self::$var[$sn]['body']) && isset(self::$var[$sn]['CommonID'])) { |
|
| 312 | 312 | // if(preg_match('/processing/',self::$var[$sn]['body'])) |
| 313 | 313 | unset(self::$commonIDs[self::$var[$sn]['CommonID']]); //Do not store common id for current page |
| 314 | 314 | unset(self::$var[$sn]['CommonID']); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * session so that it can still be retrieved when the page auto-refreshes. |
| 325 | 325 | * This is the recommended way to get $_REQUEST data. |
| 326 | 326 | */ |
| 327 | - public static function getRequestVar($varName, $default=null) { |
|
| 327 | + public static function getRequestVar($varName, $default = null) { |
|
| 328 | 328 | global $var; |
| 329 | 329 | // Set the session var, if in $_REQUESTS or if a default is given |
| 330 | 330 | if (isset($_REQUEST[$varName])) { |
@@ -340,31 +340,31 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | public static function resetLink($container, $sn) { //Do not allow sharing SN, useful for forwarding. |
| 342 | 342 | global $lock; |
| 343 | - if(isset(self::$var[$sn]['CommonID'])) { |
|
| 343 | + if (isset(self::$var[$sn]['CommonID'])) { |
|
| 344 | 344 | unset(self::$commonIDs[self::$var[$sn]['CommonID']]); //Do not store common id for reset page, to allow refreshing to always give the same page in response |
| 345 | 345 | } |
| 346 | 346 | self::$SN = $sn; |
| 347 | - if(!isset($container['Expires'])) { |
|
| 347 | + if (!isset($container['Expires'])) { |
|
| 348 | 348 | $container['Expires'] = 0; // Lasts forever |
| 349 | 349 | } |
| 350 | - if(!isset($container['RemainingPageLoads'])) { |
|
| 350 | + if (!isset($container['RemainingPageLoads'])) { |
|
| 351 | 351 | $container['RemainingPageLoads'] = 1; // Allow refreshing |
| 352 | 352 | } |
| 353 | - if(!isset($container['PreviousRequestTime'])) { |
|
| 354 | - if(isset(self::$var[$sn]['PreviousRequestTime'])) { |
|
| 353 | + if (!isset($container['PreviousRequestTime'])) { |
|
| 354 | + if (isset(self::$var[$sn]['PreviousRequestTime'])) { |
|
| 355 | 355 | $container['PreviousRequestTime'] = self::$var[$sn]['PreviousRequestTime']; // Copy across the previous request time if not explicitly set. |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | self::$var[$sn] = $container; |
| 360 | - if(!$lock && !USING_AJAX) |
|
| 360 | + if (!$lock && !USING_AJAX) |
|
| 361 | 361 | self::update(); |
| 362 | 362 | return $sn; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - public static function updateVar($key,$value) { |
|
| 365 | + public static function updateVar($key, $value) { |
|
| 366 | 366 | global $var; |
| 367 | - if($value===null) { |
|
| 367 | + if ($value === null) { |
|
| 368 | 368 | unset($var[$key]); |
| 369 | 369 | unset(self::$var[self::$SN][$key]); |
| 370 | 370 | } |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | public static function addLink($container, $sn = false) { // Container['ID'] MUST be unique to a specific action, if there will be two different outcomes from containers given the same ID then problems will likely arise. |
| 383 | - if(!isset($container['Expires'])) { |
|
| 383 | + if (!isset($container['Expires'])) { |
|
| 384 | 384 | $container['Expires'] = 0; // Lasts forever |
| 385 | 385 | } |
| 386 | - if(!isset($container['RemainingPageLoads'])) { |
|
| 386 | + if (!isset($container['RemainingPageLoads'])) { |
|
| 387 | 387 | $pageURL = $container['url'] == 'skeleton.php' ? $container['body'] : $container['url']; |
| 388 | 388 | $container['RemainingPageLoads'] = isset(self::URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL]) ? self::URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL] : 1; // Allow refreshing |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if($sn === false) { |
|
| 391 | + if ($sn === false) { |
|
| 392 | 392 | $sn = self::generateSN($container); |
| 393 | 393 | } |
| 394 | 394 | else { |
@@ -401,14 +401,14 @@ discard block |
||
| 401 | 401 | |
| 402 | 402 | protected static function generateSN(&$container) { |
| 403 | 403 | $container['CommonID'] = self::getCommonID($container); |
| 404 | - if(isset(self::$commonIDs[$container['CommonID']])) { |
|
| 404 | + if (isset(self::$commonIDs[$container['CommonID']])) { |
|
| 405 | 405 | $sn = self::$commonIDs[$container['CommonID']]; |
| 406 | 406 | $container['PreviousRequestTime'] = isset(self::$var[$sn]) ? self::$var[$sn]['PreviousRequestTime'] : MICRO_TIME; |
| 407 | 407 | } |
| 408 | 408 | else { |
| 409 | 409 | do { |
| 410 | - $sn = substr(md5(mt_rand()),0,8); |
|
| 411 | - } while(isset(self::$var[$sn])); |
|
| 410 | + $sn = substr(md5(mt_rand()), 0, 8); |
|
| 411 | + } while (isset(self::$var[$sn])); |
|
| 412 | 412 | $container['PreviousRequestTime'] = MICRO_TIME; |
| 413 | 413 | } |
| 414 | 414 | self::$commonIDs[$container['CommonID']] = $sn; |
@@ -423,21 +423,21 @@ discard block |
||
| 423 | 423 | return md5(serialize($commonContainer)); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - public static function getNewHREF($container, $forceFullURL=false) { |
|
| 427 | - $sn = self::addLink($container) . (isset($container['AJAX']) && $container['AJAX'] == true ? '&ajax=1':''); |
|
| 428 | - if($forceFullURL===true||stripos($_SERVER['REQUEST_URI'],'loader.php')===false) |
|
| 426 | + public static function getNewHREF($container, $forceFullURL = false) { |
|
| 427 | + $sn = self::addLink($container) . (isset($container['AJAX']) && $container['AJAX'] == true ? '&ajax=1' : ''); |
|
| 428 | + if ($forceFullURL === true || stripos($_SERVER['REQUEST_URI'], 'loader.php') === false) |
|
| 429 | 429 | return '/loader.php?sn=' . $sn; |
| 430 | 430 | else |
| 431 | 431 | return '?sn=' . $sn; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - public static function addAjaxReturns($element,$contents) { |
|
| 434 | + public static function addAjaxReturns($element, $contents) { |
|
| 435 | 435 | self::$ajaxReturns[$element] = $contents; |
| 436 | - return isset(self::$previousAjaxReturns[$element])&&self::$previousAjaxReturns[$element]==$contents; |
|
| 436 | + return isset(self::$previousAjaxReturns[$element]) && self::$previousAjaxReturns[$element] == $contents; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | public static function saveAjaxReturns() { |
| 440 | - if(empty(self::$ajaxReturns)) |
|
| 440 | + if (empty(self::$ajaxReturns)) |
|
| 441 | 441 | return; |
| 442 | 442 | $compressed = gzcompress(serialize(self::$ajaxReturns)); |
| 443 | 443 | self::$db->query('UPDATE active_session SET ajax_returns=' . self::$db->escapeBinary($compressed) . |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('USING_AJAX')) |
|
| 3 | +if(!defined('USING_AJAX')) { |
|
| 4 | 4 | define('USING_AJAX',false); |
| 5 | +} |
|
| 5 | 6 | class SmrSession { |
| 6 | 7 | const ALWAYS_AVAILABLE = 999999; |
| 7 | 8 | const TIME_BEFORE_EXPIRY = 3600; |
@@ -149,8 +150,7 @@ discard block |
||
| 149 | 150 | // now try the cookie |
| 150 | 151 | if (isset($_COOKIE['session_id'])) { |
| 151 | 152 | self::$session_id = $_COOKIE['session_id']; |
| 152 | - } |
|
| 153 | - else { |
|
| 153 | + } else { |
|
| 154 | 154 | // create a new session id |
| 155 | 155 | do { |
| 156 | 156 | self::$session_id = md5 (uniqid (mt_rand()) ); |
@@ -199,18 +199,15 @@ discard block |
||
| 199 | 199 | self::$account_id = 0; |
| 200 | 200 | self::$game_id = 0; |
| 201 | 201 | self::$var = array(); |
| 202 | - } |
|
| 203 | - else { |
|
| 202 | + } else { |
|
| 204 | 203 | foreach(self::$var as $key => &$value) { |
| 205 | 204 | if ($value['Expires'] > 0 && $value['Expires'] <= TIME) { // Use 0 for infinity |
| 206 | 205 | //This link is no longer valid |
| 207 | 206 | unset(self::$var[$key]); |
| 208 | - } |
|
| 209 | - else if ($value['RemainingPageLoads'] < 0) { |
|
| 207 | + } else if ($value['RemainingPageLoads'] < 0) { |
|
| 210 | 208 | //This link is no longer valid |
| 211 | 209 | unset(self::$var[$key]); |
| 212 | - } |
|
| 213 | - else { |
|
| 210 | + } else { |
|
| 214 | 211 | --$value['RemainingPageLoads']; |
| 215 | 212 | if(isset($value['CommonID'])) { |
| 216 | 213 | self::$commonIDs[$value['CommonID']] = $key; |
@@ -218,8 +215,7 @@ discard block |
||
| 218 | 215 | } |
| 219 | 216 | } unset($value); |
| 220 | 217 | } |
| 221 | - } |
|
| 222 | - else { |
|
| 218 | + } else { |
|
| 223 | 219 | self::$generate = true; |
| 224 | 220 | self::$account_id = 0; |
| 225 | 221 | self::$game_id = 0; |
@@ -240,8 +236,7 @@ discard block |
||
| 240 | 236 | self::$db->query('UPDATE active_session SET account_id=' . self::$db->escapeNumber(self::$account_id) . ',game_id=' . self::$db->escapeNumber(self::$game_id) . (!USING_AJAX ? ',last_accessed=' . self::$db->escapeNumber(TIME) : '') . ',session_var=' . self::$db->escapeBinary($compressed) . |
| 241 | 237 | ',last_sn='.self::$db->escapeString(self::$SN). |
| 242 | 238 | ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . (USING_AJAX ? ' AND last_sn='.self::$db->escapeString(self::$lastSN) : '') . ' LIMIT 1'); |
| 243 | - } |
|
| 244 | - else { |
|
| 239 | + } else { |
|
| 245 | 240 | self::$db->query('DELETE FROM active_session WHERE account_id = ' . self::$db->escapeNumber(self::$account_id) . ' AND game_id = ' . self::$db->escapeNumber(self::$game_id)); |
| 246 | 241 | self::$db->query('INSERT INTO active_session (session_id, account_id, game_id, last_accessed, session_var) VALUES(' . self::$db->escapeString(self::$session_id) . ',' . self::$db->escapeNumber(self::$account_id) . ',' . self::$db->escapeNumber(self::$game_id) . ',' . self::$db->escapeNumber(TIME) . ',' . self::$db->escapeBinary($compressed) . ')'); |
| 247 | 242 | self::$generate = false; |
@@ -283,9 +278,10 @@ discard block |
||
| 283 | 278 | } |
| 284 | 279 | |
| 285 | 280 | private static function updateSN() { |
| 286 | - if(!USING_AJAX) |
|
| 287 | - self::$db->query('UPDATE active_session SET last_sn='.self::$db->escapeString(self::$SN). |
|
| 281 | + if(!USING_AJAX) { |
|
| 282 | + self::$db->query('UPDATE active_session SET last_sn='.self::$db->escapeString(self::$SN). |
|
| 288 | 283 | ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . ' LIMIT 1'); |
| 284 | + } |
|
| 289 | 285 | } |
| 290 | 286 | |
| 291 | 287 | public static function destroy() { |
@@ -357,8 +353,9 @@ discard block |
||
| 357 | 353 | } |
| 358 | 354 | |
| 359 | 355 | self::$var[$sn] = $container; |
| 360 | - if(!$lock && !USING_AJAX) |
|
| 361 | - self::update(); |
|
| 356 | + if(!$lock && !USING_AJAX) { |
|
| 357 | + self::update(); |
|
| 358 | + } |
|
| 362 | 359 | return $sn; |
| 363 | 360 | } |
| 364 | 361 | |
@@ -367,8 +364,7 @@ discard block |
||
| 367 | 364 | if($value===null) { |
| 368 | 365 | unset($var[$key]); |
| 369 | 366 | unset(self::$var[self::$SN][$key]); |
| 370 | - } |
|
| 371 | - else { |
|
| 367 | + } else { |
|
| 372 | 368 | $var[$key] = $value; |
| 373 | 369 | self::$var[self::$SN][$key] = $value; |
| 374 | 370 | } |
@@ -390,8 +386,7 @@ discard block |
||
| 390 | 386 | |
| 391 | 387 | if($sn === false) { |
| 392 | 388 | $sn = self::generateSN($container); |
| 393 | - } |
|
| 394 | - else { |
|
| 389 | + } else { |
|
| 395 | 390 | // If we've been provided an SN to use then copy over the existing 'PreviousRequestTime' |
| 396 | 391 | $container['PreviousRequestTime'] = self::$var[$sn]['PreviousRequestTime']; |
| 397 | 392 | } |
@@ -404,8 +399,7 @@ discard block |
||
| 404 | 399 | if(isset(self::$commonIDs[$container['CommonID']])) { |
| 405 | 400 | $sn = self::$commonIDs[$container['CommonID']]; |
| 406 | 401 | $container['PreviousRequestTime'] = isset(self::$var[$sn]) ? self::$var[$sn]['PreviousRequestTime'] : MICRO_TIME; |
| 407 | - } |
|
| 408 | - else { |
|
| 402 | + } else { |
|
| 409 | 403 | do { |
| 410 | 404 | $sn = substr(md5(mt_rand()),0,8); |
| 411 | 405 | } while(isset(self::$var[$sn])); |
@@ -425,10 +419,11 @@ discard block |
||
| 425 | 419 | |
| 426 | 420 | public static function getNewHREF($container, $forceFullURL=false) { |
| 427 | 421 | $sn = self::addLink($container) . (isset($container['AJAX']) && $container['AJAX'] == true ? '&ajax=1':''); |
| 428 | - if($forceFullURL===true||stripos($_SERVER['REQUEST_URI'],'loader.php')===false) |
|
| 429 | - return '/loader.php?sn=' . $sn; |
|
| 430 | - else |
|
| 431 | - return '?sn=' . $sn; |
|
| 422 | + if($forceFullURL===true||stripos($_SERVER['REQUEST_URI'],'loader.php')===false) { |
|
| 423 | + return '/loader.php?sn=' . $sn; |
|
| 424 | + } else { |
|
| 425 | + return '?sn=' . $sn; |
|
| 426 | + } |
|
| 432 | 427 | } |
| 433 | 428 | |
| 434 | 429 | public static function addAjaxReturns($element,$contents) { |
@@ -437,8 +432,9 @@ discard block |
||
| 437 | 432 | } |
| 438 | 433 | |
| 439 | 434 | public static function saveAjaxReturns() { |
| 440 | - if(empty(self::$ajaxReturns)) |
|
| 441 | - return; |
|
| 435 | + if(empty(self::$ajaxReturns)) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 442 | 438 | $compressed = gzcompress(serialize(self::$ajaxReturns)); |
| 443 | 439 | self::$db->query('UPDATE active_session SET ajax_returns=' . self::$db->escapeBinary($compressed) . |
| 444 | 440 | ' WHERE session_id=' . self::$db->escapeString(self::$session_id) . ' LIMIT 1'); |