Question about commands

Locked
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Question about commands

Post by bludshot »

I have a 3 cvars, one in ui, one in cgame and one in game. I want to have a command where if you type it in the console it echos like this:

UI Cvar value: <value of ui cvar>
Cgame Cvar value: <value of cgame cvar>
Game Cvar value: <value of game cvar>

Of course, there are 3 states you could be in: 1. In main menu which means you aren't connected to a server, 2. "connected to" a local server, 3. Connected to a remote server.

If you were in state 1, then the game cvar value would just reply like "not connected to server", and if you were in state 2 or 3 then what you'd get back would be from the local or remote server depending on which you are on.

Also there is the possibility that the user is using a ui.qvm doesn't have the ui cvar at all, so in that case I'd say something like "ui cvar value: not present".

Can this even be done? These are read only cvars by the way.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Question about commands

Post by ^misantropia^ »

Everything is possible but not, in this case, without a lot of work. Why do you want it to work like that?
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Question about commands

Post by bludshot »

Well, it doesn't absolutely *have* to work like that, that's why I asked because if it is something that is quite beyond normal mod capability then I would probably not bother and do a pared down version of it instead.

The reason I want to do this has to do with (for starters), AGPL. My mod is being released under AGPL instead of GPL (intentionally) so that if people make server-side-only mods based on it they will still be required to release the source code (they would not have to with GPL if they never distributed the server-side-only mod for other people to run, ie: ran it only on their own server(s)). This is partly inspired by how I asked a guy who coded a 64 player server side engine "mod" for his source code and he basically told me to pay him if I wanted to see it. ioQ3's GPL license didn't require him to share his code since he only ran it on his own servers. Of course, when you connect to his server you're basically using his software/service in a sort of interactive distribution, and AGPL considers that to be distribution while GPL doesn't. And basically if I'm going to code something open source, I want it to be fully open source with no loopholes like that one.

So to satisfy the AGPL requirements (and to satisfy what I want to do), clients need some way to get the source code from the server (or at least the server needs to give you the information on how to get the source code, such as a web link).

So I'm making the command "sourceURL" that when you type it in console it echos the download link for downloading the source code (from a value stored in the qagame.qvm on the server).

If you connected to a server running a special server-side-only mod made by someone else, then the source for your cgame.qvm will be from a different location. Now I don't really *need* to have a cgSourceURL type command, but I figured hey if the user wants the source code they will need to know the locations for all 3 qvm's which may be different.

Can I just do it like this: Make a client command called "sourceURL" that has the server echo its g_sourceURL cvar value *and* that executes another command *on the client*, "cgSourceURL" which echos the client cg_sourceURL cvar value (and hopefully the ui_sourceURL value but I may have trouble accessing that)?
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Question about commands

Post by bludshot »

I have completed this code and I'll post it soon. I did it pretty much how I described at the bottom of my previous post. It actually wasn't that much work really, but I'm used to trying to do much harder and more involved things (that I know less about heh). And this article helped a hell of a lot: http://quakewiki.net/archives/code3aren ... cle9.shtml

My only remaining question about it all is -> viewtopic.php?f=16&t=46396 It's hardly important for the thing I was trying to achieve here in this thread, but, just for my own better understanding of q3 coding it would be good to know.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Question about commands

Post by bludshot »

First you define the 3 constants and create the 3 cvars for each vm, adding to these files in the appropriate places (it's easy to see where to add because you just look at what is currently there):

ui_local.h

Code: Select all

#define UI_SOURCE_URL "http://yourdomain.com/svn/uiproject/"

extern vmCvar_t ui_sourceURL;
cg_local.h

Code: Select all

#define CG_SOURCE_URL "http://somebodyelsesdomain.com/git/cgproject/"

extern  vmCvar_t		cg_sourceURL; //blud
g_local.h

Code: Select all

#define G_SOURCE_URL "http://googlecode.com/serversidemod/"
ui_main.c

Code: Select all

vmCvar_t	ui_sourceURL;

{ &ui_sourceURL, "ui_sourceURL", UI_SOURCE_URL, CVAR_INIT | CVAR_ROM },
cg_main.c

Code: Select all

vmCvar_t	cg_sourceURL; //blud

{ &cg_sourceURL, "cg_sourceURL", CG_SOURCE_URL, CVAR_ROM | CVAR_INIT  },
g_main.c

Code: Select all

vmCvar_t	g_sourceURL;

{ NULL, "g_sourceURL", G_SOURCE_URL, CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
Then you create the server side client command,
near the bottom of g_cmds.c

Code: Select all

else if  (Q_stricmp (cmd, "sourceURL") == 0)
	Cmd_SourceURL_f ( ent);
And add the function the command calls:
in g_cmds.c

Code: Select all

/*
==================
Cmd_SourceURL_f
==================
*/
static void Cmd_SourceURL_f( gentity_t *ent ) {
	char gSourceCvarString[1024]; //I am not sure about the length

	trap_Cvar_VariableStringBuffer( "g_sourceURL", gSourceCvarString, sizeof(gSourceCvarString) );

	trap_SendServerCommand( ent-g_entities, "print \"QVM:              Source Code download URL:\n\"" );
	trap_SendServerCommand( ent-g_entities, "print \"------------------------------------------------------------\n\"" );
	trap_SendServerCommand( ent-g_entities, va("print \"Server            %s\n\"", gSourceCvarString) );

	trap_SendServerCommand( ent-g_entities, "cmd_cg_source_url" );
}
Then create the client side command that the above function 'calls',
in cg_servercmds.c,
in the function: static void CG_ServerCommand( void ) {

Code: Select all

char	cgSourceCvarString[1024]; //I am not sure about the length
char	uiSourceCvarString[1024]; //I am not sure about the length

if ( !strcmp( cmd, "cmd_cg_source_url" ) ) {
	trap_Cvar_VariableStringBuffer( "cg_sourceURL", cgSourceCvarString, sizeof(cgSourceCvarString) );
	trap_Cvar_VariableStringBuffer( "ui_sourceURL", uiSourceCvarString, sizeof(uiSourceCvarString) );

	if ( strlen(uiSourceCvarString) == 0 )
	{
		strcpy( uiSourceCvarString, "base ui" );
	}

	CG_Printf( "Client            %s\n", cgSourceCvarString );
	CG_Printf( "User Interface    %s\n", uiSourceCvarString );

	return;
}
And finally, so that the clients can always auto tab complete the command in console,
in cg_consolecmds.c add:

Code: Select all

trap_AddCommand ("sourceURL");
It's true that I went overboard on this. In reality all I needed to do was have a server side command sourceURL that would echo the server game qvm's source code download link. But since I was doing that I figured I might as well do all this.

Also, in my main menu I have a menu which displays the download links, but it is only able to display the UI link of course, and for the other 2 it informs the user they need to be in a game to get those. Then in my in-game menu, I have a menu which does display all the links.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Question about commands

Post by bludshot »

Turns out my above solution had 1 problem with it. My in-game menus were displaying the value of g_sourceURL, which worked fine on a local game, but of course on a remote game it does not have access to that value.

So I fixed it by having the menu ask for a new cvar's value, cg_g_sourceURL, which I need to set in the code when you join the server.

So in ClientBegin() in g_client.c I added trap_SendServerCommand( clientNum, va("setgsourceurl \"%s\"", G_SOURCE_URL) );

Then in cg_servercmds.c in CG_ServerCommand() I had to add:

if ( !strcmp( cmd, "setgsourceurl" ) ) {
trap_Cvar_Set("cg_g_sourceURL", va("%s", CG_Argv(1)));
return;
}
Locked