more bullet proofing of network activity

This commit is contained in:
Mark Vejvoda 2010-05-13 07:13:53 +00:00
parent 57d0420b76
commit 4fc043ddb6
6 changed files with 27 additions and 4 deletions

View File

@ -654,6 +654,7 @@ void MenuStateCustomGame::update()
publishToMasterserver();
}
/*
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
{
GameSettings gameSettings;
@ -661,6 +662,7 @@ void MenuStateCustomGame::update()
serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings);
}
*/
//call the chat manager
chatManager.updateNetwork();
@ -735,15 +737,27 @@ void MenuStateCustomGame::publishToMasterserver()
void MenuStateCustomGame::simpleTask() {
if( needToRepublishToMasterserver == true &&
difftime(time(NULL),lastMasterserverPublishing) >= 5) {
difftime(time(NULL),lastMasterserverPublishing) >= 5 &&
publishToServerInfo != "") {
needToRepublishToMasterserver = false;
lastMasterserverPublishing = time(NULL);
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + publishToServerInfo;
publishToServerInfo = "";
printf("the request is:\n%s\n",request.c_str());
std::string serverInfo = SystemFlags::getHTTP(request);
}
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
{
lastSetChangedGameSettings = time(NULL);
GameSettings gameSettings;
loadGameSettings(&gameSettings);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings);
}
}
void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings)

View File

@ -85,6 +85,7 @@ public:
void stopServerDiscovery();
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam);
virtual bool getConnectHasHandshaked() const { return gotIntro; }
private:
void waitForMessage();

View File

@ -64,6 +64,7 @@ public:
void setReceivedNetworkGameStatus(bool value) { receivedNetworkGameStatus = value; }
bool hasValidSocketId();
virtual bool getConnectHasHandshaked() const { return gotIntro; }
};
}}//end namespace

View File

@ -68,8 +68,13 @@ NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasDataFirst)
}
//sanity check new message type
if(messageType<0 || messageType>=nmtCount){
throw runtime_error("Invalid message type: " + intToStr(messageType));
if(messageType < 0 || messageType >= nmtCount) {
if(getConnectHasHandshaked() == true) {
throw runtime_error("Invalid message type: " + intToStr(messageType));
}
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Invalid message type = %d (no packet handshake yet so ignored)\n",__FILE__,__FUNCTION__,__LINE__,messageType);
}
}
}

View File

@ -48,7 +48,6 @@ protected:
bool networkGameDataSynchCheckOkMap;
bool networkGameDataSynchCheckOkTile;
bool networkGameDataSynchCheckOkTech;
//bool networkGameDataSynchCheckOkFogOfWar;
string chatText;
string chatSender;
@ -99,6 +98,8 @@ public:
const string getChatText() const {return chatText;}
const string getChatSender() const {return chatSender;}
int getChatTeamIndex() const {return chatTeamIndex;}
virtual bool getConnectHasHandshaked() const= 0;
};
// =====================================================

View File

@ -79,6 +79,7 @@ public:
virtual void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck = false);
void broadcastGameSetup(const GameSettings* gameSettings);
void updateListen();
virtual bool getConnectHasHandshaked() const { return false; }
private:
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);