diff -crBN teeworlds-0.5.2-src/banmasters.cfg teeworlds-0.5.2-src-banmaster/banmasters.cfg
*** teeworlds-0.5.2-src/banmasters.cfg	Thu Jan  1 01:00:00 1970
--- teeworlds-0.5.2-src-banmaster/banmasters.cfg	Mon Feb  7 16:41:49 2011
***************
*** 0 ****
--- 1,2 ----
+ clear_banmasters
+ add_banmaster banmaster.kottnet.net
diff -crBN teeworlds-0.5.2-src/config.bam teeworlds-0.5.2-src-banmaster/config.bam
*** teeworlds-0.5.2-src/config.bam	Thu Jan  1 01:00:00 1970
--- teeworlds-0.5.2-src-banmaster/config.bam	Mon Feb  7 17:45:28 2011
***************
*** 0 ****
--- 1,8 ----
+ compiler.value = 'cl'
+ stackprotector.value = 1
+ zlib.value = nil
+ zlib.include_path = nil
+ sdl.value = 1
+ sdl.use_sdlconfig = nil
+ sdl.use_win32sdl = 1
+ sdl.use_osxframework = nil
Binary files teeworlds-0.5.2-src/datasrc/content.pyc and teeworlds-0.5.2-src-banmaster/datasrc/content.pyc differ
Binary files teeworlds-0.5.2-src/datasrc/datatypes.pyc and teeworlds-0.5.2-src-banmaster/datasrc/datatypes.pyc differ
Binary files teeworlds-0.5.2-src/datasrc/network.pyc and teeworlds-0.5.2-src-banmaster/datasrc/network.pyc differ
Binary files teeworlds-0.5.2-src/other/icons/teeworlds.res and teeworlds-0.5.2-src-banmaster/other/icons/teeworlds.res differ
diff -crBN teeworlds-0.5.2-src/src/banmaster/banmaster.h teeworlds-0.5.2-src-banmaster/src/banmaster/banmaster.h
*** teeworlds-0.5.2-src/src/banmaster/banmaster.h	Thu Jan  1 01:00:00 1970
--- teeworlds-0.5.2-src-banmaster/src/banmaster/banmaster.h	Mon Feb  7 17:48:43 2011
***************
*** 0 ****
--- 1,12 ----
+ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
+ /* If you are missing that file, acquire a complete release at teeworlds.com.                */
+ #ifndef BANMASTER_BANMASTER_H
+ #define BANMASTER_BANMASTER_H
+ 
+ static const int BANMASTER_PORT = 8302;
+ 
+ static const char BANMASTER_IPOK[] = {255, 255, 255, 255, 'i', 'p', 'o', 'k'};
+ static const char BANMASTER_IPBAN[] = {255, 255, 255, 255, 'i', 'p', 'b', 'a'};
+ static const char BANMASTER_IPCHECK[] = {255, 255, 255, 255, 'i', 'p', 'c', 'h'};
+ 
+ #endif
diff -crBN teeworlds-0.5.2-src/src/engine/e_config_variables.h teeworlds-0.5.2-src-banmaster/src/engine/e_config_variables.h
*** teeworlds-0.5.2-src/src/engine/e_config_variables.h	Mon Oct 26 19:04:31 2009
--- teeworlds-0.5.2-src-banmaster/src/engine/e_config_variables.h	Mon Feb  7 17:23:14 2011
***************
*** 66,71 ****
--- 66,72 ----
  MACRO_CONFIG_INT(sv_register, 1, 0, 1, CFGFLAG_SERVER, "Register server with master server for public listing")
  MACRO_CONFIG_STR(sv_rcon_password, 32, "", CFGFLAG_SERVER, "Remote console password")
  MACRO_CONFIG_INT(sv_map_reload, 0, 0, 1, CFGFLAG_SERVER, "Reload the current map")
