From 74842521224a20e0e843a9e4c018fb62e37d231c Mon Sep 17 00:00:00 2001 From: Nescio0 Date: Wed, 12 May 2021 19:45:07 +0200 Subject: [PATCH 01/18] less unnecessary and excessive capitalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Play A Game Against Bots" → "Play a game against bots" --- locales/English/gamecreate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/English/gamecreate.php b/locales/English/gamecreate.php index 5594879f1..ab8bc6158 100755 --- a/locales/English/gamecreate.php +++ b/locales/English/gamecreate.php @@ -43,7 +43,7 @@
On webDiplomacy, you can play games against humans or bots. If you want to play against other players, you\'re in the right place. You can just fill out this form. If you want to play against bots, - you can click "Play a Game Against Bots." Our bots are artificial intelligence users, so they are not + you can click "Play a game against bots." Our bots are artificial intelligence users, so they are not computer players like you might encounter in online chess, for example. They are very unique and they are trained rigorously based on the decisions real players made, which means they are both intelligent and unpredictable. Give them a try sometime, you might be surprised how good they are! @@ -76,7 +76,7 @@ setcookie('wD-Tutorial-GameCreate', '', time()-3600); } ?> -

Play A Game Against Bots

+

Play a game against bots

From da2affbcc2f3eb14837570e040917e016b5d20e9 Mon Sep 17 00:00:00 2001 From: Nescio0 Date: Wed, 12 May 2021 19:47:37 +0200 Subject: [PATCH 02/18] less unnecessary and excessive capitalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Play A Game Against Humans" → "Play a game against humans" --- botgamecreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botgamecreate.php b/botgamecreate.php index e562df9aa..0b6af41d2 100644 --- a/botgamecreate.php +++ b/botgamecreate.php @@ -149,7 +149,7 @@
Start a new game of Diplomacy against bots.
-

Play A Game Against Humans

+

Play a game against humans

All games against bots are unranked, with 3 day phases and 4 excused missed turns. However, anytime you ready up your orders, the game will immediately move to the next phase.

