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