+ MACRO_CONFIG_INT(sv_global_bantime, 60, 0, 1440, CFGFLAG_SERVER, "Time for banmaster bans")
  
  MACRO_CONFIG_INT(debug, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Debug mode")
  MACRO_CONFIG_INT(dbg_stress, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress systems")
diff -crBN teeworlds-0.5.2-src/src/engine/e_network.h teeworlds-0.5.2-src-banmaster/src/engine/e_network.h
*** teeworlds-0.5.2-src/src/engine/e_network.h	Mon Oct 26 19:04:31 2009
--- teeworlds-0.5.2-src-banmaster/src/engine/e_network.h	Mon Feb  7 18:03:31 2011
***************
*** 47,55 ****
  	NETSTATE_ONLINE,
  	
  	NETBANTYPE_SOFT=1,
! 	NETBANTYPE_DROP=2
  };
  
  typedef int (*NETFUNC_DELCLIENT)(int cid, void *user);
  typedef int (*NETFUNC_NEWCLIENT)(int cid, void *user);
  
--- 47,58 ----
  	NETSTATE_ONLINE,
  	
  	NETBANTYPE_SOFT=1,
! 	NETBANTYPE_DROP=2,
! 
! 	NETSERVER_MAX_BANMASTERS=16
  };
  
+ 
  typedef int (*NETFUNC_DELCLIENT)(int cid, void *user);
  typedef int (*NETFUNC_NEWCLIENT)(int cid, void *user);
  
***************
*** 76,81 ****
--- 79,89 ----
  int netserver_ban_num(NETSERVER *s); /* caution, slow */
  int netserver_ban_get(NETSERVER *s, int index, NETBANINFO *info); /* caution, slow */
  
+ int netserver_banmasters_add(NETSERVER *s, char *address);
+ int netserver_banmasters_clear(NETSERVER *s);
+ int netserver_banmasters_check(NETSERVER *s, NETADDR *addr);
+ int netserver_banmasters_dump(NETSERVER *s);
+ 
  /*void netserver_stats(NETSERVER *s, NETSTATS *stats);*/
  
  /* client side */
diff -crBN teeworlds-0.5.2-src/src/engine/e_network_server.c teeworlds-0.5.2-src-banmaster/src/engine/e_network_server.c
*** teeworlds-0.5.2-src/src/engine/e_network_server.c	Mon Oct 26 19:04:31 2009
--- teeworlds-0.5.2-src-banmaster/src/engine/e_network_server.c	Mon Feb  7 18:29:53 2011
***************
*** 2,7 ****
--- 2,9 ----
  #include "e_network.h"
  #include "e_network_internal.h"
  
+ #include <banmaster/banmaster.h>
+ 
  typedef struct
  {
  	NETCONNECTION conn;
***************
*** 59,64 ****
--- 61,69 ----
  	void *user_ptr;
  	
  	NETRECVINFO recv;
+ 	
+ 	NETADDR banmasters[NETSERVER_MAX_BANMASTERS];
+ 	int num_banmasters;
  };
  
  NETSERVER *netserver_open(NETADDR bindaddr, int max_clients, int flags)
***************
*** 382,387 ****
--- 387,408 ----
  					/* client that wants to connect */
  					if(!found)
  					{
+ 						NETCHUNK packet;
+ 						char buffer[128];
+ 						mem_copy(buffer, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK));
+ 						net_addr_str(&addr, buffer + sizeof(BANMASTER_IPCHECK), sizeof(buffer) - sizeof(BANMASTER_IPCHECK));
+ 						
+ 						packet.client_id = -1;
+ 						packet.flags = NETSENDFLAG_CONNLESS;
+ 						packet.data_size = str_length(buffer) + 1;
+ 						packet.data = buffer;
+ 						
+ 						for(i = 0; i < s->num_banmasters; i++)
+ 						{
+ 							packet.address = s->banmasters[i];
+ 							netserver_send(s, &packet);
+ 						}
+ 						
  						for(i = 0; i < s->max_clients; i++)
  						{
  							if(s->slots[i].conn.state == NET_CONNSTATE_OFFLINE)
***************
*** 488,490 ****
--- 509,556 ----
  	*addr = s->slots[client_id].conn.peeraddr;
  	return 1;
  }
