tron@2186: /* $Id$ */ tron@2186: rubidium@10429: /** @file network_client.cpp Client part of the network protocol. */ rubidium@10429: Darkvater@4826: #ifdef ENABLE_NETWORK Darkvater@4826: rubidium@5720: #include "../stdafx.h" rubidium@5720: #include "../debug.h" rubidium@7762: #include "../openttd.h" rubidium@10792: #include "network_internal.h" rubidium@5720: #include "core/tcp.h" truelight@543: #include "network_client.h" truelight@543: #include "network_gamelist.h" tron@4512: #include "network_gui.h" rubidium@5720: #include "../saveload.h" rubidium@8612: #include "../command_func.h" rubidium@10684: #include "../console_func.h" rubidium@5720: #include "../variables.h" rubidium@5720: #include "../ai/ai.h" rubidium@8626: #include "../core/alloc_func.hpp" rubidium@7425: #include "../fileio.h" rubidium@8495: #include "../md5.h" rubidium@8610: #include "../strings_func.h" rubidium@8627: #include "../window_func.h" rubidium@8710: #include "../string_func.h" rubidium@8750: #include "../player_func.h" rubidium@8750: #include "../player_base.h" rubidium@8750: #include "../player_gui.h" smatz@10402: #include "../rev.h" truelight@543: rubidium@8760: #include "table/strings.h" rubidium@8760: truelight@543: // This file handles all the client-commands truelight@543: truelight@543: truelight@543: // So we don't make too much typos ;) truelight@543: #define MY_CLIENT DEREF_CLIENT(0) truelight@543: truelight@543: static uint32 last_ack_frame; truelight@543: rubidium@8495: /** One bit of 'entropy' used to generate a salt for the company passwords. */ rubidium@8495: static uint32 _password_game_seed; rubidium@8495: /** The other bit of 'entropy' used to generate a salt for the company passwords. */ rubidium@8495: static char _password_server_unique_id[NETWORK_UNIQUE_ID_LENGTH]; rubidium@8495: rubidium@8495: /** Make sure the unique ID length is the same as a md5 hash. */ rubidium@8495: assert_compile(NETWORK_UNIQUE_ID_LENGTH == 16 * 2 + 1); rubidium@8495: rubidium@8495: /** rubidium@8495: * Generates a hashed password for the company name. rubidium@8495: * @param password the password to 'encrypt'. rubidium@8495: * @return the hashed password. rubidium@8495: */ rubidium@8495: static const char *GenerateCompanyPasswordHash(const char *password) rubidium@8495: { rubidium@8495: if (StrEmpty(password)) return password; rubidium@8495: rubidium@8495: char salted_password[NETWORK_UNIQUE_ID_LENGTH]; rubidium@8495: rubidium@8495: memset(salted_password, 0, sizeof(salted_password)); rubidium@8495: snprintf(salted_password, sizeof(salted_password), "%s", password); rubidium@8495: /* Add the game seed and the server's unique ID as the salt. */ rubidium@8748: for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH - 1; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i); rubidium@8495: skidd13@8629: Md5 checksum; skidd13@8629: uint8 digest[16]; rubidium@8495: static char hashed_password[NETWORK_UNIQUE_ID_LENGTH]; rubidium@8495: rubidium@8495: /* Generate the MD5 hash */ rubidium@8748: checksum.Append((const uint8*)salted_password, sizeof(salted_password) - 1); skidd13@8629: checksum.Finish(digest); rubidium@8495: rubidium@8495: for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]); rubidium@8748: hashed_password[lengthof(hashed_password) - 1] = '\0'; rubidium@8495: rubidium@8495: return hashed_password; rubidium@8495: } rubidium@8495: rubidium@8495: /** rubidium@8495: * Hash the current company password; used when the server 'player' sets his/her password. rubidium@8495: */ rubidium@8495: void HashCurrentCompanyPassword() rubidium@8495: { rubidium@8495: if (StrEmpty(_network_player_info[_local_player].password)) return; rubidium@8495: rubidium@10775: _password_game_seed = _settings_game.game_creation.generation_seed; rubidium@10784: ttd_strlcpy(_password_server_unique_id, _settings_client.network.network_id, sizeof(_password_server_unique_id)); rubidium@8495: rubidium@8495: const char *new_pw = GenerateCompanyPasswordHash(_network_player_info[_local_player].password); rubidium@10415: ttd_strlcpy(_network_player_info[_local_player].password, new_pw, sizeof(_network_player_info[_local_player].password)); rubidium@8495: } rubidium@8495: rubidium@8495: truelight@543: // ********** truelight@543: // Sending functions truelight@543: // DEF_CLIENT_SEND_COMMAND has no parameters truelight@543: // ********** truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_COMPANY_INFO truelight@543: // Function: Request company-info (in detail) truelight@543: // Data: truelight@543: // truelight@543: // truelight@543: Packet *p; truelight@543: _network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; truelight@543: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_JOIN truelight@543: // Function: Try to join the server truelight@543: // Data: truelight@543: // String: OpenTTD Revision (norev000 if no revision) truelight@543: // String: Player Name (max NETWORK_NAME_LENGTH) truelight@543: // uint8: Play as Player id (1..MAX_PLAYERS) truelight@543: // uint8: Language ID truelight@602: // String: Unique id to find the player back in server-listing truelight@543: // truelight@543: truelight@543: Packet *p; truelight@543: _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; truelight@543: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: p = NetworkSend_Init(PACKET_CLIENT_JOIN); rubidium@6151: p->Send_string(_openttd_revision); rubidium@10784: p->Send_string(_settings_client.network.player_name); // Player name rubidium@6151: p->Send_uint8 (_network_playas); // PlayAs rubidium@6151: p->Send_uint8 (NETLANG_ANY); // Language rubidium@10784: p->Send_string(_settings_client.network.network_id); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: rubidium@6123: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED) rubidium@6123: { rubidium@6123: // rubidium@6123: // Packet: CLIENT_NEWGRFS_CHECKED rubidium@6123: // Function: Tell the server that we have the required GRFs rubidium@6123: // Data: rubidium@6123: // rubidium@6123: rubidium@6123: Packet *p = NetworkSend_Init(PACKET_CLIENT_NEWGRFS_CHECKED); rubidium@6153: MY_CLIENT->Send_Packet(p); rubidium@6123: } rubidium@6123: truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_PASSWORD truelight@543: // Function: Send a password to the server to authorize truelight@543: // Data: truelight@543: // uint8: NetworkPasswordType truelight@543: // String: Password truelight@543: // truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD); rubidium@6151: p->Send_uint8 (type); rubidium@8495: p->Send_string(type == NETWORK_GAME_PASSWORD ? password : GenerateCompanyPasswordHash(password)); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_GETMAP truelight@543: // Function: Request the map from the server truelight@543: // Data: truelight@543: // truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_MAP_OK truelight@543: // Function: Tell the server that we are done receiving/loading the map truelight@543: // Data: truelight@543: // truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_ACK truelight@543: // Function: Tell the server we are done with this frame truelight@543: // Data: truelight@543: // uint32: current FrameCounter of the client truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK); truelight@543: rubidium@6151: p->Send_uint32(_frame_counter); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: // Send a command packet to the server truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_COMMAND truelight@543: // Function: Send a DoCommand to the Server truelight@543: // Data: truelight@543: // uint8: PlayerID (0..MAX_PLAYERS-1) truelight@543: // uint32: CommandID (see command.h) truelight@543: // uint32: P1 (free variables used in DoCommand) truelight@543: // uint32: P2 truelight@543: // uint32: Tile tron@1820: // string: text truelight@543: // uint8: CallBackID (see callback_table.c) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND); truelight@543: rubidium@6151: p->Send_uint8 (cp->player); rubidium@6151: p->Send_uint32(cp->cmd); rubidium@6151: p->Send_uint32(cp->p1); rubidium@6151: p->Send_uint32(cp->p2); rubidium@6151: p->Send_uint32((uint32)cp->tile); rubidium@6151: p->Send_string(cp->text); rubidium@6151: p->Send_uint8 (cp->callback); truelight@543: rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: // Send a chat-packet over the network Darkvater@4906: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_CHAT truelight@543: // Function: Send a chat-packet to the serve truelight@543: // Data: truelight@543: // uint8: ActionID (see network_data.h, NetworkAction) truelight@543: // uint8: Destination Type (see network_data.h, DestType); rubidium@7027: // uint16: Destination Player truelight@543: // String: Message (max MAX_TEXT_MSG_LEN) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT); truelight@543: rubidium@6151: p->Send_uint8 (action); rubidium@6151: p->Send_uint8 (type); rubidium@7027: p->Send_uint16(dest); rubidium@6151: p->Send_string(msg); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: // Send an error-packet over the network truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_ERROR truelight@543: // Function: The client made an error and is quiting the game truelight@543: // Data: truelight@543: // uint8: ErrorID (see network_data.h, NetworkErrorCode) truelight@543: // truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR); truelight@543: rubidium@6151: p->Send_uint8(errorno); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password) truelight@543: { truelight@543: // truelight@543: // Packet: PACKET_CLIENT_SET_PASSWORD truelight@543: // Function: Set the password for the clients current company truelight@543: // Data: truelight@543: // String: Password truelight@543: // truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD); truelight@543: rubidium@8495: p->Send_string(GenerateCompanyPasswordHash(password)); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name) truelight@543: { truelight@543: // truelight@543: // Packet: PACKET_CLIENT_SET_NAME truelight@543: // Function: Gives the player a new name truelight@543: // Data: truelight@543: // String: Name truelight@543: // truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME); truelight@543: rubidium@6151: p->Send_string(name); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@543: // Send an quit-packet over the network truelight@543: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg) truelight@543: { truelight@543: // truelight@543: // Packet: CLIENT_QUIT truelight@543: // Function: The client is quiting the game truelight@543: // Data: truelight@543: // String: leave-message truelight@543: // truelight@543: Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT); truelight@543: rubidium@6151: p->Send_string(leavemsg); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@543: } truelight@543: truelight@1026: DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command) truelight@1026: { truelight@1026: Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON); rubidium@6151: p->Send_string(pass); rubidium@6151: p->Send_string(command); rubidium@6153: MY_CLIENT->Send_Packet(p); truelight@1026: } truelight@1026: truelight@543: truelight@543: // ********** truelight@543: // Receiving functions truelight@543: // DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p truelight@543: // ********** truelight@543: rubidium@7425: extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir); rubidium@10233: extern StringID _switch_mode_errorstr; truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL) truelight@543: { truelight@543: // We try to join a server which is full truelight@543: _switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL; truelight@543: DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: return NETWORK_RECV_STATUS_SERVER_FULL; truelight@543: } truelight@543: truelight@841: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_BANNED) truelight@841: { truelight@841: // We try to join a server where we are banned truelight@841: _switch_mode_errorstr = STR_NETWORK_ERR_SERVER_BANNED; truelight@841: DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); truelight@841: truelight@841: return NETWORK_RECV_STATUS_SERVER_BANNED; truelight@841: } truelight@841: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) truelight@543: { truelight@543: byte company_info_version; truelight@543: int i; truelight@543: rubidium@6151: company_info_version = p->Recv_uint8(); truelight@543: Darkvater@4880: if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) { truelight@543: byte total; rubidium@5838: PlayerID current; truelight@543: rubidium@6151: total = p->Recv_uint8(); truelight@543: truelight@543: // There is no data at all.. Darkvater@4880: if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY; truelight@543: rubidium@6151: current = (Owner)p->Recv_uint8(); rubidium@11161: if (!IsValidPlayerID(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY; truelight@543: rubidium@6151: p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name)); rubidium@6151: _network_player_info[current].inaugurated_year = p->Recv_uint32(); rubidium@6151: _network_player_info[current].company_value = p->Recv_uint64(); rubidium@6151: _network_player_info[current].money = p->Recv_uint64(); rubidium@6151: _network_player_info[current].income = p->Recv_uint64(); rubidium@6151: _network_player_info[current].performance = p->Recv_uint16(); rubidium@6169: _network_player_info[current].use_password = p->Recv_bool(); truelight@543: for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) rubidium@6151: _network_player_info[current].num_vehicle[i] = p->Recv_uint16(); truelight@543: for (i = 0; i < NETWORK_STATION_TYPES; i++) rubidium@6151: _network_player_info[current].num_station[i] = p->Recv_uint16(); truelight@543: rubidium@6151: p->Recv_string(_network_player_info[current].players, sizeof(_network_player_info[current].players)); truelight@543: truelight@543: InvalidateWindow(WC_NETWORK_WINDOW, 0); truelight@543: truelight@734: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: return NETWORK_RECV_STATUS_CLOSE_QUERY; truelight@543: } truelight@543: truelight@543: // This packet contains info about the client (playas and name) truelight@543: // as client we save this in NetworkClientInfo, linked via 'index' truelight@543: // which is always an unique number on a server. truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO) truelight@543: { truelight@543: NetworkClientInfo *ci; rubidium@6151: uint16 index = p->Recv_uint16(); rubidium@6151: PlayerID playas = (Owner)p->Recv_uint8(); truelight@662: char name[NETWORK_NAME_LENGTH]; truelight@662: rubidium@6151: p->Recv_string(name, sizeof(name)); truelight@903: Darkvater@4880: if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; truelight@662: truelight@662: /* Do we receive a change of data? Most likely we changed playas */ Darkvater@4880: if (index == _network_own_client_index) _network_playas = playas; truelight@2684: truelight@543: ci = NetworkFindClientInfoFromIndex(index); truelight@543: if (ci != NULL) { truelight@543: if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) { truelight@543: // Client name changed, display the change rubidium@10685: NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", name); truelight@543: } else if (playas != ci->client_playas) { truelight@543: // The player changed from client-player.. truelight@543: // Do not display that for now truelight@543: } truelight@543: truelight@543: ci->client_playas = playas; truelight@543: ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); truelight@662: truelight@722: InvalidateWindow(WC_CLIENT_LIST, 0); truelight@722: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: // We don't have this index yet, find an empty index, and put the data there truelight@543: ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX); truelight@543: if (ci != NULL) { truelight@543: ci->client_index = index; truelight@662: ci->client_playas = playas; truelight@662: truelight@662: ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); truelight@662: truelight@722: InvalidateWindow(WC_CLIENT_LIST, 0); truelight@722: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: // Here the program should never ever come..... truelight@543: return NETWORK_RECV_STATUS_MALFORMED_PACKET; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR) truelight@543: { rubidium@6151: NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8(); truelight@543: Darkvater@2879: switch (error) { Darkvater@2879: /* We made an error in the protocol, and our connection is closed.... */ Darkvater@2879: case NETWORK_ERROR_NOT_AUTHORIZED: Darkvater@2879: case NETWORK_ERROR_NOT_EXPECTED: Darkvater@2879: case NETWORK_ERROR_PLAYER_MISMATCH: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_SERVER_ERROR; Darkvater@2879: break; Darkvater@2879: case NETWORK_ERROR_FULL: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL; Darkvater@2879: break; Darkvater@2879: case NETWORK_ERROR_WRONG_REVISION: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_WRONG_REVISION; Darkvater@2879: break; Darkvater@2879: case NETWORK_ERROR_WRONG_PASSWORD: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_WRONG_PASSWORD; Darkvater@2879: break; Darkvater@2879: case NETWORK_ERROR_KICKED: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_KICKED; Darkvater@2879: break; Darkvater@2879: case NETWORK_ERROR_CHEATER: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_CHEATER; Darkvater@2879: break; Darkvater@2879: default: Darkvater@2879: _switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION; truelight@543: } truelight@543: truelight@543: DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: return NETWORK_RECV_STATUS_SERVER_ERROR; truelight@543: } truelight@543: rubidium@6123: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS) rubidium@6123: { rubidium@6151: uint grf_count = p->Recv_uint8(); rubidium@6123: NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY; rubidium@6123: rubidium@6123: /* Check all GRFs */ rubidium@6123: for (; grf_count > 0; grf_count--) { rubidium@6123: GRFConfig c; rubidium@6123: MY_CLIENT->Recv_GRFIdentifier(p, &c); rubidium@6123: rubidium@6123: /* Check whether we know this GRF */ rubidium@6123: const GRFConfig *f = FindGRFConfig(c.grfid, c.md5sum); rubidium@6123: if (f == NULL) { rubidium@6123: /* We do not know this GRF, bail out of initialization */ rubidium@6123: char buf[sizeof(c.md5sum) * 2 + 1]; rubidium@6123: md5sumToString(buf, lastof(buf), c.md5sum); rubidium@6123: DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf); rubidium@6123: ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH; rubidium@6123: } rubidium@6123: } rubidium@6123: rubidium@6123: if (ret == NETWORK_RECV_STATUS_OKAY) { rubidium@6123: /* Start receiving the map */ rubidium@6123: SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(); rubidium@6123: } else { rubidium@6123: /* NewGRF mismatch, bail out */ rubidium@6123: _switch_mode_errorstr = STR_NETWORK_ERR_NEWGRF_MISMATCH; rubidium@6123: } rubidium@6123: return ret; rubidium@6123: } rubidium@6123: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD) truelight@543: { rubidium@6151: NetworkPasswordType type = (NetworkPasswordType)p->Recv_uint8(); truelight@543: tron@4512: switch (type) { rubidium@8495: case NETWORK_COMPANY_PASSWORD: rubidium@8495: /* Initialize the password hash salting variables. */ rubidium@8495: _password_game_seed = p->Recv_uint32(); rubidium@8495: p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id)); rubidium@8495: if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_MALFORMED_PACKET; rubidium@8495: tron@4512: case NETWORK_GAME_PASSWORD: tron@4512: ShowNetworkNeedPassword(type); tron@4512: return NETWORK_RECV_STATUS_OKAY; tron@4512: tron@4512: default: return NETWORK_RECV_STATUS_MALFORMED_PACKET; truelight@543: } truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME) truelight@543: { rubidium@6151: _network_own_client_index = p->Recv_uint16(); truelight@543: rubidium@8495: /* Initialize the password hash salting variables, even if they were previously. */ rubidium@8495: _password_game_seed = p->Recv_uint32(); rubidium@8495: p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id)); rubidium@8495: truelight@543: // Start receiving the map truelight@543: SEND_COMMAND(PACKET_CLIENT_GETMAP)(); truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WAIT) truelight@543: { truelight@543: _network_join_status = NETWORK_JOIN_STATUS_WAITING; rubidium@6151: _network_join_waiting = p->Recv_uint8(); truelight@543: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: // We are put on hold for receiving the map.. we need GUI for this ;) Darkvater@5568: DEBUG(net, 1, "The server is currently busy sending the map to someone else, please wait..." ); Darkvater@5568: DEBUG(net, 1, "There are %d clients in front of you", _network_join_waiting); truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) truelight@543: { truelight@543: static FILE *file_pointer; truelight@543: truelight@543: byte maptype; truelight@543: rubidium@6151: maptype = p->Recv_uint8(); truelight@903: Darkvater@4880: if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; truelight@543: truelight@543: // First packet, init some stuff truelight@543: if (maptype == MAP_PACKET_START) { rubidium@7425: file_pointer = FioFOpenFile("network_client.tmp", "wb", AUTOSAVE_DIR);; truelight@543: if (file_pointer == NULL) { truelight@543: _switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; truelight@543: return NETWORK_RECV_STATUS_SAVEGAME; truelight@543: } truelight@543: rubidium@6151: _frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32(); truelight@543: truelight@543: _network_join_kbytes = 0; rubidium@6151: _network_join_kbytes_total = p->Recv_uint32() / 1024; rubidium@5954: rubidium@5954: /* If the network connection has been closed due to loss of connection rubidium@5954: * or when _network_join_kbytes_total is 0, the join status window will rubidium@5954: * do a division by zero. When the connection is lost, we just return rubidium@5954: * that. If kbytes_total is 0, the packet must be malformed as a rubidium@5954: * savegame less than 1 kilobyte is practically impossible. */ rubidium@5954: if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; rubidium@5954: if (_network_join_kbytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET; rubidium@5954: rubidium@5954: _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING; rubidium@6988: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: truelight@543: // The first packet does not contain any more data truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: if (maptype == MAP_PACKET_NORMAL) { truelight@543: // We are still receiving data, put it to the file rubidium@10421: if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != (size_t)(p->size - p->pos)) { rubidium@10418: _switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; rubidium@10418: return NETWORK_RECV_STATUS_SAVEGAME; rubidium@10418: } truelight@543: truelight@543: _network_join_kbytes = ftell(file_pointer) / 1024; truelight@543: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: } truelight@543: truelight@543: // Check if this was the last packet truelight@543: if (maptype == MAP_PACKET_END) { truelight@543: fclose(file_pointer); truelight@543: truelight@543: _network_join_status = NETWORK_JOIN_STATUS_PROCESSING; truelight@543: InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: Darkvater@5664: /* The map is done downloading, load it */ rubidium@7425: if (!SafeSaveOrLoad("network_client.tmp", SL_LOAD, GM_NORMAL, AUTOSAVE_DIR)) { truelight@543: DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); truelight@543: _switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; truelight@543: return NETWORK_RECV_STATUS_SAVEGAME; truelight@543: } Darkvater@5683: /* If the savegame has successfully loaded, ALL windows have been removed, Darkvater@5683: * only toolbar/statusbar and gamefield are visible */ Darkvater@1500: truelight@543: // Say we received the map and loaded it correctly! truelight@543: SEND_COMMAND(PACKET_CLIENT_MAP_OK)(); truelight@543: Darkvater@4880: /* New company/spectator (invalid player) or company we want to join is not active Darkvater@4880: * Switch local player to spectator and await the server's judgement */ rubidium@11161: if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayerID(_network_playas) || Darkvater@4878: !GetPlayer(_network_playas)->is_active) { truelight@543: rubidium@5564: SetLocalPlayer(PLAYER_SPECTATOR); Darkvater@4880: Darkvater@5683: if (_network_playas != PLAYER_SPECTATOR) { Darkvater@1797: /* We have arrived and ready to start playing; send a command to make a new player; Darkvater@1797: * the server will give us a client-id and let us in */ Darkvater@5683: _network_join_status = NETWORK_JOIN_STATUS_REGISTERING; Darkvater@5683: ShowJoinStatusWindow(); truelight@543: NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL); truelight@543: } truelight@543: } else { truelight@543: // take control over an existing company rubidium@5564: SetLocalPlayer(_network_playas); truelight@543: } truelight@543: } truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME) truelight@543: { rubidium@6151: _frame_counter_server = p->Recv_uint32(); rubidium@6151: _frame_counter_max = p->Recv_uint32(); truelight@543: #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: // Test if the server supports this option truelight@543: // and if we are at the frame the server is truelight@543: if (p->pos < p->size) { truelight@543: _sync_frame = _frame_counter_server; rubidium@6151: _sync_seed_1 = p->Recv_uint32(); truelight@543: #ifdef NETWORK_SEND_DOUBLE_SEED rubidium@6151: _sync_seed_2 = p->Recv_uint32(); truelight@543: #endif truelight@543: } truelight@543: #endif Darkvater@5568: DEBUG(net, 5, "Received FRAME %d", _frame_counter_server); truelight@543: truelight@543: // Let the server know that we received this frame correctly truelight@543: // We do this only once per day, to save some bandwidth ;) truelight@543: if (!_network_first_time && last_ack_frame < _frame_counter) { truelight@543: last_ack_frame = _frame_counter + DAY_TICKS; Darkvater@5568: DEBUG(net, 4, "Sent ACK at %d", _frame_counter); truelight@543: SEND_COMMAND(PACKET_CLIENT_ACK)(); truelight@543: } truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC) truelight@543: { rubidium@6151: _sync_frame = p->Recv_uint32(); rubidium@6151: _sync_seed_1 = p->Recv_uint32(); truelight@543: #ifdef NETWORK_SEND_DOUBLE_SEED rubidium@6151: _sync_seed_2 = p->Recv_uint32(); truelight@543: #endif truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) truelight@543: { KUDr@5860: CommandPacket *cp = MallocT(1); rubidium@6151: cp->player = (PlayerID)p->Recv_uint8(); rubidium@6151: cp->cmd = p->Recv_uint32(); rubidium@6151: cp->p1 = p->Recv_uint32(); rubidium@6151: cp->p2 = p->Recv_uint32(); rubidium@6151: cp->tile = p->Recv_uint32(); rubidium@6151: p->Recv_string(cp->text, sizeof(cp->text)); rubidium@6151: cp->callback = p->Recv_uint8(); rubidium@6151: cp->frame = p->Recv_uint32(); rubidium@7718: cp->my_cmd = p->Recv_bool(); rubidium@6151: cp->next = NULL; truelight@543: truelight@543: // The server did send us this command.. truelight@543: // queue it in our own queue, so we can handle it in the upcoming frame! truelight@543: truelight@543: if (_local_command_queue == NULL) { truelight@543: _local_command_queue = cp; truelight@543: } else { truelight@543: // Find last packet truelight@543: CommandPacket *c = _local_command_queue; truelight@543: while (c->next != NULL) c = c->next; truelight@543: c->next = cp; truelight@543: } truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT) truelight@543: { Darkvater@4946: char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN]; Darkvater@4880: const NetworkClientInfo *ci = NULL, *ci_to; truelight@543: rubidium@6151: NetworkAction action = (NetworkAction)p->Recv_uint8(); rubidium@6151: uint16 index = p->Recv_uint16(); rubidium@6169: bool self_send = p->Recv_bool(); rubidium@6151: p->Recv_string(msg, MAX_TEXT_MSG_LEN); truelight@543: truelight@543: ci_to = NetworkFindClientInfoFromIndex(index); truelight@543: if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY; truelight@543: Darkvater@4946: /* Did we initiate the action locally? */ truelight@722: if (self_send) { truelight@722: switch (action) { truelight@722: case NETWORK_ACTION_CHAT_CLIENT: Darkvater@4946: /* For speaking to client we need the client-name */ truelight@722: snprintf(name, sizeof(name), "%s", ci_to->client_name); truelight@722: ci = NetworkFindClientInfoFromIndex(_network_own_client_index); truelight@722: break; Darkvater@4945: Darkvater@4945: /* For speaking to company or giving money, we need the player-name */ truelight@722: case NETWORK_ACTION_GIVE_MONEY: rubidium@11161: if (!IsValidPlayerID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY; Darkvater@4945: /* fallthrough */ Darkvater@4945: case NETWORK_ACTION_CHAT_COMPANY: { rubidium@11161: StringID str = IsValidPlayerID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS; peter1138@7556: SetDParam(0, ci_to->client_playas); Darkvater@4878: Darkvater@4945: GetString(name, str, lastof(name)); truelight@722: ci = NetworkFindClientInfoFromIndex(_network_own_client_index); Darkvater@4945: } break; Darkvater@4946: Darkvater@4946: default: NOT_REACHED(); break; truelight@722: } truelight@543: } else { truelight@722: /* Display message from somebody else */ truelight@602: snprintf(name, sizeof(name), "%s", ci_to->client_name); truelight@543: ci = ci_to; truelight@543: } truelight@543: truelight@543: if (ci != NULL) rubidium@10685: NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg); truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT) truelight@543: { truelight@722: char str[100]; truelight@543: uint16 index; truelight@543: NetworkClientInfo *ci; truelight@543: rubidium@6151: index = p->Recv_uint16(); rubidium@6151: GetNetworkErrorMsg(str, (NetworkErrorCode)p->Recv_uint8(), lastof(str)); truelight@543: truelight@543: ci = NetworkFindClientInfoFromIndex(index); truelight@543: if (ci != NULL) { rubidium@10685: NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str); truelight@543: truelight@543: // The client is gone, give the NetworkClientInfo free truelight@543: ci->client_index = NETWORK_EMPTY_INDEX; truelight@543: } truelight@543: truelight@543: InvalidateWindow(WC_CLIENT_LIST, 0); truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT) truelight@543: { truelight@722: char str[100]; truelight@543: uint16 index; truelight@543: NetworkClientInfo *ci; truelight@543: rubidium@6151: index = p->Recv_uint16(); rubidium@6151: p->Recv_string(str, lengthof(str)); truelight@543: truelight@543: ci = NetworkFindClientInfoFromIndex(index); truelight@543: if (ci != NULL) { rubidium@10685: NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str); truelight@543: truelight@543: // The client is gone, give the NetworkClientInfo free truelight@543: ci->client_index = NETWORK_EMPTY_INDEX; truelight@543: } else { Darkvater@5568: DEBUG(net, 0, "Unknown client (%d) is leaving the game", index); truelight@543: } truelight@543: truelight@543: InvalidateWindow(WC_CLIENT_LIST, 0); truelight@543: truelight@543: // If we come here it means we could not locate the client.. strange :s truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN) truelight@543: { truelight@543: uint16 index; truelight@543: NetworkClientInfo *ci; truelight@543: rubidium@6151: index = p->Recv_uint16(); truelight@543: truelight@543: ci = NetworkFindClientInfoFromIndex(index); truelight@722: if (ci != NULL) rubidium@10685: NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name, ""); truelight@543: truelight@543: InvalidateWindow(WC_CLIENT_LIST, 0); truelight@543: truelight@543: return NETWORK_RECV_STATUS_OKAY; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN) truelight@543: { truelight@543: _switch_mode_errorstr = STR_NETWORK_SERVER_SHUTDOWN; truelight@543: truelight@543: return NETWORK_RECV_STATUS_SERVER_ERROR; truelight@543: } truelight@543: truelight@543: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME) truelight@543: { truelight@543: // To trottle the reconnects a bit, every clients waits truelight@543: // his _local_player value before reconnecting Darkvater@4848: // PLAYER_SPECTATOR is currently 255, so to avoid long wait periods truelight@543: // set the max to 10. truelight@543: _network_reconnect = min(_local_player + 1, 10); truelight@543: _switch_mode_errorstr = STR_NETWORK_SERVER_REBOOT; truelight@543: truelight@543: return NETWORK_RECV_STATUS_SERVER_ERROR; truelight@543: } truelight@543: truelight@1026: DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON) truelight@1026: { truelight@1026: char rcon_out[NETWORK_RCONCOMMAND_LENGTH]; truelight@1026: rubidium@10685: ConsoleColour color_code = (ConsoleColour)p->Recv_uint16(); rubidium@6151: p->Recv_string(rcon_out, sizeof(rcon_out)); truelight@1026: truelight@1026: IConsolePrint(color_code, rcon_out); truelight@1026: truelight@1026: return NETWORK_RECV_STATUS_OKAY; truelight@1026: } truelight@543: truelight@543: truelight@543: truelight@543: // The layout for the receive-functions by the client truelight@543: typedef NetworkRecvStatus NetworkClientPacket(Packet *p); truelight@543: truelight@543: // This array matches PacketType. At an incoming truelight@543: // packet it is matches against this array truelight@543: // and that way the right function to handle that truelight@543: // packet is found. truelight@543: static NetworkClientPacket* const _network_client_packet[] = { truelight@543: RECEIVE_COMMAND(PACKET_SERVER_FULL), truelight@841: RECEIVE_COMMAND(PACKET_SERVER_BANNED), truelight@543: NULL, /*PACKET_CLIENT_JOIN,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_ERROR), truelight@543: NULL, /*PACKET_CLIENT_COMPANY_INFO,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD), truelight@543: NULL, /*PACKET_CLIENT_PASSWORD,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_WELCOME), truelight@543: NULL, /*PACKET_CLIENT_GETMAP,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_WAIT), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_MAP), truelight@543: NULL, /*PACKET_CLIENT_MAP_OK,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_JOIN), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_FRAME), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_SYNC), truelight@543: NULL, /*PACKET_CLIENT_ACK,*/ truelight@543: NULL, /*PACKET_CLIENT_COMMAND,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_COMMAND), truelight@543: NULL, /*PACKET_CLIENT_CHAT,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_CHAT), truelight@543: NULL, /*PACKET_CLIENT_SET_PASSWORD,*/ truelight@543: NULL, /*PACKET_CLIENT_SET_NAME,*/ truelight@543: NULL, /*PACKET_CLIENT_QUIT,*/ truelight@543: NULL, /*PACKET_CLIENT_ERROR,*/ truelight@543: RECEIVE_COMMAND(PACKET_SERVER_QUIT), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN), truelight@543: RECEIVE_COMMAND(PACKET_SERVER_NEWGAME), truelight@1026: RECEIVE_COMMAND(PACKET_SERVER_RCON), truelight@1026: NULL, /*PACKET_CLIENT_RCON,*/ rubidium@6123: RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS), rubidium@6123: NULL, /*PACKET_CLIENT_NEWGRFS_CHECKED,*/ truelight@543: }; truelight@543: truelight@543: // If this fails, check the array above with network_data.h truelight@543: assert_compile(lengthof(_network_client_packet) == PACKET_END); truelight@543: truelight@543: // Is called after a client is connected to the server rubidium@6573: void NetworkClient_Connected() truelight@543: { truelight@543: // Set the frame-counter to 0 so nothing happens till we are ready truelight@543: _frame_counter = 0; truelight@543: _frame_counter_server = 0; truelight@543: last_ack_frame = 0; truelight@543: // Request the game-info truelight@543: SEND_COMMAND(PACKET_CLIENT_JOIN)(); truelight@543: } truelight@543: truelight@543: // Reads the packets from the socket-stream, if available rubidium@5875: NetworkRecvStatus NetworkClient_ReadPackets(NetworkTCPSocketHandler *cs) truelight@543: { truelight@543: Packet *p; truelight@543: NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY; truelight@543: rubidium@6153: while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet(&res)) != NULL) { rubidium@6151: byte type = p->Recv_uint8(); Darkvater@4880: if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) { truelight@543: res = _network_client_packet[type](p); tron@2026: } else { truelight@543: res = NETWORK_RECV_STATUS_MALFORMED_PACKET; Darkvater@5568: DEBUG(net, 0, "[client] received invalid packet type %d", type); truelight@543: } truelight@543: rubidium@6149: delete p; truelight@543: } truelight@543: truelight@543: return res; truelight@543: } truelight@543: rubidium@10792: void NetworkClientSendRcon(const char *password, const char *command) rubidium@10792: { rubidium@10792: SEND_COMMAND(PACKET_CLIENT_RCON)(password, command); rubidium@10792: } rubidium@10792: rubidium@10792: void NetworkUpdatePlayerName() rubidium@10792: { rubidium@10792: NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index); rubidium@10792: rubidium@10792: if (ci == NULL) return; rubidium@10792: rubidium@10792: /* Don't change the name if it is the same as the old name */ rubidium@10792: if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) { rubidium@10792: if (!_network_server) { rubidium@10792: SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name); rubidium@10792: } else { rubidium@10792: if (NetworkFindName(_settings_client.network.player_name)) { rubidium@10792: NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name); rubidium@10792: ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name)); rubidium@10792: NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); rubidium@10792: } rubidium@10792: } rubidium@10792: } rubidium@10792: } rubidium@10792: rubidium@10792: void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg) rubidium@10792: { rubidium@10792: SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg); rubidium@10792: } rubidium@10792: rubidium@10792: void NetworkClientSetPassword() rubidium@10792: { rubidium@10792: SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password); rubidium@10792: } rubidium@10792: truelight@543: #endif /* ENABLE_NETWORK */