We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * Access properties of structures that this planet type can build. |
42 | 42 | */ |
43 | - public function structureTypes($structureID=false) { |
|
43 | + public function structureTypes($structureID = false) { |
|
44 | 44 | if (!isset($this->structures)) { |
45 | 45 | foreach (static::STRUCTURES as $ID => $Info) { |
46 | 46 | $this->structures[$ID] = new SmrPlanetStructureType($ID, $Info); |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | 'exp_gain' => 540, |
78 | 78 | ], |
79 | 79 | ]; |
80 | - public function name() { return "Terran Planet"; } |
|
81 | - public function imageLink() { return "images/planet1.png"; } |
|
82 | - public function description() { return "A lush world, with forests, seas, sweeping meadows, and indigenous lifeforms."; } |
|
80 | + public function name() { return "Terran Planet"; } |
|
81 | + public function imageLink() { return "images/planet1.png"; } |
|
82 | + public function description() { return "A lush world, with forests, seas, sweeping meadows, and indigenous lifeforms."; } |
|
83 | 83 | public function maxAttackers() { return 10; } |
84 | - public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
85 | - public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
84 | + public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
85 | + public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | class AridPlanet extends SmrPlanetType { |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | 'exp_gain' => 180, |
107 | 107 | ], |
108 | 108 | ]; |
109 | - public function name() { return "Arid Planet"; } |
|
110 | - public function imageLink() { return "images/planet2.png"; } |
|
111 | - public function description() { return "A world mostly devoid of surface water, but capable of supporting life."; } |
|
109 | + public function name() { return "Arid Planet"; } |
|
110 | + public function imageLink() { return "images/planet2.png"; } |
|
111 | + public function description() { return "A world mostly devoid of surface water, but capable of supporting life."; } |
|
112 | 112 | public function maxAttackers() { return 5; } |
113 | - public function maxLanded() { return 5; } |
|
114 | - public function menuOptions() { return ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP']; } |
|
113 | + public function maxLanded() { return 5; } |
|
114 | + public function menuOptions() { return ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP']; } |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | class DwarfPlanet extends SmrPlanetType { |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | 'exp_gain' => 540, |
136 | 136 | ], |
137 | 137 | ]; |
138 | - public function name() { return "Dwarf Planet"; } |
|
139 | - public function imageLink() { return "images/planet3.png"; } |
|
140 | - public function description() { return "A smaller than usual planet, with no native life present."; } |
|
138 | + public function name() { return "Dwarf Planet"; } |
|
139 | + public function imageLink() { return "images/planet3.png"; } |
|
140 | + public function description() { return "A smaller than usual planet, with no native life present."; } |
|
141 | 141 | public function maxAttackers() { return 5; } |
142 | - public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
143 | - public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
142 | + public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
143 | + public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | class ProtoPlanet extends SmrPlanetType { |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | 'exp_gain' => 540, |
171 | 171 | ], |
172 | 172 | ]; |
173 | - public function name() { return "Protoplanet"; } |
|
174 | - public function imageLink() { return "images/planet5.png"; } |
|
175 | - public function description() { return "A developing planet, not yet able to support the infrastructure of advanced technologies."; } |
|
173 | + public function name() { return "Protoplanet"; } |
|
174 | + public function imageLink() { return "images/planet5.png"; } |
|
175 | + public function description() { return "A developing planet, not yet able to support the infrastructure of advanced technologies."; } |
|
176 | 176 | public function maxAttackers() { return 5; } |
177 | - public function maxLanded() { return 5; } |
|
178 | - public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
177 | + public function maxLanded() { return 5; } |
|
178 | + public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | class DefenseWorld extends SmrPlanetType { |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | 'exp_gain' => 9, |
206 | 206 | ], |
207 | 207 | ]; |
208 | - public function name() { return "Defense World"; } |
|
209 | - public function imageLink() { return "images/planet4.png"; } |
|
210 | - public function description() { return "A fully armed and operational battle station loaded with excessive firepower."; } |
|
208 | + public function name() { return "Defense World"; } |
|
209 | + public function imageLink() { return "images/planet4.png"; } |
|
210 | + public function description() { return "A fully armed and operational battle station loaded with excessive firepower."; } |
|
211 | 211 | public function maxAttackers() { return 10; } |
212 | - public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
213 | - public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
212 | + public function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
213 | + public function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
214 | 214 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | private static $reverseOrder; |
5 | 5 | |
6 | 6 | private static function cmpStrProp($a, $b) { |
7 | - return (self::$reverseOrder?-1:1)*strcasecmp($a->{self::$sortKey}, $b->{self::$sortKey}); |
|
7 | + return (self::$reverseOrder ?-1 : 1) * strcasecmp($a->{self::$sortKey}, $b->{self::$sortKey}); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | private static function cmpNumElement($a, $b) { |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function cmpNum($a, $b) { |
23 | - if($a == $b) return 0; |
|
24 | - return (self::$reverseOrder?-1:1)*($a < $b ? -1 : 1); |
|
23 | + if ($a == $b) return 0; |
|
24 | + return (self::$reverseOrder ?-1 : 1) * ($a < $b ? -1 : 1); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public static function sortByStrProp(array &$array, $property, $reverseOrder = false) { |
@@ -20,7 +20,9 @@ |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function cmpNum($a, $b) { |
23 | - if($a == $b) return 0; |
|
23 | + if($a == $b) { |
|
24 | + return 0; |
|
25 | + } |
|
24 | 26 | return (self::$reverseOrder?-1:1)*($a < $b ? -1 : 1); |
25 | 27 | } |
26 | 28 |
@@ -80,7 +80,7 @@ |
||
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'] = ceil($this->getNumberOfSDs() * $this->getModifiedForceAccuracyAgainstPlayer($forces, $targetPlayer) / 100); |
85 | 85 | $damage['MaxDamage'] = ceil($damage['Launched'] * $damage['MaxDamage']); |
86 | 86 | $damage['Shield'] = ceil($damage['Launched'] * $damage['Shield']); |
@@ -960,7 +960,7 @@ |
||
960 | 960 | |
961 | 961 | public function calculateExperiencePercent($idealPrice, $offerPrice, $bargainPrice, $transactionType) { |
962 | 962 | if (($transactionType == 'Sell' && $bargainPrice < $offerPrice) || |
963 | - ($transactionType == 'Buy' && $bargainPrice > $offerPrice)) { |
|
963 | + ($transactionType == 'Buy' && $bargainPrice > $offerPrice)) { |
|
964 | 964 | return 0; |
965 | 965 | } |
966 | 966 | if ($bargainPrice == $idealPrice || $transactionType == 'Steal') { |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | do { |
1181 | 1181 | $targetPlayer = $targetPlayers[array_rand($targetPlayers)]; |
1182 | 1182 | } while ($results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()] > min($results['TotalShotsPerTargetPlayer'])); |
1183 | - $results['Weapons'][$orderID] =& $weapon->shootPlayerAsPort($this, $targetPlayer); |
|
1183 | + $results['Weapons'][$orderID] = & $weapon->shootPlayerAsPort($this, $targetPlayer); |
|
1184 | 1184 | $results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()]++; |
1185 | 1185 | if ($results['Weapons'][$orderID]['Hit']) { |
1186 | 1186 | $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | } |
1190 | 1190 | if ($this->hasCDs()) { |
1191 | 1191 | $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs(), true); |
1192 | - $results['Drones'] =& $thisCDs->shootPlayerAsPort($this, $targetPlayers[array_rand($targetPlayers)]); |
|
1192 | + $results['Drones'] = & $thisCDs->shootPlayerAsPort($this, $targetPlayers[array_rand($targetPlayers)]); |
|
1193 | 1193 | $results['TotalDamage'] += $results['Drones']['ActualDamage']['TotalDamage']; |
1194 | 1194 | $results['TotalDamagePerTargetPlayer'][$results['Drones']['TargetPlayer']->getAccountID()] += $results['Drones']['ActualDamage']['TotalDamage']; |
1195 | 1195 | } |
@@ -136,8 +136,7 @@ discard block |
||
136 | 136 | $this->checkDefenses(); |
137 | 137 | $this->getGoods(); |
138 | 138 | $this->checkForUpgrade(); |
139 | - } |
|
140 | - else { |
|
139 | + } else { |
|
141 | 140 | $this->shields = 0; |
142 | 141 | $this->combatDrones = 0; |
143 | 142 | $this->armour = 0; |
@@ -285,8 +284,9 @@ discard block |
||
285 | 284 | $x['TransactionType'] = 'Buy'; |
286 | 285 | } |
287 | 286 | $di = Plotter::findDistanceToX($x, $this->getSector(), true); |
288 | - if (is_object($di)) |
|
289 | - $di = $di->getRelativeDistance(); |
|
287 | + if (is_object($di)) { |
|
288 | + $di = $di->getRelativeDistance(); |
|
289 | + } |
|
290 | 290 | $this->goodDistances[$goodID] = max(1, $di); |
291 | 291 | } |
292 | 292 | return $this->goodDistances[$goodID]; |
@@ -312,12 +312,14 @@ discard block |
||
312 | 312 | } |
313 | 313 | |
314 | 314 | private function setGoodAmount($goodID, $amount, $doUpdate = true) { |
315 | - if ($this->isCachedVersion()) |
|
316 | - throw new Exception('Cannot update a cached port!'); |
|
315 | + if ($this->isCachedVersion()) { |
|
316 | + throw new Exception('Cannot update a cached port!'); |
|
317 | + } |
|
317 | 318 | // The new amount must be between 0 and the max for this good |
318 | 319 | $amount = max(0, min($amount, $this->getGood($goodID)['Max'])); |
319 | - if ($this->getGoodAmount($goodID) == $amount) |
|
320 | - return; |
|
320 | + if ($this->getGoodAmount($goodID) == $amount) { |
|
321 | + return; |
|
322 | + } |
|
321 | 323 | $this->goodAmounts[$goodID] = $amount; |
322 | 324 | |
323 | 325 | if ($doUpdate) { |
@@ -380,8 +382,9 @@ discard block |
||
380 | 382 | } |
381 | 383 | |
382 | 384 | public function checkForUpgrade() { |
383 | - if ($this->isCachedVersion()) |
|
384 | - throw new Exception('Cannot upgrade a cached port!'); |
|
385 | + if ($this->isCachedVersion()) { |
|
386 | + throw new Exception('Cannot upgrade a cached port!'); |
|
387 | + } |
|
385 | 388 | $upgrades = 0; |
386 | 389 | while ($this->upgrade >= $this->getUpgradeRequirement() && $this->level < 9) { |
387 | 390 | ++$upgrades; |
@@ -397,8 +400,9 @@ discard block |
||
397 | 400 | * ports to a specific level. |
398 | 401 | */ |
399 | 402 | public function upgradeToLevel($level) { |
400 | - if ($this->isCachedVersion()) |
|
401 | - throw new Exception('Cannot upgrade a cached port!'); |
|
403 | + if ($this->isCachedVersion()) { |
|
404 | + throw new Exception('Cannot upgrade a cached port!'); |
|
405 | + } |
|
402 | 406 | while ($this->getLevel() < $level) { |
403 | 407 | $this->doUpgrade(); |
404 | 408 | } |
@@ -502,8 +506,9 @@ discard block |
||
502 | 506 | * calling this function directly. |
503 | 507 | */ |
504 | 508 | public function addPortGood($goodID, $type) { |
505 | - if ($this->isCachedVersion()) |
|
506 | - throw new Exception('Cannot update a cached port!'); |
|
509 | + if ($this->isCachedVersion()) { |
|
510 | + throw new Exception('Cannot update a cached port!'); |
|
511 | + } |
|
507 | 512 | if ($this->hasGood($goodID, $type)) { |
508 | 513 | return; |
509 | 514 | } |
@@ -528,8 +533,9 @@ discard block |
||
528 | 533 | * calling this function directly. |
529 | 534 | */ |
530 | 535 | public function removePortGood($goodID) { |
531 | - if ($this->isCachedVersion()) |
|
532 | - throw new Exception('Cannot update a cached port!'); |
|
536 | + if ($this->isCachedVersion()) { |
|
537 | + throw new Exception('Cannot update a cached port!'); |
|
538 | + } |
|
533 | 539 | if (!$this->hasGood($goodID)) { |
534 | 540 | return; |
535 | 541 | } |
@@ -538,8 +544,7 @@ discard block |
||
538 | 544 | } |
539 | 545 | if (($key = array_search($goodID, $this->goodIDs['Buy'])) !== false) { |
540 | 546 | array_splice($this->goodIDs['Buy'], $key, 1); |
541 | - } |
|
542 | - elseif (($key = array_search($goodID, $this->goodIDs['Sell'])) !== false) { |
|
547 | + } elseif (($key = array_search($goodID, $this->goodIDs['Sell'])) !== false) { |
|
543 | 548 | array_splice($this->goodIDs['Sell'], $key, 1); |
544 | 549 | } |
545 | 550 | |
@@ -575,8 +580,9 @@ discard block |
||
575 | 580 | } |
576 | 581 | |
577 | 582 | protected function doDowngrade() { |
578 | - if ($this->isCachedVersion()) |
|
579 | - throw new Exception('Cannot downgrade a cached port!'); |
|
583 | + if ($this->isCachedVersion()) { |
|
584 | + throw new Exception('Cannot downgrade a cached port!'); |
|
585 | + } |
|
580 | 586 | |
581 | 587 | $goodClass = $this->getGoodClassAtLevel(); |
582 | 588 | $this->selectAndRemoveGood($goodClass); |
@@ -595,8 +601,9 @@ discard block |
||
595 | 601 | } |
596 | 602 | |
597 | 603 | public function attackedBy(AbstractSmrPlayer $trigger, array $attackers) { |
598 | - if ($this->isCachedVersion()) |
|
599 | - throw new Exception('Cannot attack a cached port!'); |
|
604 | + if ($this->isCachedVersion()) { |
|
605 | + throw new Exception('Cannot attack a cached port!'); |
|
606 | + } |
|
600 | 607 | |
601 | 608 | $trigger->increaseHOF(1, array('Combat', 'Port', 'Number Of Triggers'), HOF_PUBLIC); |
602 | 609 | foreach ($attackers as $attacker) { |
@@ -615,8 +622,7 @@ discard block |
||
615 | 622 | $newsMessage = '<span class="red bold">*MAYDAY* *MAYDAY*</span> A distress beacon has been activated by the port in sector ' . Globals::getSectorBBLink($this->getSectorID()) . '. It is under attack by '; |
616 | 623 | if ($trigger->hasAlliance()) { |
617 | 624 | $newsMessage .= 'members of ' . $trigger->getAllianceBBLink(); |
618 | - } |
|
619 | - else { |
|
625 | + } else { |
|
620 | 626 | $newsMessage .= $trigger->getBBLink(); |
621 | 627 | } |
622 | 628 | |
@@ -625,8 +631,7 @@ discard block |
||
625 | 631 | |
626 | 632 | if ($trigger->hasAlliance()) { |
627 | 633 | $newsMessage .= 'bounties of <span class="creds">' . $bounty . '</span> credits for the deaths of any raiding members of ' . $trigger->getAllianceBBLink(); |
628 | - } |
|
629 | - else { |
|
634 | + } else { |
|
630 | 635 | $newsMessage .= 'a bounty of <span class="creds">' . $bounty . '</span> credits for the death of ' . $trigger->getBBLink(); |
631 | 636 | } |
632 | 637 | $newsMessage .= ' prior to the destruction of the port, or until federal forces arrive to defend the port.'; |
@@ -640,34 +645,43 @@ discard block |
||
640 | 645 | } |
641 | 646 | |
642 | 647 | public function setShields($shields) { |
643 | - if ($this->isCachedVersion()) |
|
644 | - throw new Exception('Cannot update a cached port!'); |
|
645 | - if ($shields < 0) |
|
646 | - $shields = 0; |
|
647 | - if ($this->shields == $shields) |
|
648 | - return; |
|
648 | + if ($this->isCachedVersion()) { |
|
649 | + throw new Exception('Cannot update a cached port!'); |
|
650 | + } |
|
651 | + if ($shields < 0) { |
|
652 | + $shields = 0; |
|
653 | + } |
|
654 | + if ($this->shields == $shields) { |
|
655 | + return; |
|
656 | + } |
|
649 | 657 | $this->shields = $shields; |
650 | 658 | $this->hasChanged = true; |
651 | 659 | } |
652 | 660 | |
653 | 661 | public function setArmour($armour) { |
654 | - if ($this->isCachedVersion()) |
|
655 | - throw new Exception('Cannot update a cached port!'); |
|
656 | - if ($armour < 0) |
|
657 | - $armour = 0; |
|
658 | - if ($this->armour == $armour) |
|
659 | - return; |
|
662 | + if ($this->isCachedVersion()) { |
|
663 | + throw new Exception('Cannot update a cached port!'); |
|
664 | + } |
|
665 | + if ($armour < 0) { |
|
666 | + $armour = 0; |
|
667 | + } |
|
668 | + if ($this->armour == $armour) { |
|
669 | + return; |
|
670 | + } |
|
660 | 671 | $this->armour = $armour; |
661 | 672 | $this->hasChanged = true; |
662 | 673 | } |
663 | 674 | |
664 | 675 | public function setCDs($combatDrones) { |
665 | - if ($this->isCachedVersion()) |
|
666 | - throw new Exception('Cannot update a cached port!'); |
|
667 | - if ($combatDrones < 0) |
|
668 | - $combatDrones = 0; |
|
669 | - if ($this->combatDrones == $combatDrones) |
|
670 | - return; |
|
676 | + if ($this->isCachedVersion()) { |
|
677 | + throw new Exception('Cannot update a cached port!'); |
|
678 | + } |
|
679 | + if ($combatDrones < 0) { |
|
680 | + $combatDrones = 0; |
|
681 | + } |
|
682 | + if ($this->combatDrones == $combatDrones) { |
|
683 | + return; |
|
684 | + } |
|
671 | 685 | $this->combatDrones = $combatDrones; |
672 | 686 | $this->hasChanged = true; |
673 | 687 | } |
@@ -677,84 +691,99 @@ discard block |
||
677 | 691 | } |
678 | 692 | |
679 | 693 | public function setCredits($credits) { |
680 | - if ($this->isCachedVersion()) |
|
681 | - throw new Exception('Cannot update a cached port!'); |
|
682 | - if ($this->credits == $credits) |
|
683 | - return; |
|
694 | + if ($this->isCachedVersion()) { |
|
695 | + throw new Exception('Cannot update a cached port!'); |
|
696 | + } |
|
697 | + if ($this->credits == $credits) { |
|
698 | + return; |
|
699 | + } |
|
684 | 700 | $this->credits = $credits; |
685 | 701 | $this->hasChanged = true; |
686 | 702 | } |
687 | 703 | |
688 | 704 | public function decreaseCredits($credits) { |
689 | - if ($credits < 0) |
|
690 | - throw new Exception('Cannot decrease negative credits.'); |
|
705 | + if ($credits < 0) { |
|
706 | + throw new Exception('Cannot decrease negative credits.'); |
|
707 | + } |
|
691 | 708 | $this->setCredits($this->getCredits() - $credits); |
692 | 709 | } |
693 | 710 | |
694 | 711 | public function increaseCredits($credits) { |
695 | - if ($credits < 0) |
|
696 | - throw new Exception('Cannot increase negative credits.'); |
|
712 | + if ($credits < 0) { |
|
713 | + throw new Exception('Cannot increase negative credits.'); |
|
714 | + } |
|
697 | 715 | $this->setCredits($this->getCredits() + $credits); |
698 | 716 | } |
699 | 717 | |
700 | 718 | public function setUpgrade($upgrade) { |
701 | - if ($this->isCachedVersion()) |
|
702 | - throw new Exception('Cannot update a cached port!'); |
|
719 | + if ($this->isCachedVersion()) { |
|
720 | + throw new Exception('Cannot update a cached port!'); |
|
721 | + } |
|
703 | 722 | if ($this->getLevel() == $this->getMaxLevel()) { |
704 | 723 | $upgrade = 0; |
705 | 724 | } |
706 | - if ($this->upgrade == $upgrade) |
|
707 | - return; |
|
725 | + if ($this->upgrade == $upgrade) { |
|
726 | + return; |
|
727 | + } |
|
708 | 728 | $this->upgrade = $upgrade; |
709 | 729 | $this->hasChanged = true; |
710 | 730 | $this->checkForUpgrade(); |
711 | 731 | } |
712 | 732 | |
713 | 733 | public function decreaseUpgrade($upgrade) { |
714 | - if ($upgrade < 0) |
|
715 | - throw new Exception('Cannot decrease negative upgrade.'); |
|
734 | + if ($upgrade < 0) { |
|
735 | + throw new Exception('Cannot decrease negative upgrade.'); |
|
736 | + } |
|
716 | 737 | $this->setUpgrade($this->getUpgrade() - $upgrade); |
717 | 738 | } |
718 | 739 | |
719 | 740 | public function increaseUpgrade($upgrade) { |
720 | - if ($upgrade < 0) |
|
721 | - throw new Exception('Cannot increase negative upgrade.'); |
|
741 | + if ($upgrade < 0) { |
|
742 | + throw new Exception('Cannot increase negative upgrade.'); |
|
743 | + } |
|
722 | 744 | $this->setUpgrade($this->getUpgrade() + $upgrade); |
723 | 745 | } |
724 | 746 | |
725 | 747 | public function setLevel($level) { |
726 | - if ($this->isCachedVersion()) |
|
727 | - throw new Exception('Cannot update a cached port!'); |
|
728 | - if ($this->level == $level) |
|
729 | - return; |
|
748 | + if ($this->isCachedVersion()) { |
|
749 | + throw new Exception('Cannot update a cached port!'); |
|
750 | + } |
|
751 | + if ($this->level == $level) { |
|
752 | + return; |
|
753 | + } |
|
730 | 754 | $this->level = $level; |
731 | 755 | $this->hasChanged = true; |
732 | 756 | } |
733 | 757 | |
734 | 758 | public function increaseLevel($level) { |
735 | - if ($level < 0) |
|
736 | - throw new Exception('Cannot increase negative level.'); |
|
759 | + if ($level < 0) { |
|
760 | + throw new Exception('Cannot increase negative level.'); |
|
761 | + } |
|
737 | 762 | $this->setLevel($this->getLevel() + $level); |
738 | 763 | } |
739 | 764 | |
740 | 765 | public function decreaseLevel($level) { |
741 | - if ($level < 0) |
|
742 | - throw new Exception('Cannot increase negative level.'); |
|
766 | + if ($level < 0) { |
|
767 | + throw new Exception('Cannot increase negative level.'); |
|
768 | + } |
|
743 | 769 | $this->setLevel($this->getLevel() - $level); |
744 | 770 | } |
745 | 771 | |
746 | 772 | public function setExperience($experience) { |
747 | - if ($this->isCachedVersion()) |
|
748 | - throw new Exception('Cannot update a cached port!'); |
|
749 | - if ($this->experience == $experience) |
|
750 | - return; |
|
773 | + if ($this->isCachedVersion()) { |
|
774 | + throw new Exception('Cannot update a cached port!'); |
|
775 | + } |
|
776 | + if ($this->experience == $experience) { |
|
777 | + return; |
|
778 | + } |
|
751 | 779 | $this->experience = $experience; |
752 | 780 | $this->hasChanged = true; |
753 | 781 | } |
754 | 782 | |
755 | 783 | public function increaseExperience($experience) { |
756 | - if ($experience < 0) |
|
757 | - throw new Exception('Cannot increase negative experience.'); |
|
784 | + if ($experience < 0) { |
|
785 | + throw new Exception('Cannot increase negative experience.'); |
|
786 | + } |
|
758 | 787 | $this->setExperience($this->getExperience() + $experience); |
759 | 788 | } |
760 | 789 | |
@@ -779,8 +808,9 @@ discard block |
||
779 | 808 | } |
780 | 809 | |
781 | 810 | public function setRaceID($raceID) { |
782 | - if ($this->raceID == $raceID) |
|
783 | - return; |
|
811 | + if ($this->raceID == $raceID) { |
|
812 | + return; |
|
813 | + } |
|
784 | 814 | $this->raceID = $raceID; |
785 | 815 | $this->hasChanged = true; |
786 | 816 | $this->cacheIsValid = false; |
@@ -858,8 +888,9 @@ discard block |
||
858 | 888 | } |
859 | 889 | |
860 | 890 | public function getReinforcePercent() { |
861 | - if (!$this->isUnderAttack()) |
|
862 | - return 0; |
|
891 | + if (!$this->isUnderAttack()) { |
|
892 | + return 0; |
|
893 | + } |
|
863 | 894 | return min(1, max(0, ($this->getReinforceTime() - TIME) / ($this->getReinforceTime() - $this->getAttackStarted()))); |
864 | 895 | } |
865 | 896 | |
@@ -880,8 +911,9 @@ discard block |
||
880 | 911 | } |
881 | 912 | |
882 | 913 | private function setAttackStarted($time) { |
883 | - if ($this->attackStarted == $time) |
|
884 | - return; |
|
914 | + if ($this->attackStarted == $time) { |
|
915 | + return; |
|
916 | + } |
|
885 | 917 | $this->attackStarted = TIME; |
886 | 918 | $this->hasChanged = true; |
887 | 919 | } |
@@ -945,10 +977,10 @@ discard block |
||
945 | 977 | { |
946 | 978 | $relationsEffect = 2 - $relationsEffect; |
947 | 979 | return max($idealPrice, floor($idealPrice * $relationsEffect)); |
980 | + } else { |
|
981 | + return min($idealPrice, ceil($idealPrice * $relationsEffect)); |
|
948 | 982 | } |
949 | - else |
|
950 | - return min($idealPrice, ceil($idealPrice * $relationsEffect)); |
|
951 | -// $range = .11 - .095; |
|
983 | + // $range = .11 - .095; |
|
952 | 984 | // $rand = .095 + $range * mt_rand(0, 32767)/32767; |
953 | 985 | // |
954 | 986 | // if($transactionType == 'Buy') |
@@ -1009,8 +1041,7 @@ discard block |
||
1009 | 1041 | if ($this->getCredits() > 0) { |
1010 | 1042 | $container = create_container('skeleton.php', 'port_payout_processing.php'); |
1011 | 1043 | $container['PayoutType'] = 'Loot'; |
1012 | - } |
|
1013 | - else { |
|
1044 | + } else { |
|
1014 | 1045 | $container = create_container('skeleton.php', 'current_sector.php'); |
1015 | 1046 | $container['msg'] = 'This port has already been looted.'; |
1016 | 1047 | } |
@@ -1081,9 +1112,9 @@ discard block |
||
1081 | 1112 | if ($db->nextRecord()) { |
1082 | 1113 | self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID] = unserialize(gzuncompress($db->getField('port_info'))); |
1083 | 1114 | self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID]->setCachedTime($db->getInt('visited')); |
1115 | + } else { |
|
1116 | + self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID] = false; |
|
1084 | 1117 | } |
1085 | - else |
|
1086 | - self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID] = false; |
|
1087 | 1118 | } |
1088 | 1119 | return self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID]; |
1089 | 1120 | } |
@@ -1129,8 +1160,7 @@ discard block |
||
1129 | 1160 | ', attack_started = ' . $this->db->escapeNumber($this->getAttackStarted()) . |
1130 | 1161 | ', race_id = ' . $this->db->escapeNumber($this->getRaceID()) . ' |
1131 | 1162 | WHERE ' . $this->SQL . ' LIMIT 1'); |
1132 | - } |
|
1133 | - else { |
|
1163 | + } else { |
|
1134 | 1164 | $this->db->query('INSERT INTO port (game_id,sector_id,experience,shields,armour,combat_drones,level,credits,upgrade,reinforce_time,attack_started,race_id) |
1135 | 1165 | values |
1136 | 1166 | (' . $this->db->escapeNumber($this->getGameID()) . |
@@ -1209,11 +1239,11 @@ discard block |
||
1209 | 1239 | $cdDamage = $this->doCDDamage(min($damage['MaxDamage'], $damage['Armour'])); |
1210 | 1240 | $damage['Armour'] -= $cdDamage; |
1211 | 1241 | $damage['MaxDamage'] -= $cdDamage; |
1212 | - if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) |
|
1213 | - $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1242 | + if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) { |
|
1243 | + $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1244 | + } |
|
1214 | 1245 | } |
1215 | - } |
|
1216 | - else { //hit drones behind shields |
|
1246 | + } else { //hit drones behind shields |
|
1217 | 1247 | $cdDamage = $this->doCDDamage(floor(min($damage['MaxDamage'], $damage['Armour']) * DRONES_BEHIND_SHIELDS_DAMAGE_PERCENT)); |
1218 | 1248 | } |
1219 | 1249 | } |
@@ -1309,8 +1339,11 @@ discard block |
||
1309 | 1339 | |
1310 | 1340 | // News Entry |
1311 | 1341 | $news = $this->getDisplayName() . ' has been successfully raided by '; |
1312 | - if ($killer->hasAlliance()) $news .= 'the members of <span class="yellow">' . $killer->getAllianceBBLink() . '</span>'; |
|
1313 | - else $news .= $killer->getBBLink(); |
|
1342 | + if ($killer->hasAlliance()) { |
|
1343 | + $news .= 'the members of <span class="yellow">' . $killer->getAllianceBBLink() . '</span>'; |
|
1344 | + } else { |
|
1345 | + $news .= $killer->getBBLink(); |
|
1346 | + } |
|
1314 | 1347 | $this->db->query('INSERT INTO news (game_id, time, news_message, type,killer_id,killer_alliance,dead_id) VALUES (' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeString($news) . ', \'REGULAR\',' . $this->db->escapeNumber($killer->getAccountID()) . ',' . $this->db->escapeNumber($killer->getAllianceID()) . ',' . $this->db->escapeNumber(ACCOUNT_ID_PORT) . ')'); |
1315 | 1348 | // Killer gets a relations change and a bounty if port is taken |
1316 | 1349 | $return['KillerBounty'] = $killer->getExperience() * $this->getLevel(); |
@@ -1328,8 +1361,9 @@ discard block |
||
1328 | 1361 | |
1329 | 1362 | public function hasX(/*Object*/ $x) { |
1330 | 1363 | if (is_array($x) && $x['Type'] == 'Good') { // instanceof Good) - No Good class yet, so array is the best we can do |
1331 | - if (isset($x['ID'])) |
|
1332 | - return $this->hasGood($x['ID'], isset($x['TransactionType']) ? $x['TransactionType'] : false); |
|
1364 | + if (isset($x['ID'])) { |
|
1365 | + return $this->hasGood($x['ID'], isset($x['TransactionType']) ? $x['TransactionType'] : false); |
|
1366 | + } |
|
1333 | 1367 | } |
1334 | 1368 | return false; |
1335 | 1369 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct($dbName) { |
14 | 14 | if (!self::$dbConn) { |
15 | 15 | self::$dbConn = new mysqli(self::$host, self::$user, self::$password, |
16 | - $dbName, self::$port, self::$socket); |
|
16 | + $dbName, self::$port, self::$socket); |
|
17 | 17 | if (self::$dbConn->connect_errno) { |
18 | 18 | $this->error('Connection failed: ' . self::$dbConn->connect_error); |
19 | 19 | } |
@@ -63,8 +63,9 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | public function nextRecord() { |
66 | - if (!$this->dbResult) |
|
67 | - $this->error('No resource to get record from.'); |
|
66 | + if (!$this->dbResult) { |
|
67 | + $this->error('No resource to get record from.'); |
|
68 | + } |
|
68 | 69 | |
69 | 70 | if ($this->dbRecord = $this->dbResult->fetch_assoc()) { |
70 | 71 | return true; |
@@ -79,9 +80,10 @@ discard block |
||
79 | 80 | } |
80 | 81 | |
81 | 82 | public function getBoolean($name) { |
82 | - if ($this->dbRecord[$name] == 'TRUE') |
|
83 | - return true; |
|
84 | -// if($this->dbRecord[$name] == 'FALSE') |
|
83 | + if ($this->dbRecord[$name] == 'TRUE') { |
|
84 | + return true; |
|
85 | + } |
|
86 | + // if($this->dbRecord[$name] == 'FALSE') |
|
85 | 87 | return false; |
86 | 88 | // throw new Exception('Field is not a boolean'); |
87 | 89 | } |
@@ -114,8 +116,9 @@ discard block |
||
114 | 116 | |
115 | 117 | public function getObject($name, $compressed = false) { |
116 | 118 | $object = $this->getField($name); |
117 | - if ($compressed === true) |
|
118 | - $object = gzuncompress($object); |
|
119 | + if ($compressed === true) { |
|
120 | + $object = gzuncompress($object); |
|
121 | + } |
|
119 | 122 | return unserialize($object); |
120 | 123 | } |
121 | 124 | |
@@ -157,38 +160,43 @@ discard block |
||
157 | 160 | |
158 | 161 | public function escape($escape, $autoQuotes = true, $quotes = true) { |
159 | 162 | if (is_bool($escape)) { |
160 | - if ($autoQuotes) |
|
161 | - return $this->escapeBoolean($escape); |
|
162 | - else |
|
163 | - return $this->escapeBoolean($escape, $quotes); |
|
163 | + if ($autoQuotes) { |
|
164 | + return $this->escapeBoolean($escape); |
|
165 | + } else { |
|
166 | + return $this->escapeBoolean($escape, $quotes); |
|
167 | + } |
|
164 | 168 | } |
165 | 169 | if (is_numeric($escape)) { |
166 | 170 | return $this->escapeNumber($escape); |
167 | 171 | } |
168 | 172 | if (is_string($escape)) { |
169 | - if ($autoQuotes) |
|
170 | - return $this->escapeString($escape); |
|
171 | - else |
|
172 | - return $this->escapeString($escape, $quotes); |
|
173 | + if ($autoQuotes) { |
|
174 | + return $this->escapeString($escape); |
|
175 | + } else { |
|
176 | + return $this->escapeString($escape, $quotes); |
|
177 | + } |
|
173 | 178 | } |
174 | 179 | if (is_array($escape)) { |
175 | 180 | return $this->escapeArray($escape, $autoQuotes, $quotes); |
176 | 181 | } |
177 | 182 | if (is_object($escape)) { |
178 | - if ($autoQuotes) |
|
179 | - return $this->escapeObject($escape); |
|
180 | - else |
|
181 | - return $this->escapeObject($escape, $quotes); |
|
183 | + if ($autoQuotes) { |
|
184 | + return $this->escapeObject($escape); |
|
185 | + } else { |
|
186 | + return $this->escapeObject($escape, $quotes); |
|
187 | + } |
|
182 | 188 | } |
183 | 189 | } |
184 | 190 | |
185 | 191 | public function escapeString($string, $quotes = true, $nullable = false) { |
186 | - if ($nullable === true && ($string === null || $string === '')) |
|
187 | - return 'NULL'; |
|
188 | - if ($string === true) |
|
189 | - $string = 'TRUE'; |
|
190 | - else if ($string === false) |
|
191 | - $string = 'FALSE'; |
|
192 | + if ($nullable === true && ($string === null || $string === '')) { |
|
193 | + return 'NULL'; |
|
194 | + } |
|
195 | + if ($string === true) { |
|
196 | + $string = 'TRUE'; |
|
197 | + } else if ($string === false) { |
|
198 | + $string = 'FALSE'; |
|
199 | + } |
|
192 | 200 | if (is_array($string)) { |
193 | 201 | $escapedString = ''; |
194 | 202 | foreach ($string as $value) { |
@@ -210,14 +218,14 @@ discard block |
||
210 | 218 | $string = ''; |
211 | 219 | if ($escapeIndividually) { |
212 | 220 | foreach ($array as $value) { |
213 | - if (is_array($value)) |
|
214 | - $string .= $this->escapeArray($value, $autoQuotes, $quotes, $implodeString, $escapeIndividually) . $implodeString; |
|
215 | - else |
|
216 | - $string .= $this->escape($value, $autoQuotes, $quotes) . $implodeString; |
|
221 | + if (is_array($value)) { |
|
222 | + $string .= $this->escapeArray($value, $autoQuotes, $quotes, $implodeString, $escapeIndividually) . $implodeString; |
|
223 | + } else { |
|
224 | + $string .= $this->escape($value, $autoQuotes, $quotes) . $implodeString; |
|
225 | + } |
|
217 | 226 | } |
218 | 227 | $string = substr($string, 0, -1); |
219 | - } |
|
220 | - else { |
|
228 | + } else { |
|
221 | 229 | $string = $this->escape(implode($implodeString, $array), $autoQuotes, $quotes); |
222 | 230 | } |
223 | 231 | return $string; |
@@ -250,8 +258,9 @@ discard block |
||
250 | 258 | } |
251 | 259 | |
252 | 260 | public function escapeObject($object, $compress = false, $quotes = true, $nullable = false) { |
253 | - if ($compress === true) |
|
254 | - return $this->escapeBinary(gzcompress(serialize($object))); |
|
261 | + if ($compress === true) { |
|
262 | + return $this->escapeBinary(gzcompress(serialize($object))); |
|
263 | + } |
|
255 | 264 | return $this->escapeString(serialize($object), $quotes, $nullable); |
256 | 265 | } |
257 | 266 |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
95 | 95 | return $return; |
96 | 96 | } |
97 | - $damage =& $this->getModifiedDamage(); |
|
97 | + $damage = & $this->getModifiedDamage(); |
|
98 | 98 | if ($targetPlayer->getShip()->isFederal()) { // do less damage to fed ships |
99 | 99 | $damage['MaxDamage'] = round($damage['MaxDamage'] * self::FED_SHIP_DAMAGE_MODIFIER); |
100 | 100 | $damage['Shield'] = round($damage['Shield'] * self::FED_SHIP_DAMAGE_MODIFIER); |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | protected function &doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer, $minesAreAttacker = false) { |
134 | - $return['WeaponDamage'] =& $this->getModifiedForceDamageAgainstPlayer($forces, $targetPlayer, $minesAreAttacker); |
|
135 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doMinesDamage($return['WeaponDamage']); |
|
134 | + $return['WeaponDamage'] = & $this->getModifiedForceDamageAgainstPlayer($forces, $targetPlayer, $minesAreAttacker); |
|
135 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doMinesDamage($return['WeaponDamage']); |
|
136 | 136 | $return['ActualDamage']['Launched'] = ceil($return['WeaponDamage']['Launched'] * $return['ActualDamage']['TotalDamage'] / $return['WeaponDamage']['MaxDamage']); |
137 | 137 | |
138 | 138 | if ($return['ActualDamage']['KillingShot']) { |
139 | - $return['KillResults'] =& $targetPlayer->killPlayerByForces($forces); |
|
139 | + $return['KillResults'] = & $targetPlayer->killPlayerByForces($forces); |
|
140 | 140 | } |
141 | 141 | return $return; |
142 | 142 | } |
@@ -10,23 +10,23 @@ discard block |
||
10 | 10 | protected const USER_RANKINGS_SCORE = array( |
11 | 11 | // [Stat, a, b] |
12 | 12 | // Used as: pow(Stat * a, USER_RANKINGS_EACH_STAT_POW) * b |
13 | - array(array('Trade','Experience','Total'),.1,0.5), |
|
14 | - array(array('Trade','Money','Profit'),0.00005,0.5), |
|
15 | - array(array('Killing','Kills'),1000,1) |
|
13 | + array(array('Trade', 'Experience', 'Total'), .1, 0.5), |
|
14 | + array(array('Trade', 'Money', 'Profit'), 0.00005, 0.5), |
|
15 | + array(array('Killing', 'Kills'), 1000, 1) |
|
16 | 16 | ); |
17 | 17 | |
18 | 18 | protected static $CACHE_ACCOUNTS = array(); |
19 | 19 | protected const DEFAULT_HOTKEYS = array( |
20 | - 'MoveUp' => array('w','up'), |
|
21 | - 'ScanUp' => array('shift+w','shift+up'), |
|
22 | - 'MoveLeft' => array('a','left'), |
|
23 | - 'ScanLeft' => array('shift+a','shift+left'), |
|
24 | - 'MoveRight' => array('d','right'), |
|
25 | - 'ScanRight' => array('shift+d','shift+right'), |
|
26 | - 'MoveDown' => array('s','down'), |
|
27 | - 'ScanDown' => array('shift+s','shift+down'), |
|
28 | - 'MoveWarp' => array('e','0'), |
|
29 | - 'ScanWarp' => array('shift+e','shift+0'), |
|
20 | + 'MoveUp' => array('w', 'up'), |
|
21 | + 'ScanUp' => array('shift+w', 'shift+up'), |
|
22 | + 'MoveLeft' => array('a', 'left'), |
|
23 | + 'ScanLeft' => array('shift+a', 'shift+left'), |
|
24 | + 'MoveRight' => array('d', 'right'), |
|
25 | + 'ScanRight' => array('shift+d', 'shift+right'), |
|
26 | + 'MoveDown' => array('s', 'down'), |
|
27 | + 'ScanDown' => array('shift+s', 'shift+down'), |
|
28 | + 'MoveWarp' => array('e', '0'), |
|
29 | + 'ScanWarp' => array('shift+e', 'shift+0'), |
|
30 | 30 | 'ScanCurrent' => array('shift+1'), |
31 | 31 | 'CurrentSector' => array('1'), |
32 | 32 | 'LocalMap' => array('2'), |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | protected $oldAccountIDs = array(); |
68 | 68 | protected $maxRankAchieved; |
69 | 69 | protected $referrerID; |
70 | - protected $credits; // SMR credits |
|
70 | + protected $credits; // SMR credits |
|
71 | 71 | protected $rewardCredits; // SMR reward credits |
72 | 72 | protected $dateShort; |
73 | 73 | protected $timeShort; |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | return self::DEFAULT_HOTKEYS; |
89 | 89 | } |
90 | 90 | |
91 | - public static function &getAccount($accountID,$forceUpdate = false) { |
|
92 | - if($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
91 | + public static function &getAccount($accountID, $forceUpdate = false) { |
|
92 | + if ($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
93 | 93 | self::$CACHE_ACCOUNTS[$accountID] = new SmrAccount($accountID); |
94 | 94 | } |
95 | 95 | return self::$CACHE_ACCOUNTS[$accountID]; |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | public static function getAccountByName($login, $forceUpdate = false) { |
99 | 99 | if (empty($login)) { return null; } |
100 | 100 | $db = new SmrMySqlDatabase(); |
101 | - $db->query('SELECT account_id FROM account WHERE login = '.$db->escapeString($login).' LIMIT 1'); |
|
102 | - if($db->nextRecord()) |
|
103 | - return self::getAccount($db->getField('account_id'),$forceUpdate); |
|
101 | + $db->query('SELECT account_id FROM account WHERE login = ' . $db->escapeString($login) . ' LIMIT 1'); |
|
102 | + if ($db->nextRecord()) |
|
103 | + return self::getAccount($db->getField('account_id'), $forceUpdate); |
|
104 | 104 | $return = null; |
105 | 105 | return $return; |
106 | 106 | } |
107 | 107 | |
108 | - public static function getAccountByEmail($email, $forceUpdate=false) { |
|
108 | + public static function getAccountByEmail($email, $forceUpdate = false) { |
|
109 | 109 | if (empty($email)) { return null; } |
110 | 110 | $db = new SmrMySqlDatabase(); |
111 | - $db->query('SELECT account_id FROM account WHERE email = '.$db->escapeString($email).' LIMIT 1'); |
|
111 | + $db->query('SELECT account_id FROM account WHERE email = ' . $db->escapeString($email) . ' LIMIT 1'); |
|
112 | 112 | if ($db->nextRecord()) { |
113 | 113 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
114 | 114 | } else { |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - public static function getAccountByDiscordId($id, $forceUpdate=false) { |
|
119 | + public static function getAccountByDiscordId($id, $forceUpdate = false) { |
|
120 | 120 | if (empty($id)) { return null; } |
121 | 121 | $db = new SmrMySqlDatabase(); |
122 | - $db->query('SELECT account_id FROM account where discord_id = '.$db->escapeString($id).' LIMIT 1'); |
|
122 | + $db->query('SELECT account_id FROM account where discord_id = ' . $db->escapeString($id) . ' LIMIT 1'); |
|
123 | 123 | if ($db->nextRecord()) { |
124 | 124 | return self::getAccount($db->getField('account_id'), $forceUpdate); |
125 | 125 | } else { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | public static function getAccountByIrcNick($nick, $forceUpdate = false) { |
131 | 131 | if (empty($nick)) { return null; } |
132 | 132 | $db = new SmrMySqlDatabase(); |
133 | - $db->query('SELECT account_id FROM account WHERE irc_nick = '.$db->escapeString($nick).' LIMIT 1'); |
|
133 | + $db->query('SELECT account_id FROM account WHERE irc_nick = ' . $db->escapeString($nick) . ' LIMIT 1'); |
|
134 | 134 | if ($db->nextRecord()) { |
135 | 135 | return self::getAccount($db->getField('account_id'), $forceUpdate); |
136 | 136 | } else { |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate=false) { |
|
141 | + public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate = false) { |
|
142 | 142 | if (!$social->isValid()) { return null; } |
143 | 143 | $db = new SmrMySqlDatabase(); |
144 | 144 | $db->query('SELECT account_id FROM account JOIN account_auth USING(account_id) |
145 | - WHERE login_type = '.$db->escapeString($social->getLoginType()).' |
|
146 | - AND auth_key = '.$db->escapeString($social->getUserID()).' LIMIT 1'); |
|
145 | + WHERE login_type = '.$db->escapeString($social->getLoginType()) . ' |
|
146 | + AND auth_key = '.$db->escapeString($social->getUserID()) . ' LIMIT 1'); |
|
147 | 147 | if ($db->nextRecord()) { |
148 | 148 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
149 | 149 | } else { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | public static function createAccount($login, $password, $email, $timez, $referral) { |
155 | - if($referral!=0) { |
|
155 | + if ($referral != 0) { |
|
156 | 156 | // Will throw if referral account doesn't exist |
157 | 157 | SmrAccount::getAccount($referral); |
158 | 158 | } |
@@ -160,60 +160,60 @@ discard block |
||
160 | 160 | $passwordHash = password_hash($password, PASSWORD_DEFAULT); |
161 | 161 | $db->query('INSERT INTO account (login, password, email, validation_code, last_login, offset,referral_id,hof_name) VALUES(' . |
162 | 162 | $db->escapeString($login) . ', ' . $db->escapeString($passwordHash) . ', ' . $db->escapeString($email) . ', ' . |
163 | - $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral).','.$db->escapeString($login).')'); |
|
163 | + $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral) . ',' . $db->escapeString($login) . ')'); |
|
164 | 164 | return self::getAccountByName($login); |
165 | 165 | } |
166 | 166 | |
167 | 167 | public static function getUserScoreCaseStatement($db) { |
168 | 168 | $userRankingTypes = array(); |
169 | 169 | $case = 'FLOOR(SUM(CASE type '; |
170 | - foreach(self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
171 | - $userRankingType = $db->escapeArray($userRankingScore[0],false,false,':',false); |
|
170 | + foreach (self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
171 | + $userRankingType = $db->escapeArray($userRankingScore[0], false, false, ':', false); |
|
172 | 172 | $userRankingTypes[] = $userRankingType; |
173 | - $case.= ' WHEN '.$db->escapeString($userRankingType).' THEN POW(amount*'.$userRankingScore[1].','.SmrAccount::USER_RANKINGS_EACH_STAT_POW.')*'.$userRankingScore[2]; |
|
173 | + $case .= ' WHEN ' . $db->escapeString($userRankingType) . ' THEN POW(amount*' . $userRankingScore[1] . ',' . SmrAccount::USER_RANKINGS_EACH_STAT_POW . ')*' . $userRankingScore[2]; |
|
174 | 174 | } |
175 | 175 | $case .= ' END))'; |
176 | - return array('CASE'=>$case,'IN'=>$db->escapeArray($userRankingTypes)); |
|
176 | + return array('CASE'=>$case, 'IN'=>$db->escapeArray($userRankingTypes)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | protected function __construct($accountID) { |
180 | 180 | $this->db = new SmrMySqlDatabase(); |
181 | 181 | $this->SQL = 'account_id = ' . $this->db->escapeNumber($accountID); |
182 | - $this->db->query('SELECT * FROM account WHERE '.$this->SQL.' LIMIT 1'); |
|
182 | + $this->db->query('SELECT * FROM account WHERE ' . $this->SQL . ' LIMIT 1'); |
|
183 | 183 | |
184 | 184 | if ($this->db->nextRecord()) { |
185 | 185 | $row = $this->db->getRow(); |
186 | - $this->account_id = $row['account_id']; |
|
186 | + $this->account_id = $row['account_id']; |
|
187 | 187 | |
188 | 188 | $this->login = $row['login']; |
189 | - $this->passwordHash = $row['password']; |
|
189 | + $this->passwordHash = $row['password']; |
|
190 | 190 | $this->email = $row['email']; |
191 | - $this->validated = $this->db->getBoolean('validated'); |
|
191 | + $this->validated = $this->db->getBoolean('validated'); |
|
192 | 192 | |
193 | - $this->last_login = $row['last_login']; |
|
194 | - $this->validation_code = $row['validation_code']; |
|
195 | - $this->veteranForced = $this->db->getBoolean('veteran'); |
|
196 | - $this->logging = $this->db->getBoolean('logging'); |
|
193 | + $this->last_login = $row['last_login']; |
|
194 | + $this->validation_code = $row['validation_code']; |
|
195 | + $this->veteranForced = $this->db->getBoolean('veteran'); |
|
196 | + $this->logging = $this->db->getBoolean('logging'); |
|
197 | 197 | $this->offset = $row['offset']; |
198 | 198 | $this->images = $row['images']; |
199 | - $this->fontSize = $row['fontsize']; |
|
199 | + $this->fontSize = $row['fontsize']; |
|
200 | 200 | |
201 | - $this->passwordReset = $row['password_reset']; |
|
202 | - $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
203 | - $this->mailBanned = (int)$row['mail_banned']; |
|
201 | + $this->passwordReset = $row['password_reset']; |
|
202 | + $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
203 | + $this->mailBanned = (int)$row['mail_banned']; |
|
204 | 204 | |
205 | - $this->friendlyColour = $row['friendly_colour']; |
|
206 | - $this->neutralColour = $row['neutral_colour']; |
|
207 | - $this->enemyColour = $row['enemy_colour']; |
|
205 | + $this->friendlyColour = $row['friendly_colour']; |
|
206 | + $this->neutralColour = $row['neutral_colour']; |
|
207 | + $this->enemyColour = $row['enemy_colour']; |
|
208 | 208 | |
209 | - $this->cssLink = $row['css_link']; |
|
210 | - $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
211 | - $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
209 | + $this->cssLink = $row['css_link']; |
|
210 | + $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
211 | + $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
212 | 212 | |
213 | 213 | $this->messageNotifications = $this->db->getObject('message_notifications'); |
214 | 214 | $this->hotkeys = $this->db->getObject('hotkeys'); |
215 | - foreach(self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
216 | - if(!isset($this->hotkeys[$hotkey])) { |
|
215 | + foreach (self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
216 | + if (!isset($this->hotkeys[$hotkey])) { |
|
217 | 217 | $this->hotkeys[$hotkey] = $binding; |
218 | 218 | } |
219 | 219 | } |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | $this->oldAccountIDs[$databaseName] = $row[$oldColumn]; |
223 | 223 | } |
224 | 224 | |
225 | - $this->referrerID = $row['referral_id']; |
|
226 | - $this->maxRankAchieved = $row['max_rank_achieved']; |
|
225 | + $this->referrerID = $row['referral_id']; |
|
226 | + $this->maxRankAchieved = $row['max_rank_achieved']; |
|
227 | 227 | |
228 | 228 | $this->hofName = $row['hof_name']; |
229 | 229 | $this->discordId = $row['discord_id']; |
@@ -233,19 +233,19 @@ discard block |
||
233 | 233 | $this->timeShort = $row['time_short']; |
234 | 234 | |
235 | 235 | $this->template = $row['template']; |
236 | - $this->colourScheme = $row['colour_scheme']; |
|
236 | + $this->colourScheme = $row['colour_scheme']; |
|
237 | 237 | |
238 | - if(empty($this->hofName)) |
|
239 | - $this->hofName=$this->login; |
|
238 | + if (empty($this->hofName)) |
|
239 | + $this->hofName = $this->login; |
|
240 | 240 | } |
241 | 241 | else { |
242 | - throw new AccountNotFoundException('Account ID '.$accountID.' does not exist!'); |
|
242 | + throw new AccountNotFoundException('Account ID ' . $accountID . ' does not exist!'); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | 246 | public function isDisabled() { |
247 | 247 | $this->db->query('SELECT * FROM account_is_closed JOIN closing_reason USING(reason_id) ' . |
248 | - 'WHERE '.$this->SQL.' LIMIT 1'); |
|
248 | + 'WHERE ' . $this->SQL . ' LIMIT 1'); |
|
249 | 249 | if ($this->db->nextRecord()) { |
250 | 250 | // get the expire time |
251 | 251 | $expireTime = $this->db->getInt('expires'); |
@@ -267,64 +267,64 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | public function update() { |
270 | - $this->db->query('UPDATE account SET email = '.$this->db->escapeString($this->email). |
|
271 | - ', validation_code = '.$this->db->escapeString($this->validation_code). |
|
272 | - ', validated = '.$this->db->escapeBoolean($this->validated). |
|
273 | - ', password = '.$this->db->escapeString($this->passwordHash). |
|
274 | - ', images = '.$this->db->escapeString($this->images). |
|
275 | - ', password_reset = '.$this->db->escapeString($this->passwordReset). |
|
276 | - ', use_ajax='.$this->db->escapeBoolean($this->useAJAX). |
|
277 | - ', mail_banned='.$this->db->escapeNumber($this->mailBanned). |
|
278 | - ', max_rank_achieved='.$this->db->escapeNumber($this->maxRankAchieved). |
|
279 | - ', default_css_enabled='.$this->db->escapeBoolean($this->defaultCSSEnabled). |
|
280 | - ', center_galaxy_map_on_player='.$this->db->escapeBoolean($this->centerGalaxyMapOnPlayer). |
|
281 | - ', message_notifications='.$this->db->escapeObject($this->messageNotifications). |
|
282 | - ', hotkeys='.$this->db->escapeObject($this->hotkeys). |
|
283 | - ', last_login = '.$this->db->escapeNumber($this->last_login). |
|
284 | - ', logging = '.$this->db->escapeBoolean($this->logging). |
|
285 | - ', time_short = ' . $this->db->escapeString($this->timeShort). |
|
286 | - ', date_short = ' . $this->db->escapeString($this->dateShort). |
|
287 | - ', discord_id = ' . $this->db->escapeString($this->discordId, true, true). |
|
288 | - ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true). |
|
289 | - ', hof_name = ' . $this->db->escapeString($this->hofName). |
|
290 | - ', colour_scheme = ' . $this->db->escapeString($this->colourScheme). |
|
291 | - ', fontsize = ' . $this->db->escapeNumber($this->fontSize). |
|
292 | - ', css_link = ' . $this->db->escapeString($this->cssLink,true,true). |
|
293 | - ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true). |
|
294 | - ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true). |
|
295 | - ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true). |
|
296 | - ' WHERE '.$this->SQL.' LIMIT 1'); |
|
270 | + $this->db->query('UPDATE account SET email = ' . $this->db->escapeString($this->email) . |
|
271 | + ', validation_code = ' . $this->db->escapeString($this->validation_code) . |
|
272 | + ', validated = ' . $this->db->escapeBoolean($this->validated) . |
|
273 | + ', password = ' . $this->db->escapeString($this->passwordHash) . |
|
274 | + ', images = ' . $this->db->escapeString($this->images) . |
|
275 | + ', password_reset = ' . $this->db->escapeString($this->passwordReset) . |
|
276 | + ', use_ajax=' . $this->db->escapeBoolean($this->useAJAX) . |
|
277 | + ', mail_banned=' . $this->db->escapeNumber($this->mailBanned) . |
|
278 | + ', max_rank_achieved=' . $this->db->escapeNumber($this->maxRankAchieved) . |
|
279 | + ', default_css_enabled=' . $this->db->escapeBoolean($this->defaultCSSEnabled) . |
|
280 | + ', center_galaxy_map_on_player=' . $this->db->escapeBoolean($this->centerGalaxyMapOnPlayer) . |
|
281 | + ', message_notifications=' . $this->db->escapeObject($this->messageNotifications) . |
|
282 | + ', hotkeys=' . $this->db->escapeObject($this->hotkeys) . |
|
283 | + ', last_login = ' . $this->db->escapeNumber($this->last_login) . |
|
284 | + ', logging = ' . $this->db->escapeBoolean($this->logging) . |
|
285 | + ', time_short = ' . $this->db->escapeString($this->timeShort) . |
|
286 | + ', date_short = ' . $this->db->escapeString($this->dateShort) . |
|
287 | + ', discord_id = ' . $this->db->escapeString($this->discordId, true, true) . |
|
288 | + ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true) . |
|
289 | + ', hof_name = ' . $this->db->escapeString($this->hofName) . |
|
290 | + ', colour_scheme = ' . $this->db->escapeString($this->colourScheme) . |
|
291 | + ', fontsize = ' . $this->db->escapeNumber($this->fontSize) . |
|
292 | + ', css_link = ' . $this->db->escapeString($this->cssLink, true, true) . |
|
293 | + ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true) . |
|
294 | + ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true) . |
|
295 | + ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true) . |
|
296 | + ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
297 | 297 | $this->hasChanged = false; |
298 | 298 | } |
299 | 299 | |
300 | 300 | public function updateIP() { |
301 | 301 | $curr_ip = getIpAddress(); |
302 | - $this->log(LOG_TYPE_LOGIN, 'logged in from '.$curr_ip); |
|
302 | + $this->log(LOG_TYPE_LOGIN, 'logged in from ' . $curr_ip); |
|
303 | 303 | |
304 | 304 | // more than 50 elements in it? |
305 | 305 | |
306 | - $this->db->query('SELECT time,ip FROM account_has_ip WHERE '.$this->SQL.' ORDER BY time ASC'); |
|
306 | + $this->db->query('SELECT time,ip FROM account_has_ip WHERE ' . $this->SQL . ' ORDER BY time ASC'); |
|
307 | 307 | if ($this->db->getNumRows() > 50 && $this->db->nextRecord()) { |
308 | 308 | $delete_time = $this->db->getField('time'); |
309 | 309 | $delete_ip = $this->db->getField('ip'); |
310 | 310 | |
311 | 311 | $this->db->query('DELETE FROM account_has_ip |
312 | - WHERE '.$this->SQL.' AND |
|
313 | - time = '.$this->db->escapeNumber($delete_time).' AND |
|
312 | + WHERE '.$this->SQL . ' AND |
|
313 | + time = '.$this->db->escapeNumber($delete_time) . ' AND |
|
314 | 314 | ip = '.$this->db->escapeString($delete_ip)); |
315 | 315 | } |
316 | - list($fi,$se,$th,$fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
316 | + list($fi, $se, $th, $fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
317 | 317 | if ($curr_ip != 'unknown' && $curr_ip != 'unknown...' && $curr_ip != 'unknown, unknown') { |
318 | - $curr_ip = $fi.'.'.$se.'.'.$th.'.'.$fo; |
|
318 | + $curr_ip = $fi . '.' . $se . '.' . $th . '.' . $fo; |
|
319 | 319 | $host = gethostbyaddr($curr_ip); |
320 | 320 | } else $host = 'unknown'; |
321 | 321 | |
322 | 322 | // save...first make sure there isn't one for these keys (someone could double click and get error) |
323 | - $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES ('.$this->db->escapeNumber($this->account_id).', '.$this->db->escapeNumber(TIME).', '.$this->db->escapeString($curr_ip).', '.$this->db->escapeString($host).')'); |
|
323 | + $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES (' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeString($curr_ip) . ', ' . $this->db->escapeString($host) . ')'); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | public function updateLastLogin() { |
327 | - if($this->last_login == TIME) |
|
327 | + if ($this->last_login == TIME) |
|
328 | 328 | return; |
329 | 329 | $this->last_login = TIME; |
330 | 330 | $this->hasChanged = true; |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | public function setLoggingEnabled($bool) { |
339 | - if($this->logging==$bool) |
|
339 | + if ($this->logging == $bool) |
|
340 | 340 | return; |
341 | - $this->logging=$bool; |
|
341 | + $this->logging = $bool; |
|
342 | 342 | $this->hasChanged = true; |
343 | 343 | $this->update(); |
344 | 344 | } |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | public function isNPC() { |
361 | - if(!isset($this->npc)) { |
|
362 | - $this->db->query('SELECT login FROM npc_logins WHERE login = '.$this->db->escapeString($this->getLogin()).' LIMIT 1;'); |
|
361 | + if (!isset($this->npc)) { |
|
362 | + $this->db->query('SELECT login FROM npc_logins WHERE login = ' . $this->db->escapeString($this->getLogin()) . ' LIMIT 1;'); |
|
363 | 363 | $this->npc = $this->db->nextRecord(); |
364 | 364 | } |
365 | 365 | return $this->npc; |
366 | 366 | } |
367 | 367 | |
368 | 368 | protected function getHOFData() { |
369 | - if(!isset($this->HOF)) { |
|
369 | + if (!isset($this->HOF)) { |
|
370 | 370 | //Get Player HOF |
371 | 371 | $this->db->query('SELECT type,sum(amount) as amount FROM player_hof WHERE ' . $this->SQL . ' AND game_id IN (SELECT game_id FROM game WHERE ignore_stats = \'FALSE\') GROUP BY type'); |
372 | 372 | $this->HOF = array(); |
373 | - while($this->db->nextRecord()) { |
|
374 | - $hof =& $this->HOF; |
|
375 | - $typeList = explode(':',$this->db->getField('type')); |
|
376 | - foreach($typeList as $type) { |
|
377 | - if(!isset($hof[$type])) { |
|
373 | + while ($this->db->nextRecord()) { |
|
374 | + $hof = & $this->HOF; |
|
375 | + $typeList = explode(':', $this->db->getField('type')); |
|
376 | + foreach ($typeList as $type) { |
|
377 | + if (!isset($hof[$type])) { |
|
378 | 378 | $hof[$type] = array(); |
379 | 379 | } |
380 | - $hof =& $hof[$type]; |
|
380 | + $hof = & $hof[$type]; |
|
381 | 381 | } |
382 | 382 | $hof = $this->db->getField('amount'); |
383 | 383 | } |
@@ -386,11 +386,11 @@ discard block |
||
386 | 386 | |
387 | 387 | public function getHOF(array $typeList = null) { |
388 | 388 | $this->getHOFData(); |
389 | - if($typeList==null) |
|
389 | + if ($typeList == null) |
|
390 | 390 | return $this->HOF; |
391 | - $hof=$this->HOF; |
|
392 | - foreach($typeList as $type) { |
|
393 | - if(!isset($hof[$type])) |
|
391 | + $hof = $this->HOF; |
|
392 | + foreach ($typeList as $type) { |
|
393 | + if (!isset($hof[$type])) |
|
394 | 394 | return 0; |
395 | 395 | $hof = $hof[$type]; |
396 | 396 | } |
@@ -399,58 +399,58 @@ discard block |
||
399 | 399 | |
400 | 400 | public function getRankName() { |
401 | 401 | $rankings = Globals::getUserRanking(); |
402 | - if(isset($rankings[$this->getRank()])) |
|
402 | + if (isset($rankings[$this->getRank()])) |
|
403 | 403 | return $rankings[$this->getRank()]; |
404 | 404 | else |
405 | 405 | return end($rankings); |
406 | 406 | } |
407 | 407 | |
408 | 408 | public function getScore() { |
409 | - if(!isset($this->score)) { |
|
410 | - $score=0; |
|
411 | - foreach($this->getIndividualScores() as $each) { |
|
412 | - $score+=$each['Score']; |
|
409 | + if (!isset($this->score)) { |
|
410 | + $score = 0; |
|
411 | + foreach ($this->getIndividualScores() as $each) { |
|
412 | + $score += $each['Score']; |
|
413 | 413 | } |
414 | - $this->score=round($score); |
|
414 | + $this->score = round($score); |
|
415 | 415 | } |
416 | 416 | return $this->score; |
417 | 417 | } |
418 | 418 | |
419 | 419 | public function &getIndividualScores(SmrPlayer $player = null) { |
420 | - $gameID=0; |
|
421 | - if($player!=null) |
|
420 | + $gameID = 0; |
|
421 | + if ($player != null) |
|
422 | 422 | $gameID = $player->getGameID(); |
423 | - if(!isset($this->individualScores[$gameID])) { |
|
423 | + if (!isset($this->individualScores[$gameID])) { |
|
424 | 424 | $this->individualScores[$gameID] = array(); |
425 | - foreach(self::USER_RANKINGS_SCORE as $statScore) { |
|
426 | - if($player==null) |
|
425 | + foreach (self::USER_RANKINGS_SCORE as $statScore) { |
|
426 | + if ($player == null) |
|
427 | 427 | $stat = $this->getHOF($statScore[0]); |
428 | 428 | else |
429 | 429 | $stat = $player->getHOF($statScore[0]); |
430 | - $this->individualScores[$gameID][]=array('Stat'=>$statScore[0],'Score'=>pow($stat*$statScore[1],self::USER_RANKINGS_EACH_STAT_POW)*$statScore[2]); |
|
430 | + $this->individualScores[$gameID][] = array('Stat'=>$statScore[0], 'Score'=>pow($stat * $statScore[1], self::USER_RANKINGS_EACH_STAT_POW) * $statScore[2]); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | return $this->individualScores[$gameID]; |
434 | 434 | } |
435 | 435 | |
436 | 436 | public function getRank() { |
437 | - $rank = ceil(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 = ceil(pow($this->getScore(), self::USER_RANKINGS_TOTAL_SCORE_POW) / self::USER_RANKINGS_RANK_BOUNDARY); |
|
438 | + if ($rank < 1) |
|
439 | + $rank = 1; |
|
440 | + if ($rank > $this->maxRankAchieved) |
|
441 | 441 | $this->updateMaxRankAchieved($rank); |
442 | 442 | return $rank; |
443 | 443 | } |
444 | 444 | |
445 | 445 | protected function updateMaxRankAchieved($rank) { |
446 | - if($rank <= $this->maxRankAchieved) |
|
446 | + if ($rank <= $this->maxRankAchieved) |
|
447 | 447 | throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
448 | 448 | $delta = $rank - $this->maxRankAchieved; |
449 | - if($this->hasReferrer()) { |
|
449 | + if ($this->hasReferrer()) { |
|
450 | 450 | $this->getReferrer()->increaseSmrRewardCredits($delta * CREDITS_PER_DOLLAR); |
451 | 451 | } |
452 | - $this->maxRankAchieved+=$delta; |
|
453 | - $this->hasChanged=true; |
|
452 | + $this->maxRankAchieved += $delta; |
|
453 | + $this->hasChanged = true; |
|
454 | 454 | $this->update(); |
455 | 455 | } |
456 | 456 | |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | public function hasReferrer() { |
462 | - return $this->referrerID>0; |
|
462 | + return $this->referrerID > 0; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | public function &getReferrer() { |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | if ($this->isLoggingEnabled()) { |
471 | 471 | $this->db->query('INSERT INTO account_has_logs ' . |
472 | 472 | '(account_id, microtime, log_type_id, message, sector_id) ' . |
473 | - 'VALUES('.$this->db->escapeNumber($this->account_id).', '. $this->db->escapeMicrotime(MICRO_TIME) . ', '.$this->db->escapeNumber($log_type_id).', ' . $this->db->escapeString($msg) . ', '.$this->db->escapeNumber($sector_id).')'); |
|
473 | + 'VALUES(' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeMicrotime(MICRO_TIME) . ', ' . $this->db->escapeNumber($log_type_id) . ', ' . $this->db->escapeString($msg) . ', ' . $this->db->escapeNumber($sector_id) . ')'); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | 477 | protected function getSmrCreditsData() { |
478 | - if(!isset($this->credits)||!isset($this->rewardCredits)) { |
|
478 | + if (!isset($this->credits) || !isset($this->rewardCredits)) { |
|
479 | 479 | $this->credits = 0; |
480 | 480 | $this->rewardCredits = 0; |
481 | - $this->db->query('SELECT * FROM account_has_credits WHERE '.$this->SQL.' LIMIT 1'); |
|
481 | + $this->db->query('SELECT * FROM account_has_credits WHERE ' . $this->SQL . ' LIMIT 1'); |
|
482 | 482 | if ($this->db->nextRecord()) { |
483 | 483 | $this->credits = $this->db->getInt('credits_left'); |
484 | 484 | $this->rewardCredits = $this->db->getInt('reward_credits'); |
@@ -491,26 +491,26 @@ discard block |
||
491 | 491 | } |
492 | 492 | |
493 | 493 | public function decreaseTotalSmrCredits($totalCredits) { |
494 | - if($totalCredits==0) |
|
494 | + if ($totalCredits == 0) |
|
495 | 495 | return; |
496 | - if($totalCredits<0) |
|
496 | + if ($totalCredits < 0) |
|
497 | 497 | throw new Exception('You cannot use negative total credits'); |
498 | - if($totalCredits>$this->getTotalSmrCredits()) |
|
498 | + if ($totalCredits > $this->getTotalSmrCredits()) |
|
499 | 499 | throw new Exception('You do not have that many credits in total to use'); |
500 | 500 | |
501 | - $rewardCredits=$this->rewardCredits; |
|
502 | - $credits=$this->credits; |
|
503 | - $rewardCredits-=$totalCredits; |
|
504 | - if($rewardCredits<0) { |
|
505 | - $credits+=$rewardCredits; |
|
506 | - $rewardCredits=0; |
|
501 | + $rewardCredits = $this->rewardCredits; |
|
502 | + $credits = $this->credits; |
|
503 | + $rewardCredits -= $totalCredits; |
|
504 | + if ($rewardCredits < 0) { |
|
505 | + $credits += $rewardCredits; |
|
506 | + $rewardCredits = 0; |
|
507 | 507 | } |
508 | - if($this->credits==0 && $this->rewardCredits==0) |
|
509 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
508 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
509 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ',' . $this->db->escapeNumber($rewardCredits) . ')'); |
|
510 | 510 | else |
511 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
512 | - $this->credits=$credits; |
|
513 | - $this->rewardCredits=$rewardCredits; |
|
511 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ', reward_credits=' . $this->db->escapeNumber($rewardCredits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
512 | + $this->credits = $credits; |
|
513 | + $this->rewardCredits = $rewardCredits; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | public function getSmrCredits() { |
@@ -524,49 +524,49 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | public function setSmrCredits($credits) { |
527 | - if($this->getSmrCredits()==$credits) |
|
527 | + if ($this->getSmrCredits() == $credits) |
|
528 | 528 | return; |
529 | - if($this->credits==0 && $this->rewardCredits==0) |
|
530 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
529 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
530 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
531 | 531 | else |
532 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
533 | - $this->credits=$credits; |
|
532 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
533 | + $this->credits = $credits; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | public function increaseSmrCredits($credits) { |
537 | - if($credits==0) |
|
537 | + if ($credits == 0) |
|
538 | 538 | return; |
539 | - if($credits<0) |
|
539 | + if ($credits < 0) |
|
540 | 540 | throw new Exception('You cannot gain negative credits'); |
541 | - $this->setSmrCredits($this->getSmrCredits()+$credits); |
|
541 | + $this->setSmrCredits($this->getSmrCredits() + $credits); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | public function decreaseSmrCredits($credits) { |
545 | - if($credits==0) |
|
545 | + if ($credits == 0) |
|
546 | 546 | return; |
547 | - if($credits<0) |
|
547 | + if ($credits < 0) |
|
548 | 548 | throw new Exception('You cannot use negative credits'); |
549 | - if($credits>$this->getSmrCredits()) |
|
549 | + if ($credits > $this->getSmrCredits()) |
|
550 | 550 | throw new Exception('You cannot use more credits than you have'); |
551 | - $this->setSmrCredits($this->getSmrCredits()-$credits); |
|
551 | + $this->setSmrCredits($this->getSmrCredits() - $credits); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | public function setSmrRewardCredits($credits) { |
555 | - if($this->getSmrRewardCredits()==$credits) |
|
555 | + if ($this->getSmrRewardCredits() == $credits) |
|
556 | 556 | return; |
557 | - if($this->credits==0 && $this->rewardCredits==0) |
|
558 | - $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
557 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
558 | + $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
559 | 559 | else |
560 | - $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
561 | - $this->rewardCredits=$credits; |
|
560 | + $this->db->query('UPDATE account_has_credits SET reward_credits=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
561 | + $this->rewardCredits = $credits; |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | public function increaseSmrRewardCredits($credits) { |
565 | - if($credits==0) |
|
565 | + if ($credits == 0) |
|
566 | 566 | return; |
567 | - if($credits<0) |
|
567 | + if ($credits < 0) |
|
568 | 568 | throw new Exception('You cannot gain negative reward credits'); |
569 | - $this->setSmrRewardCredits($this->getSmrRewardCredits()+$credits); |
|
569 | + $this->setSmrRewardCredits($this->getSmrRewardCredits() + $credits); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | public function sendMessageToBox($boxTypeID, $message) { |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | self::doMessageSendingToBox($this->getAccountID(), $boxTypeID, $message); |
575 | 575 | } |
576 | 576 | |
577 | - public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID=0) { |
|
577 | + public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID = 0) { |
|
578 | 578 | $db = new SmrMySqlDatabase(); |
579 | 579 | // send him the message |
580 | 580 | $db->query('INSERT INTO message_boxes |
@@ -597,13 +597,13 @@ discard block |
||
597 | 597 | } |
598 | 598 | |
599 | 599 | public function getOldAccountID($dbName) { |
600 | - return isset($this->oldAccountIDs[$dbName])?$this->oldAccountIDs[$dbName]:0; |
|
600 | + return isset($this->oldAccountIDs[$dbName]) ? $this->oldAccountIDs[$dbName] : 0; |
|
601 | 601 | } |
602 | 602 | |
603 | - public function hasOldAccountID($dbName=false) { |
|
604 | - if($dbName===false) |
|
605 | - return count($this->getOldAccountIDs())!=0; |
|
606 | - return $this->getOldAccountID($dbName)!=0; |
|
603 | + public function hasOldAccountID($dbName = false) { |
|
604 | + if ($dbName === false) |
|
605 | + return count($this->getOldAccountIDs()) != 0; |
|
606 | + return $this->getOldAccountID($dbName) != 0; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | public function getLogin() { |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | } |
616 | 616 | |
617 | 617 | public function setEmail($email) { |
618 | - if($this->email==$email) { |
|
618 | + if ($this->email == $email) { |
|
619 | 619 | return; |
620 | 620 | } |
621 | 621 | $this->email = $email; |
@@ -632,14 +632,14 @@ discard block |
||
632 | 632 | |
633 | 633 | // check if the host got a MX or at least an A entry |
634 | 634 | if (!checkdnsrr($host, 'MX') && !checkdnsrr($host, 'A')) { |
635 | - create_error('This is not a valid email address! The domain '.$host.' does not exist.'); |
|
635 | + create_error('This is not a valid email address! The domain ' . $host . ' does not exist.'); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | if (strstr($email, ' ')) { |
639 | 639 | create_error('The email is invalid! It cannot contain any spaces.'); |
640 | 640 | } |
641 | 641 | |
642 | - $this->db->query('SELECT 1 FROM account WHERE email = '.$this->db->escapeString($email).' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
642 | + $this->db->query('SELECT 1 FROM account WHERE email = ' . $this->db->escapeString($email) . ' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
643 | 643 | if ($this->db->getNumRows() > 0) { |
644 | 644 | create_error('This email address is already registered.'); |
645 | 645 | } |
@@ -650,12 +650,12 @@ discard block |
||
650 | 650 | |
651 | 651 | // remember when we sent validation code |
652 | 652 | $this->db->query('REPLACE INTO notification (notification_type, account_id, time) |
653 | - VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()).', ' . $this->db->escapeNumber(TIME) . ')'); |
|
653 | + VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ')'); |
|
654 | 654 | |
655 | 655 | $emailMessage = |
656 | - 'You changed your email address registered with SMR and need to revalidate now!'.EOL.EOL. |
|
657 | - ' Your new validation code is: '.$this->getValidationCode().EOL.EOL. |
|
658 | - 'The Space Merchant Realms server is on the web at '.URL; |
|
656 | + 'You changed your email address registered with SMR and need to revalidate now!' . EOL . EOL . |
|
657 | + ' Your new validation code is: ' . $this->getValidationCode() . EOL . EOL . |
|
658 | + 'The Space Merchant Realms server is on the web at ' . URL; |
|
659 | 659 | |
660 | 660 | $mail = setupMailer(); |
661 | 661 | $mail->Subject = 'Your validation code!'; |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | } |
682 | 682 | |
683 | 683 | public function setFontSize($size) { |
684 | - if($this->fontSize==$size) |
|
684 | + if ($this->fontSize == $size) |
|
685 | 685 | return; |
686 | 686 | $this->fontSize = $size; |
687 | 687 | $this->hasChanged = true; |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | |
696 | 696 | // sets the extra CSS file linked in preferences |
697 | 697 | public function setCssLink($link) { |
698 | - if($this->cssLink==$link) |
|
698 | + if ($this->cssLink == $link) |
|
699 | 699 | return; |
700 | 700 | $this->cssLink = $link; |
701 | 701 | $this->hasChanged = true; |
@@ -707,11 +707,11 @@ discard block |
||
707 | 707 | } |
708 | 708 | |
709 | 709 | public function setTemplate($template) { |
710 | - if($this->template==$template) |
|
710 | + if ($this->template == $template) |
|
711 | 711 | return; |
712 | - if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) |
|
713 | - throw new Exception('Template not allowed: '.$template); |
|
714 | - $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE '.$this->SQL.' LIMIT 1'); |
|
712 | + if (!in_array($template, array_keys(Globals::getAvailableTemplates()))) |
|
713 | + throw new Exception('Template not allowed: ' . $template); |
|
714 | + $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
715 | 715 | $this->template = $template; |
716 | 716 | $colourSchemes = Globals::getAvailableColourSchemes($template); |
717 | 717 | $this->setColourScheme($colourSchemes[0]); |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | public function setColourScheme($colourScheme) { |
725 | - if($this->colourScheme==$colourScheme) |
|
725 | + if ($this->colourScheme == $colourScheme) |
|
726 | 726 | return; |
727 | - if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | - throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
727 | + if (!in_array($colourScheme, array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | + throw new Exception('Colour scheme not allowed: ' . $colourScheme); |
|
729 | 729 | $this->colourScheme = $colourScheme; |
730 | 730 | $this->hasChanged = true; |
731 | 731 | $this->update(); |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | return CSS_COLOUR_URLS[$this->getTemplate()][$this->getColourScheme()]; |
742 | 742 | } |
743 | 743 | |
744 | - public function getHofName($linked=false) { |
|
744 | + public function getHofName($linked = false) { |
|
745 | 745 | if ($linked) { |
746 | 746 | return '<a href="' . $this->getPersonalHofHREF() . '">' . $this->hofName . '</a>'; |
747 | 747 | } else { |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | } |
751 | 751 | |
752 | 752 | public function setHofName($name) { |
753 | - if($this->hofName==$name) |
|
753 | + if ($this->hofName == $name) |
|
754 | 754 | return; |
755 | 755 | $this->hofName = $name; |
756 | 756 | $this->hasChanged = true; |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | } |
763 | 763 | |
764 | 764 | public function setIrcNick($nick) { |
765 | - if($this->ircNick==$nick) |
|
765 | + if ($this->ircNick == $nick) |
|
766 | 766 | return; |
767 | 767 | $this->ircNick = $nick; |
768 | 768 | $this->hasChanged = true; |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | public function getReferralLink() { |
786 | - return URL . '/login_create.php?ref='.$this->getAccountID(); |
|
786 | + return URL . '/login_create.php?ref=' . $this->getAccountID(); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | public function getShortDateFormat() { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | } |
792 | 792 | |
793 | 793 | public function setShortDateFormat($format) { |
794 | - if($this->dateShort==$format) |
|
794 | + if ($this->dateShort == $format) |
|
795 | 795 | return; |
796 | 796 | $this->dateShort = $format; |
797 | 797 | $this->hasChanged = true; |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | } |
804 | 804 | |
805 | 805 | public function setShortTimeFormat($format) { |
806 | - if($this->timeShort==$format) |
|
806 | + if ($this->timeShort == $format) |
|
807 | 807 | return; |
808 | 808 | $this->timeShort = $format; |
809 | 809 | $this->hasChanged = true; |
@@ -815,15 +815,15 @@ discard block |
||
815 | 815 | } |
816 | 816 | |
817 | 817 | protected function setValidationCode($code) { |
818 | - if($this->validation_code == $code) |
|
818 | + if ($this->validation_code == $code) |
|
819 | 819 | return; |
820 | - $this->validation_code=$code; |
|
821 | - $this->hasChanged=true; |
|
820 | + $this->validation_code = $code; |
|
821 | + $this->hasChanged = true; |
|
822 | 822 | $this->update(); |
823 | 823 | } |
824 | 824 | |
825 | 825 | public function setValidated($bool) { |
826 | - if($this->validated == $bool) |
|
826 | + if ($this->validated == $bool) |
|
827 | 827 | return; |
828 | 828 | $this->validated = $bool; |
829 | 829 | $this->hasChanged = true; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | } |
836 | 836 | |
837 | 837 | public function isLoggedIn() { |
838 | - $this->db->query('SELECT 1 FROM active_session WHERE account_id = '.$this->db->escapeNumber($this->getAccountID()).' LIMIT 1'); |
|
838 | + $this->db->query('SELECT 1 FROM active_session WHERE account_id = ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
839 | 839 | return $this->db->nextRecord(); |
840 | 840 | } |
841 | 841 | |
@@ -876,15 +876,15 @@ discard block |
||
876 | 876 | $this->update(); |
877 | 877 | } |
878 | 878 | |
879 | - public function addAuthMethod($loginType,$authKey) { |
|
880 | - $this->db->query('SELECT account_id FROM account_auth WHERE login_type='.$this->db->escapeString($loginType).' AND auth_key = '.$this->db->escapeString($authKey).';'); |
|
881 | - if($this->db->nextRecord()) { |
|
882 | - if($this->db->getInt('account_id')!=$this->getAccountID()) { |
|
879 | + public function addAuthMethod($loginType, $authKey) { |
|
880 | + $this->db->query('SELECT account_id FROM account_auth WHERE login_type=' . $this->db->escapeString($loginType) . ' AND auth_key = ' . $this->db->escapeString($authKey) . ';'); |
|
881 | + if ($this->db->nextRecord()) { |
|
882 | + if ($this->db->getInt('account_id') != $this->getAccountID()) { |
|
883 | 883 | throw new Exception('Another account already uses this form of auth.'); |
884 | 884 | } |
885 | 885 | return true; |
886 | 886 | } |
887 | - $this->db->query('INSERT INTO account_auth values ('.$this->db->escapeNumber($this->getAccountID()).','.$this->db->escapeString($loginType).','.$this->db->escapeString($authKey).');'); |
|
887 | + $this->db->query('INSERT INTO account_auth values (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeString($loginType) . ',' . $this->db->escapeString($authKey) . ');'); |
|
888 | 888 | return true; |
889 | 889 | } |
890 | 890 | |
@@ -897,10 +897,10 @@ discard block |
||
897 | 897 | } |
898 | 898 | |
899 | 899 | protected function setPasswordReset($passwordReset) { |
900 | - if($this->passwordReset == $passwordReset) |
|
900 | + if ($this->passwordReset == $passwordReset) |
|
901 | 901 | return; |
902 | - $this->passwordReset=$passwordReset; |
|
903 | - $this->hasChanged=true; |
|
902 | + $this->passwordReset = $passwordReset; |
|
903 | + $this->hasChanged = true; |
|
904 | 904 | $this->update(); |
905 | 905 | } |
906 | 906 | |
@@ -909,7 +909,7 @@ discard block |
||
909 | 909 | } |
910 | 910 | |
911 | 911 | public function setDisplayShipImages($yesNo) { |
912 | - if($this->images == $yesNo) |
|
912 | + if ($this->images == $yesNo) |
|
913 | 913 | return; |
914 | 914 | $this->images = $yesNo; |
915 | 915 | $this->hasChanged = true; |
@@ -921,10 +921,10 @@ discard block |
||
921 | 921 | } |
922 | 922 | |
923 | 923 | public function setUseAJAX($bool) { |
924 | - if($this->useAJAX == $bool) |
|
924 | + if ($this->useAJAX == $bool) |
|
925 | 925 | return; |
926 | - $this->useAJAX=$bool; |
|
927 | - $this->hasChanged=true; |
|
926 | + $this->useAJAX = $bool; |
|
927 | + $this->hasChanged = true; |
|
928 | 928 | $this->update(); |
929 | 929 | } |
930 | 930 | |
@@ -933,16 +933,16 @@ discard block |
||
933 | 933 | } |
934 | 934 | |
935 | 935 | public function setDefaultCSSEnabled($bool) { |
936 | - if($this->defaultCSSEnabled == $bool) |
|
936 | + if ($this->defaultCSSEnabled == $bool) |
|
937 | 937 | return; |
938 | - $this->defaultCSSEnabled=$bool; |
|
939 | - $this->hasChanged=true; |
|
938 | + $this->defaultCSSEnabled = $bool; |
|
939 | + $this->hasChanged = true; |
|
940 | 940 | $this->update(); |
941 | 941 | } |
942 | 942 | |
943 | 943 | public function getHotkeys($hotkeyType = false) { |
944 | - if($hotkeyType!==false) { |
|
945 | - if(isset($this->hotkeys[$hotkeyType])) { |
|
944 | + if ($hotkeyType !== false) { |
|
945 | + if (isset($this->hotkeys[$hotkeyType])) { |
|
946 | 946 | return $this->hotkeys[$hotkeyType]; |
947 | 947 | } |
948 | 948 | else { |
@@ -952,42 +952,42 @@ discard block |
||
952 | 952 | return $this->hotkeys; |
953 | 953 | } |
954 | 954 | |
955 | - public function setHotkey($hotkeyType,$binding) { |
|
956 | - if($this->getHotkeys($hotkeyType) == $binding) |
|
955 | + public function setHotkey($hotkeyType, $binding) { |
|
956 | + if ($this->getHotkeys($hotkeyType) == $binding) |
|
957 | 957 | return; |
958 | 958 | $this->hotkeys[$hotkeyType] = $binding; |
959 | - $this->hasChanged=true; |
|
959 | + $this->hasChanged = true; |
|
960 | 960 | $this->update(); |
961 | 961 | } |
962 | 962 | |
963 | 963 | public function isReceivingMessageNotifications($messageTypeID) { |
964 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]>0:false; |
|
964 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] > 0 : false; |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | public function getMessageNotifications($messageTypeID) { |
968 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]:0; |
|
968 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] : 0; |
|
969 | 969 | } |
970 | 970 | |
971 | - public function setMessageNotifications($messageTypeID,$num) { |
|
972 | - if($this->getMessageNotifications($messageTypeID) == $num) |
|
971 | + public function setMessageNotifications($messageTypeID, $num) { |
|
972 | + if ($this->getMessageNotifications($messageTypeID) == $num) |
|
973 | 973 | return; |
974 | - $this->messageNotifications[$messageTypeID]=$num; |
|
975 | - $this->hasChanged=true; |
|
974 | + $this->messageNotifications[$messageTypeID] = $num; |
|
975 | + $this->hasChanged = true; |
|
976 | 976 | $this->update(); |
977 | 977 | } |
978 | 978 | |
979 | - public function increaseMessageNotifications($messageTypeID,$num) { |
|
980 | - if($num==0) |
|
979 | + public function increaseMessageNotifications($messageTypeID, $num) { |
|
980 | + if ($num == 0) |
|
981 | 981 | return; |
982 | - if($num<0) |
|
982 | + if ($num < 0) |
|
983 | 983 | throw new Exception('You cannot increase by a negative amount'); |
984 | 984 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) + $num); |
985 | 985 | } |
986 | 986 | |
987 | - public function decreaseMessageNotifications($messageTypeID,$num) { |
|
988 | - if($num==0) |
|
987 | + public function decreaseMessageNotifications($messageTypeID, $num) { |
|
988 | + if ($num == 0) |
|
989 | 989 | return; |
990 | - if($num<0) |
|
990 | + if ($num < 0) |
|
991 | 991 | throw new Exception('You cannot decrease by a negative amount'); |
992 | 992 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) - $num); |
993 | 993 | } |
@@ -997,10 +997,10 @@ discard block |
||
997 | 997 | } |
998 | 998 | |
999 | 999 | public function setCenterGalaxyMapOnPlayer($bool) { |
1000 | - if($this->centerGalaxyMapOnPlayer == $bool) |
|
1000 | + if ($this->centerGalaxyMapOnPlayer == $bool) |
|
1001 | 1001 | return; |
1002 | - $this->centerGalaxyMapOnPlayer=$bool; |
|
1003 | - $this->hasChanged=true; |
|
1002 | + $this->centerGalaxyMapOnPlayer = $bool; |
|
1003 | + $this->hasChanged = true; |
|
1004 | 1004 | $this->update(); |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1009,26 +1009,26 @@ discard block |
||
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | public function isMailBanned() { |
1012 | - return $this->mailBanned>TIME; |
|
1012 | + return $this->mailBanned > TIME; |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | public function setMailBanned($time) { |
1016 | - if($this->mailBanned == $time) |
|
1016 | + if ($this->mailBanned == $time) |
|
1017 | 1017 | return; |
1018 | - $this->mailBanned=$time; |
|
1019 | - $this->hasChanged=true; |
|
1018 | + $this->mailBanned = $time; |
|
1019 | + $this->hasChanged = true; |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | public function increaseMailBanned($increaseTime) { |
1023 | - $time = max(TIME,$this->getMailBanned()); |
|
1024 | - $this->setMailBanned($time+$increaseTime); |
|
1023 | + $time = max(TIME, $this->getMailBanned()); |
|
1024 | + $this->setMailBanned($time + $increaseTime); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | public function getPermissions() { |
1028 | - if(!isset($this->permissions)) { |
|
1028 | + if (!isset($this->permissions)) { |
|
1029 | 1029 | $this->permissions = array(); |
1030 | 1030 | $this->db->query('SELECT permission_id FROM account_has_permission WHERE ' . $this->SQL); |
1031 | - while($this->db->nextRecord()) { |
|
1031 | + while ($this->db->nextRecord()) { |
|
1032 | 1032 | $this->permissions[$this->db->getInt('permission_id')] = true; |
1033 | 1033 | } |
1034 | 1034 | } |
@@ -1037,28 +1037,28 @@ discard block |
||
1037 | 1037 | |
1038 | 1038 | public function hasPermission($permissionID = false) { |
1039 | 1039 | $permissions = $this->getPermissions(); |
1040 | - if($permissionID === false) { |
|
1040 | + if ($permissionID === false) { |
|
1041 | 1041 | return count($permissions) > 0; |
1042 | 1042 | } |
1043 | 1043 | return isset($permissions[$permissionID]) ? $permissions[$permissionID] : false; |
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | public function getPoints() { |
1047 | - if(!isset($this->points)) { |
|
1048 | - $this->points=0; |
|
1047 | + if (!isset($this->points)) { |
|
1048 | + $this->points = 0; |
|
1049 | 1049 | $this->db->lockTable('account_has_points'); |
1050 | - $this->db->query('SELECT * FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1051 | - if($this->db->nextRecord()) { |
|
1052 | - $this->points=$this->db->getInt('points'); |
|
1050 | + $this->db->query('SELECT * FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1051 | + if ($this->db->nextRecord()) { |
|
1052 | + $this->points = $this->db->getInt('points'); |
|
1053 | 1053 | $lastUpdate = $this->db->getInt('last_update'); |
1054 | 1054 | //we are gonna check for reducing points... |
1055 | - if($this->points>0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1056 | - $removePoints=0; |
|
1057 | - while($lastUpdate < TIME - (7 * 86400)) { |
|
1055 | + if ($this->points > 0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1056 | + $removePoints = 0; |
|
1057 | + while ($lastUpdate < TIME - (7 * 86400)) { |
|
1058 | 1058 | $removePoints++; |
1059 | 1059 | $lastUpdate += (7 * 86400); |
1060 | 1060 | } |
1061 | - $this->removePoints($removePoints,$lastUpdate); |
|
1061 | + $this->removePoints($removePoints, $lastUpdate); |
|
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | $this->db->unlock(); |
@@ -1066,30 +1066,30 @@ discard block |
||
1066 | 1066 | return $this->points; |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - public function setPoints($numPoints,$lastUpdate=false) { |
|
1070 | - $numPoints = max($numPoints,0); |
|
1071 | - if($this->getPoints()==$numPoints) |
|
1069 | + public function setPoints($numPoints, $lastUpdate = false) { |
|
1070 | + $numPoints = max($numPoints, 0); |
|
1071 | + if ($this->getPoints() == $numPoints) |
|
1072 | 1072 | return; |
1073 | - if ($this->points==0) |
|
1074 | - $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).')'); |
|
1075 | - else if($numPoints<=0) |
|
1076 | - $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1073 | + if ($this->points == 0) |
|
1074 | + $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) . ')'); |
|
1075 | + else if ($numPoints <= 0) |
|
1076 | + $this->db->query('DELETE FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1077 | 1077 | else |
1078 | - $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'); |
|
1079 | - $this->points=$numPoints; |
|
1078 | + $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'); |
|
1079 | + $this->points = $numPoints; |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | - public function removePoints($numPoints,$lastUpdate=false) { |
|
1083 | - if($numPoints>0) |
|
1084 | - $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1082 | + public function removePoints($numPoints, $lastUpdate = false) { |
|
1083 | + if ($numPoints > 0) |
|
1084 | + $this->setPoints($this->getPoints() - $numPoints, $lastUpdate); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | - public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) { |
|
1087 | + public function addPoints($numPoints, SmrAccount $admin, $reasonID, $suspicion) { |
|
1088 | 1088 | //do we have points |
1089 | - $this->setPoints($this->getPoints() + $numPoints,TIME); |
|
1089 | + $this->setPoints($this->getPoints() + $numPoints, TIME); |
|
1090 | 1090 | $totalPoints = $this->getPoints(); |
1091 | 1091 | if ($totalPoints < 10) |
1092 | - return false;//leave scripts its only a warning |
|
1092 | + return false; //leave scripts its only a warning |
|
1093 | 1093 | elseif ($totalPoints < 20) |
1094 | 1094 | $days = 2; |
1095 | 1095 | elseif ($totalPoints < 30) |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | elseif ($totalPoints < 50) |
1098 | 1098 | $days = 7; |
1099 | 1099 | elseif ($totalPoints < 75) |
1100 | - $days = 15 ; |
|
1100 | + $days = 15; |
|
1101 | 1101 | elseif ($totalPoints < 100) |
1102 | 1102 | $days = 30; |
1103 | 1103 | elseif ($totalPoints < 125) |
@@ -1111,13 +1111,13 @@ discard block |
||
1111 | 1111 | else |
1112 | 1112 | $days = 0; //Forever/indefinite |
1113 | 1113 | |
1114 | - if($days==0) { |
|
1114 | + if ($days == 0) { |
|
1115 | 1115 | $expireTime = 0; |
1116 | 1116 | } |
1117 | 1117 | else { |
1118 | 1118 | $expireTime = TIME + $days * 86400; |
1119 | 1119 | } |
1120 | - $this->banAccount($expireTime,$admin,$reasonID,$suspicion); |
|
1120 | + $this->banAccount($expireTime, $admin, $reasonID, $suspicion); |
|
1121 | 1121 | |
1122 | 1122 | return $days; |
1123 | 1123 | } |
@@ -1144,12 +1144,12 @@ discard block |
||
1144 | 1144 | $this->hasChanged = true; |
1145 | 1145 | } |
1146 | 1146 | |
1147 | - public function banAccount($expireTime,SmrAccount $admin,$reasonID,$suspicion,$removeExceptions = false) { |
|
1147 | + public function banAccount($expireTime, SmrAccount $admin, $reasonID, $suspicion, $removeExceptions = false) { |
|
1148 | 1148 | $this->db->query('REPLACE INTO account_is_closed |
1149 | 1149 | (account_id, reason_id, suspicion, expires) |
1150 | - VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($reasonID).', '.$this->db->escapeString($suspicion).', '.$this->db->escapeNumber($expireTime).')'); |
|
1150 | + VALUES('.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($reasonID) . ', ' . $this->db->escapeString($suspicion) . ', ' . $this->db->escapeNumber($expireTime) . ')'); |
|
1151 | 1151 | $this->db->lockTable('active_session'); |
1152 | - $this->db->query('DELETE FROM active_session WHERE '.$this->SQL.' LIMIT 1'); |
|
1152 | + $this->db->query('DELETE FROM active_session WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1153 | 1153 | $this->db->unlock(); |
1154 | 1154 | |
1155 | 1155 | $this->db->query('INSERT INTO account_has_closing_history |
@@ -1169,38 +1169,38 @@ discard block |
||
1169 | 1169 | $player->update(); |
1170 | 1170 | } |
1171 | 1171 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account closed by ' . $admin->getLogin() . '.'); |
1172 | - if($removeExceptions!==false) |
|
1172 | + if ($removeExceptions !== false) |
|
1173 | 1173 | $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - public function unbanAccount(SmrAccount $admin = null,$currException=false) { |
|
1176 | + public function unbanAccount(SmrAccount $admin = null, $currException = false) { |
|
1177 | 1177 | $adminID = 0; |
1178 | - if($admin!==null) |
|
1178 | + if ($admin !== null) |
|
1179 | 1179 | $adminID = $admin->getAccountID(); |
1180 | 1180 | $this->db->query('DELETE FROM account_is_closed WHERE ' . $this->SQL . ' LIMIT 1'); |
1181 | 1181 | $this->db->query('INSERT INTO account_has_closing_history |
1182 | 1182 | (account_id, time, admin_id, action) |
1183 | 1183 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($adminID) . ', ' . $this->db->escapeString('Opened') . ')'); |
1184 | 1184 | $this->db->query('UPDATE player SET last_turn_update = GREATEST(' . $this->db->escapeNumber(TIME) . ', last_turn_update) WHERE ' . $this->SQL); |
1185 | - if($admin!==null) |
|
1185 | + if ($admin !== null) |
|
1186 | 1186 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
1187 | 1187 | else |
1188 | 1188 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
1189 | - if($currException!==false) |
|
1189 | + if ($currException !== false) |
|
1190 | 1190 | $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
1191 | 1191 | VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeString($currException) . ')'); |
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | public function getToggleAJAXHREF() { |
1195 | 1195 | global $var; |
1196 | - return SmrSession::getNewHREF(create_container('skeleton.php','toggle_processing.php',array('toggle'=>'AJAX','referrer'=>$var['body']))); |
|
1196 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'toggle_processing.php', array('toggle'=>'AJAX', 'referrer'=>$var['body']))); |
|
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | public function getUserRankingHREF() { |
1200 | - return SmrSession::getNewHREF(create_container('skeleton.php','rankings_view.php')); |
|
1200 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'rankings_view.php')); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | public function getPersonalHofHREF() { |
1204 | - return SmrSession::getNewHREF(create_container('skeleton.php','hall_of_fame_player_detail.php',array('account_id' => $this->getAccountID()))); |
|
1204 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'hall_of_fame_player_detail.php', array('account_id' => $this->getAccountID()))); |
|
1205 | 1205 | } |
1206 | 1206 | } |
@@ -99,8 +99,9 @@ discard block |
||
99 | 99 | if (empty($login)) { return null; } |
100 | 100 | $db = new SmrMySqlDatabase(); |
101 | 101 | $db->query('SELECT account_id FROM account WHERE login = '.$db->escapeString($login).' LIMIT 1'); |
102 | - if($db->nextRecord()) |
|
103 | - return self::getAccount($db->getField('account_id'),$forceUpdate); |
|
102 | + if($db->nextRecord()) { |
|
103 | + return self::getAccount($db->getField('account_id'),$forceUpdate); |
|
104 | + } |
|
104 | 105 | $return = null; |
105 | 106 | return $return; |
106 | 107 | } |
@@ -235,10 +236,10 @@ discard block |
||
235 | 236 | $this->template = $row['template']; |
236 | 237 | $this->colourScheme = $row['colour_scheme']; |
237 | 238 | |
238 | - if(empty($this->hofName)) |
|
239 | - $this->hofName=$this->login; |
|
240 | - } |
|
241 | - else { |
|
239 | + if(empty($this->hofName)) { |
|
240 | + $this->hofName=$this->login; |
|
241 | + } |
|
242 | + } else { |
|
242 | 243 | throw new AccountNotFoundException('Account ID '.$accountID.' does not exist!'); |
243 | 244 | } |
244 | 245 | } |
@@ -260,8 +261,7 @@ discard block |
||
260 | 261 | 'Reason' => $this->db->getField('reason'), |
261 | 262 | 'ReasonID' => $this->db->getInt('reason_id') |
262 | 263 | ); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | } |
@@ -317,15 +317,18 @@ discard block |
||
317 | 317 | if ($curr_ip != 'unknown' && $curr_ip != 'unknown...' && $curr_ip != 'unknown, unknown') { |
318 | 318 | $curr_ip = $fi.'.'.$se.'.'.$th.'.'.$fo; |
319 | 319 | $host = gethostbyaddr($curr_ip); |
320 | - } else $host = 'unknown'; |
|
320 | + } else { |
|
321 | + $host = 'unknown'; |
|
322 | + } |
|
321 | 323 | |
322 | 324 | // save...first make sure there isn't one for these keys (someone could double click and get error) |
323 | 325 | $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES ('.$this->db->escapeNumber($this->account_id).', '.$this->db->escapeNumber(TIME).', '.$this->db->escapeString($curr_ip).', '.$this->db->escapeString($host).')'); |
324 | 326 | } |
325 | 327 | |
326 | 328 | public function updateLastLogin() { |
327 | - if($this->last_login == TIME) |
|
328 | - return; |
|
329 | + if($this->last_login == TIME) { |
|
330 | + return; |
|
331 | + } |
|
329 | 332 | $this->last_login = TIME; |
330 | 333 | $this->hasChanged = true; |
331 | 334 | $this->update(); |
@@ -336,8 +339,9 @@ discard block |
||
336 | 339 | } |
337 | 340 | |
338 | 341 | public function setLoggingEnabled($bool) { |
339 | - if($this->logging==$bool) |
|
340 | - return; |
|
342 | + if($this->logging==$bool) { |
|
343 | + return; |
|
344 | + } |
|
341 | 345 | $this->logging=$bool; |
342 | 346 | $this->hasChanged = true; |
343 | 347 | $this->update(); |
@@ -386,12 +390,14 @@ discard block |
||
386 | 390 | |
387 | 391 | public function getHOF(array $typeList = null) { |
388 | 392 | $this->getHOFData(); |
389 | - if($typeList==null) |
|
390 | - return $this->HOF; |
|
393 | + if($typeList==null) { |
|
394 | + return $this->HOF; |
|
395 | + } |
|
391 | 396 | $hof=$this->HOF; |
392 | 397 | foreach($typeList as $type) { |
393 | - if(!isset($hof[$type])) |
|
394 | - return 0; |
|
398 | + if(!isset($hof[$type])) { |
|
399 | + return 0; |
|
400 | + } |
|
395 | 401 | $hof = $hof[$type]; |
396 | 402 | } |
397 | 403 | return $hof; |
@@ -399,10 +405,11 @@ discard block |
||
399 | 405 | |
400 | 406 | public function getRankName() { |
401 | 407 | $rankings = Globals::getUserRanking(); |
402 | - if(isset($rankings[$this->getRank()])) |
|
403 | - return $rankings[$this->getRank()]; |
|
404 | - else |
|
405 | - return end($rankings); |
|
408 | + if(isset($rankings[$this->getRank()])) { |
|
409 | + return $rankings[$this->getRank()]; |
|
410 | + } else { |
|
411 | + return end($rankings); |
|
412 | + } |
|
406 | 413 | } |
407 | 414 | |
408 | 415 | public function getScore() { |
@@ -418,15 +425,17 @@ discard block |
||
418 | 425 | |
419 | 426 | public function &getIndividualScores(SmrPlayer $player = null) { |
420 | 427 | $gameID=0; |
421 | - if($player!=null) |
|
422 | - $gameID = $player->getGameID(); |
|
428 | + if($player!=null) { |
|
429 | + $gameID = $player->getGameID(); |
|
430 | + } |
|
423 | 431 | if(!isset($this->individualScores[$gameID])) { |
424 | 432 | $this->individualScores[$gameID] = array(); |
425 | 433 | foreach(self::USER_RANKINGS_SCORE as $statScore) { |
426 | - if($player==null) |
|
427 | - $stat = $this->getHOF($statScore[0]); |
|
428 | - else |
|
429 | - $stat = $player->getHOF($statScore[0]); |
|
434 | + if($player==null) { |
|
435 | + $stat = $this->getHOF($statScore[0]); |
|
436 | + } else { |
|
437 | + $stat = $player->getHOF($statScore[0]); |
|
438 | + } |
|
430 | 439 | $this->individualScores[$gameID][]=array('Stat'=>$statScore[0],'Score'=>pow($stat*$statScore[1],self::USER_RANKINGS_EACH_STAT_POW)*$statScore[2]); |
431 | 440 | } |
432 | 441 | } |
@@ -435,16 +444,19 @@ discard block |
||
435 | 444 | |
436 | 445 | public function getRank() { |
437 | 446 | $rank = ceil(pow($this->getScore(),self::USER_RANKINGS_TOTAL_SCORE_POW)/self::USER_RANKINGS_RANK_BOUNDARY); |
438 | - if($rank<1) |
|
439 | - $rank=1; |
|
440 | - if($rank > $this->maxRankAchieved) |
|
441 | - $this->updateMaxRankAchieved($rank); |
|
447 | + if($rank<1) { |
|
448 | + $rank=1; |
|
449 | + } |
|
450 | + if($rank > $this->maxRankAchieved) { |
|
451 | + $this->updateMaxRankAchieved($rank); |
|
452 | + } |
|
442 | 453 | return $rank; |
443 | 454 | } |
444 | 455 | |
445 | 456 | protected function updateMaxRankAchieved($rank) { |
446 | - if($rank <= $this->maxRankAchieved) |
|
447 | - throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
|
457 | + if($rank <= $this->maxRankAchieved) { |
|
458 | + throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
|
459 | + } |
|
448 | 460 | $delta = $rank - $this->maxRankAchieved; |
449 | 461 | if($this->hasReferrer()) { |
450 | 462 | $this->getReferrer()->increaseSmrRewardCredits($delta * CREDITS_PER_DOLLAR); |
@@ -491,12 +503,15 @@ discard block |
||
491 | 503 | } |
492 | 504 | |
493 | 505 | public function decreaseTotalSmrCredits($totalCredits) { |
494 | - if($totalCredits==0) |
|
495 | - return; |
|
496 | - if($totalCredits<0) |
|
497 | - throw new Exception('You cannot use negative total credits'); |
|
498 | - if($totalCredits>$this->getTotalSmrCredits()) |
|
499 | - throw new Exception('You do not have that many credits in total to use'); |
|
506 | + if($totalCredits==0) { |
|
507 | + return; |
|
508 | + } |
|
509 | + if($totalCredits<0) { |
|
510 | + throw new Exception('You cannot use negative total credits'); |
|
511 | + } |
|
512 | + if($totalCredits>$this->getTotalSmrCredits()) { |
|
513 | + throw new Exception('You do not have that many credits in total to use'); |
|
514 | + } |
|
500 | 515 | |
501 | 516 | $rewardCredits=$this->rewardCredits; |
502 | 517 | $credits=$this->credits; |
@@ -505,10 +520,11 @@ discard block |
||
505 | 520 | $credits+=$rewardCredits; |
506 | 521 | $rewardCredits=0; |
507 | 522 | } |
508 | - if($this->credits==0 && $this->rewardCredits==0) |
|
509 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
510 | - else |
|
511 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
523 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
524 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
525 | + } else { |
|
526 | + $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
527 | + } |
|
512 | 528 | $this->credits=$credits; |
513 | 529 | $this->rewardCredits=$rewardCredits; |
514 | 530 | } |
@@ -524,48 +540,59 @@ discard block |
||
524 | 540 | } |
525 | 541 | |
526 | 542 | public function setSmrCredits($credits) { |
527 | - if($this->getSmrCredits()==$credits) |
|
528 | - return; |
|
529 | - if($this->credits==0 && $this->rewardCredits==0) |
|
530 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
531 | - else |
|
532 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
543 | + if($this->getSmrCredits()==$credits) { |
|
544 | + return; |
|
545 | + } |
|
546 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
547 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
548 | + } else { |
|
549 | + $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
550 | + } |
|
533 | 551 | $this->credits=$credits; |
534 | 552 | } |
535 | 553 | |
536 | 554 | public function increaseSmrCredits($credits) { |
537 | - if($credits==0) |
|
538 | - return; |
|
539 | - if($credits<0) |
|
540 | - throw new Exception('You cannot gain negative credits'); |
|
555 | + if($credits==0) { |
|
556 | + return; |
|
557 | + } |
|
558 | + if($credits<0) { |
|
559 | + throw new Exception('You cannot gain negative credits'); |
|
560 | + } |
|
541 | 561 | $this->setSmrCredits($this->getSmrCredits()+$credits); |
542 | 562 | } |
543 | 563 | |
544 | 564 | public function decreaseSmrCredits($credits) { |
545 | - if($credits==0) |
|
546 | - return; |
|
547 | - if($credits<0) |
|
548 | - throw new Exception('You cannot use negative credits'); |
|
549 | - if($credits>$this->getSmrCredits()) |
|
550 | - throw new Exception('You cannot use more credits than you have'); |
|
565 | + if($credits==0) { |
|
566 | + return; |
|
567 | + } |
|
568 | + if($credits<0) { |
|
569 | + throw new Exception('You cannot use negative credits'); |
|
570 | + } |
|
571 | + if($credits>$this->getSmrCredits()) { |
|
572 | + throw new Exception('You cannot use more credits than you have'); |
|
573 | + } |
|
551 | 574 | $this->setSmrCredits($this->getSmrCredits()-$credits); |
552 | 575 | } |
553 | 576 | |
554 | 577 | public function setSmrRewardCredits($credits) { |
555 | - if($this->getSmrRewardCredits()==$credits) |
|
556 | - return; |
|
557 | - if($this->credits==0 && $this->rewardCredits==0) |
|
558 | - $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
559 | - else |
|
560 | - $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
578 | + if($this->getSmrRewardCredits()==$credits) { |
|
579 | + return; |
|
580 | + } |
|
581 | + if($this->credits==0 && $this->rewardCredits==0) { |
|
582 | + $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
583 | + } else { |
|
584 | + $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
585 | + } |
|
561 | 586 | $this->rewardCredits=$credits; |
562 | 587 | } |
563 | 588 | |
564 | 589 | public function increaseSmrRewardCredits($credits) { |
565 | - if($credits==0) |
|
566 | - return; |
|
567 | - if($credits<0) |
|
568 | - throw new Exception('You cannot gain negative reward credits'); |
|
590 | + if($credits==0) { |
|
591 | + return; |
|
592 | + } |
|
593 | + if($credits<0) { |
|
594 | + throw new Exception('You cannot gain negative reward credits'); |
|
595 | + } |
|
569 | 596 | $this->setSmrRewardCredits($this->getSmrRewardCredits()+$credits); |
570 | 597 | } |
571 | 598 | |
@@ -601,8 +628,9 @@ discard block |
||
601 | 628 | } |
602 | 629 | |
603 | 630 | public function hasOldAccountID($dbName=false) { |
604 | - if($dbName===false) |
|
605 | - return count($this->getOldAccountIDs())!=0; |
|
631 | + if($dbName===false) { |
|
632 | + return count($this->getOldAccountIDs())!=0; |
|
633 | + } |
|
606 | 634 | return $this->getOldAccountID($dbName)!=0; |
607 | 635 | } |
608 | 636 | |
@@ -681,8 +709,9 @@ discard block |
||
681 | 709 | } |
682 | 710 | |
683 | 711 | public function setFontSize($size) { |
684 | - if($this->fontSize==$size) |
|
685 | - return; |
|
712 | + if($this->fontSize==$size) { |
|
713 | + return; |
|
714 | + } |
|
686 | 715 | $this->fontSize = $size; |
687 | 716 | $this->hasChanged = true; |
688 | 717 | $this->update(); |
@@ -695,8 +724,9 @@ discard block |
||
695 | 724 | |
696 | 725 | // sets the extra CSS file linked in preferences |
697 | 726 | public function setCssLink($link) { |
698 | - if($this->cssLink==$link) |
|
699 | - return; |
|
727 | + if($this->cssLink==$link) { |
|
728 | + return; |
|
729 | + } |
|
700 | 730 | $this->cssLink = $link; |
701 | 731 | $this->hasChanged = true; |
702 | 732 | $this->update(); |
@@ -707,10 +737,12 @@ discard block |
||
707 | 737 | } |
708 | 738 | |
709 | 739 | public function setTemplate($template) { |
710 | - if($this->template==$template) |
|
711 | - return; |
|
712 | - if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) |
|
713 | - throw new Exception('Template not allowed: '.$template); |
|
740 | + if($this->template==$template) { |
|
741 | + return; |
|
742 | + } |
|
743 | + if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) { |
|
744 | + throw new Exception('Template not allowed: '.$template); |
|
745 | + } |
|
714 | 746 | $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE '.$this->SQL.' LIMIT 1'); |
715 | 747 | $this->template = $template; |
716 | 748 | $colourSchemes = Globals::getAvailableColourSchemes($template); |
@@ -722,10 +754,12 @@ discard block |
||
722 | 754 | } |
723 | 755 | |
724 | 756 | public function setColourScheme($colourScheme) { |
725 | - if($this->colourScheme==$colourScheme) |
|
726 | - return; |
|
727 | - if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
728 | - throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
757 | + if($this->colourScheme==$colourScheme) { |
|
758 | + return; |
|
759 | + } |
|
760 | + if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) { |
|
761 | + throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
762 | + } |
|
729 | 763 | $this->colourScheme = $colourScheme; |
730 | 764 | $this->hasChanged = true; |
731 | 765 | $this->update(); |
@@ -750,8 +784,9 @@ discard block |
||
750 | 784 | } |
751 | 785 | |
752 | 786 | public function setHofName($name) { |
753 | - if($this->hofName==$name) |
|
754 | - return; |
|
787 | + if($this->hofName==$name) { |
|
788 | + return; |
|
789 | + } |
|
755 | 790 | $this->hofName = $name; |
756 | 791 | $this->hasChanged = true; |
757 | 792 | $this->update(); |
@@ -762,8 +797,9 @@ discard block |
||
762 | 797 | } |
763 | 798 | |
764 | 799 | public function setIrcNick($nick) { |
765 | - if($this->ircNick==$nick) |
|
766 | - return; |
|
800 | + if($this->ircNick==$nick) { |
|
801 | + return; |
|
802 | + } |
|
767 | 803 | $this->ircNick = $nick; |
768 | 804 | $this->hasChanged = true; |
769 | 805 | $this->update(); |
@@ -791,8 +827,9 @@ discard block |
||
791 | 827 | } |
792 | 828 | |
793 | 829 | public function setShortDateFormat($format) { |
794 | - if($this->dateShort==$format) |
|
795 | - return; |
|
830 | + if($this->dateShort==$format) { |
|
831 | + return; |
|
832 | + } |
|
796 | 833 | $this->dateShort = $format; |
797 | 834 | $this->hasChanged = true; |
798 | 835 | $this->update(); |
@@ -803,8 +840,9 @@ discard block |
||
803 | 840 | } |
804 | 841 | |
805 | 842 | public function setShortTimeFormat($format) { |
806 | - if($this->timeShort==$format) |
|
807 | - return; |
|
843 | + if($this->timeShort==$format) { |
|
844 | + return; |
|
845 | + } |
|
808 | 846 | $this->timeShort = $format; |
809 | 847 | $this->hasChanged = true; |
810 | 848 | $this->update(); |
@@ -815,16 +853,18 @@ discard block |
||
815 | 853 | } |
816 | 854 | |
817 | 855 | protected function setValidationCode($code) { |
818 | - if($this->validation_code == $code) |
|
819 | - return; |
|
856 | + if($this->validation_code == $code) { |
|
857 | + return; |
|
858 | + } |
|
820 | 859 | $this->validation_code=$code; |
821 | 860 | $this->hasChanged=true; |
822 | 861 | $this->update(); |
823 | 862 | } |
824 | 863 | |
825 | 864 | public function setValidated($bool) { |
826 | - if($this->validated == $bool) |
|
827 | - return; |
|
865 | + if($this->validated == $bool) { |
|
866 | + return; |
|
867 | + } |
|
828 | 868 | $this->validated = $bool; |
829 | 869 | $this->hasChanged = true; |
830 | 870 | $this->update(); |
@@ -897,8 +937,9 @@ discard block |
||
897 | 937 | } |
898 | 938 | |
899 | 939 | protected function setPasswordReset($passwordReset) { |
900 | - if($this->passwordReset == $passwordReset) |
|
901 | - return; |
|
940 | + if($this->passwordReset == $passwordReset) { |
|
941 | + return; |
|
942 | + } |
|
902 | 943 | $this->passwordReset=$passwordReset; |
903 | 944 | $this->hasChanged=true; |
904 | 945 | $this->update(); |
@@ -909,8 +950,9 @@ discard block |
||
909 | 950 | } |
910 | 951 | |
911 | 952 | public function setDisplayShipImages($yesNo) { |
912 | - if($this->images == $yesNo) |
|
913 | - return; |
|
953 | + if($this->images == $yesNo) { |
|
954 | + return; |
|
955 | + } |
|
914 | 956 | $this->images = $yesNo; |
915 | 957 | $this->hasChanged = true; |
916 | 958 | $this->update(); |
@@ -921,8 +963,9 @@ discard block |
||
921 | 963 | } |
922 | 964 | |
923 | 965 | public function setUseAJAX($bool) { |
924 | - if($this->useAJAX == $bool) |
|
925 | - return; |
|
966 | + if($this->useAJAX == $bool) { |
|
967 | + return; |
|
968 | + } |
|
926 | 969 | $this->useAJAX=$bool; |
927 | 970 | $this->hasChanged=true; |
928 | 971 | $this->update(); |
@@ -933,8 +976,9 @@ discard block |
||
933 | 976 | } |
934 | 977 | |
935 | 978 | public function setDefaultCSSEnabled($bool) { |
936 | - if($this->defaultCSSEnabled == $bool) |
|
937 | - return; |
|
979 | + if($this->defaultCSSEnabled == $bool) { |
|
980 | + return; |
|
981 | + } |
|
938 | 982 | $this->defaultCSSEnabled=$bool; |
939 | 983 | $this->hasChanged=true; |
940 | 984 | $this->update(); |
@@ -944,8 +988,7 @@ discard block |
||
944 | 988 | if($hotkeyType!==false) { |
945 | 989 | if(isset($this->hotkeys[$hotkeyType])) { |
946 | 990 | return $this->hotkeys[$hotkeyType]; |
947 | - } |
|
948 | - else { |
|
991 | + } else { |
|
949 | 992 | return array(); |
950 | 993 | } |
951 | 994 | } |
@@ -953,8 +996,9 @@ discard block |
||
953 | 996 | } |
954 | 997 | |
955 | 998 | public function setHotkey($hotkeyType,$binding) { |
956 | - if($this->getHotkeys($hotkeyType) == $binding) |
|
957 | - return; |
|
999 | + if($this->getHotkeys($hotkeyType) == $binding) { |
|
1000 | + return; |
|
1001 | + } |
|
958 | 1002 | $this->hotkeys[$hotkeyType] = $binding; |
959 | 1003 | $this->hasChanged=true; |
960 | 1004 | $this->update(); |
@@ -969,26 +1013,31 @@ discard block |
||
969 | 1013 | } |
970 | 1014 | |
971 | 1015 | public function setMessageNotifications($messageTypeID,$num) { |
972 | - if($this->getMessageNotifications($messageTypeID) == $num) |
|
973 | - return; |
|
1016 | + if($this->getMessageNotifications($messageTypeID) == $num) { |
|
1017 | + return; |
|
1018 | + } |
|
974 | 1019 | $this->messageNotifications[$messageTypeID]=$num; |
975 | 1020 | $this->hasChanged=true; |
976 | 1021 | $this->update(); |
977 | 1022 | } |
978 | 1023 | |
979 | 1024 | public function increaseMessageNotifications($messageTypeID,$num) { |
980 | - if($num==0) |
|
981 | - return; |
|
982 | - if($num<0) |
|
983 | - throw new Exception('You cannot increase by a negative amount'); |
|
1025 | + if($num==0) { |
|
1026 | + return; |
|
1027 | + } |
|
1028 | + if($num<0) { |
|
1029 | + throw new Exception('You cannot increase by a negative amount'); |
|
1030 | + } |
|
984 | 1031 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) + $num); |
985 | 1032 | } |
986 | 1033 | |
987 | 1034 | public function decreaseMessageNotifications($messageTypeID,$num) { |
988 | - if($num==0) |
|
989 | - return; |
|
990 | - if($num<0) |
|
991 | - throw new Exception('You cannot decrease by a negative amount'); |
|
1035 | + if($num==0) { |
|
1036 | + return; |
|
1037 | + } |
|
1038 | + if($num<0) { |
|
1039 | + throw new Exception('You cannot decrease by a negative amount'); |
|
1040 | + } |
|
992 | 1041 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) - $num); |
993 | 1042 | } |
994 | 1043 | |
@@ -997,8 +1046,9 @@ discard block |
||
997 | 1046 | } |
998 | 1047 | |
999 | 1048 | public function setCenterGalaxyMapOnPlayer($bool) { |
1000 | - if($this->centerGalaxyMapOnPlayer == $bool) |
|
1001 | - return; |
|
1049 | + if($this->centerGalaxyMapOnPlayer == $bool) { |
|
1050 | + return; |
|
1051 | + } |
|
1002 | 1052 | $this->centerGalaxyMapOnPlayer=$bool; |
1003 | 1053 | $this->hasChanged=true; |
1004 | 1054 | $this->update(); |
@@ -1013,8 +1063,9 @@ discard block |
||
1013 | 1063 | } |
1014 | 1064 | |
1015 | 1065 | public function setMailBanned($time) { |
1016 | - if($this->mailBanned == $time) |
|
1017 | - return; |
|
1066 | + if($this->mailBanned == $time) { |
|
1067 | + return; |
|
1068 | + } |
|
1018 | 1069 | $this->mailBanned=$time; |
1019 | 1070 | $this->hasChanged=true; |
1020 | 1071 | } |
@@ -1068,53 +1119,59 @@ discard block |
||
1068 | 1119 | |
1069 | 1120 | public function setPoints($numPoints,$lastUpdate=false) { |
1070 | 1121 | $numPoints = max($numPoints,0); |
1071 | - if($this->getPoints()==$numPoints) |
|
1072 | - return; |
|
1073 | - if ($this->points==0) |
|
1074 | - $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).')'); |
|
1075 | - else if($numPoints<=0) |
|
1076 | - $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1077 | - else |
|
1078 | - $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'); |
|
1122 | + if($this->getPoints()==$numPoints) { |
|
1123 | + return; |
|
1124 | + } |
|
1125 | + if ($this->points==0) { |
|
1126 | + $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).')'); |
|
1127 | + } else if($numPoints<=0) { |
|
1128 | + $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1129 | + } else { |
|
1130 | + $this->db->query('UPDATE account_has_points SET points = '.$this->db->escapeNumber($numPoints).($lastUpdate ? ', last_update = '.$this->db->escapeNumber(TIME) : '').' WHERE '.$this->SQL.' LIMIT 1'); |
|
1131 | + } |
|
1079 | 1132 | $this->points=$numPoints; |
1080 | 1133 | } |
1081 | 1134 | |
1082 | 1135 | public function removePoints($numPoints,$lastUpdate=false) { |
1083 | - if($numPoints>0) |
|
1084 | - $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1136 | + if($numPoints>0) { |
|
1137 | + $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1138 | + } |
|
1085 | 1139 | } |
1086 | 1140 | |
1087 | 1141 | public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) { |
1088 | 1142 | //do we have points |
1089 | 1143 | $this->setPoints($this->getPoints() + $numPoints,TIME); |
1090 | 1144 | $totalPoints = $this->getPoints(); |
1091 | - if ($totalPoints < 10) |
|
1092 | - return false;//leave scripts its only a warning |
|
1093 | - elseif ($totalPoints < 20) |
|
1094 | - $days = 2; |
|
1095 | - elseif ($totalPoints < 30) |
|
1096 | - $days = 4; |
|
1097 | - elseif ($totalPoints < 50) |
|
1098 | - $days = 7; |
|
1099 | - elseif ($totalPoints < 75) |
|
1100 | - $days = 15 ; |
|
1101 | - elseif ($totalPoints < 100) |
|
1102 | - $days = 30; |
|
1103 | - elseif ($totalPoints < 125) |
|
1104 | - $days = 60; |
|
1105 | - elseif ($totalPoints < 150) |
|
1106 | - $days = 120; |
|
1107 | - elseif ($totalPoints < 175) |
|
1108 | - $days = 240; |
|
1109 | - elseif ($totalPoints < 200) |
|
1110 | - $days = 480; |
|
1111 | - else |
|
1112 | - $days = 0; //Forever/indefinite |
|
1145 | + if ($totalPoints < 10) { |
|
1146 | + return false; |
|
1147 | + } |
|
1148 | + //leave scripts its only a warning |
|
1149 | + elseif ($totalPoints < 20) { |
|
1150 | + $days = 2; |
|
1151 | + } elseif ($totalPoints < 30) { |
|
1152 | + $days = 4; |
|
1153 | + } elseif ($totalPoints < 50) { |
|
1154 | + $days = 7; |
|
1155 | + } elseif ($totalPoints < 75) { |
|
1156 | + $days = 15 ; |
|
1157 | + } elseif ($totalPoints < 100) { |
|
1158 | + $days = 30; |
|
1159 | + } elseif ($totalPoints < 125) { |
|
1160 | + $days = 60; |
|
1161 | + } elseif ($totalPoints < 150) { |
|
1162 | + $days = 120; |
|
1163 | + } elseif ($totalPoints < 175) { |
|
1164 | + $days = 240; |
|
1165 | + } elseif ($totalPoints < 200) { |
|
1166 | + $days = 480; |
|
1167 | + } else { |
|
1168 | + $days = 0; |
|
1169 | + } |
|
1170 | + //Forever/indefinite |
|
1113 | 1171 | |
1114 | 1172 | if($days==0) { |
1115 | 1173 | $expireTime = 0; |
1116 | - } |
|
1117 | - else { |
|
1174 | + } else { |
|
1118 | 1175 | $expireTime = TIME + $days * 86400; |
1119 | 1176 | } |
1120 | 1177 | $this->banAccount($expireTime,$admin,$reasonID,$suspicion); |
@@ -1169,26 +1226,30 @@ discard block |
||
1169 | 1226 | $player->update(); |
1170 | 1227 | } |
1171 | 1228 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account closed by ' . $admin->getLogin() . '.'); |
1172 | - if($removeExceptions!==false) |
|
1173 | - $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
|
1229 | + if($removeExceptions!==false) { |
|
1230 | + $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
|
1231 | + } |
|
1174 | 1232 | } |
1175 | 1233 | |
1176 | 1234 | public function unbanAccount(SmrAccount $admin = null,$currException=false) { |
1177 | 1235 | $adminID = 0; |
1178 | - if($admin!==null) |
|
1179 | - $adminID = $admin->getAccountID(); |
|
1236 | + if($admin!==null) { |
|
1237 | + $adminID = $admin->getAccountID(); |
|
1238 | + } |
|
1180 | 1239 | $this->db->query('DELETE FROM account_is_closed WHERE ' . $this->SQL . ' LIMIT 1'); |
1181 | 1240 | $this->db->query('INSERT INTO account_has_closing_history |
1182 | 1241 | (account_id, time, admin_id, action) |
1183 | 1242 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($adminID) . ', ' . $this->db->escapeString('Opened') . ')'); |
1184 | 1243 | $this->db->query('UPDATE player SET last_turn_update = GREATEST(' . $this->db->escapeNumber(TIME) . ', last_turn_update) WHERE ' . $this->SQL); |
1185 | - if($admin!==null) |
|
1186 | - $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
|
1187 | - else |
|
1188 | - $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
|
1189 | - if($currException!==false) |
|
1190 | - $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
|
1244 | + if($admin!==null) { |
|
1245 | + $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
|
1246 | + } else { |
|
1247 | + $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
|
1248 | + } |
|
1249 | + if($currException!==false) { |
|
1250 | + $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
|
1191 | 1251 | VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeString($currException) . ')'); |
1252 | + } |
|
1192 | 1253 | } |
1193 | 1254 | |
1194 | 1255 | public function getToggleAJAXHREF() { |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | foreach (Globals::getGoods() as $goodId => $value) { |
105 | 105 | if ($goods[$goodId]===true) { |
106 | 106 | if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS && |
107 | - $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
|
107 | + $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
|
108 | 108 | $rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $races[$raceID], $sectors[$targetSectorId]->getPort()->getRaceID(), $sectors[$currentSectorId]->getPort()->getGoodDistance($goodId), $sectors[$targetSectorId]->getPort()->getGoodDistance($goodId), $distance, $goodId); |
109 | 109 | } |
110 | 110 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | foreach (Globals::getGoods() as $goodId => $value) { |
131 | 131 | if ($goods[$goodId]===true) { |
132 | 132 | if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS && |
133 | - $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
|
133 | + $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
|
134 | 134 | $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); |
135 | 135 | $fakeReturn = new OneWayRoute($targetSectorId, $currentSectorId, $sectors[$targetSectorId]->getPort()->getRaceID(), $sectors[$currentSectorId]->getPort()->getRaceID(), 0, 0, $distance, GOOD_NOTHING); |
136 | 136 | $mpr = new MultiplePortRoute($owr, $fakeReturn); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | self::$moneyRoutes = array(); |
22 | 22 | $runs = array(); |
23 | 23 | $totalTasks = 0; |
24 | - foreach($routeLists as $key => &$value) { |
|
24 | + foreach ($routeLists as $key => &$value) { |
|
25 | 25 | self::startRoutesToContinue($maxNumPorts, $key, $value, $routeLists); |
26 | 26 | if ($totalTasks % 10 === 0 && $totalTasks > $numberOfRoutes) { |
27 | 27 | self::trimRoutes($numberOfRoutes); |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | // $tasksCompleted = 0; |
32 | 32 | self::trimRoutes($numberOfRoutes); |
33 | 33 | $allRoutes = array(); |
34 | - $allRoutes[self::EXP_ROUTE] =& self::$expRoutes; |
|
35 | - $allRoutes[self::MONEY_ROUTE] =& self::$moneyRoutes; |
|
34 | + $allRoutes[self::EXP_ROUTE] = & self::$expRoutes; |
|
35 | + $allRoutes[self::MONEY_ROUTE] = & self::$moneyRoutes; |
|
36 | 36 | return $allRoutes; |
37 | 37 | } |
38 | 38 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param expRoutes |
46 | 46 | */ |
47 | 47 | static function startRoutesToContinue($maxNumPorts, $startSectorId, array &$forwardRoutes, array &$routeLists) { |
48 | - foreach($forwardRoutes as &$currentStepRoute) { |
|
48 | + foreach ($forwardRoutes as &$currentStepRoute) { |
|
49 | 49 | $currentStepBuySector = $currentStepRoute->getBuySectorId(); |
50 | 50 | if ($currentStepBuySector > $startSectorId) { // Not already checked |
51 | 51 | self::getContinueRoutes($maxNumPorts - 1, $startSectorId, $currentStepRoute, $routeLists[$currentStepBuySector], $routeLists, $currentStepRoute->getGoodID() === GOOD_NOTHING); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | * @param allRoutes |
64 | 64 | */ |
65 | 65 | private static function getContinueRoutes($maxNumPorts, $startSectorId, Route &$routeToContinue, array &$forwardRoutes, array &$routeLists, $lastGoodIsNothing) { |
66 | - foreach($forwardRoutes as &$currentStepRoute) { |
|
66 | + foreach ($forwardRoutes as &$currentStepRoute) { |
|
67 | 67 | $currentStepBuySector = $currentStepRoute->getBuySectorId(); |
68 | - if ($lastGoodIsNothing & ($lastGoodIsNothing = GOOD_NOTHING === $currentStepRoute->getGoodID())) |
|
68 | + if ($lastGoodIsNothing&($lastGoodIsNothing = GOOD_NOTHING === $currentStepRoute->getGoodID())) |
|
69 | 69 | continue; // Don't do two nothings in a row |
70 | 70 | if ($currentStepBuySector >= $startSectorId) { // Not already checked or back to start |
71 | 71 | if ($currentStepBuySector === $startSectorId) { // Route returns to start |
@@ -83,26 +83,26 @@ discard block |
||
83 | 83 | |
84 | 84 | private static function &findOneWayRoutes(array &$sectors, array &$distances, $routesForPort, array &$goods, array &$races) { |
85 | 85 | $routes = array(); |
86 | - foreach($distances as $currentSectorId => &$d) { |
|
86 | + foreach ($distances as $currentSectorId => &$d) { |
|
87 | 87 | $raceID = $sectors[$currentSectorId]->getPort()->getRaceID(); |
88 | - if (isset($races[$raceID])===false) { |
|
89 | - echo 'Error with Race ID: '.$sectors[$currentSectorId]->getPort()->getRaceID(); |
|
88 | + if (isset($races[$raceID]) === false) { |
|
89 | + echo 'Error with Race ID: ' . $sectors[$currentSectorId]->getPort()->getRaceID(); |
|
90 | 90 | continue; |
91 | 91 | } |
92 | - if($races[$raceID]===false) |
|
92 | + if ($races[$raceID] === false) |
|
93 | 93 | continue; |
94 | 94 | $rl = array(); |
95 | - foreach($d as $targetSectorId => &$distance) { |
|
95 | + foreach ($d as $targetSectorId => &$distance) { |
|
96 | 96 | if (!$races[$sectors[$targetSectorId]->getPort()->getRaceID()]) |
97 | 97 | continue; |
98 | - if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
98 | + if ($routesForPort !== -1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
99 | 99 | continue; |
100 | 100 | |
101 | - if ($goods[GOOD_NOTHING]===true) |
|
101 | + if ($goods[GOOD_NOTHING] === true) |
|
102 | 102 | $rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $races[$raceID], $sectors[$targetSectorId]->getPort()->getRaceID(), 0, 0, $distance, GOOD_NOTHING); |
103 | 103 | |
104 | 104 | foreach (Globals::getGoods() as $goodId => $value) { |
105 | - if ($goods[$goodId]===true) { |
|
105 | + if ($goods[$goodId] === true) { |
|
106 | 106 | if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS && |
107 | 107 | $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
108 | 108 | $rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $races[$raceID], $sectors[$targetSectorId]->getPort()->getRaceID(), $sectors[$currentSectorId]->getPort()->getGoodDistance($goodId), $sectors[$targetSectorId]->getPort()->getGoodDistance($goodId), $distance, $goodId); |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | public static function &generateOneWayRoutes(array &$sectors, array &$distances, array &$goods, &$races, &$routesForPort) { |
119 | 119 | self::$expRoutes = array(); |
120 | 120 | self::$moneyRoutes = array(); |
121 | - foreach($distances as $currentSectorId => &$d) { |
|
122 | - if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()]===false) |
|
121 | + foreach ($distances as $currentSectorId => &$d) { |
|
122 | + if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()] === false) |
|
123 | 123 | continue; |
124 | - foreach($d as $targetSectorId => &$distance) { |
|
125 | - if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()]===false) |
|
124 | + foreach ($d as $targetSectorId => &$distance) { |
|
125 | + if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()] === false) |
|
126 | 126 | continue; |
127 | - if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
127 | + if ($routesForPort !== -1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
128 | 128 | continue; |
129 | 129 | |
130 | 130 | foreach (Globals::getGoods() as $goodId => $value) { |
131 | - if ($goods[$goodId]===true) { |
|
131 | + if ($goods[$goodId] === true) { |
|
132 | 132 | if ($sectors[$currentSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_SELLS && |
133 | 133 | $sectors[$targetSectorId]->getPort()->getGoodTransaction($goodId) === self::GOOD_BUYS) { |
134 | 134 | $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); |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | $overallMultiplier = $r->getOverallExpMultiplier(); |
152 | 152 | if ($overallMultiplier > self::$dontAddWorseThan[self::EXP_ROUTE]) { |
153 | 153 | if (isset(self::$expRoutes[$overallMultiplier])) { |
154 | - $rl =& self::$expRoutes[$overallMultiplier]; |
|
154 | + $rl = & self::$expRoutes[$overallMultiplier]; |
|
155 | 155 | } |
156 | 156 | else { |
157 | 157 | $rl = array(); |
158 | 158 | } |
159 | - $rl[] =& $r; |
|
160 | - self::$expRoutes[$overallMultiplier] =& $rl; |
|
159 | + $rl[] = & $r; |
|
160 | + self::$expRoutes[$overallMultiplier] = & $rl; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -165,32 +165,32 @@ discard block |
||
165 | 165 | $overallMultiplier = $r->getOverallMoneyMultiplier(); |
166 | 166 | if ($overallMultiplier > self::$dontAddWorseThan[self::MONEY_ROUTE]) { |
167 | 167 | if (isset(self::$moneyRoutes[$overallMultiplier])) { |
168 | - $rl =& self::$moneyRoutes[$overallMultiplier]; |
|
168 | + $rl = & self::$moneyRoutes[$overallMultiplier]; |
|
169 | 169 | } |
170 | 170 | else { |
171 | 171 | $rl = array(); |
172 | 172 | } |
173 | - $rl[] =& $r; |
|
174 | - self::$moneyRoutes[$overallMultiplier] =& $rl; |
|
173 | + $rl[] = & $r; |
|
174 | + self::$moneyRoutes[$overallMultiplier] = & $rl; |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | 178 | public static function trimRoutes($trimToBestXRoutes) { |
179 | 179 | $i = 0; |
180 | 180 | krsort(self::$expRoutes); |
181 | - foreach(self::$expRoutes as $multi => &$routesByMulti) { |
|
182 | - if(count($routesByMulti)+$i < $trimToBestXRoutes) { |
|
181 | + foreach (self::$expRoutes as $multi => &$routesByMulti) { |
|
182 | + if (count($routesByMulti) + $i < $trimToBestXRoutes) { |
|
183 | 183 | $i += count($routesByMulti); |
184 | 184 | } |
185 | - else if($i > $trimToBestXRoutes) { |
|
185 | + else if ($i > $trimToBestXRoutes) { |
|
186 | 186 | unset(self::$expRoutes[$multi]); |
187 | 187 | } |
188 | 188 | else { |
189 | - foreach($routesByMulti as $key => &$value) { |
|
189 | + foreach ($routesByMulti as $key => &$value) { |
|
190 | 190 | $i++; |
191 | - if($i < $trimToBestXRoutes) |
|
191 | + if ($i < $trimToBestXRoutes) |
|
192 | 192 | continue; |
193 | - if($i === $trimToBestXRoutes) { |
|
193 | + if ($i === $trimToBestXRoutes) { |
|
194 | 194 | self::$dontAddWorseThan[self::EXP_ROUTE] = $multi; |
195 | 195 | continue; |
196 | 196 | } |
@@ -201,20 +201,20 @@ discard block |
||
201 | 201 | |
202 | 202 | $i = 0; |
203 | 203 | krsort(self::$moneyRoutes); |
204 | - foreach(self::$moneyRoutes as $multi => &$routesByMulti) { |
|
205 | - if(count($routesByMulti)+$i < $trimToBestXRoutes) { |
|
204 | + foreach (self::$moneyRoutes as $multi => &$routesByMulti) { |
|
205 | + if (count($routesByMulti) + $i < $trimToBestXRoutes) { |
|
206 | 206 | $i += count($routesByMulti); |
207 | 207 | } |
208 | - else if($i > $trimToBestXRoutes) { |
|
208 | + else if ($i > $trimToBestXRoutes) { |
|
209 | 209 | unset(self::$moneyRoutes[$multi]); |
210 | 210 | continue; |
211 | 211 | } |
212 | 212 | else { |
213 | - foreach($routesByMulti as $key => &$value) { |
|
213 | + foreach ($routesByMulti as $key => &$value) { |
|
214 | 214 | $i++; |
215 | - if($i < $trimToBestXRoutes) |
|
215 | + if ($i < $trimToBestXRoutes) |
|
216 | 216 | continue; |
217 | - if($i === $trimToBestXRoutes) { |
|
217 | + if ($i === $trimToBestXRoutes) { |
|
218 | 218 | self::$dontAddWorseThan[self::MONEY_ROUTE] = $multi; |
219 | 219 | continue; |
220 | 220 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $this->buySectorId = $_buySectorId; |
278 | 278 | $this->sellDi = $_sellDi; |
279 | 279 | $this->buyDi = $_buyDi; |
280 | - $this->distance =& $_distance; |
|
280 | + $this->distance = & $_distance; |
|
281 | 281 | $this->goodId = $_goodId; |
282 | 282 | $this->sellPortRace = $_sellPortRace; |
283 | 283 | $this->buyPortRace = $_buyPortRace; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | public function getMoneyMultiplierSum() {// TODO sellDi stuff and check accuracy of formula |
323 | 323 | $buyRelFactor = 1; |
324 | 324 | $sellRelFactor = 1; |
325 | - if (ROUTE_GEN_USE_RELATIONS_FACTOR===true) { |
|
325 | + if (ROUTE_GEN_USE_RELATIONS_FACTOR === true) { |
|
326 | 326 | //TODO: This needs to be converted for PHP/SMR. |
327 | 327 | // $relations = max(PlayerPreferences.getRelationsForRace($this->buyPortRace), Settings.MAX_MONEY_RELATIONS); |
328 | 328 | // $buyRelFactor = ($relations + 350) / 8415.0; |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | public function compareTo(OneWayRoute &$compare) { |
356 | - if ($this->equals($compare)===true) |
|
356 | + if ($this->equals($compare) === true) |
|
357 | 357 | return 0; |
358 | 358 | if ($this->getOverallExpMultiplier() > $compare->getOverallExpMultiplier()) |
359 | 359 | return 1; |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | private $returnRoute; |
383 | 383 | |
384 | 384 | public function __construct(OneWayRoute &$_forwardRoute, OneWayRoute &$_returnRoute) { |
385 | - $this->forwardRoute =& $_forwardRoute; |
|
386 | - $this->returnRoute =& $_returnRoute; |
|
385 | + $this->forwardRoute = & $_forwardRoute; |
|
386 | + $this->returnRoute = & $_returnRoute; |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | public function &getForwardRoute() { |
@@ -65,15 +65,16 @@ discard block |
||
65 | 65 | private static function getContinueRoutes($maxNumPorts, $startSectorId, Route &$routeToContinue, array &$forwardRoutes, array &$routeLists, $lastGoodIsNothing) { |
66 | 66 | foreach($forwardRoutes as &$currentStepRoute) { |
67 | 67 | $currentStepBuySector = $currentStepRoute->getBuySectorId(); |
68 | - if ($lastGoodIsNothing & ($lastGoodIsNothing = GOOD_NOTHING === $currentStepRoute->getGoodID())) |
|
69 | - continue; // Don't do two nothings in a row |
|
68 | + if ($lastGoodIsNothing & ($lastGoodIsNothing = GOOD_NOTHING === $currentStepRoute->getGoodID())) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + // Don't do two nothings in a row |
|
70 | 72 | if ($currentStepBuySector >= $startSectorId) { // Not already checked or back to start |
71 | 73 | if ($currentStepBuySector === $startSectorId) { // Route returns to start |
72 | 74 | $mpr = new MultiplePortRoute($routeToContinue, $currentStepRoute); |
73 | 75 | self::addExpRoute($mpr); |
74 | 76 | self::addMoneyRoute($mpr); |
75 | - } |
|
76 | - else if ($maxNumPorts > 1 && !$routeToContinue->containsPort($currentStepBuySector)) { |
|
77 | + } else if ($maxNumPorts > 1 && !$routeToContinue->containsPort($currentStepBuySector)) { |
|
77 | 78 | $mpr = new MultiplePortRoute($routeToContinue, $currentStepRoute); |
78 | 79 | self::getContinueRoutes($maxNumPorts - 1, $startSectorId, $mpr, $routeLists[$currentStepBuySector], $routeLists, $lastGoodIsNothing); |
79 | 80 | } |
@@ -89,17 +90,21 @@ discard block |
||
89 | 90 | echo 'Error with Race ID: '.$sectors[$currentSectorId]->getPort()->getRaceID(); |
90 | 91 | continue; |
91 | 92 | } |
92 | - if($races[$raceID]===false) |
|
93 | - continue; |
|
93 | + if($races[$raceID]===false) { |
|
94 | + continue; |
|
95 | + } |
|
94 | 96 | $rl = array(); |
95 | 97 | foreach($d as $targetSectorId => &$distance) { |
96 | - if (!$races[$sectors[$targetSectorId]->getPort()->getRaceID()]) |
|
97 | - continue; |
|
98 | - if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
99 | - continue; |
|
98 | + if (!$races[$sectors[$targetSectorId]->getPort()->getRaceID()]) { |
|
99 | + continue; |
|
100 | + } |
|
101 | + if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) { |
|
102 | + continue; |
|
103 | + } |
|
100 | 104 | |
101 | - if ($goods[GOOD_NOTHING]===true) |
|
102 | - $rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $races[$raceID], $sectors[$targetSectorId]->getPort()->getRaceID(), 0, 0, $distance, GOOD_NOTHING); |
|
105 | + if ($goods[GOOD_NOTHING]===true) { |
|
106 | + $rl[] = new OneWayRoute($currentSectorId, $targetSectorId, $races[$raceID], $sectors[$targetSectorId]->getPort()->getRaceID(), 0, 0, $distance, GOOD_NOTHING); |
|
107 | + } |
|
103 | 108 | |
104 | 109 | foreach (Globals::getGoods() as $goodId => $value) { |
105 | 110 | if ($goods[$goodId]===true) { |
@@ -119,13 +124,16 @@ discard block |
||
119 | 124 | self::$expRoutes = array(); |
120 | 125 | self::$moneyRoutes = array(); |
121 | 126 | foreach($distances as $currentSectorId => &$d) { |
122 | - if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()]===false) |
|
123 | - continue; |
|
127 | + if ($races[$sectors[$currentSectorId]->getPort()->getRaceID()]===false) { |
|
128 | + continue; |
|
129 | + } |
|
124 | 130 | foreach($d as $targetSectorId => &$distance) { |
125 | - if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()]===false) |
|
126 | - continue; |
|
127 | - if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) |
|
128 | - continue; |
|
131 | + if ($races[$sectors[$targetSectorId]->getPort()->getRaceID()]===false) { |
|
132 | + continue; |
|
133 | + } |
|
134 | + if($routesForPort!==-1 && $currentSectorId !== $routesForPort && $targetSectorId !== $routesForPort) { |
|
135 | + continue; |
|
136 | + } |
|
129 | 137 | |
130 | 138 | foreach (Globals::getGoods() as $goodId => $value) { |
131 | 139 | if ($goods[$goodId]===true) { |
@@ -152,8 +160,7 @@ discard block |
||
152 | 160 | if ($overallMultiplier > self::$dontAddWorseThan[self::EXP_ROUTE]) { |
153 | 161 | if (isset(self::$expRoutes[$overallMultiplier])) { |
154 | 162 | $rl =& self::$expRoutes[$overallMultiplier]; |
155 | - } |
|
156 | - else { |
|
163 | + } else { |
|
157 | 164 | $rl = array(); |
158 | 165 | } |
159 | 166 | $rl[] =& $r; |
@@ -166,8 +173,7 @@ discard block |
||
166 | 173 | if ($overallMultiplier > self::$dontAddWorseThan[self::MONEY_ROUTE]) { |
167 | 174 | if (isset(self::$moneyRoutes[$overallMultiplier])) { |
168 | 175 | $rl =& self::$moneyRoutes[$overallMultiplier]; |
169 | - } |
|
170 | - else { |
|
176 | + } else { |
|
171 | 177 | $rl = array(); |
172 | 178 | } |
173 | 179 | $rl[] =& $r; |
@@ -181,15 +187,14 @@ discard block |
||
181 | 187 | foreach(self::$expRoutes as $multi => &$routesByMulti) { |
182 | 188 | if(count($routesByMulti)+$i < $trimToBestXRoutes) { |
183 | 189 | $i += count($routesByMulti); |
184 | - } |
|
185 | - else if($i > $trimToBestXRoutes) { |
|
190 | + } else if($i > $trimToBestXRoutes) { |
|
186 | 191 | unset(self::$expRoutes[$multi]); |
187 | - } |
|
188 | - else { |
|
192 | + } else { |
|
189 | 193 | foreach($routesByMulti as $key => &$value) { |
190 | 194 | $i++; |
191 | - if($i < $trimToBestXRoutes) |
|
192 | - continue; |
|
195 | + if($i < $trimToBestXRoutes) { |
|
196 | + continue; |
|
197 | + } |
|
193 | 198 | if($i === $trimToBestXRoutes) { |
194 | 199 | self::$dontAddWorseThan[self::EXP_ROUTE] = $multi; |
195 | 200 | continue; |
@@ -204,16 +209,15 @@ discard block |
||
204 | 209 | foreach(self::$moneyRoutes as $multi => &$routesByMulti) { |
205 | 210 | if(count($routesByMulti)+$i < $trimToBestXRoutes) { |
206 | 211 | $i += count($routesByMulti); |
207 | - } |
|
208 | - else if($i > $trimToBestXRoutes) { |
|
212 | + } else if($i > $trimToBestXRoutes) { |
|
209 | 213 | unset(self::$moneyRoutes[$multi]); |
210 | 214 | continue; |
211 | - } |
|
212 | - else { |
|
215 | + } else { |
|
213 | 216 | foreach($routesByMulti as $key => &$value) { |
214 | 217 | $i++; |
215 | - if($i < $trimToBestXRoutes) |
|
216 | - continue; |
|
218 | + if($i < $trimToBestXRoutes) { |
|
219 | + continue; |
|
220 | + } |
|
217 | 221 | if($i === $trimToBestXRoutes) { |
218 | 222 | self::$dontAddWorseThan[self::MONEY_ROUTE] = $multi; |
219 | 223 | continue; |
@@ -377,18 +381,21 @@ discard block |
||
377 | 381 | } |
378 | 382 | |
379 | 383 | public function getTurnsForRoute() { |
380 | - if ($this->goodId === GOOD_NOTHING) |
|
381 | - $tradeTurns = 0; |
|
382 | - else |
|
383 | - $tradeTurns = 2 * TURNS_PER_TRADE; |
|
384 | + if ($this->goodId === GOOD_NOTHING) { |
|
385 | + $tradeTurns = 0; |
|
386 | + } else { |
|
387 | + $tradeTurns = 2 * TURNS_PER_TRADE; |
|
388 | + } |
|
384 | 389 | return $this->distance->getTurns() + $tradeTurns; |
385 | 390 | } |
386 | 391 | |
387 | 392 | public function compareTo(OneWayRoute &$compare) { |
388 | - if ($this->equals($compare)===true) |
|
389 | - return 0; |
|
390 | - if ($this->getOverallExpMultiplier() > $compare->getOverallExpMultiplier()) |
|
391 | - return 1; |
|
393 | + if ($this->equals($compare)===true) { |
|
394 | + return 0; |
|
395 | + } |
|
396 | + if ($this->getOverallExpMultiplier() > $compare->getOverallExpMultiplier()) { |
|
397 | + return 1; |
|
398 | + } |
|
392 | 399 | return -1; |
393 | 400 | } |
394 | 401 |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | JOIN chess_game ON account_id = black_id OR account_id = white_id |
33 | 33 | WHERE end_time > ' . TIME . ' OR end_time IS NULL;'); |
34 | 34 | $games = array(); |
35 | - while($db->nextRecord()) { |
|
35 | + while ($db->nextRecord()) { |
|
36 | 36 | $game = self::getChessGame($db->getInt('chess_game_id'), $forceUpdate); |
37 | - if($game->getCurrentTurnAccount()->isNPC()) { |
|
37 | + if ($game->getCurrentTurnAccount()->isNPC()) { |
|
38 | 38 | $games[] = $game; |
39 | 39 | } |
40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $db = new SmrMySqlDatabase(); |
46 | 46 | $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);'); |
47 | 47 | $games = array(); |
48 | - while($db->nextRecord()) { |
|
48 | + while ($db->nextRecord()) { |
|
49 | 49 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
50 | 50 | } |
51 | 51 | return $games; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | $db = new SmrMySqlDatabase(); |
56 | 56 | $db->query('SELECT chess_game_id FROM chess_game WHERE black_id = ' . $db->escapeNumber($accountID) . ' OR white_id = ' . $db->escapeNumber($accountID) . ';'); |
57 | 57 | $games = array(); |
58 | - while($db->nextRecord()) { |
|
58 | + while ($db->nextRecord()) { |
|
59 | 59 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
60 | 60 | } |
61 | 61 | return $games; |
62 | 62 | } |
63 | 63 | |
64 | - public static function &getChessGame($chessGameID,$forceUpdate = false) { |
|
65 | - if($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
64 | + public static function &getChessGame($chessGameID, $forceUpdate = false) { |
|
65 | + if ($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
66 | 66 | self::$CACHE_CHESS_GAMES[$chessGameID] = new ChessGame($chessGameID); |
67 | 67 | } |
68 | 68 | return self::$CACHE_CHESS_GAMES[$chessGameID]; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $this->db->query('SELECT * |
74 | 74 | FROM chess_game |
75 | 75 | WHERE chess_game_id=' . $this->db->escapeNumber($chessGameID) . ' LIMIT 1;'); |
76 | - if($this->db->nextRecord()) { |
|
76 | + if ($this->db->nextRecord()) { |
|
77 | 77 | $this->chessGameID = $chessGameID; |
78 | 78 | $this->gameID = $this->db->getInt('game_id'); |
79 | 79 | $this->startDate = $this->db->getInt('start_time'); |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function isPlayerChecked(array &$board, array &$hasMoved, $colour) { |
96 | - foreach($board as &$row) { |
|
97 | - foreach($row as &$p) { |
|
98 | - if($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
96 | + foreach ($board as &$row) { |
|
97 | + foreach ($row as &$p) { |
|
98 | + if ($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | 'King' => false |
120 | 120 | ) |
121 | 121 | ), |
122 | - ChessPiece::PAWN => array(-1,-1) |
|
122 | + ChessPiece::PAWN => array(-1, -1) |
|
123 | 123 | ); |
124 | 124 | } |
125 | 125 | |
@@ -142,17 +142,17 @@ discard block |
||
142 | 142 | $this->resetHasMoved(); |
143 | 143 | |
144 | 144 | try { |
145 | - while($db->nextRecord()) { |
|
146 | - if($debugInfo === true) { |
|
145 | + while ($db->nextRecord()) { |
|
146 | + if ($debugInfo === true) { |
|
147 | 147 | 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; |
148 | 148 | } |
149 | - 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())) { |
|
149 | + 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 | 150 | break; |
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
154 | - catch(Exception $e) { |
|
155 | - if($debugInfo === true) { |
|
154 | + catch (Exception $e) { |
|
155 | + if ($debugInfo === true) { |
|
156 | 156 | echo $e->getMessage() . EOL . $e->getTraceAsString() . EOL; |
157 | 157 | } |
158 | 158 | // We probably tried an invalid move - move on. |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | public function getBoard() { |
163 | - if($this->board == null) { |
|
163 | + if ($this->board == null) { |
|
164 | 164 | $this->db->query('SELECT * FROM chess_game_pieces WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ';'); |
165 | 165 | $pieces = array(); |
166 | - while($this->db->nextRecord()) { |
|
166 | + while ($this->db->nextRecord()) { |
|
167 | 167 | $accountID = $this->db->getInt('account_id'); |
168 | 168 | $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')); |
169 | 169 | } |
170 | - $this->board =& $this->parsePieces($pieces); |
|
170 | + $this->board = & $this->parsePieces($pieces); |
|
171 | 171 | } |
172 | 172 | return $this->board; |
173 | 173 | } |
@@ -178,20 +178,20 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | public function getMoves() { |
181 | - if($this->moves == null) { |
|
181 | + if ($this->moves == null) { |
|
182 | 182 | $this->db->query('SELECT * FROM chess_game_moves WHERE chess_game_id = ' . $this->db->escapeNumber($this->chessGameID) . ' ORDER BY move_id;'); |
183 | 183 | $this->moves = array(); |
184 | 184 | $mate = false; |
185 | - while($this->db->nextRecord()) { |
|
185 | + while ($this->db->nextRecord()) { |
|
186 | 186 | $pieceTakenID = $this->db->getField('piece_taken') == null ? null : $this->db->getInt('piece_taken'); |
187 | 187 | $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')); |
188 | 188 | $mate = $this->db->getField('checked') == 'MATE'; |
189 | 189 | } |
190 | - if(!$mate && $this->hasEnded()) { |
|
191 | - if($this->getWinner() != 0) { |
|
190 | + if (!$mate && $this->hasEnded()) { |
|
191 | + if ($this->getWinner() != 0) { |
|
192 | 192 | $this->moves[] = ($this->getWinner() == $this->getWhiteID() ? 'Black' : 'White') . ' Resigned.'; |
193 | 193 | } |
194 | - else if(count($this->moves) < 2) { |
|
194 | + else if (count($this->moves) < 2) { |
|
195 | 195 | $this->moves[] = 'Game Cancelled.'; |
196 | 196 | } |
197 | 197 | else { |
@@ -204,30 +204,30 @@ discard block |
||
204 | 204 | |
205 | 205 | public function getFENString() { |
206 | 206 | $fen = ''; |
207 | - $board =& $this->getBoard(); |
|
207 | + $board = & $this->getBoard(); |
|
208 | 208 | $blanks = 0; |
209 | - for($y=0; $y < 8; $y++) { |
|
210 | - if($y > 0) { |
|
209 | + for ($y = 0; $y < 8; $y++) { |
|
210 | + if ($y > 0) { |
|
211 | 211 | $fen .= '/'; |
212 | 212 | } |
213 | - for($x=0; $x < 8; $x++) { |
|
214 | - if($board[$y][$x] == null) { |
|
213 | + for ($x = 0; $x < 8; $x++) { |
|
214 | + if ($board[$y][$x] == null) { |
|
215 | 215 | $blanks++; |
216 | 216 | } |
217 | 217 | else { |
218 | - if($blanks > 0) { |
|
218 | + if ($blanks > 0) { |
|
219 | 219 | $fen .= $blanks; |
220 | 220 | $blanks = 0; |
221 | 221 | } |
222 | 222 | $fen .= $board[$y][$x]->getPieceLetter(); |
223 | 223 | } |
224 | 224 | } |
225 | - if($blanks > 0) { |
|
225 | + if ($blanks > 0) { |
|
226 | 226 | $fen .= $blanks; |
227 | 227 | $blanks = 0; |
228 | 228 | } |
229 | 229 | } |
230 | - switch($this->getCurrentTurnColour()) { |
|
230 | + switch ($this->getCurrentTurnColour()) { |
|
231 | 231 | case self::PLAYER_WHITE: |
232 | 232 | $fen .= ' w '; |
233 | 233 | break; |
@@ -238,30 +238,30 @@ discard block |
||
238 | 238 | |
239 | 239 | // Castling |
240 | 240 | $castling = ''; |
241 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
242 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
241 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
242 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
243 | 243 | $castling .= 'K'; |
244 | 244 | } |
245 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
245 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
246 | 246 | $castling .= 'Q'; |
247 | 247 | } |
248 | 248 | } |
249 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
250 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
249 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
250 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
251 | 251 | $castling .= 'k'; |
252 | 252 | } |
253 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
253 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
254 | 254 | $castling .= 'q'; |
255 | 255 | } |
256 | 256 | } |
257 | - if($castling == '') { |
|
257 | + if ($castling == '') { |
|
258 | 258 | $castling = '-'; |
259 | 259 | } |
260 | 260 | $fen .= $castling . ' '; |
261 | 261 | |
262 | - if($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
262 | + if ($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
263 | 263 | $fen .= chr(ord('a') + $this->hasMoved[ChessPiece::PAWN][0]); |
264 | - switch($this->hasMoved[ChessPiece::PAWN][1]) { |
|
264 | + switch ($this->hasMoved[ChessPiece::PAWN][1]) { |
|
265 | 265 | case 3: |
266 | 266 | $fen .= '6'; |
267 | 267 | break; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | else { |
274 | 274 | $fen .= '-'; |
275 | 275 | } |
276 | - $fen .= ' 0 ' . floor(count($this->moves)/2); |
|
276 | + $fen .= ' 0 ' . floor(count($this->moves) / 2); |
|
277 | 277 | |
278 | 278 | return $fen; |
279 | 279 | } |
@@ -281,17 +281,17 @@ discard block |
||
281 | 281 | public static function &parsePieces(array &$pieces) { |
282 | 282 | $board = array(); |
283 | 283 | $row = array(); |
284 | - for($i=0;$i<8;$i++) { |
|
284 | + for ($i = 0; $i < 8; $i++) { |
|
285 | 285 | $row[] = null; |
286 | 286 | } |
287 | - for($i=0;$i<8;$i++) { |
|
287 | + for ($i = 0; $i < 8; $i++) { |
|
288 | 288 | $board[] = $row; |
289 | 289 | } |
290 | - foreach($pieces as &$piece) { |
|
291 | - if($board[$piece->getY()][$piece->getX()] != null) { |
|
290 | + foreach ($pieces as &$piece) { |
|
291 | + if ($board[$piece->getY()][$piece->getX()] != null) { |
|
292 | 292 | throw new Exception('Two pieces found in the same tile.'); |
293 | 293 | } |
294 | - $board[$piece->getY()][$piece->getX()] =& $piece; |
|
294 | + $board[$piece->getY()][$piece->getX()] = & $piece; |
|
295 | 295 | } |
296 | 296 | return $board; |
297 | 297 | } |
@@ -299,8 +299,7 @@ discard block |
||
299 | 299 | public static function getStandardGame($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
300 | 300 | $white = $whitePlayer->getAccountID(); |
301 | 301 | $black = $blackPlayer->getAccountID(); |
302 | - return array |
|
303 | - ( |
|
302 | + return array( |
|
304 | 303 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::ROOK, 0, 0), |
305 | 304 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::KNIGHT, 1, 0), |
306 | 305 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::BISHOP, 2, 0), |
@@ -340,7 +339,7 @@ discard block |
||
340 | 339 | } |
341 | 340 | |
342 | 341 | public static function insertNewGame($startDate, $endDate, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
343 | - if($startDate == null) { |
|
342 | + if ($startDate == null) { |
|
344 | 343 | throw new Exception('Start date cannot be null.'); |
345 | 344 | } |
346 | 345 | |
@@ -358,7 +357,7 @@ discard block |
||
358 | 357 | private static function insertPieces($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
359 | 358 | $db = new SmrMySqlDatabase(); |
360 | 359 | $pieces = self::getStandardGame($chessGameID, $whitePlayer, $blackPlayer); |
361 | - foreach($pieces as $p) { |
|
360 | + foreach ($pieces as $p) { |
|
362 | 361 | $db->query('INSERT INTO chess_game_pieces' . |
363 | 362 | '(chess_game_id,account_id,piece_id,x,y)' . |
364 | 363 | 'values' . |
@@ -370,65 +369,65 @@ discard block |
||
370 | 369 | // This move will be set as the most recent move |
371 | 370 | $this->lastMove = [ |
372 | 371 | 'From' => ['X' => $startX, 'Y' => $startY], |
373 | - 'To' => ['X' => $endX, 'Y' => $endY], |
|
372 | + 'To' => ['X' => $endX, 'Y' => $endY], |
|
374 | 373 | ]; |
375 | 374 | |
376 | 375 | $otherPlayerColour = self::getOtherColour($playerColour); |
377 | - if($pieceID == ChessPiece::KING) { |
|
376 | + if ($pieceID == ChessPiece::KING) { |
|
378 | 377 | $this->hasMoved[$playerColour][ChessPiece::KING] = true; |
379 | 378 | } |
380 | 379 | // Check if the piece moving is a rook and mark it as moved to stop castling. |
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; |
|
380 | + if ($pieceID == ChessPiece::ROOK && ($startX == 0 || $startX == 7) && ($startY == ($playerColour == self::PLAYER_WHITE ? 7 : 0))) { |
|
381 | + $this->hasMoved[$playerColour][ChessPiece::ROOK][$startX == 0 ? 'Queen' : 'King'] = true; |
|
383 | 382 | } |
384 | 383 | // 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. |
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; |
|
384 | + if ($pieceTaken == ChessPiece::ROOK && ($endX == 0 || $endX == 7) && $endY == ($otherPlayerColour == self::PLAYER_WHITE ? 7 : 0)) { |
|
385 | + $this->hasMoved[$otherPlayerColour][ChessPiece::ROOK][$endX == 0 ? 'Queen' : 'King'] = true; |
|
387 | 386 | } |
388 | - if($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
387 | + if ($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
389 | 388 | $this->hasMoved[ChessPiece::PAWN] = array($endX, $endY); |
390 | 389 | } |
391 | 390 | else { |
392 | - $this->hasMoved[ChessPiece::PAWN] = array(-1,-1); |
|
391 | + $this->hasMoved[ChessPiece::PAWN] = array(-1, -1); |
|
393 | 392 | } |
394 | 393 | return ($castling == 'Queen' ? '0-0-0' : ($castling == 'King' ? '0-0' : '')) |
395 | 394 | . ChessPiece::getSymbolForPiece($pieceID, $playerColour) |
396 | - . chr(ord('a')+$startX) |
|
397 | - . (8-$startY) |
|
395 | + . chr(ord('a') + $startX) |
|
396 | + . (8 - $startY) |
|
398 | 397 | . ' ' |
399 | 398 | . ($pieceTaken == null ? '' : ChessPiece::getSymbolForPiece($pieceTaken, $otherPlayerColour)) |
400 | - . chr(ord('a')+$endX) |
|
401 | - . (8-$endY) |
|
399 | + . chr(ord('a') + $endX) |
|
400 | + . (8 - $endY) |
|
402 | 401 | . ($promotionPieceID == null ? '' : ChessPiece::getSymbolForPiece($promotionPieceID, $playerColour)) |
403 | 402 | . ' ' |
404 | - . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++') ) |
|
403 | + . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++')) |
|
405 | 404 | . ($enPassant ? ' e.p.' : ''); |
406 | 405 | } |
407 | 406 | |
408 | 407 | public function isCheckmated($colour) { |
409 | - $board =& $this->board; |
|
410 | - $hasMoved =& $this->getHasMoved(); |
|
408 | + $board = & $this->board; |
|
409 | + $hasMoved = & $this->getHasMoved(); |
|
411 | 410 | $king = null; |
412 | - foreach($board as $row) { |
|
413 | - foreach($row as $piece) { |
|
414 | - if($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
411 | + foreach ($board as $row) { |
|
412 | + foreach ($row as $piece) { |
|
413 | + if ($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
415 | 414 | $king = $piece; |
416 | 415 | break; |
417 | 416 | } |
418 | 417 | } |
419 | 418 | } |
420 | - if($king == null) { |
|
419 | + if ($king == null) { |
|
421 | 420 | throw new Exception('Could not find the king: game id = ' . $this->chessGameID); |
422 | 421 | } |
423 | - if(!self::isPlayerChecked($board, $hasMoved, $colour)) { |
|
422 | + if (!self::isPlayerChecked($board, $hasMoved, $colour)) { |
|
424 | 423 | return false; |
425 | 424 | } |
426 | - foreach($board as $row) { |
|
427 | - foreach($row as $piece) { |
|
428 | - if($piece != null && $piece->colour == $colour) { |
|
425 | + foreach ($board as $row) { |
|
426 | + foreach ($row as $piece) { |
|
427 | + if ($piece != null && $piece->colour == $colour) { |
|
429 | 428 | $moves = $piece->getPossibleMoves($board, $hasMoved); |
430 | 429 | //There are moves we can make, we are clearly not checkmated. |
431 | - if(count($moves) > 0) { |
|
430 | + if (count($moves) > 0) { |
|
432 | 431 | return false; |
433 | 432 | } |
434 | 433 | } |
@@ -439,15 +438,15 @@ discard block |
||
439 | 438 | |
440 | 439 | public static function isCastling($x, $toX) { |
441 | 440 | $movement = $toX - $x; |
442 | - if(abs($movement) == 2) { |
|
441 | + if (abs($movement) == 2) { |
|
443 | 442 | //To the left. |
444 | - if($movement == -2) { |
|
443 | + if ($movement == -2) { |
|
445 | 444 | return array('Type' => 'Queen', |
446 | 445 | 'X' => 0, |
447 | 446 | 'ToX' => 3 |
448 | 447 | ); |
449 | 448 | } //To the right |
450 | - else if($movement == 2) { |
|
449 | + else if ($movement == 2) { |
|
451 | 450 | return array('Type' => 'King', |
452 | 451 | 'X' => 7, |
453 | 452 | 'ToX' => 5 |
@@ -458,36 +457,36 @@ discard block |
||
458 | 457 | } |
459 | 458 | |
460 | 459 | public static function movePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $pawnPromotionPiece = ChessPiece::QUEEN) { |
461 | - if(!self::isValidCoord($x, $y, $board)) { |
|
460 | + if (!self::isValidCoord($x, $y, $board)) { |
|
462 | 461 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
463 | 462 | } |
464 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
463 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
465 | 464 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
466 | 465 | } |
467 | 466 | $pieceTaken = $board[$toY][$toX]; |
468 | 467 | $board[$toY][$toX] = $board[$y][$x]; |
469 | - $p =& $board[$toY][$toX]; |
|
468 | + $p = & $board[$toY][$toX]; |
|
470 | 469 | $board[$y][$x] = null; |
471 | - if($p == null) { |
|
470 | + if ($p == null) { |
|
472 | 471 | throw new Exception('Trying to move non-existent piece: ' . var_export($board, true)); |
473 | 472 | } |
474 | 473 | $p->setX($toX); |
475 | 474 | $p->setY($toY); |
476 | 475 | |
477 | 476 | $oldPawnMovement = $hasMoved[ChessPiece::PAWN]; |
478 | - $nextPawnMovement = array(-1,-1); |
|
477 | + $nextPawnMovement = array(-1, -1); |
|
479 | 478 | $castling = false; |
480 | 479 | $enPassant = false; |
481 | 480 | $rookMoved = false; |
482 | 481 | $rookTaken = false; |
483 | 482 | $pawnPromotion = false; |
484 | - if($p->pieceID == ChessPiece::KING) { |
|
483 | + if ($p->pieceID == ChessPiece::KING) { |
|
485 | 484 | //Castling? |
486 | 485 | $castling = self::isCastling($x, $toX); |
487 | - if($castling !== false) { |
|
486 | + if ($castling !== false) { |
|
488 | 487 | $hasMoved[$p->colour][ChessPiece::KING] = true; |
489 | 488 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = true; |
490 | - if($board[$y][$castling['X']] == null) { |
|
489 | + if ($board[$y][$castling['X']] == null) { |
|
491 | 490 | throw new Exception('Cannot castle with non-existent castle.'); |
492 | 491 | } |
493 | 492 | $board[$toY][$castling['ToX']] = $board[$y][$castling['X']]; |
@@ -495,37 +494,37 @@ discard block |
||
495 | 494 | $board[$y][$castling['X']] = null; |
496 | 495 | } |
497 | 496 | } |
498 | - else if($p->pieceID == ChessPiece::PAWN) { |
|
499 | - if($toY == 0 || $toY == 7) { |
|
497 | + else if ($p->pieceID == ChessPiece::PAWN) { |
|
498 | + if ($toY == 0 || $toY == 7) { |
|
500 | 499 | $pawnPromotion = $p->promote($pawnPromotionPiece, $board); |
501 | 500 | } |
502 | 501 | //Double move to track? |
503 | - else if(($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
502 | + else if (($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
504 | 503 | $nextPawnMovement = array($toX, $toY); |
505 | 504 | } |
506 | 505 | //En passant? |
507 | - else if($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
506 | + else if ($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
508 | 507 | ($hasMoved[ChessPiece::PAWN][1] == 3 && $toY == 2 || $hasMoved[ChessPiece::PAWN][1] == 4 && $toY == 5)) { |
509 | 508 | $enPassant = true; |
510 | 509 | $pieceTaken = $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]]; |
511 | - if($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
510 | + if ($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
512 | 511 | throw new Exception('Cannot en passant a non-existent pawn.'); |
513 | 512 | } |
514 | 513 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = null; |
515 | 514 | } |
516 | 515 | } |
517 | - else if($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
516 | + else if ($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
518 | 517 | //Rook moved? |
519 | - if($hasMoved[$p->colour][ChessPiece::ROOK][$x==0?'Queen':'King'] === false) { |
|
518 | + if ($hasMoved[$p->colour][ChessPiece::ROOK][$x == 0 ? 'Queen' : 'King'] === false) { |
|
520 | 519 | // We set rook moved in here as it's used for move info. |
521 | - $rookMoved = $x==0?'Queen':'King'; |
|
520 | + $rookMoved = $x == 0 ? 'Queen' : 'King'; |
|
522 | 521 | $hasMoved[$p->colour][ChessPiece::ROOK][$rookMoved] = true; |
523 | 522 | } |
524 | 523 | } |
525 | 524 | // 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. |
526 | - if($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
527 | - if($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX==0?'Queen':'King'] === false) { |
|
528 | - $rookTaken = $toX==0?'Queen':'King'; |
|
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'; |
|
529 | 528 | $hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$rookTaken] = true; |
530 | 529 | } |
531 | 530 | } |
@@ -542,18 +541,18 @@ discard block |
||
542 | 541 | } |
543 | 542 | |
544 | 543 | public static function undoMovePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $moveInfo) { |
545 | - if(!self::isValidCoord($x, $y, $board)) { |
|
544 | + if (!self::isValidCoord($x, $y, $board)) { |
|
546 | 545 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
547 | 546 | } |
548 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
547 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
549 | 548 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
550 | 549 | } |
551 | - if($board[$y][$x] != null) { |
|
550 | + if ($board[$y][$x] != null) { |
|
552 | 551 | throw new Exception('Undoing move onto another piece? x=' . $x . ', y=' . $y); |
553 | 552 | } |
554 | 553 | $board[$y][$x] = $board[$toY][$toX]; |
555 | - $p =& $board[$y][$x]; |
|
556 | - if($p == null) { |
|
554 | + $p = & $board[$y][$x]; |
|
555 | + if ($p == null) { |
|
557 | 556 | throw new Exception('Trying to undo move of a non-existent piece: ' . var_export($board, true)); |
558 | 557 | } |
559 | 558 | $board[$toY][$toX] = $moveInfo['PieceTaken']; |
@@ -562,12 +561,12 @@ discard block |
||
562 | 561 | |
563 | 562 | $hasMoved[ChessPiece::PAWN] = $moveInfo['OldPawnMovement']; |
564 | 563 | //Castling |
565 | - if($p->pieceID == ChessPiece::KING) { |
|
564 | + if ($p->pieceID == ChessPiece::KING) { |
|
566 | 565 | $castling = self::isCastling($x, $toX); |
567 | - if($castling !== false) { |
|
566 | + if ($castling !== false) { |
|
568 | 567 | $hasMoved[$p->colour][ChessPiece::KING] = false; |
569 | 568 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = false; |
570 | - if($board[$toY][$castling['ToX']] == null) { |
|
569 | + if ($board[$toY][$castling['ToX']] == null) { |
|
571 | 570 | throw new Exception('Cannot undo castle with non-existent castle.'); |
572 | 571 | } |
573 | 572 | $board[$y][$castling['X']] = $board[$toY][$castling['ToX']]; |
@@ -575,25 +574,25 @@ discard block |
||
575 | 574 | $board[$toY][$castling['ToX']] = null; |
576 | 575 | } |
577 | 576 | } |
578 | - else if($moveInfo['EnPassant'] === true) { |
|
577 | + else if ($moveInfo['EnPassant'] === true) { |
|
579 | 578 | $board[$toY][$toX] = null; |
580 | 579 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = $moveInfo['PieceTaken']; |
581 | 580 | } |
582 | - else if($moveInfo['RookMoved'] !== false) { |
|
581 | + else if ($moveInfo['RookMoved'] !== false) { |
|
583 | 582 | $hasMoved[$p->colour][ChessPiece::ROOK][$moveInfo['RookMoved']] = false; |
584 | 583 | } |
585 | - if($moveInfo['RookTaken'] !== false) { |
|
584 | + if ($moveInfo['RookTaken'] !== false) { |
|
586 | 585 | $hasMoved[$moveInfo['PieceTaken']->colour][ChessPiece::ROOK][$moveInfo['RookTaken']] = false; |
587 | 586 | } |
588 | 587 | } |
589 | 588 | |
590 | 589 | public function tryAlgebraicMove($move) { |
591 | - if(strlen($move) != 4 && strlen($move) != 5) { |
|
590 | + if (strlen($move) != 4 && strlen($move) != 5) { |
|
592 | 591 | throw new Exception('Move of length "' . strlen($move) . '" is not valid, full move: ' . $move); |
593 | 592 | } |
594 | 593 | $aVal = ord('a'); |
595 | 594 | $hVal = ord('h'); |
596 | - if(ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
595 | + if (ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
597 | 596 | || ord($move[0]) > $hVal || ord($move[2]) > $hVal |
598 | 597 | || $move[1] < 1 || $move[3] < 1 |
599 | 598 | || $move[1] > 8 || $move[3] > 8) { |
@@ -604,73 +603,73 @@ discard block |
||
604 | 603 | $toX = ord($move[2]) - $aVal; |
605 | 604 | $toY = 8 - $move[3]; |
606 | 605 | $pawnPromotionPiece = null; |
607 | - if(isset($move[4])) { |
|
606 | + if (isset($move[4])) { |
|
608 | 607 | $pawnPromotionPiece = ChessPiece::getPieceForLetter($move[4]); |
609 | 608 | } |
610 | 609 | return $this->tryMove($x, $y, $toX, $toY, $this->getCurrentTurnAccountID(), $pawnPromotionPiece); |
611 | 610 | } |
612 | 611 | |
613 | 612 | public function tryMove($x, $y, $toX, $toY, $forAccountID, $pawnPromotionPiece) { |
614 | - if($this->hasEnded()) { |
|
613 | + if ($this->hasEnded()) { |
|
615 | 614 | return 5; |
616 | 615 | } |
617 | - if($this->getCurrentTurnAccountID() != $forAccountID) { |
|
616 | + if ($this->getCurrentTurnAccountID() != $forAccountID) { |
|
618 | 617 | return 4; |
619 | 618 | } |
620 | 619 | $lastTurnPlayer = $this->getCurrentTurnPlayer(); |
621 | 620 | $this->getBoard(); |
622 | 621 | $p = $this->board[$y][$x]; |
623 | - if($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
622 | + if ($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
624 | 623 | return 2; |
625 | 624 | } |
626 | 625 | |
627 | 626 | $moves = $p->getPossibleMoves($this->board, $this->getHasMoved(), $forAccountID); |
628 | - foreach($moves as $move) { |
|
629 | - if($move[0]==$toX && $move[1]==$toY) { |
|
627 | + foreach ($moves as $move) { |
|
628 | + if ($move[0] == $toX && $move[1] == $toY) { |
|
630 | 629 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
631 | 630 | $currentPlayer = $this->getCurrentTurnPlayer(); |
632 | 631 | |
633 | 632 | $moveInfo = ChessGame::movePiece($this->board, $this->getHasMoved(), $x, $y, $toX, $toY, $pawnPromotionPiece); |
634 | 633 | |
635 | 634 | //We have taken the move, we should refresh $p |
636 | - $p =& $this->board[$toY][$toX]; |
|
635 | + $p = & $this->board[$toY][$toX]; |
|
637 | 636 | |
638 | 637 | $pieceTakenID = null; |
639 | - if($moveInfo['PieceTaken'] != null) { |
|
638 | + if ($moveInfo['PieceTaken'] != null) { |
|
640 | 639 | $pieceTakenID = $moveInfo['PieceTaken']->pieceID; |
641 | - if($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
640 | + if ($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
642 | 641 | throw new Exception('King was taken.'); |
643 | 642 | } |
644 | 643 | } |
645 | 644 | |
646 | 645 | $pieceID = $p->pieceID; |
647 | 646 | $pieceNo = $p->pieceNo; |
648 | - if($moveInfo['PawnPromotion'] !== false) { |
|
647 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
649 | 648 | $p->pieceID = $moveInfo['PawnPromotion']['PieceID']; |
650 | 649 | $p->pieceNo = $moveInfo['PawnPromotion']['PieceNo']; |
651 | 650 | } |
652 | 651 | |
653 | 652 | $checking = null; |
654 | - if($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
653 | + if ($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
655 | 654 | $checking = 'CHECK'; |
656 | 655 | } |
657 | - if($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
656 | + if ($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
658 | 657 | $checking = 'MATE'; |
659 | 658 | } |
660 | - if($this->moves!=null) { |
|
659 | + if ($this->moves != null) { |
|
661 | 660 | $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']); |
662 | 661 | } |
663 | - if(self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
662 | + if (self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
664 | 663 | return 3; |
665 | 664 | } |
666 | 665 | |
667 | 666 | $otherPlayer = $this->getCurrentTurnPlayer(); |
668 | - if($moveInfo['PawnPromotion'] !== false) { |
|
667 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
669 | 668 | $piecePromotedSymbol = $p->getPieceSymbol(); |
670 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted','Total'), HOF_PUBLIC); |
|
671 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted','Total'), HOF_PUBLIC); |
|
672 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
673 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
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); |
|
674 | 673 | } |
675 | 674 | $this->db->query('INSERT INTO chess_game_moves |
676 | 675 | (chess_game_id,piece_id,start_x,start_y,end_x,end_y,checked,piece_taken,castling,en_passant,promote_piece_id) |
@@ -678,37 +677,37 @@ discard block |
||
678 | 677 | (' . $this->db->escapeNumber($p->chessGameID) . ',' . $this->db->escapeNumber($pieceID) . ',' . $this->db->escapeNumber($x) . ',' . $this->db->escapeNumber($y) . ',' . $this->db->escapeNumber($toX) . ',' . $this->db->escapeNumber($toY) . ',' . $this->db->escapeString($checking, true, true) . ',' . ($moveInfo['PieceTaken'] == null ? 'NULL' : $this->db->escapeNumber($moveInfo['PieceTaken']->pieceID)) . ',' . $this->db->escapeString($moveInfo['Castling']['Type'], true, true) . ',' . $this->db->escapeBoolean($moveInfo['EnPassant']) . ',' . ($moveInfo['PawnPromotion'] == false ? 'NULL' : $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID'])) . ');'); |
679 | 678 | |
680 | 679 | |
681 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Total Taken'), HOF_PUBLIC); |
|
682 | - if($moveInfo['PieceTaken'] != null) { |
|
680 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Total Taken'), HOF_PUBLIC); |
|
681 | + if ($moveInfo['PieceTaken'] != null) { |
|
683 | 682 | $this->db->query('DELETE FROM chess_game_pieces |
684 | 683 | 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) . ';'); |
685 | 684 | |
686 | 685 | $pieceTakenSymbol = $moveInfo['PieceTaken']->getPieceSymbol(); |
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); |
|
686 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', 'Total'), HOF_PUBLIC); |
|
687 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', 'Total'), HOF_PUBLIC); |
|
688 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
689 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
691 | 690 | } |
692 | 691 | $this->db->query('UPDATE chess_game_pieces |
693 | 692 | SET x=' . $this->db->escapeNumber($toX) . ', y=' . $this->db->escapeNumber($toY) . |
694 | 693 | ($moveInfo['PawnPromotion'] !== false ? ', piece_id=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID']) . ', piece_no=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceNo']) : '') . ' |
695 | 694 | 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) . ';'); |
696 | - if($moveInfo['Castling'] !== false) { |
|
695 | + if ($moveInfo['Castling'] !== false) { |
|
697 | 696 | $this->db->query('UPDATE chess_game_pieces |
698 | 697 | SET x=' . $this->db->escapeNumber($moveInfo['Castling']['ToX']) . ' |
699 | 698 | 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) . ';'); |
700 | 699 | } |
701 | 700 | $return = 0; |
702 | - if($checking == 'MATE') { |
|
701 | + if ($checking == 'MATE') { |
|
703 | 702 | $this->setWinner($forAccountID); |
704 | 703 | $return = 1; |
705 | 704 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'You have just lost [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
706 | 705 | } |
707 | 706 | else { |
708 | 707 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'It is now your turn in [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
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); |
|
708 | + if ($checking == 'CHECK') { |
|
709 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Given'), HOF_PUBLIC); |
|
710 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Received'), HOF_PUBLIC); |
|
712 | 711 | } |
713 | 712 | } |
714 | 713 | $currentPlayer->saveHOF(); |
@@ -747,10 +746,10 @@ discard block |
||
747 | 746 | } |
748 | 747 | |
749 | 748 | public function getColourID($colour) { |
750 | - if($colour == self::PLAYER_WHITE) { |
|
749 | + if ($colour == self::PLAYER_WHITE) { |
|
751 | 750 | return $this->getWhiteID(); |
752 | 751 | } |
753 | - if($colour == self::PLAYER_BLACK) { |
|
752 | + if ($colour == self::PLAYER_BLACK) { |
|
754 | 753 | return $this->getBlackID(); |
755 | 754 | } |
756 | 755 | } |
@@ -760,10 +759,10 @@ discard block |
||
760 | 759 | } |
761 | 760 | |
762 | 761 | public function getColourForAccountID($accountID) { |
763 | - if($accountID == $this->getWhiteID()) { |
|
762 | + if ($accountID == $this->getWhiteID()) { |
|
764 | 763 | return self::PLAYER_WHITE; |
765 | 764 | } |
766 | - if($accountID == $this->getBlackID()) { |
|
765 | + if ($accountID == $this->getBlackID()) { |
|
767 | 766 | return self::PLAYER_BLACK; |
768 | 767 | } |
769 | 768 | return false; |
@@ -791,8 +790,8 @@ discard block |
||
791 | 790 | $winningPlayer = $this->getColourPlayer($winnerColour); |
792 | 791 | $losingPlayer = $this->getColourPlayer(self::getOtherColour($winnerColour)); |
793 | 792 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
794 | - $winningPlayer->increaseHOF(1, array($chessType,'Games','Won'), HOF_PUBLIC); |
|
795 | - $losingPlayer->increaseHOF(1, array($chessType,'Games','Lost'), HOF_PUBLIC); |
|
793 | + $winningPlayer->increaseHOF(1, array($chessType, 'Games', 'Won'), HOF_PUBLIC); |
|
794 | + $losingPlayer->increaseHOF(1, array($chessType, 'Games', 'Lost'), HOF_PUBLIC); |
|
796 | 795 | return array('Winner' => $winningPlayer, 'Loser' => $losingPlayer); |
797 | 796 | } |
798 | 797 | |
@@ -833,21 +832,21 @@ discard block |
||
833 | 832 | } |
834 | 833 | |
835 | 834 | public static function getOtherColour($colour) { |
836 | - if($colour == self::PLAYER_WHITE) { |
|
835 | + if ($colour == self::PLAYER_WHITE) { |
|
837 | 836 | return self::PLAYER_BLACK; |
838 | 837 | } |
839 | - if($colour == self::PLAYER_BLACK) { |
|
838 | + if ($colour == self::PLAYER_BLACK) { |
|
840 | 839 | return self::PLAYER_WHITE; |
841 | 840 | } |
842 | 841 | return false; |
843 | 842 | } |
844 | 843 | |
845 | 844 | public function resign($accountID) { |
846 | - if($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
845 | + if ($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
847 | 846 | return false; |
848 | 847 | } |
849 | 848 | // If only 1 person has moved then just end the game. |
850 | - if(count($this->getMoves()) < 2) { |
|
849 | + if (count($this->getMoves()) < 2) { |
|
851 | 850 | $this->endDate = TIME; |
852 | 851 | $this->db->query('UPDATE chess_game |
853 | 852 | SET end_time=' . $this->db->escapeNumber(TIME) . ' |
@@ -859,17 +858,17 @@ discard block |
||
859 | 858 | $winnerAccountID = $this->getColourID(self::getOtherColour($loserColour)); |
860 | 859 | $results = $this->setWinner($winnerAccountID); |
861 | 860 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
862 | - $results['Loser']->increaseHOF(1, array($chessType,'Games','Resigned'), HOF_PUBLIC); |
|
861 | + $results['Loser']->increaseHOF(1, array($chessType, 'Games', 'Resigned'), HOF_PUBLIC); |
|
863 | 862 | SmrPlayer::sendMessageFromCasino($results['Winner']->getGameID(), $results['Winner']->getPlayerID(), '[player=' . $results['Loser']->getPlayerID() . '] just resigned against you in [chess=' . $this->getChessGameID() . '].'); |
864 | 863 | return 0; |
865 | 864 | } |
866 | 865 | } |
867 | 866 | |
868 | 867 | public function getPlayGameHREF() { |
869 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_play.php',array('ChessGameID' => $this->chessGameID))); |
|
868 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_play.php', array('ChessGameID' => $this->chessGameID))); |
|
870 | 869 | } |
871 | 870 | |
872 | 871 | public function getResignHREF() { |
873 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_resign_processing.php',array('ChessGameID' => $this->chessGameID))); |
|
872 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_resign_processing.php', array('ChessGameID' => $this->chessGameID))); |
|
874 | 873 | } |
875 | 874 | } |
@@ -81,8 +81,7 @@ discard block |
||
81 | 81 | $this->blackID = $this->db->getInt('black_id'); |
82 | 82 | $this->winner = $this->db->getInt('winner_id'); |
83 | 83 | $this->resetHasMoved(); |
84 | - } |
|
85 | - else { |
|
84 | + } else { |
|
86 | 85 | throw new Exception('Chess game not found: ' . $chessGameID); |
87 | 86 | } |
88 | 87 | } |
@@ -149,8 +148,7 @@ discard block |
||
149 | 148 | break; |
150 | 149 | } |
151 | 150 | } |
152 | - } |
|
153 | - catch(Exception $e) { |
|
151 | + } catch(Exception $e) { |
|
154 | 152 | if($debugInfo === true) { |
155 | 153 | echo $e->getMessage() . EOL . $e->getTraceAsString() . EOL; |
156 | 154 | } |
@@ -189,11 +187,9 @@ discard block |
||
189 | 187 | if(!$mate && $this->hasEnded()) { |
190 | 188 | if($this->getWinner() != 0) { |
191 | 189 | $this->moves[] = ($this->getWinner() == $this->getWhiteID() ? 'Black' : 'White') . ' Resigned.'; |
192 | - } |
|
193 | - else if(count($this->moves) < 2) { |
|
190 | + } else if(count($this->moves) < 2) { |
|
194 | 191 | $this->moves[] = 'Game Cancelled.'; |
195 | - } |
|
196 | - else { |
|
192 | + } else { |
|
197 | 193 | $this->moves[] = 'Game Drawn.'; |
198 | 194 | } |
199 | 195 | } |
@@ -212,8 +208,7 @@ discard block |
||
212 | 208 | for($x=0; $x < 8; $x++) { |
213 | 209 | if($board[$y][$x] == null) { |
214 | 210 | $blanks++; |
215 | - } |
|
216 | - else { |
|
211 | + } else { |
|
217 | 212 | if($blanks > 0) { |
218 | 213 | $fen .= $blanks; |
219 | 214 | $blanks = 0; |
@@ -268,8 +263,7 @@ discard block |
||
268 | 263 | $fen .= '3'; |
269 | 264 | break; |
270 | 265 | } |
271 | - } |
|
272 | - else { |
|
266 | + } else { |
|
273 | 267 | $fen .= '-'; |
274 | 268 | } |
275 | 269 | $fen .= ' 0 ' . floor(count($this->moves)/2); |
@@ -386,8 +380,7 @@ discard block |
||
386 | 380 | } |
387 | 381 | if($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
388 | 382 | $this->hasMoved[ChessPiece::PAWN] = array($endX, $endY); |
389 | - } |
|
390 | - else { |
|
383 | + } else { |
|
391 | 384 | $this->hasMoved[ChessPiece::PAWN] = array(-1,-1); |
392 | 385 | } |
393 | 386 | return ($castling == 'Queen' ? '0-0-0' : ($castling == 'King' ? '0-0' : '')) |
@@ -493,8 +486,7 @@ discard block |
||
493 | 486 | $board[$toY][$castling['ToX']]->setX($castling['ToX']); |
494 | 487 | $board[$y][$castling['X']] = null; |
495 | 488 | } |
496 | - } |
|
497 | - else if($p->pieceID == ChessPiece::PAWN) { |
|
489 | + } else if($p->pieceID == ChessPiece::PAWN) { |
|
498 | 490 | if($toY == 0 || $toY == 7) { |
499 | 491 | $pawnPromotion = $p->promote($pawnPromotionPiece, $board); |
500 | 492 | } |
@@ -512,8 +504,7 @@ discard block |
||
512 | 504 | } |
513 | 505 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = null; |
514 | 506 | } |
515 | - } |
|
516 | - else if($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
507 | + } else if($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
517 | 508 | //Rook moved? |
518 | 509 | if($hasMoved[$p->colour][ChessPiece::ROOK][$x==0?'Queen':'King'] === false) { |
519 | 510 | // We set rook moved in here as it's used for move info. |
@@ -573,12 +564,10 @@ discard block |
||
573 | 564 | $board[$y][$castling['X']]->setX($castling['X']); |
574 | 565 | $board[$toY][$castling['ToX']] = null; |
575 | 566 | } |
576 | - } |
|
577 | - else if($moveInfo['EnPassant'] === true) { |
|
567 | + } else if($moveInfo['EnPassant'] === true) { |
|
578 | 568 | $board[$toY][$toX] = null; |
579 | 569 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = $moveInfo['PieceTaken']; |
580 | - } |
|
581 | - else if($moveInfo['RookMoved'] !== false) { |
|
570 | + } else if($moveInfo['RookMoved'] !== false) { |
|
582 | 571 | $hasMoved[$p->colour][ChessPiece::ROOK][$moveInfo['RookMoved']] = false; |
583 | 572 | } |
584 | 573 | if($moveInfo['RookTaken'] !== false) { |
@@ -702,8 +691,7 @@ discard block |
||
702 | 691 | $this->setWinner($forAccountID); |
703 | 692 | $return = 1; |
704 | 693 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'You have just lost [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
705 | - } |
|
706 | - else { |
|
694 | + } else { |
|
707 | 695 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'It is now your turn in [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
708 | 696 | if($checking == 'CHECK') { |
709 | 697 | $currentPlayer->increaseHOF(1, array($chessType,'Moves','Check Given'), HOF_PUBLIC); |
@@ -853,8 +841,7 @@ discard block |
||
853 | 841 | SET end_time=' . $this->db->escapeNumber(TIME) . ' |
854 | 842 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ';'); |
855 | 843 | return 1; |
856 | - } |
|
857 | - else { |
|
844 | + } else { |
|
858 | 845 | $loserColour = $this->getColourForAccountID($accountID); |
859 | 846 | $winnerAccountID = $this->getColourID(self::getOtherColour($loserColour)); |
860 | 847 | $results = $this->setWinner($winnerAccountID); |