diff options
author | truelight <truelight@openttd.org> | 2004-12-20 16:02:01 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2004-12-20 16:02:01 +0000 |
commit | 9938d19d76f4e5cffe727ce46b4bdef59c813ce7 (patch) | |
tree | 0af8a168a8079b09ae4398464cf72f5fa503a523 | |
parent | f3a8d2ad39b55748795a6170661376be5fe4caa7 (diff) | |
download | openttd-9938d19d76f4e5cffe727ce46b4bdef59c813ce7.tar.xz |
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
went bankrupt, without joining the wrong company (or even failing to do so)
-rw-r--r-- | network.c | 1 | ||||
-rw-r--r-- | network_client.c | 11 | ||||
-rw-r--r-- | network_gui.c | 22 | ||||
-rw-r--r-- | network_server.c | 13 |
4 files changed, 33 insertions, 14 deletions
@@ -762,6 +762,7 @@ static void NetworkInitialize(void) // Clean the client_info memory memset(_network_client_info, 0, sizeof(_network_client_info)); memset(_network_player_info, 0, sizeof(_network_player_info)); + _network_lobby_company_count = 0; _sync_frame = 0; _network_first_time = true; diff --git a/network_client.c b/network_client.c index 4730aab5e..e5a4d600d 100644 --- a/network_client.c +++ b/network_client.c @@ -275,16 +275,17 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) byte current; total = NetworkRecv_uint8(p); - _network_lobby_company_count = total; // There is no data at all.. if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY; - current = NetworkRecv_uint8(p) - 1; + current = NetworkRecv_uint8(p); if (current >= MAX_PLAYERS) return NETWORK_RECV_STATUS_CLOSE_QUERY; + _network_lobby_company_count++; + NetworkRecv_string(p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name)); _network_player_info[current].inaugurated_year = NetworkRecv_uint8(p); _network_player_info[current].company_value = NetworkRecv_uint64(p); @@ -300,11 +301,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) InvalidateWindow(WC_NETWORK_WINDOW, 0); - if (total == current + 1) - // This was the last one - return NETWORK_RECV_STATUS_CLOSE_QUERY; - else - return NETWORK_RECV_STATUS_OKAY; + return NETWORK_RECV_STATUS_OKAY; } return NETWORK_RECV_STATUS_CLOSE_QUERY; diff --git a/network_gui.c b/network_gui.c index 2e92f5db1..8bb3f01f6 100644 --- a/network_gui.c +++ b/network_gui.c @@ -614,6 +614,21 @@ static void ShowNetworkStartServerWindow(void) WP(w,querystr_d).buf = _edit_str_buf; } +static byte NetworkLobbyFindCompanyIndex(byte pos) +{ + byte i; + /* Scroll through all _network_player_info and get the 'pos' item + that is not empty */ + for (i = 0; i < MAX_PLAYERS; i++) { + if (_network_player_info[i].company_name[0] != '\0') { + if (pos-- == 0) + return i; + } + } + + return 0; +} + static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) { switch(e->event) { @@ -638,10 +653,11 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) GfxFillRect(11, 41, 139, 165, 0xD7); pos = w->vscroll.pos; while (pos < _network_lobby_company_count) { - if (_selected_company_item == pos) + byte index = NetworkLobbyFindCompanyIndex(pos); + if (_selected_company_item == index) GfxFillRect(11, y - 1, 139, y + 10, 155); // show highlighted item with a different colour - DoDrawString(_network_player_info[pos].company_name, 13, y, 2); + DoDrawString(_network_player_info[index].company_name, 13, y, 2); pos++; y += NET_PRC__SIZE_OF_ROW_COMPANY; @@ -728,6 +744,8 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) return; } + _selected_company_item = NetworkLobbyFindCompanyIndex(_selected_company_item); + SetWindowDirty(w); break; case 7: /* Join company */ diff --git a/network_server.c b/network_server.c index 9c448e12f..59665cfa9 100644 --- a/network_server.c +++ b/network_server.c @@ -67,8 +67,6 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) Packet *p; byte active = 0; - byte current = 0; - FOR_ALL_PLAYERS(player) { if (player->is_active) @@ -91,13 +89,11 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) if (!player->is_active) continue; - current++; - p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); NetworkSend_uint8 (p, active); - NetworkSend_uint8 (p, current); + NetworkSend_uint8 (p, player->index); NetworkSend_string(p, _network_player_info[player->index].company_name); NetworkSend_uint8 (p, _network_player_info[player->index].inaugurated_year); @@ -119,6 +115,13 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) NetworkSend_Packet(p, cs); } + + p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); + + NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); + NetworkSend_uint8 (p, 0); + + NetworkSend_Packet(p, cs); } DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error) |