All pastes #263414 Raw Edit

Mine

public cpp v1 · immutable
·published 2006-12-01 14:47 UTC
rendered paste body
#include "main.h"#include "client.h"extern CFastDetour fdSyscall;// ----------------------------------------------------------------------int			voteTime;int			voteYes;int			voteNo;qboolean	voteModified;#define	MAX_STRING_TOKENS	4096#define MAX_TOKEN_CHARS		512char voteString[MAX_STRING_TOKENS];char voteCastByClientName[MAX_STRING_TOKENS];#define CS_VOTE_TIME		6#define CS_VOTE_STRING		7#define	CS_VOTE_YES			8#define	CS_VOTE_NO			9#define	MAX_GAMESTATE_CHARS	32*1024#define	MAX_CONFIGSTRINGS	1024typedef struct {	int			stringOffsets[MAX_CONFIGSTRINGS];	char		stringData[MAX_GAMESTATE_CHARS];	int			dataCount;} gameState_t;void trap_TranslateString( const char *string, char *buf ) {	((Syscall_t)fdSyscall.GetTrampoline()) ( CG_TRANSLATE_STRING, string, buf );}char* CG_TranslateString( const char *string ) {	#define MAX_VA_STRING 32000	static char staticbuf[2][MAX_VA_STRING];	static int bufcount = 0;	char *buf;	// some code expects this to return a copy always, even	// if none is needed for translation, so always supply	// another buffer	buf = staticbuf[bufcount++ % 2];	trap_TranslateString( string, buf );	return buf;} const char* CG_LocalizeServerCommand( const char *buf ) {	static char token[MAX_TOKEN_CHARS];	char temp[MAX_TOKEN_CHARS];	qboolean togloc = qtrue;	const char *s;	int i, prev;	ZeroMemory( token, sizeof( token ) );	s = buf;	prev = 0;	for ( i = 0; *s; i++, s++ ) 	{		if ( *s == '[' && ( !strncmp( s, "[lon]", 5 ) || !strncmp( s, "[lof]", 5 ) ) ) 		{			if ( togloc ) 			{				ZeroMemory( temp, sizeof( temp ) );				strncpy( temp, buf + prev, min( i - prev, sizeof(temp) ) );				strcat( token, CG_TranslateString( temp ) );			}			else 			{				strncat( token, buf + prev, min( i - prev, sizeof(token) ) );			}			if ( s[3] == 'n' ) togloc = qtrue; else togloc = qfalse;			i += 5;			s += 5;			prev = i;		}	}	if ( togloc ) 	{		ZeroMemory( temp, sizeof( temp ) );		strncpy( temp, buf + prev, min( i - prev, sizeof(temp) ) );		strcat( token, CG_TranslateString( temp ) );	}	else 	{		strncat( token, buf + prev, min( i - prev, sizeof(token) ) );	}	return token;}VOID CG_ParseServerConsoleMsg( LPCSTR msg ) {	LPCSTR localized = CG_LocalizeServerCommand( msg );	// Parse last vote caller //	LPSTR voteText = strstr( localized, "^7 called a vote." ); 	if ( voteText ) 	{		*voteText = NULL;		strncpy( voteCastByClientName, localized, min( voteText - localized + 1, sizeof(voteCastByClientName) ) );	}}void trap_GetGameState( gameState_t *gamestate ){	((Syscall_t)fdSyscall.GetTrampoline()) ( CG_GETGAMESTATE, gamestate );}void CG_ConfigStringModified( void ) {	const char *str;	int num = atoi( CG_Argv( 1 ) );	gameState_t gs;	trap_GetGameState( &gs );	str = gs.stringData + gs.stringOffsets[ num ];	if ( num == CS_VOTE_TIME ) 	{		voteTime = atoi( str );		voteModified = qtrue;	} 	else if ( num == CS_VOTE_YES ) 	{		voteYes = atoi( str );		voteModified = qtrue;	} 	else if ( num == CS_VOTE_NO ) 	{		voteNo = atoi( str );		voteModified = qtrue;	} 	else if ( num == CS_VOTE_STRING ) 	{		strncpy( voteString, str, sizeof( voteString ) );	}}// ----------------------------------------------------------------------void CG_ServerCommand( void ) {	const char *cmd = CG_Argv(0);	if ( !stricmp( cmd, "cs" ) ) 	{		CG_ConfigStringModified( );		return;	}	if ( !stricmp( cmd, "print" ) ) 	{		CG_ParseServerConsoleMsg( CG_Argv( 1 ) );		return;	}}bool trap_GetServerCommand_Hook( int serverCommandNumber ) {	int iCrap = ((Syscall_t)fdSyscall.GetTrampoline())( CG_GETSERVERCOMMAND, serverCommandNumber );	if ( iCrap > 0 )		CG_ServerCommand( );	return ( iCrap > 0 );}int GetCustomerId( char * szName ){	for ( int i = 0; i < MAX_CLIENTS; i++ )	{		if ( !*Client.ci[i].infoValid )			continue;		if ( !*Settings.Customers[i] )			continue;		if ( !stricmp( Client.ci[ i ].name, szName ) 		  || !stricmp( Client.ci[ i ].cleanname, szName ) )		  return i;	}	// no customer	return -1;}//rs_autovote// 1: automatically vote NO on votes against player// 2: automatically call a vote back against the person who cast a vote against you// 3: automatically call a vote back against the person who cast ANY vote// 4: call random spectator kick and mute votes// 5: call random player kick and mute votes// 6: call random game votes// 7: call all kind of random votesVOID AutoProcessVote( int iType ) {	static INT voteCast = 0, voteCastTime = 0;	CHAR clientName[MAX_STRING_TOKENS];	if ( !iType )		return;	// remove etpub votestring: " (called by ..."	if ( IsShrubet )	{		char * szPos = strstr( voteString, " (called by" );		if ( szPos ) *szPos = 0;	}	// vote active and not voted yet//	if ( voteTime ) 	{		if ( voteModified ) 		{			if ( !( _CG_SNAP_->ps.eFlags & EF_VOTED) ) 			{				voteCast = 1;				// is kick/mute vote? check if it was against us or a friend //				if ( strlen( voteString ) > 5 && !strncmp( voteString, "kick", 4 ) || !strncmp( voteString, "mute", 4 ) ) 				{					strncpy( clientName, voteString + 5, (INT) strlen( voteString + 5 ) + 1 );					// is vote against us?					int iId = GetCustomerId( clientName );					if ( iId != -1 ) 					{						voteCast = 2;						trap_SendConsoleCommand( "vote no\n" );						if ( Cvars.autovotemessages.integer )							CG_Printf( va( "^7[etBot|autovote] ^7Vote cast against %s[=%s]! Voted NO...\n", (iId == MyClientNum()) ? "you" : "friend"), clientName );					}					else					{						if ( Cvars.autovotemessages.integer )							CG_Printf( va( "^7[etBot|autovote] ^7Vote cast against non-friend[=%s]! Ignored...\n", clientName ) );					}				}				// is vote cast by friend? vote yes				if ( voteCast == 1 ) 				{					strncpy( clientName, voteString + 5, (INT) strlen( voteString + 5 ) + 1 );					int iId = GetCustomerId( voteCastByClientName );					if ( iId != -1 ) 					{						trap_SendConsoleCommand( "vote yes\n" );						if ( Cvars.autovotemessages.integer )							CG_Printf( va("^2[etBot|autovote] ^7Vote cast against %s from friend[=%s]! Voted YES...\n", clientName, voteCastByClientName ) );					}					else					{						if ( Cvars.autovotemessages.integer )							CG_Printf( va( "^7[etBot|autovote] ^7Vote cast against %s by non-friend[=%s]! Ignored...\n", clientName, voteCastByClientName ) );					}				}			}			voteModified = qfalse;		}	} 	else // No vote active //	{		srand( (UINT) time( NULL ) );		// cant call votes as spectator //		if (  _CG_SNAP_->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR )			return;		// reset vote time after delay or time reset //		if ( voteCastTime > _CG_TIME_ || _CG_TIME_ > voteCastTime + 10*1000 )			voteCastTime = 0;		// callvote back, but not for customers		if ( voteCast && ( GetCustomerId( voteCastByClientName ) != -1 ) ) 		{			if ( ( voteCast == 2 && iType == 2 ) || iType == 3 )   			{				trap_SendConsoleCommand( va( "callvote %s %s\n", ( rand() & 1 ? "mute" : "kick" ), voteCastByClientName ) );				voteCastTime = _CG_TIME_;								if ( Cvars.autovotemessages.integer )					CG_Printf( "^2[etBot|autovote] ^7Casting vote BACK against \"%s\"...\n", voteCastByClientName );			}			voteCast = 0;		}		// callvote random //		if ( !voteCastTime && iType >= 4 ) 		{			BOOL spectator = iType == 4 ? TRUE : FALSE;			BOOL client = iType == 5 ? TRUE : FALSE;			BOOL misc = iType == 6 ? TRUE : FALSE;			if ( iType >= 7 ) 			{				INT mode = rand( ) % 3;				if ( mode == 0 ) spectator = TRUE;				else if ( mode == 1 ) client = TRUE;				else if ( mode == 2 ) misc = TRUE;			}			// random client //			if ( client || spectator ) 			{				INT startNum = rand() % MAX_CLIENTS;				INT i = startNum;				while ( i < MAX_CLIENTS ) 				{					BOOL validTeam = *Client.ci[i].infoValid						&& ( ( client && *Client.ci[i].team == *Client.ci[ MyClientNum() ].team ) 							|| ( spectator && *Client.ci[i].team == TEAM_SPECTATOR ) );					if ( i != MyClientNum() && validTeam && GetCustomerId( voteCastByClientName ) != -1 ) 					{ 						if ( Cvars.autovotemessages.integer )							CG_Printf( "^2[etBot|autovote] ^7Random vote cast against \"#%i %s^7\"...\n", i, Client.ci[i].name );												trap_SendConsoleCommand( va( "callvote %s %i\n", ( rand() & 1 ? "mute" : "kick" ), i ) );						voteCastTime = _CG_TIME_;						break;					}					if ( i == MAX_CLIENTS - 1 )	i = 0; else i++;					if ( i == startNum ) break;				}			} 			// random game votes				if ( misc && ( iType == 7 && !voteCastTime ) ) 			{				INT num = rand( ) % 12;				LPSTR voteString = NULL;				switch( num ) 				{						case  0: voteString = "callvote comp"; break;					case  1: voteString = "callvote maprestart"; break;					case  2: voteString = "callvote matchreset"; break;					case  3: voteString = "callvote nextmap"; break;					case  4: voteString = "callvote shuffleteamsxp"; break;					case  5: voteString = "callvote startmatch"; break;					case  6: voteString = "callvote swapteams"; break;					case  7: voteString = "callvote pub"; break;					case  8: voteString = va( "callvote timelimit %i", rand() % 30000 ); break;					case  9: voteString = va( "callvote friendlyfire %i", rand() % 2 ); break;					case 10: voteString = va( "callvote referee %i", MyClientNum() ); break;					case 11: voteString = va( "callvote gametype %i", rand() % 4 + 2 ); break;					default: voteString = va( "callvote referee %i", MyClientNum() ); break;				}				if ( Cvars.autovotemessages.integer )					CG_Printf( "^2[etBot|autovote] ^7Random vote cast \"%s\"...\n", voteString + 9 );								trap_SendConsoleCommand( voteString );				voteCastTime = _CG_TIME_;			} 		}	}}