truelight@543: #include "stdafx.h" tron@1299: #include "debug.h" tron@1317: #include "string.h" tron@1309: #include "strings.h" truelight@543: #include "network_data.h" truelight@543: truelight@543: #ifdef ENABLE_NETWORK truelight@543: truelight@543: #include "table/strings.h" truelight@543: #include "network_server.h" truelight@668: #include "network_udp.h" truelight@543: #include "console.h" truelight@543: #include "command.h" truelight@543: #include "gfx.h" truelight@543: #include "vehicle.h" truelight@543: #include "station.h" truelight@543: #include "settings.h" truelight@543: truelight@543: // This file handles all the server-commands truelight@543: truelight@716: void NetworkHandleCommandQueue(NetworkClientState *cs); truelight@543: void NetworkPopulateCompanyInfo(void); truelight@716: void NetworkSendPatchSettings(NetworkClientState *cs); truelight@716: truelight@716: extern const char _openttd_revision[]; truelight@543: truelight@543: // Is the network enabled? truelight@543: truelight@543: // ********** truelight@543: // Sending functions truelight@716: // DEF_SERVER_SEND_COMMAND has parameter: NetworkClientState *cs truelight@543: // ********** truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkClientState *cs, NetworkClientInfo *ci) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_CLIENT_INFO truelight@543: // Function: Sends info about a client truelight@543: // Data: truelight@543: // uint16: The index of the client (always unique on a server. 1 = server) truelight@543: // uint8: As which player the client is playing truelight@543: // String: The name of the client truelight@602: // String: The unique id of the client truelight@543: // truelight@543: truelight@543: Packet *p; truelight@543: truelight@543: if (ci->client_index != NETWORK_EMPTY_INDEX) { truelight@543: p = NetworkSend_Init(PACKET_SERVER_CLIENT_INFO); truelight@543: NetworkSend_uint16(p, ci->client_index); truelight@543: NetworkSend_uint8 (p, ci->client_playas); truelight@543: NetworkSend_string(p, ci->client_name); truelight@602: NetworkSend_string(p, ci->unique_id); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_COMPANY_INFO truelight@543: // Function: Sends info about the companies truelight@543: // Data: truelight@543: // truelight@543: truelight@543: int i; truelight@543: truelight@543: Player *player; truelight@543: Packet *p; truelight@543: truelight@543: byte active = 0; truelight@543: truelight@543: FOR_ALL_PLAYERS(player) { truelight@543: if (player->is_active) truelight@543: active++; truelight@543: } truelight@543: truelight@543: if (active == 0) { truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); truelight@543: truelight@543: NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); truelight@543: NetworkSend_uint8 (p, active); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: return; truelight@543: } truelight@543: truelight@543: NetworkPopulateCompanyInfo(); truelight@543: truelight@543: FOR_ALL_PLAYERS(player) { truelight@543: if (!player->is_active) truelight@543: continue; truelight@543: truelight@543: p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); truelight@543: truelight@543: NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); truelight@543: NetworkSend_uint8 (p, active); truelight@734: NetworkSend_uint8 (p, player->index); truelight@543: truelight@543: NetworkSend_string(p, _network_player_info[player->index].company_name); truelight@543: NetworkSend_uint8 (p, _network_player_info[player->index].inaugurated_year); truelight@543: NetworkSend_uint64(p, _network_player_info[player->index].company_value); truelight@543: NetworkSend_uint64(p, _network_player_info[player->index].money); truelight@543: NetworkSend_uint64(p, _network_player_info[player->index].income); truelight@543: NetworkSend_uint16(p, _network_player_info[player->index].performance); truelight@543: truelight@1011: /* Send 1 if there is a passord for the company else send 0 */ truelight@1011: if (_network_player_info[player->index].password[0] != '\0') { truelight@1011: NetworkSend_uint8 (p, 1); truelight@1011: } else { truelight@1011: NetworkSend_uint8 (p, 0); truelight@1011: } truelight@1011: truelight@543: for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) truelight@543: NetworkSend_uint16(p, _network_player_info[player->index].num_vehicle[i]); truelight@543: truelight@543: for (i = 0; i < NETWORK_STATION_TYPES; i++) truelight@543: NetworkSend_uint16(p, _network_player_info[player->index].num_station[i]); truelight@543: truelight@543: if (_network_player_info[player->index].players[0] == '\0') truelight@543: NetworkSend_string(p, ""); truelight@543: else truelight@543: NetworkSend_string(p, _network_player_info[player->index].players); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@734: truelight@734: p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); truelight@734: truelight@734: NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); truelight@734: NetworkSend_uint8 (p, 0); truelight@734: truelight@734: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_ERROR truelight@543: // Function: The client made an error truelight@543: // Data: truelight@543: // uint8: ErrorID (see network_data.h, NetworkErrorCode) truelight@543: // truelight@543: truelight@716: NetworkClientState *new_cs; truelight@722: char str[100]; truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR); truelight@543: NetworkSend_uint8(p, error); truelight@543: NetworkSend_Packet(p, cs); truelight@543: truelight@543: // Only send when the current client was in game truelight@543: if (cs->status > STATUS_AUTH) { truelight@543: NetworkGetClientName(client_name, sizeof(client_name), cs); truelight@543: truelight@722: GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + error); truelight@543: truelight@722: DEBUG(net, 2)("[NET] %s made an error (%s) and his connection is closed", client_name, str); truelight@543: truelight@722: NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); truelight@543: truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status > STATUS_AUTH && new_cs != cs) { truelight@543: // Some errors we filter to a more general error. Clients don't have to know the real truelight@543: // reason a joining failed. truelight@543: if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || error == NETWORK_ERROR_WRONG_REVISION) truelight@543: error = NETWORK_ERROR_ILLEGAL_PACKET; truelight@543: truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->index, error); truelight@543: } truelight@543: } truelight@543: } else { truelight@543: DEBUG(net, 2)("[NET] Clientno %d has made an error and his connection is closed", cs->index); truelight@543: } truelight@543: truelight@543: cs->quited = true; truelight@543: truelight@543: // Make sure the data get's there before we close the connection truelight@543: NetworkSend_Packets(cs); truelight@543: truelight@543: // The client made a mistake, so drop his connection now! truelight@716: NetworkCloseClient(cs); truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkClientState *cs, NetworkPasswordType type) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_NEED_PASSWORD truelight@543: // Function: Indication to the client that the server needs a password truelight@543: // Data: truelight@543: // uint8: Type of password truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD); truelight@543: NetworkSend_uint8(p, type); truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_WELCOME truelight@543: // Function: The client is joined and ready to receive his map truelight@543: // Data: truelight@543: // uint16: Own ClientID truelight@543: // truelight@543: truelight@543: Packet *p; truelight@716: NetworkClientState *new_cs; truelight@543: truelight@543: // Invalid packet when status is AUTH or higher truelight@543: if (cs->status >= STATUS_AUTH) truelight@543: return; truelight@543: truelight@543: cs->status = STATUS_AUTH; truelight@543: _network_game_info.clients_on++; truelight@543: truelight@543: p = NetworkSend_Init(PACKET_SERVER_WELCOME); truelight@543: NetworkSend_uint16(p, cs->index); truelight@543: NetworkSend_Packet(p, cs); truelight@543: truelight@543: // Transmit info about all the active clients truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs != cs && new_cs->status > STATUS_AUTH) truelight@543: SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, DEREF_CLIENT_INFO(new_cs)); truelight@543: } truelight@543: // Also send the info of the server truelight@543: SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX)); truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT) truelight@543: { truelight@543: // truelight@543: // Packet: PACKET_SERVER_WAIT truelight@543: // Function: The client can not receive the map at the moment because truelight@543: // someone else is already receiving the map truelight@543: // Data: truelight@543: // uint8: Clients awaiting map truelight@543: // truelight@543: int waiting = 0; truelight@716: NetworkClientState *new_cs; truelight@543: Packet *p; truelight@543: truelight@543: // Count how many players are waiting in the queue truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status == STATUS_MAP_WAIT) truelight@543: waiting++; truelight@543: } truelight@543: truelight@543: p = NetworkSend_Init(PACKET_SERVER_WAIT); truelight@543: NetworkSend_uint8(p, waiting); truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: // This sends the map to the client truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_MAP truelight@543: // Function: Sends the map to the client, or a part of it (it is splitted in truelight@543: // a lot of multiple packets) truelight@543: // Data: truelight@543: // uint8: packet-type (MAP_PACKET_START, MAP_PACKET_NORMAL and MAP_PACKET_END) truelight@543: // if MAP_PACKET_START: truelight@543: // uint32: The current FrameCounter truelight@543: // if MAP_PACKET_NORMAL: truelight@543: // piece of the map (till max-size of packet) truelight@543: // if MAP_PACKET_END: truelight@543: // uint32: seed0 of player truelight@543: // uint32: seed1 of player truelight@543: // last 2 are repeated MAX_PLAYERS time truelight@543: // truelight@543: truelight@543: char filename[256]; truelight@543: static FILE *file_pointer; truelight@543: static uint sent_packets; // How many packets we did send succecfully last time truelight@543: truelight@543: if (cs->status < STATUS_AUTH) { truelight@543: // Illegal call, return error and ignore the packet truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED); truelight@543: return; truelight@543: } truelight@543: if (cs->status == STATUS_AUTH) { truelight@543: Packet *p; truelight@543: truelight@543: // Make a dump of the current game truelight@543: sprintf(filename, "%s%snetwork_server.tmp", _path.autosave_dir, PATHSEP); truelight@543: if (SaveOrLoad(filename, SL_SAVE) != SL_OK) error("network savedump failed"); truelight@543: truelight@543: file_pointer = fopen(filename, "rb"); truelight@543: fseek(file_pointer, 0, SEEK_END); truelight@543: truelight@543: // Now send the _frame_counter and how many packets are coming truelight@543: p = NetworkSend_Init(PACKET_SERVER_MAP); truelight@543: NetworkSend_uint8(p, MAP_PACKET_START); truelight@543: NetworkSend_uint32(p, _frame_counter); truelight@543: NetworkSend_uint32(p, ftell(file_pointer)); truelight@543: NetworkSend_Packet(p, cs); truelight@543: truelight@543: fseek(file_pointer, 0, SEEK_SET); truelight@543: truelight@543: sent_packets = 4; // We start with trying 4 packets truelight@543: truelight@543: cs->status = STATUS_MAP; truelight@543: } truelight@543: truelight@543: if (cs->status == STATUS_MAP) { truelight@543: uint i; truelight@543: int res; truelight@543: for (i = 0; i < sent_packets; i++) { truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); truelight@543: NetworkSend_uint8(p, MAP_PACKET_NORMAL); truelight@543: res = fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer); truelight@543: if (ferror(file_pointer)) { truelight@543: error("Error reading temporary network savegame!"); truelight@543: } truelight@543: p->size += res; truelight@543: NetworkSend_Packet(p, cs); truelight@543: if (feof(file_pointer)) { truelight@543: // Done reading! truelight@543: int i; truelight@543: Packet *p; truelight@543: truelight@543: // XXX - Delete this when patch-settings are saved in-game truelight@543: NetworkSendPatchSettings(cs); truelight@543: truelight@543: p = NetworkSend_Init(PACKET_SERVER_MAP); truelight@543: NetworkSend_uint8(p, MAP_PACKET_END); truelight@543: // Send the player_seeds in this packet truelight@543: for (i = 0; i < MAX_PLAYERS; i++) { truelight@543: NetworkSend_uint32(p, _player_seeds[i][0]); truelight@543: NetworkSend_uint32(p, _player_seeds[i][1]); truelight@543: } truelight@543: NetworkSend_Packet(p, cs); truelight@543: truelight@543: // Set the status to DONE_MAP, no we will wait for the client truelight@543: // to send it is ready (maybe that happens like never ;)) truelight@543: cs->status = STATUS_DONE_MAP; truelight@543: fclose(file_pointer); truelight@543: truelight@543: { truelight@716: NetworkClientState *new_cs; truelight@543: bool new_map_client = false; truelight@543: // Check if there is a client waiting for receiving the map truelight@543: // and start sending him the map truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status == STATUS_MAP_WAIT) { truelight@543: // Check if we already have a new client to send the map to truelight@543: if (!new_map_client) { truelight@543: // If not, this client will get the map truelight@543: new_cs->status = STATUS_AUTH; truelight@543: new_map_client = true; truelight@543: SEND_COMMAND(PACKET_SERVER_MAP)(new_cs); truelight@543: } else { truelight@543: // Else, send the other clients how many clients are in front of them truelight@543: SEND_COMMAND(PACKET_SERVER_WAIT)(new_cs); truelight@543: } truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@543: // There is no more data, so break the for truelight@543: break; truelight@543: } truelight@543: } truelight@543: truelight@543: // Send all packets (forced) and check if we have send it all truelight@543: NetworkSend_Packets(cs); truelight@543: if (cs->packet_queue == NULL) { truelight@543: // All are sent, increase the sent_packets truelight@543: sent_packets *= 2; truelight@543: } else { truelight@543: // Not everything is sent, decrease the sent_packets truelight@543: if (sent_packets > 1) sent_packets /= 2; truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkClientState *cs, uint16 client_index) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_JOIN truelight@543: // Function: A client is joined (all active clients receive this after a truelight@543: // PACKET_CLIENT_MAP_OK) Mostly what directly follows is a truelight@543: // PACKET_SERVER_CLIENT_INFO truelight@543: // Data: truelight@543: // uint16: Client-Index truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_JOIN); truelight@543: truelight@543: NetworkSend_uint16(p, client_index); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_FRAME) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_FRAME truelight@543: // Function: Sends the current frame-counter to the client truelight@543: // Data: truelight@543: // uint32: Frame Counter truelight@543: // uint32: Frame Counter Max (how far may the client walk before the server?) truelight@543: // [uint32: general-seed-1] truelight@543: // [uint32: general-seed-2] truelight@543: // (last two depends on compile-settings, and are not default settings) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_FRAME); truelight@543: NetworkSend_uint32(p, _frame_counter); truelight@543: NetworkSend_uint32(p, _frame_counter_max); truelight@543: #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: NetworkSend_uint32(p, _sync_seed_1); truelight@543: #ifdef NETWORK_SEND_DOUBLE_SEED truelight@543: NetworkSend_uint32(p, _sync_seed_2); truelight@543: #endif truelight@543: #endif truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_SYNC truelight@543: // Function: Sends a sync-check to the client truelight@543: // Data: truelight@543: // uint32: Frame Counter truelight@543: // uint32: General-seed-1 truelight@543: // [uint32: general-seed-2] truelight@543: // (last one depends on compile-settings, and are not default settings) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_SYNC); truelight@543: NetworkSend_uint32(p, _frame_counter); truelight@543: NetworkSend_uint32(p, _sync_seed_1); truelight@543: truelight@543: #ifdef NETWORK_SEND_DOUBLE_SEED truelight@543: NetworkSend_uint32(p, _sync_seed_2); truelight@543: #endif truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, CommandPacket *cp) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_COMMAND truelight@543: // Function: Sends a DoCommand to the client 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 truelight@543: // uint32: decode_params truelight@543: // 10 times the last one (lengthof(cp->dp)) truelight@543: // uint8: CallBackID (see callback_table.c) truelight@543: // uint32: Frame of execution truelight@543: // truelight@543: tron@959: uint i; truelight@571: char *dparam_char; truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND); truelight@543: truelight@543: NetworkSend_uint8(p, cp->player); truelight@543: NetworkSend_uint32(p, cp->cmd); truelight@543: NetworkSend_uint32(p, cp->p1); truelight@543: NetworkSend_uint32(p, cp->p2); truelight@543: NetworkSend_uint32(p, cp->tile); truelight@571: /* We are going to send them byte by byte, because dparam is misused truelight@571: for chars (if it is used), and else we have a BigEndian / LittleEndian truelight@571: problem.. we should fix the misuse of dparam... -- TrueLight */ truelight@571: dparam_char = (char *)&cp->dp[0]; truelight@571: for (i = 0; i < lengthof(cp->dp) * 4; i++) { truelight@571: NetworkSend_uint8(p, *dparam_char); truelight@571: dparam_char++; truelight@543: } truelight@543: NetworkSend_uint8(p, cp->callback); truelight@543: NetworkSend_uint32(p, cp->frame); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@722: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, NetworkAction action, uint16 client_index, bool self_send, const char *msg) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_CHAT truelight@543: // Function: Sends a chat-packet to the client truelight@543: // Data: truelight@543: // uint8: ActionID (see network_data.h, NetworkAction) truelight@543: // uint16: Client-index truelight@543: // String: Message (max MAX_TEXT_MSG_LEN) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_CHAT); truelight@543: truelight@543: NetworkSend_uint8(p, action); truelight@543: NetworkSend_uint16(p, client_index); truelight@722: NetworkSend_uint8(p, self_send); truelight@543: NetworkSend_string(p, msg); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientState *cs, uint16 client_index, NetworkErrorCode errorno) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_ERROR_QUIT truelight@543: // Function: One of the clients made an error and is quiting the game truelight@543: // This packet informs the other clients of that. truelight@543: // Data: truelight@543: // uint16: Client-index truelight@543: // uint8: ErrorID (see network_data.h, NetworkErrorCode) truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR_QUIT); truelight@543: truelight@543: NetworkSend_uint16(p, client_index); truelight@543: NetworkSend_uint8(p, errorno); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@716: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientState *cs, uint16 client_index, const char *leavemsg) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_ERROR_QUIT truelight@543: // Function: A client left the game, and this packets informs the other clients truelight@543: // of that. truelight@543: // Data: truelight@543: // uint16: Client-index truelight@543: // String: leave-message truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_QUIT); truelight@543: truelight@543: NetworkSend_uint16(p, client_index); truelight@543: NetworkSend_string(p, leavemsg); truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN) truelight@543: { truelight@543: // truelight@543: // Packet: SERVER_SHUTDOWN truelight@543: // Function: Let the clients know that the server is closing truelight@543: // Data: truelight@543: // truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_SHUTDOWN); truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME) truelight@543: { truelight@543: // truelight@543: // Packet: PACKET_SERVER_NEWGAME truelight@543: // Function: Let the clients know that the server is loading a new map truelight@543: // Data: truelight@543: // truelight@543: // truelight@543: truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_NEWGAME); truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@1026: DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkClientState *cs, uint16 color, const char *command) truelight@1026: { truelight@1026: Packet *p = NetworkSend_Init(PACKET_SERVER_RCON); truelight@1026: truelight@1026: NetworkSend_uint16(p, color); truelight@1026: NetworkSend_string(p, command); truelight@1026: NetworkSend_Packet(p, cs); truelight@1026: } truelight@1026: truelight@543: // ********** truelight@543: // Receiving functions truelight@716: // DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientState *cs, Packet *p truelight@543: // ********** truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO) truelight@543: { truelight@543: SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)(cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN) truelight@543: { truelight@543: char name[NETWORK_NAME_LENGTH]; truelight@602: char unique_id[NETWORK_NAME_LENGTH]; truelight@543: NetworkClientInfo *ci; truelight@543: char test_name[NETWORK_NAME_LENGTH]; truelight@543: byte playas; truelight@543: NetworkLanguage client_lang; truelight@543: char client_revision[NETWORK_REVISION_LENGTH]; truelight@543: truelight@543: truelight@903: NetworkRecv_string(cs, p, client_revision, sizeof(client_revision)); truelight@543: truelight@692: #if defined(WITH_REV) || defined(WITH_REV_HACK) darkvater@659: // Check if the client has revision control enabled darkvater@659: if (strncmp(NOREV_STRING, client_revision, sizeof(client_revision)) != 0) { truelight@624: if (strncmp(_network_game_info.server_revision, client_revision, sizeof(_network_game_info.server_revision) - 1) != 0) { truelight@543: // Different revisions!! truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_REVISION); truelight@543: truelight@543: return; truelight@543: } truelight@543: } darkvater@663: #endif truelight@543: truelight@903: NetworkRecv_string(cs, p, name, sizeof(name)); truelight@903: playas = NetworkRecv_uint8(cs, p); truelight@903: client_lang = NetworkRecv_uint8(cs, p); truelight@903: NetworkRecv_string(cs, p, unique_id, sizeof(unique_id)); truelight@903: truelight@903: if (cs->quited) truelight@903: return; truelight@543: truelight@543: // Check if someone else already has that name truelight@543: snprintf(test_name, sizeof(test_name), "%s", name); truelight@543: truelight@543: if (test_name[0] == '\0') { truelight@543: // We need a valid name.. make it Player truelight@543: snprintf(test_name, sizeof(test_name), "Player"); truelight@543: } truelight@543: truelight@543: if (!NetworkFindName(test_name)) { truelight@543: // We could not create a name for this player truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NAME_IN_USE); truelight@543: return; truelight@543: } truelight@543: truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: truelight@543: snprintf(ci->client_name, sizeof(ci->client_name), "%s", test_name); truelight@602: snprintf(ci->unique_id, sizeof(ci->unique_id), "%s", unique_id); truelight@543: ci->client_playas = playas; truelight@543: ci->client_lang = client_lang; truelight@543: truelight@543: // We now want a password from the client truelight@543: // else we do not allow him in! truelight@543: if (_network_game_info.use_password) truelight@543: SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD); truelight@543: else { truelight@1045: if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS && _network_player_info[ci->client_playas - 1].password[0] != '\0') { truelight@543: SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD); truelight@543: } truelight@543: else { truelight@543: SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); truelight@543: } truelight@543: } truelight@690: truelight@690: /* Make sure companies to who people try to join are not autocleaned */ truelight@690: if (playas >= 1 && playas <= MAX_PLAYERS) truelight@690: _network_player_info[playas-1].months_empty = 0; truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD) truelight@543: { truelight@543: NetworkPasswordType type; truelight@543: char password[NETWORK_PASSWORD_LENGTH]; truelight@543: NetworkClientInfo *ci; truelight@543: truelight@903: type = NetworkRecv_uint8(cs, p); truelight@903: NetworkRecv_string(cs, p, password, sizeof(password)); truelight@543: truelight@543: if (cs->status == STATUS_INACTIVE && type == NETWORK_GAME_PASSWORD) { truelight@543: // Check game-password truelight@543: if (strncmp(password, _network_game_info.server_password, sizeof(password)) != 0) { truelight@543: // Password is invalid truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_PASSWORD); truelight@543: return; truelight@543: } truelight@543: truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: truelight@543: if (ci->client_playas <= MAX_PLAYERS && _network_player_info[ci->client_playas - 1].password[0] != '\0') { truelight@543: SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD); truelight@543: return; truelight@543: } truelight@543: truelight@543: // Valid password, allow user truelight@543: SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); truelight@543: return; truelight@543: } else if (cs->status == STATUS_INACTIVE && type == NETWORK_COMPANY_PASSWORD) { truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: truelight@543: if (strncmp(password, _network_player_info[ci->client_playas - 1].password, sizeof(password)) != 0) { truelight@543: // Password is invalid truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_PASSWORD); truelight@543: return; truelight@543: } truelight@543: truelight@543: SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); truelight@543: return; truelight@543: } truelight@543: truelight@543: truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); truelight@543: return; truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP) truelight@543: { truelight@716: NetworkClientState *new_cs; truelight@543: truelight@543: // The client was never joined.. so this is impossible, right? truelight@543: // Ignore the packet, give the client a warning, and close his connection truelight@543: if (cs->status < STATUS_AUTH || cs->quited) { truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED); truelight@543: return; truelight@543: } truelight@543: truelight@543: // Check if someone else is receiving the map truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status == STATUS_MAP) { truelight@543: // Tell the new client to wait truelight@543: cs->status = STATUS_MAP_WAIT; truelight@543: SEND_COMMAND(PACKET_SERVER_WAIT)(cs); truelight@543: return; truelight@543: } truelight@543: } truelight@543: truelight@543: // We receive a request to upload the map.. give it to the client! truelight@543: SEND_COMMAND(PACKET_SERVER_MAP)(cs); truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK) truelight@543: { truelight@543: // Client has the map, now start syncing truelight@543: if (cs->status == STATUS_DONE_MAP && !cs->quited) { truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@716: NetworkClientState *new_cs; truelight@543: truelight@543: NetworkGetClientName(client_name, sizeof(client_name), cs); truelight@543: truelight@722: NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, client_name, ""); truelight@543: truelight@543: // Mark the client as pre-active, and wait for an ACK truelight@543: // so we know he is done loading and in sync with us truelight@543: cs->status = STATUS_PRE_ACTIVE; truelight@543: NetworkHandleCommandQueue(cs); truelight@543: SEND_COMMAND(PACKET_SERVER_FRAME)(cs); truelight@543: SEND_COMMAND(PACKET_SERVER_SYNC)(cs); truelight@543: truelight@543: // This is the frame the client receives truelight@543: // we need it later on to make sure the client is not too slow truelight@543: cs->last_frame = _frame_counter; truelight@543: cs->last_frame_server = _frame_counter; truelight@543: truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status > STATUS_AUTH) { truelight@543: SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, DEREF_CLIENT_INFO(cs)); truelight@543: SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->index); truelight@543: } truelight@543: } truelight@543: } else { truelight@543: // Wrong status for this packet, give a warning to client, and close connection truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); truelight@543: } truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) truelight@543: { truelight@543: // The client has done a command and wants us to handle it tron@959: uint i; truelight@543: byte callback; truelight@716: NetworkClientState *new_cs; truelight@543: NetworkClientInfo *ci; truelight@571: char *dparam_char; truelight@543: truelight@543: CommandPacket *cp = malloc(sizeof(CommandPacket)); truelight@543: truelight@543: // The client was never joined.. so this is impossible, right? truelight@543: // Ignore the packet, give the client a warning, and close his connection truelight@543: if (cs->status < STATUS_DONE_MAP || cs->quited) { truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); truelight@543: return; truelight@543: } truelight@543: truelight@903: cp->player = NetworkRecv_uint8(cs, p); truelight@903: cp->cmd = NetworkRecv_uint32(cs, p); truelight@903: cp->p1 = NetworkRecv_uint32(cs, p); truelight@903: cp->p2 = NetworkRecv_uint32(cs, p); truelight@903: cp->tile = NetworkRecv_uint32(cs, p); truelight@571: /* We are going to send them byte by byte, because dparam is misused truelight@571: for chars (if it is used), and else we have a BigEndian / LittleEndian truelight@571: problem.. we should fix the misuse of dparam... -- TrueLight */ truelight@571: dparam_char = (char *)&cp->dp[0]; truelight@571: for (i = 0; i < lengthof(cp->dp) * 4; i++) { truelight@903: *dparam_char = NetworkRecv_uint8(cs, p); truelight@571: dparam_char++; truelight@571: } truelight@543: truelight@903: callback = NetworkRecv_uint8(cs, p); truelight@903: truelight@903: if (cs->quited) truelight@903: return; truelight@903: truelight@903: /* Check if cp->cmd is valid */ truelight@903: if (!IsValidCommand(cp->cmd)) { truelight@903: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); truelight@903: return; truelight@903: } truelight@543: truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: // Only CMD_PLAYER_CTRL is always allowed, for the rest, playas needs truelight@543: // to match the player in the packet truelight@686: if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0) && ci->client_playas-1 != cp->player) { truelight@543: // The player did a command with the wrong player_id.. bad!! truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH); truelight@543: return; truelight@543: } truelight@748: switch (cp->cmd) { truelight@748: /* Player_ctrl is not always allowed */ truelight@748: case CMD_PLAYER_CTRL: truelight@748: { truelight@748: /* cp->p1 == 0, is allowed */ truelight@748: if (cp->p1 == 0) { truelight@748: // UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl truelight@748: cp->p2 = cs - _clients; truelight@748: } else { truelight@748: /* The rest are cheats */ truelight@748: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER); truelight@748: return; truelight@748: } truelight@748: } break; truelight@748: truelight@748: /* Don't allow those commands if server == advertising (considered cheating) */ truelight@748: case CMD_MONEY_CHEAT: truelight@748: { truelight@748: if (_network_advertise) { truelight@748: SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER); truelight@748: return; truelight@748: } truelight@748: } break; truelight@543: } truelight@543: truelight@543: truelight@543: // The frame can be executed in the same frame as the next frame-packet truelight@543: // That frame just before that frame is saved in _frame_counter_max truelight@543: cp->frame = _frame_counter_max + 1; truelight@903: cp->next = NULL; truelight@543: truelight@543: // Queue the command for the clients (are send at the end of the frame truelight@543: // if they can handle it ;)) truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status > STATUS_AUTH) { truelight@543: // Callbacks are only send back to the client who sent them in the truelight@543: // first place. This filters that out. truelight@543: if (new_cs != cs) truelight@543: cp->callback = 0; truelight@543: else truelight@543: cp->callback = callback; truelight@903: truelight@543: NetworkAddCommandQueue(new_cs, cp); truelight@543: } truelight@543: } truelight@543: truelight@543: cp->callback = 0; truelight@543: // Queue the command on the server 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: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR) truelight@543: { truelight@543: // This packets means a client noticed an error and is reporting this truelight@543: // to us. Display the error and report it to the other clients truelight@716: NetworkClientState *new_cs; truelight@903: byte errorno = NetworkRecv_uint8(cs, p); truelight@722: char str[100]; truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: truelight@543: // The client was never joined.. thank the client for the packet, but ignore it truelight@543: if (cs->status < STATUS_DONE_MAP || cs->quited) { truelight@543: cs->quited = true; truelight@543: return; truelight@543: } truelight@543: truelight@543: NetworkGetClientName(client_name, sizeof(client_name), cs); truelight@543: truelight@722: GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno); truelight@543: truelight@722: DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str); truelight@543: truelight@722: NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); truelight@543: truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status > STATUS_AUTH) { truelight@543: SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->index, errorno); truelight@543: } truelight@543: } truelight@543: truelight@543: cs->quited = true; truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT) truelight@543: { truelight@543: // The client wants to leave. Display this and report it to the other truelight@543: // clients. truelight@716: NetworkClientState *new_cs; truelight@722: char str[100]; truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: truelight@543: // The client was never joined.. thank the client for the packet, but ignore it truelight@543: if (cs->status < STATUS_DONE_MAP || cs->quited) { truelight@543: cs->quited = true; truelight@543: return; truelight@543: } truelight@543: truelight@903: NetworkRecv_string(cs, p, str, 100); truelight@543: truelight@543: NetworkGetClientName(client_name, sizeof(client_name), cs); truelight@543: truelight@722: NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); truelight@543: truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: if (new_cs->status > STATUS_AUTH) { truelight@722: SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->index, str); truelight@543: } truelight@543: } truelight@543: truelight@543: cs->quited = true; truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK) truelight@543: { truelight@543: // The client received the frame, make note of it truelight@903: cs->last_frame = NetworkRecv_uint32(cs, p); truelight@543: // With those 2 values we can calculate the lag realtime truelight@543: cs->last_frame_server = _frame_counter; truelight@543: truelight@543: // The client is now really active truelight@543: if (cs->status == STATUS_PRE_ACTIVE) truelight@543: cs->status = STATUS_ACTIVE; truelight@543: } truelight@543: truelight@543: truelight@543: truelight@839: void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, uint16 from_index) truelight@543: { truelight@716: NetworkClientState *cs; truelight@543: NetworkClientInfo *ci, *ci_own, *ci_to; truelight@543: truelight@543: switch (desttype) { truelight@543: case DESTTYPE_CLIENT: truelight@722: /* Are we sending to the server? */ truelight@722: if (dest == NETWORK_SERVER_INDEX) { truelight@543: ci = NetworkFindClientInfoFromIndex(from_index); truelight@722: /* Display the text locally, and that is it */ truelight@543: if (ci != NULL) truelight@722: NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); truelight@543: } else { truelight@722: /* Else find the client to send the message to */ truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: if (cs->index == dest) { truelight@722: SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); truelight@543: break; truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@543: // Display the message locally (so you know you have sent it) truelight@543: if (from_index != dest) { truelight@722: if (from_index == NETWORK_SERVER_INDEX) { truelight@543: ci = NetworkFindClientInfoFromIndex(from_index); truelight@543: ci_to = NetworkFindClientInfoFromIndex(dest); truelight@543: if (ci != NULL && ci_to != NULL) truelight@722: NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), true, ci_to->client_name, "%s", msg); truelight@543: } else { truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: if (cs->index == from_index) { truelight@722: SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, dest, true, msg); truelight@543: break; truelight@543: } truelight@543: } truelight@543: } truelight@543: } truelight@543: break; truelight@543: case DESTTYPE_PLAYER: { truelight@543: bool show_local = true; // If this is false, the message is already displayed truelight@543: // on the client who did sent it. truelight@722: /* Find all clients that belong to this player */ truelight@733: ci_to = NULL; truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: if (ci->client_playas == dest) { truelight@722: SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); truelight@733: if (cs->index == from_index) { truelight@543: show_local = false; truelight@733: } truelight@733: ci_to = ci; // Remember a client that is in the company for company-name truelight@543: } truelight@543: } truelight@733: truelight@543: ci = NetworkFindClientInfoFromIndex(from_index); truelight@543: ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); truelight@543: if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) { truelight@722: NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); truelight@543: if (from_index == NETWORK_SERVER_INDEX) truelight@543: show_local = false; truelight@733: ci_to = ci; truelight@543: } truelight@543: truelight@733: /* There is no such player */ truelight@733: if (ci_to == NULL) truelight@733: break; truelight@733: truelight@543: // Display the message locally (so you know you have sent it) truelight@543: if (ci != NULL && show_local) { truelight@543: if (from_index == NETWORK_SERVER_INDEX) { truelight@543: char name[NETWORK_NAME_LENGTH]; truelight@733: GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1); truelight@733: NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas-1), true, name, "%s", msg); truelight@543: } else { truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: if (cs->index == from_index) { truelight@779: SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_index, true, msg); truelight@543: } truelight@543: } truelight@543: } truelight@543: } truelight@543: } truelight@543: break; truelight@543: default: truelight@543: DEBUG(net, 0)("[NET][Server] Received unknown destination type %d. Doing broadcast instead.\n"); truelight@543: /* fall-through to next case */ truelight@543: case DESTTYPE_BROADCAST: truelight@543: FOR_ALL_CLIENTS(cs) { truelight@722: SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); truelight@543: } truelight@543: ci = NetworkFindClientInfoFromIndex(from_index); truelight@543: if (ci != NULL) truelight@722: NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); truelight@543: break; truelight@543: } truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT) truelight@543: { truelight@903: NetworkAction action = NetworkRecv_uint8(cs, p); truelight@903: DestType desttype = NetworkRecv_uint8(cs, p); truelight@903: int dest = NetworkRecv_uint8(cs, p); truelight@543: char msg[MAX_TEXT_MSG_LEN]; truelight@543: truelight@903: NetworkRecv_string(cs, p, msg, MAX_TEXT_MSG_LEN); truelight@543: truelight@543: NetworkServer_HandleChat(action, desttype, dest, msg, cs->index); truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD) truelight@543: { truelight@543: char password[NETWORK_PASSWORD_LENGTH]; truelight@543: NetworkClientInfo *ci; truelight@543: truelight@903: NetworkRecv_string(cs, p, password, sizeof(password)); truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: truelight@543: if (ci->client_playas <= MAX_PLAYERS) { truelight@543: ttd_strlcpy(_network_player_info[ci->client_playas - 1].password, password, sizeof(_network_player_info[ci->client_playas - 1].password)); truelight@543: } truelight@543: } truelight@543: truelight@543: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME) truelight@543: { truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: NetworkClientInfo *ci; truelight@543: truelight@903: NetworkRecv_string(cs, p, client_name, sizeof(client_name)); truelight@543: ci = DEREF_CLIENT_INFO(cs); truelight@543: truelight@903: if (cs->quited) truelight@903: return; truelight@903: truelight@543: if (ci != NULL) { truelight@543: // Display change truelight@793: if (NetworkFindName(client_name)) { truelight@793: NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, client_name); truelight@793: ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name)); truelight@543: NetworkUpdateClientInfo(ci->client_index); truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@1026: DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_RCON) truelight@1026: { truelight@1026: char pass[NETWORK_PASSWORD_LENGTH]; truelight@1026: char command[NETWORK_RCONCOMMAND_LENGTH]; truelight@1026: truelight@1026: if (_network_game_info.rcon_password[0] == '\0') truelight@1026: return; truelight@1026: truelight@1026: NetworkRecv_string(cs, p, pass, sizeof(pass)); truelight@1026: NetworkRecv_string(cs, p, command, sizeof(command)); truelight@1026: truelight@1026: if (strncmp(pass, _network_game_info.rcon_password, sizeof(pass)) != 0) { truelight@1026: DEBUG(net, 0)("[RCon] Wrong password from client-id %d", cs->index); truelight@1026: return; truelight@1026: } truelight@1026: truelight@1026: DEBUG(net, 0)("[RCon] Client-id %d executed: %s", cs->index, command); truelight@1026: truelight@1026: _redirect_console_to_client = cs->index; truelight@1026: IConsoleCmdExec(command); truelight@1026: _redirect_console_to_client = 0; truelight@1026: return; truelight@1026: } truelight@1026: truelight@543: // The layout for the receive-functions by the server truelight@716: typedef void NetworkServerPacket(NetworkClientState *cs, Packet *p); truelight@543: 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 NetworkServerPacket* const _network_server_packet[] = { truelight@543: NULL, /*PACKET_SERVER_FULL,*/ truelight@841: NULL, /*PACKET_SERVER_BANNED,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_JOIN), truelight@543: NULL, /*PACKET_SERVER_ERROR,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO), truelight@543: NULL, /*PACKET_SERVER_COMPANY_INFO,*/ truelight@543: NULL, /*PACKET_SERVER_CLIENT_INFO,*/ truelight@543: NULL, /*PACKET_SERVER_NEED_PASSWORD,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD), truelight@543: NULL, /*PACKET_SERVER_WELCOME,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_GETMAP), truelight@543: NULL, /*PACKET_SERVER_WAIT,*/ truelight@543: NULL, /*PACKET_SERVER_MAP,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK), truelight@543: NULL, /*PACKET_SERVER_JOIN,*/ truelight@543: NULL, /*PACKET_SERVER_FRAME,*/ truelight@543: NULL, /*PACKET_SERVER_SYNC,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_ACK), truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_COMMAND), truelight@543: NULL, /*PACKET_SERVER_COMMAND,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_CHAT), truelight@543: NULL, /*PACKET_SERVER_CHAT,*/ truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD), truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME), truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_QUIT), truelight@543: RECEIVE_COMMAND(PACKET_CLIENT_ERROR), truelight@543: NULL, /*PACKET_SERVER_QUIT,*/ truelight@543: NULL, /*PACKET_SERVER_ERROR_QUIT,*/ truelight@543: NULL, /*PACKET_SERVER_SHUTDOWN,*/ truelight@543: NULL, /*PACKET_SERVER_NEWGAME,*/ truelight@1026: NULL, /*PACKET_SERVER_RCON,*/ truelight@1026: RECEIVE_COMMAND(PACKET_CLIENT_RCON), truelight@543: }; truelight@543: truelight@543: // If this fails, check the array above with network_data.h truelight@543: assert_compile(lengthof(_network_server_packet) == PACKET_END); truelight@543: truelight@543: truelight@543: extern const SettingDesc patch_settings[]; truelight@543: truelight@543: // This is a TEMPORARY solution to get the patch-settings truelight@543: // to the client. When the patch-settings are saved in the savegame truelight@543: // this should be removed!! truelight@716: void NetworkSendPatchSettings(NetworkClientState *cs) truelight@543: { truelight@543: const SettingDesc *item; truelight@543: Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); truelight@543: NetworkSend_uint8(p, MAP_PACKET_PATCH); truelight@543: // Now send all the patch-settings in a pretty order.. truelight@543: truelight@543: item = patch_settings; truelight@543: truelight@543: while (item->name != NULL) { truelight@543: switch (item->flags) { truelight@543: case SDT_BOOL: truelight@543: case SDT_INT8: truelight@543: case SDT_UINT8: truelight@543: NetworkSend_uint8(p, *(uint8 *)item->ptr); truelight@543: break; truelight@543: case SDT_INT16: truelight@543: case SDT_UINT16: truelight@543: NetworkSend_uint16(p, *(uint16 *)item->ptr); truelight@543: break; truelight@543: case SDT_INT32: truelight@543: case SDT_UINT32: truelight@543: NetworkSend_uint32(p, *(uint32 *)item->ptr); truelight@543: break; truelight@543: } truelight@543: item++; truelight@543: } truelight@543: truelight@543: NetworkSend_Packet(p, cs); truelight@543: } truelight@543: truelight@543: // This update the company_info-stuff truelight@543: void NetworkPopulateCompanyInfo(void) truelight@543: { truelight@543: char password[NETWORK_PASSWORD_LENGTH]; truelight@543: Player *p; truelight@543: Vehicle *v; truelight@543: Station *s; truelight@716: NetworkClientState *cs; truelight@543: NetworkClientInfo *ci; truelight@543: int i; truelight@690: uint16 months_empty; truelight@543: truelight@543: FOR_ALL_PLAYERS(p) { truelight@543: if (!p->is_active) { truelight@543: memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo)); truelight@543: continue; truelight@543: } truelight@543: truelight@543: // Clean the info but not the password truelight@543: ttd_strlcpy(password, _network_player_info[p->index].password, sizeof(password)); truelight@690: months_empty = _network_player_info[p->index].months_empty; truelight@543: memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo)); truelight@690: _network_player_info[p->index].months_empty = months_empty; truelight@543: ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password)); truelight@543: truelight@543: // Grap the company name darkvater@1017: SetDParam(0, p->name_1); darkvater@1017: SetDParam(1, p->name_2); darkvater@1017: GetString(_network_player_info[p->index].company_name, STR_JUST_STRING); truelight@543: truelight@543: // Check the income truelight@543: if (_cur_year - 1 == p->inaugurated_year) truelight@543: // The player is here just 1 year, so display [2], else display[1] truelight@543: for (i = 0; i < 13; i++) truelight@543: _network_player_info[p->index].income -= p->yearly_expenses[2][i]; truelight@543: else truelight@543: for (i = 0; i < 13; i++) truelight@543: _network_player_info[p->index].income -= p->yearly_expenses[1][i]; truelight@543: truelight@543: // Set some general stuff truelight@543: _network_player_info[p->index].inaugurated_year = p->inaugurated_year; truelight@543: _network_player_info[p->index].company_value = p->old_economy[0].company_value; truelight@543: _network_player_info[p->index].money = p->money64; truelight@543: _network_player_info[p->index].performance = p->old_economy[0].performance_history; truelight@543: } truelight@543: truelight@543: // Go through all vehicles and count the type of vehicles truelight@543: FOR_ALL_VEHICLES(v) { truelight@543: if (v->owner < MAX_PLAYERS) truelight@543: switch (v->type) { truelight@543: case VEH_Train: bjarni@1067: if (v->subtype == TS_Front_Engine) truelight@543: _network_player_info[v->owner].num_vehicle[0]++; truelight@543: break; truelight@543: case VEH_Road: truelight@543: if (v->cargo_type != CT_PASSENGERS) truelight@543: _network_player_info[v->owner].num_vehicle[1]++; truelight@543: else truelight@543: _network_player_info[v->owner].num_vehicle[2]++; truelight@543: break; truelight@543: case VEH_Aircraft: truelight@543: if (v->subtype <= 2) truelight@543: _network_player_info[v->owner].num_vehicle[3]++; truelight@543: break; truelight@543: case VEH_Ship: truelight@543: _network_player_info[v->owner].num_vehicle[4]++; truelight@543: break; truelight@543: } truelight@543: } truelight@543: truelight@543: // Go through all stations and count the types of stations truelight@543: FOR_ALL_STATIONS(s) { truelight@543: if (s->owner < MAX_PLAYERS) { truelight@543: if ((s->facilities & FACIL_TRAIN)) truelight@543: _network_player_info[s->owner].num_station[0]++; truelight@543: if ((s->facilities & FACIL_TRUCK_STOP)) truelight@543: _network_player_info[s->owner].num_station[1]++; truelight@543: if ((s->facilities & FACIL_BUS_STOP)) truelight@543: _network_player_info[s->owner].num_station[2]++; truelight@543: if ((s->facilities & FACIL_AIRPORT)) truelight@543: _network_player_info[s->owner].num_station[3]++; truelight@543: if ((s->facilities & FACIL_DOCK)) truelight@543: _network_player_info[s->owner].num_station[4]++; truelight@543: } truelight@543: } truelight@543: truelight@543: ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); truelight@543: // Register local player (if not dedicated) darkvater@667: if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) darkvater@667: ttd_strlcpy(_network_player_info[ci->client_playas-1].players, ci->client_name, sizeof(_network_player_info[ci->client_playas-1].players)); truelight@543: truelight@543: FOR_ALL_CLIENTS(cs) { truelight@793: char client_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: truelight@543: NetworkGetClientName(client_name, sizeof(client_name), cs); truelight@543: truelight@543: ci = DEREF_CLIENT_INFO(cs); darkvater@667: if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) { darkvater@667: if (strlen(_network_player_info[ci->client_playas-1].players) != 0) darkvater@667: strncat(_network_player_info[ci->client_playas-1].players, ", ", sizeof(_network_player_info[ci->client_playas-1].players)); truelight@668: darkvater@667: strncat(_network_player_info[ci->client_playas-1].players, client_name, sizeof(_network_player_info[ci->client_playas-1].players)); truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@543: // Send a packet to all clients with updated info about this client_index truelight@543: void NetworkUpdateClientInfo(uint16 client_index) truelight@543: { truelight@716: NetworkClientState *cs; truelight@543: NetworkClientInfo *ci; truelight@543: truelight@543: ci = NetworkFindClientInfoFromIndex(client_index); truelight@543: truelight@656: if (ci == NULL) truelight@656: return; truelight@656: truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci); truelight@543: } truelight@543: } truelight@543: truelight@785: extern void SwitchMode(int new_mode); truelight@785: truelight@785: /* Check if we want to restart the map */ tron@1093: static void NetworkCheckRestartMap(void) truelight@785: { darkvater@970: if (_network_restart_game_date != 0 && _cur_year + MAX_YEAR_BEGIN_REAL >= _network_restart_game_date) { truelight@785: _docommand_recursive = 0; truelight@785: darkvater@970: DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + MAX_YEAR_BEGIN_REAL); truelight@785: truelight@785: _random_seeds[0][0] = Random(); truelight@785: _random_seeds[0][1] = InteractiveRandom(); truelight@785: truelight@785: SwitchMode(SM_NEWGAME); truelight@785: } truelight@785: } truelight@785: truelight@690: /* Check if the server has autoclean_companies activated truelight@690: Two things happen: truelight@690: 1) If a company is not protected, it is closed after 1 year (for example) truelight@690: 2) If a company is protected, protection is disabled after 3 years (for example) truelight@690: (and item 1. happens a year later) */ tron@1093: static void NetworkAutoCleanCompanies(void) truelight@690: { truelight@716: NetworkClientState *cs; truelight@690: NetworkClientInfo *ci; truelight@690: Player *p; truelight@690: bool clients_in_company[MAX_PLAYERS]; truelight@690: truelight@690: if (!_network_autoclean_companies) truelight@690: return; truelight@690: truelight@690: memset(clients_in_company, 0, sizeof(clients_in_company)); truelight@690: truelight@690: /* Detect the active companies */ truelight@690: FOR_ALL_CLIENTS(cs) { truelight@690: ci = DEREF_CLIENT_INFO(cs); truelight@690: if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) { truelight@690: clients_in_company[ci->client_playas-1] = true; truelight@690: } truelight@690: } truelight@690: if (!_network_dedicated) { truelight@690: ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); truelight@690: if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) { truelight@690: clients_in_company[ci->client_playas-1] = true; truelight@690: } truelight@690: } truelight@690: truelight@690: /* Go through all the comapnies */ truelight@690: FOR_ALL_PLAYERS(p) { truelight@690: /* Skip the non-active once */ truelight@690: if (!p->is_active || p->is_ai) truelight@690: continue; truelight@690: truelight@690: if (!clients_in_company[p->index]) { truelight@690: /* The company is empty for one month more */ truelight@690: _network_player_info[p->index].months_empty++; truelight@690: truelight@690: /* Is the company empty for autoclean_unprotected-months, and is there no protection? */ truelight@690: if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') { truelight@690: /* Shut the company down */ truelight@690: DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL); truelight@690: IConsolePrintF(_iconsole_color_default, "Auto-cleaned company #%d", p->index+1); truelight@690: } truelight@690: /* Is the compnay empty for autoclean_protected-months, and there is a protection? */ truelight@690: if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') { truelight@690: /* Unprotect the company */ truelight@690: _network_player_info[p->index].password[0] = '\0'; truelight@690: IConsolePrintF(_iconsole_color_default, "Auto-removed protection from company #%d", p->index+1); truelight@690: _network_player_info[p->index].months_empty = 0; truelight@690: } truelight@690: } else { truelight@690: /* It is not empty, reset the date */ truelight@690: _network_player_info[p->index].months_empty = 0; truelight@690: } truelight@690: } truelight@690: } truelight@690: truelight@543: // This function changes new_name to a name that is unique (by adding #1 ...) truelight@543: // and it returns true if that succeeded. truelight@793: bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]) truelight@543: { truelight@716: NetworkClientState *new_cs; truelight@543: NetworkClientInfo *ci; truelight@543: bool found_name = false; truelight@543: byte number = 0; truelight@793: char original_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: truelight@543: // We use NETWORK_NAME_LENGTH in here, because new_name is really a pointer truelight@793: ttd_strlcpy(original_name, new_name, NETWORK_CLIENT_NAME_LENGTH); truelight@543: truelight@543: while (!found_name) { truelight@543: found_name = true; truelight@543: FOR_ALL_CLIENTS(new_cs) { truelight@543: ci = DEREF_CLIENT_INFO(new_cs); truelight@793: if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) { truelight@543: // Name already in use truelight@543: found_name = false; truelight@543: break; truelight@543: } truelight@543: } truelight@543: // Check if it is the same as the server-name truelight@543: ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); truelight@543: if (ci != NULL) { truelight@793: if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) { truelight@543: // Name already in use truelight@543: found_name = false; truelight@543: } truelight@543: } truelight@543: truelight@543: if (!found_name) { truelight@543: // Try a new name ( #1, #2, and so on) truelight@543: miham@826: // Stop if we tried for more than 50 times.. truelight@543: if (number++ > 50) break; truelight@793: snprintf(new_name, NETWORK_CLIENT_NAME_LENGTH, "%s #%d", original_name, number); truelight@543: } truelight@543: } truelight@543: truelight@543: return found_name; truelight@543: } truelight@543: truelight@543: // Reads a packet from the stream truelight@716: bool NetworkServer_ReadPackets(NetworkClientState *cs) truelight@543: { truelight@543: Packet *p; truelight@543: NetworkRecvStatus res; truelight@543: while((p = NetworkRecv_Packet(cs, &res)) != NULL) { truelight@903: byte type = NetworkRecv_uint8(cs, p); truelight@903: if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->quited) truelight@543: _network_server_packet[type](cs, p); truelight@543: else truelight@543: DEBUG(net, 0)("[NET][Server] Received invalid packet type %d", type); truelight@543: free(p); truelight@543: } truelight@543: truelight@543: return true; truelight@543: } truelight@543: truelight@543: // Handle the local command-queue truelight@716: void NetworkHandleCommandQueue(NetworkClientState *cs) { truelight@543: if (cs->command_queue != NULL) { truelight@543: CommandPacket *cp; truelight@543: CommandPacket *cp_prev; truelight@543: truelight@543: cp = cs->command_queue; truelight@543: cp_prev = NULL; truelight@543: truelight@543: while (cp != NULL) { truelight@543: SEND_COMMAND(PACKET_SERVER_COMMAND)(cs, cp); truelight@543: truelight@543: if (cp_prev != NULL) { truelight@543: cp_prev->next = cp->next; truelight@543: free(cp); truelight@543: cp = cp_prev->next; truelight@543: } else { truelight@543: // This means we are at our first packet truelight@543: cs->command_queue = cp->next; truelight@543: free(cp); truelight@543: cp = cs->command_queue; truelight@543: } truelight@543: } truelight@543: } truelight@543: } truelight@543: truelight@543: // This is called every tick if this is a _network_server truelight@543: void NetworkServer_Tick(void) truelight@543: { truelight@543: #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: static uint32 last_sync_frame = 0; truelight@543: #endif truelight@716: NetworkClientState *cs; truelight@543: bool send_frame = false; truelight@543: truelight@543: // Update max-frame-counter truelight@543: if (_frame_counter > _frame_counter_max) { truelight@543: _frame_counter_max = _frame_counter + _network_frame_freq; truelight@543: send_frame = true; truelight@543: } truelight@543: truelight@543: // Now we are done with the frame, inform the clients that they can truelight@543: // do their frame! truelight@543: FOR_ALL_CLIENTS(cs) { truelight@543: // Check if the speed of the client is what we can expect from a client truelight@543: if (cs->status == STATUS_ACTIVE) { truelight@543: // 1 lag-point per day truelight@543: int lag = NetworkCalculateLag(cs) / DAY_TICKS; truelight@543: if (lag > 0) { truelight@543: if (lag > 3) { truelight@543: // Client did still not report in after 4 game-day, drop him truelight@543: // (that is, the 3 of above, + 1 before any lag is counted) miham@826: IConsolePrintF(_iconsole_color_error,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index); truelight@716: NetworkCloseClient(cs); truelight@543: continue; truelight@543: } truelight@543: truelight@543: // Report once per time we detect the lag truelight@543: if (cs->lag_test == 0) { truelight@543: IConsolePrintF(_iconsole_color_warning,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index); truelight@543: cs->lag_test = 1; truelight@543: } truelight@543: } else { truelight@543: cs->lag_test = 0; truelight@543: } truelight@543: } truelight@543: truelight@543: truelight@543: // Check if we can send command, and if we have anything in the queue truelight@543: if (cs->status > STATUS_DONE_MAP) { truelight@543: NetworkHandleCommandQueue(cs); truelight@543: } truelight@543: truelight@543: // Do we need to send the new frame-packet? truelight@543: if (send_frame && cs->status == STATUS_ACTIVE) { truelight@543: SEND_COMMAND(PACKET_SERVER_FRAME)(cs); truelight@543: } truelight@543: #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: // Is it time to send a sync-packet to all clients? truelight@543: if (last_sync_frame + _network_sync_freq < _frame_counter) { truelight@543: SEND_COMMAND(PACKET_SERVER_SYNC)(cs); truelight@543: } truelight@543: #endif truelight@543: } truelight@543: truelight@543: #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: // Update the last_sync_frame if needed! truelight@543: if (last_sync_frame + _network_sync_freq < _frame_counter) { truelight@543: last_sync_frame = _frame_counter; truelight@543: } truelight@543: #endif truelight@668: truelight@668: /* See if we need to advertise */ truelight@668: NetworkUDPAdvertise(); truelight@543: } truelight@543: truelight@785: void NetworkServerYearlyLoop(void) truelight@785: { truelight@785: NetworkCheckRestartMap(); truelight@785: } truelight@785: truelight@716: void NetworkServerMonthlyLoop(void) truelight@690: { truelight@690: NetworkAutoCleanCompanies(); truelight@690: } truelight@690: truelight@543: #endif /* ENABLE_NETWORK */