Codechange: pass the socket handler that is going to send the packet into the packet

This commit is contained in:
Rubidium 2024-02-04 12:31:56 +01:00 committed by rubidium42
parent 3c488e1eb8
commit 6eff879e49
12 changed files with 91 additions and 90 deletions

View File

@ -38,13 +38,14 @@ Packet::Packet(NetworkSocketHandler *cs, size_t limit, size_t initial_read_size)
/**
* Creates a packet to send
* @param cs The socket handler associated with the socket we are writing to; could be \c nullptr.
* @param type The type of the packet to send
* @param limit The maximum number of bytes the packet may have. Default is COMPAT_MTU.
* Be careful of compatibility with older clients/servers when changing
* the limit as it might break things if the other side is not expecting
* much larger packets than what they support.
*/
Packet::Packet(PacketType type, size_t limit) : pos(0), limit(limit), cs(nullptr)
Packet::Packet(NetworkSocketHandler *cs, PacketType type, size_t limit) : pos(0), limit(limit), cs(cs)
{
/* Allocate space for the the size so we can write that in just before sending the packet. */
this->Send_uint16(0);
@ -57,7 +58,8 @@ Packet::Packet(PacketType type, size_t limit) : pos(0), limit(limit), cs(nullptr
*/
void Packet::PrepareToSend()
{
assert(this->cs == nullptr);
/* Prevent this to be called twice and for packets that have been received. */
assert(this->buffer[0] == 0 && this->buffer[1] == 0);
this->buffer[0] = GB(this->Size(), 0, 8);
this->buffer[1] = GB(this->Size(), 8, 8);
@ -243,7 +245,6 @@ size_t Packet::Size() const
*/
bool Packet::ParsePacketSize()
{
assert(this->cs != nullptr);
size_t size = (size_t)this->buffer[0];
size += (size_t)this->buffer[1] << 8;

View File

@ -53,7 +53,7 @@ private:
public:
Packet(NetworkSocketHandler *cs, size_t limit, size_t initial_read_size = sizeof(PacketSize));
Packet(PacketType type, size_t limit = COMPAT_MTU);
Packet(NetworkSocketHandler *cs, PacketType type, size_t limit = COMPAT_MTU);
/* Sending/writing of packets */
void PrepareToSend();

View File

@ -35,7 +35,7 @@ public:
/* Check if the client is banned. */
for (const auto &entry : _network_ban_list) {
if (address.IsInNetmask(entry)) {
Packet p(Tban_packet);
Packet p(nullptr, Tban_packet);
p.PrepareToSend();
Debug(net, 2, "[{}] Banned ip tried to join ({}), refused", Tsocket::GetName(), entry);
@ -52,7 +52,7 @@ public:
if (!Tsocket::AllowConnection()) {
/* No more clients allowed?
* Send to the client that we are full! */
Packet p(Tfull_packet);
Packet p(nullptr, Tfull_packet);
p.PrepareToSend();
if (p.TransferOut<int>(send, s, 0) < 0) {

View File

@ -134,7 +134,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode error)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_ERROR);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_ERROR);
p->Send_uint8(error);
this->SendPacket(std::move(p));
@ -149,7 +149,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode er
/** Send the protocol version to the admin. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_PROTOCOL);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_PROTOCOL);
/* announce the protocol version */
p->Send_uint8(NETWORK_GAME_ADMIN_VERSION);
@ -169,7 +169,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
/** Send a welcome message to the admin. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_WELCOME);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_WELCOME);
p->Send_string(_settings_client.network.server_name);
p->Send_string(GetNetworkRevisionString());
@ -190,7 +190,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
/** Tell the admin we started a new game. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_NEWGAME);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_NEWGAME);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -198,7 +198,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame()
/** Tell the admin we're shutting down. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_SHUTDOWN);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_SHUTDOWN);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -206,7 +206,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown()
/** Tell the admin the date. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_DATE);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_DATE);
p->Send_uint32(TimerGameCalendar::date.base());
this->SendPacket(std::move(p));
@ -220,7 +220,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID client_id)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CLIENT_JOIN);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CLIENT_JOIN);
p->Send_uint32(client_id);
this->SendPacket(std::move(p));
@ -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;
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CLIENT_INFO);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CLIENT_INFO);
p->Send_uint32(ci->client_id);
p->Send_string(cs == nullptr ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
@ -259,7 +259,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const NetworkClientInfo *ci)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CLIENT_UPDATE);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CLIENT_UPDATE);
p->Send_uint32(ci->client_id);
p->Send_string(ci->client_name);
@ -276,7 +276,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const Networ
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID client_id)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CLIENT_QUIT);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CLIENT_QUIT);
p->Send_uint32(client_id);
this->SendPacket(std::move(p));
@ -291,7 +291,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID clien
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID client_id, NetworkErrorCode error)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CLIENT_ERROR);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CLIENT_ERROR);
p->Send_uint32(client_id);
p->Send_uint8 (error);
@ -306,7 +306,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID clie
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID company_id)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_NEW);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_NEW);
p->Send_uint8(company_id);
this->SendPacket(std::move(p));
@ -320,7 +320,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID comp
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company *c)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_INFO);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_INFO);
p->Send_uint8 (c->index);
SetDParam(0, c->index);
@ -345,7 +345,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Company *c)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_UPDATE);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_UPDATE);
p->Send_uint8 (c->index);
SetDParam(0, c->index);
@ -368,7 +368,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason acrr)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_REMOVE);
p->Send_uint8(company_id);
p->Send_uint8(acrr);
@ -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]));
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
p->Send_uint8(company->index);
@ -418,7 +418,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
/* Go through all the companies. */
for (const Company *company : Company::Iterate()) {
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_COMPANY_STATS);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_STATS);
/* Send the information. */
p->Send_uint8(company->index);
@ -447,7 +447,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CHAT);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CHAT);
p->Send_uint8 (action);
p->Send_uint8 (desttype);
@ -465,7 +465,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const std::string_view command)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_RCON_END);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_RCON_END);
p->Send_string(command);
this->SendPacket(std::move(p));
@ -480,7 +480,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const std::string
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16_t colour, const std::string_view result)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_RCON);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_RCON);
p->Send_uint16(colour);
p->Send_string(result);
@ -539,7 +539,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const std::string
* smaller than COMPAT_MTU. */
if (origin.size() + string.size() + 2 + 3 >= COMPAT_MTU) return NETWORK_RECV_STATUS_OKAY;
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CONSOLE);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CONSOLE);
p->Send_string(origin);
p->Send_string(string);
@ -554,7 +554,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const std::string
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::string_view json)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_GAMESCRIPT);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_GAMESCRIPT);
p->Send_string(json);
this->SendPacket(std::move(p));
@ -565,7 +565,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::str
/** Send ping-reply (pong) to admin **/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32_t d1)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_PONG);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_PONG);
p->Send_uint32(d1);
this->SendPacket(std::move(p));
@ -576,7 +576,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32_t d1)
/** Send the names of the commands. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CMD_NAMES);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CMD_NAMES);
for (uint16_t i = 0; i < CMD_END; i++) {
const char *cmdname = GetCommandName(static_cast<Commands>(i));
@ -588,7 +588,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
p->Send_bool(false);
this->SendPacket(std::move(p));
p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CMD_NAMES);
p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CMD_NAMES);
}
p->Send_bool(true);
@ -610,7 +610,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
*/
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID client_id, const CommandPacket &cp)
{
auto p = std::make_unique<Packet>(ADMIN_PACKET_SERVER_CMD_LOGGING);
auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_CMD_LOGGING);
p->Send_uint32(client_id);
p->Send_uint8 (cp.company);

