diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/packet.cpp | 14 | ||||
-rw-r--r-- | src/network/core/packet.h | 2 | ||||
-rw-r--r-- | src/network/core/tcp.cpp | 4 | ||||
-rw-r--r-- | src/network/network_client.cpp | 30 | ||||
-rw-r--r-- | src/network/network_server.cpp | 48 |
5 files changed, 40 insertions, 58 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 7a43173f1..a70bd6ca0 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -48,20 +48,6 @@ Packet::Packet(PacketType type) } /** - * Create a packet for sending - * @param type the of packet - * @return the newly created packet - */ -Packet *NetworkSend_Init(PacketType type) -{ - Packet *packet = new Packet(type); - /* An error is inplace here, because it simply means we ran out of memory. */ - if (packet == NULL) error("Failed to allocate Packet"); - - return packet; -} - -/** * Writes the packet size from the raw packet from packet->size */ void Packet::PrepareToSend() diff --git a/src/network/core/packet.h b/src/network/core/packet.h index 6b5442e0e..7079b927b 100644 --- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -72,8 +72,6 @@ public: void Recv_string(char *buffer, size_t size, bool allow_newlines = false); }; -Packet *NetworkSend_Init(PacketType type); - #endif /* ENABLE_NETWORK */ #endif /* NETWORK_CORE_PACKET_H */ diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index b30e4e526..c3a7733e3 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -134,16 +134,14 @@ bool NetworkTCPSocketHandler::Send_Packets() Packet *NetworkTCPSocketHandler::Recv_Packet() { ssize_t res; - Packet *p; if (!this->IsConnected()) return NULL; if (this->packet_recv == NULL) { this->packet_recv = new Packet(this); - if (this->packet_recv == NULL) error("Failed to allocate packet"); } - p = this->packet_recv; + Packet *p = this->packet_recv; /* Read packet size */ if (p->pos < sizeof(PacketSize)) { diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 97bd2baaa..e7bca2778 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -123,7 +123,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO) _network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); - p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO); + p = new Packet(PACKET_CLIENT_COMPANY_INFO); MY_CLIENT->Send_Packet(p); } @@ -144,7 +144,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN) _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); - p = NetworkSend_Init(PACKET_CLIENT_JOIN); + p = new Packet(PACKET_CLIENT_JOIN); p->Send_string(_openttd_revision); p->Send_string(_settings_client.network.client_name); // Client name p->Send_uint8 (_network_join_as); // PlayAs @@ -161,7 +161,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED) * Data: */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_NEWGRFS_CHECKED); + Packet *p = new Packet(PACKET_CLIENT_NEWGRFS_CHECKED); MY_CLIENT->Send_Packet(p); } @@ -174,7 +174,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, * uint8: NetworkPasswordType * String: Password */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD); + Packet *p = new Packet(PACKET_CLIENT_PASSWORD); p->Send_uint8 (type); p->Send_string(type == NETWORK_GAME_PASSWORD ? password : GenerateCompanyPasswordHash(password)); MY_CLIENT->Send_Packet(p); @@ -189,7 +189,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP) * <none> */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP); + Packet *p = new Packet(PACKET_CLIENT_GETMAP); MY_CLIENT->Send_Packet(p); } @@ -202,7 +202,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK) * <none> */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK); + Packet *p = new Packet(PACKET_CLIENT_MAP_OK); MY_CLIENT->Send_Packet(p); } @@ -215,7 +215,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK) * uint32: current FrameCounter of the client */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK); + Packet *p = new Packet(PACKET_CLIENT_ACK); p->Send_uint32(_frame_counter); MY_CLIENT->Send_Packet(p); @@ -237,7 +237,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(const CommandPacket *cp) * uint8: CallBackID (see callback_table.c) */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND); + Packet *p = new Packet(PACKET_CLIENT_COMMAND); MY_CLIENT->Send_Command(p, cp); MY_CLIENT->Send_Packet(p); @@ -257,7 +257,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType * uint64: Some arbitrary number */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT); + Packet *p = new Packet(PACKET_CLIENT_CHAT); p->Send_uint8 (action); p->Send_uint8 (type); @@ -277,7 +277,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno) * Data: * uint8: ErrorID (see network_data.h, NetworkErrorCode) */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR); + Packet *p = new Packet(PACKET_CLIENT_ERROR); p->Send_uint8(errorno); MY_CLIENT->Send_Packet(p); @@ -291,7 +291,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password) * Data: * String: Password */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD); + Packet *p = new Packet(PACKET_CLIENT_SET_PASSWORD); p->Send_string(GenerateCompanyPasswordHash(password)); MY_CLIENT->Send_Packet(p); @@ -305,7 +305,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name) * Data: * String: Name */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME); + Packet *p = new Packet(PACKET_CLIENT_SET_NAME); p->Send_string(name); MY_CLIENT->Send_Packet(p); @@ -319,14 +319,14 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)() * Function: The client is quiting the game * Data: */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT); + Packet *p = new Packet(PACKET_CLIENT_QUIT); MY_CLIENT->Send_Packet(p); } DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command) { - Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON); + Packet *p = new Packet(PACKET_CLIENT_RCON); p->Send_string(pass); p->Send_string(command); MY_CLIENT->Send_Packet(p); @@ -334,7 +334,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char * DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_MOVE)(CompanyID company, const char *pass) { - Packet *p = NetworkSend_Init(PACKET_CLIENT_MOVE); + Packet *p = new Packet(PACKET_CLIENT_MOVE); p->Send_uint8(company); p->Send_string(GenerateCompanyPasswordHash(pass)); MY_CLIENT->Send_Packet(p); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index ebc23e89d..7a3ec4cb4 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -53,7 +53,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkClientSocket *cs */ if (ci->client_id != INVALID_CLIENT_ID) { - Packet *p = NetworkSend_Init(PACKET_SERVER_CLIENT_INFO); + Packet *p = new Packet(PACKET_SERVER_CLIENT_INFO); p->Send_uint32(ci->client_id); p->Send_uint8 (ci->client_playas); p->Send_string(ci->client_name); @@ -106,7 +106,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) Packet *p; FOR_ALL_COMPANIES(company) { - p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); + p = new Packet(PACKET_SERVER_COMPANY_INFO); p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION); p->Send_bool (true); @@ -121,7 +121,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) cs->Send_Packet(p); } - p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); + p = new Packet(PACKET_SERVER_COMPANY_INFO); p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION); p->Send_bool (false); @@ -139,7 +139,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw */ char str[100]; - Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR); + Packet *p = new Packet(PACKET_SERVER_ERROR); p->Send_uint8(error); cs->Send_Packet(p); @@ -193,7 +193,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHECK_NEWGRFS)(NetworkClientSocket * * 16 * uint8: MD5 checksum of the GRF */ - Packet *p = NetworkSend_Init(PACKET_SERVER_CHECK_NEWGRFS); + Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS); const GRFConfig *c; uint grf_count = 0; @@ -223,7 +223,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkClientSocket * cs->status = STATUS_AUTHORIZING; - Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD); + Packet *p = new Packet(PACKET_SERVER_NEED_PASSWORD); p->Send_uint8(type); p->Send_uint32(_settings_game.game_creation.generation_seed); p->Send_string(_settings_client.network.network_id); @@ -248,7 +248,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME) cs->status = STATUS_AUTH; _network_game_info.clients_on++; - p = NetworkSend_Init(PACKET_SERVER_WELCOME); + p = new Packet(PACKET_SERVER_WELCOME); p->Send_uint32(cs->client_id); p->Send_uint32(_settings_game.game_creation.generation_seed); p->Send_string(_settings_client.network.network_id); @@ -281,7 +281,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT) if (new_cs->status == STATUS_MAP_WAIT) waiting++; } - p = NetworkSend_Init(PACKET_SERVER_WAIT); + p = new Packet(PACKET_SERVER_WAIT); p->Send_uint8(waiting); cs->Send_Packet(p); } @@ -325,7 +325,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?"); /* Now send the _frame_counter and how many packets are coming */ - p = NetworkSend_Init(PACKET_SERVER_MAP); + p = new Packet(PACKET_SERVER_MAP); p->Send_uint8 (MAP_PACKET_START); p->Send_uint32(_frame_counter); p->Send_uint32(ftell(file_pointer)); @@ -345,7 +345,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) uint i; int res; for (i = 0; i < sent_packets; i++) { - Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); + Packet *p = new Packet(PACKET_SERVER_MAP); p->Send_uint8(MAP_PACKET_NORMAL); res = (int)fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer); @@ -355,7 +355,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) cs->Send_Packet(p); if (feof(file_pointer)) { /* Done reading! */ - Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); + Packet *p = new Packet(PACKET_SERVER_MAP); p->Send_uint8(MAP_PACKET_END); cs->Send_Packet(p); @@ -413,7 +413,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkClientSocket *cs, Clien * uint32: Client-identifier */ - Packet *p = NetworkSend_Init(PACKET_SERVER_JOIN); + Packet *p = new Packet(PACKET_SERVER_JOIN); p->Send_uint32(client_id); @@ -434,7 +434,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_FRAME) * (last two depends on compile-settings, and are not default settings) */ - Packet *p = NetworkSend_Init(PACKET_SERVER_FRAME); + Packet *p = new Packet(PACKET_SERVER_FRAME); p->Send_uint32(_frame_counter); p->Send_uint32(_frame_counter_max); #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME @@ -458,7 +458,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC) * (last one depends on compile-settings, and are not default settings) */ - Packet *p = NetworkSend_Init(PACKET_SERVER_SYNC); + Packet *p = new Packet(PACKET_SERVER_SYNC); p->Send_uint32(_frame_counter); p->Send_uint32(_sync_seed_1); @@ -484,7 +484,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientSocket *cs, co * uint32: Frame of execution */ - Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND); + Packet *p = new Packet(PACKET_SERVER_COMMAND); cs->Send_Command(p, cp); p->Send_uint32(cp->frame); @@ -505,7 +505,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientSocket *cs, Netwo * uint64: Arbitrary data */ - Packet *p = NetworkSend_Init(PACKET_SERVER_CHAT); + Packet *p = new Packet(PACKET_SERVER_CHAT); p->Send_uint8 (action); p->Send_uint32(client_id); @@ -527,7 +527,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientSocket *cs, * uint8: ErrorID (see network_data.h, NetworkErrorCode) */ - Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR_QUIT); + Packet *p = new Packet(PACKET_SERVER_ERROR_QUIT); p->Send_uint32(client_id); p->Send_uint8 (errorno); @@ -545,7 +545,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientSocket *cs, Clien * uint32: Client-identifier */ - Packet *p = NetworkSend_Init(PACKET_SERVER_QUIT); + Packet *p = new Packet(PACKET_SERVER_QUIT); p->Send_uint32(client_id); @@ -561,7 +561,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN) * <none> */ - Packet *p = NetworkSend_Init(PACKET_SERVER_SHUTDOWN); + Packet *p = new Packet(PACKET_SERVER_SHUTDOWN); cs->Send_Packet(p); } @@ -574,13 +574,13 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME) * <none> */ - Packet *p = NetworkSend_Init(PACKET_SERVER_NEWGAME); + Packet *p = new Packet(PACKET_SERVER_NEWGAME); cs->Send_Packet(p); } DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkClientSocket *cs, uint16 colour, const char *command) { - Packet *p = NetworkSend_Init(PACKET_SERVER_RCON); + Packet *p = new Packet(PACKET_SERVER_RCON); p->Send_uint16(colour); p->Send_string(command); @@ -589,7 +589,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkClientSocket *cs, uint1 DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_MOVE)(NetworkClientSocket *cs, ClientID client_id, CompanyID company_id) { - Packet *p = NetworkSend_Init(PACKET_SERVER_MOVE); + Packet *p = new Packet(PACKET_SERVER_MOVE); p->Send_uint32(client_id); p->Send_uint8(company_id); @@ -598,7 +598,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_MOVE)(NetworkClientSocket *cs, Clien DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMPANY_UPDATE)(NetworkClientSocket *cs) { - Packet *p = NetworkSend_Init(PACKET_SERVER_COMPANY_UPDATE); + Packet *p = new Packet(PACKET_SERVER_COMPANY_UPDATE); p->Send_uint16(_network_company_passworded); cs->Send_Packet(p); @@ -606,7 +606,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMPANY_UPDATE)(NetworkClientSocket DEF_SERVER_SEND_COMMAND(PACKET_SERVER_CONFIG_UPDATE) { - Packet *p = NetworkSend_Init(PACKET_SERVER_CONFIG_UPDATE); + Packet *p = new Packet(PACKET_SERVER_CONFIG_UPDATE); p->Send_uint8(_settings_client.network.max_companies); p->Send_uint8(_settings_client.network.max_spectators); |