(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.

This commit is contained in:
Darkvater 2006-01-25 19:03:50 +00:00
parent 0d80c70b5f
commit 2b287a9e72
6 changed files with 117 additions and 133 deletions

View File

@ -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 /* 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. */ * as manually added. */
void NetworkAddServer(const char *b) void NetworkAddServer(const char *b)
{ {
@ -1343,7 +1343,7 @@ void NetworkStartUp(void)
memset(&_network_game_info, 0, sizeof(_network_game_info)); memset(&_network_game_info, 0, sizeof(_network_game_info));
_network_game_info.clients_max = 10; // XXX - hardcoded, string limiation -- TrueLight _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; _network_game_info.spectators_max = _network_game_info.clients_max;
// Let's load the network in windows // Let's load the network in windows

View File

@ -66,6 +66,7 @@ typedef struct NetworkGameInfo {
char server_revision[NETWORK_REVISION_LENGTH]; // The SVN version number the server is using (e.g.: 'r304') 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 even shows a SVN version in release-version, so
// it is easy to compare if a server is of the correct version // 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 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 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 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 // networking settings
VARDEF uint32 _network_ip_list[MAX_INTERFACES + 1]; // Network IPs 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; VARDEF uint _network_server_port;
/* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of /* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of

View File

@ -301,8 +301,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
if (current >= MAX_PLAYERS) if (current >= MAX_PLAYERS)
return NETWORK_RECV_STATUS_CLOSE_QUERY; 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)); 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].inaugurated_year = NetworkRecv_uint8(MY_CLIENT, p);
_network_player_info[current].company_value = NetworkRecv_uint64(MY_CLIENT, p); _network_player_info[current].company_value = NetworkRecv_uint64(MY_CLIENT, p);

View File

@ -15,34 +15,23 @@ extern void UpdateNetworkGameWindow(bool unselect);
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
{ {
NetworkGameList *item; NetworkGameList *item, *prev_item;
item = _network_game_list; prev_item = NULL;
if (item != NULL) { for (item = _network_game_list; item != NULL; item = item->next) {
while (item->next != NULL) { if (item->ip == ip && item->port == port) return item;
if (item->ip == ip && item->port == port) prev_item = item;
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;
} }
DEBUG(net, 4) ("[NET][GameList] Added server to list"); item = malloc(sizeof(*item));
memset(item, 0, sizeof(*item)); memset(item, 0, sizeof(*item));
item->next = NULL; item->next = NULL;
item->ip = ip; item->ip = ip;
item->port = port; 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); UpdateNetworkGameWindow(false);
@ -51,28 +40,20 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
void NetworkGameListRemoveItem(NetworkGameList *remove) void NetworkGameListRemoveItem(NetworkGameList *remove)
{ {
NetworkGameList *item; NetworkGameList *item, *prev_item;
item = _network_game_list; 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 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;
}
// examine each item
while ( item->next != NULL ) {
if ( item->next == remove )
{
item->next = remove->next;
free(remove); free(remove);
DEBUG(net, 4) ("[NET][GameList] Removed server from list"); DEBUG(net, 4) ("[NET][GameList] Removed server from list");
UpdateNetworkGameWindow(false);
return; return;
} }
item = item->next; prev_item = item;
} }
} }

View File

@ -31,7 +31,6 @@ static void ShowNetworkStartServerWindow(void);
static void ShowNetworkLobbyWindow(void); static void ShowNetworkLobbyWindow(void);
static byte _selected_field; static byte _selected_field;
static bool _first_time_show_network_game_window = true;
static const StringID _connection_types_dropdown[] = { static const StringID _connection_types_dropdown[] = {
STR_NETWORK_LAN_INTERNET, STR_NETWORK_LAN_INTERNET,
@ -69,10 +68,10 @@ static const StringID _language_dropdown[] = {
}; };
enum { enum {
NET_PRC__OFFSET_TOP_WIDGET = 74, NET_PRC__OFFSET_TOP_WIDGET = 54,
NET_PRC__OFFSET_TOP_WIDGET_COMPANY = 42, NET_PRC__OFFSET_TOP_WIDGET_COMPANY = 42,
NET_PRC__SIZE_OF_ROW = 14, NET_PRC__SIZE_OF_ROW = 14,
NET_PRC__SIZE_OF_ROW_COMPANY = 12, NET_PRC__SIZE_OF_ROW_COMPANY = 12,
}; };
static NetworkGameList *_selected_item = NULL; static NetworkGameList *_selected_item = NULL;
@ -89,11 +88,11 @@ void UpdateNetworkGameWindow(bool unselect)
if (w != NULL) { if (w != NULL) {
if (unselect) _selected_item = NULL; if (unselect) _selected_item = NULL;
w->vscroll.count = _network_game_count; SendWindowMessage(WC_NETWORK_WINDOW, 0, true, 0, 0);
SetWindowDirty(w);
} }
} }
/* uses WP(w, querystr_d) */
static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
@ -103,24 +102,26 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break; break;
case WE_PAINT: { case WE_PAINT: {
const NetworkGameList* sel = _selected_item; const NetworkGameList *sel = _selected_item;
w->disabled_state = 0; w->disabled_state = 0;
if (sel == NULL) { 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) { } 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) { } 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 && } else if (sel->info.companies_on >= sel->info.companies_max &&
sel->info.spectators_on >= sel->info.spectators_max) { sel->info.spectators_on >= sel->info.spectators_max) {
SETBIT(w->disabled_state, 17); SETBIT(w->disabled_state, 17);
// revisions don't match, check if server has no revision; then allow connection // 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) { } else if (!sel->info.compatible) {
if (strncmp(sel->info.server_revision, NOREV_STRING, sizeof(sel->info.server_revision)) != 0) SETBIT(w->disabled_state, 16); // Revision mismatch, join button disabled
SETBIT(w->disabled_state, 17); // Revision mismatch, join button disabled
} }
SetDParam(0, 0x00); SetDParam(0, 0x00);
@ -129,13 +130,14 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
DrawEditBox(w, 3); DrawEditBox(w, 3);
DrawString(9, 23, STR_NETWORK_PLAYER_NAME, 2); DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
DrawString(9, 43, STR_NETWORK_CONNECTION, 2); DrawString(210, 23, STR_NETWORK_PLAYER_NAME, 2);
{ // draw list of games { // draw list of games
uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3; uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
int32 n = 0; int32 n = 0;
int32 pos = w->vscroll.pos; 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; const NetworkGameList *cur_item = _network_game_list;
while (pos > 0 && cur_item != NULL) { while (pos > 0 && cur_item != NULL) {
@ -144,32 +146,28 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
} }
while (cur_item != NULL) { while (cur_item != NULL) {
bool compatible = // show highlighted item with a different colour
strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) == 0 || if (cur_item == sel) GfxFillRect(w->widget[6].left + 1, y - 2, w->widget[8].right - 1, y + 9, 10);
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
SetDParamStr(0, cur_item->info.server_name); 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(0, cur_item->info.clients_on);
SetDParam(1, cur_item->info.clients_max); SetDParam(1, cur_item->info.clients_max);
SetDParam(2, cur_item->info.companies_on); SetDParam(2, cur_item->info.companies_on);
SetDParam(3, cur_item->info.companies_max); 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 // only draw icons if the server is online
if (cur_item->online) { if (cur_item->online) {
// draw a lock if the server is password protected. // 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. // 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 // 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; cur_item = cur_item->next;
@ -178,74 +176,74 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
} }
} }
// right menu /* Draw the right menu */
GfxFillRect(252, 23, 478, 65, 157); GfxFillRect(311, 43, 539, 92, 157);
if (sel == NULL) { if (sel == NULL) {
DrawStringMultiCenter(365, 40, STR_NETWORK_GAME_INFO, 0); DrawStringMultiCenter(425, 58, STR_NETWORK_GAME_INFO, 0);
} else if (!sel->online) { } else if (!sel->online) {
SetDParamStr(0, sel->info.server_name); 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 } 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); 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); 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(0, sel->info.clients_on);
SetDParam(1, sel->info.clients_max); SetDParam(1, sel->info.clients_max);
SetDParam(2, sel->info.companies_on); SetDParam(2, sel->info.companies_on);
SetDParam(3, sel->info.companies_max); SetDParam(3, sel->info.companies_max);
DrawString(260, y, STR_NETWORK_CLIENTS, 2); DrawString(x, y, STR_NETWORK_CLIENTS, 2);
y += 10; y += 10;
SetDParam(0, _language_dropdown[sel->info.server_lang]); 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; y += 10;
SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set); 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; y += 10;
SetDParam(0, sel->info.map_width); SetDParam(0, sel->info.map_width);
SetDParam(1, sel->info.map_height); 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; y += 10;
SetDParamStr(0, sel->info.server_revision); 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; y += 10;
SetDParamStr(0, sel->info.hostname); SetDParamStr(0, sel->info.hostname);
SetDParam(1, sel->port); 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; y += 10;
SetDParam(0, sel->info.start_date); 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; y += 10;
SetDParam(0, sel->info.game_date); 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 += 10;
y += 2; y += 2;
if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) { if (!sel->info.compatible) {
if (strncmp(sel->info.server_revision, NOREV_STRING, sizeof(sel->info.server_revision)) != 0) DrawStringMultiCenter(425, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
DrawStringMultiCenter(365, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
} else if (sel->info.clients_on == sel->info.clients_max) { } else if (sel->info.clients_on == sel->info.clients_max) {
// Show: server full, when clients_on == 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) { } 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; y += 10;
@ -300,7 +298,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
case 13: /* Start server */ case 13: /* Start server */
ShowNetworkStartServerWindow(); ShowNetworkStartServerWindow();
break; break;
case 17: /* Join Game */ case 16: /* Join Game */
if (_selected_item != NULL) { if (_selected_item != NULL) {
memcpy(&_network_game_info, &_selected_item->info, sizeof(NetworkGameInfo)); 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)); 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(); ShowNetworkLobbyWindow();
} }
break; break;
case 18: // Refresh case 17: // Refresh
if (_selected_item != NULL) { if (_selected_item != NULL) {
NetworkQueryServer(_selected_item->info.hostname, _selected_item->port, true); 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); if (_selected_field == 3) HandleEditBox(w, 3);
break; 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: case WE_KEYPRESS:
if (_selected_field != 3) { 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); NetworkGameListRemoveItem(_selected_item);
NetworkRebuildHostList(); 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; _selected_item = NULL;
} }
} }
@ -358,48 +361,48 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT:
NetworkAddServer(e->edittext.str); NetworkAddServer(e->edittext.str);
NetworkRebuildHostList(); NetworkRebuildHostList();
} break; break;
} }
} }
static const Widget _network_game_window_widgets[] = { static const Widget _network_game_window_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, BGC, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { 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_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 */ /* 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_6, RESIZE_NONE, BGC, 90, 181, 22, 33, STR_NETWORK_COMBO1, STR_NETWORK_CONNECTION_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, BGC, 220, 230, 43, 52, STR_0225, 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_PUSHTXTBTN, RESIZE_NONE, BTC, 10, 170, 42, 53, 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_PUSHTXTBTN, RESIZE_NONE, BTC, 171, 250, 42, 53, 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, 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_MATRIX, RESIZE_NONE, BGC, 10, 290, 54, 222, (12 << 8) + 1, STR_NETWORK_CLICK_GAME_TO_SELECT},
{ WWT_SCROLLBAR, RESIZE_NONE, BGC, 220, 231, 62, 185, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { 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, 30, 130, 232, 243, 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, 180, 280, 232, 243, 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},
/* RIGHT SIDE */ /* RIGHT SIDE */
{ WWT_IMGBTN, RESIZE_NONE, BGC, 250, 480, 22, 185, STR_NULL, STR_NULL}, { WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 315, 415, 232, 243, STR_NETWORK_START_SERVER, STR_NETWORK_START_SERVER_TIP},
{ WWT_6, RESIZE_NONE, BGC, 251, 479, 23, 184, STR_NULL, STR_NULL}, { WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 430, 535, 232, 243, STR_012E_CANCEL, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, BTC, 257, 360, 164, 175, STR_NETWORK_JOIN_GAME, STR_NULL}, { WWT_PANEL, RESIZE_NONE, BGC, 310, 540, 42, 222, STR_NULL, 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}, { WIDGETS_END},
}; };
static const WindowDesc _network_game_window_desc = { static const WindowDesc _network_game_window_desc = {
WDP_CENTER, WDP_CENTER, 550, 215, WDP_CENTER, WDP_CENTER, 550, 250,
WC_NETWORK_WINDOW,0, WC_NETWORK_WINDOW,0,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_network_game_window_widgets, _network_game_window_widgets,
@ -408,23 +411,24 @@ static const WindowDesc _network_game_window_desc = {
void ShowNetworkGameWindow(void) void ShowNetworkGameWindow(void)
{ {
uint i; static bool _first_time_show_network_game_window = true;
Window *w; Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0); DeleteWindowById(WC_NETWORK_WINDOW, 0);
/* Only show once */ /* Only show once */
if (_first_time_show_network_game_window) { if (_first_time_show_network_game_window) {
const char* const *srv;
_first_time_show_network_game_window = false; _first_time_show_network_game_window = false;
// add all servers from the config file to our list // add all servers from the config file to our list
for (i = 0; i != lengthof(_network_host_list); i++) { for (srv = _network_host_list; srv != endof(_network_host_list) && *srv != NULL; srv++) {
if (_network_host_list[i] == NULL) break; NetworkAddServer(*srv);
NetworkAddServer(_network_host_list[i]);
} }
} }
w = AllocateWindowDesc(&_network_game_window_desc); w = AllocateWindowDesc(&_network_game_window_desc);
ttd_strlcpy(_edit_str_buf, _network_player_name, MAX_QUERYSTR_LEN); 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.caret = true;
WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1; 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; int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
w->disabled_state = (_selected_company_item == -1) ? 1 << 7 : 0; 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->companies_on == gi->companies_max) SETBIT(w->disabled_state, 8);
if (gi->spectators_on == gi->spectators_max) SETBIT(w->disabled_state, 9); if (gi->spectators_on == gi->spectators_max) SETBIT(w->disabled_state, 9);
@ -841,8 +844,6 @@ static void ShowNetworkLobbyWindow(void)
Window *w; Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0); DeleteWindowById(WC_NETWORK_WINDOW, 0);
_network_lobby_company_count = 0;
NetworkQueryServer(_network_last_host, _network_last_port, false); NetworkQueryServer(_network_last_host, _network_last_port, false);
w = AllocateWindowDesc(&_network_lobby_window_desc); w = AllocateWindowDesc(&_network_lobby_window_desc);

View File

@ -93,6 +93,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER)
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE) DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
{ {
extern const char _openttd_revision[];
NetworkGameList *item; NetworkGameList *item;
byte game_info_version; byte game_info_version;
@ -102,15 +103,14 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
game_info_version = NetworkRecv_uint8(&_udp_cs, p); game_info_version = NetworkRecv_uint8(&_udp_cs, p);
if (_udp_cs.quited) if (_udp_cs.quited) return;
return;
DEBUG(net, 6)("[NET][UDP] Server response from %s:%d", inet_ntoa(client_addr->sin_addr),ntohs(client_addr->sin_port)); DEBUG(net, 6)("[NET][UDP] Server response from %s:%d", inet_ntoa(client_addr->sin_addr),ntohs(client_addr->sin_port));
// Find next item // Find next item
item = NetworkGameListAddItem(inet_addr(inet_ntoa(client_addr->sin_addr)), ntohs(client_addr->sin_port)); 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 */ * they are to be received */
switch (game_info_version) { switch (game_info_version) {
case 2: case 2:
@ -142,6 +142,12 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
if (item->info.hostname[0] == '\0') if (item->info.hostname[0] == '\0')
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr)); 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; break;
} }