diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index c759caac..818c4985 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -133,16 +133,16 @@ void ChatManager::keyPress(char c){ } } -void ChatManager::updateNetwork() -{ +void ChatManager::updateNetwork() { try { GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); string text; string sender; Config &config= Config::getInstance(); - if(!gameNetworkInterface->getChatText().empty()) - { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str()); + + if(gameNetworkInterface->getChatText().empty() == false) { int teamIndex= gameNetworkInterface->getChatTeamIndex(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex); @@ -154,6 +154,10 @@ void ChatManager::updateNetwork() } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + gameNetworkInterface->clearChatInfo(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } } catch(const std::exception &ex) { diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 57e99fae..3236e660 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -401,7 +401,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{ //validate command type if(ct == NULL) { char szBuf[1024]=""; - sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for network command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.", + sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for\nnetwork command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.", __FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf); diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 2bd41227..63bf2796 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -687,6 +687,9 @@ void ClientInterface::waitForMessage() if(chrono.getMillis() > messageWaitTimeout) { //throw runtime_error("Timeout waiting for message"); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + sendTextMessage("Timeout waiting for message",-1); DisplayErrorMessage("Timeout waiting for message"); quit= true; @@ -703,16 +706,17 @@ void ClientInterface::waitForMessage() void ClientInterface::quitGame(bool userManuallyQuit) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] userManuallyQuit = %d\n",__FILE__,__FUNCTION__,__LINE__,userManuallyQuit); if(clientSocket != NULL && userManuallyQuit == true) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; sendTextMessage(sQuitText,-1); close(); } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void ClientInterface::close() diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 1a3c5c50..0e284ce7 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -144,8 +144,10 @@ void ConnectionSlotThread::execute() { // class ConnectionSlot // ===================================================== -ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) -{ +ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) { + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + this->serverInterface = serverInterface; this->playerIndex = playerIndex; this->socket = NULL; @@ -153,8 +155,8 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface); this->slotThreadWorker->start(); - this->ready= false; - this->gotIntro = false; + this->ready = false; + this->gotIntro = false; networkGameDataSynchCheckOkMap = false; networkGameDataSynchCheckOkTile = false; @@ -256,7 +258,7 @@ void ConnectionSlot::update(bool checkForNewClients) { chatSender = networkMessageText.getSender(); chatTeamIndex = networkMessageText.getTeamIndex(); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); } } break; @@ -480,7 +482,7 @@ void ConnectionSlot::update(bool checkForNewClients) { } } else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling close...\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__); close(); } @@ -496,9 +498,14 @@ void ConnectionSlot::update(bool checkForNewClients) { void ConnectionSlot::close() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); - BaseThread::shutdownAndWait(slotThreadWorker); - delete slotThreadWorker; - slotThreadWorker = NULL; + // In case we are closing from within the context of the thread + // only signal it to quit here + //if(slotThreadWorker != NULL) { + // slotThreadWorker->signalQuit(); + //} + //BaseThread::shutdownAndWait(slotThreadWorker); + //delete slotThreadWorker; + //slotThreadWorker = NULL; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -507,14 +514,18 @@ void ConnectionSlot::close() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chatText.clear(); - chatSender.clear(); - chatTeamIndex= -1; + //chatText.clear(); + //chatSender.clear(); + //chatTeamIndex= -1; + + if(ready == false) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); + serverInterface->updateListen(); + } + ready = false; gotIntro = false; - serverInterface->updateListen(); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 7e2e2008..9bbcae75 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -108,8 +108,14 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) { else { throw runtime_error(sErr); } +} +void NetworkInterface::clearChatInfo() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + chatText.clear(); + chatSender.clear(); + chatTeamIndex= -1; } // ===================================================== diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index edd2b55c..b0ef8b30 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -101,6 +101,8 @@ public: const string getChatSender() const {return chatSender;} int getChatTeamIndex() const {return chatTeamIndex;} + void clearChatInfo(); + virtual bool getConnectHasHandshaked() const= 0; }; diff --git a/source/glest_game/network/network_types.cpp b/source/glest_game/network/network_types.cpp index aca0348f..57874aaa 100644 --- a/source/glest_game/network/network_types.cpp +++ b/source/glest_game/network/network_types.cpp @@ -44,6 +44,9 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, //validate unit if(unit != NULL) { + this->unitFactionIndex = unit->getFaction()->getIndex(); + this->unitFactionUnitCount = unit->getFaction()->getUnitCount(); + const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId); if(ct != NULL && ct->getClass() == ccBuild) { @@ -75,8 +78,8 @@ void NetworkCommand::preprocessNetworkCommand(World *world) { string NetworkCommand::toString() const { char szBuf[1024]=""; - sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d", - networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex); + sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d\nunitFactionUnitCount = %d\nunitFactionIndex = %d", + networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex,unitFactionUnitCount,unitFactionIndex); string result = szBuf; return result; diff --git a/source/glest_game/network/network_types.h b/source/glest_game/network/network_types.h index 08fa4e96..997b1f86 100644 --- a/source/glest_game/network/network_types.h +++ b/source/glest_game/network/network_types.h @@ -69,6 +69,8 @@ private: int16 targetId; int16 wantQueue; int16 fromFactionIndex; + int16 unitFactionUnitCount; + int16 unitFactionIndex; public: NetworkCommand(){}; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index bf8483c9..25dd5f77 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -199,9 +199,9 @@ void ServerInterface::update() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - chatText.clear(); - chatSender.clear(); - chatTeamIndex= -1; + //chatText.clear(); + //chatSender.clear(); + //chatTeamIndex= -1; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); @@ -328,18 +328,26 @@ void ServerInterface::update() { // Step #4 dispatch pending chat messages for(int i= 0; i< GameConstants::maxPlayers; ++i) { ConnectionSlot* connectionSlot= slots[i]; - if(connectionSlot != NULL && connectionSlot->isConnected() == true && + if(connectionSlot != NULL && connectionSlot->getChatText().empty() == false) { - chatText = connectionSlot->getChatText(); - chatSender = connectionSlot->getChatSender(); - chatTeamIndex = connectionSlot->getChatTeamIndex(); + string newChatText = connectionSlot->getChatText().c_str(); + string newChatSender = connectionSlot->getChatSender().c_str(); + int newChatTeamIndex = connectionSlot->getChatTeamIndex(); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatSender.c_str(),newChatTeamIndex); - NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex); + NetworkMessageText networkMessageText(newChatText,newChatSender,newChatTeamIndex); broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex()); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatSender.c_str(),newChatTeamIndex); + + connectionSlot->clearChatInfo(); + + chatText = newChatText.c_str(); + chatSender = newChatSender.c_str(); + chatTeamIndex = newChatTeamIndex; + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after connectionSlot->clearChatInfo chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); } } @@ -347,9 +355,10 @@ void ServerInterface::update() { //process text messages if(chatText.empty() == true) { - chatText.clear(); - chatSender.clear(); - chatTeamIndex= -1; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //chatText.clear(); + //chatSender.clear(); + //chatTeamIndex= -1; for(int i= 0; i< GameConstants::maxPlayers; ++i) { ConnectionSlot* connectionSlot= slots[i];