Mercurial > hg > openttd
changeset 13238:5d0bc0bb8150 draft
(svn r17746) -Codechange: 'operator new' doesn't return NULL, NetworkSend_Init() is useless
author | smatz <smatz@openttd.org> |
---|---|
date | Fri, 09 Oct 2009 11:03:00 +0000 |
parents | 30bea6aca458 |
children | 53ddcc216269 |
files | src/network/core/packet.cpp src/network/core/packet.h src/network/core/tcp.cpp src/network/network_client.cpp src/network/network_server.cpp |
diffstat | 5 files changed, 40 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -48,20 +48,6 @@ } /** - * 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()
--- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -72,8 +72,6 @@ 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 */
--- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -134,16 +134,14 @@ 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)) {
--- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -123,7 +123,7 @@ _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 @@ _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 @@ * 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 @@ * 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 @@ * <none> */ - Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP); + Packet *p = new Packet(PACKET_CLIENT_GETMAP); MY_CLIENT->Send_Packet(p); } @@ -202,7 +202,7 @@ * <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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ * 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_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);
--- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -53,7 +53,7 @@ */ 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 @@ 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 @@ 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 @@ */ 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 @@ * 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ * 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 @@ * (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 @@ * (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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ * <none> */ - Packet *p = NetworkSend_Init(PACKET_SERVER_SHUTDOWN); + Packet *p = new Packet(PACKET_SERVER_SHUTDOWN); cs->Send_Packet(p); } @@ -574,13 +574,13 @@ * <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_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_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(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);