diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index e323749d2..4b187b174 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1347,7 +1347,13 @@ void MenuStateCustomGame::render() { catch(const std::exception &ex) { char szBuf[4096]=""; sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - throw runtime_error(szBuf); + //throw runtime_error(szBuf); + + SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + //throw runtime_error(szBuf);!!! + showGeneralError=true; + generalErrorToShow = ex.what(); } } @@ -1950,8 +1956,11 @@ void MenuStateCustomGame::simpleTask(BaseThread *callingThread) { ServerInterface *serverInterface= NetworkManager::getInstance().getServerInterface(false); if(serverInterface != NULL) { - NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL)); - serverInterface->broadcastPing(&msg); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + NetworkMessagePing *msg = new NetworkMessagePing(GameConstants::networkPingInterval,time(NULL)); + //serverInterface->broadcastPing(&msg); + serverInterface->queueBroadcastMessage(msg); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } } safeMutex.ReleaseLock(); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 378df7402..57d7d8f51 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -605,6 +605,7 @@ void ServerInterface::update() { validateConnectedClients(); processTextMessageQueue(); + processBroadCastMessageQueue(); std::map socketTriggeredList; //update all slots @@ -1099,10 +1100,34 @@ void ServerInterface::waitUntilReady(Checksum* checksum) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] END\n",__FUNCTION__); } +void ServerInterface::processBroadCastMessageQueue() { + MutexSafeWrapper safeMutexSlot(&broadcastMessageQueueThreadAccessor,intToStr(__LINE__)); + if(broadcastMessageQueue.size() > 0) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] broadcastMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,broadcastMessageQueue.size()); + for(int i = 0; i < broadcastMessageQueue.size(); ++i) { + pair &item = broadcastMessageQueue[i]; + if(item.first != NULL) { + this->broadcastMessage(item.first,item.second); + delete item.first; + } + item.first = NULL; + } + broadcastMessageQueue.clear(); + } +} + +void ServerInterface::queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot) { + MutexSafeWrapper safeMutexSlot(&broadcastMessageQueueThreadAccessor,intToStr(__LINE__)); + pair item; + item.first = networkMessage; + item.second = excludeSlot; + broadcastMessageQueue.push_back(item); +} + void ServerInterface::processTextMessageQueue() { MutexSafeWrapper safeMutexSlot(&textMessageQueueThreadAccessor,intToStr(__LINE__)); if(textMessageQueue.size() > 0) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] textMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,textMessageQueue.size()); for(int i = 0; i < textMessageQueue.size(); ++i) { TextMessageQueue &item = textMessageQueue[i]; sendTextMessage(item.text, item.teamIndex, item.echoLocal); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 0e8a44798..6d6ad457c 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -67,6 +67,9 @@ private: Mutex textMessageQueueThreadAccessor; vector textMessageQueue; + Mutex broadcastMessageQueueThreadAccessor; + vector > broadcastMessageQueue; + public: ServerInterface(); virtual ~ServerInterface(); @@ -84,7 +87,6 @@ public: // message sending virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false); void sendTextMessage(const string &text, int teamIndex, bool echoLocal, int lockedSlotIndex); - void queueTextMessage(const string &text, int teamIndex, bool echoLocal=false); virtual void quitGame(bool userManuallyQuit); @@ -125,6 +127,8 @@ public: this->broadcastMessage(networkMessage,excludeSlot); } + void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot=-1); + virtual string getHumanPlayerName(int index=-1); virtual int getHumanPlayerIndex() const; @@ -152,6 +156,7 @@ private: int64 getNextEventId(); void processTextMessageQueue(); + void processBroadCastMessageQueue(); }; }}//end namespace