ref: 37e1dbf1353a1b1f39dc2702178904aed04a476d
parent: 58fba3477da8fc6bdec3558489556c3439f90fc5
author: Simon Howard <[email protected]>
date: Fri Aug 30 20:13:05 EDT 2013
Add notification window to the waiting screen to show whether the server was added to the global master server. Subversion-branch: /branches/v2-branch Subversion-revision: 2629
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -37,6 +37,7 @@
#include "net_client.h"
#include "net_gui.h"
+#include "net_query.h"
#include "net_server.h"
#include "textscreen.h"
@@ -46,6 +47,7 @@
static txt_label_t *player_labels[NET_MAXPLAYERS];
static txt_label_t *ip_labels[NET_MAXPLAYERS];
static txt_label_t *drone_label;
+static txt_label_t *master_msg_label;
static boolean had_warning;
static void EscapePressed(TXT_UNCAST_ARG(widget), void *unused)
@@ -73,6 +75,8 @@
TXT_SignalConnect(cancel, "pressed", EscapePressed, NULL);
TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel);
+ TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_BOTTOM,
+ TXT_SCREEN_W / 2, TXT_SCREEN_H - 9);
old_max_players = 0;
}
@@ -182,6 +186,55 @@
TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, startgame);
}
+static void BuildMasterStatusWindow(void)
+{
+ txt_window_t *master_window;
+
+ master_window = TXT_NewWindow(NULL);
+ master_msg_label = TXT_NewLabel("");
+ TXT_AddWidget(master_window, master_msg_label);
+
+ // This window is here purely for information, so it should be
+ // in the background.
+
+ TXT_LowerWindow(master_window);
+ TXT_SetWindowPosition(master_window, TXT_HORIZ_CENTER, TXT_VERT_CENTER,
+ TXT_SCREEN_W / 2, TXT_SCREEN_H - 4);
+ TXT_SetWindowAction(master_window, TXT_HORIZ_LEFT, NULL);
+ TXT_SetWindowAction(master_window, TXT_HORIZ_CENTER, NULL);
+ TXT_SetWindowAction(master_window, TXT_HORIZ_RIGHT, NULL);
+}
+
+static void CheckMasterStatus(void)
+{
+ boolean added;
+
+ if (!NET_Query_CheckAddedToMaster(&added))
+ {
+ return;
+ }
+
+ if (master_msg_label == NULL)
+ {
+ BuildMasterStatusWindow();
+ }
+
+ if (added)
+ {
+ TXT_SetLabel(master_msg_label,
+ "Your server is now registered with the global master server.\n"
+ "Other players can find your server online.");
+ }
+ else
+ {
+ TXT_SetLabel(master_msg_label,
+ "Failed to register with the master server. Your server is not\n"
+ "publicly accessible. You may need to reconfigure your Internet\n"
+ "router to add a port forward for UDP port 2342. Look up\n"
+ "information on port forwarding online.");
+ }
+}
+
static void PrintSHA1Digest(char *s, byte *digest)
{
unsigned int i;
@@ -307,6 +360,7 @@
{
UpdateGUI();
CheckSHA1Sums();
+ CheckMasterStatus();
TXT_DispatchEvents();
TXT_DrawDesktop();
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -81,9 +81,8 @@
boolean printed;
} query_target_t;
-// Transmit a query packet
-
static boolean registered_with_master = false;
+static boolean got_master_response = false;
static net_context_t *query_context;
static query_target_t *targets;
@@ -158,7 +157,22 @@
printf("Failed to register with master server at %s\n",
MASTER_SERVER_ADDRESS);
}
+
+ got_master_response = true;
}
+}
+
+boolean NET_Query_CheckAddedToMaster(boolean *result)
+{
+ // Got response from master yet?
+
+ if (!got_master_response)
+ {
+ return false;
+ }
+
+ *result = registered_with_master;
+ return true;
}
// Send a query to the master server.
--- a/src/net_query.h
+++ b/src/net_query.h
@@ -44,6 +44,7 @@
extern net_addr_t *NET_Query_ResolveMaster(net_context_t *context);
extern void NET_Query_AddToMaster(net_addr_t *master_addr);
+extern boolean NET_Query_CheckAddedToMaster(boolean *result);
extern void NET_Query_MasterResponse(net_packet_t *packet);
#endif /* #ifndef NET_QUERY_H */