about summary refs log tree commit diff
path: root/src/mastersrv
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-02-10 21:54:52 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-02-10 21:54:52 +0000
commit548a919ea379a3b9d1d9e41cf4dad6b4779fd3e6 (patch)
tree85666198fed3d4803f3ec3373c134d12bde9329b /src/mastersrv
parent2f969d9d6fece689e05857580ffb1843439e5fbb (diff)
downloadzcatch-548a919ea379a3b9d1d9e41cf4dad6b4779fd3e6.tar.gz
zcatch-548a919ea379a3b9d1d9e41cf4dad6b4779fd3e6.zip
merged 0.3.4 changes to trunk
Diffstat (limited to 'src/mastersrv')
-rw-r--r--src/mastersrv/mastersrv.cpp28
-rw-r--r--src/mastersrv/mastersrv.h3
2 files changed, 31 insertions, 0 deletions
diff --git a/src/mastersrv/mastersrv.cpp b/src/mastersrv/mastersrv.cpp
index aa799919..b83330a5 100644
--- a/src/mastersrv/mastersrv.cpp
+++ b/src/mastersrv/mastersrv.cpp
@@ -27,6 +27,14 @@ static struct packet_data
 	unsigned char header[sizeof(SERVERBROWSE_LIST)];
 	NETADDR4 servers[MAX_SERVERS];
 } data;
+
+static struct count_packet_data
+{
+	unsigned char header[sizeof(SERVERBROWSE_COUNT)];
+	unsigned char high;
+	unsigned char low;
+} count_data;
+
 static int64 server_expire[MAX_SERVERS];
 static int num_servers = 0;
 
@@ -41,6 +49,9 @@ void send_ok(NETADDR4 *addr)
 	p.flags = PACKETFLAG_CONNLESS;
 	p.data_size = sizeof(SERVERBROWSE_FWOK);
 	p.data = SERVERBROWSE_FWOK;
+	
+	// send on both to be sure
+	net_checker.send(&p);
 	net_op.send(&p);
 }
 
@@ -183,6 +194,8 @@ int main(int argc, char **argv)
 	// TODO: check socket for errors
 	
 	mem_copy(data.header, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST));
+	mem_copy(count_data.header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT));
+	
 	dbg_msg("mastersrv", "started");
 	
 	while(1)
@@ -207,6 +220,21 @@ int main(int argc, char **argv)
 				// add it
 				add_checkserver(&packet.address, &alt);
 			}
+			else if(packet.data_size == sizeof(SERVERBROWSE_GETCOUNT) &&
+				memcmp(packet.data, SERVERBROWSE_GETCOUNT, sizeof(SERVERBROWSE_GETCOUNT)) == 0)
+			{
+				dbg_msg("mastersrv", "count requested, responding with %d", num_servers);
+				
+				NETPACKET p;
+				p.client_id = -1;
+				p.address = packet.address;
+				p.flags = PACKETFLAG_CONNLESS;
+				p.data_size = sizeof(count_data);
+				p.data = &count_data;
+				count_data.high = (num_servers>>8)&0xff;
+				count_data.low = num_servers&0xff;
+				net_op.send(&p);
+			}
 			else if(packet.data_size == sizeof(SERVERBROWSE_GETLIST) &&
 				memcmp(packet.data, SERVERBROWSE_GETLIST, sizeof(SERVERBROWSE_GETLIST)) == 0)
 			{
diff --git a/src/mastersrv/mastersrv.h b/src/mastersrv/mastersrv.h
index 1de5b9ef..b5347914 100644
--- a/src/mastersrv/mastersrv.h
+++ b/src/mastersrv/mastersrv.h
@@ -10,6 +10,9 @@ static const unsigned char SERVERBROWSE_HEARTBEAT[] = {255, 255, 255, 255, 'b',
 static const unsigned char SERVERBROWSE_GETLIST[] = {255, 255, 255, 255, 'r', 'e', 'q', 't'};
 static const unsigned char SERVERBROWSE_LIST[] = {255, 255, 255, 255, 'l', 'i', 's', 't'};
 
+static const unsigned char SERVERBROWSE_GETCOUNT[] = {255, 255, 255, 255, 'c', 'o', 'u', 'n'};
+static const unsigned char SERVERBROWSE_COUNT[] = {255, 255, 255, 255, 's', 'i', 'z', 'e'};
+
 static const unsigned char SERVERBROWSE_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', 'f'};
 static const unsigned char SERVERBROWSE_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', 'o'};