MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / ProcessChatMessage

Method ProcessChatMessage

neo/game/MultiplayerGame.cpp:2979–3061  ·  view source on GitHub ↗

================ idMultiplayerGame::ProcessChatMessage ================ */

Source from the content-addressed store, hash-verified

2977================
2978*/
2979void idMultiplayerGame::ProcessChatMessage( int clientNum, bool team, const char *name, const char *text, const char *sound ) {
2980 idBitMsg outMsg;
2981 byte msgBuf[ 256 ];
2982 const char *prefix = NULL;
2983 int send_to; // 0 - all, 1 - specs, 2 - team
2984 int i;
2985 idEntity *ent;
2986 idPlayer *p;
2987 idStr prefixed_name;
2988
2989 assert( !gameLocal.isClient );
2990
2991 if ( clientNum >= 0 ) {
2992 p = static_cast< idPlayer * >( gameLocal.entities[ clientNum ] );
2993 if ( !( p && p->IsType( idPlayer::Type ) ) ) {
2994 return;
2995 }
2996
2997 if ( p->spectating ) {
2998 prefix = "spectating";
2999 if ( team || ( !g_spectatorChat.GetBool() && ( gameState == GAMEON || gameState == SUDDENDEATH ) ) ) {
3000 // to specs
3001 send_to = 1;
3002 } else {
3003 // to all
3004 send_to = 0;
3005 }
3006 } else if ( team ) {
3007 prefix = "team";
3008 // to team
3009 send_to = 2;
3010 } else {
3011 // to all
3012 send_to = 0;
3013 }
3014 } else {
3015 p = NULL;
3016 send_to = 0;
3017 }
3018 // put the message together
3019 outMsg.Init( msgBuf, sizeof( msgBuf ) );
3020 outMsg.WriteByte( GAME_RELIABLE_MESSAGE_CHAT );
3021 if ( prefix ) {
3022 prefixed_name = va( "(%s) %s", prefix, name );
3023 } else {
3024 prefixed_name = name;
3025 }
3026 outMsg.WriteString( prefixed_name );
3027 outMsg.WriteString( text, -1, false );
3028 if ( !send_to ) {
3029 AddChatLine( "%s^0: %s\n", prefixed_name.c_str(), text );
3030 networkSystem->ServerSendReliableMessage( -1, outMsg );
3031 if ( sound ) {
3032 PlayGlobalSound( -1, SND_COUNT, sound );
3033 }
3034 } else {
3035 for ( i = 0; i < gameLocal.numClients; i++ ) {
3036 ent = gameLocal.entities[ i ];

Callers 2

Cmd_SayFunction · 0.45

Calls 8

vaFunction · 0.85
IsTypeMethod · 0.45
GetBoolMethod · 0.45
InitMethod · 0.45
WriteByteMethod · 0.45
WriteStringMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected