Server: pq_connectmute tutorial

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Server: pq_connectmute tutorial

Post by Baker »

With mods (at least in NetQuake), traditionally the way the ban file works is that mods read the ban file in and then if the ip address matches a banned ip, the player gets booted.

Vulnerability

It takes at least a fraction of a second for the mod to read the ban file. Maybe 1 second or 2 seconds.

During that time a player can spam chat. With a creative alias, they can connect, chat spam, connect, chat spam, connect chat spam.

And they can ruin a game by doing so, particularly a team game where communication is important. At a minimum it is disruptive. And they aren't supposed to be able to connect to a server they are banned on anyway.

PQ_CONNECTMUTE: # of seconds before a player is allowed to speak upon connecting ...

This engine modification allows the server to only permit chatting after X seconds of being connected. This gives the mod time to read the ban file and execute it. I have ProQuake in dedicated server mod set it to 3 automatically.

I wrote this for ProQuake server about 2 years ago. Actually, R00k walked me through the implementation because at the time I was very new to engine coding.

Anyway, this is a "bandage" to solve this issue. The preferred way would be the engine reading the ban file unless there is a good reason that QuakeC is the "right way" to do this for reasons I am unaware of.

Tutorial (Adapted to GLQuake/WinQuake)

1. in host.c, create a cvar "pq_connectmute" with a default value of 0! Yes zero.

Add this:
// Baker 3.99g - from Rook ... protect against players connecting and spamming before banfile can kick in
cvar_t pq_connectmute = {"pq_connectmute", "0", false, true}; // (value in seconds)
Add the yellow:
Cvar_RegisterVariable (&coop);
Cvar_RegisterVariable (&pq_connectmute); // Baker 3.99g: from Rook, protection against repeatedly connecting + spamming
2. sv_main.c

We default pq_connectmute to 0 because it is undesireable in single player or a listen server. But for a dedicated server, we will likely want it. GLQuake/WinQuake doesn't have sophisticated cvar defaulting, so we need to set it to 3 in the code if the server is running in dedicated mode.

Add this to SV_Init:

Code: Select all

	// Baker: Dedicated server "defaults" - this is ok because quake.rc is executed later, so these "defaults" won't override config.cfg settings, etc.
	if (COM_CheckParm ("-dedicated")) {
		Cvar_Set("pq_connectmute", "3"); 	// Baker 3.99g: "Default" it to 10 seconds
	}
At first glance, you would think this is improper because it would override the value specified in the command line or elsewhere, but it's fine because that all occurs later.

3. Open host_cmd.c and in Host_Say add the yellow:
// turn on color set 1
if (!fromServer)
{
// R00k - dont allow new connecting players to spam obscenities...
if (pq_connectmute.value && (net_time - host_client->netconnection->connecttime) < pq_connectmute.value)
return;
So if pq_connectmute has a value of 3, it will be 3 seconds before the server will allow a player to chat. The ban file will have been read by that time and executed.

And banned players spamming chat with a script is no longer possible.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Another "bandage", this time limiting the ability for disruptive players to ruin games. This time it is joining a team game setup in progress and selecting a color.

There is an annoying player who likes to connect to servers and disrupt the setup of team games by connecting via a proxy and selecting a color, before a game start.

This little "bandage" prevents any color change for X seconds in theory.

Code: Select all

	 // Baker: If the player pants color isn't 0
	 //        and the player shirt color isn't 0  (hence playercolor will be 0)
	 //        and pq_colorlock has a non-zero value
	 //        then deny changes to the color for X seconds as specified in pq_colorlock
	 if (playercolor && !pq_colorlock.value && (net_time - host_client->netconnection->connecttime) < pq_colorlock.value)
		return;		
So if a player cannot select a color until being connected for, say, 45 seconds it is rather difficult to be able to reconnect and ruin a game setup if you can't change your color immediately upon connecting.

[Better anti-proxy prevention in the engine would be a far better solution, this is a POOR solution. But with someone using a proxy and reconnecting after being kicked/banned, it should be an effective solution.]
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

Neat. :D

Don't forget to define and register the pq_colorlock cvar by the way. :wink:

I'd bag these for DirectQ only it's not really meant to be used as a server (I even removed the dedicated server a good time back).

Feck it, I'm bagging pq_colorlock anyway. :lol:
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

This tutorial does fall solidly into the boring and low utility category.

It's not exciting like ripping the awesome Enforcer lasers effect out of ezQuake or perverting Rook's powerupshells stuff in an EF_YELLOW tutorial on how to make cool looking forcefielded monsters :D

However, that's actually why it is important to write it up and file it here to collect the knowledge and if someone casually reads some of the info here, might see something.

There have probably been 10 external texture tutorials and 6 MD3 tutorials in Quakesrc.org, but what everyone needs are the oddball ones (like scratch.qc -- I had never even heard of that).

I have a few more boring ones on the way too. :P

It's all good. Eventually I have a very large endgame planned, but I spend my time plodding around with small details that have to get fixed for that to matter. The car is no good if the frame cannot support the weight ;)
FrikaC
Site Admin
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Post by FrikaC »

I totally think the engine should handle all the ban features. There's no good reason I can think of for a mod to handle any of that stuff.
Downsider
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Post by Downsider »

I'd like the finished scratch QC deal, I think Avirox has it, because I hate stripping out Quake stuff or starting from 100% scratch every time I experiment.

^ Sometimes nessecary due to the PSP's limited RAM. Can't load nice maps if I'm precaching all these Quake models and textures that won't be in the final version anyway! :(
Post Reply