@@ -390,25 +390,14 @@ void ConnectionManager::doRelay() {
390390 */
391391Bool ConnectionManager::processNetCommand (NetCommandRef *ref) {
392392 NetCommandMsg *msg = ref->getCommand ();
393+ NetCommandType cmdType = msg->getNetCommandType ();
393394
394- if ((msg->getNetCommandType () == NETCOMMANDTYPE_ACKSTAGE1) ||
395- (msg->getNetCommandType () == NETCOMMANDTYPE_ACKSTAGE2) ||
396- (msg->getNetCommandType () == NETCOMMANDTYPE_ACKBOTH)) {
397-
398- processAck (msg);
399- return FALSE ;
400- }
401-
395+ // Early validation checks
402396 if ((m_connections[msg->getPlayerID ()] == NULL ) && (msg->getPlayerID () != m_localSlot)) {
403397 // if this is from a player that is no longer in the game, then ignore them.
404398 return TRUE ;
405399 }
406400
407- if (msg->getNetCommandType () == NETCOMMANDTYPE_WRAPPER) {
408- processWrapper (ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command.
409- return FALSE ;
410- }
411-
412401 if ((msg->getPlayerID () >= 0 ) && (msg->getPlayerID () < MAX_SLOTS) && (msg->getPlayerID () != m_localSlot)) {
413402 if (m_connections[msg->getPlayerID ()] == NULL ) {
414403 return TRUE ;
@@ -421,93 +410,93 @@ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) {
421410 // This was a fix for a command count bug where a command would be
422411 // executed, then a command for that old frame would be added to the
423412 // FrameData for that frame + 256, and would screw up the command count.
424-
425- if (IsCommandSynchronized (msg->getNetCommandType ())) {
413+ if (IsCommandSynchronized (cmdType)) {
426414 if (ref->getCommand ()->getExecutionFrame () < TheGameLogic->getFrame ()) {
427415 return TRUE ;
428416 }
429417 }
430418
431- if (msg->getNetCommandType () == NETCOMMANDTYPE_FRAMEINFO) {
432- processFrameInfo ((NetFrameCommandMsg *)msg);
433-
434- // need to set the relay so we don't send it to ourselves.
435- UnsignedByte relay = ref->getRelay ();
436- relay = relay & (0xff ^ (1 << m_localSlot));
437- ref->setRelay (relay);
438- return FALSE ;
419+ // Handle disconnect commands as a range
420+ if ((cmdType > NETCOMMANDTYPE_DISCONNECTSTART) && (cmdType < NETCOMMANDTYPE_DISCONNECTEND)) {
421+ m_disconnectManager->processDisconnectCommand (ref, this );
422+ return TRUE ;
439423 }
440424
441- if (msg->getNetCommandType () == NETCOMMANDTYPE_PROGRESS)
442- {
443- // DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID()));
444- processProgress ((NetProgressCommandMsg *) msg);
425+ // Process command by type
426+ switch (cmdType) {
427+ case NETCOMMANDTYPE_ACKSTAGE1:
428+ case NETCOMMANDTYPE_ACKSTAGE2:
429+ case NETCOMMANDTYPE_ACKBOTH:
430+ processAck (msg);
431+ return FALSE ;
445432
446- // need to set the relay so we don't send it to ourselves.
447- UnsignedByte relay = ref->getRelay ();
448- relay = relay & (0xff ^ (1 << m_localSlot));
449- ref->setRelay (relay);
450- return FALSE ;
451- }
433+ case NETCOMMANDTYPE_WRAPPER:
434+ processWrapper (ref); // need to send the NetCommandRef since we have to construct the relay for the wrapped command.
435+ return FALSE ;
452436
453- if (msg->getNetCommandType () == NETCOMMANDTYPE_TIMEOUTSTART)
454- {
455- DEBUG_LOG ((" ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d" , msg->getPlayerID ()));
456- processTimeOutGameStart (msg);
457- return FALSE ;
458- }
437+ case NETCOMMANDTYPE_FRAMEINFO: {
438+ processFrameInfo ((NetFrameCommandMsg *)msg);
439+ // need to set the relay so we don't send it to ourselves.
440+ UnsignedByte relay = ref->getRelay ();
441+ relay = relay & (0xff ^ (1 << m_localSlot));
442+ ref->setRelay (relay);
443+ return FALSE ;
444+ }
459445
460- if (msg->getNetCommandType () == NETCOMMANDTYPE_RUNAHEADMETRICS) {
461- processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *)msg);
462- return TRUE ;
463- }
446+ case NETCOMMANDTYPE_PROGRESS: {
447+ // DEBUG_LOG(("ConnectionManager::processNetCommand - got a progress net command from player %d", msg->getPlayerID()));
448+ processProgress ((NetProgressCommandMsg *) msg);
449+ // need to set the relay so we don't send it to ourselves.
450+ UnsignedByte relay = ref->getRelay ();
451+ relay = relay & (0xff ^ (1 << m_localSlot));
452+ ref->setRelay (relay);
453+ return FALSE ;
454+ }
464455
465- if (msg->getNetCommandType () == NETCOMMANDTYPE_KEEPALIVE) {
466- return TRUE ;
467- }
456+ case NETCOMMANDTYPE_TIMEOUTSTART:
457+ DEBUG_LOG ((" ConnectionManager::processNetCommand - got a TimeOut GameStart net command from player %d" , msg->getPlayerID ()));
458+ processTimeOutGameStart (msg);
459+ return FALSE ;
468460
469- if ((msg->getNetCommandType () > NETCOMMANDTYPE_DISCONNECTSTART) && (msg->getNetCommandType () < NETCOMMANDTYPE_DISCONNECTEND)) {
470- m_disconnectManager->processDisconnectCommand (ref, this );
471- return TRUE ;
472- }
461+ case NETCOMMANDTYPE_RUNAHEADMETRICS:
462+ processRunAheadMetrics ((NetRunAheadMetricsCommandMsg *)msg);
463+ return TRUE ;
473464
474- if (msg->getNetCommandType () == NETCOMMANDTYPE_DISCONNECTCHAT) {
475- processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
476- }
465+ case NETCOMMANDTYPE_KEEPALIVE:
466+ return TRUE ;
477467
478- if (msg->getNetCommandType () == NETCOMMANDTYPE_LOADCOMPLETE)
479- {
480- DEBUG_LOG ((" ConnectionManager::processNetCommand - got a Load Complete net command from player %d" , msg->getPlayerID ()));
481- processLoadComplete (msg);
482- return FALSE ;
483- }
468+ case NETCOMMANDTYPE_DISCONNECTCHAT:
469+ processDisconnectChat ((NetDisconnectChatCommandMsg *)msg);
470+ return FALSE ;
484471
485- if (msg-> getNetCommandType () == NETCOMMANDTYPE_CHAT) {
486- processChat ((NetChatCommandMsg *) msg);
487- return FALSE ;
488- }
472+ case NETCOMMANDTYPE_LOADCOMPLETE:
473+ DEBUG_LOG (( " ConnectionManager::processNetCommand - got a Load Complete net command from player %d " , msg-> getPlayerID ()) );
474+ processLoadComplete (msg) ;
475+ return FALSE ;
489476
490- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILE) {
491- processFile ((NetFileCommandMsg *)msg);
492- return FALSE ;
493- }
477+ case NETCOMMANDTYPE_CHAT:
478+ processChat ((NetChatCommandMsg *)msg);
479+ return FALSE ;
494480
495- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEANNOUNCE) {
496- processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
497- return FALSE ;
498- }
481+ case NETCOMMANDTYPE_FILE:
482+ processFile ((NetFileCommandMsg *)msg);
483+ return FALSE ;
499484
500- if (msg->getNetCommandType () == NETCOMMANDTYPE_FILEPROGRESS) {
501- processFileProgress ((NetFileProgressCommandMsg *)msg);
502- return FALSE ;
503- }
485+ case NETCOMMANDTYPE_FILEANNOUNCE:
486+ processFileAnnounce ((NetFileAnnounceCommandMsg *)msg);
487+ return FALSE ;
504488
505- if (msg->getNetCommandType () == NETCOMMANDTYPE_FRAMERESENDREQUEST) {
506- processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
507- return TRUE ;
508- }
489+ case NETCOMMANDTYPE_FILEPROGRESS:
490+ processFileProgress ((NetFileProgressCommandMsg *)msg);
491+ return FALSE ;
492+
493+ case NETCOMMANDTYPE_FRAMERESENDREQUEST:
494+ processFrameResendRequest ((NetFrameResendRequestCommandMsg *)msg);
495+ return TRUE ;
509496
510- return FALSE ;
497+ default :
498+ return FALSE ;
499+ }
511500}
512501
513502void ConnectionManager::processFrameResendRequest (NetFrameResendRequestCommandMsg *msg) {
0 commit comments