(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)
This commit is contained in:
truelight 2004-12-20 16:02:01 +00:00
parent 7460764d91
commit 5f25a0788a
4 changed files with 33 additions and 14 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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)