From 1c114ed8ce60a62652de1a177117cf1b2db0d683 Mon Sep 17 00:00:00 2001 From: Kestas Kuliukas Date: Mon, 8 Nov 2021 11:34:03 +0000 Subject: [PATCH 03/18] Test commit --- usercp.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usercp.php b/usercp.php index 36fcb9c0e..6b09eab86 100755 --- a/usercp.php +++ b/usercp.php @@ -23,6 +23,8 @@ * @subpackage Forms */ +// Staging test commit + require_once('header.php'); require_once(l_r('objects/mailer.php')); From a7a0400f4127d3ffe969622fe3637be717f9db12 Mon Sep 17 00:00:00 2001 From: Kestas Kuliukas Date: Sat, 18 Dec 2021 14:03:08 +0800 Subject: [PATCH 04/18] Bug fixes to remove clutter from error logs --- board.php | 7 ++- board/info/orders.php | 113 +++++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 54 deletions(-) diff --git a/board.php b/board.php index cea33f0b0..4583eb261 100755 --- a/board.php +++ b/board.php @@ -277,8 +277,11 @@ // Post messages we sent, and get the user we're speaking to $msgCountryID = $CB->findTab(); - $CB->postMessage($msgCountryID); - $DB->sql_put("COMMIT"); + if( isset($Member) ) + { + $CB->postMessage($msgCountryID); + $DB->sql_put("COMMIT"); + } $forum = $CB->output($msgCountryID); diff --git a/board/info/orders.php b/board/info/orders.php index 1267f2957..3ed3ac7f7 100755 --- a/board/info/orders.php +++ b/board/info/orders.php @@ -72,6 +72,15 @@ function orderIndex($title, $depth) } } +// People have got invalid territory IDs into the moves archive, this wil prevent it crashing the moves page +function tryGetTerritoryName($terrID) { + global $terrIDToName; + + if( key_exists($terrID,$terrIDToName) ) + return $terrIDToName[$terrID]; + else + return "???"; +} //TODO: Merge this code with the normal order output code function outputOrderLogs(array $orders) { @@ -92,21 +101,21 @@ function outputOrderLogs(array $orders) foreach($types as $phase=>$orderTypes) { - if ($phase == 'Diplomacy' ) { - $buffer .= '
  • '.l_t($phase)."
  • \n\t\t\t
      "; - } else { - $orderFound=0; - foreach($orderTypes as $t) { - if (array_key_exists($t, $orders)) { - $orderFound=1; - break; - } - } - if ($orderFound) - $buffer .= '
    • '.orderIndex(l_t($phase), 3).''.l_t($phase)."
    • \n\t\t\t
        "; - else - continue; - } + if ($phase == 'Diplomacy' ) { + $buffer .= '
      • '.l_t($phase)."
      • \n\t\t\t
          "; + } else { + $orderFound=0; + foreach($orderTypes as $t) { + if (array_key_exists($t, $orders)) { + $orderFound=1; + break; + } + } + if ($orderFound) + $buffer .= '
        • '.orderIndex(l_t($phase), 3).''.l_t($phase)."
        • \n\t\t\t
            "; + else + continue; + } foreach($orderTypes as $orderType) { @@ -116,18 +125,18 @@ function outputOrderLogs(array $orders) { $buffer .= '
          • '; - if ($order['dislodged'] == 'Yes' || ($order['success'] == 'No' && $order['type'] != 'hold')) - $buffer .= ''; // underline failed orders - + if ($order['dislodged'] == 'Yes' || ($order['success'] == 'No' && $order['type'] != 'hold')) + $buffer .= ''; // underline failed orders + if ( $phase == 'Retreats' ) { switch($order['type']) { case 'retreat': - $buffer .= l_t('The %s at %s retreat to %s',l_t($order['unitType']),l_t($terrIDToName[$order['terrID']]),l_t($terrIDToName[$order['toTerrID']])); + $buffer .= l_t('The %s at %s retreat to %s',l_t($order['unitType']),l_t(tryGetTerritoryName($order['terrID'])),l_t(tryGetTerritoryName($order['toTerrID']))); break; case 'disband': - $buffer .= l_t('The %s at %s disband',l_t($order['unitType']),l_t($terrIDToName[$order['terrID']])); + $buffer .= l_t('The %s at %s disband',l_t($order['unitType']),l_t(tryGetTerritoryName($order['terrID']))); } } elseif ( $phase == 'Unit-placement' ) @@ -136,46 +145,46 @@ function outputOrderLogs(array $orders) { case 'build army': case 'build fleet': - $buffer .= l_t('Build %s at %s',($order['type']=='build army'?l_t('army'):l_t('fleet')),l_t($terrIDToName[$order['terrID']])); + $buffer .= l_t('Build %s at %s',($order['type']=='build army'?l_t('army'):l_t('fleet')),l_t(tryGetTerritoryName($order['terrID']))); break; case 'wait': $buffer .= l_t('Do not use build order'); break; case 'destroy': - $buffer .= l_t('Destroy the unit at %s',l_t($terrIDToName[$order['terrID']])); + $buffer .= l_t('Destroy the unit at %s',l_t(tryGetTerritoryName($order['terrID']))); } } else { - $buffer .= l_t("The %s at %s %s",l_t($order['unitType']),l_t($terrIDToName[$order['terrID']]),l_t($order['type'])). - ($order['toTerrID'] ? l_t(" to %s",l_t($terrIDToName[$order['toTerrID']])) : '' ). - ($order['fromTerrID'] ? l_t(" from %s",l_t($terrIDToName[$order['fromTerrID']])) : ''). + $buffer .= l_t("The %s at %s %s",l_t($order['unitType']),l_t(tryGetTerritoryName($order['terrID'])),l_t($order['type'])). + ($order['toTerrID'] ? l_t(" to %s",l_t(tryGetTerritoryName($order['toTerrID']))) : '' ). + ($order['fromTerrID'] ? l_t(" from %s",l_t(tryGetTerritoryName($order['fromTerrID']))) : ''). ($order['viaConvoy'] == 'Yes' ? l_t(" via convoy") : ''); } - - $buffer .= '.'; - - if ($order['dislodged'] == 'Yes' || ($order['success'] == 'No' && $order['type'] != 'hold')) { - $buffer .= ''; - - if ($order['success'] == 'No') { - /* - if ($order['type'] == 'move') // not sure its good idea to say 'bounce' - $buffer .= ' (bounce)'; // when you don't really know cause of failure - else if ($order['type'] == 'retreat') - $buffer .= ' (fail)'; - else if ($order['type'] != 'hold')// supports and convoy - $buffer .= ' (cut)'; - */ - if ($order['type'] != 'hold') - $buffer .= ' ('.l_t('fail').')'; - } - - if ($order['dislodged'] == 'Yes') - $buffer .= ' ('.l_t('dislodged').')'; - } - - $buffer .= '
          • '; + + $buffer .= '.'; + + if ($order['dislodged'] == 'Yes' || ($order['success'] == 'No' && $order['type'] != 'hold')) { + $buffer .= ''; + + if ($order['success'] == 'No') { + /* + if ($order['type'] == 'move') // not sure its good idea to say 'bounce' + $buffer .= ' (bounce)'; // when you don't really know cause of failure + else if ($order['type'] == 'retreat') + $buffer .= ' (fail)'; + else if ($order['type'] != 'hold')// supports and convoy + $buffer .= ' (cut)'; + */ + if ($order['type'] != 'hold') + $buffer .= ' ('.l_t('fail').')'; + } + + if ($order['dislodged'] == 'Yes') + $buffer .= ' ('.l_t('dislodged').')'; + } + + $buffer .= ''; } } @@ -189,7 +198,7 @@ function outputOrderLogs(array $orders) print '

            '.l_t('Order history').'

            '; print '
            '; -$tabl = $DB->sql_tabl("SELECT turn, countryID, LOWER(unitType) as unitType, LOWER(type) as type, terrID, toTerrID, fromTerrID, viaConvoy, success, dislodged +$tabl = $DB->sql_tabl("SELECT turn, countryID, LOWER(unitType) as unitType, LOWER(type) as type, terrID, toTerrID, fromTerrID, viaConvoy, success, dislodged FROM wD_MovesArchive WHERE gameID = ".$Game->id." ORDER BY turn DESC, countryID ASC"); @@ -224,7 +233,7 @@ function outputOrderLogs(array $orders) $buffer .= orderIndex(l_t($countryIDToName[$row['countryID']]), 2); - $buffer .= ''.l_t($countryIDToName[$row['countryID']]).":
            "; + $buffer .= ''.l_t($countryIDToName[$row['countryID']]).":
            "; $lastCountryID = $row['countryID']; } @@ -245,4 +254,4 @@ function outputOrderLogs(array $orders) print '

            '; -?> +?> From ca028ed5daa943b26fc249cfb15875a86c9a7735 Mon Sep 17 00:00:00 2001 From: Kestas Kuliukas Date: Sat, 18 Dec 2021 14:11:00 +0800 Subject: [PATCH 05/18] Locking fix for map, to prevent deadlocks --- map.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/map.php b/map.php index 0f362a592..70321fd97 100755 --- a/map.php +++ b/map.php @@ -136,10 +136,10 @@ global $Game; $Variant=libVariant::loadFromGameID($_REQUEST['gameID']); libVariant::setGlobals($Variant); - // Locking this game for update is excessive; worst case the map is overwritten - // Actually - $DB->sql_put("COMMIT"); - $Game=$Variant->Game($_REQUEST['gameID'], UPDATE); + // Get a global lock to prevent two people writing the map at the same time, or rendering the map while a game is being processed + // This replaces a game FOR UPDATE lock which would cause deadlocks + $DB->get_lock('gamemaster',1); + $Game=$Variant->Game($_REQUEST['gameID']); /* * Determine which turn we are viewing. This is made a little trickier because From 70d906011e9fc7b476534ffc124aee713dafcda8 Mon Sep 17 00:00:00 2001 From: Colin Flaherty Date: Thu, 6 Jan 2022 18:14:46 +0000 Subject: [PATCH 06/18] Return timeSent in api + minor fixes --- api.php | 9 +++++---- api/responses/game_state.php | 3 ++- api/responses/message.php | 5 ++++- lib/gamemessage.php | 6 +++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/api.php b/api.php index 5d46d5161..5070cef9e 100644 --- a/api.php +++ b/api.php @@ -673,17 +673,18 @@ public function run($userID, $permissionIsExplicit) { throw new ClientForbiddenException('User does not have explicit permission to make this API call.'); } - if ($toCountryID < 1 || $toCountryID > count($game->Members) || $toCountryID == $countryID) { + if ($toCountryID < 1 || $toCountryID > count($game->Members->ByUserID) || $toCountryID == $countryID) { throw new RequestException('Invalid toCountryID'); } $toUser = new User($game->Members->ByCountryID[$toCountryID]->userID); if(!$toUser->isCountryMuted($game->id, $countryID)) { - libGameMessage::send($toCountryID, $countryID, $message); + $time = libGameMessage::send($toCountryID, $countryID, $message); } - // FIXME: what to return? - return json_encode($args); + $DB->sql_put("COMMIT"); + + return $time; } } diff --git a/api/responses/game_state.php b/api/responses/game_state.php index 548524730..cbf17284a 100755 --- a/api/responses/game_state.php +++ b/api/responses/game_state.php @@ -389,7 +389,7 @@ function load() // messages if ($this->pressType != 'NoPress') { $msgTabl = $DB->sql_tabl( - "SELECT turn, fromCountryID, toCountryID, message, phaseMarker from wD_GameMessages_Redacted WHERE gameID = ".$this->gameID." AND (fromCountryID = ".$this->countryID." OR toCountryID = ".$this->countryID.") ORDER BY timeSent" + "SELECT turn, fromCountryID, toCountryID, message, timeSent, phaseMarker from wD_GameMessages_Redacted WHERE gameID = ".$this->gameID." AND (fromCountryID = ".$this->countryID." OR toCountryID = ".$this->countryID.") ORDER BY timeSent" ); while ($row = $DB->tabl_hash($msgTabl)) { @@ -397,6 +397,7 @@ function load() $row['message'], $row['fromCountryID'], $row['toCountryID'], + $row['timeSent'], $row['phaseMarker'] ); $phase = $gameSteps->get($row['turn'], 'Diplomacy', array()); diff --git a/api/responses/message.php b/api/responses/message.php index 953dffdc9..bd25332be 100644 --- a/api/responses/message.php +++ b/api/responses/message.php @@ -29,6 +29,7 @@ class Message { public $message; public $fromCountryID; public $toCountryID; + public $timeSent; public $phaseMarker; function toJson() { return json_encode($this); } @@ -38,14 +39,16 @@ function toJson() { return json_encode($this); } * @param string $message - message * @param int $fromCountryID - sender country ID * @param int $toCountryID - receiver country ID + * @param int $timeSent - time sent * @param string $phaseMarker - Diplomacy/Retreat/Builds/etc */ - function __construct($message, $fromCountryID, $toCountryID, $phaseMarker = null) + function __construct($message, $fromCountryID, $toCountryID, $timeSent, $phaseMarker = null) { $this->message = $message; $this->fromCountryID = intval($fromCountryID); $this->toCountryID = intval($toCountryID); + $this->timeSent = intval($timeSent); $this->phaseMarker = $phaseMarker; } } diff --git a/lib/gamemessage.php b/lib/gamemessage.php index 699a70467..b73158df4 100755 --- a/lib/gamemessage.php +++ b/lib/gamemessage.php @@ -63,6 +63,8 @@ static public function send($toCountryID, $fromCountryID, $message, $gameID=-1) throw new Exception(l_t("Message too long")); } + $time = time(); + $DB->sql_put("INSERT INTO wD_GameMessages (gameID, toCountryID, fromCountryID, turn, message, phaseMarker, timeSent) VALUES(".$Game->id.", @@ -71,12 +73,14 @@ static public function send($toCountryID, $fromCountryID, $message, $gameID=-1) ".$Game->turn.", '".$message."', '".$Game->phase."', - ".time().")"); + ".$time.")"); if ($toCountryID != $fromCountryID || $fromCountryID == 0) { libGameMessage::notify($toCountryID, $fromCountryID); } + + return $time; } /** From e4ba822eb45893feeb57ca7b206b67e8ff4c3bc4 Mon Sep 17 00:00:00 2001 From: "Kestas \"Chris\" Kuliukas" Date: Sat, 12 Feb 2022 17:12:23 +0800 Subject: [PATCH 07/18] Updated the PayPal donation button target Changed donation button to pay in USD, have more modern styling, and go straight to the WebDiplomacy Pty Ltd PayPal. (Note that this used to be defined in config.php so it could be changed per-site, it would be good to restore this functionality since this is specific to our installation.) --- donations.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/donations.php b/donations.php index a9780562f..46de4bccf 100644 --- a/donations.php +++ b/donations.php @@ -74,13 +74,21 @@ functionality is locked behind a paywall, nor do we ever discriminate in any way

            If you would like to support the site, click the button below. After submitting a donation, please send an email to a Co-owner at ".Config::$adminEMail." with your username to receive a donator marker.
            - - - - - - +

            From 1110a81e2e9e059e77ea014840ea286a37d96bb1 Mon Sep 17 00:00:00 2001 From: "Kestas \"Chris\" Kuliukas" Date: Sat, 12 Feb 2022 17:43:25 +0800 Subject: [PATCH 08/18] Changed donation link to embed userid Changed to embed user id in case paypal email doesn't match user email --- donations.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/donations.php b/donations.php index 46de4bccf..6f1e160ed 100644 --- a/donations.php +++ b/donations.php @@ -73,22 +73,13 @@ functionality is locked behind a paywall, nor do we ever discriminate in any way
            How do I donate?

            - If you would like to support the site, click the button below. After submitting a donation, please send an email to a Co-owner at ".Config::$adminEMail." with your username to receive a donator marker.
            -

            + If you would like to support the site, click the button below. You will receive a donation marker so that other users are aware that you are helping to keep the site we all enjoy up and running.
            +
            + + + + +

            From 309f39d9ac30aa613424e331da834b334761e8cc Mon Sep 17 00:00:00 2001 From: "Kestas \"Chris\" Kuliukas" Date: Sat, 12 Feb 2022 18:30:01 +0800 Subject: [PATCH 09/18] Thank you splash page Thank you blurb --- donations.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/donations.php b/donations.php index 6f1e160ed..68cbd633f 100644 --- a/donations.php +++ b/donations.php @@ -28,7 +28,22 @@ libHTML::starthtml(); print libHTML::pageTitle(l_t('Donations'),l_t('Learn how to donate and what your donations are used for.')); -print " +if( isset($_GET['thank-you']) ) +{ + print " +
            +
            Thank you!
            +
            +

            + Thank you for your donation! Donations help to keep the server up and running for all users, and with fees of only hundreds of USD per year every donation helps keep the server running for free, for everyone.
            + Thanks again! It may take some time for the PayPal receipt to be registered by the server, please contact the team if you do not receive a marker. +

            +
            +
            "; +} +else +{ + print "
            Why do you need donations?
            @@ -82,9 +97,9 @@ functionality is locked behind a paywall, nor do we ever discriminate in any way

            - -
    "; +
    "; ?> +