mirror of
https://github.com/glest/glest-source.git
synced 2025-09-08 15:00:41 +02:00
- updated disconnect checking to include a timeout check for our custom ping
This commit is contained in:
@@ -38,6 +38,7 @@ public:
|
|||||||
static const int updateFps= 40;
|
static const int updateFps= 40;
|
||||||
static const int cameraFps= 100;
|
static const int cameraFps= 100;
|
||||||
static int networkFramePeriod;
|
static int networkFramePeriod;
|
||||||
|
static const int networkPingInterval = 5;
|
||||||
//static const int networkExtraLatency= 200;
|
//static const int networkExtraLatency= 200;
|
||||||
static const int maxClientConnectHandshakeSecs= 10;
|
static const int maxClientConnectHandshakeSecs= 10;
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ struct FormatString {
|
|||||||
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
|
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
|
||||||
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
||||||
{
|
{
|
||||||
lastNetworkSend = time(NULL);
|
lastNetworkSendPing = time(NULL);
|
||||||
|
|
||||||
returnMenuInfo=joinMenuInfo;
|
returnMenuInfo=joinMenuInfo;
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
@@ -362,12 +362,18 @@ void MenuStateConnectedGame::update()
|
|||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
const int pingFrequency = 5;
|
if(difftime(time(NULL),lastNetworkSendPing) >= GameConstants::networkPingInterval) {
|
||||||
if(difftime(time(NULL),lastNetworkSend) >= pingFrequency) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
lastNetworkSend = time(NULL);
|
bool isFirstPing = (lastNetworkSendPing == 0);
|
||||||
clientInterface->sendPingMessage(pingFrequency, time(NULL));
|
lastNetworkSendPing = time(NULL);
|
||||||
|
clientInterface->sendPingMessage(GameConstants::networkPingInterval, time(NULL));
|
||||||
|
|
||||||
|
if(isFirstPing == false && clientInterface->getLastPingLag() >= (GameConstants::networkPingInterval * 2)) {
|
||||||
|
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||||
|
clientInterface->sendTextMessage(playerNameStr + "'s connection timed out communicating with server.",-1);
|
||||||
|
clientInterface->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update status label
|
//update status label
|
||||||
|
@@ -71,7 +71,7 @@ private:
|
|||||||
string currentMap;
|
string currentMap;
|
||||||
JoinMenu returnMenuInfo;
|
JoinMenu returnMenuInfo;
|
||||||
bool settingsReceivedFromServer;
|
bool settingsReceivedFromServer;
|
||||||
time_t lastNetworkSend;
|
time_t lastNetworkSendPing;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -95,6 +95,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
masterServererErrorToShow = "---";
|
masterServererErrorToShow = "---";
|
||||||
lastSetChangedGameSettings = 0;
|
lastSetChangedGameSettings = 0;
|
||||||
lastMasterserverPublishing = 0;
|
lastMasterserverPublishing = 0;
|
||||||
|
lastNetworkPing = 0;
|
||||||
soundConnectionCount=0;
|
soundConnectionCount=0;
|
||||||
|
|
||||||
vector<string> teamItems, controlItems, results;
|
vector<string> teamItems, controlItems, results;
|
||||||
@@ -1098,8 +1099,11 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
|
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
|
||||||
publishToServerInfo.clear();
|
publishToServerInfo.clear();
|
||||||
|
|
||||||
bool broadCastSettings = needToBroadcastServerSettings;
|
bool broadCastSettings = needToBroadcastServerSettings;
|
||||||
needToBroadcastServerSettings=false;
|
needToBroadcastServerSettings=false;
|
||||||
|
|
||||||
|
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
if(republish == true) {
|
if(republish == true) {
|
||||||
@@ -1156,6 +1160,14 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(needPing == true) {
|
||||||
|
lastNetworkPing = time(NULL);
|
||||||
|
|
||||||
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL));
|
||||||
|
serverInterface->broadcastPing(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,6 +72,8 @@ private:
|
|||||||
bool needToSetChangedGameSettings;
|
bool needToSetChangedGameSettings;
|
||||||
time_t lastSetChangedGameSettings;
|
time_t lastSetChangedGameSettings;
|
||||||
time_t lastMasterserverPublishing;
|
time_t lastMasterserverPublishing;
|
||||||
|
time_t lastNetworkPing;
|
||||||
|
|
||||||
bool needToRepublishToMasterserver;
|
bool needToRepublishToMasterserver;
|
||||||
bool needToBroadcastServerSettings;
|
bool needToBroadcastServerSettings;
|
||||||
std::map<string,string> publishToServerInfo;
|
std::map<string,string> publishToServerInfo;
|
||||||
|
@@ -273,6 +273,7 @@ void ClientInterface::updateLobby()
|
|||||||
NetworkMessagePing networkMessagePing;
|
NetworkMessagePing networkMessagePing;
|
||||||
if(receiveMessage(&networkMessagePing)) {
|
if(receiveMessage(&networkMessagePing)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
lastPingInfo = networkMessagePing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -558,6 +559,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
|||||||
NetworkMessagePing networkMessagePing;
|
NetworkMessagePing networkMessagePing;
|
||||||
if(receiveMessage(&networkMessagePing)) {
|
if(receiveMessage(&networkMessagePing)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
lastPingInfo = networkMessagePing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -898,6 +900,7 @@ bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess
|
|||||||
discard = true;
|
discard = true;
|
||||||
NetworkMessagePing msg = NetworkMessagePing();
|
NetworkMessagePing msg = NetworkMessagePing();
|
||||||
this->receiveMessage(&msg);
|
this->receiveMessage(&msg);
|
||||||
|
lastPingInfo = msg;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case nmtLaunch:
|
case nmtLaunch:
|
||||||
|
@@ -268,6 +268,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
NetworkMessagePing networkMessagePing;
|
NetworkMessagePing networkMessagePing;
|
||||||
if(receiveMessage(&networkMessagePing)) {
|
if(receiveMessage(&networkMessagePing)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
lastPingInfo = networkMessagePing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -84,10 +84,8 @@ protected:
|
|||||||
bool networkGameDataSynchCheckOkTile;
|
bool networkGameDataSynchCheckOkTile;
|
||||||
bool networkGameDataSynchCheckOkTech;
|
bool networkGameDataSynchCheckOkTech;
|
||||||
|
|
||||||
//string chatText;
|
|
||||||
//string chatSender;
|
|
||||||
//int chatTeamIndex;
|
|
||||||
std::vector<ChatMsgInfo> chatTextList;
|
std::vector<ChatMsgInfo> chatTextList;
|
||||||
|
NetworkMessagePing lastPingInfo;
|
||||||
|
|
||||||
static DisplayMessageFunction pCB_DisplayMessage;
|
static DisplayMessageFunction pCB_DisplayMessage;
|
||||||
void DisplayErrorMessage(string sErr, bool closeSocket=true);
|
void DisplayErrorMessage(string sErr, bool closeSocket=true);
|
||||||
@@ -117,7 +115,6 @@ public:
|
|||||||
|
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
|
||||||
//virtual void setGameSettings(GameSettings *serverGameSettings) { gameSettings = *serverGameSettings; }
|
|
||||||
const virtual GameSettings * getGameSettings() { return &gameSettings; }
|
const virtual GameSettings * getGameSettings() { return &gameSettings; }
|
||||||
|
|
||||||
static void setAllowDownloadDataSynch(bool value) { allowDownloadDataSynch = value; }
|
static void setAllowDownloadDataSynch(bool value) { allowDownloadDataSynch = value; }
|
||||||
@@ -133,12 +130,6 @@ public:
|
|||||||
virtual bool getNetworkGameDataSynchCheckOkMap() { return networkGameDataSynchCheckOkMap; }
|
virtual bool getNetworkGameDataSynchCheckOkMap() { return networkGameDataSynchCheckOkMap; }
|
||||||
virtual bool getNetworkGameDataSynchCheckOkTile() { return networkGameDataSynchCheckOkTile; }
|
virtual bool getNetworkGameDataSynchCheckOkTile() { return networkGameDataSynchCheckOkTile; }
|
||||||
virtual bool getNetworkGameDataSynchCheckOkTech() { return networkGameDataSynchCheckOkTech; }
|
virtual bool getNetworkGameDataSynchCheckOkTech() { return networkGameDataSynchCheckOkTech; }
|
||||||
//virtual bool getNetworkGameDataSynchCheckOkFogOfWar() { return networkGameDataSynchCheckOkFogOfWar; }
|
|
||||||
//virtual void setNetworkGameDataSynchCheckOkFogOfWar(bool value) { networkGameDataSynchCheckOkFogOfWar = value; }
|
|
||||||
|
|
||||||
//const string getChatText() const {return chatText;}
|
|
||||||
//const string getChatSender() const {return chatSender;}
|
|
||||||
//int getChatTeamIndex() const {return chatTeamIndex;}
|
|
||||||
|
|
||||||
const std::vector<ChatMsgInfo> & getChatTextList() const { return chatTextList; }
|
const std::vector<ChatMsgInfo> & getChatTextList() const { return chatTextList; }
|
||||||
void clearChatInfo();
|
void clearChatInfo();
|
||||||
@@ -146,6 +137,11 @@ public:
|
|||||||
|
|
||||||
virtual bool getConnectHasHandshaked() const= 0;
|
virtual bool getConnectHasHandshaked() const= 0;
|
||||||
|
|
||||||
|
NetworkMessagePing getLastPingInfo() const { return lastPingInfo; }
|
||||||
|
double getLastPingLag() const {
|
||||||
|
return difftime(time(NULL),lastPingInfo.getPingTime());
|
||||||
|
}
|
||||||
|
|
||||||
std::string getIpAddress();
|
std::string getIpAddress();
|
||||||
float getThreadedPingMS(std::string host);
|
float getThreadedPingMS(std::string host);
|
||||||
|
|
||||||
|
@@ -690,6 +690,7 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess
|
|||||||
discard = true;
|
discard = true;
|
||||||
NetworkMessagePing msg = NetworkMessagePing();
|
NetworkMessagePing msg = NetworkMessagePing();
|
||||||
connectionSlot->receiveMessage(&msg);
|
connectionSlot->receiveMessage(&msg);
|
||||||
|
lastPingInfo = msg;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -91,6 +91,10 @@ public:
|
|||||||
bool isPortBound() const { return serverSocket.isPortBound(); }
|
bool isPortBound() const { return serverSocket.isPortBound(); }
|
||||||
int getBindPort() const { return serverSocket.getBindPort(); }
|
int getBindPort() const { return serverSocket.getBindPort(); }
|
||||||
|
|
||||||
|
void broadcastPing(const NetworkMessagePing* networkMessage, int excludeSlot= -1) {
|
||||||
|
this->broadcastMessage(networkMessage,excludeSlot);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
||||||
|
Reference in New Issue
Block a user