diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index 2222f7be04..16259c64ce 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -65,12 +65,12 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection([[maybe_unused]] bool * if the OS-network-buffer is full) * @param packet the packet to send */ -void NetworkTCPSocketHandler::SendPacket(Packet *packet) +void NetworkTCPSocketHandler::SendPacket(std::unique_ptr &&packet) { assert(packet != nullptr); packet->PrepareToSend(); - this->packet_queue.push_back(std::unique_ptr(packet)); + this->packet_queue.push_back(std::move(packet)); } /** diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index 1d77711b94..419a278587 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -47,7 +47,7 @@ public: virtual NetworkRecvStatus CloseConnection(bool error = true); void CloseSocket(); - virtual void SendPacket(Packet *packet); + virtual void SendPacket(std::unique_ptr &&packet); SendPacketsState SendPackets(bool closing_down = false); virtual std::unique_ptr ReceivePacket(); diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 3df0182937..a5c5483bf2 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -134,10 +134,10 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler() */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode error) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_ERROR); + auto p = std::make_unique(ADMIN_PACKET_SERVER_ERROR); p->Send_uint8(error); - this->SendPacket(p); + this->SendPacket(std::move(p)); std::string error_message = GetString(GetNetworkErrorMsg(error)); @@ -149,7 +149,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode er /** Send the protocol version to the admin. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_PROTOCOL); + auto p = std::make_unique(ADMIN_PACKET_SERVER_PROTOCOL); /* announce the protocol version */ p->Send_uint8(NETWORK_GAME_ADMIN_VERSION); @@ -161,7 +161,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol() } p->Send_bool(false); - this->SendPacket(p); + this->SendPacket(std::move(p)); return this->SendWelcome(); } @@ -169,7 +169,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol() /** Send a welcome message to the admin. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME); + auto p = std::make_unique(ADMIN_PACKET_SERVER_WELCOME); p->Send_string(_settings_client.network.server_name); p->Send_string(GetNetworkRevisionString()); @@ -182,7 +182,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome() p->Send_uint16(Map::SizeX()); p->Send_uint16(Map::SizeY()); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -190,26 +190,26 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome() /** Tell the admin we started a new game. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_NEWGAME); - this->SendPacket(p); + auto p = std::make_unique(ADMIN_PACKET_SERVER_NEWGAME); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } /** Tell the admin we're shutting down. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_SHUTDOWN); - this->SendPacket(p); + auto p = std::make_unique(ADMIN_PACKET_SERVER_SHUTDOWN); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } /** Tell the admin the date. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE); + auto p = std::make_unique(ADMIN_PACKET_SERVER_DATE); p->Send_uint32(TimerGameCalendar::date.base()); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -220,10 +220,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate() */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID client_id) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_JOIN); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CLIENT_JOIN); p->Send_uint32(client_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -238,7 +238,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC /* Only send data when we're a proper client, not just someone trying to query the server. */ if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY; - Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CLIENT_INFO); p->Send_uint32(ci->client_id); p->Send_string(cs == nullptr ? "" : const_cast(cs->client_address).GetHostname()); @@ -247,7 +247,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC p->Send_uint32(ci->join_date.base()); p->Send_uint8 (ci->client_playas); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -259,13 +259,13 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const NetworkClientInfo *ci) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_UPDATE); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CLIENT_UPDATE); p->Send_uint32(ci->client_id); p->Send_string(ci->client_name); p->Send_uint8 (ci->client_playas); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -276,10 +276,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const Networ */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID client_id) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_QUIT); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CLIENT_QUIT); p->Send_uint32(client_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -291,11 +291,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID clien */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID client_id, NetworkErrorCode error) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_ERROR); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CLIENT_ERROR); p->Send_uint32(client_id); p->Send_uint8 (error); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -306,10 +306,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID clie */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID company_id) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_NEW); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_NEW); p->Send_uint8(company_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -320,7 +320,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID comp */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company *c) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_INFO); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_INFO); p->Send_uint8 (c->index); SetDParam(0, c->index); @@ -333,7 +333,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company p->Send_bool (c->is_ai); p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -345,7 +345,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Company *c) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_UPDATE); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_UPDATE); p->Send_uint8 (c->index); SetDParam(0, c->index); @@ -356,7 +356,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa p->Send_bool (NetworkCompanyIsPassworded(c->index)); p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -368,12 +368,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason acrr) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_REMOVE); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_REMOVE); p->Send_uint8(company_id); p->Send_uint8(acrr); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -385,7 +385,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy() /* Get the income. */ Money income = -std::reduce(std::begin(company->yearly_expenses[0]), std::end(company->yearly_expenses[0])); - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_ECONOMY); p->Send_uint8(company->index); @@ -402,7 +402,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy() p->Send_uint16(static_cast(std::min(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum()))); } - this->SendPacket(p); + this->SendPacket(std::move(p)); } @@ -418,7 +418,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats() /* Go through all the companies. */ for (const Company *company : Company::Iterate()) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS); + auto p = std::make_unique(ADMIN_PACKET_SERVER_COMPANY_STATS); /* Send the information. */ p->Send_uint8(company->index); @@ -431,7 +431,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats() p->Send_uint16(company_stats[company->index].num_station[i]); } - this->SendPacket(p); + this->SendPacket(std::move(p)); } return NETWORK_RECV_STATUS_OKAY; @@ -447,7 +447,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats() */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CHAT); p->Send_uint8 (action); p->Send_uint8 (desttype); @@ -455,7 +455,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action p->Send_string(msg); p->Send_uint64(data); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -465,10 +465,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const std::string_view command) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON_END); + auto p = std::make_unique(ADMIN_PACKET_SERVER_RCON_END); p->Send_string(command); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -480,11 +480,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const std::string */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16_t colour, const std::string_view result) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON); + auto p = std::make_unique(ADMIN_PACKET_SERVER_RCON); p->Send_uint16(colour); p->Send_string(result); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -539,11 +539,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const std::string * smaller than COMPAT_MTU. */ if (origin.size() + string.size() + 2 + 3 >= COMPAT_MTU) return NETWORK_RECV_STATUS_OKAY; - Packet *p = new Packet(ADMIN_PACKET_SERVER_CONSOLE); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CONSOLE); p->Send_string(origin); p->Send_string(string); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -554,10 +554,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const std::string */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::string_view json) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_GAMESCRIPT); + auto p = std::make_unique(ADMIN_PACKET_SERVER_GAMESCRIPT); p->Send_string(json); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -565,10 +565,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::str /** Send ping-reply (pong) to admin **/ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32_t d1) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_PONG); + auto p = std::make_unique(ADMIN_PACKET_SERVER_PONG); p->Send_uint32(d1); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -576,7 +576,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32_t d1) /** Send the names of the commands. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames() { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CMD_NAMES); for (uint16_t i = 0; i < CMD_END; i++) { const char *cmdname = GetCommandName(static_cast(i)); @@ -586,9 +586,9 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames() * byte for string '\0' termination and 1 bool "no more data" */ if (!p->CanWriteToPacket(strlen(cmdname) + 5)) { p->Send_bool(false); - this->SendPacket(p); + this->SendPacket(std::move(p)); - p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES); + p = std::make_unique(ADMIN_PACKET_SERVER_CMD_NAMES); } p->Send_bool(true); @@ -598,7 +598,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames() /* Marker to notify the end of the packet has been reached. */ p->Send_bool(false); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -610,7 +610,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames() */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID client_id, const CommandPacket *cp) { - Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_LOGGING); + auto p = std::make_unique(ADMIN_PACKET_SERVER_CMD_LOGGING); p->Send_uint32(client_id); p->Send_uint8 (cp->company); @@ -618,7 +618,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID clien p->Send_buffer(cp->data); p->Send_uint32(cp->frame); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 670b7db47a..b63b8ff4e3 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -331,7 +331,6 @@ static_assert(NETWORK_SERVER_ID_LENGTH == MD5_HASH_BYTES * 2 + 1); /*********** * Sending functions - * DEF_CLIENT_SEND_COMMAND has no parameters ************/ /** Tell the server we would like to join. */ @@ -345,13 +344,13 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin() _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); - Packet *p = new Packet(PACKET_CLIENT_JOIN); + auto p = std::make_unique(PACKET_CLIENT_JOIN); p->Send_string(GetNetworkRevisionString()); p->Send_uint32(_openttd_newgrf_version); p->Send_string(_settings_client.network.client_name); // Client name p->Send_uint8 (_network_join.company); // PlayAs p->Send_uint8 (0); // Used to be language - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -360,8 +359,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendNewGRFsOk() { Debug(net, 9, "Client::SendNewGRFsOk()"); - Packet *p = new Packet(PACKET_CLIENT_NEWGRFS_CHECKED); - my_client->SendPacket(p); + auto p = std::make_unique(PACKET_CLIENT_NEWGRFS_CHECKED); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -373,9 +372,9 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword(const std::st { Debug(net, 9, "Client::SendGamePassword()"); - Packet *p = new Packet(PACKET_CLIENT_GAME_PASSWORD); + auto p = std::make_unique(PACKET_CLIENT_GAME_PASSWORD); p->Send_string(password); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -387,9 +386,9 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword(const std: { Debug(net, 9, "Client::SendCompanyPassword()"); - Packet *p = new Packet(PACKET_CLIENT_COMPANY_PASSWORD); + auto p = std::make_unique(PACKET_CLIENT_COMPANY_PASSWORD); p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -401,8 +400,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap() Debug(net, 9, "Client::status = MAP_WAIT"); my_client->status = STATUS_MAP_WAIT; - Packet *p = new Packet(PACKET_CLIENT_GETMAP); - my_client->SendPacket(p); + auto p = std::make_unique(PACKET_CLIENT_GETMAP); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -414,8 +413,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk() Debug(net, 9, "Client::status = ACTIVE"); my_client->status = STATUS_ACTIVE; - Packet *p = new Packet(PACKET_CLIENT_MAP_OK); - my_client->SendPacket(p); + auto p = std::make_unique(PACKET_CLIENT_MAP_OK); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -424,11 +423,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendAck() { Debug(net, 9, "Client::SendAck()"); - Packet *p = new Packet(PACKET_CLIENT_ACK); + auto p = std::make_unique(PACKET_CLIENT_ACK); p->Send_uint32(_frame_counter); p->Send_uint8 (my_client->token); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -440,10 +439,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke { Debug(net, 9, "Client::SendCommand(): cmd={}", cp->cmd); - Packet *p = new Packet(PACKET_CLIENT_COMMAND); - my_client->NetworkGameSocketHandler::SendCommand(p, cp); + auto p = std::make_unique(PACKET_CLIENT_COMMAND); + my_client->NetworkGameSocketHandler::SendCommand(p.get(), cp); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -452,7 +451,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, { Debug(net, 9, "Client::SendChat(): action={}, type={}, dest={}", action, type, dest); - Packet *p = new Packet(PACKET_CLIENT_CHAT); + auto p = std::make_unique(PACKET_CLIENT_CHAT); p->Send_uint8 (action); p->Send_uint8 (type); @@ -460,7 +459,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, p->Send_string(msg); p->Send_uint64(data); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -469,10 +468,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendError(NetworkErrorCode err { Debug(net, 9, "Client::SendError(): errorno={}", errorno); - Packet *p = new Packet(PACKET_CLIENT_ERROR); + auto p = std::make_unique(PACKET_CLIENT_ERROR); p->Send_uint8(errorno); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -484,10 +483,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword(const std::str { Debug(net, 9, "Client::SendSetPassword()"); - Packet *p = new Packet(PACKET_CLIENT_SET_PASSWORD); + auto p = std::make_unique(PACKET_CLIENT_SET_PASSWORD); p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -499,10 +498,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName(const std::string { Debug(net, 9, "Client::SendSetName()"); - Packet *p = new Packet(PACKET_CLIENT_SET_NAME); + auto p = std::make_unique(PACKET_CLIENT_SET_NAME); p->Send_string(name); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -513,9 +512,9 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit() { Debug(net, 9, "Client::SendSetName()"); - Packet *p = new Packet(PACKET_CLIENT_QUIT); + auto p = std::make_unique(PACKET_CLIENT_QUIT); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -528,10 +527,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pa { Debug(net, 9, "Client::SendRCon()"); - Packet *p = new Packet(PACKET_CLIENT_RCON); + auto p = std::make_unique(PACKET_CLIENT_RCON); p->Send_string(pass); p->Send_string(command); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -544,10 +543,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, co { Debug(net, 9, "Client::SendMove(): company={}", company); - Packet *p = new Packet(PACKET_CLIENT_MOVE); + auto p = std::make_unique(PACKET_CLIENT_MOVE); p->Send_uint8(company); p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); - my_client->SendPacket(p); + my_client->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index e4a8ea8675..a6fd8ad7c4 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -204,7 +204,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type) this->Connect(); - Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_LIST); + auto p = std::make_unique(PACKET_CONTENT_CLIENT_INFO_LIST); p->Send_uint8 ((byte)type); p->Send_uint32(0xffffffff); p->Send_uint8 (1); @@ -221,7 +221,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type) */ - this->SendPacket(p); + this->SendPacket(std::move(p)); } /** @@ -240,14 +240,14 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con * The rest of the packet can be used for the IDs. */ uint p_count = std::min(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t)); - Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU); + auto p = std::make_unique(PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU); p->Send_uint16(p_count); for (uint i = 0; i < p_count; i++) { p->Send_uint32(content_ids[i]); } - this->SendPacket(p); + this->SendPacket(std::move(p)); count -= p_count; content_ids += p_count; } @@ -268,7 +268,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo assert(cv->size() < (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint8_t)) / (sizeof(uint8_t) + sizeof(uint32_t) + (send_md5sum ? MD5_HASH_BYTES : 0))); - Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU); + auto p = std::make_unique(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU); p->Send_uint8((uint8_t)cv->size()); for (const ContentInfo *ci : *cv) { @@ -281,7 +281,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo } } - this->SendPacket(p); + this->SendPacket(std::move(p)); for (ContentInfo *ci : *cv) { bool found = false; @@ -365,14 +365,14 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co * The rest of the packet can be used for the IDs. */ uint p_count = std::min(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t)); - Packet *p = new Packet(PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU); + auto p = std::make_unique(PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU); p->Send_uint16(p_count); for (uint i = 0; i < p_count; i++) { p->Send_uint32(content_ids[i]); } - this->SendPacket(p); + this->SendPacket(std::move(p)); count -= p_count; content_ids += p_count; } diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp index b049376cc9..6ea5ec8e05 100644 --- a/src/network/network_coordinator.cpp +++ b/src/network/network_coordinator.cpp @@ -458,7 +458,7 @@ void ClientNetworkCoordinatorSocketHandler::Register() this->Connect(); - Packet *p = new Packet(PACKET_COORDINATOR_SERVER_REGISTER); + auto p = std::make_unique(PACKET_COORDINATOR_SERVER_REGISTER); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_uint8(_settings_client.network.server_game_type); p->Send_uint16(_settings_client.network.server_port); @@ -470,7 +470,7 @@ void ClientNetworkCoordinatorSocketHandler::Register() p->Send_string(_settings_client.network.server_invite_code_secret); } - this->SendPacket(p); + this->SendPacket(std::move(p)); } /** @@ -480,11 +480,11 @@ void ClientNetworkCoordinatorSocketHandler::SendServerUpdate() { Debug(net, 6, "Sending server update to Game Coordinator"); - Packet *p = new Packet(PACKET_COORDINATOR_SERVER_UPDATE, TCP_MTU); + auto p = std::make_unique(PACKET_COORDINATOR_SERVER_UPDATE, TCP_MTU); p->Send_uint8(NETWORK_COORDINATOR_VERSION); - SerializeNetworkGameInfo(p, GetCurrentNetworkServerGameInfo(), this->next_update.time_since_epoch() != std::chrono::nanoseconds::zero()); + SerializeNetworkGameInfo(p.get(), GetCurrentNetworkServerGameInfo(), this->next_update.time_since_epoch() != std::chrono::nanoseconds::zero()); - this->SendPacket(p); + this->SendPacket(std::move(p)); this->next_update = std::chrono::steady_clock::now() + NETWORK_COORDINATOR_DELAY_BETWEEN_UPDATES; } @@ -498,13 +498,13 @@ void ClientNetworkCoordinatorSocketHandler::GetListing() _network_game_list_version++; - Packet *p = new Packet(PACKET_COORDINATOR_CLIENT_LISTING); + auto p = std::make_unique(PACKET_COORDINATOR_CLIENT_LISTING); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_uint8(NETWORK_GAME_INFO_VERSION); p->Send_string(_openttd_revision); p->Send_uint32(this->newgrf_lookup_table_cursor); - this->SendPacket(p); + this->SendPacket(std::move(p)); } /** @@ -530,11 +530,11 @@ void ClientNetworkCoordinatorSocketHandler::ConnectToServer(const std::string &i this->Connect(); - Packet *p = new Packet(PACKET_COORDINATOR_CLIENT_CONNECT); + auto p = std::make_unique(PACKET_COORDINATOR_CLIENT_CONNECT); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(invite_code); - this->SendPacket(p); + this->SendPacket(std::move(p)); } /** @@ -547,12 +547,12 @@ void ClientNetworkCoordinatorSocketHandler::ConnectFailure(const std::string &to /* Connecter will destroy itself. */ this->game_connecter = nullptr; - Packet *p = new Packet(PACKET_COORDINATOR_SERCLI_CONNECT_FAILED); + auto p = std::make_unique(PACKET_COORDINATOR_SERCLI_CONNECT_FAILED); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(token); p->Send_uint8(tracking_number); - this->SendPacket(p); + this->SendPacket(std::move(p)); /* We do not close the associated connecter here yet, as the * Game Coordinator might have other methods of connecting available. */ @@ -578,10 +578,10 @@ void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &to } else { /* The client informs the Game Coordinator about the success. The server * doesn't have to, as it is implied by the client telling. */ - Packet *p = new Packet(PACKET_COORDINATOR_CLIENT_CONNECTED); + auto p = std::make_unique(PACKET_COORDINATOR_CLIENT_CONNECTED); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(token); - this->SendPacket(p); + this->SendPacket(std::move(p)); /* Find the connecter; it can happen it no longer exist, in cases where * we aborted the connect but the Game Coordinator was already in the @@ -606,12 +606,12 @@ void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &to */ void ClientNetworkCoordinatorSocketHandler::StunResult(const std::string &token, uint8_t family, bool result) { - Packet *p = new Packet(PACKET_COORDINATOR_SERCLI_STUN_RESULT); + auto p = std::make_unique(PACKET_COORDINATOR_SERCLI_STUN_RESULT); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(token); p->Send_uint8(family); p->Send_bool(result); - this->SendPacket(p); + this->SendPacket(std::move(p)); } /** diff --git a/src/network/network_query.cpp b/src/network/network_query.cpp index 0fb128b610..9b0e57b982 100644 --- a/src/network/network_query.cpp +++ b/src/network/network_query.cpp @@ -83,7 +83,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::SendGameInfo() { Debug(net, 9, "Query::SendGameInfo()"); - this->SendPacket(new Packet(PACKET_CLIENT_GAME_INFO)); + this->SendPacket(std::make_unique(PACKET_CLIENT_GAME_INFO)); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 946956e6ee..001e0a7b7c 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -129,7 +129,7 @@ struct PacketWriter : SaveFilter { while (!this->packets.empty()) { bool last_packet = this->packets.front()->GetPacketType() == PACKET_SERVER_MAP_DONE; - socket->SendPacket(this->packets.front().release()); + socket->SendPacket(std::move(this->packets.front())); this->packets.pop_front(); if (last_packet) return true; @@ -315,7 +315,6 @@ static void NetworkHandleCommandQueue(NetworkClientSocket *cs); /*********** * Sending functions - * DEF_SERVER_SEND_COMMAND has parameter: NetworkClientSocket *cs ************/ /** @@ -327,12 +326,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientIn Debug(net, 9, "client[{}] SendClientInfo(): client_id={}", this->client_id, ci->client_id); if (ci->client_id != INVALID_CLIENT_ID) { - Packet *p = new Packet(PACKET_SERVER_CLIENT_INFO); + auto p = std::make_unique(PACKET_SERVER_CLIENT_INFO); p->Send_uint32(ci->client_id); p->Send_uint8 (ci->client_playas); p->Send_string(ci->client_name); - this->SendPacket(p); + this->SendPacket(std::move(p)); } return NETWORK_RECV_STATUS_OKAY; } @@ -342,10 +341,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo() { Debug(net, 9, "client[{}] SendGameInfo()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_GAME_INFO, TCP_MTU); - SerializeNetworkGameInfo(p, GetCurrentNetworkServerGameInfo()); + auto p = std::make_unique(PACKET_SERVER_GAME_INFO, TCP_MTU); + SerializeNetworkGameInfo(p.get(), GetCurrentNetworkServerGameInfo()); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -359,11 +358,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err { Debug(net, 9, "client[{}] SendError(): error={}", this->client_id, error); - Packet *p = new Packet(PACKET_SERVER_ERROR); + auto p = std::make_unique(PACKET_SERVER_ERROR); p->Send_uint8(error); if (!reason.empty()) p->Send_string(reason); - this->SendPacket(p); + this->SendPacket(std::move(p)); StringID strid = GetNetworkErrorMsg(error); @@ -404,7 +403,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck() { Debug(net, 9, "client[{}] SendNewGRFCheck()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU); + auto p = std::make_unique(PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU); const GRFConfig *c; uint grf_count = 0; @@ -414,10 +413,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck() p->Send_uint8 (grf_count); for (c = _grfconfig; c != nullptr; c = c->next) { - if (!HasBit(c->flags, GCF_STATIC)) SerializeGRFIdentifier(p, &c->ident); + if (!HasBit(c->flags, GCF_STATIC)) SerializeGRFIdentifier(p.get(), &c->ident); } - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -434,8 +433,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword() /* Reset 'lag' counters */ this->last_frame = this->last_frame_server = _frame_counter; - Packet *p = new Packet(PACKET_SERVER_NEED_GAME_PASSWORD); - this->SendPacket(p); + auto p = std::make_unique(PACKET_SERVER_NEED_GAME_PASSWORD); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -452,10 +451,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword() /* Reset 'lag' counters */ this->last_frame = this->last_frame_server = _frame_counter; - Packet *p = new Packet(PACKET_SERVER_NEED_COMPANY_PASSWORD); + auto p = std::make_unique(PACKET_SERVER_NEED_COMPANY_PASSWORD); p->Send_uint32(_settings_game.game_creation.generation_seed); p->Send_string(_settings_client.network.network_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -464,8 +463,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome() { Debug(net, 9, "client[{}] SendWelcome()", this->client_id); - Packet *p; - /* Invalid packet when status is AUTH or higher */ if (this->status >= STATUS_AUTHORIZED) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET); @@ -476,11 +473,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome() _network_game_info.clients_on++; - p = new Packet(PACKET_SERVER_WELCOME); + auto p = std::make_unique(PACKET_SERVER_WELCOME); p->Send_uint32(this->client_id); p->Send_uint32(_settings_game.game_creation.generation_seed); p->Send_string(_settings_client.network.network_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); /* Transmit info about all the active clients */ for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) { @@ -498,7 +495,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait() Debug(net, 9, "client[{}] SendWait()", this->client_id); int waiting = 1; // current player getting the map counts as 1 - Packet *p; /* Count how many clients are waiting in the queue, in front of you! */ for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) { @@ -506,9 +502,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait() if (new_cs->GetInfo()->join_date < this->GetInfo()->join_date || (new_cs->GetInfo()->join_date == this->GetInfo()->join_date && new_cs->client_id < this->client_id)) waiting++; } - p = new Packet(PACKET_SERVER_WAIT); + auto p = std::make_unique(PACKET_SERVER_WAIT); p->Send_uint8(waiting); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -556,9 +552,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap() this->savegame = std::make_shared(this); /* Now send the _frame_counter and how many packets are coming */ - Packet *p = new Packet(PACKET_SERVER_MAP_BEGIN); + auto p = std::make_unique(PACKET_SERVER_MAP_BEGIN); p->Send_uint32(_frame_counter); - this->SendPacket(p); + this->SendPacket(std::move(p)); NetworkSyncCommandQueue(this); Debug(net, 9, "client[{}] status = MAP", this->client_id); @@ -599,18 +595,18 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin(ClientID client_id) { Debug(net, 9, "client[{}] SendJoin(): client_id={}", this->client_id, client_id); - Packet *p = new Packet(PACKET_SERVER_JOIN); + auto p = std::make_unique(PACKET_SERVER_JOIN); p->Send_uint32(client_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } /** Tell the client that they may run to a particular frame. */ NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame() { - Packet *p = new Packet(PACKET_SERVER_FRAME); + auto p = std::make_unique(PACKET_SERVER_FRAME); p->Send_uint32(_frame_counter); p->Send_uint32(_frame_counter_max); #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME @@ -626,7 +622,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame() p->Send_uint8(this->last_token); } - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -635,14 +631,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync() { Debug(net, 9, "client[{}] SendSync(), frame_counter={}, sync_seed_1={}", this->client_id, _frame_counter, _sync_seed_1); - Packet *p = new Packet(PACKET_SERVER_SYNC); + auto p = std::make_unique(PACKET_SERVER_SYNC); p->Send_uint32(_frame_counter); p->Send_uint32(_sync_seed_1); #ifdef NETWORK_SEND_DOUBLE_SEED p->Send_uint32(_sync_seed_2); #endif - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -654,13 +650,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke { Debug(net, 9, "client[{}] SendCommand(): cmd={}", this->client_id, cp->cmd); - Packet *p = new Packet(PACKET_SERVER_COMMAND); + auto p = std::make_unique(PACKET_SERVER_COMMAND); - this->NetworkGameSocketHandler::SendCommand(p, cp); + this->NetworkGameSocketHandler::SendCommand(p.get(), cp); p->Send_uint32(cp->frame); p->Send_bool (cp->my_cmd); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -678,7 +674,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY; - Packet *p = new Packet(PACKET_SERVER_CHAT); + auto p = std::make_unique(PACKET_SERVER_CHAT); p->Send_uint8 (action); p->Send_uint32(client_id); @@ -686,7 +682,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, p->Send_string(msg); p->Send_uint64(data); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -703,14 +699,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(const std::st if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY; - Packet *p = new Packet(PACKET_SERVER_EXTERNAL_CHAT); + auto p = std::make_unique(PACKET_SERVER_EXTERNAL_CHAT); p->Send_string(source); p->Send_uint16(colour); p->Send_string(user); p->Send_string(msg); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -723,12 +719,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit(ClientID client_ { Debug(net, 9, "client[{}] SendErrorQuit(): client_id={}, errorno={}", this->client_id, client_id, errorno); - Packet *p = new Packet(PACKET_SERVER_ERROR_QUIT); + auto p = std::make_unique(PACKET_SERVER_ERROR_QUIT); p->Send_uint32(client_id); p->Send_uint8 (errorno); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -740,11 +736,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit(ClientID client_id) { Debug(net, 9, "client[{}] SendQuit(): client_id={}", this->client_id, client_id); - Packet *p = new Packet(PACKET_SERVER_QUIT); + auto p = std::make_unique(PACKET_SERVER_QUIT); p->Send_uint32(client_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -753,8 +749,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown() { Debug(net, 9, "client[{}] SendShutdown()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_SHUTDOWN); - this->SendPacket(p); + auto p = std::make_unique(PACKET_SERVER_SHUTDOWN); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -763,8 +759,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame() { Debug(net, 9, "client[{}] SendNewGame()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_NEWGAME); - this->SendPacket(p); + auto p = std::make_unique(PACKET_SERVER_NEWGAME); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -777,11 +773,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16_t colour { Debug(net, 9, "client[{}] SendRConResult()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_RCON); + auto p = std::make_unique(PACKET_SERVER_RCON); p->Send_uint16(colour); p->Send_string(command); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -794,11 +790,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove(ClientID client_id, C { Debug(net, 9, "client[{}] SendMove(): client_id={}", this->client_id, client_id); - Packet *p = new Packet(PACKET_SERVER_MOVE); + auto p = std::make_unique(PACKET_SERVER_MOVE); p->Send_uint32(client_id); p->Send_uint8(company_id); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -807,11 +803,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate() { Debug(net, 9, "client[{}] SendCompanyUpdate()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_COMPANY_UPDATE); + auto p = std::make_unique(PACKET_SERVER_COMPANY_UPDATE); static_assert(sizeof(_network_company_passworded) <= sizeof(uint16_t)); p->Send_uint16(_network_company_passworded); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } @@ -820,11 +816,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate() { Debug(net, 9, "client[{}] SendConfigUpdate()", this->client_id); - Packet *p = new Packet(PACKET_SERVER_CONFIG_UPDATE); + auto p = std::make_unique(PACKET_SERVER_CONFIG_UPDATE); p->Send_uint8(_settings_client.network.max_companies); p->Send_string(_settings_client.network.server_name); - this->SendPacket(p); + this->SendPacket(std::move(p)); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/network/network_stun.cpp b/src/network/network_stun.cpp index dd394c669b..c606ff0c83 100644 --- a/src/network/network_stun.cpp +++ b/src/network/network_stun.cpp @@ -92,12 +92,12 @@ std::unique_ptr ClientNetworkStunSocketHandler:: stun_handler->Connect(token, family); - Packet *p = new Packet(PACKET_STUN_SERCLI_STUN); + auto p = std::make_unique(PACKET_STUN_SERCLI_STUN); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(token); p->Send_uint8(family); - stun_handler->SendPacket(p); + stun_handler->SendPacket(std::move(p)); return stun_handler; } diff --git a/src/network/network_turn.cpp b/src/network/network_turn.cpp index 7a9bd43fc5..83b1afdd28 100644 --- a/src/network/network_turn.cpp +++ b/src/network/network_turn.cpp @@ -100,11 +100,11 @@ void ClientNetworkTurnSocketHandler::Connect() { auto turn_handler = std::make_unique(token, tracking_number, connection_string); - Packet *p = new Packet(PACKET_TURN_SERCLI_CONNECT); + auto p = std::make_unique(PACKET_TURN_SERCLI_CONNECT); p->Send_uint8(NETWORK_COORDINATOR_VERSION); p->Send_string(ticket); - turn_handler->SendPacket(p); + turn_handler->SendPacket(std::move(p)); return turn_handler; }