================ idMultiplayerGame::ProcessChatMessage ================ */
| 3710 | ================ |
| 3711 | */ |
| 3712 | void idMultiplayerGame::ProcessChatMessage( int clientNum, bool team, const char *name, const char *text, const char *sound ) { |
| 3713 | idBitMsg outMsg; |
| 3714 | byte msgBuf[ 256 ]; |
| 3715 | const char *prefix = NULL; |
| 3716 | int send_to; // 0 - all, 1 - specs, 2 - team |
| 3717 | int i; |
| 3718 | idEntity *ent; |
| 3719 | idPlayer *p; |
| 3720 | idStr prefixed_name; |
| 3721 | |
| 3722 | assert( !gameLocal.isClient ); |
| 3723 | |
| 3724 | if ( clientNum >= 0 ) { |
| 3725 | p = static_cast< idPlayer * >( gameLocal.entities[ clientNum ] ); |
| 3726 | if ( !( p && p->IsType( idPlayer::Type ) ) ) { |
| 3727 | return; |
| 3728 | } |
| 3729 | |
| 3730 | if ( p->spectating ) { |
| 3731 | prefix = "spectating"; |
| 3732 | if ( team || ( !g_spectatorChat.GetBool() && ( gameState == GAMEON || gameState == SUDDENDEATH ) ) ) { |
| 3733 | // to specs |
| 3734 | send_to = 1; |
| 3735 | } else { |
| 3736 | // to all |
| 3737 | send_to = 0; |
| 3738 | } |
| 3739 | } else if ( team ) { |
| 3740 | prefix = "team"; |
| 3741 | // to team |
| 3742 | send_to = 2; |
| 3743 | } else { |
| 3744 | // to all |
| 3745 | send_to = 0; |
| 3746 | } |
| 3747 | } else { |
| 3748 | p = NULL; |
| 3749 | send_to = 0; |
| 3750 | } |
| 3751 | // put the message together |
| 3752 | outMsg.Init( msgBuf, sizeof( msgBuf ) ); |
| 3753 | outMsg.WriteByte( GAME_RELIABLE_MESSAGE_CHAT ); |
| 3754 | if ( prefix ) { |
| 3755 | prefixed_name = va( "(%s) %s", prefix, name ); |
| 3756 | } else { |
| 3757 | prefixed_name = name; |
| 3758 | } |
| 3759 | outMsg.WriteString( prefixed_name ); |
| 3760 | outMsg.WriteString( text, -1, false ); |
| 3761 | if ( !send_to ) { |
| 3762 | AddChatLine( "%s^0: %s\n", prefixed_name.c_str(), text ); |
| 3763 | networkSystem->ServerSendReliableMessage( -1, outMsg ); |
| 3764 | if ( sound ) { |
| 3765 | PlayGlobalSound( -1, SND_COUNT, sound ); |
| 3766 | } |
| 3767 | } else { |
| 3768 | for ( i = 0; i < gameLocal.numClients; i++ ) { |
| 3769 | ent = gameLocal.entities[ i ]; |
no test coverage detected