コード例 #1
0
ファイル: g_svcmds.cpp プロジェクト: bibendovsky/rtcw
/*
==================
Svcmd_KickNum_f

Kick a user off of the server
==================
*/
static void Svcmd_KickNum_f( void ) {
	gclient_t   *cl;
	int timeout = -1;
	const char    *ip;
	char userinfo[MAX_INFO_STRING];
	char sTimeout[MAX_TOKEN_CHARS];
	char name[MAX_TOKEN_CHARS];
	int clientNum;

	// make sure server is running
	if ( !G_Is_SV_Running() ) {
		G_Printf( "Server is not running.\n" );
		return;
	}

	if ( trap_Argc() < 2 || trap_Argc() > 3 ) {
		G_Printf( "Usage: kick <client number> [timeout]\n" );
		return;
	}

	if ( trap_Argc() == 3 ) {
		trap_Argv( 2, sTimeout, sizeof( sTimeout ) );
		timeout = atoi( sTimeout );
	} else {
		timeout = 300;
	}

	trap_Argv( 1, name, sizeof( name ) );
	clientNum = atoi( name );

	cl = G_GetPlayerByNum( clientNum );
	if ( !cl ) {
		return;
	}
	if ( cl->pers.localClient ) {
		G_Printf( "Cannot kick host player\n" );
		return;
	}

	trap_GetUserinfo( cl->ps.clientNum, userinfo, sizeof( userinfo ) );
	ip = Info_ValueForKey( userinfo, "ip" );
	// use engine banning system, mods may choose to use their own banlist
	if ( USE_ENGINE_BANLIST ) {

		// kick but dont ban bots, they arent that lame
		if ( ( g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT ) ) {
			timeout = 0;
		}
		trap_DropClient( cl->ps.clientNum, "player kicked", timeout );
	} else {
		trap_DropClient( cl->ps.clientNum, "player kicked", 0 );

		// kick but dont ban bots, they arent that lame
		if ( !( g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT ) ) {
			AddIPBan( ip );
		}
	}
}
コード例 #2
0
ファイル: g_svcmds.c プロジェクト: leakcim1324/ETrun
/*
=================
ConsoleCommand

=================
*/
qboolean	ConsoleCommand( void ) {
	char	cmd[MAX_TOKEN_CHARS];

	trap_Argv( 0, cmd, sizeof( cmd ) );

#ifdef SAVEGAME_SUPPORT
	if (Q_stricmp (cmd, "savegame") == 0) {

		if( g_gametype.integer != GT_SINGLE_PLAYER )
			return qtrue;

		// don't allow a manual savegame command while we are waiting for the game to start/exit
		if (g_reloading.integer)
			return qtrue;
		if (saveGamePending)
			return qtrue;

		trap_Argv( 1, cmd, sizeof( cmd ) );
		if (strlen(cmd) > 0) {
			// strip the extension if provided
			if (strrchr(cmd, '.')) {
				cmd[strrchr(cmd,'.')-cmd] = '\0';
			}
			if ( !Q_stricmp( cmd, "current") ) {		// beginning of map
				Com_Printf("sorry, '%s' is a reserved savegame name.  please use another name.\n", cmd);
				return qtrue;
			}

			if (G_SaveGame( cmd ))
				trap_SendServerCommand(-1, "cp \"Game Saved\n\"");	// deletedgame
			else
				G_Printf( "Unable to save game.\n" );

		} else {	// need a name
			G_Printf( "syntax: savegame <name>\n" );
		}

		return qtrue;
	}
#endif // SAVEGAME_SUPPORT

	if ( Q_stricmp (cmd, "entitylist") == 0 ) {
		Svcmd_EntityList_f();
		return qtrue;
	}

	if ( Q_stricmp (cmd, "forceteam") == 0 ) {
		Svcmd_ForceTeam_f();
		return qtrue;
	}

	if (Q_stricmp (cmd, "game_memory") == 0) {
		Svcmd_GameMem_f();
		return qtrue;
	}

	/*if (Q_stricmp (cmd, "addbot") == 0) {
		Svcmd_AddBot_f();
		return qtrue;
	}
	if (Q_stricmp (cmd, "removebot") == 0) {
		Svcmd_AddBot_f();
		return qtrue;
	}*/
	if (Q_stricmp (cmd, "addip") == 0) {
		Svcmd_AddIP_f();
		return qtrue;
	}

	if (Q_stricmp (cmd, "removeip") == 0) {
		Svcmd_RemoveIP_f();
		return qtrue;
	}

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

	if (Q_stricmp (cmd, "listmaxlivesip") == 0) {
		PrintMaxLivesGUID();
		return qtrue;
	}

	if (Q_stricmp (cmd, "reset_match") == 0) {
		Svcmd_ResetMatch_f(qtrue, qtrue);
		return qtrue;
	}

	if (Q_stricmp (cmd, "swap_teams") == 0) {
		Svcmd_SwapTeams_f();
		return qtrue;
	}

	if (Q_stricmp (cmd, "shuffle_teams") == 0) {
		Svcmd_ShuffleTeams_f();
		return qtrue;
	}

	// -NERVE - SMF

	if (Q_stricmp (cmd, "makeReferee") == 0) {
		G_MakeReferee();
		return qtrue;
	}

	if (Q_stricmp (cmd, "removeReferee") == 0) {
		G_RemoveReferee();
		return qtrue;
	}

	/*if (Q_stricmp (cmd, "mute") == 0) {
		G_MuteClient();
		return qtrue;
	}

	if (Q_stricmp (cmd, "unmute") == 0) {
		G_UnMuteClient();
		return qtrue;
	}*/

	if (Q_stricmp (cmd, "ban") == 0) {
		G_PlayerBan();
		return qtrue;
	}

	if( Q_stricmp( cmd, "campaign" ) == 0 ) {
		Svcmd_Campaign_f();
		return qtrue;
	}

	if( Q_stricmp( cmd, "listcampaigns" ) == 0 ) {
		Svcmd_ListCampaigns_f();
		return qtrue;
	}

	// fretn - moved from engine
	if (!Q_stricmp(cmd, "kick")) {
		Svcmd_Kick_f();
		return qtrue;
	}
	
	if (!Q_stricmp(cmd, "clientkick")) {
		Svcmd_KickNum_f();
		return qtrue;
	}
	
	if (!Q_stricmp(cmd, "noVoteLimit")) {
		Svcmd_noVoteLimit();
		return qtrue;
	}

	if (!Q_stricmp(cmd, "cp")) {
		AP(va("cp \"%s\n\"", ConcatArgs(1)));
		return qtrue;
	}
	if (!Q_stricmp(cmd, "qsay")) {
		AP(va("chat \"%s\"", ConcatArgs(1)));
		G_LogPrintf("qsay: \"%s\n\"", ConcatArgs(1));
		return qtrue;
	}
	if (!Q_stricmp(cmd, "bp")) {
		AP(va("bp \"%s\"", ConcatArgs(1)));
		G_LogPrintf("banner: \"%s\n\"", ConcatArgs(1));
		return qtrue;
	}
	if (!Q_stricmp(cmd, "cpm")) {
		AP(va("cpm \"%s\n\"", ConcatArgs(1)));
		return qtrue;
	}


	if (!Q_stricmp(cmd, "freespec"))
	{
		gclient_t	*cl;
		char num[MAX_TOKEN_CHARS];
		int clientnum;

		trap_Argv(1, num, sizeof(num));
		clientnum = atoi(num);

		cl = G_GetPlayerByNum( clientnum );

		if ( !cl ) {
			return;
		}

		cl->sess.freeSpec = qtrue;
		return qtrue;
	}

	if (!Q_stricmp(cmd, "pcmd")) {
		gclient_t	*cl;
		char	name[MAX_TOKEN_CHARS];
		int		clientNum;

		trap_Argv(1, name, sizeof(name));
		clientNum = atoi(name);

		cl = G_GetPlayerByNum( clientNum );
	
		if ( !cl ) {
			return;
		}

		trap_SendServerCommand(cl - level.clients, va("pcmd %s", ConcatArgs(2)));
		return qtrue;
	}


	if (!Q_stricmp(cmd, "blockmap")) {
		char map[MAX_STRING_TOKENS];
		char blocklist[MAX_CVAR_VALUE_STRING];

		trap_Argv(1, map, sizeof(map));

		if (strlen(tjg_blockedMaps.string) + strlen(map) > sizeof(tjg_blockedMaps.string))
		{
			AP("print \"tjg_blockedMaps is full.\n\"");
		}
		else
		{
			Com_sprintf(blocklist, sizeof(blocklist), "%s %s", tjg_blockedMaps.string, map);
			trap_Cvar_Set("tjg_blockedMaps", va("%s", blocklist));
		}


		return qtrue;
	}

	
	if (!tjg_recordMode.integer)
	{
		if (!Q_stricmp(cmd, "forcecvar")) 
		{
			char cvar_name[MAX_TOKEN_CHARS]; 
			char cvar_val[MAX_TOKEN_CHARS];
			trap_Argv(1, cvar_name, sizeof(cvar_name)); 
			trap_Argv(2, cvar_val, sizeof(cvar_val)); 
			trap_Cvar_Set(cvar_name, va("%d", atoi(cvar_val))); 
			AP(va("print \"Forced %s to %s.\n\"", cvar_name, va("%d", atoi(cvar_val)) ) ); 
			return qtrue;
		}
	}

	if( g_dedicated.integer ) {
		if( !Q_stricmp (cmd, "say")) {
			trap_SendServerCommand( -1, va("cpm \"server: %s\n\"", ConcatArgs(1) ) );
			return qtrue;
		}

		// OSP - console also gets ref commands
		if(!level.fLocalHost && Q_stricmp(cmd, "ref") == 0) {
			// CHRUKER: b005 - G_refCommandCheck expects the next argument (warn, pause, lock etc).
			trap_Argv(1, cmd, sizeof(cmd)); 
			if(!G_refCommandCheck(NULL, cmd)) {
				G_refHelp_cmd(NULL);
			}
			return(qtrue);
		}

		// everything else will also be printed as a say command
//		trap_SendServerCommand( -1, va("cpm \"server: %s\n\"", ConcatArgs(0) ) );

		// prints to the console instead now
		return qfalse;
	}


	return qfalse;
}