(svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.

Change: Made code a little bit more readable by putting _selected_item in a local var with a shorter name.
This commit is contained in:
ludde 2005-07-15 18:43:39 +00:00
parent 3486e7e9d5
commit 6a3f58e050
2 changed files with 39 additions and 31 deletions

View File

@ -49,6 +49,8 @@ enum {
NETWORK_PLAYERS_LENGTH = 200, NETWORK_PLAYERS_LENGTH = 200,
NETWORK_CLIENT_NAME_LENGTH = 25, NETWORK_CLIENT_NAME_LENGTH = 25,
NETWORK_RCONCOMMAND_LENGTH = 500, NETWORK_RCONCOMMAND_LENGTH = 500,
NETWORK_NUM_LANGUAGES = 4,
}; };
// This is the struct used by both client and server // This is the struct used by both client and server

View File

@ -99,18 +99,20 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
_selected_item = NULL; _selected_item = NULL;
break; break;
case WE_PAINT: { case WE_PAINT: {
NetworkGameList *sel = _selected_item;
w->disabled_state = 0; w->disabled_state = 0;
if (_selected_item == NULL) { if (sel == NULL) {
SETBIT(w->disabled_state, 17); SETBIT(w->disabled_state, 18); SETBIT(w->disabled_state, 17); SETBIT(w->disabled_state, 18);
} else if (!_selected_item->online) { } else if (!sel->online) {
SETBIT(w->disabled_state, 17); // Server offline, join button disabled SETBIT(w->disabled_state, 17); // Server offline, join button disabled
} else if (_selected_item->info.clients_on == _selected_item->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, 17); // Server full, join button disabled
// 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(_selected_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) { } else if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
if (strncmp(_selected_item->info.server_revision, NOREV_STRING, sizeof(_selected_item->info.server_revision)) != 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 SETBIT(w->disabled_state, 17); // Revision mismatch, join button disabled
} }
@ -139,11 +141,11 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
} }
while (cur_item != NULL) { while (cur_item != NULL) {
bool compatible = (strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) == 0); bool compatible =
if (strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision)) == 0) !strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) ||
compatible = true; !strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision));
if (cur_item == _selected_item) if (cur_item == sel)
GfxFillRect(11, y - 2, 218, y + 9, 10); // show highlighted item with a different colour GfxFillRect(11, y - 2, 218, y + 9, 10); // show highlighted item with a different colour
snprintf(servername, sizeof(servername), "%s", cur_item->info.server_name); snprintf(servername, sizeof(servername), "%s", cur_item->info.server_name);
@ -176,10 +178,10 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
// right menu // right menu
GfxFillRect(252, 23, 478, 65, 157); GfxFillRect(252, 23, 478, 65, 157);
if (_selected_item == NULL) { if (sel == NULL) {
DrawStringMultiCenter(365, 40, STR_NETWORK_GAME_INFO, 0); DrawStringMultiCenter(365, 40, STR_NETWORK_GAME_INFO, 0);
} else if (!_selected_item->online) { } else if (!sel->online) {
SetDParamStr(0, _selected_item->info.server_name); SetDParamStr(0, sel->info.server_name);
DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name
DrawStringMultiCenter(365, 110, STR_NETWORK_SERVER_OFFLINE, 2); // server offline DrawStringMultiCenter(365, 110, STR_NETWORK_SERVER_OFFLINE, 2); // server offline
@ -189,56 +191,60 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
DrawStringMultiCenter(365, 30, STR_NETWORK_GAME_INFO, 0); DrawStringMultiCenter(365, 30, STR_NETWORK_GAME_INFO, 0);
SetDParamStr(0, _selected_item->info.server_name); SetDParamStr(0, sel->info.server_name);
DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name
SetDParamStr(0, _selected_item->info.map_name); SetDParamStr(0, sel->info.map_name);
DrawStringMultiCenter(365, 54, STR_02BD, 2); // map name DrawStringMultiCenter(365, 54, STR_02BD, 2); // map name
SetDParam(0, _selected_item->info.clients_on); SetDParam(0, sel->info.clients_on);
SetDParam(1, _selected_item->info.clients_max); SetDParam(1, sel->info.clients_max);
DrawString(260, y, STR_NETWORK_CLIENTS, 2); // clients on the server / maximum slots DrawString(260, y, STR_NETWORK_CLIENTS, 2); // clients on the server / maximum slots
y+=10; y+=10;
SetDParam(0, STR_NETWORK_LANG_ANY+_selected_item->info.server_lang); if (sel->info.server_lang < NETWORK_NUM_LANGUAGES) {
DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language SetDParam(0, STR_NETWORK_LANG_ANY+sel->info.server_lang);
DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language
}
y+=10; y+=10;
SetDParam(0, STR_TEMPERATE_LANDSCAPE+_selected_item->info.map_set); if (sel->info.map_set < NUM_LANDSCAPE ) {
DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset SetDParam(0, STR_TEMPERATE_LANDSCAPE+sel->info.map_set);
DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset
}
y+=10; y+=10;
SetDParam(0, _selected_item->info.map_width); SetDParam(0, sel->info.map_width);
SetDParam(1, _selected_item->info.map_height); SetDParam(1, sel->info.map_height);
DrawString(260, y, STR_NETWORK_MAP_SIZE, 2); // map size DrawString(260, y, STR_NETWORK_MAP_SIZE, 2); // map size
y+=10; y+=10;
SetDParamStr(0, _selected_item->info.server_revision); SetDParamStr(0, sel->info.server_revision);
DrawString(260, y, STR_NETWORK_SERVER_VERSION, 2); // server version DrawString(260, y, STR_NETWORK_SERVER_VERSION, 2); // server version
y+=10; y+=10;
SetDParamStr(0, _selected_item->info.hostname); SetDParamStr(0, sel->info.hostname);
SetDParam(1, _selected_item->port); SetDParam(1, sel->port);
DrawString(260, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address DrawString(260, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
y+=10; y+=10;
SetDParam(0, _selected_item->info.start_date); SetDParam(0, sel->info.start_date);
DrawString(260, y, STR_NETWORK_START_DATE, 2); // start date DrawString(260, y, STR_NETWORK_START_DATE, 2); // start date
y+=10; y+=10;
SetDParam(0, _selected_item->info.game_date); SetDParam(0, sel->info.game_date);
DrawString(260, y, STR_NETWORK_CURRENT_DATE, 2); // current date DrawString(260, y, STR_NETWORK_CURRENT_DATE, 2); // current date
y+=10; y+=10;
y+=2; y+=2;
if (strncmp(_selected_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) { if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
if (strncmp(_selected_item->info.server_revision, NOREV_STRING, sizeof(_selected_item->info.server_revision)) != 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 DrawStringMultiCenter(365, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
} else if (_selected_item->info.clients_on == _selected_item->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(365, y, STR_NETWORK_SERVER_FULL, 2); // server full
} else if (_selected_item->info.use_password) } else if (sel->info.use_password)
DrawStringMultiCenter(365, y, STR_NETWORK_PASSWORD, 2); // password warning DrawStringMultiCenter(365, y, STR_NETWORK_PASSWORD, 2); // password warning
y+=10; y+=10;