Adding a function to svcmds

Locked
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Adding a function to svcmds

Post by nexus024 »

I have been following this excellent tutorial thats been provided here on how to cloak oneself in quake. What I would like to do however is make this feature available to admins only. I changed it around a bit as detailed below but when I go on the server and issue 'rcon cloak' it causes a buffer overflow and crashes all clients connected to server. Anyone know why this might be happening?

g_svcmds.c

Code: Select all

/*
=================
Svcmd_Cloak_f
=================
*/
void Svcmd_Cloak_f( gentity_t *ent ) {

	char *msg; // message to player

	ent->flags ^= FL_CLOAK;

	if (!(ent->flags & FL_CLOAK)) {
		msg = "Cloaking OFF\n";
		ent->client->ps.powerups[PW_INVIS] = level.time;
		// Removes the invisible powerup from the player
	}        
	else {
		msg = "Cloaking ON\n";
		ent->client->ps.powerups[PW_INVIS] = level.time + 1000000000;
		// Gives the invisible powerup to the player
	}

	trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
}


// Console commands down at bottom
if ( Q_stricmp (cmd, "cloak") == 0 ) {
		Svcmd_Cloak_f( ent );
		return qtrue;
}
jkoder
Posts: 59
Joined: Tue Jun 17, 2008 9:10 pm

Re: Adding a function to svcmds

Post by jkoder »

Where are you getting the "ent" reference from in ConsoleCommand()?

Why don't you just insert a command in g_cmds and only tell admins about it. Give it an obscure name
so people can't access it by mistake.
jkoder
Posts: 59
Joined: Tue Jun 17, 2008 9:10 pm

Re: Adding a function to svcmds

Post by jkoder »

Did you take a look at function "void SVC_RemoteCommand( netadr_t from, msg_t *msg )" in sv_main.c
in the server project? It takes an IP address and a command as arguments, so my guess is that you can't associate
a player in the game with rcon, only an IP address. Which is logical if you think that the engine is
meant to be generic and loosely coupled. Unless you can map this IP address to a player I don't think you can get this to work though I only looked into this for a few minutes.
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: Adding a function to svcmds

Post by nexus024 »

Why don't you just insert a command in g_cmds and only tell admins about it. Give it an obscure name
so people can't access it by mistake.
Excellent idea. I never thought of doing that. Thanks!
Locked