Esempio n. 1
0
static void con_kick_all(void *result, void *user_data, int cid)
{
	if(!game.controller->is_race())
		return;
	
	for (int i = 0; i < MAX_CLIENTS; i++)
		if(game.players[i] && !game.players[i]->authed)
			server_kick(i, "You was kicked by 'kick_all'");

	char buf[128];
	str_format(buf, sizeof(buf), "All players are kicked.");
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
}
void PLAYER::afk_timer(int new_target_x, int new_target_y)
{
	/*
		afk timer (x, y = mouse coordinates)
		Since a player has to move the mouse to play, this is a better method than checking
		the player's position in the game world, because it can easily be bypassed by just locking a key.
		Frozen players could be kicked as well, because they can't move.
		It also works for spectators.
	*/
	
	if(authed) return; // don't kick admins
	if(config.sv_afk_time == 0) return; // 0 = disabled
	
	if(new_target_x != last_target_x || new_target_y != last_target_y)
	{
		// mouse was moved => playing, reset everything
		last_target_x = new_target_x;
		last_target_y = new_target_y;
		last_playtime = time_get();
		sent_afk_warning = 0;
		sent_afk_warning2 = 0;
	}
	else
	{
		// not playing, check how long
		if(sent_afk_warning == 0 && last_playtime < time_get()-time_freq()*(int)(config.sv_afk_time*0.5))
		{
			sprintf(
				afk_msg,
				"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
				(int)(config.sv_afk_time*0.5),config.sv_afk_time);
			game.send_chat_target(client_id, afk_msg);
			sent_afk_warning = 1;
		} 
		else if(sent_afk_warning2 == 0 && last_playtime < time_get()-time_freq()*(int)(config.sv_afk_time*0.9))
		{
			sprintf(
				afk_msg,
				"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
				(int)(config.sv_afk_time*0.9),
				config.sv_afk_time
			);
			game.send_chat_target(client_id, afk_msg);
			sent_afk_warning2 = 1;
		} else if(last_playtime < time_get()-time_freq()*config.sv_afk_time)
		{
			server_kick(client_id,"Away from keyboard");
		}
	}
}