--- a/network.c Wed Dec 15 11:42:05 2004 +0000
+++ b/network.c Wed Dec 15 15:19:51 2004 +0000
@@ -404,7 +404,7 @@
cs->quited = false;
if (_network_server) {
- ci = &_network_client_info[client_no];
+ ci = DEREF_CLIENT_INFO(cs);
memset(ci, 0, sizeof(*ci));
cs->index = _network_client_index++;
@@ -700,6 +700,7 @@
_local_command_queue = NULL;
// Clean all client-sockets
+ memset(_clients, 0, sizeof(_clients));
for (cs = _clients; cs != &_clients[MAX_CLIENTS]; cs++) {
cs->socket = INVALID_SOCKET;
cs->status = STATUS_INACTIVE;
--- a/network.h Wed Dec 15 11:42:05 2004 +0000
+++ b/network.h Wed Dec 15 15:19:51 2004 +0000
@@ -27,7 +27,6 @@
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
-#define NETWORK_DISCOVER_PORT 3978
#define NETWORK_DEFAULT_PORT 3979
#define MAX_INTERFACES 9
--- a/network_client.c Wed Dec 15 11:42:05 2004 +0000
+++ b/network_client.c Wed Dec 15 15:19:51 2004 +0000
@@ -65,7 +65,7 @@
p = NetworkSend_Init(PACKET_CLIENT_JOIN);
NetworkSend_string(p, _openttd_revision);
NetworkSend_string(p, _network_player_name); // Player name
- NetworkSend_uint8(p, _network_playas); // Password
+ NetworkSend_uint8(p, _network_playas); // PlayAs
NetworkSend_uint8(p, NETLANG_ANY); // Language
NetworkSend_string(p, _network_unique_id);
NetworkSend_Packet(p, MY_CLIENT);
@@ -317,15 +317,19 @@
{
NetworkClientInfo *ci;
uint16 index = NetworkRecv_uint16(p);
+ byte playas = NetworkRecv_uint8(p);
+ char name[NETWORK_NAME_LENGTH];
+ char unique_id[NETWORK_NAME_LENGTH];
+
+ NetworkRecv_string(p, name, sizeof(name));
+ NetworkRecv_string(p, unique_id, sizeof(unique_id));
+
+ /* Do we receive a change of data? Most likely we changed playas */
+ if (index == _network_own_client_index)
+ _network_playas = playas;
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
- byte playas;
- char name[NETWORK_NAME_LENGTH];
-
- playas = NetworkRecv_uint8(p);
- NetworkRecv_string(p, name, sizeof(name));
-
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
// Client name changed, display the change
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, name);
@@ -336,6 +340,7 @@
ci->client_playas = playas;
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
+
return NETWORK_RECV_STATUS_OKAY;
}
@@ -343,9 +348,11 @@
ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX);
if (ci != NULL) {
ci->client_index = index;
- ci->client_playas = NetworkRecv_uint8(p);
- NetworkRecv_string(p, ci->client_name, sizeof(ci->client_name));
- NetworkRecv_string(p, ci->unique_id, sizeof(ci->unique_id));
+ ci->client_playas = playas;
+
+ ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
+ ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id));
+
return NETWORK_RECV_STATUS_OKAY;
}
--- a/network_server.c Wed Dec 15 11:42:05 2004 +0000
+++ b/network_server.c Wed Dec 15 15:19:51 2004 +0000
@@ -778,7 +778,7 @@
return;
}
if (cp->cmd == CMD_PLAYER_CTRL) {
- // UGLY! p1 is mis-used to get the client-id in CmdPlayerCtrl
+ // UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
cp->p2 = cs - _clients;
}
--- a/players.c Wed Dec 15 11:42:05 2004 +0000
+++ b/players.c Wed Dec 15 15:19:51 2004 +0000
@@ -662,8 +662,6 @@
_docommand_recursive = 0;
DoCommandP(0, ci->client_playas-1, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
}
- } else {
- _network_playas = p->index + 1;
}
} else {
if (_network_server) {
@@ -672,8 +670,6 @@
ci = &_network_client_info[p2];
ci->client_playas = OWNER_SPECTATOR;
NetworkUpdateClientInfo(ci->client_index);
- } else {
- _network_playas = OWNER_SPECTATOR;
}
#endif /* ENABLE_NETWORK */
}