- added queued broadcast message ability and tried to fix tomreyn's fuzzer program issue

This commit is contained in:
Mark Vejvoda 2011-01-12 00:16:50 +00:00
parent d622c7bf7f
commit 26a382bd64
3 changed files with 44 additions and 5 deletions

View File

@ -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();

View File

@ -605,6 +605,7 @@ void ServerInterface::update() {
validateConnectedClients();
processTextMessageQueue();
processBroadCastMessageQueue();
std::map<PLATFORM_SOCKET,bool> 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<const NetworkMessage *,int> &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<const NetworkMessage *,int> 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);

View File

@ -67,6 +67,9 @@ private:
Mutex textMessageQueueThreadAccessor;
vector<TextMessageQueue> textMessageQueue;
Mutex broadcastMessageQueueThreadAccessor;
vector<pair<const NetworkMessage *,int> > 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