diff --git a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp index 66b4e0f2b40..6bd869f1bff 100644 --- a/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp @@ -420,21 +420,24 @@ void ConnectionManager::doRelay() { */ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) { NetCommandMsg *msg = ref->getCommand(); + NetCommandType cmdType = msg->getNetCommandType(); - if ((msg->getNetCommandType() == NETCOMMANDTYPE_ACKSTAGE1) || - (msg->getNetCommandType() == NETCOMMANDTYPE_ACKSTAGE2) || - (msg->getNetCommandType() == NETCOMMANDTYPE_ACKBOTH)) { - + // Handle ACK commands first (before connection validation) + if ((cmdType == NETCOMMANDTYPE_ACKSTAGE1) || + (cmdType == NETCOMMANDTYPE_ACKSTAGE2) || + (cmdType == NETCOMMANDTYPE_ACKBOTH)) { processAck(msg); return FALSE; } + // Early validation checks if ((m_connections[msg->getPlayerID()] == NULL) && (msg->getPlayerID() != m_localSlot)) { // if this is from a player that is no longer in the game, then ignore them. return TRUE; } - if (msg->getNetCommandType() == NETCOMMANDTYPE_WRAPPER) { + // Handle WRAPPER commands (before second connection validation) + if (cmdType == NETCOMMANDTYPE_WRAPPER) { processWrapper(ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command. return FALSE; } @@ -451,93 +454,84 @@ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) { // This was a fix for a command count bug where a command would be // executed, then a command for that old frame would be added to the // FrameData for that frame + 256, and would screw up the command count. - - if (IsCommandSynchronized(msg->getNetCommandType())) { + if (IsCommandSynchronized(cmdType)) { if (ref->getCommand()->getExecutionFrame() < TheGameLogic->getFrame()) { return TRUE; } } - if (msg->getNetCommandType() == NETCOMMANDTYPE_FRAMEINFO) { - processFrameInfo((NetFrameCommandMsg *)msg); - - // need to set the relay so we don't send it to ourselves. - UnsignedByte relay = ref->getRelay(); - relay = relay & (0xff ^ (1 << m_localSlot)); - ref->setRelay(relay); - return FALSE; + // Handle disconnect commands as a range + if ((cmdType > NETCOMMANDTYPE_DISCONNECTSTART) && (cmdType < NETCOMMANDTYPE_DISCONNECTEND)) { + m_disconnectManager->processDisconnectCommand(ref, this); + return TRUE; } - if (msg->getNetCommandType() == NETCOMMANDTYPE_PROGRESS) - { - //DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID())); - processProgress((NetProgressCommandMsg *) msg); + // Process command by type + switch (cmdType) { - // need to set the relay so we don't send it to ourselves. - UnsignedByte relay = ref->getRelay(); - relay = relay & (0xff ^ (1 << m_localSlot)); - ref->setRelay(relay); - return FALSE; - } + case NETCOMMANDTYPE_FRAMEINFO: { + processFrameInfo((NetFrameCommandMsg *)msg); + // need to set the relay so we don't send it to ourselves. + UnsignedByte relay = ref->getRelay(); + relay = relay & (0xff ^ (1 << m_localSlot)); + ref->setRelay(relay); + return FALSE; + } - if (msg->getNetCommandType() == NETCOMMANDTYPE_TIMEOUTSTART) - { - DEBUG_LOG(("ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d", msg->getPlayerID())); - processTimeOutGameStart(msg); - return FALSE; - } + case NETCOMMANDTYPE_PROGRESS: { + //DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID())); + processProgress((NetProgressCommandMsg *) msg); + // need to set the relay so we don't send it to ourselves. + UnsignedByte relay = ref->getRelay(); + relay = relay & (0xff ^ (1 << m_localSlot)); + ref->setRelay(relay); + return FALSE; + } - if (msg->getNetCommandType() == NETCOMMANDTYPE_RUNAHEADMETRICS) { - processRunAheadMetrics((NetRunAheadMetricsCommandMsg *)msg); - return TRUE; - } + case NETCOMMANDTYPE_TIMEOUTSTART: + DEBUG_LOG(("ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d", msg->getPlayerID())); + processTimeOutGameStart(msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_KEEPALIVE) { - return TRUE; - } + case NETCOMMANDTYPE_RUNAHEADMETRICS: + processRunAheadMetrics((NetRunAheadMetricsCommandMsg *)msg); + return TRUE; - if ((msg->getNetCommandType() > NETCOMMANDTYPE_DISCONNECTSTART) && (msg->getNetCommandType() < NETCOMMANDTYPE_DISCONNECTEND)) { - m_disconnectManager->processDisconnectCommand(ref, this); - return TRUE; - } + case NETCOMMANDTYPE_KEEPALIVE: + return TRUE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTCHAT) { - processDisconnectChat((NetDisconnectChatCommandMsg *)msg); - } + case NETCOMMANDTYPE_DISCONNECTCHAT: + processDisconnectChat((NetDisconnectChatCommandMsg *)msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_LOADCOMPLETE) - { - DEBUG_LOG(("ConnectionManager::processNetCommand - got a Load Complete net command from player %d", msg->getPlayerID())); - processLoadComplete(msg); - return FALSE; - } + case NETCOMMANDTYPE_LOADCOMPLETE: + DEBUG_LOG(("ConnectionManager::processNetCommand - got a Load Complete net command from player %d", msg->getPlayerID())); + processLoadComplete(msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_CHAT) { - processChat((NetChatCommandMsg *)msg); - return FALSE; - } + case NETCOMMANDTYPE_CHAT: + processChat((NetChatCommandMsg *)msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_FILE) { - processFile((NetFileCommandMsg *)msg); - return FALSE; - } + case NETCOMMANDTYPE_FILE: + processFile((NetFileCommandMsg *)msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_FILEANNOUNCE) { - processFileAnnounce((NetFileAnnounceCommandMsg *)msg); - return FALSE; - } + case NETCOMMANDTYPE_FILEANNOUNCE: + processFileAnnounce((NetFileAnnounceCommandMsg *)msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_FILEPROGRESS) { - processFileProgress((NetFileProgressCommandMsg *)msg); - return FALSE; - } + case NETCOMMANDTYPE_FILEPROGRESS: + processFileProgress((NetFileProgressCommandMsg *)msg); + return FALSE; - if (msg->getNetCommandType() == NETCOMMANDTYPE_FRAMERESENDREQUEST) { - processFrameResendRequest((NetFrameResendRequestCommandMsg *)msg); - return TRUE; - } + case NETCOMMANDTYPE_FRAMERESENDREQUEST: + processFrameResendRequest((NetFrameResendRequestCommandMsg *)msg); + return TRUE; - return FALSE; + default: + return FALSE; + } } void ConnectionManager::processFrameResendRequest(NetFrameResendRequestCommandMsg *msg) { diff --git a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp index 94268e63863..cd00da753c9 100644 --- a/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp +++ b/Core/GameEngine/Source/GameNetwork/DisconnectManager.cpp @@ -268,20 +268,38 @@ void DisconnectManager::updateWaitForPacketRouter(ConnectionManager *conMgr) { void DisconnectManager::processDisconnectCommand(NetCommandRef *ref, ConnectionManager *conMgr) { NetCommandMsg *msg = ref->getCommand(); - if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTKEEPALIVE) { - processDisconnectKeepAlive(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTPLAYER) { - processDisconnectPlayer(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_PACKETROUTERQUERY) { - processPacketRouterQuery(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_PACKETROUTERACK) { - processPacketRouterAck(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTVOTE) { - processDisconnectVote(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTFRAME) { - processDisconnectFrame(msg, conMgr); - } else if (msg->getNetCommandType() == NETCOMMANDTYPE_DISCONNECTSCREENOFF) { - processDisconnectScreenOff(msg, conMgr); + + switch (msg->getNetCommandType()) { + case NETCOMMANDTYPE_DISCONNECTKEEPALIVE: + processDisconnectKeepAlive(msg, conMgr); + break; + + case NETCOMMANDTYPE_DISCONNECTPLAYER: + processDisconnectPlayer(msg, conMgr); + break; + + case NETCOMMANDTYPE_PACKETROUTERQUERY: + processPacketRouterQuery(msg, conMgr); + break; + + case NETCOMMANDTYPE_PACKETROUTERACK: + processPacketRouterAck(msg, conMgr); + break; + + case NETCOMMANDTYPE_DISCONNECTVOTE: + processDisconnectVote(msg, conMgr); + break; + + case NETCOMMANDTYPE_DISCONNECTFRAME: + processDisconnectFrame(msg, conMgr); + break; + + case NETCOMMANDTYPE_DISCONNECTSCREENOFF: + processDisconnectScreenOff(msg, conMgr); + break; + + default: + break; } } diff --git a/Core/GameEngine/Source/GameNetwork/FirewallHelper.cpp b/Core/GameEngine/Source/GameNetwork/FirewallHelper.cpp index d8ffb64f340..f173050b636 100644 --- a/Core/GameEngine/Source/GameNetwork/FirewallHelper.cpp +++ b/Core/GameEngine/Source/GameNetwork/FirewallHelper.cpp @@ -204,47 +204,40 @@ Bool FirewallHelperClass::detectFirewall(void) Bool FirewallHelperClass::behaviorDetectionUpdate() { - if (m_currentState == DETECTIONSTATE_IDLE) { - return FALSE; - } - - if (m_currentState == DETECTIONSTATE_DONE) { - return TRUE; - } - - if (m_currentState == DETECTIONSTATE_BEGIN) { - return detectionBeginUpdate(); - } - - if (m_currentState == DETECTIONSTATE_TEST1) { - return detectionTest1Update(); - } - - if (m_currentState == DETECTIONSTATE_TEST2) { - return detectionTest2Update(); - } - - if (m_currentState == DETECTIONSTATE_TEST3) { - return detectionTest3Update(); - } - - if (m_currentState == DETECTIONSTATE_TEST3_WAITFORRESPONSES) { - return detectionTest3WaitForResponsesUpdate(); - } - - if (m_currentState == DETECTIONSTATE_TEST4_1) { - return detectionTest4Stage1Update(); - } - - if (m_currentState == DETECTIONSTATE_TEST4_2) { - return detectionTest4Stage2Update(); - } - - if (m_currentState == DETECTIONSTATE_TEST5) { - return detectionTest5Update(); + switch (m_currentState) { + case DETECTIONSTATE_IDLE: + return FALSE; + + case DETECTIONSTATE_DONE: + return TRUE; + + case DETECTIONSTATE_BEGIN: + return detectionBeginUpdate(); + + case DETECTIONSTATE_TEST1: + return detectionTest1Update(); + + case DETECTIONSTATE_TEST2: + return detectionTest2Update(); + + case DETECTIONSTATE_TEST3: + return detectionTest3Update(); + + case DETECTIONSTATE_TEST3_WAITFORRESPONSES: + return detectionTest3WaitForResponsesUpdate(); + + case DETECTIONSTATE_TEST4_1: + return detectionTest4Stage1Update(); + + case DETECTIONSTATE_TEST4_2: + return detectionTest4Stage2Update(); + + case DETECTIONSTATE_TEST5: + return detectionTest5Update(); + + default: + return TRUE; } - - return TRUE; } /***********************************************************************************************