summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-01-25 19:03:50 +0000
committerDarkvater <darkvater@openttd.org>2006-01-25 19:03:50 +0000
commit2b287a9e72c0b717f9d39915441a0d681611124b (patch)
tree75d7c397982c18c2480f8bf3c9c44629f76776f3
parent0d80c70b5f1d29ac2fc2145ec5720dfb001e8eba (diff)
downloadopenttd-2b287a9e72c0b717f9d39915441a0d681611124b.tar.xz
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
-rw-r--r--network.c4
-rw-r--r--network.h4
-rw-r--r--network_client.c2
-rw-r--r--network_gamelist.c55
-rw-r--r--network_gui.c173
-rw-r--r--network_udp.c12
6 files changed, 117 insertions, 133 deletions
diff --git a/network.c b/network.c
index 7aa24a603..c1a0a2238 100644
--- a/network.c
+++ b/network.c
@@ -833,7 +833,7 @@ NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool
}
/* Validates an address entered as a string and adds the server to
- * the list. If you use this functions, the games will be marked
+ * the list. If you use this function, the games will be marked
* as manually added. */
void NetworkAddServer(const char *b)
{
@@ -1343,7 +1343,7 @@ void NetworkStartUp(void)
memset(&_network_game_info, 0, sizeof(_network_game_info));
_network_game_info.clients_max = 10; // XXX - hardcoded, string limiation -- TrueLight
- _network_game_info.companies_max = MAX_PLAYERS;
+ _network_game_info.companies_max = MAX_PLAYERS; // 8
_network_game_info.spectators_max = _network_game_info.clients_max;
// Let's load the network in windows
diff --git a/network.h b/network.h
index 6bcfec530..b8840ded7 100644
--- a/network.h
+++ b/network.h
@@ -66,6 +66,7 @@ typedef struct NetworkGameInfo {
char server_revision[NETWORK_REVISION_LENGTH]; // The SVN version number the server is using (e.g.: 'r304')
// It even shows a SVN version in release-version, so
// it is easy to compare if a server is of the correct version
+ bool compatible; // Can we connect to this server or not? (based on server_revision)
byte server_lang; // Language of the server (we should make a nice table for this)
byte use_password; // Is set to != 0 if it uses a password
char server_password[NETWORK_PASSWORD_LENGTH]; // On the server: the game password, on the client: != "" if server has password
@@ -157,9 +158,6 @@ VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a s
// networking settings
VARDEF uint32 _network_ip_list[MAX_INTERFACES + 1]; // Network IPs
-VARDEF uint16 _network_game_count;
-
-VARDEF uint16 _network_lobby_company_count;
VARDEF uint _network_server_port;
/* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of
diff --git a/network_client.c b/network_client.c
index a7452fd87..f8d88e8fc 100644
--- a/network_client.c
+++ b/network_client.c
@@ -301,8 +301,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
if (current >= MAX_PLAYERS)
return NETWORK_RECV_STATUS_CLOSE_QUERY;
- _network_lobby_company_count++;
-
NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
_network_player_info[current].inaugurated_year = NetworkRecv_uint8(MY_CLIENT, p);
_network_player_info[current].company_value = NetworkRecv_uint64(MY_CLIENT, p);
diff --git a/network_gamelist.c b/network_gamelist.c
index bff7166d1..a90b50aaa 100644
--- a/network_gamelist.c
+++ b/network_gamelist.c
@@ -15,34 +15,23 @@ extern void UpdateNetworkGameWindow(bool unselect);
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
{
- NetworkGameList *item;
+ NetworkGameList *item, *prev_item;
- item = _network_game_list;
- if (item != NULL) {
- while (item->next != NULL) {
- if (item->ip == ip && item->port == port)
- return item;
- item = item->next;
- }
-
- if (item->ip == ip && item->port == port)
- return item;
-
- item->next = malloc(sizeof(*item));
- item = item->next;
- } else {
- item = malloc(sizeof(*item));
- _network_game_list = item;
+ prev_item = NULL;
+ for (item = _network_game_list; item != NULL; item = item->next) {
+ if (item->ip == ip && item->port == port) return item;
+ prev_item = item;
}
- DEBUG(net, 4) ("[NET][GameList] Added server to list");
-
+ item = malloc(sizeof(*item));
memset(item, 0, sizeof(*item));
-
item->next = NULL;
item->ip = ip;
item->port = port;
- _network_game_count++;
+
+ if (prev_item == NULL) {_network_game_list = item;}
+ else {prev_item->next = item;}
+ DEBUG(net, 4) ("[NET][GameList] Added server to list");
UpdateNetworkGameWindow(false);
@@ -51,28 +40,20 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
void NetworkGameListRemoveItem(NetworkGameList *remove)
{
- NetworkGameList *item;
+ NetworkGameList *item, *prev_item;
- item = _network_game_list;
-
- // examine head of the list
- if ( remove == _network_game_list ) {
- _network_game_list = remove->next;
- free(remove);
- DEBUG(net, 4) ("[NET][GameList] Removed server from list");
- return;
- }
+ prev_item = NULL;
+ for (item = _network_game_list; item != NULL; item = item->next) {
+ if (remove == item) {
+ if (prev_item == NULL) {_network_game_list = remove->next;}
+ else {prev_item->next = remove->next;}
- // examine each item
- while ( item->next != NULL ) {
- if ( item->next == remove )
- {
- item->next = remove->next;
free(remove);
DEBUG(net, 4) ("[NET][GameList] Removed server from list");
+ UpdateNetworkGameWindow(false);
return;
}
- item = item->next;
+ prev_item = item;
}
}
diff --git a/network_gui.c b/network_gui.c
index 8021c8ee1..c97bcd5d6 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -31,7 +31,6 @@ static void ShowNetworkStartServerWindow(void);
static void ShowNetworkLobbyWindow(void);
static byte _selected_field;
-static bool _first_time_show_network_game_window = true;
static const StringID _connection_types_dropdown[] = {
STR_NETWORK_LAN_INTERNET,
@@ -69,10 +68,10 @@ static const StringID _language_dropdown[] = {
};
enum {
- NET_PRC__OFFSET_TOP_WIDGET = 74,
- NET_PRC__OFFSET_TOP_WIDGET_COMPANY = 42,
- NET_PRC__SIZE_OF_ROW = 14,
- NET_PRC__SIZE_OF_ROW_COMPANY = 12,
+ NET_PRC__OFFSET_TOP_WIDGET = 54,
+ NET_PRC__OFFSET_TOP_WIDGET_COMPANY = 42,
+ NET_PRC__SIZE_OF_ROW = 14,
+ NET_PRC__SIZE_OF_ROW_COMPANY = 12,
};
static NetworkGameList *_selected_item = NULL;
@@ -89,11 +88,11 @@ void UpdateNetworkGameWindow(bool unselect)
if (w != NULL) {
if (unselect) _selected_item = NULL;
- w->vscroll.count = _network_game_count;
- SetWindowDirty(w);
+ SendWindowMessage(WC_NETWORK_WINDOW, 0, true, 0, 0);
}
}
+/* uses WP(w, querystr_d) */
static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -103,24 +102,26 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break;
case WE_PAINT: {
- const NetworkGameList* sel = _selected_item;
+ const NetworkGameList *sel = _selected_item;
w->disabled_state = 0;
if (sel == NULL) {
- SETBIT(w->disabled_state, 17); SETBIT(w->disabled_state, 18);
+ SETBIT(w->disabled_state, 16); SETBIT(w->disabled_state, 17);
} else if (!sel->online) {
- SETBIT(w->disabled_state, 17); // Server offline, join button disabled
+ SETBIT(w->disabled_state, 16); // Server offline, join button disabled
} else if (sel->info.clients_on >= sel->info.clients_max) {
- SETBIT(w->disabled_state, 17); // Server full, join button disabled
+ SETBIT(w->disabled_state, 16); // Server full, join button disabled
+ } else if (sel->info.companies_on >= sel->info.companies_max &&
+ sel->info.spectators_on >= sel->info.spectators_max) {
+ SETBIT(w->disabled_state, 16);
} else if (sel->info.companies_on >= sel->info.companies_max &&
sel->info.spectators_on >= sel->info.spectators_max) {
SETBIT(w->disabled_state, 17);
// revisions don't match, check if server has no revision; then allow connection
- } else if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
- if (strncmp(sel->info.server_revision, NOREV_STRING, sizeof(sel->info.server_revision)) != 0)
- SETBIT(w->disabled_state, 17); // Revision mismatch, join button disabled
+ } else if (!sel->info.compatible) {
+ SETBIT(w->disabled_state, 16); // Revision mismatch, join button disabled
}
SetDParam(0, 0x00);
@@ -129,13 +130,14 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
DrawEditBox(w, 3);
- DrawString(9, 23, STR_NETWORK_PLAYER_NAME, 2);
- DrawString(9, 43, STR_NETWORK_CONNECTION, 2);
+ DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
+ DrawString(210, 23, STR_NETWORK_PLAYER_NAME, 2);
{ // draw list of games
uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
int32 n = 0;
int32 pos = w->vscroll.pos;
+ uint max_name_width = w->widget[6].right - w->widget[6].left - 5;
const NetworkGameList *cur_item = _network_game_list;
while (pos > 0 && cur_item != NULL) {
@@ -144,32 +146,28 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
}
while (cur_item != NULL) {
- bool compatible =
- strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) == 0 ||
- strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision)) == 0;
-
- if (cur_item == sel)
- GfxFillRect(11, y - 2, 218, y + 9, 10); // show highlighted item with a different colour
+ // show highlighted item with a different colour
+ if (cur_item == sel) GfxFillRect(w->widget[6].left + 1, y - 2, w->widget[8].right - 1, y + 9, 10);
SetDParamStr(0, cur_item->info.server_name);
- DrawStringTruncated(15, y, STR_02BD, 16, 110);
+ DrawStringTruncated(w->widget[6].left + 5, y, STR_02BD, 16, max_name_width);
SetDParam(0, cur_item->info.clients_on);
SetDParam(1, cur_item->info.clients_max);
SetDParam(2, cur_item->info.companies_on);
SetDParam(3, cur_item->info.companies_max);
- DrawString(135, y, STR_NETWORK_GENERAL_ONLINE, 2);
+ DrawStringCentered(210, y, STR_NETWORK_GENERAL_ONLINE, 2);
// only draw icons if the server is online
if (cur_item->online) {
// draw a lock if the server is password protected.
- if (cur_item->info.use_password) DrawSprite(SPR_LOCK, 186, y - 1);
+ if (cur_item->info.use_password) DrawSprite(SPR_LOCK, w->widget[8].left + 5, y - 1);
// draw red or green icon, depending on compatibility with server.
- DrawSprite(SPR_BLOT | (compatible ? PALETTE_TO_GREEN : PALETTE_TO_RED), 195, y);
+ DrawSprite(SPR_BLOT | (cur_item->info.compatible ? PALETTE_TO_GREEN : PALETTE_TO_RED), w->widget[8].left + 15, y);
// draw flag according to server language
- DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, 206, y);
+ DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, w->widget[8].left + 25, y);
}
cur_item = cur_item->next;
@@ -178,74 +176,74 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
}
}
- // right menu
- GfxFillRect(252, 23, 478, 65, 157);
+ /* Draw the right menu */
+ GfxFillRect(311, 43, 539, 92, 157);
if (sel == NULL) {
- DrawStringMultiCenter(365, 40, STR_NETWORK_GAME_INFO, 0);
+ DrawStringMultiCenter(425, 58, STR_NETWORK_GAME_INFO, 0);
} else if (!sel->online) {
SetDParamStr(0, sel->info.server_name);
- DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name
+ DrawStringMultiCenter(425, 68, STR_ORANGE, 2); // game name
- DrawStringMultiCenter(365, 110, STR_NETWORK_SERVER_OFFLINE, 2); // server offline
+ DrawStringMultiCenter(425, 132, STR_NETWORK_SERVER_OFFLINE, 2); // server offline
} else { // show game info
- uint16 y = 70;
+ uint16 y = 100;
+ const uint16 x = w->widget[15].left + 5;
- DrawStringMultiCenter(365, 30, STR_NETWORK_GAME_INFO, 0);
+ DrawStringMultiCenter(425, 48, STR_NETWORK_GAME_INFO, 0);
SetDParamStr(0, sel->info.server_name);
- DrawStringCenteredTruncated(w->widget[16].left, w->widget[16].right, 42, STR_ORANGE, 16); // game name
+ DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
SetDParamStr(0, sel->info.map_name);
- DrawStringCenteredTruncated(w->widget[16].left, w->widget[16].right, 54, STR_02BD, 16); // map name
+ DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 74, STR_02BD, 16); // map name
SetDParam(0, sel->info.clients_on);
SetDParam(1, sel->info.clients_max);
SetDParam(2, sel->info.companies_on);
SetDParam(3, sel->info.companies_max);
- DrawString(260, y, STR_NETWORK_CLIENTS, 2);
+ DrawString(x, y, STR_NETWORK_CLIENTS, 2);
y += 10;
SetDParam(0, _language_dropdown[sel->info.server_lang]);
- DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language
+ DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language
y += 10;
SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
- DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset
+ DrawString(x, y, STR_NETWORK_TILESET, 2); // tileset
y += 10;
SetDParam(0, sel->info.map_width);
SetDParam(1, sel->info.map_height);
- DrawString(260, y, STR_NETWORK_MAP_SIZE, 2); // map size
+ DrawString(x, y, STR_NETWORK_MAP_SIZE, 2); // map size
y += 10;
SetDParamStr(0, sel->info.server_revision);
- DrawString(260, y, STR_NETWORK_SERVER_VERSION, 2); // server version
+ DrawString(x, y, STR_NETWORK_SERVER_VERSION, 2); // server version
y += 10;
SetDParamStr(0, sel->info.hostname);
SetDParam(1, sel->port);
- DrawString(260, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
+ DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
y += 10;
SetDParam(0, sel->info.start_date);
- DrawString(260, y, STR_NETWORK_START_DATE, 2); // start date
+ DrawString(x, y, STR_NETWORK_START_DATE, 2); // start date
y += 10;
SetDParam(0, sel->info.game_date);
- DrawString(260, y, STR_NETWORK_CURRENT_DATE, 2); // current date
+ DrawString(x, y, STR_NETWORK_CURRENT_DATE, 2); // current date
y += 10;
y += 2;
- if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
- if (strncmp(sel->info.server_revision, NOREV_STRING, sizeof(sel->info.server_revision)) != 0)
- DrawStringMultiCenter(365, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
+ if (!sel->info.compatible) {
+ DrawStringMultiCenter(425, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
} else if (sel->info.clients_on == sel->info.clients_max) {
// Show: server full, when clients_on == clients_max
- DrawStringMultiCenter(365, y, STR_NETWORK_SERVER_FULL, 2); // server full
+ DrawStringMultiCenter(425, y, STR_NETWORK_SERVER_FULL, 2); // server full
} else if (sel->info.use_password) {
- DrawStringMultiCenter(365, y, STR_NETWORK_PASSWORD, 2); // password warning
+ DrawStringMultiCenter(425, y, STR_NETWORK_PASSWORD, 2); // password warning
}
y += 10;
@@ -300,7 +298,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
case 13: /* Start server */
ShowNetworkStartServerWindow();
break;
- case 17: /* Join Game */
+ case 16: /* Join Game */
if (_selected_item != NULL) {
memcpy(&_network_game_info, &_selected_item->info, sizeof(NetworkGameInfo));
snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&_selected_item->ip));
@@ -308,7 +306,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
ShowNetworkLobbyWindow();
}
break;
- case 18: // Refresh
+ case 17: // Refresh
if (_selected_item != NULL) {
NetworkQueryServer(_selected_item->info.hostname, _selected_item->port, true);
}
@@ -330,17 +328,22 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
if (_selected_field == 3) HandleEditBox(w, 3);
break;
+ case WE_MESSAGE: {
+ const NetworkGameList *nglist;
+ w->vscroll.count = 0;
+ /* Game-count has changed, update scroll-count, scrollbar, and resort */
+ for (nglist = _network_game_list; nglist != NULL; nglist = nglist->next) w->vscroll.count++;
+ if (w->vscroll.count >= w->vscroll.cap && w->vscroll.pos > w->vscroll.count - w->vscroll.cap) w->vscroll.pos--;
+
+ SetWindowDirty(w);
+ } break;
+
case WE_KEYPRESS:
if (_selected_field != 3) {
- if ( e->keypress.keycode == WKC_DELETE ) { // press 'delete' to remove servers
- if (_selected_item != NULL) {
+ if (_selected_item != NULL) {
+ if (e->keypress.keycode == WKC_DELETE) { /* Press 'delete' to remove servers */
NetworkGameListRemoveItem(_selected_item);
NetworkRebuildHostList();
- SetWindowDirty(w);
- _network_game_count--;
- // reposition scrollbar
- if (_network_game_count >= w->vscroll.cap && w->vscroll.pos > _network_game_count-w->vscroll.cap) w->vscroll.pos--;
- UpdateNetworkGameWindow(false);
_selected_item = NULL;
}
}
@@ -358,48 +361,48 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break;
- case WE_ON_EDIT_TEXT: {
+ case WE_ON_EDIT_TEXT:
NetworkAddServer(e->edittext.str);
NetworkRebuildHostList();
- } break;
+ break;
}
}
static const Widget _network_game_window_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, BGC, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, BGC, 11, 549, 0, 13, STR_NETWORK_MULTIPLAYER, STR_NULL},
-{ WWT_IMGBTN, RESIZE_NONE, BGC, 0, 549, 14, 214, STR_NULL, STR_NULL},
+{ WWT_IMGBTN, RESIZE_NONE, BGC, 0, 549, 14, 249, STR_NULL, STR_NULL},
/* LEFT SIDE */
-{ WWT_IMGBTN, RESIZE_NONE, BGC, 90, 291, 22, 33, STR_NULL, STR_NETWORK_ENTER_NAME_TIP},
+{ WWT_IMGBTN, RESIZE_NONE, BGC, 310, 461, 22, 33, STR_NULL, STR_NETWORK_ENTER_NAME_TIP},
-{ WWT_6, RESIZE_NONE, BGC, 90, 231, 42, 53, STR_NETWORK_COMBO1, STR_NETWORK_CONNECTION_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, BGC, 220, 230, 43, 52, STR_0225, STR_NETWORK_CONNECTION_TIP},
+{ WWT_6, RESIZE_NONE, BGC, 90, 181, 22, 33, STR_NETWORK_COMBO1, STR_NETWORK_CONNECTION_TIP},
+{ WWT_TEXTBTN, RESIZE_NONE, BGC, 170, 180, 23, 32, STR_0225, STR_NETWORK_CONNECTION_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, BTC, 10, 130, 62, 73, STR_NETWORK_GAME_NAME, STR_NETWORK_GAME_NAME_TIP},
-{ WWT_TEXTBTN, RESIZE_NONE, BTC, 131, 180, 62, 73, STR_NETWORK_CLIENTS_CAPTION,STR_NETWORK_CLIENTS_CAPTION_TIP},
-{ WWT_PANEL, RESIZE_NONE, BTC, 181, 219, 62, 73, 0, STR_NETWORK_INFO_ICONS_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 10, 170, 42, 53, STR_NETWORK_GAME_NAME, STR_NETWORK_GAME_NAME_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 171, 250, 42, 53, STR_NETWORK_CLIENTS_CAPTION,STR_NETWORK_CLIENTS_CAPTION_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 251, 290, 42, 53, STR_EMPTY, STR_NETWORK_INFO_ICONS_TIP},
-{ WWT_MATRIX, RESIZE_NONE, BGC, 10, 219, 74, 185, 0x801, STR_NETWORK_CLICK_GAME_TO_SELECT},
-{ WWT_SCROLLBAR, RESIZE_NONE, BGC, 220, 231, 62, 185, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{ WWT_MATRIX, RESIZE_NONE, BGC, 10, 290, 54, 222, (12 << 8) + 1, STR_NETWORK_CLICK_GAME_TO_SELECT},
+{ WWT_SCROLLBAR, RESIZE_NONE, BGC, 291, 302, 42, 222, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 10, 115, 195, 206, STR_NETWORK_FIND_SERVER, STR_NETWORK_FIND_SERVER_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 125, 231, 195, 206, STR_NETWORK_ADD_SERVER, STR_NETWORK_ADD_SERVER_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 250, 360, 195, 206, STR_NETWORK_START_SERVER, STR_NETWORK_START_SERVER_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 370, 480, 195, 206, STR_012E_CANCEL, STR_NULL},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 30, 130, 232, 243, STR_NETWORK_FIND_SERVER, STR_NETWORK_FIND_SERVER_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 180, 280, 232, 243, STR_NETWORK_ADD_SERVER, STR_NETWORK_ADD_SERVER_TIP},
/* RIGHT SIDE */
-{ WWT_IMGBTN, RESIZE_NONE, BGC, 250, 480, 22, 185, STR_NULL, STR_NULL},
-{ WWT_6, RESIZE_NONE, BGC, 251, 479, 23, 184, STR_NULL, STR_NULL},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 315, 415, 232, 243, STR_NETWORK_START_SERVER, STR_NETWORK_START_SERVER_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 430, 535, 232, 243, STR_012E_CANCEL, STR_NULL},
+
+{ WWT_PANEL, RESIZE_NONE, BGC, 310, 540, 42, 222, STR_NULL, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 257, 360, 164, 175, STR_NETWORK_JOIN_GAME, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 370, 473, 164, 175, STR_NETWORK_REFRESH, STR_NETWORK_REFRESH_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 315, 415, 201, 212, STR_NETWORK_JOIN_GAME, STR_NULL},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 430, 535, 201, 212, STR_NETWORK_REFRESH, STR_NETWORK_REFRESH_TIP},
{ WIDGETS_END},
};
static const WindowDesc _network_game_window_desc = {
- WDP_CENTER, WDP_CENTER, 550, 215,
+ WDP_CENTER, WDP_CENTER, 550, 250,
WC_NETWORK_WINDOW,0,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_network_game_window_widgets,
@@ -408,23 +411,24 @@ static const WindowDesc _network_game_window_desc = {
void ShowNetworkGameWindow(void)
{
- uint i;
+ static bool _first_time_show_network_game_window = true;
Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0);
/* Only show once */
if (_first_time_show_network_game_window) {
+ const char* const *srv;
+
_first_time_show_network_game_window = false;
// add all servers from the config file to our list
- for (i = 0; i != lengthof(_network_host_list); i++) {
- if (_network_host_list[i] == NULL) break;
- NetworkAddServer(_network_host_list[i]);
+ for (srv = _network_host_list; srv != endof(_network_host_list) && *srv != NULL; srv++) {
+ NetworkAddServer(*srv);
}
}
w = AllocateWindowDesc(&_network_game_window_desc);
ttd_strlcpy(_edit_str_buf, _network_player_name, MAX_QUERYSTR_LEN);
- w->vscroll.cap = 8;
+ w->vscroll.cap = 12;
WP(w, querystr_d).text.caret = true;
WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1;
@@ -668,7 +672,6 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
w->disabled_state = (_selected_company_item == -1) ? 1 << 7 : 0;
- assert(_network_lobby_company_count == gi->companies_on);
if (gi->companies_on == gi->companies_max) SETBIT(w->disabled_state, 8);
if (gi->spectators_on == gi->spectators_max) SETBIT(w->disabled_state, 9);
@@ -841,8 +844,6 @@ static void ShowNetworkLobbyWindow(void)
Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0);
- _network_lobby_company_count = 0;
-
NetworkQueryServer(_network_last_host, _network_last_port, false);
w = AllocateWindowDesc(&_network_lobby_window_desc);
diff --git a/network_udp.c b/network_udp.c
index 3248b98a1..154214621 100644
--- a/network_udp.c
+++ b/network_udp.c
@@ -93,6 +93,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER)
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
{
+ extern const char _openttd_revision[];
NetworkGameList *item;
byte game_info_version;
@@ -102,15 +103,14 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
game_info_version = NetworkRecv_uint8(&_udp_cs, p);
- if (_udp_cs.quited)
- return;
+ if (_udp_cs.quited) return;
DEBUG(net, 6)("[NET][UDP] Server response from %s:%d", inet_ntoa(client_addr->sin_addr),ntohs(client_addr->sin_port));
// Find next item
item = NetworkGameListAddItem(inet_addr(inet_ntoa(client_addr->sin_addr)), ntohs(client_addr->sin_port));
- /* Please observe the order. In the order in which packets are sent
+ /* Please observer the order. In the order in which packets are sent
* they are to be received */
switch (game_info_version) {
case 2:
@@ -142,6 +142,12 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
if (item->info.hostname[0] == '\0')
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr));
+
+ /* Check if we are allowed on this server based on the revision-match */
+ item->info.compatible = (
+ strncmp(item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH) == 0 ||
+ strncmp(item->info.server_revision, NOREV_STRING, NETWORK_REVISION_LENGTH) == 0) ? true : false;
+
break;
}