From 81cc68305c34fdd71a5f6fb6e5f8b4dced8c092f Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 13 Jun 2012 16:19:44 +0000 Subject: [PATCH] - added the ability to remove cell markers --- source/glest_game/game/game.cpp | 92 +++++++++++++++++++ source/glest_game/game/game.h | 7 ++ source/glest_game/graphics/renderer.cpp | 4 + .../glest_game/network/client_interface.cpp | 45 +++++++++ source/glest_game/network/client_interface.h | 1 + source/glest_game/network/connection_slot.cpp | 29 ++++++ .../glest_game/network/network_interface.cpp | 19 ++++ source/glest_game/network/network_interface.h | 34 +++++++ source/glest_game/network/network_message.cpp | 29 ++++++ source/glest_game/network/network_message.h | 37 +++++++- .../glest_game/network/server_interface.cpp | 86 ++++++++++++++--- source/glest_game/network/server_interface.h | 4 + 12 files changed, 375 insertions(+), 12 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 1ca8ccf6..21d23a74 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -115,10 +115,13 @@ Game::Game() : ProgramState(NULL) { saveGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1; markCellPopupMenuIndex = -1; + unmarkCellPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1; isMarkCellEnabled = false; markCellTexture = NULL; + isUnMarkCellEnabled = false; + unmarkCellTexture = NULL; masterserverMode = false; currentUIState=NULL; @@ -167,10 +170,13 @@ void Game::resetMembers() { saveGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1; markCellPopupMenuIndex = -1; + unmarkCellPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1; isMarkCellEnabled = false; markCellTexture = NULL; + isUnMarkCellEnabled = false; + unmarkCellTexture = NULL; currentUIState = NULL; @@ -741,6 +747,8 @@ void Game::load(int loadTypes) { string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); const string markCellTextureFilename = data_path + "data/core/misc_textures/mark_cell.png"; markCellTexture = Renderer::findFactionLogoTexture(markCellTextureFilename); + const string unmarkCellTextureFilename = data_path + "data/core/misc_textures/unmark_cell.png"; + unmarkCellTexture = Renderer::findFactionLogoTexture(unmarkCellTextureFilename); string scenarioDir = ""; if(gameSettings.getScenarioDir() != "") { @@ -1153,6 +1161,8 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) { menuItems.push_back(lang.get("MarkCell")); markCellPopupMenuIndex = menuItems.size()-1; + menuItems.push_back(lang.get("UnMarkCell")); + unmarkCellPopupMenuIndex = menuItems.size()-1; if(allowAdminMenuItems == true){ menuItems.push_back(lang.get("PauseResumeGame")); @@ -1383,6 +1393,7 @@ void Game::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); updateNetworkMarkedCells(); + updateNetworkUnMarkedCells(); //check for quiting status if(NetworkManager::getInstance().getGameNetworkInterface() != NULL && @@ -1578,6 +1589,33 @@ void Game::updateNetworkMarkedCells() { } } +void Game::updateNetworkUnMarkedCells() { + try { + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + + if(gameNetworkInterface != NULL && + gameNetworkInterface->getUnMarkedCellList(false).empty() == false) { + Lang &lang= Lang::getInstance(); + + std::vector chatList = gameNetworkInterface->getUnMarkedCellList(true); + for(int idx = 0; idx < chatList.size(); idx++) { + UnMarkedCell mc = chatList[idx]; + mc.setFaction((const Faction *)world.getFaction(mc.getFactionIndex())); + + Map *map= world.getMap(); + Vec2i surfaceCellPos = map->toSurfCoords(mc.getTargetPos()); + mapMarkedCellList.erase(surfaceCellPos); + } + } + } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + throw megaglest_runtime_error(szBuf); + } +} + void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRole role) { if(role == nrServer && isNetworkGame == true && difftime(time(NULL),lastNetworkPlayerConnectionCheck) >= NETWORK_PLAYER_CONNECTION_CHECK_SECONDS) { @@ -1916,6 +1954,7 @@ void Game::mouseDownLeft(int x, int y) { NetworkManager &networkManager= NetworkManager::getInstance(); bool messageBoxClick= false; bool originalIsMarkCellEnabled = isMarkCellEnabled; + bool originalIsUnMarkCellEnabled = isUnMarkCellEnabled; if(popupMenu.mouseClick(x, y)) { std::pair result = popupMenu.mouseClickedMenuItem(x, y); @@ -2015,6 +2054,9 @@ void Game::mouseDownLeft(int x, int y) { else if(result.first == markCellPopupMenuIndex) { isMarkCellEnabled = true; } + else if(result.first == unmarkCellPopupMenuIndex) { + isUnMarkCellEnabled = true; + } } else if(popupMenuSwitchTeams.mouseClick(x, y)) { //popupMenuSwitchTeams @@ -2115,6 +2157,30 @@ void Game::mouseDownLeft(int x, int y) { isMarkCellEnabled = false; + Renderer &renderer= Renderer::getInstance(); + //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); + renderer.forceQuadCacheUpdate(); + } + if(originalIsUnMarkCellEnabled == true && isUnMarkCellEnabled == true) { + Vec2i surfaceCellPos = map->toSurfCoords(Vec2i(xCell,yCell)); + SurfaceCell *sc = map->getSurfaceCell(surfaceCellPos); + Vec3f vertex = sc->getVertex(); + Vec2i targetPos(vertex.x,vertex.z); + + //MarkedCell mc(targetPos,world.getThisFaction(),"placeholder for note"); + //mapMarkedCellList[surfaceCellPos] = mc; + if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) { + MarkedCell mc = mapMarkedCellList[surfaceCellPos]; + if(mc.getFaction() == world.getThisFaction()) { + mapMarkedCellList.erase(surfaceCellPos); + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(),mc.getFaction()->getIndex()); + } + } + //printf("#1 ADDED in marked list pos [%s] markedCells.size() = %lu\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size()); + + isUnMarkCellEnabled = false; + Renderer &renderer= Renderer::getInstance(); //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); renderer.forceQuadCacheUpdate(); @@ -2156,6 +2222,32 @@ void Game::mouseDownLeft(int x, int y) { //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); renderer.forceQuadCacheUpdate(); } + + if(originalIsUnMarkCellEnabled == true && isUnMarkCellEnabled == true) { + Vec2i targetPos; + Vec2i screenPos(x,y); + Renderer &renderer= Renderer::getInstance(); + renderer.computePosition(screenPos, targetPos); + Vec2i surfaceCellPos = map->toSurfCoords(targetPos); + + //MarkedCell mc(targetPos,world.getThisFaction(),"placeholder for note"); + //mapMarkedCellList[surfaceCellPos] = mc; + if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) { + MarkedCell mc = mapMarkedCellList[surfaceCellPos]; + if(mc.getFaction() == world.getThisFaction()) { + mapMarkedCellList.erase(surfaceCellPos); + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(),mc.getFaction()->getIndex()); + } + } + //printf("#1 ADDED in marked list pos [%s] markedCells.size() = %lu\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size()); + + isUnMarkCellEnabled = false; + + //Renderer &renderer= Renderer::getInstance(); + //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); + renderer.forceQuadCacheUpdate(); + } } } diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 58cd21cf..e7e19c5e 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -149,12 +149,15 @@ private: int saveGamePopupMenuIndex; int loadGamePopupMenuIndex; int markCellPopupMenuIndex; + int unmarkCellPopupMenuIndex; int keyboardSetupPopupMenuIndex; //GLuint statelist3dMenu; ProgramState *currentUIState; bool isMarkCellEnabled; Texture2D *markCellTexture; + bool isUnMarkCellEnabled; + Texture2D *unmarkCellTexture; std::map mapMarkedCellList; bool masterserverMode; @@ -179,6 +182,9 @@ public: bool isMarkCellMode() const { return isMarkCellEnabled; } const Texture2D * getMarkCellTexture() const { return markCellTexture; } + bool isUnMarkCellMode() const { return isUnMarkCellEnabled; } + const Texture2D * getUnMarkCellTexture() const { return unmarkCellTexture; } + std::map getMapMarkedCellList() const { return mapMarkedCellList; } bool isMasterserverMode() const { return masterserverMode; } @@ -306,6 +312,7 @@ private: void renderVideoPlayer(); void updateNetworkMarkedCells(); + void updateNetworkUnMarkedCells(); }; }}//end namespace diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 73ea7a7d..13e0fbb0 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1611,6 +1611,10 @@ void Renderer::renderMouse2d(int x, int y, int anim, float fade) { const Texture2D *texture= game->getMarkCellTexture(); renderTextureQuad(x-18,y-50,32,32,texture,0.8f); } + if(game->isUnMarkCellMode() == true) { + const Texture2D *texture= game->getUnMarkCellTexture(); + renderTextureQuad(x-18,y-50,32,32,texture,0.8f); + } } float color1 = 0.0, color2 = 0.0; diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 89f1178d..14f643cd 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -484,6 +484,18 @@ void ClientInterface::updateLobby() { } } break; + case nmtUnMarkCell: + { + NetworkMessageUnMarkCell networkMessageMarkCell; + if(receiveMessage(&networkMessageMarkCell)) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + + UnMarkedCell msg(networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + this->addUnMarkedCell(msg); + } + } + break; case nmtLaunch: case nmtBroadCastSetup: @@ -698,6 +710,19 @@ void ClientInterface::updateFrame(int *checkFrame) { this->addMarkedCell(msg); } } + break; + + case nmtUnMarkCell: + { + NetworkMessageUnMarkCell networkMessageMarkCell; + if(receiveMessage(&networkMessageMarkCell)) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + + UnMarkedCell msg(networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + this->addUnMarkedCell(msg); + } + } break; case nmtLaunch: @@ -1200,6 +1225,14 @@ void ClientInterface::sendMarkCellMessage(Vec2i targetPos, int factionIndex, str sendMessage(&networkMessageMarkCell); } +void ClientInterface::sendUnMarkCellMessage(Vec2i targetPos, int factionIndex) { + string humanPlayerName = getHumanPlayerName(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); + + NetworkMessageUnMarkCell networkMessageMarkCell(targetPos,factionIndex); + sendMessage(&networkMessageMarkCell); +} + void ClientInterface::sendPingMessage(int32 pingFrequency, int64 pingTime) { NetworkMessagePing networkMessagePing(pingFrequency,pingTime); sendMessage(&networkMessagePing); @@ -1401,6 +1434,18 @@ bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess } break; + case nmtUnMarkCell: + { + discard = true; + NetworkMessageUnMarkCell networkMessageMarkCell; + receiveMessage(&networkMessageMarkCell); + + UnMarkedCell msg(networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + this->addUnMarkedCell(msg); + } + break; + case nmtSynchNetworkGameData: { discard = true; diff --git a/source/glest_game/network/client_interface.h b/source/glest_game/network/client_interface.h index 5cef02ee..0a4d3c0d 100644 --- a/source/glest_game/network/client_interface.h +++ b/source/glest_game/network/client_interface.h @@ -87,6 +87,7 @@ public: virtual void quitGame(bool userManuallyQuit); virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note); + virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex); //misc virtual string getNetworkStatus() ; diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index ce36c340..e2481475 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -590,6 +590,35 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } break; + case nmtUnMarkCell: + { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtUnMarkCell gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro); + + if(gotIntro == true) { + NetworkMessageUnMarkCell networkMessageMarkCell; + if(receiveMessage(&networkMessageMarkCell)) { + UnMarkedCell msg(networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + + this->addUnMarkedCell(msg); + //gotTextMsg = true; + } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); + this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); + close(); + return; + } + } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); + this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); + close(); + return; + } + } + break; + //command list case nmtCommandList: { diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index fd735253..732bc7af 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -146,6 +146,25 @@ void NetworkInterface::clearMarkedCellList() { } } +std::vector NetworkInterface::getUnMarkedCellList(bool clearList) { + std::vector result; + if(unmarkedCellList.empty() == false) { + result = unmarkedCellList; + + if(clearList == true) { + unmarkedCellList.clear(); + } + } + return result; +} + +void NetworkInterface::clearUnMarkedCellList() { + if(unmarkedCellList.empty() == false) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unmarkedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,unmarkedCellList.size()); + unmarkedCellList.clear(); + } +} + std::string NetworkInterface::getIpAddress() { std::string result = ""; diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index e5e36816..bdf97468 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -115,6 +115,34 @@ public: string getNote() const { return note; } }; +class UnMarkedCell { +protected: + Vec2i targetPos; + const Faction *faction; + int factionIndex; + +public: + UnMarkedCell() { + faction = NULL; + factionIndex = -1; + } + UnMarkedCell(Vec2i targetPos,const Faction *faction) { + this->targetPos = targetPos; + this->faction = faction; + this->factionIndex = -1; + } + UnMarkedCell(Vec2i targetPos,int factionIndex) { + this->targetPos = targetPos; + this->faction = NULL; + this->factionIndex = factionIndex; + } + + Vec2i getTargetPos() const { return targetPos; } + const Faction * getFaction() const { return faction; } + void setFaction(const Faction *faction) { this->faction = faction; } + int getFactionIndex() const { return factionIndex; } +}; + typedef int (*DisplayMessageFunction)(const char *msg, bool exit); class NetworkInterface { @@ -131,6 +159,7 @@ protected: std::vector chatTextList; NetworkMessagePing lastPingInfo; std::vector markedCellList; + std::vector unmarkedCellList; static DisplayMessageFunction pCB_DisplayMessage; void DisplayErrorMessage(string sErr, bool closeSocket=true); @@ -186,6 +215,10 @@ public: void clearMarkedCellList(); void addMarkedCell(const MarkedCell &msg) { markedCellList.push_back(msg); } + std::vector getUnMarkedCellList(bool clearList); + void clearUnMarkedCellList(); + void addUnMarkedCell(const UnMarkedCell &msg) { unmarkedCellList.push_back(msg); } + virtual bool getConnectHasHandshaked() const= 0; NetworkMessagePing getLastPingInfo() const { return lastPingInfo; } @@ -239,6 +272,7 @@ public: virtual void quitGame(bool userManuallyQuit)=0; virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note) = 0; + virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex) = 0; //misc virtual string getNetworkStatus() = 0; diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index c002ad23..b83d10fd 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -1014,4 +1014,33 @@ void NetworkMessageMarkCell::send(Socket* socket) const{ NetworkMessage::send(socket, &data, sizeof(data)); } +// ===================================================== +// class NetworkMessageUnMarkCell +// ===================================================== + +NetworkMessageUnMarkCell::NetworkMessageUnMarkCell(Vec2i target, int factionIndex) { + data.messageType = nmtUnMarkCell; + data.targetX = target.x; + data.targetY = target.y; + data.factionIndex = factionIndex; +} + +NetworkMessageUnMarkCell * NetworkMessageUnMarkCell::getCopy() const { + NetworkMessageUnMarkCell *copy = new NetworkMessageUnMarkCell(); + copy->data = this->data; + return copy; +} + +bool NetworkMessageUnMarkCell::receive(Socket* socket){ + bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + return result; +} + +void NetworkMessageUnMarkCell::send(Socket* socket) const{ + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtUnMarkCell\n",__FILE__,__FUNCTION__,__LINE__); + + assert(data.messageType == nmtUnMarkCell); + NetworkMessage::send(socket, &data, sizeof(data)); +} + }}//end namespace diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 29884f1a..fb54e64c 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -44,6 +44,7 @@ enum NetworkMessageType { nmtPlayerIndexMessage, nmtLoadingStatusMessage, nmtMarkCell, + nmtUnMarkCell, nmtCount }; @@ -731,7 +732,7 @@ public: // ===================================================== -// class NetworkMessageText +// class NetworkMessageMarkCell // // Mark a Cell message nmtMarkCell // ===================================================== @@ -768,6 +769,40 @@ public: }; #pragma pack(pop) +// ===================================================== +// class NetworkUnMessageMarkCell +// +// Mark a Cell message nmtUnMarkCell +// ===================================================== + +#pragma pack(push, 1) +class NetworkMessageUnMarkCell: public NetworkMessage { + +private: + struct Data{ + int8 messageType; + + int16 targetX; + int16 targetY; + int8 factionIndex; + }; + +private: + Data data; + +public: + NetworkMessageUnMarkCell(){} + NetworkMessageUnMarkCell(Vec2i target, int factionIndex); + + Vec2i getTarget() const { return Vec2i(data.targetX,data.targetY); } + int getFactionIndex() const { return data.factionIndex; } + + virtual bool receive(Socket* socket); + virtual void send(Socket* socket) const; + NetworkMessageUnMarkCell * getCopy() const; +}; +#pragma pack(pop) + }}//end namespace #endif diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index f753f315..877fd8c1 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1133,6 +1133,45 @@ void ServerInterface::dispatchPendingMarkCellMessages(std::vector &erro } } +void ServerInterface::dispatchPendingUnMarkCellMessages(std::vector &errorMsgList) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { + MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); + ConnectionSlot* connectionSlot= slots[i]; + if(connectionSlot != NULL && + connectionSlot->getUnMarkedCellList(false).empty() == false) { + try { + std::vector chatText = connectionSlot->getUnMarkedCellList(true); + for(int chatIdx = 0; + exitServer == false && slots[i] != NULL && + chatIdx < chatText.size(); chatIdx++) { + connectionSlot= slots[i]; + if(connectionSlot != NULL) { + UnMarkedCell msg(chatText[chatIdx]); + this->addUnMarkedCell(msg); + + NetworkMessageUnMarkCell networkMessageMarkCell(msg.getTargetPos(),msg.getFactionIndex()); + broadcastMessage(&networkMessageMarkCell, connectionSlot->getPlayerIndex(),i); + + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + } + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); + // Its possible that the slot is disconnected here + // so check the original pointer again + if(slots[i] != NULL) { + slots[i]->clearUnMarkedCellList(); + } + } + catch(const exception &ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + errorMsgList.push_back(ex.what()); + } + } + } +} + void ServerInterface::update() { Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); @@ -1206,6 +1245,7 @@ void ServerInterface::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); dispatchPendingMarkCellMessages(errorMsgList); + dispatchPendingUnMarkCellMessages(errorMsgList); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } @@ -1386,17 +1426,6 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess this->addMarkedCell(msg); -// string newChatText = msg.chatText.c_str(); -// //string newChatSender = msg.chatSender.c_str(); -// int newChatTeamIndex = msg.chatTeamIndex; -// int newChatPlayerIndex = msg.chatPlayerIndex; -// string newChatLanguage = msg.targetLanguage.c_str(); -// -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); -// -// NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex,newChatLanguage); -// broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex()); - NetworkMessageMarkCell networkMessageMarkCellBroadcast( networkMessageMarkCell.getTarget(), networkMessageMarkCell.getFactionIndex(), @@ -1408,6 +1437,27 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess } break; + case nmtUnMarkCell: + { + discard = true; + NetworkMessageUnMarkCell networkMessageMarkCell; + connectionSlot->receiveMessage(&networkMessageMarkCell); + + UnMarkedCell msg(networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + + this->addUnMarkedCell(msg); + + NetworkMessageUnMarkCell networkMessageMarkCellBroadcast( + networkMessageMarkCell.getTarget(), + networkMessageMarkCell.getFactionIndex()); + broadcastMessage(&networkMessageMarkCellBroadcast, connectionSlot->getPlayerIndex()); + + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + + } + break; + case nmtSynchNetworkGameData: { discard = true; @@ -1763,6 +1813,20 @@ void ServerInterface::sendMarkCellMessage(Vec2i targetPos, int factionIndex, str if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } +void ServerInterface::sendUnMarkCellMessage(Vec2i targetPos, int factionIndex) { + sendUnMarkCellMessage(targetPos, factionIndex, -1); +} + +void ServerInterface::sendUnMarkCellMessage(Vec2i targetPos, int factionIndex, int lockedSlotIndex) { + //printf("Line: %d text [%s] echoLocal = %d\n",__LINE__,text.c_str(),echoLocal); + //assert(text.length() > 0); + + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); + NetworkMessageUnMarkCell networkMessageMarkCell(targetPos,factionIndex); + broadcastMessage(&networkMessageMarkCell, -1, lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +} + void ServerInterface::quitGame(bool userManuallyQuit) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); NetworkMessageQuit networkMessageQuit; diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 9abc1a77..dcd6d154 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -119,6 +119,9 @@ public: virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note); void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note, int lockedSlotIndex); + virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex); + void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex, int lockedSlotIndex); + virtual void quitGame(bool userManuallyQuit); virtual string getNetworkStatus(); ServerSocket *getServerSocket() @@ -230,6 +233,7 @@ protected: void executeNetworkCommandsFromClients(); void dispatchPendingChatMessages(std::vector &errorMsgList); void dispatchPendingMarkCellMessages(std::vector &errorMsgList); + void dispatchPendingUnMarkCellMessages(std::vector &errorMsgList); void shutdownMasterserverPublishThread(); };