mirror of
https://github.com/jeremysrand/BuGS.git
synced 2024-06-10 08:29:30 +00:00
Make the timeouts configurable with net scores.
This commit is contained in:
parent
6afbf4eb85
commit
59dc11e516
|
@ -27,6 +27,10 @@
|
||||||
/* Defines and macros */
|
/* Defines and macros */
|
||||||
|
|
||||||
#define GLOBAL_SCORE_REFRESH_TIME (15 * 60 * 60)
|
#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)
|
||||||
|
|
||||||
#define TOOLFAIL(string) \
|
#define TOOLFAIL(string) \
|
||||||
if (toolerror()) SysFailMgr(toolerror(), (Pointer)"\p" string "\n\r Error Code -> $");
|
if (toolerror()) SysFailMgr(toolerror(), (Pointer)"\p" string "\n\r Error Code -> $");
|
||||||
|
@ -241,6 +245,10 @@ int main(void)
|
||||||
highScoreInitParams.scorePort = NETWORK_SERVERPORT;
|
highScoreInitParams.scorePort = NETWORK_SERVERPORT;
|
||||||
highScoreInitParams.secret1 = NETWORK_SERVERSECRET1;
|
highScoreInitParams.secret1 = NETWORK_SERVERSECRET1;
|
||||||
highScoreInitParams.secret2 = NETWORK_SERVERSECRET2;
|
highScoreInitParams.secret2 = NETWORK_SERVERSECRET2;
|
||||||
|
highScoreInitParams.shutdownTimeout = SHUTDOWN_NETWORK_TIMEOUT;
|
||||||
|
highScoreInitParams.connectTimeout = TCP_CONNECT_TIMEOUT;
|
||||||
|
highScoreInitParams.readTimeout = READ_NETWORK_TIMEOUT;
|
||||||
|
highScoreInitParams.retryTimeout = NETWORK_RETRY_TIMEOUT;
|
||||||
|
|
||||||
highScoreInitParams.displayConnectionString = showConnectionString;
|
highScoreInitParams.displayConnectionString = showConnectionString;
|
||||||
highScoreInitParams.waitForVbl = waitForVbl;
|
highScoreInitParams.waitForVbl = waitForVbl;
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
#define RESPONSE_TYPE_SCORES 1
|
#define RESPONSE_TYPE_SCORES 1
|
||||||
#define RESPONSE_TYPE_STATUS 2
|
#define RESPONSE_TYPE_STATUS 2
|
||||||
|
|
||||||
#define SHUTDOWN_NETWORK_TIMEOUT (2 * 60)
|
#define DEFAULT_SHUTDOWN_NETWORK_TIMEOUT (2 * 60)
|
||||||
#define TCP_CONNECT_TIMEOUT (8 * 60)
|
#define DEFAULT_TCP_CONNECT_TIMEOUT (8 * 60)
|
||||||
#define READ_NETWORK_TIMEOUT (5 * 60)
|
#define DEFAULT_READ_NETWORK_TIMEOUT (5 * 60)
|
||||||
#define NETWORK_RETRY_TIMEOUT (3 * 60 * 60)
|
#define DEFAULT_NETWORK_RETRY_TIMEOUT (3 * 60 * 60)
|
||||||
|
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
|
@ -252,6 +252,15 @@ void NSGS_InitNetwork(tNSGSHighScoreInitParams * params)
|
||||||
|
|
||||||
memcpy(&(networkGlobals->initParams), params, sizeof(networkGlobals->initParams));
|
memcpy(&(networkGlobals->initParams), params, sizeof(networkGlobals->initParams));
|
||||||
|
|
||||||
|
if (networkGlobals->initParams.shutdownTimeout == 0)
|
||||||
|
networkGlobals->initParams.shutdownTimeout = DEFAULT_SHUTDOWN_NETWORK_TIMEOUT;
|
||||||
|
if (networkGlobals->initParams.connectTimeout == 0)
|
||||||
|
networkGlobals->initParams.connectTimeout = DEFAULT_TCP_CONNECT_TIMEOUT;
|
||||||
|
if (networkGlobals->initParams.readTimeout == 0)
|
||||||
|
networkGlobals->initParams.readTimeout = DEFAULT_READ_NETWORK_TIMEOUT;
|
||||||
|
if (networkGlobals->initParams.retryTimeout == 0)
|
||||||
|
networkGlobals->initParams.retryTimeout = DEFAULT_NETWORK_RETRY_TIMEOUT;
|
||||||
|
|
||||||
networkGlobals->networkStartedConnected = TCPIPGetConnectStatus();
|
networkGlobals->networkStartedConnected = TCPIPGetConnectStatus();
|
||||||
if (networkGlobals->networkStartedConnected) {
|
if (networkGlobals->networkStartedConnected) {
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_CONNECTED;
|
networkGlobals->gameNetworkState = GAME_NETWORK_CONNECTED;
|
||||||
|
@ -301,7 +310,7 @@ void NSGS_DisconnectNetwork(void)
|
||||||
if (networkGlobals->gameNetworkState < GAME_NETWORK_CLOSING_TCP) {
|
if (networkGlobals->gameNetworkState < GAME_NETWORK_CLOSING_TCP) {
|
||||||
TCPIPCloseTCP(networkGlobals->ipid);
|
TCPIPCloseTCP(networkGlobals->ipid);
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
||||||
networkGlobals->timeout = SHUTDOWN_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.shutdownTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -373,7 +382,7 @@ static void handleSocketError(void)
|
||||||
if (networkGlobals->initParams.displayError != NULL)
|
if (networkGlobals->initParams.displayError != NULL)
|
||||||
networkGlobals->initParams.displayError(NSGS_SOCKET_ERROR, networkGlobals->errorCode);
|
networkGlobals->initParams.displayError(NSGS_SOCKET_ERROR, networkGlobals->errorCode);
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_FAILURE;
|
networkGlobals->gameNetworkState = GAME_NETWORK_FAILURE;
|
||||||
networkGlobals->timeout = NETWORK_RETRY_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.retryTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleProtocolFailed(void)
|
static void handleProtocolFailed(void)
|
||||||
|
@ -382,7 +391,7 @@ static void handleProtocolFailed(void)
|
||||||
if (networkGlobals->initParams.displayError != NULL)
|
if (networkGlobals->initParams.displayError != NULL)
|
||||||
networkGlobals->initParams.displayError(NSGS_PROTOCOL_ERROR, networkGlobals->errorCode);
|
networkGlobals->initParams.displayError(NSGS_PROTOCOL_ERROR, networkGlobals->errorCode);
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_FAILURE;
|
networkGlobals->gameNetworkState = GAME_NETWORK_FAILURE;
|
||||||
networkGlobals->timeout = NETWORK_RETRY_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.retryTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleFailure(void)
|
static void handleFailure(void)
|
||||||
|
@ -421,7 +430,7 @@ static void handleTcpUnconnected(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_TCP;
|
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_TCP;
|
||||||
networkGlobals->timeout = TCP_CONNECT_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.connectTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleWaitingForTcp(void)
|
static void handleWaitingForTcp(void)
|
||||||
|
@ -451,7 +460,7 @@ static void handleWaitingForTcp(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_HELLO;
|
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_HELLO;
|
||||||
networkGlobals->timeout = READ_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.readTimeout;
|
||||||
networkGlobals->bytesRead = 0;
|
networkGlobals->bytesRead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +509,7 @@ static void handleWaitingForHello(void)
|
||||||
} else {
|
} else {
|
||||||
TCPIPCloseTCP(networkGlobals->ipid);
|
TCPIPCloseTCP(networkGlobals->ipid);
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
||||||
networkGlobals->timeout = SHUTDOWN_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.shutdownTimeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +530,7 @@ static void handleRequestScores(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_SCORES;
|
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_SCORES;
|
||||||
networkGlobals->timeout = READ_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.readTimeout;
|
||||||
networkGlobals->bytesRead = 0;
|
networkGlobals->bytesRead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +575,7 @@ static void handleWaitingForScores(void)
|
||||||
|
|
||||||
TCPIPCloseTCP(networkGlobals->ipid);
|
TCPIPCloseTCP(networkGlobals->ipid);
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
networkGlobals->gameNetworkState = GAME_NETWORK_CLOSING_TCP;
|
||||||
networkGlobals->timeout = SHUTDOWN_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.shutdownTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleSetHighScore(void)
|
static void handleSetHighScore(void)
|
||||||
|
@ -587,7 +596,7 @@ static void handleSetHighScore(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_SCORE_ACK;
|
networkGlobals->gameNetworkState = GAME_NETWORK_WAITING_FOR_SCORE_ACK;
|
||||||
networkGlobals->timeout = READ_NETWORK_TIMEOUT;
|
networkGlobals->timeout = networkGlobals->initParams.readTimeout;
|
||||||
networkGlobals->bytesRead = 0;
|
networkGlobals->bytesRead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,26 @@ typedef struct tNSGSHighScoreInitParams
|
||||||
unsigned long secret1;
|
unsigned long secret1;
|
||||||
unsigned long secret2;
|
unsigned long secret2;
|
||||||
|
|
||||||
|
/* Each of these timeouts are measured in poll periods. So, if you call NSGS_PollNetwork() every 60th of a
|
||||||
|
second, then you would use 60 to set the timeout to 1 second. If these are zero, then the "good value"
|
||||||
|
in the comment will be used as a default.
|
||||||
|
|
||||||
|
The shutdown timeout controls how long we wait for a clean TCP disconnection before forcing an abort of
|
||||||
|
the connection. Two seconds is a good value for this timeout. */
|
||||||
|
unsigned int shutdownTimeout;
|
||||||
|
|
||||||
|
/* The connect timeout is the amount of time we wait for a TCP connection to come up before declaring a
|
||||||
|
timeout protocol error. Eight seconds is a good value for this timeout. */
|
||||||
|
unsigned int connectTimeout;
|
||||||
|
|
||||||
|
/* The read timeout is the amount of time we wait for a response from the server after we have made a
|
||||||
|
request of it, whether that is getting the high score list or setting a new high score. Five seconds
|
||||||
|
is a good value for this timeout. */
|
||||||
|
unsigned int readTimeout;
|
||||||
|
|
||||||
|
/* The retry timeout is the amount of time we wait in an error state before retrying. This only happens
|
||||||
|
for "soft" errors where a retry is worthwhile. Three minutes is a good value for this timeout. */
|
||||||
|
unsigned int retryTimeout;
|
||||||
|
|
||||||
/* This function should display a message to the user that the network is being brought up and they should
|
/* This function should display a message to the user that the network is being brought up and they should
|
||||||
be patient when the argument is TRUE and when the argument is FALSE, it should clear that message. This
|
be patient when the argument is TRUE and when the argument is FALSE, it should clear that message. This
|
||||||
|
|
Loading…
Reference in New Issue
Block a user