diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index f5a92b568..8ab52bdac 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -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 { - lastNetworkSendPing = time(NULL); + lastNetworkSendPing = 0; returnMenuInfo=joinMenuInfo; Lang &lang= Lang::getInstance(); @@ -362,17 +362,19 @@ void MenuStateConnectedGame::update() ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); Lang &lang= Lang::getInstance(); - if(difftime(time(NULL),lastNetworkSendPing) >= GameConstants::networkPingInterval) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__); + if(clientInterface != NULL && clientInterface->isConnected()) { + if(difftime(time(NULL),lastNetworkSendPing) >= GameConstants::networkPingInterval) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__); - bool isFirstPing = (lastNetworkSendPing == 0); - lastNetworkSendPing = time(NULL); - clientInterface->sendPingMessage(GameConstants::networkPingInterval, 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(); + 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(); + } } } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index c5e281125..a8688b2d6 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1163,6 +1163,7 @@ void MenuStateCustomGame::simpleTask() { if(needPing == true) { lastNetworkPing = time(NULL); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] Sending nmtPing to clients\n",__FILE__,__FUNCTION__,__LINE__); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL)); serverInterface->broadcastPing(&msg);