+ 
+ int netserver_banmasters_add(NETSERVER *s, char *address)
+ {
+ 	if(s->num_banmasters >= NETSERVER_MAX_BANMASTERS)
+ 		return 2;
+ 	
+ 	if(net_host_lookup(address, &s->banmasters[s->num_banmasters], NETTYPE_IPV4))
+ 		return 1;
+ 	
+ 	if(s->banmasters[s->num_banmasters].port == 0)
+ 		s->banmasters[s->num_banmasters].port = BANMASTER_PORT;
+ 	
+ 	s->num_banmasters++;
+ 	
+ 	return 0;
+ }
+ 
+ int netserver_banmasters_clear(NETSERVER *s)
+ {
+ 	s->num_banmasters = 0;
+ 	return 0;
+ }
+ 
+ int netserver_banmasters_check(NETSERVER *s, NETADDR *addr)
+ {
+ 	int i;
+ 	for(i = 0; i < s->num_banmasters; i++)
+ 	{
+ 		if(!net_addr_comp(&s->banmasters[i], addr))
+ 			return 1;
+ 	}
+ 	return 0;
+ }
+ 
+ int netserver_banmasters_dump(NETSERVER *s)
+ {
+ 	int i;
+ 	char ip[64];
+ 	for(i	= 0; i < s->num_banmasters; i++)
+ 	{
+ 		net_addr_str(&s->banmasters[i], ip, sizeof(ip));
+ 		dbg_msg("server/banmaster", "%d: %s", i, ip);
+ 	}
+ 	return 0;
+ }
diff -crBN teeworlds-0.5.2-src/src/engine/server/es_server.c teeworlds-0.5.2-src-banmaster/src/engine/server/es_server.c
*** teeworlds-0.5.2-src/src/engine/server/es_server.c	Mon Oct 26 19:04:31 2009
--- teeworlds-0.5.2-src-banmaster/src/engine/server/es_server.c	Mon Feb  7 18:31:53 2011
***************
*** 22,27 ****
--- 22,29 ----
  
  #include <mastersrv/mastersrv.h>
  
+ #include <banmaster/banmaster.h>
+ 
  #if defined(CONF_FAMILY_WINDOWS) 
  	#define _WIN32_WINNT 0x0500 
  	#include <windows.h> 
***************
*** 29,34 ****
--- 31,38 ----
  
  static SNAPBUILD builder;
  
+ static const char SERVER_BANMASTERFILE[] = "banmasters.cfg";
+ 
  static int64 game_start_time;
  static int current_tick = 0;
  static int run_server = 1;
***************
*** 914,920 ****
  
  	/* flags */
  	i = 0;
! 	if(config.password[0])   /* password set */
  		i |= SRVFLAG_PASSWORD;
  	str_format(buf, sizeof(buf), "%d", i);
  	packer_add_string(&p, buf, 2);
--- 918,924 ----
  
  	/* flags */
  	i = 0;
! 	if(config.password[0])	 /* password set */
  		i |= SRVFLAG_PASSWORD;
  	str_format(buf, sizeof(buf), "%d", i);
  	packer_add_string(&p, buf, 2);
***************
*** 923,937 ****
  	str_format(buf, sizeof(buf), "%d", browseinfo_progression);
  	packer_add_string(&p, buf, 4);
  	
! 	str_format(buf, sizeof(buf), "%d", player_count); packer_add_string(&p, buf, 3);  /* num players */
  	str_format(buf, sizeof(buf), "%d", netserver_max_clients(net)); packer_add_string(&p, buf, 3); /* max players */
  
  	for(i = 0; i < MAX_CLIENTS; i++)
  	{
  		if(clients[i].state != SRVCLIENT_STATE_EMPTY)
  		{
! 			packer_add_string(&p, clients[i].name, 48);  /* player name */
! 			str_format(buf, sizeof(buf), "%d", clients[i].score); packer_add_string(&p, buf, 6);  /* player score */
  		}
  	}
  	
--- 927,941 ----
  	str_format(buf, sizeof(buf), "%d", browseinfo_progression);
  	packer_add_string(&p, buf, 4);
  	
! 	str_format(buf, sizeof(buf), "%d", player_count); packer_add_string(&p, buf, 3);	/* num players */
  	str_format(buf, sizeof(buf), "%d", netserver_max_clients(net)); packer_add_string(&p, buf, 3); /* max players */
  
  	for(i = 0; i < MAX_CLIENTS; i++)
  	{
  		if(clients[i].state != SRVCLIENT_STATE_EMPTY)
  		{
! 			packer_add_string(&p, clients[i].name, 48);	/* player name */
! 			str_format(buf, sizeof(buf), "%d", clients[i].score); packer_add_string(&p, buf, 6);	/* player score */
  		}
  	}
  	
***************
*** 973,978 ****
--- 977,1030 ----
  				{
  					server_send_serverinfo(&packet.address, -1);
  				}