View File

@ -344,7 +344,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
_network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING;
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
auto p = std::make_unique<Packet>(PACKET_CLIENT_JOIN);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_JOIN);
p->Send_string(GetNetworkRevisionString());
p->Send_uint32(_openttd_newgrf_version);
p->Send_string(_settings_client.network.client_name); // Client name
@ -359,7 +359,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendNewGRFsOk()
{
Debug(net, 9, "Client::SendNewGRFsOk()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_NEWGRFS_CHECKED);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_NEWGRFS_CHECKED);
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -372,7 +372,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword(const std::st
{
Debug(net, 9, "Client::SendGamePassword()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_GAME_PASSWORD);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_GAME_PASSWORD);
p->Send_string(password);
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
@ -386,7 +386,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword(const std:
{
Debug(net, 9, "Client::SendCompanyPassword()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_COMPANY_PASSWORD);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_COMPANY_PASSWORD);
p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
@ -400,7 +400,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap()
Debug(net, 9, "Client::status = MAP_WAIT");
my_client->status = STATUS_MAP_WAIT;
auto p = std::make_unique<Packet>(PACKET_CLIENT_GETMAP);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_GETMAP);
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -413,7 +413,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk()
Debug(net, 9, "Client::status = ACTIVE");
my_client->status = STATUS_ACTIVE;
auto p = std::make_unique<Packet>(PACKET_CLIENT_MAP_OK);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_MAP_OK);
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -423,7 +423,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendAck()
{
Debug(net, 9, "Client::SendAck()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_ACK);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_ACK);
p->Send_uint32(_frame_counter);
p->Send_uint8 (my_client->token);
@ -439,7 +439,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke
{
Debug(net, 9, "Client::SendCommand(): cmd={}", cp.cmd);
auto p = std::make_unique<Packet>(PACKET_CLIENT_COMMAND);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_COMMAND);
my_client->NetworkGameSocketHandler::SendCommand(*p, cp);
my_client->SendPacket(std::move(p));
@ -451,7 +451,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action,
{
Debug(net, 9, "Client::SendChat(): action={}, type={}, dest={}", action, type, dest);
auto p = std::make_unique<Packet>(PACKET_CLIENT_CHAT);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_CHAT);
p->Send_uint8 (action);
p->Send_uint8 (type);
@ -468,7 +468,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendError(NetworkErrorCode err
{
Debug(net, 9, "Client::SendError(): errorno={}", errorno);
auto p = std::make_unique<Packet>(PACKET_CLIENT_ERROR);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_ERROR);
p->Send_uint8(errorno);
my_client->SendPacket(std::move(p));
@ -483,7 +483,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword(const std::str
{
Debug(net, 9, "Client::SendSetPassword()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_SET_PASSWORD);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_SET_PASSWORD);
p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
my_client->SendPacket(std::move(p));
@ -498,7 +498,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName(const std::string
{
Debug(net, 9, "Client::SendSetName()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_SET_NAME);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_SET_NAME);
p->Send_string(name);
my_client->SendPacket(std::move(p));
@ -512,7 +512,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit()
{
Debug(net, 9, "Client::SendQuit()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_QUIT);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_QUIT);
my_client->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
@ -527,7 +527,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pa
{
Debug(net, 9, "Client::SendRCon()");
auto p = std::make_unique<Packet>(PACKET_CLIENT_RCON);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_RCON);
p->Send_string(pass);
p->Send_string(command);
my_client->SendPacket(std::move(p));
@ -543,7 +543,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, co
{
Debug(net, 9, "Client::SendMove(): company={}", company);
auto p = std::make_unique<Packet>(PACKET_CLIENT_MOVE);
auto p = std::make_unique<Packet>(my_client, PACKET_CLIENT_MOVE);
p->Send_uint8(company);
p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed));
my_client->SendPacket(std::move(p));

View File

@ -204,7 +204,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
this->Connect();
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_INFO_LIST);
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_INFO_LIST);
p->Send_uint8 ((byte)type);
p->Send_uint32(0xffffffff);
p->Send_uint8 (1);
@ -240,7 +240,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con
* The rest of the packet can be used for the IDs. */
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU);
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU);
p->Send_uint16(p_count);
for (uint i = 0; i < p_count; i++) {
@ -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)));
auto p = std::make_unique<Packet>(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU);
auto p = std::make_unique<Packet>(this, 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) {
@ -365,7 +365,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
* The rest of the packet can be used for the IDs. */
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU);
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU);
p->Send_uint16(p_count);
for (uint i = 0; i < p_count; i++) {

View File

@ -458,7 +458,7 @@ void ClientNetworkCoordinatorSocketHandler::Register()
this->Connect();
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_SERVER_REGISTER);
auto p = std::make_unique<Packet>(this, 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);
@ -480,7 +480,7 @@ void ClientNetworkCoordinatorSocketHandler::SendServerUpdate()
{
Debug(net, 6, "Sending server update to Game Coordinator");
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_SERVER_UPDATE, TCP_MTU);
auto p = std::make_unique<Packet>(this, 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());
@ -498,7 +498,7 @@ void ClientNetworkCoordinatorSocketHandler::GetListing()
_network_game_list_version++;
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_CLIENT_LISTING);
auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_CLIENT_LISTING);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_uint8(NETWORK_GAME_INFO_VERSION);
p->Send_string(_openttd_revision);
@ -530,7 +530,7 @@ void ClientNetworkCoordinatorSocketHandler::ConnectToServer(const std::string &i
this->Connect();
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_CLIENT_CONNECT);
auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_CLIENT_CONNECT);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(invite_code);
@ -547,7 +547,7 @@ void ClientNetworkCoordinatorSocketHandler::ConnectFailure(const std::string &to
/* Connecter will destroy itself. */
this->game_connecter = nullptr;
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_SERCLI_CONNECT_FAILED);
auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_SERCLI_CONNECT_FAILED);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(token);
p->Send_uint8(tracking_number);
@ -578,7 +578,7 @@ 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. */
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_CLIENT_CONNECTED);
auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_CLIENT_CONNECTED);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(token);
this->SendPacket(std::move(p));
@ -606,7 +606,7 @@ void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &to
*/
void ClientNetworkCoordinatorSocketHandler::StunResult(const std::string &token, uint8_t family, bool result)
{
auto p = std::make_unique<Packet>(PACKET_COORDINATOR_SERCLI_STUN_RESULT);
auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_SERCLI_STUN_RESULT);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(token);
p->Send_uint8(family);

View File

@ -83,7 +83,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::SendGameInfo()
{
Debug(net, 9, "Query::SendGameInfo()");
this->SendPacket(std::make_unique<Packet>(PACKET_CLIENT_GAME_INFO));
this->SendPacket(std::make_unique<Packet>(this, PACKET_CLIENT_GAME_INFO));
return NETWORK_RECV_STATUS_OKAY;
}

View File

@ -143,7 +143,7 @@ struct PacketWriter : SaveFilter {
/* We want to abort the saving when the socket is closed. */
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->current == nullptr) this->current = std::make_unique<Packet>(PACKET_SERVER_MAP_DATA, TCP_MTU);
if (this->current == nullptr) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
byte *bufe = buf + size;
while (buf != bufe) {
@ -152,7 +152,7 @@ struct PacketWriter : SaveFilter {
if (!this->current->CanWriteToPacket(1)) {
this->packets.push_back(std::move(this->current));
if (buf != bufe) this->current = std::make_unique<Packet>(PACKET_SERVER_MAP_DATA, TCP_MTU);
if (buf != bufe) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
}
}
@ -170,10 +170,10 @@ struct PacketWriter : SaveFilter {
if (this->current != nullptr) this->packets.push_back(std::move(this->current));
/* Add a packet stating that this is the end to the queue. */
this->packets.push_back(std::make_unique<Packet>(PACKET_SERVER_MAP_DONE));
this->packets.push_back(std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DONE));
/* Fast-track the size to the client. */
auto p = std::make_unique<Packet>(PACKET_SERVER_MAP_SIZE);
auto p = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_SIZE);
p->Send_uint32((uint32_t)this->total_size);
this->packets.push_front(std::move(p));
}
@ -324,7 +324,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientIn
Debug(net, 9, "client[{}] SendClientInfo(): client_id={}", this->client_id, ci->client_id);
if (ci->client_id != INVALID_CLIENT_ID) {
auto p = std::make_unique<Packet>(PACKET_SERVER_CLIENT_INFO);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CLIENT_INFO);
p->Send_uint32(ci->client_id);
p->Send_uint8 (ci->client_playas);
p->Send_string(ci->client_name);
@ -339,7 +339,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo()
{
Debug(net, 9, "client[{}] SendGameInfo()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_GAME_INFO, TCP_MTU);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_GAME_INFO, TCP_MTU);
SerializeNetworkGameInfo(*p, GetCurrentNetworkServerGameInfo());
this->SendPacket(std::move(p));
@ -356,7 +356,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err
{
Debug(net, 9, "client[{}] SendError(): error={}", this->client_id, error);
auto p = std::make_unique<Packet>(PACKET_SERVER_ERROR);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_ERROR);
p->Send_uint8(error);
if (!reason.empty()) p->Send_string(reason);
@ -401,7 +401,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
{
Debug(net, 9, "client[{}] SendNewGRFCheck()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
const GRFConfig *c;
uint grf_count = 0;
@ -436,7 +436,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
auto p = std::make_unique<Packet>(PACKET_SERVER_NEED_GAME_PASSWORD);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_NEED_GAME_PASSWORD);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -459,7 +459,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
auto p = std::make_unique<Packet>(PACKET_SERVER_NEED_COMPANY_PASSWORD);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_NEED_COMPANY_PASSWORD);
p->Send_uint32(_settings_game.game_creation.generation_seed);
p->Send_string(_settings_client.network.network_id);
this->SendPacket(std::move(p));
@ -481,7 +481,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome()
_network_game_info.clients_on++;
auto p = std::make_unique<Packet>(PACKET_SERVER_WELCOME);
auto p = std::make_unique<Packet>(this, 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);
@ -510,7 +510,7 @@ 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++;
}
auto p = std::make_unique<Packet>(PACKET_SERVER_WAIT);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_WAIT);
p->Send_uint8(waiting);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
@ -560,7 +560,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
this->savegame = std::make_shared<PacketWriter>(this);
/* Now send the _frame_counter and how many packets are coming */
auto p = std::make_unique<Packet>(PACKET_SERVER_MAP_BEGIN);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_MAP_BEGIN);
p->Send_uint32(_frame_counter);
this->SendPacket(std::move(p));
@ -603,7 +603,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin(ClientID client_id)
{
Debug(net, 9, "client[{}] SendJoin(): client_id={}", this->client_id, client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_JOIN);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_JOIN);
p->Send_uint32(client_id);
@ -614,7 +614,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin(ClientID client_id)
/** Tell the client that they may run to a particular frame. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame()
{
auto p = std::make_unique<Packet>(PACKET_SERVER_FRAME);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_FRAME);
p->Send_uint32(_frame_counter);
p->Send_uint32(_frame_counter_max);
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
@ -639,7 +639,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync()
{
Debug(net, 9, "client[{}] SendSync(), frame_counter={}, sync_seed_1={}", this->client_id, _frame_counter, _sync_seed_1);
auto p = std::make_unique<Packet>(PACKET_SERVER_SYNC);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_SYNC);
p->Send_uint32(_frame_counter);
p->Send_uint32(_sync_seed_1);
@ -658,7 +658,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke
{
Debug(net, 9, "client[{}] SendCommand(): cmd={}", this->client_id, cp.cmd);
auto p = std::make_unique<Packet>(PACKET_SERVER_COMMAND);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_COMMAND);
this->NetworkGameSocketHandler::SendCommand(*p, cp);
p->Send_uint32(cp.frame);
@ -682,7 +682,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action,
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
auto p = std::make_unique<Packet>(PACKET_SERVER_CHAT);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CHAT);
p->Send_uint8 (action);
p->Send_uint32(client_id);
@ -707,7 +707,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(const std::st
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
auto p = std::make_unique<Packet>(PACKET_SERVER_EXTERNAL_CHAT);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_EXTERNAL_CHAT);
p->Send_string(source);
p->Send_uint16(colour);
@ -727,7 +727,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit(ClientID client_
{
Debug(net, 9, "client[{}] SendErrorQuit(): client_id={}, errorno={}", this->client_id, client_id, errorno);
auto p = std::make_unique<Packet>(PACKET_SERVER_ERROR_QUIT);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_ERROR_QUIT);
p->Send_uint32(client_id);
p->Send_uint8 (errorno);
@ -744,7 +744,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit(ClientID client_id)
{
Debug(net, 9, "client[{}] SendQuit(): client_id={}", this->client_id, client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_QUIT);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_QUIT);
p->Send_uint32(client_id);
@ -757,7 +757,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown()
{
Debug(net, 9, "client[{}] SendShutdown()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_SHUTDOWN);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_SHUTDOWN);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -767,7 +767,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
{
Debug(net, 9, "client[{}] SendNewGame()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_NEWGAME);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_NEWGAME);
this->SendPacket(std::move(p));
return NETWORK_RECV_STATUS_OKAY;
}
@ -781,7 +781,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16_t colour
{
Debug(net, 9, "client[{}] SendRConResult()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_RCON);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_RCON);
p->Send_uint16(colour);
p->Send_string(command);
@ -798,7 +798,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove(ClientID client_id, C
{
Debug(net, 9, "client[{}] SendMove(): client_id={}", this->client_id, client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_MOVE);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_MOVE);
p->Send_uint32(client_id);
p->Send_uint8(company_id);
@ -811,7 +811,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate()
{
Debug(net, 9, "client[{}] SendCompanyUpdate()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_COMPANY_UPDATE);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_COMPANY_UPDATE);
static_assert(sizeof(_network_company_passworded) <= sizeof(uint16_t));
p->Send_uint16(_network_company_passworded);
@ -824,7 +824,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate()
{
Debug(net, 9, "client[{}] SendConfigUpdate()", this->client_id);
auto p = std::make_unique<Packet>(PACKET_SERVER_CONFIG_UPDATE);
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CONFIG_UPDATE);
p->Send_uint8(_settings_client.network.max_companies);
p->Send_string(_settings_client.network.server_name);

View File

@ -92,7 +92,7 @@ std::unique_ptr<ClientNetworkStunSocketHandler> ClientNetworkStunSocketHandler::
stun_handler->Connect(token, family);
auto p = std::make_unique<Packet>(PACKET_STUN_SERCLI_STUN);
auto p = std::make_unique<Packet>(stun_handler.get(), PACKET_STUN_SERCLI_STUN);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(token);
p->Send_uint8(family);

View File

@ -100,7 +100,7 @@ void ClientNetworkTurnSocketHandler::Connect()
{
auto turn_handler = std::make_unique<ClientNetworkTurnSocketHandler>(token, tracking_number, connection_string);
auto p = std::make_unique<Packet>(PACKET_TURN_SERCLI_CONNECT);
auto p = std::make_unique<Packet>(turn_handler.get(), PACKET_TURN_SERCLI_CONNECT);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
p->Send_string(ticket);

View File

@ -75,7 +75,7 @@ public:
void ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet &, NetworkAddress &client_addr)
{
Packet packet(PACKET_UDP_SERVER_RESPONSE);
Packet packet(this, PACKET_UDP_SERVER_RESPONSE);
this->SendPacket(packet, client_addr);
Debug(net, 7, "Queried from {}", client_addr.GetHostname());
@ -104,7 +104,7 @@ static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
for (NetworkAddress &addr : _broadcast_list) {
Debug(net, 5, "Broadcasting to {}", addr.GetHostname());
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
Packet p(socket, PACKET_UDP_CLIENT_FIND_SERVER);
socket->SendPacket(p, addr, true, true);
}
}