Banning

Locked
ensiform
Posts: 93
Joined: Mon Jul 25, 2005 5:20 am

Banning

Post by ensiform »

If anyone is interested i figured out how to completely not have a need for g_banIPs cvar.

just give a shout and ill post it.
corncobman
Posts: 304
Joined: Fri Aug 08, 2003 7:00 am

Post by corncobman »

Post.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-

[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
ensiform
Posts: 93
Joined: Mon Jul 25, 2005 5:20 am

Post by ensiform »

In g_svcmds.c add the following above the entitylist function:

Code: Select all

/*
=================
Svcmd_ListIPs_f
=================
*/
void Svcmd_ListIPs_f( void )
{
	int		i;
	char	*str;
	byte	b[4];

	G_Printf ( "%d IP slots used.\n", numIPFilters );
	for ( i = 0 ; i < numIPFilters ; i++ ) 
	{
		G_Printf ( "%d: ", i );
		if (ipFilters[i].compare == 0xffffffff)
		{
			G_Printf ( "unused\n" );
		}
		else
		{
			*(unsigned *)b = ipFilters[i].compare;
			str = va("%i.%i.%i.%i \n", b[0], b[1], b[2], b[3]);
			G_Printf ( "%s\n", str );
		}
	}
}

/*
=================
G_SaveBanIP
=================
*/
void G_SaveBanIP( void )
{//save out all the banned IPs
	int		i;
	char	*str;
	fileHandle_t fh;
	byte	b[4];

	trap_FS_FOpenFile("banlist.dat", &fh, FS_WRITE);
	if ( !fh )
	{
		G_Printf ( "G_SaveBanIP - ERROR: can't open banlist.dat\n" );
		return;
	}
	
	str = va("%d \n", numIPFilters);
	trap_FS_Write(str, strlen(str), fh);
	for ( i = 0 ; i < numIPFilters ; i++ ) 
	{
		if (ipFilters[i].compare == 0xffffffff)
		{
			str = "unused \n";
			trap_FS_Write(str, strlen(str), fh);
		}
		else
		{
			*(unsigned *)b = ipFilters[i].compare;
			str = va("%i.%i.%i.%i \n", b[0], b[1], b[2], b[3]);
			trap_FS_Write(str, strlen(str), fh);
		}
	}

	trap_FS_FCloseFile(fh);
	G_Printf ( "G_SaveBanIP - banlist.dat ^3SAVED SUCCESSFULLY^7:\n" ); // comment this out if u dont need a successful message
}

/*
=================
G_LoadIPBans
=================
*/
void G_LoadIPBans( void )
{//load in all the banned IPs
	int		i, len;
	char	*p, *token;
	fileHandle_t fh;
	char	banIPBuffer[MAX_IPFILTERS*32];			//	The list of file names read in
	char	banIPFile[MAX_QPATH];

	len = trap_FS_FOpenFile("banlist.dat", &fh, FS_READ);
	if ( !fh )
	{
		G_Printf ( "G_LoadBanIP - ERROR: can't open banlist.dat\n" );
		return;
	}
	
	trap_FS_Read(banIPBuffer, len, fh);
	banIPBuffer[len] = 0;
	trap_FS_FCloseFile(fh);
	p = banIPBuffer;
	COM_BeginParseSession(banIPFile);

	token = COM_ParseExt( &p, qtrue );
	if ( token )
	{
		numIPFilters = atoi(token);

		for ( i = 0 ; i < numIPFilters ; i++ ) 
		{
			token = COM_ParseExt( &p, qtrue );
			if ( token )
			{//have an ip
				if ( !Q_stricmp("unused",token) )
				{
					ipFilters[i].compare = 0xffffffffu;
				}
				else
				{
					StringToFilter(token,&ipFilters[i]);
				}
			}
			else
			{
				break;
			}
		}
	}
	G_Printf ( "G_LoadBanIP - banlist.dat ^3LOADED SUCCESSFULLY^7:\n" ); // comment this out if u dont need a successful message
}

/*
=================
G_ProcessBanList
=================
*/
void G_ProcessBanList( void )
{
	G_SaveBanIP();		// add new stuff to the list
	G_LoadIPBans();		// reload the list
}
now still in g_svcmds.c replace the of the following:

Code: Select all

UpdateIPBans();
with:

Code: Select all

G_ProcessBanList();
void G_ProcessBanList( void ); // store new values in file; reload it for security

okay now, open up g_local.h and add this in the area where there are some defines for g_svcmds.c:

Code: Select all

void G_ProcessBanList( void );	// store new values in file; reload it for security
now open up g_main.c and get to G_InitGame.

it should now look something like this:

Code: Select all

/*
============
G_InitGame

============
*/
extern void G_LoadIPBans(void);	// ensiform
void G_InitGame( int levelTime, int randomSeed, int restart ) { ...

in that function comment or delete this:

Code: Select all

G_ProcessIPBans();
and add:

Code: Select all

G_LoadIPBans();
now, scroll down to G_ShutdownGame.

it should now look something like this:

Code: Select all

/*
=================
G_ShutdownGame
=================
*/
extern void G_SaveBanIP( void ); // ensiform
void G_ShutdownGame( int restart ) {
	G_Printf ("==== ShutdownGame ====\n");
below that add:

Code: Select all

G_SaveBanIP();
thats pretty much it except go back to g_svcmds.c and we need to change how the listip command works and add a reloadbans function (optional if u want).

Code: Select all

	if (Q_stricmp (cmd, "listip") == 0) {
		Svcmd_ListIPs_f();
		//trap_SendConsoleCommand( EXEC_NOW, "g_banIPs\n" );
		return qtrue;
	}

	if (Q_stricmp (cmd, "reloadBans") == 0) {
		G_LoadIPBans();
		return qtrue;
	}
/me sighs at how long that took.

if u need any assistance, like line numbers etc, feel free to ask.
Last edited by ensiform on Sat Sep 17, 2005 11:55 pm, edited 1 time in total.
ensiform
Posts: 93
Joined: Mon Jul 25, 2005 5:20 am

Post by ensiform »

mmm since UpdateIPBans, and G_ProcessIPBans are no longer used, you could delete or comment out. You could also do that with the g_banIPs cvar, as its not used, but u will have to comment those functions out if u get rid of the cvar because the cvar is referenced in them.
ensiform
Posts: 93
Joined: Mon Jul 25, 2005 5:20 am

Post by ensiform »

Code: Select all

char   banIPBuffer[MAX_IPFILTERS*32];         //   The list of file names read in 
it appears... that corncobman tells me that this does not work with QVM compile and that 31 works so i guess if your using qvm use 31.
corncobman
Posts: 304
Joined: Fri Aug 08, 2003 7:00 am

Post by corncobman »

The exact error message that comes up during compilation is:

"Locals > 32k in G_LoadIPBans"
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-

[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
stick881
Posts: 5
Joined: Tue Dec 13, 2005 6:40 pm

Details

Post by stick881 »

ensiform wrote:c add the following above the entitylist function:.
Can you PM me with more details? thanks. :D
[url=http://www.play-casinos.d-4u.com]Play Casinos[/url] [url=http://virtual-online-gambling-10.9a7.net]gambling no download[/url]
Locked