Skip to content

Commit

Permalink
Add a timeout to the TCP connect state. Prior to this, it was possibl…
Browse files Browse the repository at this point in the history
…e to block (indefinitely?) if there is a network glitch when trying to upload a score.
  • Loading branch information
jeremysrand committed Jul 3, 2021
1 parent 165d489 commit 2a43113
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BuGS/Read.Me.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ This project would not have been a success without help from the Apple // commun
* Ken Gagne and Juiced.GS for making tools like ORCA and GoldenGate available.
* Stephen Heumann for NetDisk which I used to transfer my latest build to my real GS for testing.
* Ewen Wannop (Speccie) for his great network tools, especially Versions which I am using to assist in pushing out fixes and new versions of BuGS. I had a problem with the Check File Finder extension but very quickly he found the problem. I very much appreciate his support getting that problem fixed.
* Stefan Wessels for his extensive testing leading up to v2.0 of BuGS. At the time of updating this document, he is trying very hard to beat my high score online and is very close to doing so (his scores are posted as SQW). Thanks so much for your help and enthusiasm and I am sure you will beat my score soon.
* Stefan Wessels for his extensive testing leading up to v2.0 of BuGS. He identified a problem which could lead to waves of scorpions appearing over and over again due to the behaviour of the random number generator and also found a problem with timeouts not working when trying to upload a score. At the time of updating this document, he is trying very hard to beat my high score online and is very close to doing so (his scores are posted as SQW). Thanks so much for your help and enthusiasm and I am sure you will beat my score soon.

## Contact:

Expand Down
14 changes: 12 additions & 2 deletions BuGS/globalScores.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#define GLOBAL_SCORE_REFRESH_TIME (15 * 60 * 60)
#define SHUTDOWN_NETWORK_TIMEOUT (2 * 60)
#define TCP_CONNECT_TIMEOUT (8 * 60)
#define READ_NETWORK_TIMEOUT (5 * 60)
#define NETWORK_RETRY_TIMEOUT (3 * 60 * 60)

Expand Down Expand Up @@ -90,7 +91,8 @@ typedef struct tStatusResponse {


typedef enum tProtocolErrors {
HELLO_TIMEOUT_ERROR = 1,
TCP_CONNECT_TIMEOUT_ERROR = 1,
HELLO_TIMEOUT_ERROR,
HELLO_TOO_BIG_ERROR,
HELLO_UNEXPECTED_RESPONSE_ERROR,
HIGH_SCORE_TIMEOUT_ERROR,
Expand Down Expand Up @@ -431,6 +433,7 @@ void pollNetwork(void)
break;
}
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_TCP;
networkGlobals->timeout = TCP_CONNECT_TIMEOUT;
break;

case GAME_NETWORK_WAITING_FOR_TCP:
Expand All @@ -441,8 +444,15 @@ void pollNetwork(void)
break;
}
if ((networkGlobals->tcpStatus.srState == TCPSSYNSENT) ||
(networkGlobals->tcpStatus.srState == TCPSSYNRCVD))
(networkGlobals->tcpStatus.srState == TCPSSYNRCVD)) {
if (networkGlobals->timeout > 0) {
networkGlobals->timeout--;
} else {
networkGlobals->gameNetworkState = GAME_NETWORK_PROTOCOL_FAILED;
networkGlobals->errorCode = TCP_CONNECT_TIMEOUT_ERROR;
}
break;
}

if (networkGlobals->tcpStatus.srState != TCPSESTABLISHED) {
abortConnection();
Expand Down
2 changes: 1 addition & 1 deletion BuGS/main.rez
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ resource rVersion (1) {
{
1, /* Major version number in BCD */
9, /* Minor version number in BCD */
3, /* Bug version number in BCD */
4, /* Bug version number in BCD */
beta, /* Development phase */
0 /* Release number */
},
Expand Down

0 comments on commit 2a43113

Please sign in to comment.