From 5cd56f822732ed5d26a20392dc6cbbc17b97048b Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:56:12 +0100 Subject: [PATCH 1/4] handling situation where current player is a spectator --- calypso.game.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/calypso.game.php b/calypso.game.php index 9649534..6b77b7f 100644 --- a/calypso.game.php +++ b/calypso.game.php @@ -33,6 +33,7 @@ class Calypso extends Table 4 => '', ); + const DUMMY = 0; const SPADES = 1; const HEARTS = 2; const CLUBS = 3; @@ -354,7 +355,8 @@ function getPartnerSuit($player_suit) { self::CLUBS => self::DIAMONDS, self::DIAMONDS => self::CLUBS, self::HEARTS => self::SPADES, - self::SPADES => self::HEARTS + self::SPADES => self::HEARTS, + self::DUMMY => self::DUMMY, )[$player_suit]; } // get suit the same colour as a given suit - feeds through to UI @@ -363,20 +365,21 @@ function getSameColourSuit($player_suit) { self::CLUBS => self::SPADES, self::DIAMONDS => self::HEARTS, self::HEARTS => self::DIAMONDS, - self::SPADES => self::CLUBS + self::SPADES => self::CLUBS, + self::DUMMY => self::DUMMY, )[$player_suit]; } function getPlayerSuit($player_id) { $sql = "SELECT player_id, trump_suit FROM player WHERE player_id=".$player_id.";"; $query_result = self::getCollectionFromDB( $sql, true ); - return $query_result[$player_id]; + return $query_result[$player_id] ?? 0; } function getPlayerIDFromSuit($suit){ $sql = "SELECT trump_suit, player_id FROM player WHERE trump_suit=".$suit.";"; $query_result = self::getCollectionFromDB( $sql, true ); - return $query_result[$suit]; + return $query_result[$suit] ?? 0; } function getPartnerID($player_id){ From 3c0d10bd4f1395d61958a19c61e83b752be0ff22 Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:09:53 +0100 Subject: [PATCH 2/4] more direct approach to spectator handling --- calypso.game.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/calypso.game.php b/calypso.game.php index 6b77b7f..5986525 100644 --- a/calypso.game.php +++ b/calypso.game.php @@ -273,16 +273,26 @@ protected function getAllDatas() } $result['hand'] = $this->cards->getCardsInLocation( 'hand', $current_player_id ); - $player_suit = self::getPlayerSuit($current_player_id); - $partner_suit = self::getPartnerSuit($player_suit); - // give suits in order: player suit, partner suit, - // same colour as player, same colour as partner - $result['suits_by_status'] = array( - +$player_suit, - $partner_suit, - self::getSameColourSuit($player_suit), - self::getSameColourSuit($partner_suit), - ); + if (!self::isSpectator()){ + $player_suit = self::getPlayerSuit($current_player_id); + $partner_suit = self::getPartnerSuit($player_suit); + // give suits in order: player suit, partner suit, + // same colour as player, same colour as partner + $result['suits_by_status'] = array( + +$player_suit, + $partner_suit, + self::getSameColourSuit($player_suit), + self::getSameColourSuit($partner_suit), + ); + } else { + // dummy ranking to keep nice and smooth + $result['suits_by_status'] = array( + self::CLUBS, + self::DIAMONDS, + self::HEARTS, + self::SPADES, + ); + } $result['cardsontable'] = $this->cards->getCardsInLocation( 'cardsontable' ); $result['cardsincalypsos'] = $this->cards->getCardsInLocation( 'calypso' ); @@ -373,13 +383,13 @@ function getSameColourSuit($player_suit) { function getPlayerSuit($player_id) { $sql = "SELECT player_id, trump_suit FROM player WHERE player_id=".$player_id.";"; $query_result = self::getCollectionFromDB( $sql, true ); - return $query_result[$player_id] ?? 0; + return $query_result[$player_id]; } function getPlayerIDFromSuit($suit){ $sql = "SELECT trump_suit, player_id FROM player WHERE trump_suit=".$suit.";"; $query_result = self::getCollectionFromDB( $sql, true ); - return $query_result[$suit] ?? 0; + return $query_result[$suit]; } function getPartnerID($player_id){ From f0c2ab0fc471d54145e29dbd8ae4b183496252d9 Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:11:51 +0100 Subject: [PATCH 3/4] ch-ch-ch-ch-changelog --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 40c73e5..95764d8 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Fixed + +- Fixed spectator (silent) server errors by skipping problematic functions + ## [beta-v01] - 2023-07-15 Entered beta on 15/7 - no changes From 9b56ed8185bfcfe45d0980aa0abece3a05de30c7 Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:39:12 +0100 Subject: [PATCH 4/4] don't need that silly dummy business anymore --- calypso.game.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/calypso.game.php b/calypso.game.php index 5986525..942d767 100644 --- a/calypso.game.php +++ b/calypso.game.php @@ -33,7 +33,6 @@ class Calypso extends Table 4 => '', ); - const DUMMY = 0; const SPADES = 1; const HEARTS = 2; const CLUBS = 3; @@ -366,7 +365,6 @@ function getPartnerSuit($player_suit) { self::DIAMONDS => self::CLUBS, self::HEARTS => self::SPADES, self::SPADES => self::HEARTS, - self::DUMMY => self::DUMMY, )[$player_suit]; } // get suit the same colour as a given suit - feeds through to UI @@ -376,7 +374,6 @@ function getSameColourSuit($player_suit) { self::DIAMONDS => self::HEARTS, self::HEARTS => self::DIAMONDS, self::SPADES => self::CLUBS, - self::DUMMY => self::DUMMY, )[$player_suit]; }