@@ -420,25 +420,14 @@ 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-
428- processAck (msg);
429- return FALSE ;
430- }
431-
425+ // Early validation checks
432426 if ((m_connections[msg->getPlayerID ()] == NULL ) && (msg->getPlayerID () != m_localSlot)) {
433427 // if this is from a player that is no longer in the game, then ignore them.
434428 return TRUE ;
435429 }
436430
437- if (msg->getNetCommandType () == NETCOMMANDTYPE_WRAPPER) {
438- processWrapper (ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command.
439- return FALSE ;
440- }
441-
442431 if ((msg->getPlayerID () >= 0 ) && (msg->getPlayerID () < MAX_SLOTS) && (msg->getPlayerID () != m_localSlot)) {
443432 if (m_connections[msg->getPlayerID ()] == NULL ) {
444433 return TRUE ;
@@ -451,93 +440,93 @@ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) {
451440 // This was a fix for a command count bug where a command would be
452441 // executed, then a command for that old frame would be added to the
453442 // FrameData for that frame + 256, and would screw up the command count.
454-
455- if (IsCommandSynchronized (msg->getNetCommandType ())) {
443+ if (IsCommandSynchronized (cmdType)) {
456444 if (ref->getCommand ()->getExecutionFrame () < TheGameLogic->getFrame ()) {
457445 return TRUE ;
458446 }
459447 }
460448
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 ;
449+ // Handle disconnect commands as a range
450+ if ((cmdType > NETCOMMANDTYPE_DISCONNECTSTART) && (cmdType < NETCOMMANDTYPE_DISCONNECTEND)) {
451+ m_disconnectManager->processDisconnectCommand (ref, this );
452+ return TRUE ;
469453 }
470454
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);
455+ // Process command by type
456+ switch (cmdType) {
457+ case NETCOMMANDTYPE_ACKSTAGE1:
458+ case NETCOMMANDTYPE_ACKSTAGE2:
459+ case NETCOMMANDTYPE_ACKBOTH:
460+ processAck (msg);
461+ return FALSE ;
475462
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- }
463+ case NETCOMMANDTYPE_WRAPPER:
464+ processWrapper (ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command.
465+ return FALSE ;
482466
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- }
467+ case NETCOMMANDTYPE_FRAMEINFO: {
468+ processFrameInfo ((NetFrameCommandMsg *)msg);
469+ // need to set the relay so we don't send it to ourselves.
470+ UnsignedByte relay = ref->getRelay ();
471+ relay = relay & (0xff ^ (1 << m_localSlot));
472+ ref->setRelay (relay);
473+ return FALSE ;
474+ }
489475
490- if (msg->getNetCommandType () == NETCOMMANDTYPE_RUNAHEADMETRICS) {
491- processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *)msg);
492- return TRUE ;
493- }
476+ case NETCOMMANDTYPE_PROGRESS: {
477+ // DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID()));
478+ processProgress ((NetProgressCommandMsg *) msg);
479+ // need to set the relay so we don't send it to ourselves.
480+ UnsignedByte relay = ref->getRelay ();
481+ relay = relay & (0xff ^ (1 << m_localSlot));
482+ ref->setRelay (relay);
483+ return FALSE ;
484+ }
494485
495- if (msg->getNetCommandType () == NETCOMMANDTYPE_KEEPALIVE) {
496- return TRUE ;
497- }
486+ case NETCOMMANDTYPE_TIMEOUTSTART:
487+ DEBUG_LOG ((" ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d" , msg->getPlayerID ()));
488+ processTimeOutGameStart (msg);
489+ return FALSE ;
498490
499- if ((msg->getNetCommandType () > NETCOMMANDTYPE_DISCONNECTSTART) && (msg->getNetCommandType () < NETCOMMANDTYPE_DISCONNECTEND)) {
500- m_disconnectManager->processDisconnectCommand (ref, this );
501- return TRUE ;
502- }
491+ case NETCOMMANDTYPE_RUNAHEADMETRICS:
492+ processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *)msg);
493+ return TRUE ;
503494
504- if (msg->getNetCommandType () == NETCOMMANDTYPE_DISCONNECTCHAT) {
505- processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
506- }
495+ case NETCOMMANDTYPE_KEEPALIVE:
496+ return TRUE ;
507497
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- }
498+ case NETCOMMANDTYPE_DISCONNECTCHAT:
499+ processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
500+ return FALSE ;
514501
515- if (msg-> getNetCommandType () == NETCOMMANDTYPE_CHAT) {
516- processChat ((NetChatCommandMsg *) msg);
517- return FALSE ;
518- }
502+ case NETCOMMANDTYPE_LOADCOMPLETE:
503+ DEBUG_LOG (( " ConnectionManager::processNetCommand - got a Load Complete net command from player %d " , msg-> getPlayerID ()) );
504+ processLoadComplete (msg) ;
505+ return FALSE ;
519506
520- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILE) {
521- processFile ((NetFileCommandMsg *)msg);
522- return FALSE ;
523- }
507+ case NETCOMMANDTYPE_CHAT:
508+ processChat ((NetChatCommandMsg *)msg);
509+ return FALSE ;
524510
525- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEANNOUNCE) {
526- processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
527- return FALSE ;
528- }
511+ case NETCOMMANDTYPE_FILE:
512+ processFile ((NetFileCommandMsg *)msg);
513+ return FALSE ;
529514
530- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEPROGRESS) {
531- processFileProgress ((NetFileProgressCommandMsg *)msg);
532- return FALSE ;
533- }
515+ case NETCOMMANDTYPE_FILEANNOUNCE:
516+ processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
517+ return FALSE ;
534518
535- if (msg->getNetCommandType () == NETCOMMANDTYPE_FRAMERESENDREQUEST) {
536- processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
537- return TRUE ;
538- }
519+ case NETCOMMANDTYPE_FILEPROGRESS:
520+ processFileProgress ((NetFileProgressCommandMsg *)msg);
521+ return FALSE ;
522+
523+ case NETCOMMANDTYPE_FRAMERESENDREQUEST:
524+ processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
525+ return TRUE ;
539526
540- return FALSE ;
527+ default :
528+ return FALSE ;
529+ }
541530}
542531
543532void ConnectionManager::processFrameResendRequest (NetFrameResendRequestCommandMsg *msg) {
0 commit comments