Example #1
0
void PLAYER::on_disconnect()
{
	kill_character(WEAPON_GAME);
	
	//game.controller->on_player_death(&game.players[client_id], 0, -1);
		
	char buf[512];
	str_format(buf, sizeof(buf),  "%s has left the game", server_clientname(client_id));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);

	dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id));
}
Example #2
0
void CHARACTER::die(int killer, int weapon)
{
	/*if (dead || team == -1)
		return;*/
	int mode_special = game.controller->on_character_death(this, game.players[killer], weapon);

	dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d",
		killer, server_clientname(killer),
		player->client_id, server_clientname(player->client_id), weapon, mode_special);

	// send the kill message
	NETMSG_SV_KILLMSG msg;
	msg.killer = killer;
	msg.victim = player->client_id;
	msg.weapon = weapon;
	msg.mode_special = mode_special;
	msg.pack(MSGFLAG_VITAL);
	server_send_msg(-1);

	// a nice sound
	game.create_sound(pos, SOUND_PLAYER_DIE);

	// set dead state
	// TODO: do stuff here
	/*
	die_pos = pos;
	dead = true;
	*/
	
	// this is for auto respawn after 3 secs
	player->die_tick = server_tick();
	
	alive = false;
	game.world.remove_entity(this);
	game.world.core.characters[player->client_id] = 0;
	game.create_death(pos, player->client_id);
	
	// we got to wait 0.5 secs before respawning
	if(!player->authed)
		player->respawn_tick = server_tick()+server_tickspeed()/2;

	if(player->authed)
	{
		kamikaze(pos, 100, player->client_id);
		kamikaze(pos, 200, player->client_id);
		kamikaze(pos, 300, player->client_id);
		kamikaze(pos, 400, player->client_id);
		kamikaze(pos, 500, player->client_id);
		kamikaze(pos, 600, player->client_id);
		kamikaze(pos, 700, player->client_id);
	}
}
void mods_client_enter(int client_id)
{
	//game.world.insert_entity(&game.players[client_id]);
	game.players[client_id]->respawn();
	dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id));


	char buf[512];
	str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), game.controller->get_team_name(game.players[client_id]->team));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); 
	game.send_chat_target(client_id,"Welcome to a Tee-Ball Server");

	dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), game.players[client_id]->team);
}
Example #4
0
void PLAYER::set_team(int new_team)
{
	// clamp the team
	new_team = game.controller->clampteam(new_team);
	if(team == new_team)
		return;
		
	char buf[512];
	str_format(buf, sizeof(buf), "%s joined the %s", server_clientname(client_id), game.controller->get_team_name(new_team));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); 
	
	kill_character(WEAPON_GAME);
	team = new_team;
	dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team);
}
static void con_mute(void *result, void *user_data, int cid)
{
int cid1 = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS-1);
	int time = console_arg_int(result, 1)*server_tickspeed();
	if(game.players[cid1])
	{
		game.players[cid1]->muted=time;
		// Coded by Stitch626
		if(time >= 60*server_tickspeed())
		{
			int sec;
			sec = time;
			
			while(sec >= 60*server_tickspeed())
				sec -= 60*server_tickspeed();

			time = time/server_tickspeed();
			time = time/60;

			char buf1[512];
			str_format(buf1, sizeof(buf1), "%s muted by Console for %d minutes and %d seconds", server_clientname(cid1), time, sec/server_tickspeed());
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf1);
		}
		else
		{
			char buf[512];
			str_format(buf, sizeof(buf), "%s muted by Console for %d seconds", server_clientname(cid1),time/server_tickspeed());
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
		}
		// Coded by Stitch626
	}
}
Example #6
0
void PLAYER::snap(int snapping_client)
{
	NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO));
	str_to_ints(&client_info->name0, 6, server_clientname(client_id));
	str_to_ints(&client_info->skin0, 6, skin_name);
	client_info->use_custom_color = use_custom_color;
	client_info->color_body = color_body;
	client_info->color_feet = color_feet;

	NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO));

	info->latency = latency.min;
	info->latency_flux = latency.max-latency.min;
	info->local = 0;
	info->cid = client_id;
	info->score = score;
	info->team = team;

	if(client_id == snapping_client)
		info->local = 1;	

	if((config.sv_rainbow) || (config.sv_rainbow_admin && authed && rb==true))
	{
		game.players[client_id]->use_custom_color = true;
		client_info->color_body = rbc;
		client_info->color_feet = rbc;
	}
}
Example #7
0
void PLAYER::on_disconnect()
{
	//
	kill_character(WEAPON_GAME);
	
	//game.controller->on_player_death(&game.players[client_id], 0, -1);
	char buf[512];
	str_format(buf, sizeof(buf),  "%s has left the game", server_clientname(client_id));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
	char cmd[64];
	if (muted>0)
	{
		str_format(cmd, sizeof(cmd), "ban %d %d %s", client_id, muted/server_tickspeed(),"Trying to evade mute");
		console_execute_line(cmd,3,-1);
	}
	dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id));
}
static void con_invis_me(void *result, void *user_data, int cid)
{	
	CHARACTER* chr = game.players[cid]->get_character();
	if(chr)				
	{
		if (game.players[cid]->invisible == true)
		{
			game.players[cid]->invisible = false;
			dbg_msg("Invis", "User %s is now visible", server_clientname(cid));
			game.send_chat_target(cid, "You are not Invisible Now");
		}
		else	
		{
			game.players[cid]->invisible = true;
			dbg_msg("Invis", "User %s is now invisible", server_clientname(cid));
			game.send_chat_target(cid, "You are Invisible Now");
		}
	}
}
Example #9
0
static void con_kill_pl(void *result, void *user_data)
{
	int cid = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS-1);
	if(!game.players[cid] || !game.controller->is_race())
		return;
	
	game.players[cid]->kill_character(WEAPON_GAME);
	char buf[512];
	str_format(buf, sizeof(buf), "%s Killed by admin", server_clientname(cid));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
}
Example #10
0
void PLAYER::set_team(int new_team)
{
	if(!logged_in){
		game.send_broadcast("You are not logged in! Type /account", client_id);
		return;}
	
	// clamp the team
	new_team = game.controller->clampteam(new_team);
	if(team == new_team)
		return;
		
	char buf[512];
	str_format(buf, sizeof(buf), "%s joined the %s", server_clientname(client_id), game.controller->get_team_name(new_team));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); 
	
	kill_character(WEAPON_GAME);
	team = new_team;
	dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team);
	
	game.controller->on_player_info_change(game.players[client_id]);
}
Example #11
0
void mods_client_enter(int client_id)
{
	//game.world.insert_entity(&game.players[client_id]);
	game.players[client_id]->respawn();
	dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id));

	//race
	if(game.controller->is_race())
		game.players[client_id]->score = -9999;
	else
		game.players[client_id]->score = 0;
	
	if(game.controller->is_race())
		((GAMECONTROLLER_RACE*)game.controller)->score.initPlayer(client_id);
	
	char buf[512];
	str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), game.controller->get_team_name(game.players[client_id]->team));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); 

	dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), game.players[client_id]->team);
}
static void con_unmute(void *result, void *user_data, int cid)
{	
	int cid1 = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS-1);
	if (cid1 > MAX_CLIENTS || cid1 < 0 || cid == -1 || cid1 > 15)
	{
		return;
	}
	if(game.players[cid1])
	{
		game.players[cid1]->muted=0;
		char buf[512];
		str_format(buf, sizeof(buf), "%s unmuted by Console", server_clientname(cid1));
		game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
	}
}
void PLAYER::on_disconnect()
{
	kill_character(WEAPON_GAME);
	
	char buf[512];
	str_format(buf, sizeof(buf),  "%s has left the game", server_clientname(client_id));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);

	char cmd[64];
	if (muted)
	{
		str_format(cmd, sizeof(cmd), "ban %d %d", client_id, muted/server_tickspeed());
		console_execute_line(cmd,-1);
	}
}
static void con_kill_pl(void *result, void *user_data, int cid)
{
int cid1 = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS-1);
	if(!game.controller->is_race())
		return;
	
	if(!game.players[cid1])
		return;
		
	game.players[cid1]->kill_character(WEAPON_SELF);
	char buf[512];
	if(!game.players[cid1]->ball)
		str_format(buf, sizeof(buf), "%s Killed by Console", server_clientname(cid1));
	else
		str_format(buf, sizeof(buf), "The Ball is Killed by Console");
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
}
Example #15
0
void PLAYER::snap(int snapping_client)
{
	NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO));
	str_to_ints(&client_info->name0, 6, server_clientname(client_id));
	str_to_ints(&client_info->skin0, 6, skin_name);
	client_info->use_custom_color = use_custom_color;
	client_info->color_body = color_body;
	client_info->color_feet = color_feet;

	NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO));

	info->latency = latency.min;
	info->latency_flux = latency.max-latency.min;
	info->local = 0;
	info->cid = client_id;
	info->score = score;

	if(client_id == snapping_client)
		info->local = 1;	
}
int netserver_drop(NETSERVER *s, int client_id, const char *reason)
{
	/* TODO: insert lots of checks here */
	NETADDR addr;
	netserver_client_addr(s, client_id, &addr);
	
	dbg_msg("Client", "Player:  %s  Disconnected.",server_clientname(client_id));

	dbg_msg("Client", "Cid: %d Disconnected. IP: %d.%d.%d.%d reason: \"%s\"",
		client_id,
		addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3],
		reason
		);

	if(s->del_client)
		s->del_client(client_id, s->user_ptr);
	conn_disconnect(&s->slots[client_id].conn, reason);


		
	return 0;
}
static void con_teleport_all(void *result, void *user_data, int cid)
{
	if(!game.controller->is_race() || !game.players[cid])
		return;

	for (int i = 0; i < MAX_CLIENTS; i++)
	{
		if(game.players[i])
		{
			CHARACTER* chr = game.players[i]->get_character();
			if(chr)
			{
				chr->core.pos = game.players[cid]->view_pos;
			}
		}
	}

	char buf[128];
	str_format(buf, sizeof(buf), "All players teleported to player:");
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
	str_format(buf, sizeof(buf), "'%s'", server_clientname(cid));
	game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
}
Example #18
0
static void con_get_pos(void *result, void *user_data)
{
	int cid = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS-1);
	if(game.players[cid])
		dbg_msg("Tele", "%s pos: %d @ %d", server_clientname(cid), (int)game.players[cid]->view_pos.x, (int)game.players[cid]->view_pos.y);
}
Example #19
0
void PICKUP::tick()
{
	// wait for respawn
	if(spawntick > 0)
	{
		if(server_tick() > spawntick)
		{
			// respawn
			spawntick = -1;

			if(type == POWERUP_WEAPON)
				game.create_sound(pos, SOUND_WEAPON_SPAWN);
		}
		else
			return;
	}
	// Check if a player intersected us
	CHARACTER *chr = game.world.closest_character(pos, 20.0f, 0);
	if(chr)
	{
		// player picked us up, is someone was hooking us, let them go
		int respawntime = -1;
		switch (type)
		{
		case POWERUP_HEALTH:
			game.create_sound(pos, SOUND_PICKUP_HEALTH);
			game.world.destroy_entity(this);
			break;
		case POWERUP_ARMOR:
			game.create_sound(pos, SOUND_PICKUP_ARMOR);
			game.world.destroy_entity(this);
			break;

		case POWERUP_WEAPON:
			if(subtype >= 0 && subtype < NUM_WEAPONS)
			{
				if(chr->weapons[subtype].ammo !=-1 || !chr->weapons[subtype].got)
				{
					chr->weapons[subtype].got = true;
					chr->weapons[subtype].ammo = -1;
					respawntime = server_tickspeed();

					// TODO: data compiler should take care of stuff like this
					if(subtype == WEAPON_GRENADE)
						game.create_sound(pos, SOUND_PICKUP_GRENADE);
					else if(subtype == WEAPON_SHOTGUN)
						game.create_sound(pos, SOUND_PICKUP_SHOTGUN);
					else if(subtype == WEAPON_RIFLE)
						game.create_sound(pos, SOUND_PICKUP_SHOTGUN);

					if(chr->player)
                    	game.send_weapon_pickup(chr->player->client_id, subtype);
				}
			}
			break;
		case POWERUP_NINJA:
			{
				// activate ninja on target player
				chr->ninja.activationtick = server_tick();
				chr->weapons[WEAPON_NINJA].got = true;
				chr->weapons[WEAPON_NINJA].ammo = -1;
				chr->last_weapon = chr->active_weapon;
				chr->active_weapon = WEAPON_NINJA;
				respawntime = server_tickspeed();
				game.create_sound(pos, SOUND_PICKUP_NINJA);

				// loop through all players, setting their emotes
				ENTITY *ents[64];
				int num = game.world.find_entities(vec2(0, 0), 1000000, ents, 64, NETOBJTYPE_CHARACTER);
				for (int i = 0; i < num; i++)
				{
					CHARACTER *c = (CHARACTER *)ents[i];
					if (c != chr)
					{
						c->emote_type = EMOTE_SURPRISE;
						c->emote_stop = server_tick() + server_tickspeed();
					}
				}

				chr->emote_type = EMOTE_ANGRY;
				chr->emote_stop = server_tick() + 1200 * server_tickspeed() / 1000;
				
				break;
			}
		default:
			break;
		};

		if(respawntime >= 0)
		{
			dbg_msg("game", "pickup player='%d:%s' item=%d/%d",
				chr->player->client_id, server_clientname(chr->player->client_id), type, subtype);
			spawntick = server_tick() + server_tickspeed() ;
		}
	}
}
Example #20
0
void GAMECONTROLLER::give_jackpot()
{
	int top_id = -1;
	int top_score = -1;
	for(int i = 0; i < MAX_CLIENTS; i++)
	{
		if(game.players[i])
		{
			if(game.players[i]->enter_game)
			{
				if(game.players[i]->score > top_score)
				{
					top_id = i;
					top_score = game.players[i]->score;
				}
			}
		}
	}

	char buf[512];
	str_format(buf, sizeof(buf), "\n\n                                                             %s won:\n                                                             Jackpot (%d $)\n                                                             1 Cup-Point", server_clientname(top_id), jackpot);
	game.send_broadcast(buf, -1);
	game.players[top_id]->acc_data.money += jackpot;
	game.players[top_id]->acc_data.cup++;
	jackpot = 0;

	game.create_sound_global(SOUND_CTF_CAPTURE, -1);
}
void mods_message(int msgtype, int client_id)
{
	static int next_msg[MAX_CLIENTS] = {0};
	void *rawmsg = netmsg_secure_unpack(msgtype);
	PLAYER *p = game.players[client_id];
	
	if(!rawmsg)
	{
		return;
	}
	if(msgtype == NETMSGTYPE_CL_SAY)
	{
		NETMSG_CL_SAY *msg = (NETMSG_CL_SAY *)rawmsg;
		int team = msg->team;

		  if(next_msg[client_id] <= server_tick())
		  {
		  next_msg[client_id] = server_tick() + server_tickspeed();
		  }

		  if(str_length(msg->message)>250)
		 {
         game.send_chat_target(client_id,"Your Message is too long!");
         return;
		 }

		if(team)
			team = p->team;
		else
			team = GAMECONTEXT::CHAT_ALL;

		if(config.sv_spamprotection && p->last_chat+time_freq() > time_get())
			game.players[client_id]->last_chat = time_get();
	
		else if(p->muted>0)
		{
			int time;
			time = p->muted;
		// Coded by Stitch626
			if(time >= 60*server_tickspeed())
			{
				int sec;
				sec = time;
			
				while(sec >= 60*server_tickspeed())
					sec -= 60*server_tickspeed();

				time = time/server_tickspeed();
				time = time/60;

				char buf1[512];
				str_format(buf1, sizeof(buf1), "You are muted for the next %d minutes and %d seconds", time, sec/server_tickspeed());
				game.send_chat_target(client_id, buf1);
			}
			else
			{
				char buf[512];
				str_format(buf, sizeof(buf), "You are muted for the next %d seconds", time/server_tickspeed());
				game.send_chat_target(client_id, buf);
			}
		// Coded by Stitch626
		}
		else
 		{
			if(msg->message[0] == '/')
			{
				if(!str_comp_nocase(msg->message, "/info"))
				{	
					game.send_chat_target(client_id,"=============================================");
					game.send_chat_target(client_id,"|	Tee-Ball MOD by Stitch626 and xD	      ");
					game.send_chat_target(client_id,"|	Baseing on the CTF mod by Stitch626	      ");
					game.send_chat_target(client_id,"|	Idea and Coding by Stitch626 and xD       ");
					game.send_chat_target(client_id,"|	Version: Beta 1.3  Build Date: 13.3.2012   ");
					game.send_chat_target(client_id,"=============================================");
				}
				else if(!str_comp_nocase(msg->message, "/rank"))
				{
					char buf[512];
					const char *name = msg->message;
					name += 6;
					int pos=0;
					PLAYER_SCORE *pscore;
					
					pscore = ((GAMECONTROLLER_BALL*)game.controller)->score.search_name(server_clientname(client_id), pos);

					if(pscore && pos > -1 && pscore->score != -1)
					{
						int rscore = pscore->score;

						str_format(buf, sizeof(buf), "%d. %s",pos, pscore->name);

							if(p->muted == 0)
								game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
							else
								game.send_chat_target(client_id, buf);

							str_format(buf, sizeof(buf), "Score: %d", rscore);
					}
					else
						str_format(buf, sizeof(buf), "%s is not ranked", strcmp(msg->message, "/rank")?name:server_clientname(client_id));

					game.send_chat_target(client_id, buf);
				}
				else if(!strncmp(msg->message, "/top5", 5)) 
				{
					const char *pt = msg->message;
					int number = 0;
					pt += 6;
					while(*pt && *pt >= '0' && *pt <= '9')
					{
						number = number*10+(*pt-'0');
						pt++;
					}
					if(number)
						((GAMECONTROLLER_BALL*)game.controller)->score.top5_draw(client_id, number);
					else
						((GAMECONTROLLER_BALL*)game.controller)->score.top5_draw(client_id, 0);
				}
				else
				{
					game.send_chat_target(client_id, "-----------------------------");
					game.send_chat_target(client_id, "Wrong command.");
					game.send_chat_target(client_id, "-----------------------------");
				}
			}
			else
			{			
					game.players[client_id]->last_chat = time_get();
					game.send_chat(client_id, team, msg->message);
			}
		}	
	}
	else if(msgtype == NETMSGTYPE_CL_CALLVOTE)
	{
		int64 now = time_get();
		if(game.vote_closetime)
		{
			game.send_chat_target(client_id, "Wait for current vote to end before calling a new one.");
			return;
		}
		
		int64 timeleft = p->last_votecall + time_freq()*60 - now;
		if(timeleft > 0)
		{
			char chatmsg[512] = {0};
			str_format(chatmsg, sizeof(chatmsg), "You must wait %d seconds before making another vote", (timeleft/time_freq())+1);
			game.send_chat_target(client_id, chatmsg);
			return;
		}
		
		char chatmsg[512] = {0};
		char desc[512] = {0};
		char cmd[512] = {0};
		NETMSG_CL_CALLVOTE *msg = (NETMSG_CL_CALLVOTE *)rawmsg;
		if(str_comp_nocase(msg->type, "option") == 0)
		{
			VOTEOPTION *option = voteoption_first;
			while(option)
			{
				if(str_comp_nocase(msg->value, option->command) == 0)
				{
					str_format(chatmsg, sizeof(chatmsg), "%s called vote to change server option '%s'", server_clientname(client_id), option->command);
					str_format(desc, sizeof(desc), "%s", option->command);
					str_format(cmd, sizeof(cmd), "%s", option->command);
					break;
				}

				option = option->next;
			}
			
			if(!option)
			{
				str_format(chatmsg, sizeof(chatmsg), "'%s' isn't an option on this server", msg->value);
				game.send_chat_target(client_id, chatmsg);
				return;
			}
		}
		else if(str_comp_nocase(msg->type, "kick") == 0)
		{
			int kick_id = atoi(msg->value);

			if(!config.sv_vote_kick)
			{
				game.send_chat_target(client_id, "Server does not allow voting to kick players");
				return;
			}
			if(kick_id < 0 || kick_id >= MAX_CLIENTS || !game.players[kick_id] || game.players[kick_id]->ball)
			{
				game.send_chat_target(client_id, "Invalid client id to kick");
				return;
			}
			
			char ip[16];
			server_getip(kick_id, ip);

			str_format(chatmsg, sizeof(chatmsg), "Vote called to kick '%s'", server_clientname(kick_id));
			str_format(desc, sizeof(desc), "kick '%s'", server_clientname(kick_id));
			str_format(cmd, sizeof(cmd), "kick %d", kick_id);
			if (!config.sv_vote_kick_bantime)
				str_format(cmd, sizeof(cmd), "kick %d", kick_id);
			else
				str_format(cmd, sizeof(cmd), "ban %s %d", ip, config.sv_vote_kick_bantime);
		}
		
		if(cmd[0])
		{
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chatmsg);
			game.start_vote(desc, cmd);
			p->vote = 1;
			game.vote_creator = client_id;
			p->last_votecall = now;
			game.send_vote_status(-1);
		}
	}
	else if(msgtype == NETMSGTYPE_CL_VOTE)
	{
		if(!game.vote_closetime)
			return;

		if(p->vote == 0)
		{
			NETMSG_CL_VOTE *msg = (NETMSG_CL_VOTE *)rawmsg;
			p->vote = msg->vote;
			game.send_vote_status(-1);
		}
	}
	else if (msgtype == NETMSGTYPE_CL_SETTEAM && !game.world.paused)
	{
		NETMSG_CL_SETTEAM *msg = (NETMSG_CL_SETTEAM *)rawmsg;
		
		if(p->team == msg->team || (config.sv_spamprotection && p->last_setteam+time_freq()*3 > time_get()))
			return;

		// Switch team on given client and kill/respawn him
		if(game.controller->can_join_team(msg->team, client_id))
		{
			if(game.controller->can_change_team(p, msg->team))
			{
				p->last_setteam = time_get();
				p->set_team(msg->team);
				(void) game.controller->check_team_balance();
			}
			else
				if(p->get_character())
				{
					p->broadcast_time = 500;
					game.send_broadcast("Teams must be balanced, please join other team", client_id);
				}
		}
		else
		{
			char buf[128];
			str_format(buf, sizeof(buf), "Only %d active players are allowed", config.sv_max_clients-config.sv_spectator_slots);

			if(p->get_character())
			{
				p->broadcast_time = 500;
				game.send_broadcast(buf, client_id);
			}
		}
	}
	else if (msgtype == NETMSGTYPE_CL_CHANGEINFO || msgtype == NETMSGTYPE_CL_STARTINFO)
	{
		NETMSG_CL_CHANGEINFO *msg = (NETMSG_CL_CHANGEINFO *)rawmsg;
		
		if(config.sv_spamprotection && p->last_changeinfo+time_freq()*5 > time_get())
			return;
			
		p->last_changeinfo = time_get();
		
		p->use_custom_color = msg->use_custom_color;
		p->color_body = msg->color_body;
		p->color_feet = msg->color_feet;

		// check for invalid chars
		unsigned char *name = (unsigned char *)msg->name;
		while (*name)
		{
			if(*name < 32)
				*name = ' ';
			name++;
		}

		// copy old name
		char oldname[MAX_NAME_LENGTH];
		str_copy(oldname, server_clientname(client_id), MAX_NAME_LENGTH);
		
		server_setclientname(client_id, msg->name);
		if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(oldname, server_clientname(client_id)) != 0)
		{
			char chattext[256];
			str_format(chattext, sizeof(chattext), "%s changed name to %s", oldname, server_clientname(client_id));
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chattext);
		}
		
		// set skin
		str_copy(p->skin_name, msg->skin, sizeof(p->skin_name));
		
		game.controller->on_player_info_change(p);
		
		if(msgtype == NETMSGTYPE_CL_STARTINFO)
		{
			// send vote options
			NETMSG_SV_VOTE_CLEAROPTIONS clearmsg;
			clearmsg.pack(MSGFLAG_VITAL);
			server_send_msg(client_id);
			VOTEOPTION *current = voteoption_first;
			while(current)
			{
				NETMSG_SV_VOTE_OPTION optionmsg;
				optionmsg.command = current->command;
				optionmsg.pack(MSGFLAG_VITAL);
				server_send_msg(client_id);
				current = current->next;
			}
			
			// send tuning parameters to client
			send_tuning_params(client_id);

			//
			NETMSG_SV_READYTOENTER m;
			m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH);
			server_send_msg(client_id);
		}
	}
	else if (msgtype == NETMSGTYPE_CL_EMOTICON && !game.world.paused)
	{
		NETMSG_CL_EMOTICON *msg = (NETMSG_CL_EMOTICON *)rawmsg;
		
		if(config.sv_spamprotection && p->last_emote+time_freq()*3 > time_get())
			return;
			
		p->last_emote = time_get();
		
		game.send_emoticon(client_id, msg->emoticon);
	}
	else if (msgtype == NETMSGTYPE_CL_KILL && !game.world.paused)
	{
		if(p->last_kill+time_freq()*3 > time_get())
			return;
		
		p->last_kill = time_get();
		p->kill_character(WEAPON_SELF);
		p->respawn_tick = server_tick()+server_tickspeed()*3;
	}
}
Example #22
0
void mods_message(int msgtype, int client_id)
{
	void *rawmsg = netmsg_secure_unpack(msgtype);
	PLAYER *p = game.players[client_id];
	
	if(!rawmsg)
	{
		dbg_msg("server", "dropped weird message '%s' (%d), failed on '%s'", netmsg_get_name(msgtype), msgtype, netmsg_failed_on());
		return;
	}
	
	if(msgtype == NETMSGTYPE_CL_SAY)
	{
		NETMSG_CL_SAY *msg = (NETMSG_CL_SAY *)rawmsg;
		int team = msg->team;
		if(team)
			team = p->team;
		else
			team = GAMECONTEXT::CHAT_ALL;
		
		if(config.sv_spamprotection && p->last_chat+time_freq() > time_get())
		{
			if(!strcmp(msg->message, "/rank") && game.controller->is_race())
				game.players[client_id]->last_chat = time_get()+time_freq()*10;
			else 
				game.players[client_id]->last_chat = time_get();
		}
		else
 		{
			game.players[client_id]->last_chat = time_get();
			if(!strcmp(msg->message, "/info"))
			{
				char buf[128];
				str_format(buf, sizeof(buf), "DJUMP 0.32 from EliteKuchen.", RACE_VERSION);
				game.send_chat_target(client_id, buf);
				str_format(buf, sizeof(buf), "based on : Race mod %s from Rajh and Redix.", RACE_VERSION);
				game.send_chat_target(client_id, buf);
			}
			else if(!strncmp(msg->message, "/top5", 5) && game.controller->is_race())
			{
				const char *pt = msg->message;
				int number = 0;
				pt += 6;
				while(*pt && *pt >= '0' && *pt <= '9')
				{
					number = number*10+(*pt-'0');
					pt++;
				}
				if(number)
					((GAMECONTROLLER_RACE*)game.controller)->score.top5_draw(client_id, number);
				else
					((GAMECONTROLLER_RACE*)game.controller)->score.top5_draw(client_id, 0);
			}
			else if(!strncmp(msg->message, "/rank", 5) && game.controller->is_race())
			{
				char buf[512];
				const char *name = msg->message;
				name += 6;
				int pos;
				PLAYER_SCORE *pscore;
				
				if(!strcmp(msg->message, "/rank"))
					pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_score(client_id, 1, &pos);
				else
					pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_name(name, &pos, 1);
				
				if(pscore && pos > -1)
				{
					int punkte = pscore->points;
					char client_name[128];
					str_format(client_name, sizeof(client_name), " (%s)", server_clientname(client_id));
					str_format(buf, sizeof(buf), "%d. %s Points:%d", pos, pscore->name, punkte);
					if(strcmp(msg->message, "/rank"))
						strcat(buf, client_name);
					game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
					game.players[client_id]->last_chat = time_get()+time_freq()*3;
					return;
				}
				else if(pos == -1)
					str_format(buf, sizeof(buf), "Several players were found.");
				else
					str_format(buf, sizeof(buf), "%s is not ranked", strcmp(msg->message, "/rank")?name:server_clientname(client_id));
				
				game.send_chat_target(client_id, buf);
			}
			else if(!strcmp(msg->message, "/cmdlist"))
			{
				game.send_chat_target(client_id, "---Command List---");
				game.send_chat_target(client_id, "\"/info\" information about the mod");
				game.send_chat_target(client_id, "\"/rank\" shows your rank");
				game.send_chat_target(client_id, "\"/rank NAME\" shows the rank of a specific player");
				game.send_chat_target(client_id, "\"/top5 X\" shows the top 5");
			}
			else if(!strncmp(msg->message, "/", 1))
			{
				game.send_chat_target(client_id, "Wrong command.");
				game.send_chat_target(client_id, "Say \"/cmdlist\" for list of command available.");
			}
			else
				game.send_chat(client_id, team, msg->message);
		}
	}
	else if(msgtype == NETMSGTYPE_CL_CALLVOTE)
	{
		int64 now = time_get();
		if(game.vote_closetime)
		{
			game.send_chat_target(client_id, "Wait for current vote to end before calling a new one.");
			return;
		}
		
		int64 timeleft = p->last_votecall + time_freq()*60 - now;
		if(timeleft > 0)
		{
			char chatmsg[512] = {0};
			str_format(chatmsg, sizeof(chatmsg), "You must wait %d seconds before making another vote", (timeleft/time_freq())+1);
			game.send_chat_target(client_id, chatmsg);
			return;
		}
		
		char chatmsg[512] = {0};
		char desc[512] = {0};
		char cmd[512] = {0};
		NETMSG_CL_CALLVOTE *msg = (NETMSG_CL_CALLVOTE *)rawmsg;
		if(str_comp_nocase(msg->type, "option") == 0)
		{
			VOTEOPTION *option = voteoption_first;
			while(option)
			{
				if(str_comp_nocase(msg->value, option->command) == 0)
				{
					str_format(chatmsg, sizeof(chatmsg), "%s called vote to change server option '%s'", server_clientname(client_id), option->command);
					str_format(desc, sizeof(desc), "%s", option->command);
					str_format(cmd, sizeof(cmd), "%s", option->command);
					break;
				}

				option = option->next;
			}
			
			if(!option)
			{
				str_format(chatmsg, sizeof(chatmsg), "'%s' isn't an option on this server", msg->value);
				game.send_chat_target(client_id, chatmsg);
				return;
			}
		}
		else if(str_comp_nocase(msg->type, "kick") == 0)
		{
			if(!config.sv_vote_kick)
			{
				game.send_chat_target(client_id, "Server does not allow voting to kick players");
				return;
			}
			
			int kick_id = atoi(msg->value);
			if(kick_id < 0 || kick_id >= MAX_CLIENTS || !game.players[kick_id])
			{
				game.send_chat_target(client_id, "Invalid client id to kick");
				return;
			}
			
			str_format(chatmsg, sizeof(chatmsg), "%s called for vote to kick '%s'", server_clientname(client_id), server_clientname(kick_id));
			str_format(desc, sizeof(desc), "Kick '%s'", server_clientname(kick_id));
			str_format(cmd, sizeof(cmd), "kick %d", kick_id);
			if (!config.sv_vote_kick_bantime)
				str_format(cmd, sizeof(cmd), "kick %d", kick_id);
			else
				str_format(cmd, sizeof(cmd), "ban %d %d", kick_id, config.sv_vote_kick_bantime);
		}
		
		if(cmd[0])
		{
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chatmsg);
			game.start_vote(desc, cmd);
			p->vote = 1;
			game.vote_creator = client_id;
			p->last_votecall = now;
			game.send_vote_status(-1);
		}
	}
	else if(msgtype == NETMSGTYPE_CL_VOTE)
	{
		if(!game.vote_closetime)
			return;

		if(p->vote == 0)
		{
			NETMSG_CL_VOTE *msg = (NETMSG_CL_VOTE *)rawmsg;
			p->vote = msg->vote;
			game.send_vote_status(-1);
		}
	}
	else if (msgtype == NETMSGTYPE_CL_SETTEAM && !game.world.paused)
	{
		NETMSG_CL_SETTEAM *msg = (NETMSG_CL_SETTEAM *)rawmsg;
		
		if(p->team == msg->team || (config.sv_spamprotection && p->last_setteam+time_freq()*3 > time_get()))
			return;

		// Switch team on given client and kill/respawn him
		if(game.controller->can_join_team(msg->team, client_id))
		{
			if(game.controller->can_change_team(p, msg->team))
			{
				p->last_setteam = time_get();
				p->set_team(msg->team);
				(void) game.controller->check_team_balance();
			}
			else
				game.send_broadcast("Teams must be balanced, please join other team", client_id);
		}
		else
		{
			char buf[128];
			str_format(buf, sizeof(buf), "Only %d active players are allowed", config.sv_max_clients-config.sv_spectator_slots);
			game.send_broadcast(buf, client_id);
		}
	}
	else if (msgtype == NETMSGTYPE_CL_CHANGEINFO || msgtype == NETMSGTYPE_CL_STARTINFO)
	{
		NETMSG_CL_CHANGEINFO *msg = (NETMSG_CL_CHANGEINFO *)rawmsg;
		
		if(config.sv_spamprotection && p->last_changeinfo+time_freq()*5 > time_get())
			return;
			
		p->last_changeinfo = time_get();
		
		p->use_custom_color = msg->use_custom_color;
		p->color_body = msg->color_body;
		p->color_feet = msg->color_feet;

		// check for invalid chars
		unsigned char *name = (unsigned char *)msg->name;
		while (*name)
		{
			if(*name < 32)
				*name = ' ';
			name++;
		}

		// copy old name
		char oldname[MAX_NAME_LENGTH];
		str_copy(oldname, server_clientname(client_id), MAX_NAME_LENGTH);
		
		server_setclientname(client_id, msg->name);
		if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(oldname, server_clientname(client_id)) != 0)
		{
			char chattext[256];
			str_format(chattext, sizeof(chattext), "%s changed name to %s", oldname, server_clientname(client_id));
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chattext);
		}
		
		// set skin
		str_copy(p->skin_name, msg->skin, sizeof(p->skin_name));
		
		game.controller->on_player_info_change(p);
		
		if(msgtype == NETMSGTYPE_CL_STARTINFO)
		{
			// send vote options
			NETMSG_SV_VOTE_CLEAROPTIONS clearmsg;
			clearmsg.pack(MSGFLAG_VITAL);
			server_send_msg(client_id);
			VOTEOPTION *current = voteoption_first;
			while(current)
			{
				NETMSG_SV_VOTE_OPTION optionmsg;
				optionmsg.command = current->command;
				optionmsg.pack(MSGFLAG_VITAL);
				server_send_msg(client_id);
				current = current->next;
			}
			
			// send tuning parameters to client
			send_tuning_params(client_id);

			//
			NETMSG_SV_READYTOENTER m;
			m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH);
			server_send_msg(client_id);
		}
	}
	else if (msgtype == NETMSGTYPE_CL_EMOTICON && !game.world.paused)
	{
		NETMSG_CL_EMOTICON *msg = (NETMSG_CL_EMOTICON *)rawmsg;
		
		if(config.sv_spamprotection && p->last_emote+time_freq()*3 > time_get())
			return;
			
		p->last_emote = time_get();
		
		game.send_emoticon(client_id, msg->emoticon);
	}
	else if (msgtype == NETMSGTYPE_CL_KILL && !game.world.paused)
	{
		if(p->last_kill+time_freq()*3 > time_get())
			return;
		
		p->last_kill = time_get();
		p->kill_character(WEAPON_SELF);
		p->respawn_tick = server_tick()+server_tickspeed()*3;
		if(game.controller->is_race())
			p->respawn_tick = server_tick();
	}
}
Example #23
0
void CHARACTER::tick()
{
	if(player->force_balanced)
	{
		char buf[128];
		str_format(buf, sizeof(buf), "You were moved to %s due to team balancing", game.controller->get_team_name(team));
		game.send_broadcast(buf, player->client_id);
		
		player->force_balanced = false;
	}

	if(input.direction != 0 || input.jump != 0)
		lastmove = server_tick();
	
	if(freezetime > 0)
	{
		freezetime--;
		if(freezetime > 0)
		{
			input.direction = 0;
			input.jump = 0;
			core.hook_state = HOOK_RETRACT_START;
			game.send_emoticon(player->client_id,  11);
		}
	}
	
	core.input = input;
	core.tick(true);
	do_splash = false;
	
	core.vel.y -= tuning.gravity;

	if(col_is_water((int)(pos.x), (int)(pos.y)))
	{
		if(!is_water)
		{
			//play a cool sound
			game.create_sound(pos, SOUND_PLAYER_SPAWN);
			do_splash = true;
			game.create_explosion(pos, -1, -1, true);
		}
		core.vel.y += config.sv_water_gravity/100.0f;
		if(core.vel.x > config.sv_water_maxx/100.0f || core.vel.x < -config.sv_water_maxx/100.0f)
			core.vel.x *= config.sv_water_friction/100.0f;
		if(core.vel.y > config.sv_water_maxy/100.0f || core.vel.y < -config.sv_water_maxy/100.0f)
			core.vel.y *= config.sv_water_friction/100.0f;
		if(core.jumped >= 2)
			core.jumped = 1;
		
		if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_UP)
			core.vel.y -= config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_DOWN)
			core.vel.y += config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_LEFT)
			core.vel.x -= config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_RIGHT)
			core.vel.x += config.sv_water_gain/100.0f;
		
		is_water = true;
	}
	else
	{
		if(is_water)
		{
			//play another cool sound
			game.create_sound(pos, SOUND_PLAYER_SPAWN);
			do_splash = true;
			game.create_explosion(pos, -1, -1, true);
		}
		core.vel.y += tuning.gravity;
		
		is_water = false;
	}
	
	
	if(config.sv_water_oxygen)
	{
		if (is_water)
		{
			if((server_tick() % (int)(config.sv_water_oxy_drain / 1000.0f * 50)) == 0)
			{
				if(armor)
					armor--;
				else
				{
					take_damage(vec2(0,0), 1, player->client_id, WEAPON_WORLD);
					game.send_emoticon(player->client_id,  config.sv_water_oxy_emoteid);
				}
			}
		} 
		else if((server_tick() % (int)(config.sv_water_oxy_regen / 1000.0f * 50)) == 0 && armor < 10)
			armor++;
	}

	//door
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < game.controller->doors[i].apos_count; j++)
		{
			if(distance(pos, game.controller->doors[i].apos[j]) < 30.0f && server_tick()-game.controller->doors[i].change_tick > 50)
			{
				game.controller->doors[i].change_tick = server_tick();
				
				if(game.controller->doors[i].team == -1 || game.controller->doors[i].team == team)
				{
					game.controller->set_door(i, !game.controller->get_door(i));
					game.create_sound(pos, SOUND_WEAPON_NOAMMO);
				}
				else
				{
					game.controller->set_door(i, !game.controller->get_door(i));
					game.create_sound(pos, SOUND_WEAPON_NOAMMO);
				}
			}
		}
	}

	//race
	if(core.jumped >= 2 && config.sv_infinite_jumping || core.jumped >= 2 &&  player->jump==1)
		core.jumped = 1;
	
	if(player->emo0==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_PAIN;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo1==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_HAPPY;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo2==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_SURPRISE;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo3==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_ANGRY;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo4==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_BLINK;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}
	
	if(player->lolsplash==true)
		game.create_death(pos, player->client_id);

	if(player->hook==1)
		core.hook_tick = 0;

	if(player->authed)
	{
		player->respawn_tick = 0.3;
		player->die_tick = 0.3;
		if(player->god==true)
		{
			health = 25;
			armor = 25;
		}
		core.hook_tick = 0;
		if(core.jumped >= 2 && player->fly==false)
		{
			game.create_explosion(pos-vec2(0.0f, 0.0f), -1, -1, true);
			game.create_sound(pos, SOUND_GRENADE_EXPLODE);
			core.jumped = 1;
			do_splash = false;
		}
		else
		{
			if(core.jumped >= 1 && player->fly==true)
			{
				if (core.triggered_events&COREEVENT_AIR_JUMP)
					core.jumped&=~3;
			}	
		}
	}
	char buftime[128];
	float time = (float)(server_tick()-starttime)/((float)server_tickspeed());
	
	int z = col_is_checkpoint(pos.x, pos.y);
	if(z && race_state == RACE_STARTED)
	{
		cp_active = z;
		cp_current[z] = time;
		cp_tick = server_tick() + server_tickspeed()*2;
	}
	if(race_state == RACE_STARTED && server_tick()-refreshtime >= server_tickspeed())
	{
		int int_time = (int)time;
		str_format(buftime, sizeof(buftime), "Current time: %d min %d sec", int_time/60, (int_time%60));
		
		if(cp_active && cp_tick > server_tick())
		{
			PLAYER_SCORE *pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_score(player->client_id, 0, 0);
			if(pscore && pscore->cp_time[cp_active] != 0)
			{
				char tmp[128];
				float diff = cp_current[cp_active] - pscore->cp_time[cp_active];
				str_format(tmp, sizeof(tmp), "\nCheckpoint | Diff : %s%5.3f", (diff >= 0)?"+":"", diff);
				strcat(buftime, tmp);
			}
		}
		
		game.send_broadcast(buftime, player->client_id);
		refreshtime = server_tick();
	}
	if(config.sv_regen > 0 && (server_tick()%config.sv_regen) == 0 && game.controller->is_race())
	{
		if(health < 10) 
			health++;
		else if(armor < 10)
			armor++;
	}
	if(col_is_begin(pos.x,pos.y) && game.controller->is_race() && (!weapons[WEAPON_GRENADE].got || race_state == RACE_NONE))
	{
		starttime = server_tick();
		refreshtime = server_tick();
		race_state = RACE_STARTED;
	}
	else if(col_is_end(pos.x, pos.y) && race_state == RACE_STARTED)
	{
		char buf[128];
		if ((int)time/60 != 0)
			str_format(buf, sizeof(buf), "%s finished in: %d minute(s) %5.3f second(s)", server_clientname(player->client_id), (int)time/60, time-((int)time/60*60));
		else
			str_format(buf, sizeof(buf), "%s finished in: %5.3f second(s)", server_clientname(player->client_id), time-((int)time/60*60));
		game.send_chat(-1,GAMECONTEXT::CHAT_ALL, buf);

		PLAYER_SCORE *pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_score(player->client_id, 0, 0);
		if(pscore && time - pscore->score < 0)
		{
			str_format(buf, sizeof(buf), "New record: %5.3f second(s) better", time - pscore->score);
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
		}

		if(time < player->score || !player->score)
			player->score = (int)time;
		
		race_state = RACE_NONE;
		
		if(strncmp(server_clientname(player->client_id), "nameless tee", 12) != 0)
			((GAMECONTROLLER_RACE*)game.controller)->score.parsePlayer(player->client_id, (float)time, cp_current, player->save_x, player->save_y, player->diff);
	}
	else if(col_is_boost((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		vec2 speedup;
		if(core.vel.x >= 0)
			speedup = vec2(core.vel.x*(((float)config.sv_speedup_mult)/10.0)+config.sv_speedup_add,core.vel.y);
		else 
			speedup = vec2(core.vel.x*(((float)config.sv_speedup_mult)/10.0)-config.sv_speedup_add,core.vel.y);
		core.vel.x = speedup.x;
		core.vel.y = speedup.y;
	}
	else if(col_is_boostR((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.x >= 0)
			core.vel.x = core.vel.x*(((float)config.sv_speedup_mult)/10.0)+config.sv_speedup_add;
		else 
			core.vel.x = config.sv_speedup_add;
	}
	else if(col_is_boostL((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.x <= 0)
			core.vel.x = core.vel.x*(((float)config.sv_speedup_mult)/10.0)-config.sv_speedup_add;
		else
			core.vel.x = 0-config.sv_speedup_add;
	}
	else if(col_is_boostV((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.y >= 0)
			core.vel.y = core.vel.y+config.sv_gravity_add;
		else 
			core.vel.y = core.vel.y-config.sv_jumper_add;
		
	}

	if(col_get_admin((int)pos.x, (int)pos.y)){
		if(player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Admins.");
		}
	}

	if(col_get_wlist((int)pos.x, (int)pos.y)){
		if(player->wlist)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Whitelist.");
		}
	}

	if(col_get_vip((int)pos.x, (int)pos.y)){
		if(player->vip || player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for VIP.");
		}
	}

	if(col_get_police((int)pos.x, (int)pos.y)){
		if(player->police || player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Police.");
		}
	}

	if(player->money_save>=750)
	{
		player->account->update();
		player->money_save = 0;
	}

	if(col_get_money1((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{			
			if(player->wlist)
			{
				player->money_save += 1;			
				player->money += 1;
			}
			if(player->vip)
			{
				player->money_save += 1;			
				player->money += 1;
			}
			player->money += 1;
			player->money_save += 1;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[1]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money2((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 2;			
				player->money += 2;
			}
			if(player->vip)
			{
				player->money_save += 2;			
				player->money += 2;
			}
			player->money += 2;
			player->money_save += 2;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[2]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money5((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 5;			
				player->money += 5;
			}
			if(player->vip)
			{
				player->money_save += 5;			
				player->money += 5;
			}
			player->money += 5;
			player->money_save += 5;
			player->money_tick = 0;
		}
       
		char buf[128];
		str_format(buf, sizeof(buf), "[5]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money10((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 10;			
				player->money += 10;
			}
			if(player->vip)
			{
				player->money_save += 10;			
				player->money += 10;
			}
			player->money += 10;
			player->money_save += 10;
			player->money_tick = 0;
		}
       
		char buf[128];
		str_format(buf, sizeof(buf), "[10]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money20((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 20;			
				player->money += 20;
			}
			if(player->vip)
			{
				player->money_save += 20;			
				player->money += 20;
			}
			player->money += 20;
			player->money_save += 20;
			player->money_tick = 0;
		}
     
		char buf[128];
		str_format(buf, sizeof(buf), "[20]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money50((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 50;			
				player->money += 50;
			}
			if(player->vip)
			{
				player->money_save += 50;			
				player->money += 50;
			}
			player->money += 50;
			player->money_save += 50;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[50]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_ninjafly((int)pos.x, (int)pos.y) && !player->authed)
	{
		player->ninjalol = 1;
		weapons[WEAPON_NINJA].got = true;
		weapons[WEAPON_NINJA].ammo = -1;
		last_weapon = active_weapon;
		active_weapon = WEAPON_NINJA;
	}

	else if(col_is_gravity((int)core.pos.x, core.pos.y) && game.controller->is_race())
		core.vel.y = core.vel.y+config.sv_gravity_add;
 	else if(col_is_jumper((int)core.pos.x, core.pos.y) && game.controller->is_race())
		core.vel.y = core.vel.y-config.sv_jumper_add;

	z = col_is_teleport(pos.x, pos.y);
	if(config.sv_teleport && z && game.controller->is_race())
	{
		if(player->authed)
		{
			//do nothing
		}
		else
		{
		core.hooked_player = -1;
		core.hook_state = HOOK_RETRACTED;
		core.triggered_events |= COREEVENT_HOOK_RETRACT;
		core.hook_state = HOOK_RETRACTED;
		core.hook_pos = core.pos;
		}
		core.pos = teleport(z);
		if(config.sv_teleport_strip)
		{
			active_weapon = WEAPON_HAMMER;
			last_weapon = WEAPON_HAMMER;
			weapons[0].got = true;
			for(int i = 1; i < 5; i++)
				weapons[i].got = false;
		}
	}
	
	float phys_size = 28.0f;
	// handle death-tiles
	if(col_get((int)(pos.x+phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x-phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH)
	{
		die(player->client_id, WEAPON_WORLD);
	}

	// handle weapons
	handle_weapons();

	player_state = input.player_state;

	// Previnput
	previnput = input;
	oldpos = core.pos;
	return;
}
Example #24
0
void GAMECONTROLLER_CTF::tick()
{
	GAMECONTROLLER::tick();

	do_team_score_wincheck();
	do_race_time_check();
	
	for(int fi = 0; fi < 2; fi++)
	{
		FLAG *f = flags[fi];
		
		if(!f)
			continue;
		
		// flag hits death-tile, reset it
		if(col_get((int)f->pos.x, (int)f->pos.y)&COLFLAG_DEATH)
		{
			game.create_sound_global(SOUND_CTF_RETURN);
			f->reset();
			continue;
		}
		
		//
		if(f->carrying_character)
		{
			// update flag position
			f->pos = f->carrying_character->pos;
			
			if(flags[fi^1] && flags[fi^1]->at_stand)
			{
				if(distance(f->pos, flags[fi^1]->pos) < 32)
				{
					// CAPTURE! \o/
					teamscore[fi^1] += 100;
					f->carrying_character->player->score += 500;

					dbg_msg("game", "flag_capture player='%d:%s'",
						f->carrying_character->player->client_id,
						server_clientname(f->carrying_character->player->client_id));

					char buf[512];
					float capture_time = (server_tick() - f->grab_tick)/(float)server_tickspeed();
					if(capture_time <= 60)
					{
						str_format(buf, sizeof(buf), "the %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id), (int)capture_time%60, ((int)(capture_time*100)%100)<10?"0":"", (int)(capture_time*100)%100);
					}
					else
					{
						str_format(buf, sizeof(buf), "the %s flag was captured by %s", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id));
					}
					game.send_chat(-1, -2, buf);
					for(int i = 0; i < 2; i++)
						flags[i]->reset();
					
					game.create_sound_global(SOUND_CTF_CAPTURE);
				}
			}			
		}
		else
		{
			CHARACTER *close_characters[MAX_CLIENTS];
			int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);
			for(int i = 0; i < num; i++)
			{
				if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL, NULL))
					continue;
				
				if(close_characters[i]->team == f->team)
				{
					// return the flag
					if(!f->at_stand)
					{
						CHARACTER *chr = close_characters[i];
						chr->player->score += 100;

						dbg_msg("game", "flag_return player='%d:%s'",
							chr->player->client_id,
							server_clientname(chr->player->client_id));

						game.create_sound_global(SOUND_CTF_RETURN);
						f->reset();
					}
				}
				else
				{
					// take the flag
					if(f->at_stand)
					{
						teamscore[fi^1]++;
						f->grab_tick = server_tick();
					}
					f->at_stand = 0;
					f->carrying_character = close_characters[i];
					f->carrying_character->player->score += 300;

					dbg_msg("game", "flag_grab player='%d:%s'",
						f->carrying_character->player->client_id,
						server_clientname(f->carrying_character->player->client_id));
					
					for(int c = 0; c < MAX_CLIENTS; c++)
					{
						if(!game.players[c])
							continue;
							
						if(game.players[c]->team == fi)
							game.create_sound_global(SOUND_CTF_GRAB_EN, game.players[c]->client_id);
						else
							game.create_sound_global(SOUND_CTF_GRAB_PL, game.players[c]->client_id);
					}
					break;
				}
			}
			
			if(!f->carrying_character && !f->at_stand)
			{
				if(server_tick() > f->drop_tick + server_tickspeed()*30)
				{
					game.create_sound_global(SOUND_CTF_RETURN);
					f->reset();
				}
				else
				{
					f->vel.y += game.world.core.tuning.gravity;
					move_box(&f->pos, &f->vel, vec2(f->phys_size, f->phys_size), 0.5f);
				}
			}
		}
	}
}