+ 				
+ 				if(packet.data_size == sizeof(BANMASTER_IPOK) &&
+ 					memcmp(packet.data, BANMASTER_IPOK, sizeof(BANMASTER_IPOK)) == 0 &&
+ 					netserver_banmasters_check(net, &packet.address))
+ 				{
+ 				}
+ 
+ 				if(packet.data_size >= sizeof(BANMASTER_IPBAN) &&
+ 					memcmp(packet.data, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN)) == 0 &&
+ 					config.sv_global_bantime &&
+ 					netserver_banmasters_check(net, &packet.address))
+ 				{
+ 					UNPACKER unpacker;
+ 					char ip[32];
+ 					char reason[256];
+ 					char buffer[512];
+ 					NETADDR addr;
+ 					int i;
+ 
+ 					unpacker_reset(&unpacker, (unsigned char*)packet.data + sizeof(BANMASTER_IPBAN), packet.data_size - sizeof(BANMASTER_IPBAN));
+ 
+ 					str_copy(ip, unpacker_get_string(&unpacker), sizeof(ip));
+ 					str_copy(reason, unpacker_get_string(&unpacker), sizeof(reason));
+ 					str_sanitize(ip);
+ 					str_sanitize(reason);
+ 					
+ 					if(net_addr_from_str(&addr, ip))
+ 					{
+ 						dbg_msg("globalbans", "dropped weird message from banmaster");
+ 						return;
+ 					}
+ 					
+ 					str_format(buffer, sizeof(buffer), "you have been banned for %d minutes (%s)", config.sv_global_bantime, reason);
+ 					
+ 					for(i = 0; i < MAX_CLIENTS; i++)
+ 					{
+ 						if(clients[i].state	!= SRVCLIENT_STATE_EMPTY)
+ 						{
+ 							NETADDR client_addr;
+ 							netserver_client_addr(net, i, &client_addr);
+ 							if(!net_addr_comp(&addr, &client_addr))
+ 								netserver_drop(net, i, buffer);
+ 						}
+ 					}
+ 					
+ 					netserver_ban_add(net, addr, config.sv_global_bantime * 60);
+ 					dbg_msg("globalbans", "added ban, ip=%d.%d.%d.%d, reason=\"%s\"", addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3], reason);
+ 				}
  			}
  		}
  		else
***************
*** 1051,1056 ****
--- 1103,1110 ----
  	
  	netserver_set_callbacks(net, new_client_callback, del_client_callback, 0);
  	
+ 	console_execute_file(SERVER_BANMASTERFILE);
+ 	
  	dbg_msg("server", "server name is '%s'", config.sv_name);
  	
  	mods_init();
***************
*** 1333,1338 ****
--- 1387,1413 ----
  	demorec_record_stop();
  }
  
+ static void con_add_banmaster(void *result, void *user_data)
+ {
+ 	int adding_result = netserver_banmasters_add(net, console_arg_string(result, 0));
+ 	if(adding_result == 0)
+ 		dbg_msg("server/banmaster", "succesfully added banmaster '%s'", console_arg_string(result, 0));
+ 	else if(adding_result == 1)
+ 		dbg_msg("server/banmaster", "invalid address for banmaster / net lookup failed");
+ 	else
+ 		dbg_msg("server/banmaster", "too many banmasters");
+ }
+ 
+ static void con_banmasters(void *result, void *user_data)
+ {
+ 	netserver_banmasters_dump(net);
+ }
+ 
+ static void con_clear_banmasters(void *result, void *user_data)
+ {
+ 	netserver_banmasters_clear(net);
+ }
+ 
  static void server_register_commands()
  {
  	MACRO_REGISTER_COMMAND("kick", "i", CFGFLAG_SERVER, con_kick, 0, "");
***************
*** 1344,1349 ****
--- 1419,1428 ----
  
  	MACRO_REGISTER_COMMAND("record", "s", CFGFLAG_SERVER, con_record, 0, "");
  	MACRO_REGISTER_COMMAND("stoprecord", "", CFGFLAG_SERVER, con_stoprecord, 0, "");
+ 	
+ 	MACRO_REGISTER_COMMAND("add_banmaster", "s", CFGFLAG_SERVER, con_add_banmaster, 0, "");
+ 	MACRO_REGISTER_COMMAND("banmasters", "", CFGFLAG_SERVER, con_banmasters, 0, "");
+ 	MACRO_REGISTER_COMMAND("clear_banmasters", "", CFGFLAG_SERVER, con_clear_banmasters, 0, "");
  }
  
  int main(int argc, char **argv)
