about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/client/ec_client.c58
-rw-r--r--src/engine/e_if_client.h14
-rw-r--r--src/game/client/components/menus.cpp2
-rw-r--r--src/game/client/components/menus_browser.cpp8
-rw-r--r--src/game/variables.hpp2
5 files changed, 81 insertions, 3 deletions
diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c
index 26846d73..a99f901d 100644
--- a/src/engine/client/ec_client.c
+++ b/src/engine/client/ec_client.c
@@ -24,6 +24,7 @@
 #include <engine/e_huffman.h>
 
 #include <mastersrv/mastersrv.h>
+#include <versionsrv/versionsrv.h>
 
 const int prediction_margin = 7; /* magic network prediction value */
 
@@ -63,6 +64,9 @@ static int ack_game_tick = -1;
 static int current_recv_tick = 0;
 static int rcon_authed = 0;
 
+/* version-checking */
+static char versionstr[10] = "0";
+
 /* pinging */
 static int64 ping_start_time = 0;
 
@@ -383,7 +387,7 @@ static void client_send_input()
 
 	if(current_predtick <= 0)
 		return;
-	
+	 
 	/* fetch input */
 	size = modc_snap_input(inputs[current_input].data);
 	
@@ -411,6 +415,11 @@ static void client_send_input()
 	client_send_msg();
 }
 
+const char *client_latestversion()
+{
+	return versionstr;
+}
+
 /* TODO: OPT: do this alot smarter! */
 int *client_get_input(int tick)
 {
@@ -708,6 +717,23 @@ static void client_process_packet(NETCHUNK *packet)
 	if(packet->client_id == -1)
 	{
 		/* connectionlesss */
+		if(packet->data_size == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)) &&
+			memcmp(packet->data, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0)
+		{
+			unsigned char *versiondata = (unsigned char*) packet->data + sizeof(VERSIONSRV_VERSION);
+			int version_match = !memcmp(versiondata, VERSION_DATA, sizeof(VERSION_DATA));
+			
+			dbg_msg("client/version", "version does %s (%d.%d.%d)",
+				version_match ? "match" : "NOT match",
+				versiondata[1], versiondata[2], versiondata[3]);
+			
+			/* assume version is out of date when version-data doesn't match */
+			if (!version_match)
+			{
+				sprintf(versionstr, "%d.%d.%d", versiondata[1], versiondata[2], versiondata[3]);
+			}
+		}
+		
 		if(packet->data_size >= (int)sizeof(SERVERBROWSE_LIST) &&
 			memcmp(packet->data, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST)) == 0)
 		{
@@ -1263,6 +1289,33 @@ static void client_update()
 	client_serverbrowse_update();
 }
 
+static int client_getversion()
+{
+	NETADDR addr;
+	NETCHUNK packet;
+	
+	mem_zero(&addr, sizeof(NETADDR));
+	mem_zero(&packet, sizeof(NETCHUNK));
+	
+	if(net_host_lookup(config.cl_version_server, &addr, NETTYPE_IPV4))
+	{
+		dbg_msg("client/version", "could not find the address of %s, skipping version fetch", config.cl_version_server);
+		return -1;
+	}
+	
+	addr.port = VERSIONSRV_PORT;
+	
+	packet.client_id = -1;
+	packet.address = addr;
+	packet.data = VERSIONSRV_GETVERSION;
+	packet.data_size = sizeof(VERSIONSRV_GETVERSION);
+	packet.flags = NETSENDFLAG_CONNLESS;
+	
+	netclient_send(net, &packet);
+	
+	return 0;
+}
+
 extern int editor_update_and_render();
 extern void editor_init();
 
@@ -1310,6 +1363,9 @@ static void client_run()
 	config.cl_connect[0] = 0;
 	*/
 	
+	/* fetch latest client-version from versionsrv */
+	client_getversion();
+	
 	/* never start with the editor */
 	config.cl_editor = 0;
 		
diff --git a/src/engine/e_if_client.h b/src/engine/e_if_client.h
index b94aad29..6137145b 100644
--- a/src/engine/e_if_client.h
+++ b/src/engine/e_if_client.h
@@ -403,6 +403,20 @@ int client_rcon_authed();
 	Group: Other
 **********************************************************************************/
 /*
+	Function: client_latestversion
+		Returns 0 if there's no version difference
+	
+	Arguments:
+		arg1 - desc
+	
+	Returns:
+
+	See Also:
+		<other_func>
+*/
+const char *client_latestversion();
+
+/*
 	Function: client_get_input
 		TODO
 	
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index de2e5711..cf817083 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -709,7 +709,7 @@ void MENUS::render_game(RECT main_view)
 					gameclient.send_switch_team(0);
 					menu_active = false;
 				}
-			}						
+			}
 		}
 	}
 }
diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp
index c213e3f1..6354ee22 100644
--- a/src/game/client/components/menus_browser.cpp
+++ b/src/game/client/components/menus_browser.cpp
@@ -14,6 +14,7 @@ extern "C" {
 #include <game/client/ui.hpp>
 #include <game/client/gc_render.hpp>
 #include "menus.hpp"
+#include <game/version.hpp>
 
 void MENUS::render_serverbrowser_serverlist(RECT view)
 {
@@ -593,7 +594,12 @@ void MENUS::render_serverbrowser(RECT main_view)
 				client_serverbrowse_refresh(1);
 		}
 		
-		ui_do_label(&status_toolbar, "new version.. LOLZ!!", 14.0f, -1);
+		char buf[512];
+		if(strcmp(client_latestversion(), "0") != 0)
+			str_format(buf, sizeof(buf), "Teeworlds %s is out! Download it at www.teeworlds.com! Current version: %s", client_latestversion(), GAME_VERSION);
+		else
+			str_format(buf, sizeof(buf), "Current version: %s", GAME_VERSION);
+		ui_do_label(&status_toolbar, buf, 14.0f, -1);
 	}
 	
 	// do the button box
diff --git a/src/game/variables.hpp b/src/game/variables.hpp
index 543e9e1f..2803915c 100644
--- a/src/game/variables.hpp
+++ b/src/game/variables.hpp
@@ -26,6 +26,8 @@ MACRO_CONFIG_INT(cl_flow, 0, 0, 1)
 MACRO_CONFIG_INT(cl_show_welcome, 1, 0, 1)
 MACRO_CONFIG_INT(cl_motd_time, 10, 0, 100)
 
+MACRO_CONFIG_STR(cl_version_server, 100, "version.teeworlds.com")
+
 MACRO_CONFIG_INT(player_use_custom_color, 0, 0, 1)
 MACRO_CONFIG_INT(player_color_body, 65408, 0, 0)
 MACRO_CONFIG_INT(player_color_feet, 65408, 0, 0)