Server CVAR in cgame


(funRut) #1

Hello there,
So i am editing the source of ET and want to add a cvar.
I followed this:
http://www.splashdamage.com/forums/showthread.php/6095-Adding-New-CVARs

I don’t really get it (it was ussefull i learned some things from it :stuck_out_tongue: )
So my idea was to make specterators use voicechat/teamchat
There are 2 parts of code that deal whit this:
g_cmds.c
Line 3395
Till
Line 3420

cg_consolecmds.c
Line 473
Till
Line 520

I followed the above tutorial but how do i actually make the client use the same setting as the server?
(Server admin sets c_advspecchat to 1 or 0)
then the code checks if its 1 or 0:


	if (advspecchat.integer == 0)
		{
				if ( cgs.clientinfo[cg.clientNum].team == TEAM_SPECTATOR || cgs.clientinfo[cg.clientNum].team == TEAM_FREE ) 
				{
	        		CG_Printf( CG_TranslateString( "Advanced Voice chat is disabled on this server.
" ) );
	        		return;
	        	}
			
		}
	   else if (advspecchat.integer == 1) 
		{
		    trap_Argv( 1, chatCmd, 64 );
           trap_SendConsoleCommand( va( "cmd vsay %s
", chatCmd ) );
	    }
	   else
	    {
		    CG_Printf( CG_TranslateString( "Invalid server configuration. advspecchat MUST be 1 OR 0. 
" ) );
	    }
		if ( cgs.clientinfo[cg.clientNum].team == TEAM_SPECTATOR || cgs.clientinfo[cg.clientNum].team == TEAM_FREE ) {
			CG_Printf( CG_TranslateString( "Can't voice chat as a spectator.
" ) );
			return;
		}

I’m sorry if this code is crappy, I’m still learning and i only know a bit of C++
Everything i try results in the cvar not working ingame or a ton of compiler errors

Regards,

-Rut.

EDIT:
I can see and set the cvar ingame now, however the above code ignores it
also i added the cvar in the server files and when i use it in the server code it says:

Error 1 error C2065: ‘g_advspecchat’ : undeclared identifier

I use this code (above) the client spec chat code i posted above:


const char	*info;
        qhandle_t	g_advspecchat;

        info = CG_ConfigString( CS_SERVERINFO );
		g_advspecchat = Info_ValueForKey( info, "g_advspecchat" );

Maybe a better description:
I basicly want a cvar so server admins can enable the advanced spec chat
the problem is i don’t know how to make the cvar “info” avivable on server and client
(Only server should set the cvar)
so if g_advspecchat is 1 it must be 1 on client and server
(Also is the above code right for checking a cvar?)


(ETJump-Zero) #2

Didn’t really include how to tell client that g_advspecchat is off but it’s a little hackish way to achieve what you wanted.

Add this to around line 205 on g_main.c

vmCvar_t		g_advspechat;

This to around line 425

{ &g_advspecchat, "g_advspecchat", "0", CVAR_ARCHIVE },

It should look like this

{ &g_nextmap, "nextmap", "", CVAR_TEMP },
	{ &g_nextcampaign, "nextcampaign", "", CVAR_TEMP },

	{ &g_disableComplaints, "g_disableComplaints", "0", CVAR_ARCHIVE },
	{ &g_advspecchat, "g_advspecchat", "0", CVAR_ARCHIVE },

};

Open g_local.h
Line 1792 add this

extern vmCvar_t	g_advspecchat;

Now you have the cvar and need to add the functionality. You said you wanted to be able to toggle spectator teamchat/voicechat. It’s rather simple and you don’t have to touch cgame at all :>

g_cmds.c line 3316. Add the bold part in the if-block.

if( [B]g_advspecchat.integer == 0 &&[/B]ent->client->sess.sessionTeam == TEAM_SPECTATOR || ent->client->sess.sessionTeam == TEAM_FREE ) {
			trap_SendServerCommand( ent-g_entities, "print \"Can't team chat as spectator
\"
" );
			return;
		}

It will let you talk on teamchat as a spectator if g_advspecchat > 0.

Now we need to do the same for vsay.

Few lines later

else if (Q_stricmp (cmd, "vsay_team") == 0) {
		if( g_advspecchat.integer == 0 && ent->client->sess.sessionTeam == TEAM_SPECTATOR || ent->client->sess.sessionTeam == TEAM_FREE ) {
			trap_SendServerCommand( ent-g_entities, "print \"Can't team chat as spectator
\"
" );
			return;
		}

Now you can use /vsay_team /vsay on spec.

Simplest way to allow clients to open the vsay menu would be to remove the check on CG_QuickMessage_f on cg_consolecommands.c line ~320.

if( cgs.clientinfo[ cg.clientNum ].team == TEAM_SPECTATOR ) {
		return;
	}

Then another check on cg_consolecommands.c ~line 392

if ( cg.snap && ( cg.snap->ps.pm_type != PM_INTERMISSION ) ) {
		if ( cgs.clientinfo[cg.clientNum].team == TEAM_SPECTATOR || cgs.clientinfo[cg.clientNum].team == TEAM_FREE ) {
			CG_Printf ( CG_TranslateString( "Can't team voice chat as a spectator.
" ) );
			return;
		}
	}

And another… on CG_SayPlayerClass_f
and on CG_VoiceChat_f
and CG_TeamVoiceChat_f
and CG_BuddyVoiceChat_f

Remove the same check on all of them (they’re right next to eachother so just scroll down a bit) and you should be able to use vsays thru the menu aswell. If you want the menu to not open if g_advspecchat is off it’s slightly more complicated and I’m afraid I don’t have time for that now :frowning:

This post is badly formatted but can’t help it, I’m a terrible writer. :smiley: I hope it helps a bit.


(ETJump-Zero) #3

The cvar serverside should be CVAR_SERVERINFO

{ &g_advSpecChat, "g_advSpecChat", "0", CVAR_SERVERINFO | CVAR_LATCH },

Make a clientside cvar like

{ &cg_advSpecChat,			"", "0", 0 },

Add to CG_ParseServerinfo line ~120

cg_advSpecChat.integer = atoi (Info_ValueForKey( info, "g_advSpecChat" ) );

Now it should be updated to whatever it is on serverside and you can make the checks on clientside functions. Don’t forget to add them to serverside functions aswell, tho!

Zero


(funRut) #4

Thanks,
I found this today:
http://www.splashdamage.com/forums/showthread.php/10119-Double-jump?p=100323&viewfull=1#post100323
It seems work fine :slight_smile:
If anyone wants to see the code i will post it

Regards,

-Rut.