@@ -420,21 +420,24 @@ void ConnectionManager::doRelay() {
420420 */
421421Bool ConnectionManager::processNetCommand (NetCommandRef *ref) {
422422 NetCommandMsg *msg = ref->getCommand ();
423+ NetCommandType cmdType = msg->getNetCommandType ();
423424
424- if ((msg-> getNetCommandType () == NETCOMMANDTYPE_ACKSTAGE1) ||
425- (msg-> getNetCommandType () == NETCOMMANDTYPE_ACKSTAGE2 ) ||
426- (msg-> getNetCommandType () == NETCOMMANDTYPE_ACKBOTH)) {
427-
425+ // Handle ACK commands first (before connection validation)
426+ if ((cmdType == NETCOMMANDTYPE_ACKSTAGE1 ) ||
427+ (cmdType == NETCOMMANDTYPE_ACKSTAGE2) ||
428+ (cmdType == NETCOMMANDTYPE_ACKBOTH)) {
428429 processAck (msg);
429430 return FALSE ;
430431 }
431432
433+ // Early validation checks
432434 if ((m_connections[msg->getPlayerID ()] == NULL ) && (msg->getPlayerID () != m_localSlot)) {
433435 // if this is from a player that is no longer in the game, then ignore them.
434436 return TRUE ;
435437 }
436438
437- if (msg->getNetCommandType () == NETCOMMANDTYPE_WRAPPER) {
439+ // Handle WRAPPER commands (before second connection validation)
440+ if (cmdType == NETCOMMANDTYPE_WRAPPER) {
438441 processWrapper (ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command.
439442 return FALSE ;
440443 }
@@ -451,93 +454,84 @@ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) {
451454 // This was a fix for a command count bug where a command would be
452455 // executed, then a command for that old frame would be added to the
453456 // FrameData for that frame + 256, and would screw up the command count.
454-
455- if (IsCommandSynchronized (msg->getNetCommandType ())) {
457+ if (IsCommandSynchronized (cmdType)) {
456458 if (ref->getCommand ()->getExecutionFrame () < TheGameLogic->getFrame ()) {
457459 return TRUE ;
458460 }
459461 }
460462
461- if (msg->getNetCommandType () == NETCOMMANDTYPE_FRAMEINFO) {
462- processFrameInfo ((NetFrameCommandMsg *)msg);
463-
464- // need to set the relay so we don't send it to ourselves.
465- UnsignedByte relay = ref->getRelay ();
466- relay = relay & (0xff ^ (1 << m_localSlot));
467- ref->setRelay (relay);
468- return FALSE ;
463+ // Handle disconnect commands as a range
464+ if ((cmdType > NETCOMMANDTYPE_DISCONNECTSTART) && (cmdType < NETCOMMANDTYPE_DISCONNECTEND)) {
465+ m_disconnectManager->processDisconnectCommand (ref, this );
466+ return TRUE ;
469467 }
470468
471- if (msg->getNetCommandType () == NETCOMMANDTYPE_PROGRESS)
472- {
473- // DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID()));
474- processProgress ((NetProgressCommandMsg *) msg);
469+ // Process command by type
470+ switch (cmdType) {
475471
476- // need to set the relay so we don't send it to ourselves.
477- UnsignedByte relay = ref->getRelay ();
478- relay = relay & (0xff ^ (1 << m_localSlot));
479- ref->setRelay (relay);
480- return FALSE ;
481- }
472+ case NETCOMMANDTYPE_FRAMEINFO: {
473+ processFrameInfo ((NetFrameCommandMsg *)msg);
474+ // need to set the relay so we don't send it to ourselves.
475+ UnsignedByte relay = ref->getRelay ();
476+ relay = relay & (0xff ^ (1 << m_localSlot));
477+ ref->setRelay (relay);
478+ return FALSE ;
479+ }
482480
483- if (msg->getNetCommandType () == NETCOMMANDTYPE_TIMEOUTSTART)
484- {
485- DEBUG_LOG ((" ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d" , msg->getPlayerID ()));
486- processTimeOutGameStart (msg);
487- return FALSE ;
488- }
481+ case NETCOMMANDTYPE_PROGRESS: {
482+ // DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID()));
483+ processProgress ((NetProgressCommandMsg *) msg);
484+ // need to set the relay so we don't send it to ourselves.
485+ UnsignedByte relay = ref->getRelay ();
486+ relay = relay & (0xff ^ (1 << m_localSlot));
487+ ref->setRelay (relay);
488+ return FALSE ;
489+ }
489490
490- if (msg-> getNetCommandType () == NETCOMMANDTYPE_RUNAHEADMETRICS) {
491- processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *) msg);
492- return TRUE ;
493- }
491+ case NETCOMMANDTYPE_TIMEOUTSTART:
492+ DEBUG_LOG (( " ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d " , msg-> getPlayerID ()) );
493+ processTimeOutGameStart (msg) ;
494+ return FALSE ;
494495
495- if (msg-> getNetCommandType () == NETCOMMANDTYPE_KEEPALIVE) {
496- return TRUE ;
497- }
496+ case NETCOMMANDTYPE_RUNAHEADMETRICS:
497+ processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *)msg) ;
498+ return TRUE ;
498499
499- if ((msg->getNetCommandType () > NETCOMMANDTYPE_DISCONNECTSTART) && (msg->getNetCommandType () < NETCOMMANDTYPE_DISCONNECTEND)) {
500- m_disconnectManager->processDisconnectCommand (ref, this );
501- return TRUE ;
502- }
500+ case NETCOMMANDTYPE_KEEPALIVE:
501+ return TRUE ;
503502
504- if (msg-> getNetCommandType () == NETCOMMANDTYPE_DISCONNECTCHAT) {
505- processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
506- }
503+ case NETCOMMANDTYPE_DISCONNECTCHAT:
504+ processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
505+ return FALSE ;
507506
508- if (msg->getNetCommandType () == NETCOMMANDTYPE_LOADCOMPLETE)
509- {
510- DEBUG_LOG ((" ConnectionManager::processNetCommand - got a Load Complete net command from player %d" , msg->getPlayerID ()));
511- processLoadComplete (msg);
512- return FALSE ;
513- }
507+ case NETCOMMANDTYPE_LOADCOMPLETE:
508+ DEBUG_LOG ((" ConnectionManager::processNetCommand - got a Load Complete net command from player %d" , msg->getPlayerID ()));
509+ processLoadComplete (msg);
510+ return FALSE ;
514511
515- if (msg->getNetCommandType () == NETCOMMANDTYPE_CHAT) {
516- processChat ((NetChatCommandMsg *)msg);
517- return FALSE ;
518- }
512+ case NETCOMMANDTYPE_CHAT:
513+ processChat ((NetChatCommandMsg *)msg);
514+ return FALSE ;
519515
520- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILE) {
521- processFile ((NetFileCommandMsg *)msg);
522- return FALSE ;
523- }
516+ case NETCOMMANDTYPE_FILE:
517+ processFile ((NetFileCommandMsg *)msg);
518+ return FALSE ;
524519
525- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEANNOUNCE) {
526- processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
527- return FALSE ;
528- }
520+ case NETCOMMANDTYPE_FILEANNOUNCE:
521+ processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
522+ return FALSE ;
529523
530- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEPROGRESS) {
531- processFileProgress ((NetFileProgressCommandMsg *)msg);
532- return FALSE ;
533- }
524+ case NETCOMMANDTYPE_FILEPROGRESS:
525+ processFileProgress ((NetFileProgressCommandMsg *)msg);
526+ return FALSE ;
534527
535- if (msg->getNetCommandType () == NETCOMMANDTYPE_FRAMERESENDREQUEST) {
536- processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
537- return TRUE ;
538- }
528+ case NETCOMMANDTYPE_FRAMERESENDREQUEST:
529+ processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
530+ return TRUE ;
539531
540- return FALSE ;
532+ default :
533+ return FALSE ;
534+ }
541535}
542536
543537void ConnectionManager::processFrameResendRequest (NetFrameResendRequestCommandMsg *msg) {
0 commit comments