mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use references for handling received TCP packets
parent
794f12dc24
commit
72a44b0df6
|
@ -90,8 +90,8 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
||||||
if (!this->IsConnected()) return SPS_CLOSED;
|
if (!this->IsConnected()) return SPS_CLOSED;
|
||||||
|
|
||||||
while (!this->packet_queue.empty()) {
|
while (!this->packet_queue.empty()) {
|
||||||
Packet *p = this->packet_queue.front().get();
|
Packet &p = *this->packet_queue.front();
|
||||||
ssize_t res = p->TransferOut<int>(send, this->sock, 0);
|
ssize_t res = p.TransferOut<int>(send, this->sock, 0);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
NetworkError err = NetworkError::GetLast();
|
NetworkError err = NetworkError::GetLast();
|
||||||
if (!err.WouldBlock()) {
|
if (!err.WouldBlock()) {
|
||||||
|
@ -111,7 +111,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is this packet sent? */
|
/* Is this packet sent? */
|
||||||
if (p->RemainingBytesToTransfer() == 0) {
|
if (p.RemainingBytesToTransfer() == 0) {
|
||||||
/* Go to the next packet */
|
/* Go to the next packet */
|
||||||
this->packet_queue.pop_front();
|
this->packet_queue.pop_front();
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,12 +136,12 @@ std::unique_ptr<Packet> NetworkTCPSocketHandler::ReceivePacket()
|
||||||
this->packet_recv = std::make_unique<Packet>(this, TCP_MTU);
|
this->packet_recv = std::make_unique<Packet>(this, TCP_MTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet *p = this->packet_recv.get();
|
Packet &p = *this->packet_recv.get();
|
||||||
|
|
||||||
/* Read packet size */
|
/* Read packet size */
|
||||||
if (!p->HasPacketSizeData()) {
|
if (!p.HasPacketSizeData()) {
|
||||||
while (p->RemainingBytesToTransfer() != 0) {
|
while (p.RemainingBytesToTransfer() != 0) {
|
||||||
res = p->TransferIn<int>(recv, this->sock, 0);
|
res = p.TransferIn<int>(recv, this->sock, 0);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
NetworkError err = NetworkError::GetLast();
|
NetworkError err = NetworkError::GetLast();
|
||||||
if (!err.WouldBlock()) {
|
if (!err.WouldBlock()) {
|
||||||
|
@ -161,15 +161,15 @@ std::unique_ptr<Packet> NetworkTCPSocketHandler::ReceivePacket()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the size in the received packet and if not valid, close the connection. */
|
/* Parse the size in the received packet and if not valid, close the connection. */
|
||||||
if (!p->ParsePacketSize()) {
|
if (!p.ParsePacketSize()) {
|
||||||
this->CloseConnection();
|
this->CloseConnection();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read rest of packet */
|
/* Read rest of packet */
|
||||||
while (p->RemainingBytesToTransfer() != 0) {
|
while (p.RemainingBytesToTransfer() != 0) {
|
||||||
res = p->TransferIn<int>(recv, this->sock, 0);
|
res = p.TransferIn<int>(recv, this->sock, 0);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
NetworkError err = NetworkError::GetLast();
|
NetworkError err = NetworkError::GetLast();
|
||||||
if (!err.WouldBlock()) {
|
if (!err.WouldBlock()) {
|
||||||
|
@ -188,7 +188,7 @@ std::unique_ptr<Packet> NetworkTCPSocketHandler::ReceivePacket()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p->PrepareToRead();
|
p.PrepareToRead();
|
||||||
return std::move(this->packet_recv);
|
return std::move(this->packet_recv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool)
|
||||||
* @param p the packet to handle.
|
* @param p the packet to handle.
|
||||||
* @return #NetworkRecvStatus of handling.
|
* @return #NetworkRecvStatus of handling.
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
|
NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet &p)
|
||||||
{
|
{
|
||||||
PacketAdminType type = (PacketAdminType)p->Recv_uint8();
|
PacketAdminType type = (PacketAdminType)p.Recv_uint8();
|
||||||
|
|
||||||
if (this->HasClientQuit()) {
|
if (this->HasClientQuit()) {
|
||||||
Debug(net, 0, "[tcp/admin] Received invalid packet from '{}' ({})", this->admin_name, this->admin_version);
|
Debug(net, 0, "[tcp/admin] Received invalid packet from '{}' ({})", this->admin_name, this->admin_version);
|
||||||
|
@ -110,7 +110,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::ReceivePackets()
|
||||||
{
|
{
|
||||||
std::unique_ptr<Packet> p;
|
std::unique_ptr<Packet> p;
|
||||||
while ((p = this->ReceivePacket()) != nullptr) {
|
while ((p = this->ReceivePacket()) != nullptr) {
|
||||||
NetworkRecvStatus res = this->HandlePacket(p.get());
|
NetworkRecvStatus res = this->HandlePacket(*p);
|
||||||
if (res != NETWORK_RECV_STATUS_OKAY) return res;
|
if (res != NETWORK_RECV_STATUS_OKAY) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,40 +128,40 @@ NetworkRecvStatus NetworkAdminSocketHandler::ReceiveInvalidPacket(PacketAdminTyp
|
||||||
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_JOIN); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_JOIN); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_QUIT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_QUIT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_POLL); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_POLL); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_CHAT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_CHAT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_EXTERNAL_CHAT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_EXTERNAL_CHAT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_RCON); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_RCON); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_GAMESCRIPT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_GAMESCRIPT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_PING); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_PING(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_PING); }
|
||||||
|
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_FULL(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_FULL); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_FULL(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_FULL); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_BANNED(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_BANNED); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_BANNED(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_BANNED); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_ERROR(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_ERROR); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_ERROR(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_ERROR); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PROTOCOL(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PROTOCOL); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PROTOCOL(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PROTOCOL); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_WELCOME(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_WELCOME); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_WELCOME(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_WELCOME); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_NEWGAME(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_NEWGAME); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_NEWGAME(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_NEWGAME); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_SHUTDOWN(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_SHUTDOWN); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_SHUTDOWN(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_SHUTDOWN); }
|
||||||
|
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_DATE(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_DATE); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_DATE(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_DATE); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_JOIN(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_JOIN); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_JOIN(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_JOIN); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_INFO); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_INFO(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_INFO); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_UPDATE(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_UPDATE); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_UPDATE(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_UPDATE); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_QUIT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_QUIT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_QUIT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_QUIT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_ERROR(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_ERROR); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CLIENT_ERROR(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CLIENT_ERROR); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_NEW(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_NEW); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_NEW(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_NEW); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_INFO); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_INFO(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_INFO); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_UPDATE); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_UPDATE); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_REMOVE(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_REMOVE); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_REMOVE(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_REMOVE); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_ECONOMY(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_ECONOMY); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_ECONOMY(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_ECONOMY); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_STATS(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_STATS); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_COMPANY_STATS(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_COMPANY_STATS); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CHAT(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CHAT); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CHAT(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CHAT); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CONSOLE(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CONSOLE); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CONSOLE(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CONSOLE); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_NAMES(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_NAMES); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_NAMES(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_NAMES); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_LOGGING(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_LOGGING); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_LOGGING(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_LOGGING); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON_END(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON_END); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON_END(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON_END); }
|
||||||
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PONG(Packet *) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PONG); }
|
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PONG(Packet &) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PONG); }
|
||||||
|
|
|
@ -125,14 +125,14 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification to the server that this admin is quitting.
|
* Notification to the server that this admin is quitting.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet):
|
* Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet):
|
||||||
|
@ -141,7 +141,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Poll the server for certain updates, an invalid poll (e.g. not existent id) gets silently dropped:
|
* Poll the server for certain updates, an invalid poll (e.g. not existent id) gets silently dropped:
|
||||||
|
@ -152,7 +152,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send chat as the server:
|
* Send chat as the server:
|
||||||
|
@ -163,7 +163,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send chat from the external source:
|
* Send chat from the external source:
|
||||||
|
@ -174,7 +174,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command on the servers console:
|
* Execute a command on the servers console:
|
||||||
|
@ -182,7 +182,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a JSON string to the current active GameScript.
|
* Send a JSON string to the current active GameScript.
|
||||||
|
@ -190,7 +190,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ping the server, requiring the server to reply with a pong packet.
|
* Ping the server, requiring the server to reply with a pong packet.
|
||||||
|
@ -198,21 +198,21 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
|
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server is full (connection gets closed).
|
* The server is full (connection gets closed).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The source IP address is banned (connection gets closed).
|
* The source IP address is banned (connection gets closed).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An error was caused by this admin connection (connection gets closed).
|
* An error was caused by this admin connection (connection gets closed).
|
||||||
|
@ -220,7 +220,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inform a just joined admin about the protocol specifics:
|
* Inform a just joined admin about the protocol specifics:
|
||||||
|
@ -231,7 +231,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Welcome a connected admin to the game:
|
* Welcome a connected admin to the game:
|
||||||
|
@ -247,21 +247,21 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification about a newgame.
|
* Notification about a newgame.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification about the server shutting down.
|
* Notification about the server shutting down.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the current date of the game:
|
* Send the current date of the game:
|
||||||
|
@ -269,7 +269,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_DATE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_DATE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification of a new client:
|
* Notification of a new client:
|
||||||
|
@ -277,7 +277,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client information of a specific client:
|
* Client information of a specific client:
|
||||||
|
@ -290,7 +290,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client update details on a specific client (e.g. after rename or move):
|
* Client update details on a specific client (e.g. after rename or move):
|
||||||
|
@ -300,7 +300,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification about a client leaving the game.
|
* Notification about a client leaving the game.
|
||||||
|
@ -308,7 +308,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification about a client error (and thus the clients disconnection).
|
* Notification about a client error (and thus the clients disconnection).
|
||||||
|
@ -317,7 +317,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification of a new company:
|
* Notification of a new company:
|
||||||
|
@ -325,7 +325,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Company information on a specific company:
|
* Company information on a specific company:
|
||||||
|
@ -339,7 +339,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Company information of a specific company:
|
* Company information of a specific company:
|
||||||
|
@ -356,7 +356,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification about a removed company (e.g. due to bankruptcy).
|
* Notification about a removed company (e.g. due to bankruptcy).
|
||||||
|
@ -365,7 +365,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Economy update of a specific company:
|
* Economy update of a specific company:
|
||||||
|
@ -383,7 +383,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Company statistics on stations and vehicles:
|
* Company statistics on stations and vehicles:
|
||||||
|
@ -401,7 +401,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send chat from the game into the admin network:
|
* Send chat from the game into the admin network:
|
||||||
|
@ -413,7 +413,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Result of an rcon command:
|
* Result of an rcon command:
|
||||||
|
@ -422,7 +422,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send what would be printed on the server's console also into the admin network.
|
* Send what would be printed on the server's console also into the admin network.
|
||||||
|
@ -431,7 +431,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send DoCommand names to the bot upon request only.
|
* Send DoCommand names to the bot upon request only.
|
||||||
|
@ -450,7 +450,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send incoming command packets to the admin network.
|
* Send incoming command packets to the admin network.
|
||||||
|
@ -470,7 +470,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a ping-reply (pong) to the admin that sent us the ping packet.
|
* Send a ping-reply (pong) to the admin that sent us the ping packet.
|
||||||
|
@ -478,7 +478,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_PONG(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_PONG(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the admin connection that the rcon command has finished.
|
* Notify the admin connection that the rcon command has finished.
|
||||||
|
@ -486,9 +486,9 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return The state the network should have.
|
* @return The state the network should have.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_RCON_END(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_RCON_END(Packet &p);
|
||||||
|
|
||||||
NetworkRecvStatus HandlePacket(Packet *p);
|
NetworkRecvStatus HandlePacket(Packet &p);
|
||||||
public:
|
public:
|
||||||
NetworkRecvStatus CloseConnection(bool error = true) override;
|
NetworkRecvStatus CloseConnection(bool error = true) override;
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,9 @@ std::optional<std::string> ContentInfo::GetTextfile(TextfileType type) const
|
||||||
* @param p the packet to handle
|
* @param p the packet to handle
|
||||||
* @return true if we should immediately handle further packets, false otherwise
|
* @return true if we should immediately handle further packets, false otherwise
|
||||||
*/
|
*/
|
||||||
bool NetworkContentSocketHandler::HandlePacket(Packet *p)
|
bool NetworkContentSocketHandler::HandlePacket(Packet &p)
|
||||||
{
|
{
|
||||||
PacketContentType type = (PacketContentType)p->Recv_uint8();
|
PacketContentType type = (PacketContentType)p.Recv_uint8();
|
||||||
|
|
||||||
switch (this->HasClientQuit() ? PACKET_CONTENT_END : type) {
|
switch (this->HasClientQuit() ? PACKET_CONTENT_END : type) {
|
||||||
case PACKET_CONTENT_CLIENT_INFO_LIST: return this->Receive_CLIENT_INFO_LIST(p);
|
case PACKET_CONTENT_CLIENT_INFO_LIST: return this->Receive_CLIENT_INFO_LIST(p);
|
||||||
|
@ -150,7 +150,7 @@ bool NetworkContentSocketHandler::ReceivePackets()
|
||||||
static const int MAX_PACKETS_TO_RECEIVE = 42;
|
static const int MAX_PACKETS_TO_RECEIVE = 42;
|
||||||
int i = MAX_PACKETS_TO_RECEIVE;
|
int i = MAX_PACKETS_TO_RECEIVE;
|
||||||
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
||||||
bool cont = this->HandlePacket(p.get());
|
bool cont = this->HandlePacket(*p);
|
||||||
if (!cont) return true;
|
if (!cont) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +169,13 @@ bool NetworkContentSocketHandler::ReceiveInvalidPacket(PacketContentType type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_LIST); }
|
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_LIST); }
|
||||||
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_ID(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_ID); }
|
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_ID(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_ID); }
|
||||||
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID); }
|
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID); }
|
||||||
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5); }
|
bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5); }
|
||||||
bool NetworkContentSocketHandler::Receive_SERVER_INFO(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_INFO); }
|
bool NetworkContentSocketHandler::Receive_SERVER_INFO(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_INFO); }
|
||||||
bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_CONTENT); }
|
bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_CONTENT); }
|
||||||
bool NetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_CONTENT); }
|
bool NetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet &) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_CONTENT); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to get the subdirectory a #ContentInfo is located in.
|
* Helper to get the subdirectory a #ContentInfo is located in.
|
||||||
|
|
|
@ -34,7 +34,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
|
virtual bool Receive_CLIENT_INFO_LIST(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client requesting a list of content info:
|
* Client requesting a list of content info:
|
||||||
|
@ -43,7 +43,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_INFO_ID(Packet *p);
|
virtual bool Receive_CLIENT_INFO_ID(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client requesting a list of content info based on an external
|
* Client requesting a list of content info based on an external
|
||||||
|
@ -57,7 +57,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
|
virtual bool Receive_CLIENT_INFO_EXTID(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client requesting a list of content info based on an external
|
* Client requesting a list of content info based on an external
|
||||||
|
@ -72,7 +72,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
|
virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server sending list of content info:
|
* Server sending list of content info:
|
||||||
|
@ -90,7 +90,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERVER_INFO(Packet *p);
|
virtual bool Receive_SERVER_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client requesting the actual content:
|
* Client requesting the actual content:
|
||||||
|
@ -99,7 +99,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_CONTENT(Packet *p);
|
virtual bool Receive_CLIENT_CONTENT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server sending list of content info:
|
* Server sending list of content info:
|
||||||
|
@ -111,9 +111,9 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERVER_CONTENT(Packet *p);
|
virtual bool Receive_SERVER_CONTENT(Packet &p);
|
||||||
|
|
||||||
bool HandlePacket(Packet *p);
|
bool HandlePacket(Packet &p);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Create a new cs socket handler for a given cs
|
* Create a new cs socket handler for a given cs
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
* @param p The packet to handle.
|
* @param p The packet to handle.
|
||||||
* @return True iff we should immediately handle further packets.
|
* @return True iff we should immediately handle further packets.
|
||||||
*/
|
*/
|
||||||
bool NetworkCoordinatorSocketHandler::HandlePacket(Packet *p)
|
bool NetworkCoordinatorSocketHandler::HandlePacket(Packet &p)
|
||||||
{
|
{
|
||||||
PacketCoordinatorType type = (PacketCoordinatorType)p->Recv_uint8();
|
PacketCoordinatorType type = (PacketCoordinatorType)p.Recv_uint8();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PACKET_COORDINATOR_GC_ERROR: return this->Receive_GC_ERROR(p);
|
case PACKET_COORDINATOR_GC_ERROR: return this->Receive_GC_ERROR(p);
|
||||||
|
@ -68,7 +68,7 @@ bool NetworkCoordinatorSocketHandler::ReceivePackets()
|
||||||
static const int MAX_PACKETS_TO_RECEIVE = 42;
|
static const int MAX_PACKETS_TO_RECEIVE = 42;
|
||||||
int i = MAX_PACKETS_TO_RECEIVE;
|
int i = MAX_PACKETS_TO_RECEIVE;
|
||||||
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
||||||
bool cont = this->HandlePacket(p.get());
|
bool cont = this->HandlePacket(*p);
|
||||||
if (!cont) return true;
|
if (!cont) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,20 +86,20 @@ bool NetworkCoordinatorSocketHandler::ReceiveInvalidPacket(PacketCoordinatorType
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_ERROR); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_ERROR); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_SERVER_REGISTER(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_REGISTER); }
|
bool NetworkCoordinatorSocketHandler::Receive_SERVER_REGISTER(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_REGISTER); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_REGISTER_ACK); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_REGISTER_ACK); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_SERVER_UPDATE(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_UPDATE); }
|
bool NetworkCoordinatorSocketHandler::Receive_SERVER_UPDATE(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_UPDATE); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_LISTING(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_LISTING); }
|
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_LISTING(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_LISTING); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_LISTING); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_LISTING); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_CONNECT(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_CONNECT); }
|
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_CONNECT(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_CONNECT); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_CONNECTING); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_CONNECTING); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_SERCLI_CONNECT_FAILED(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERCLI_CONNECT_FAILED); }
|
bool NetworkCoordinatorSocketHandler::Receive_SERCLI_CONNECT_FAILED(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERCLI_CONNECT_FAILED); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_CONNECT_FAILED(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_CONNECT_FAILED); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_CONNECT_FAILED(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_CONNECT_FAILED); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_CONNECTED(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_CONNECTED); }
|
bool NetworkCoordinatorSocketHandler::Receive_CLIENT_CONNECTED(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_CLIENT_CONNECTED); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_DIRECT_CONNECT(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_DIRECT_CONNECT); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_DIRECT_CONNECT(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_DIRECT_CONNECT); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_STUN_REQUEST(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_STUN_REQUEST); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_STUN_REQUEST(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_STUN_REQUEST); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_SERCLI_STUN_RESULT(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERCLI_STUN_RESULT); }
|
bool NetworkCoordinatorSocketHandler::Receive_SERCLI_STUN_RESULT(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERCLI_STUN_RESULT); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_STUN_CONNECT); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_STUN_CONNECT); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_NEWGRF_LOOKUP); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_NEWGRF_LOOKUP); }
|
||||||
bool NetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet *) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_TURN_CONNECT); }
|
bool NetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet &) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_GC_TURN_CONNECT); }
|
||||||
|
|
|
@ -83,7 +83,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_ERROR(Packet *p);
|
virtual bool Receive_GC_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server is starting a multiplayer game and wants to let the
|
* Server is starting a multiplayer game and wants to let the
|
||||||
|
@ -98,7 +98,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERVER_REGISTER(Packet *p);
|
virtual bool Receive_SERVER_REGISTER(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator acknowledges the registration.
|
* Game Coordinator acknowledges the registration.
|
||||||
|
@ -110,7 +110,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_REGISTER_ACK(Packet *p);
|
virtual bool Receive_GC_REGISTER_ACK(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an update of the current state of the server to the Game Coordinator.
|
* Send an update of the current state of the server to the Game Coordinator.
|
||||||
|
@ -121,7 +121,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERVER_UPDATE(Packet *p);
|
virtual bool Receive_SERVER_UPDATE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client requests a list of all public servers.
|
* Client requests a list of all public servers.
|
||||||
|
@ -134,7 +134,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_LISTING(Packet *p);
|
virtual bool Receive_CLIENT_LISTING(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator replies with a list of all public servers. Multiple
|
* Game Coordinator replies with a list of all public servers. Multiple
|
||||||
|
@ -149,7 +149,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_LISTING(Packet *p);
|
virtual bool Receive_GC_LISTING(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client wants to connect to a Server.
|
* Client wants to connect to a Server.
|
||||||
|
@ -160,7 +160,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_CONNECT(Packet *p);
|
virtual bool Receive_CLIENT_CONNECT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator informs the Client under what token it will start the
|
* Game Coordinator informs the Client under what token it will start the
|
||||||
|
@ -172,7 +172,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_CONNECTING(Packet *p);
|
virtual bool Receive_GC_CONNECTING(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client or Server failed to connect to the remote side.
|
* Client or Server failed to connect to the remote side.
|
||||||
|
@ -184,7 +184,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERCLI_CONNECT_FAILED(Packet *p);
|
virtual bool Receive_SERCLI_CONNECT_FAILED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator informs the Client that it failed to find a way to
|
* Game Coordinator informs the Client that it failed to find a way to
|
||||||
|
@ -196,7 +196,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_CONNECT_FAILED(Packet *p);
|
virtual bool Receive_GC_CONNECT_FAILED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client informs the Game Coordinator the connection with the Server is
|
* Client informs the Game Coordinator the connection with the Server is
|
||||||
|
@ -208,7 +208,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_CLIENT_CONNECTED(Packet *p);
|
virtual bool Receive_CLIENT_CONNECTED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator requests that the Client makes a direct connection to
|
* Game Coordinator requests that the Client makes a direct connection to
|
||||||
|
@ -222,7 +222,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_DIRECT_CONNECT(Packet *p);
|
virtual bool Receive_GC_DIRECT_CONNECT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator requests the client/server to do a STUN request to the
|
* Game Coordinator requests the client/server to do a STUN request to the
|
||||||
|
@ -237,7 +237,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_STUN_REQUEST(Packet *p);
|
virtual bool Receive_GC_STUN_REQUEST(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client/server informs the Game Coordinator the result of a STUN request.
|
* Client/server informs the Game Coordinator the result of a STUN request.
|
||||||
|
@ -250,7 +250,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERCLI_STUN_RESULT(Packet *p);
|
virtual bool Receive_SERCLI_STUN_RESULT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator informs the client/server of its STUN peer (the host:ip
|
* Game Coordinator informs the client/server of its STUN peer (the host:ip
|
||||||
|
@ -266,7 +266,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_STUN_CONNECT(Packet *p);
|
virtual bool Receive_GC_STUN_CONNECT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator informs the client of updates for the NewGRFs lookup table
|
* Game Coordinator informs the client of updates for the NewGRFs lookup table
|
||||||
|
@ -289,7 +289,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_NEWGRF_LOOKUP(Packet *p);
|
virtual bool Receive_GC_NEWGRF_LOOKUP(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Coordinator requests that we make a connection to the indicated
|
* Game Coordinator requests that we make a connection to the indicated
|
||||||
|
@ -303,9 +303,9 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_GC_TURN_CONNECT(Packet *p);
|
virtual bool Receive_GC_TURN_CONNECT(Packet &p);
|
||||||
|
|
||||||
bool HandlePacket(Packet *p);
|
bool HandlePacket(Packet &p);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Create a new cs socket handler for a given cs.
|
* Create a new cs socket handler for a given cs.
|
||||||
|
|
|
@ -61,9 +61,9 @@ NetworkRecvStatus NetworkGameSocketHandler::CloseConnection(bool)
|
||||||
* @param p the packet to handle
|
* @param p the packet to handle
|
||||||
* @return #NetworkRecvStatus of handling.
|
* @return #NetworkRecvStatus of handling.
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
|
NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet &p)
|
||||||
{
|
{
|
||||||
PacketGameType type = (PacketGameType)p->Recv_uint8();
|
PacketGameType type = (PacketGameType)p.Recv_uint8();
|
||||||
|
|
||||||
if (this->HasClientQuit()) {
|
if (this->HasClientQuit()) {
|
||||||
Debug(net, 0, "[tcp/game] Received invalid packet from client {}", this->client_id);
|
Debug(net, 0, "[tcp/game] Received invalid packet from client {}", this->client_id);
|
||||||
|
@ -137,7 +137,7 @@ NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets()
|
||||||
{
|
{
|
||||||
std::unique_ptr<Packet> p;
|
std::unique_ptr<Packet> p;
|
||||||
while ((p = this->ReceivePacket()) != nullptr) {
|
while ((p = this->ReceivePacket()) != nullptr) {
|
||||||
NetworkRecvStatus res = HandlePacket(p.get());
|
NetworkRecvStatus res = HandlePacket(*p);
|
||||||
if (res != NETWORK_RECV_STATUS_OKAY) return res;
|
if (res != NETWORK_RECV_STATUS_OKAY) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,50 +155,50 @@ NetworkRecvStatus NetworkGameSocketHandler::ReceiveInvalidPacket(PacketGameType
|
||||||
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_FULL); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_FULL); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_BANNED); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_BANNED); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_JOIN); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_JOIN); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_INFO); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_INFO); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_GAME_INFO); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_GAME_INFO); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_GAME_PASSWORD); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_GAME_PASSWORD); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_COMPANY_PASSWORD); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_COMPANY_PASSWORD); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_PASSWORD); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_PASSWORD); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_PASSWORD); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_PASSWORD); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_WELCOME); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_WELCOME); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GETMAP); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GETMAP); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_WAIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_WAIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_BEGIN); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_BEGIN); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_SIZE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_SIZE); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DATA); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DATA); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DONE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DONE); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MAP_OK); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MAP_OK); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_JOIN); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_JOIN); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_FRAME); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_FRAME); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_SYNC); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_SYNC); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ACK); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ACK); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMMAND); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMMAND); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMMAND); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMMAND); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_CHAT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_CHAT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHAT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHAT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_EXTERNAL_CHAT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_EXTERNAL_CHAT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_PASSWORD); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_PASSWORD); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_NAME); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_NAME); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_QUIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_QUIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEWGAME); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEWGAME); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_RCON); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_RCON); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_RCON); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_RCON); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHECK_NEWGRFS); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHECK_NEWGRFS); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_NEWGRFS_CHECKED); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_NEWGRFS_CHECKED); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_MOVE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_MOVE); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet &) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); }
|
||||||
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
|
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet &) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
|
||||||
|
|
||||||
void NetworkGameSocketHandler::DeferDeletion()
|
void NetworkGameSocketHandler::DeferDeletion()
|
||||||
{
|
{
|
||||||
|
|
|
@ -164,13 +164,13 @@ protected:
|
||||||
* Notification that the server is full.
|
* Notification that the server is full.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification that the client trying to join is banned.
|
* Notification that the client trying to join is banned.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to join the server:
|
* Try to join the server:
|
||||||
|
@ -180,27 +180,27 @@ protected:
|
||||||
* uint8_t ID of the clients Language.
|
* uint8_t ID of the clients Language.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client made an error:
|
* The client made an error:
|
||||||
* uint8_t Error code caused (see NetworkErrorCode).
|
* uint8_t Error code caused (see NetworkErrorCode).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request game information.
|
* Request game information.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends information about the game.
|
* Sends information about the game.
|
||||||
* Serialized NetworkGameInfo. See game_info.h for details.
|
* Serialized NetworkGameInfo. See game_info.h for details.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send information about a client:
|
* Send information about a client:
|
||||||
|
@ -209,13 +209,13 @@ protected:
|
||||||
* string Name of the client.
|
* string Name of the client.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indication to the client that the server needs a game password.
|
* Indication to the client that the server needs a game password.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indication to the client that the server needs a company password:
|
* Indication to the client that the server needs a company password:
|
||||||
|
@ -223,7 +223,7 @@ protected:
|
||||||
* string Network ID of the server.
|
* string Network ID of the server.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a password to the server to authorize:
|
* Send a password to the server to authorize:
|
||||||
|
@ -231,7 +231,7 @@ protected:
|
||||||
* string The password.
|
* string The password.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a password to the server to authorize
|
* Send a password to the server to authorize
|
||||||
|
@ -239,7 +239,7 @@ protected:
|
||||||
* string The password.
|
* string The password.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client is joined and ready to receive their map:
|
* The client is joined and ready to receive their map:
|
||||||
|
@ -248,61 +248,61 @@ protected:
|
||||||
* string Network ID of the server.
|
* string Network ID of the server.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the map from the server.
|
* Request the map from the server.
|
||||||
* uint32_t NewGRF version (release versions of OpenTTD only).
|
* uint32_t NewGRF version (release versions of OpenTTD only).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification that another client is currently receiving the map:
|
* Notification that another client is currently receiving the map:
|
||||||
* uint8_t Number of clients waiting in front of you.
|
* uint8_t Number of clients waiting in front of you.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends that the server will begin with sending the map to the client:
|
* Sends that the server will begin with sending the map to the client:
|
||||||
* uint32_t Current frame.
|
* uint32_t Current frame.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the size of the map to the client.
|
* Sends the size of the map to the client.
|
||||||
* uint32_t Size of the (compressed) map (in bytes).
|
* uint32_t Size of the (compressed) map (in bytes).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the data of the map to the client:
|
* Sends the data of the map to the client:
|
||||||
* Contains a part of the map (until max size of packet).
|
* Contains a part of the map (until max size of packet).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends that all data of the map are sent to the client:
|
* Sends that all data of the map are sent to the client:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the server that we are done receiving/loading the map.
|
* Tell the server that we are done receiving/loading the map.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:
|
* A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:
|
||||||
* uint32_t ID of the client that just joined the game.
|
* uint32_t ID of the client that just joined the game.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the current frame counter to the client:
|
* Sends the current frame counter to the client:
|
||||||
|
@ -313,7 +313,7 @@ protected:
|
||||||
* uint8_t Random token to validate the client is actually listening (only occasionally present).
|
* uint8_t Random token to validate the client is actually listening (only occasionally present).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sync-check to the client:
|
* Sends a sync-check to the client:
|
||||||
|
@ -322,7 +322,7 @@ protected:
|
||||||
* uint32_t General seed 2 (dependent on compile settings, not default).
|
* uint32_t General seed 2 (dependent on compile settings, not default).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the server we are done with this frame:
|
* Tell the server we are done with this frame:
|
||||||
|
@ -330,7 +330,7 @@ protected:
|
||||||
* uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet.
|
* uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a DoCommand to the Server:
|
* Send a DoCommand to the Server:
|
||||||
|
@ -341,7 +341,7 @@ protected:
|
||||||
* uint8_t ID of the callback.
|
* uint8_t ID of the callback.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a DoCommand to the client:
|
* Sends a DoCommand to the client:
|
||||||
|
@ -353,7 +353,7 @@ protected:
|
||||||
* uint32_t Frame of execution.
|
* uint32_t Frame of execution.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat-packet to the server:
|
* Sends a chat-packet to the server:
|
||||||
|
@ -364,7 +364,7 @@ protected:
|
||||||
* uint64_t data (used e.g. for 'give money' actions).
|
* uint64_t data (used e.g. for 'give money' actions).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat-packet to the client:
|
* Sends a chat-packet to the client:
|
||||||
|
@ -374,7 +374,7 @@ protected:
|
||||||
* uint64_t data (used e.g. for 'give money' actions).
|
* uint64_t data (used e.g. for 'give money' actions).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat-packet for external source to the client:
|
* Sends a chat-packet for external source to the client:
|
||||||
|
@ -384,41 +384,41 @@ protected:
|
||||||
* string Message (max NETWORK_CHAT_LENGTH).
|
* string Message (max NETWORK_CHAT_LENGTH).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the password for the clients current company:
|
* Set the password for the clients current company:
|
||||||
* string The password.
|
* string The password.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the client a new name:
|
* Gives the client a new name:
|
||||||
* string New name of the client.
|
* string New name of the client.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client is quitting the game.
|
* The client is quitting the game.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client made an error and is quitting the game.
|
* The client made an error and is quitting the game.
|
||||||
* uint8_t Error of the code caused (see NetworkErrorCode).
|
* uint8_t Error of the code caused (see NetworkErrorCode).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification that a client left the game:
|
* Notification that a client left the game:
|
||||||
* uint32_t ID of the client.
|
* uint32_t ID of the client.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inform all clients that one client made an error and thus has quit/been disconnected:
|
* Inform all clients that one client made an error and thus has quit/been disconnected:
|
||||||
|
@ -426,19 +426,19 @@ protected:
|
||||||
* uint8_t Code of the error caused (see NetworkErrorCode).
|
* uint8_t Code of the error caused (see NetworkErrorCode).
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let the clients know that the server is closing.
|
* Let the clients know that the server is closing.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let the clients know that the server is loading a new map.
|
* Let the clients know that the server is loading a new map.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the result of an issues RCon command back to the client:
|
* Send the result of an issues RCon command back to the client:
|
||||||
|
@ -446,7 +446,7 @@ protected:
|
||||||
* string Output of the RCon command
|
* string Output of the RCon command
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an RCon command to the server:
|
* Send an RCon command to the server:
|
||||||
|
@ -454,7 +454,7 @@ protected:
|
||||||
* string Command to be executed.
|
* string Command to be executed.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends information about all used GRFs to the client:
|
* Sends information about all used GRFs to the client:
|
||||||
|
@ -463,13 +463,13 @@ protected:
|
||||||
* 16 * uint8_t MD5 checksum of the GRF
|
* 16 * uint8_t MD5 checksum of the GRF
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the server that we have the required GRFs
|
* Tell the server that we have the required GRFs
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a client from one company into another:
|
* Move a client from one company into another:
|
||||||
|
@ -477,7 +477,7 @@ protected:
|
||||||
* uint8_t ID of the new company.
|
* uint8_t ID of the new company.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the server to move this client into another company:
|
* Request the server to move this client into another company:
|
||||||
|
@ -485,14 +485,14 @@ protected:
|
||||||
* string Password, if the company is password protected.
|
* string Password, if the company is password protected.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p);
|
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the clients knowledge of which company is password protected:
|
* Update the clients knowledge of which company is password protected:
|
||||||
* uint16_t Bitwise representation of each company
|
* uint16_t Bitwise representation of each company
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the clients knowledge of the max settings:
|
* Update the clients knowledge of the max settings:
|
||||||
|
@ -500,9 +500,9 @@ protected:
|
||||||
* uint8_t Maximum number of spectators allowed.
|
* uint8_t Maximum number of spectators allowed.
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
*/
|
*/
|
||||||
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
|
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet &p);
|
||||||
|
|
||||||
NetworkRecvStatus HandlePacket(Packet *p);
|
NetworkRecvStatus HandlePacket(Packet &p);
|
||||||
|
|
||||||
NetworkGameSocketHandler(SOCKET s);
|
NetworkGameSocketHandler(SOCKET s);
|
||||||
public:
|
public:
|
||||||
|
@ -542,8 +542,8 @@ public:
|
||||||
|
|
||||||
NetworkRecvStatus ReceivePackets();
|
NetworkRecvStatus ReceivePackets();
|
||||||
|
|
||||||
const char *ReceiveCommand(Packet *p, CommandPacket *cp);
|
const char *ReceiveCommand(Packet &p, CommandPacket *cp);
|
||||||
void SendCommand(Packet *p, const CommandPacket *cp);
|
void SendCommand(Packet &p, const CommandPacket *cp);
|
||||||
|
|
||||||
bool IsPendingDeletion() const { return this->is_pending_deletion; }
|
bool IsPendingDeletion() const { return this->is_pending_deletion; }
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,4 @@ bool NetworkStunSocketHandler::ReceiveInvalidPacket(PacketStunType type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkStunSocketHandler::Receive_SERCLI_STUN(Packet *) { return this->ReceiveInvalidPacket(PACKET_STUN_SERCLI_STUN); }
|
bool NetworkStunSocketHandler::Receive_SERCLI_STUN(Packet &) { return this->ReceiveInvalidPacket(PACKET_STUN_SERCLI_STUN); }
|
||||||
|
|
|
@ -39,7 +39,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERCLI_STUN(Packet *p);
|
virtual bool Receive_SERCLI_STUN(Packet &p);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
* @param p the packet to handle
|
* @param p the packet to handle
|
||||||
* @return true if we should immediately handle further packets, false otherwise
|
* @return true if we should immediately handle further packets, false otherwise
|
||||||
*/
|
*/
|
||||||
bool NetworkTurnSocketHandler::HandlePacket(Packet *p)
|
bool NetworkTurnSocketHandler::HandlePacket(Packet &p)
|
||||||
{
|
{
|
||||||
PacketTurnType type = (PacketTurnType)p->Recv_uint8();
|
PacketTurnType type = (PacketTurnType)p.Recv_uint8();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PACKET_TURN_TURN_ERROR: return this->Receive_TURN_ERROR(p);
|
case PACKET_TURN_TURN_ERROR: return this->Receive_TURN_ERROR(p);
|
||||||
|
@ -47,7 +47,7 @@ bool NetworkTurnSocketHandler::ReceivePackets()
|
||||||
static const int MAX_PACKETS_TO_RECEIVE = 4;
|
static const int MAX_PACKETS_TO_RECEIVE = 4;
|
||||||
int i = MAX_PACKETS_TO_RECEIVE;
|
int i = MAX_PACKETS_TO_RECEIVE;
|
||||||
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
|
||||||
bool cont = this->HandlePacket(p.get());
|
bool cont = this->HandlePacket(*p);
|
||||||
if (!cont) return true;
|
if (!cont) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,6 @@ bool NetworkTurnSocketHandler::ReceiveInvalidPacket(PacketTurnType type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkTurnSocketHandler::Receive_TURN_ERROR(Packet *) { return this->ReceiveInvalidPacket(PACKET_TURN_TURN_ERROR); }
|
bool NetworkTurnSocketHandler::Receive_TURN_ERROR(Packet &) { return this->ReceiveInvalidPacket(PACKET_TURN_TURN_ERROR); }
|
||||||
bool NetworkTurnSocketHandler::Receive_SERCLI_CONNECT(Packet *) { return this->ReceiveInvalidPacket(PACKET_TURN_SERCLI_CONNECT); }
|
bool NetworkTurnSocketHandler::Receive_SERCLI_CONNECT(Packet &) { return this->ReceiveInvalidPacket(PACKET_TURN_SERCLI_CONNECT); }
|
||||||
bool NetworkTurnSocketHandler::Receive_TURN_CONNECTED(Packet *) { return this->ReceiveInvalidPacket(PACKET_TURN_TURN_CONNECTED); }
|
bool NetworkTurnSocketHandler::Receive_TURN_CONNECTED(Packet &) { return this->ReceiveInvalidPacket(PACKET_TURN_TURN_CONNECTED); }
|
||||||
|
|
|
@ -38,7 +38,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_TURN_ERROR(Packet *p);
|
virtual bool Receive_TURN_ERROR(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client or servers wants to connect to the TURN server (on request by
|
* Client or servers wants to connect to the TURN server (on request by
|
||||||
|
@ -50,7 +50,7 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_SERCLI_CONNECT(Packet *p);
|
virtual bool Receive_SERCLI_CONNECT(Packet &p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN server has connected client and server together and will now relay
|
* TURN server has connected client and server together and will now relay
|
||||||
|
@ -62,9 +62,9 @@ protected:
|
||||||
* @param p The packet that was just received.
|
* @param p The packet that was just received.
|
||||||
* @return True upon success, otherwise false.
|
* @return True upon success, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool Receive_TURN_CONNECTED(Packet *p);
|
virtual bool Receive_TURN_CONNECTED(Packet &p);
|
||||||
|
|
||||||
bool HandlePacket(Packet *p);
|
bool HandlePacket(Packet &p);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Create a new cs socket handler for a given cs.
|
* Create a new cs socket handler for a given cs.
|
||||||
|
|
|
@ -489,11 +489,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16_t colour, con
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
std::string command = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
std::string command = p.Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
||||||
|
|
||||||
Debug(net, 3, "[admin] Rcon command from '{}' ({}): {}", this->admin_name, this->admin_version, command);
|
Debug(net, 3, "[admin] Rcon command from '{}' ({}): {}", this->admin_name, this->admin_version, command);
|
||||||
|
|
||||||
|
@ -503,11 +503,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
|
||||||
return this->SendRconEnd(command);
|
return this->SendRconEnd(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
std::string json = p->Recv_string(NETWORK_GAMESCRIPT_JSON_LENGTH);
|
std::string json = p.Recv_string(NETWORK_GAMESCRIPT_JSON_LENGTH);
|
||||||
|
|
||||||
Debug(net, 6, "[admin] GameScript JSON from '{}' ({}): {}", this->admin_name, this->admin_version, json);
|
Debug(net, 6, "[admin] GameScript JSON from '{}' ({}): {}", this->admin_name, this->admin_version, json);
|
||||||
|
|
||||||
|
@ -515,11 +515,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Pack
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
uint32_t d1 = p->Recv_uint32();
|
uint32_t d1 = p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 6, "[admin] Ping from '{}' ({}): {}", this->admin_name, this->admin_version, d1);
|
Debug(net, 6, "[admin] Ping from '{}' ({}): {}", this->admin_name, this->admin_version, d1);
|
||||||
|
|
||||||
|
@ -627,11 +627,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID clien
|
||||||
* Receiving functions
|
* Receiving functions
|
||||||
************/
|
************/
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status != ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
|
|
||||||
if (_settings_client.network.admin_password.empty() ||
|
if (_settings_client.network.admin_password.empty() ||
|
||||||
_settings_client.network.admin_password.compare(password) != 0) {
|
_settings_client.network.admin_password.compare(password) != 0) {
|
||||||
|
@ -639,8 +639,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
||||||
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->admin_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
this->admin_name = p.Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
||||||
this->admin_version = p->Recv_string(NETWORK_REVISION_LENGTH);
|
this->admin_version = p.Recv_string(NETWORK_REVISION_LENGTH);
|
||||||
|
|
||||||
if (this->admin_name.empty() || this->admin_version.empty()) {
|
if (this->admin_name.empty() || this->admin_version.empty()) {
|
||||||
/* no name or version supplied */
|
/* no name or version supplied */
|
||||||
|
@ -654,18 +654,18 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
||||||
return this->SendProtocol();
|
return this->SendProtocol();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet &)
|
||||||
{
|
{
|
||||||
/* The admin is leaving nothing else to do */
|
/* The admin is leaving nothing else to do */
|
||||||
return this->CloseConnection();
|
return this->CloseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
AdminUpdateType type = (AdminUpdateType)p->Recv_uint16();
|
AdminUpdateType type = (AdminUpdateType)p.Recv_uint16();
|
||||||
AdminUpdateFrequency freq = (AdminUpdateFrequency)p->Recv_uint16();
|
AdminUpdateFrequency freq = (AdminUpdateFrequency)p.Recv_uint16();
|
||||||
|
|
||||||
if (type >= ADMIN_UPDATE_END || (_admin_update_type_frequencies[type] & freq) != freq) {
|
if (type >= ADMIN_UPDATE_END || (_admin_update_type_frequencies[type] & freq) != freq) {
|
||||||
/* The server does not know of this UpdateType. */
|
/* The server does not know of this UpdateType. */
|
||||||
|
@ -680,12 +680,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENC
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
AdminUpdateType type = (AdminUpdateType)p->Recv_uint8();
|
AdminUpdateType type = (AdminUpdateType)p.Recv_uint8();
|
||||||
uint32_t d1 = p->Recv_uint32();
|
uint32_t d1 = p.Recv_uint32();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ADMIN_UPDATE_DATE:
|
case ADMIN_UPDATE_DATE:
|
||||||
|
@ -746,15 +746,15 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
NetworkAction action = (NetworkAction)p->Recv_uint8();
|
NetworkAction action = (NetworkAction)p.Recv_uint8();
|
||||||
DestType desttype = (DestType)p->Recv_uint8();
|
DestType desttype = (DestType)p.Recv_uint8();
|
||||||
int dest = p->Recv_uint32();
|
int dest = p.Recv_uint32();
|
||||||
|
|
||||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case NETWORK_ACTION_CHAT:
|
case NETWORK_ACTION_CHAT:
|
||||||
|
@ -772,14 +772,14 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet *p)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
std::string source = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string source = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
TextColour colour = (TextColour)p->Recv_uint16();
|
TextColour colour = (TextColour)p.Recv_uint16();
|
||||||
std::string user = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string user = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
|
|
||||||
if (!IsValidConsoleColour(colour)) {
|
if (!IsValidConsoleColour(colour)) {
|
||||||
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16_t)colour, source, user, msg, this->admin_name, this->admin_version);
|
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16_t)colour, source, user, msg, this->admin_name, this->admin_version);
|
||||||
|
|
|
@ -24,15 +24,15 @@ extern NetworkAdminSocketPool _networkadminsocket_pool;
|
||||||
/** Class for handling the server side of the game connection. */
|
/** Class for handling the server side of the game connection. */
|
||||||
class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
|
class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
|
||||||
protected:
|
protected:
|
||||||
NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_JOIN(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_QUIT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_POLL(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_POLL(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_CHAT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_RCON(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_RCON(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_ADMIN_PING(Packet *p) override;
|
NetworkRecvStatus Receive_ADMIN_PING(Packet &p) override;
|
||||||
|
|
||||||
NetworkRecvStatus SendProtocol();
|
NetworkRecvStatus SendProtocol();
|
||||||
NetworkRecvStatus SendPong(uint32_t d1);
|
NetworkRecvStatus SendPong(uint32_t d1);
|
||||||
|
|
|
@ -81,19 +81,19 @@ struct PacketReader : LoadFilter {
|
||||||
* Add a packet to this buffer.
|
* Add a packet to this buffer.
|
||||||
* @param p The packet to add.
|
* @param p The packet to add.
|
||||||
*/
|
*/
|
||||||
void AddPacket(Packet *p)
|
void AddPacket(Packet &p)
|
||||||
{
|
{
|
||||||
assert(this->read_bytes == 0);
|
assert(this->read_bytes == 0);
|
||||||
p->TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
|
p.TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
|
||||||
|
|
||||||
/* Did everything fit in the current chunk, then we're done. */
|
/* Did everything fit in the current chunk, then we're done. */
|
||||||
if (p->RemainingBytesToTransfer() == 0) return;
|
if (p.RemainingBytesToTransfer() == 0) return;
|
||||||
|
|
||||||
/* Allocate a new chunk and add the remaining data. */
|
/* Allocate a new chunk and add the remaining data. */
|
||||||
this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
|
this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
|
||||||
this->bufe = this->buf + CHUNK;
|
this->bufe = this->buf + CHUNK;
|
||||||
|
|
||||||
p->TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
|
p.TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Read(byte *rbuf, size_t size) override
|
size_t Read(byte *rbuf, size_t size) override
|
||||||
|
@ -440,7 +440,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke
|
||||||
Debug(net, 9, "Client::SendCommand(): cmd={}", cp->cmd);
|
Debug(net, 9, "Client::SendCommand(): cmd={}", cp->cmd);
|
||||||
|
|
||||||
auto p = std::make_unique<Packet>(PACKET_CLIENT_COMMAND);
|
auto p = std::make_unique<Packet>(PACKET_CLIENT_COMMAND);
|
||||||
my_client->NetworkGameSocketHandler::SendCommand(p.get(), cp);
|
my_client->NetworkGameSocketHandler::SendCommand(*p, cp);
|
||||||
|
|
||||||
my_client->SendPacket(std::move(p));
|
my_client->SendPacket(std::move(p));
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
@ -562,12 +562,11 @@ bool ClientNetworkGameSocketHandler::IsConnected()
|
||||||
|
|
||||||
/***********
|
/***********
|
||||||
* Receiving functions
|
* Receiving functions
|
||||||
* DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
|
|
||||||
************/
|
************/
|
||||||
|
|
||||||
extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<struct LoadFilter> lf);
|
extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<struct LoadFilter> lf);
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Client::Receive_SERVER_FULL()");
|
Debug(net, 9, "Client::Receive_SERVER_FULL()");
|
||||||
|
|
||||||
|
@ -577,7 +576,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *)
|
||||||
return NETWORK_RECV_STATUS_SERVER_FULL;
|
return NETWORK_RECV_STATUS_SERVER_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Client::Receive_SERVER_BANNED()");
|
Debug(net, 9, "Client::Receive_SERVER_BANNED()");
|
||||||
|
|
||||||
|
@ -590,15 +589,15 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *
|
||||||
/* This packet contains info about the client (playas and name)
|
/* This packet contains info about the client (playas and name)
|
||||||
* as client we save this in NetworkClientInfo, linked via 'client_id'
|
* as client we save this in NetworkClientInfo, linked via 'client_id'
|
||||||
* which is always an unique number on a server. */
|
* which is always an unique number on a server. */
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet &p)
|
||||||
{
|
{
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
CompanyID playas = (CompanyID)p->Recv_uint8();
|
CompanyID playas = (CompanyID)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_CLIENT_INFO(): client_id={}, playas={}", client_id, playas);
|
Debug(net, 9, "Client::Receive_SERVER_CLIENT_INFO(): client_id={}, playas={}", client_id, playas);
|
||||||
|
|
||||||
std::string name = p->Recv_string(NETWORK_NAME_LENGTH);
|
std::string name = p.Recv_string(NETWORK_NAME_LENGTH);
|
||||||
|
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
||||||
|
@ -648,7 +647,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Pac
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet &p)
|
||||||
{
|
{
|
||||||
static const StringID network_error_strings[] = {
|
static const StringID network_error_strings[] = {
|
||||||
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_GENERAL
|
STR_NETWORK_ERROR_LOSTCONNECTION, // NETWORK_ERROR_GENERAL
|
||||||
|
@ -675,15 +674,15 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
|
||||||
};
|
};
|
||||||
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
|
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
|
||||||
|
|
||||||
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
|
NetworkErrorCode error = (NetworkErrorCode)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_ERROR(): error={}", error);
|
Debug(net, 9, "Client::Receive_SERVER_ERROR(): error={}", error);
|
||||||
|
|
||||||
StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
|
StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
|
||||||
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
|
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
|
||||||
/* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
|
/* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
|
||||||
if (error == NETWORK_ERROR_KICKED && p->CanReadFromPacket(1)) {
|
if (error == NETWORK_ERROR_KICKED && p.CanReadFromPacket(1)) {
|
||||||
SetDParamStr(0, p->Recv_string(NETWORK_CHAT_LENGTH));
|
SetDParamStr(0, p.Recv_string(NETWORK_CHAT_LENGTH));
|
||||||
ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
|
ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
|
||||||
} else {
|
} else {
|
||||||
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
|
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
|
||||||
|
@ -695,11 +694,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
|
||||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
uint grf_count = p->Recv_uint8();
|
uint grf_count = p.Recv_uint8();
|
||||||
NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;
|
NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_CHECK_NEWGRFS(): grf_count={}", grf_count);
|
Debug(net, 9, "Client::Receive_SERVER_CHECK_NEWGRFS(): grf_count={}", grf_count);
|
||||||
|
@ -707,7 +706,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(P
|
||||||
/* Check all GRFs */
|
/* Check all GRFs */
|
||||||
for (; grf_count > 0; grf_count--) {
|
for (; grf_count > 0; grf_count--) {
|
||||||
GRFIdentifier c;
|
GRFIdentifier c;
|
||||||
DeserializeGRFIdentifier(*p, c);
|
DeserializeGRFIdentifier(p, c);
|
||||||
|
|
||||||
/* Check whether we know this GRF */
|
/* Check whether we know this GRF */
|
||||||
const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, &c.md5sum);
|
const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, &c.md5sum);
|
||||||
|
@ -728,7 +727,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(P
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet &)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
Debug(net, 9, "Client::status = AUTH_GAME");
|
Debug(net, 9, "Client::status = AUTH_GAME");
|
||||||
|
@ -745,7 +744,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSW
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_COMPANY) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_COMPANY) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
Debug(net, 9, "Client::status = AUTH_COMPANY");
|
Debug(net, 9, "Client::status = AUTH_COMPANY");
|
||||||
|
@ -753,8 +752,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PA
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_NEED_COMPANY_PASSWORD()");
|
Debug(net, 9, "Client::Receive_SERVER_NEED_COMPANY_PASSWORD()");
|
||||||
|
|
||||||
_password_game_seed = p->Recv_uint32();
|
_password_game_seed = p.Recv_uint32();
|
||||||
_password_server_id = p->Recv_string(NETWORK_SERVER_ID_LENGTH);
|
_password_server_id = p.Recv_string(NETWORK_SERVER_ID_LENGTH);
|
||||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
if (!_network_join.company_password.empty()) {
|
if (!_network_join.company_password.empty()) {
|
||||||
|
@ -766,25 +765,25 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PA
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
Debug(net, 9, "Client::status = AUTHORIZED");
|
Debug(net, 9, "Client::status = AUTHORIZED");
|
||||||
this->status = STATUS_AUTHORIZED;
|
this->status = STATUS_AUTHORIZED;
|
||||||
|
|
||||||
_network_own_client_id = (ClientID)p->Recv_uint32();
|
_network_own_client_id = (ClientID)p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_WELCOME(): client_id={}", _network_own_client_id);
|
Debug(net, 9, "Client::Receive_SERVER_WELCOME(): client_id={}", _network_own_client_id);
|
||||||
|
|
||||||
/* Initialize the password hash salting variables, even if they were previously. */
|
/* Initialize the password hash salting variables, even if they were previously. */
|
||||||
_password_game_seed = p->Recv_uint32();
|
_password_game_seed = p.Recv_uint32();
|
||||||
_password_server_id = p->Recv_string(NETWORK_SERVER_ID_LENGTH);
|
_password_server_id = p.Recv_string(NETWORK_SERVER_ID_LENGTH);
|
||||||
|
|
||||||
/* Start receiving the map */
|
/* Start receiving the map */
|
||||||
return SendGetMap();
|
return SendGetMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet &p)
|
||||||
{
|
{
|
||||||
/* We set the internal wait state when requesting the map. */
|
/* We set the internal wait state when requesting the map. */
|
||||||
if (this->status != STATUS_MAP_WAIT) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_MAP_WAIT) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
@ -794,13 +793,13 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p)
|
||||||
/* But... only now we set the join status to waiting, instead of requesting. */
|
/* But... only now we set the join status to waiting, instead of requesting. */
|
||||||
Debug(net, 9, "Client::join_status = WAITING");
|
Debug(net, 9, "Client::join_status = WAITING");
|
||||||
_network_join_status = NETWORK_JOIN_STATUS_WAITING;
|
_network_join_status = NETWORK_JOIN_STATUS_WAITING;
|
||||||
_network_join_waiting = p->Recv_uint8();
|
_network_join_waiting = p.Recv_uint8();
|
||||||
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
||||||
|
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
Debug(net, 9, "Client::status = MAP");
|
Debug(net, 9, "Client::status = MAP");
|
||||||
|
@ -810,7 +809,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe
|
||||||
|
|
||||||
this->savegame = std::make_shared<PacketReader>();
|
this->savegame = std::make_shared<PacketReader>();
|
||||||
|
|
||||||
_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
|
_frame_counter = _frame_counter_server = _frame_counter_max = p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_MAP_BEGIN(): frame_counter={}", _frame_counter);
|
Debug(net, 9, "Client::Receive_SERVER_MAP_BEGIN(): frame_counter={}", _frame_counter);
|
||||||
|
|
||||||
|
@ -824,12 +823,12 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
_network_join_bytes_total = p->Recv_uint32();
|
_network_join_bytes_total = p.Recv_uint32();
|
||||||
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_MAP_SIZE(): bytes_total={}", _network_join_bytes_total);
|
Debug(net, 9, "Client::Receive_SERVER_MAP_SIZE(): bytes_total={}", _network_join_bytes_total);
|
||||||
|
@ -837,7 +836,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
@ -851,7 +850,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet &)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
@ -907,29 +906,29 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
_frame_counter_server = p->Recv_uint32();
|
_frame_counter_server = p.Recv_uint32();
|
||||||
_frame_counter_max = p->Recv_uint32();
|
_frame_counter_max = p.Recv_uint32();
|
||||||
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
|
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
|
||||||
/* Test if the server supports this option
|
/* Test if the server supports this option
|
||||||
* and if we are at the frame the server is */
|
* and if we are at the frame the server is */
|
||||||
#ifdef NETWORK_SEND_DOUBLE_SEED
|
#ifdef NETWORK_SEND_DOUBLE_SEED
|
||||||
if (p->CanReadFromPacket(sizeof(uint32_t) + sizeof(uint32_t))) {
|
if (p.CanReadFromPacket(sizeof(uint32_t) + sizeof(uint32_t))) {
|
||||||
#else
|
#else
|
||||||
if (p->CanReadFromPacket(sizeof(uint32_t))) {
|
if (p.CanReadFromPacket(sizeof(uint32_t))) {
|
||||||
#endif
|
#endif
|
||||||
_sync_frame = _frame_counter_server;
|
_sync_frame = _frame_counter_server;
|
||||||
_sync_seed_1 = p->Recv_uint32();
|
_sync_seed_1 = p.Recv_uint32();
|
||||||
#ifdef NETWORK_SEND_DOUBLE_SEED
|
#ifdef NETWORK_SEND_DOUBLE_SEED
|
||||||
_sync_seed_2 = p->Recv_uint32();
|
_sync_seed_2 = p.Recv_uint32();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Receive the token. */
|
/* Receive the token. */
|
||||||
if (p->CanReadFromPacket(sizeof(uint8_t))) this->token = p->Recv_uint8();
|
if (p.CanReadFromPacket(sizeof(uint8_t))) this->token = p.Recv_uint8();
|
||||||
|
|
||||||
/* Let the server know that we received this frame correctly
|
/* Let the server know that we received this frame correctly
|
||||||
* We do this only once per day, to save some bandwidth ;) */
|
* We do this only once per day, to save some bandwidth ;) */
|
||||||
|
@ -942,14 +941,14 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
_sync_frame = p->Recv_uint32();
|
_sync_frame = p.Recv_uint32();
|
||||||
_sync_seed_1 = p->Recv_uint32();
|
_sync_seed_1 = p.Recv_uint32();
|
||||||
#ifdef NETWORK_SEND_DOUBLE_SEED
|
#ifdef NETWORK_SEND_DOUBLE_SEED
|
||||||
_sync_seed_2 = p->Recv_uint32();
|
_sync_seed_2 = p.Recv_uint32();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_SYNC(): sync_frame={}, sync_seed_1={}", _sync_frame, _sync_seed_1);
|
Debug(net, 9, "Client::Receive_SERVER_SYNC(): sync_frame={}, sync_seed_1={}", _sync_frame, _sync_seed_1);
|
||||||
|
@ -957,14 +956,14 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
CommandPacket cp;
|
CommandPacket cp;
|
||||||
const char *err = this->ReceiveCommand(p, &cp);
|
const char *err = this->ReceiveCommand(p, &cp);
|
||||||
cp.frame = p->Recv_uint32();
|
cp.frame = p.Recv_uint32();
|
||||||
cp.my_cmd = p->Recv_bool();
|
cp.my_cmd = p.Recv_bool();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_COMMAND(): cmd={}, frame={}", cp.cmd, cp.frame);
|
Debug(net, 9, "Client::Receive_SERVER_COMMAND(): cmd={}, frame={}", cp.cmd, cp.frame);
|
||||||
|
|
||||||
|
@ -978,18 +977,18 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
const NetworkClientInfo *ci = nullptr, *ci_to;
|
const NetworkClientInfo *ci = nullptr, *ci_to;
|
||||||
|
|
||||||
NetworkAction action = (NetworkAction)p->Recv_uint8();
|
NetworkAction action = (NetworkAction)p.Recv_uint8();
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
bool self_send = p->Recv_bool();
|
bool self_send = p.Recv_bool();
|
||||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
int64_t data = p->Recv_uint64();
|
int64_t data = p.Recv_uint64();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_CHAT(): action={}, client_id={}, self_send={}", action, client_id, self_send);
|
Debug(net, 9, "Client::Receive_SERVER_CHAT(): action={}, client_id={}, self_send={}", action, client_id, self_send);
|
||||||
|
|
||||||
|
@ -1029,14 +1028,14 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
std::string source = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string source = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
TextColour colour = (TextColour)p->Recv_uint16();
|
TextColour colour = (TextColour)p.Recv_uint16();
|
||||||
std::string user = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string user = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_EXTERNAL_CHAT(): source={}", source);
|
Debug(net, 9, "Client::Receive_SERVER_EXTERNAL_CHAT(): source={}", source);
|
||||||
|
|
||||||
|
@ -1047,17 +1046,17 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(P
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_ERROR_QUIT(): client_id={}", client_id);
|
Debug(net, 9, "Client::Receive_SERVER_ERROR_QUIT(): client_id={}", client_id);
|
||||||
|
|
||||||
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
|
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
|
||||||
if (ci != nullptr) {
|
if (ci != nullptr) {
|
||||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
|
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", GetNetworkErrorMsg((NetworkErrorCode)p.Recv_uint8()));
|
||||||
delete ci;
|
delete ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1066,11 +1065,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Pack
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_QUIT(): client_id={}", client_id);
|
Debug(net, 9, "Client::Receive_SERVER_QUIT(): client_id={}", client_id);
|
||||||
|
|
||||||
|
@ -1088,11 +1087,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_JOIN(): client_id={}", client_id);
|
Debug(net, 9, "Client::Receive_SERVER_JOIN(): client_id={}", client_id);
|
||||||
|
|
||||||
|
@ -1106,7 +1105,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Client::Receive_SERVER_SHUTDOWN()");
|
Debug(net, 9, "Client::Receive_SERVER_SHUTDOWN()");
|
||||||
|
|
||||||
|
@ -1121,7 +1120,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet
|
||||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet *)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Client::Receive_SERVER_NEWGAME()");
|
Debug(net, 9, "Client::Receive_SERVER_NEWGAME()");
|
||||||
|
|
||||||
|
@ -1140,29 +1139,29 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet
|
||||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_RCON()");
|
Debug(net, 9, "Client::Receive_SERVER_RCON()");
|
||||||
|
|
||||||
TextColour colour_code = (TextColour)p->Recv_uint16();
|
TextColour colour_code = (TextColour)p.Recv_uint16();
|
||||||
if (!IsValidConsoleColour(colour_code)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (!IsValidConsoleColour(colour_code)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
std::string rcon_out = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
std::string rcon_out = p.Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
||||||
|
|
||||||
IConsolePrint(colour_code, rcon_out);
|
IConsolePrint(colour_code, rcon_out);
|
||||||
|
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
/* Nothing more in this packet... */
|
/* Nothing more in this packet... */
|
||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p.Recv_uint32();
|
||||||
CompanyID company_id = (CompanyID)p->Recv_uint8();
|
CompanyID company_id = (CompanyID)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_MOVE(): client_id={}, comapny_id={}", client_id, company_id);
|
Debug(net, 9, "Client::Receive_SERVER_MOVE(): client_id={}, comapny_id={}", client_id, company_id);
|
||||||
|
|
||||||
|
@ -1186,12 +1185,12 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
_network_server_max_companies = p->Recv_uint8();
|
_network_server_max_companies = p.Recv_uint8();
|
||||||
_network_server_name = p->Recv_string(NETWORK_NAME_LENGTH);
|
_network_server_name = p.Recv_string(NETWORK_NAME_LENGTH);
|
||||||
SetWindowClassesDirty(WC_CLIENT_LIST);
|
SetWindowClassesDirty(WC_CLIENT_LIST);
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_CONFIG_UPDATE(): max_companies={}", _network_server_max_companies);
|
Debug(net, 9, "Client::Receive_SERVER_CONFIG_UPDATE(): max_companies={}", _network_server_max_companies);
|
||||||
|
@ -1199,12 +1198,12 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(P
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
static_assert(sizeof(_network_company_passworded) <= sizeof(uint16_t));
|
static_assert(sizeof(_network_company_passworded) <= sizeof(uint16_t));
|
||||||
_network_company_passworded = p->Recv_uint16();
|
_network_company_passworded = p.Recv_uint16();
|
||||||
SetWindowClassesDirty(WC_COMPANY);
|
SetWindowClassesDirty(WC_COMPANY);
|
||||||
|
|
||||||
Debug(net, 9, "Client::Receive_SERVER_COMPANY_UPDATE()");
|
Debug(net, 9, "Client::Receive_SERVER_COMPANY_UPDATE()");
|
||||||
|
|
|
@ -40,33 +40,33 @@ protected:
|
||||||
friend void NetworkClose(bool close_admins);
|
friend void NetworkClose(bool close_admins);
|
||||||
static ClientNetworkGameSocketHandler *my_client; ///< This is us!
|
static ClientNetworkGameSocketHandler *my_client; ///< This is us!
|
||||||
|
|
||||||
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_FULL(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_BANNED(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_ERROR(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_WAIT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_JOIN(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_FRAME(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_SYNC(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_COMMAND(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_CHAT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_QUIT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_RCON(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_MOVE(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet &p) override;
|
||||||
|
|
||||||
static NetworkRecvStatus SendNewGRFsOk();
|
static NetworkRecvStatus SendNewGRFsOk();
|
||||||
static NetworkRecvStatus SendGetMap();
|
static NetworkRecvStatus SendGetMap();
|
||||||
|
|
|
@ -424,16 +424,16 @@ void NetworkDistributeCommands()
|
||||||
* @param cp the struct to write the data to.
|
* @param cp the struct to write the data to.
|
||||||
* @return an error message. When nullptr there has been no error.
|
* @return an error message. When nullptr there has been no error.
|
||||||
*/
|
*/
|
||||||
const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *cp)
|
const char *NetworkGameSocketHandler::ReceiveCommand(Packet &p, CommandPacket *cp)
|
||||||
{
|
{
|
||||||
cp->company = (CompanyID)p->Recv_uint8();
|
cp->company = (CompanyID)p.Recv_uint8();
|
||||||
cp->cmd = static_cast<Commands>(p->Recv_uint16());
|
cp->cmd = static_cast<Commands>(p.Recv_uint16());
|
||||||
if (!IsValidCommand(cp->cmd)) return "invalid command";
|
if (!IsValidCommand(cp->cmd)) return "invalid command";
|
||||||
if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) return "single-player only command";
|
if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) return "single-player only command";
|
||||||
cp->err_msg = p->Recv_uint16();
|
cp->err_msg = p.Recv_uint16();
|
||||||
cp->data = _cmd_dispatch[cp->cmd].Sanitize(p->Recv_buffer());
|
cp->data = _cmd_dispatch[cp->cmd].Sanitize(p.Recv_buffer());
|
||||||
|
|
||||||
byte callback = p->Recv_uint8();
|
byte callback = p.Recv_uint8();
|
||||||
if (callback >= _callback_table.size() || _cmd_dispatch[cp->cmd].Unpack[callback] == nullptr) return "invalid callback";
|
if (callback >= _callback_table.size() || _cmd_dispatch[cp->cmd].Unpack[callback] == nullptr) return "invalid callback";
|
||||||
|
|
||||||
cp->callback = _callback_table[callback];
|
cp->callback = _callback_table[callback];
|
||||||
|
@ -445,19 +445,19 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *c
|
||||||
* @param p the packet to send it in.
|
* @param p the packet to send it in.
|
||||||
* @param cp the packet to actually send.
|
* @param cp the packet to actually send.
|
||||||
*/
|
*/
|
||||||
void NetworkGameSocketHandler::SendCommand(Packet *p, const CommandPacket *cp)
|
void NetworkGameSocketHandler::SendCommand(Packet &p, const CommandPacket *cp)
|
||||||
{
|
{
|
||||||
p->Send_uint8(cp->company);
|
p.Send_uint8(cp->company);
|
||||||
p->Send_uint16(cp->cmd);
|
p.Send_uint16(cp->cmd);
|
||||||
p->Send_uint16(cp->err_msg);
|
p.Send_uint16(cp->err_msg);
|
||||||
p->Send_buffer(cp->data);
|
p.Send_buffer(cp->data);
|
||||||
|
|
||||||
size_t callback = FindCallbackIndex(cp->callback);
|
size_t callback = FindCallbackIndex(cp->callback);
|
||||||
if (callback > UINT8_MAX || _cmd_dispatch[cp->cmd].Unpack[callback] == nullptr) {
|
if (callback > UINT8_MAX || _cmd_dispatch[cp->cmd].Unpack[callback] == nullptr) {
|
||||||
Debug(net, 0, "Unknown callback for command; no callback sent (command: {})", cp->cmd);
|
Debug(net, 0, "Unknown callback for command; no callback sent (command: {})", cp->cmd);
|
||||||
callback = 0; // _callback_table[0] == nullptr
|
callback = 0; // _callback_table[0] == nullptr
|
||||||
}
|
}
|
||||||
p->Send_uint8 ((uint8_t)callback);
|
p.Send_uint8 ((uint8_t)callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper to process a single ClientID argument. */
|
/** Helper to process a single ClientID argument. */
|
||||||
|
|
|
@ -49,34 +49,34 @@ static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
|
||||||
*/
|
*/
|
||||||
typedef bool (*HasProc)(const ContentInfo *ci, bool md5sum);
|
typedef bool (*HasProc)(const ContentInfo *ci, bool md5sum);
|
||||||
|
|
||||||
bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
|
bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
|
||||||
{
|
{
|
||||||
ContentInfo *ci = new ContentInfo();
|
ContentInfo *ci = new ContentInfo();
|
||||||
ci->type = (ContentType)p->Recv_uint8();
|
ci->type = (ContentType)p.Recv_uint8();
|
||||||
ci->id = (ContentID)p->Recv_uint32();
|
ci->id = (ContentID)p.Recv_uint32();
|
||||||
ci->filesize = p->Recv_uint32();
|
ci->filesize = p.Recv_uint32();
|
||||||
|
|
||||||
ci->name = p->Recv_string(NETWORK_CONTENT_NAME_LENGTH);
|
ci->name = p.Recv_string(NETWORK_CONTENT_NAME_LENGTH);
|
||||||
ci->version = p->Recv_string(NETWORK_CONTENT_VERSION_LENGTH);
|
ci->version = p.Recv_string(NETWORK_CONTENT_VERSION_LENGTH);
|
||||||
ci->url = p->Recv_string(NETWORK_CONTENT_URL_LENGTH);
|
ci->url = p.Recv_string(NETWORK_CONTENT_URL_LENGTH);
|
||||||
ci->description = p->Recv_string(NETWORK_CONTENT_DESC_LENGTH, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE);
|
ci->description = p.Recv_string(NETWORK_CONTENT_DESC_LENGTH, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE);
|
||||||
|
|
||||||
ci->unique_id = p->Recv_uint32();
|
ci->unique_id = p.Recv_uint32();
|
||||||
for (size_t j = 0; j < ci->md5sum.size(); j++) {
|
for (size_t j = 0; j < ci->md5sum.size(); j++) {
|
||||||
ci->md5sum[j] = p->Recv_uint8();
|
ci->md5sum[j] = p.Recv_uint8();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint dependency_count = p->Recv_uint8();
|
uint dependency_count = p.Recv_uint8();
|
||||||
ci->dependencies.reserve(dependency_count);
|
ci->dependencies.reserve(dependency_count);
|
||||||
for (uint i = 0; i < dependency_count; i++) {
|
for (uint i = 0; i < dependency_count; i++) {
|
||||||
ContentID dependency_cid = (ContentID)p->Recv_uint32();
|
ContentID dependency_cid = (ContentID)p.Recv_uint32();
|
||||||
ci->dependencies.push_back(dependency_cid);
|
ci->dependencies.push_back(dependency_cid);
|
||||||
this->reverse_dependency_map.insert({ dependency_cid, ci->id });
|
this->reverse_dependency_map.insert({ dependency_cid, ci->id });
|
||||||
}
|
}
|
||||||
|
|
||||||
uint tag_count = p->Recv_uint8();
|
uint tag_count = p.Recv_uint8();
|
||||||
ci->tags.reserve(tag_count);
|
ci->tags.reserve(tag_count);
|
||||||
for (uint i = 0; i < tag_count; i++) ci->tags.push_back(p->Recv_string(NETWORK_CONTENT_TAG_LENGTH));
|
for (uint i = 0; i < tag_count; i++) ci->tags.push_back(p.Recv_string(NETWORK_CONTENT_TAG_LENGTH));
|
||||||
|
|
||||||
if (!ci->IsValid()) {
|
if (!ci->IsValid()) {
|
||||||
delete ci;
|
delete ci;
|
||||||
|
@ -477,16 +477,16 @@ static inline ssize_t TransferOutFWrite(FILE *file, const char *buffer, size_t a
|
||||||
return fwrite(buffer, 1, amount, file);
|
return fwrite(buffer, 1, amount, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
|
bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->curFile == nullptr) {
|
if (this->curFile == nullptr) {
|
||||||
delete this->curInfo;
|
delete this->curInfo;
|
||||||
/* When we haven't opened a file this must be our first packet with metadata. */
|
/* When we haven't opened a file this must be our first packet with metadata. */
|
||||||
this->curInfo = new ContentInfo;
|
this->curInfo = new ContentInfo;
|
||||||
this->curInfo->type = (ContentType)p->Recv_uint8();
|
this->curInfo->type = (ContentType)p.Recv_uint8();
|
||||||
this->curInfo->id = (ContentID)p->Recv_uint32();
|
this->curInfo->id = (ContentID)p.Recv_uint32();
|
||||||
this->curInfo->filesize = p->Recv_uint32();
|
this->curInfo->filesize = p.Recv_uint32();
|
||||||
this->curInfo->filename = p->Recv_string(NETWORK_CONTENT_FILENAME_LENGTH);
|
this->curInfo->filename = p.Recv_string(NETWORK_CONTENT_FILENAME_LENGTH);
|
||||||
|
|
||||||
if (!this->BeforeDownload()) {
|
if (!this->BeforeDownload()) {
|
||||||
this->CloseConnection();
|
this->CloseConnection();
|
||||||
|
@ -494,8 +494,8 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* We have a file opened, thus are downloading internal content */
|
/* We have a file opened, thus are downloading internal content */
|
||||||
size_t toRead = p->RemainingBytesToTransfer();
|
size_t toRead = p.RemainingBytesToTransfer();
|
||||||
if (toRead != 0 && (size_t)p->TransferOut(TransferOutFWrite, this->curFile) != toRead) {
|
if (toRead != 0 && (size_t)p.TransferOut(TransferOutFWrite, this->curFile) != toRead) {
|
||||||
CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
|
CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
|
||||||
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
|
||||||
this->CloseConnection();
|
this->CloseConnection();
|
||||||
|
|
|
@ -82,8 +82,8 @@ protected:
|
||||||
|
|
||||||
friend class NetworkContentConnecter;
|
friend class NetworkContentConnecter;
|
||||||
|
|
||||||
bool Receive_SERVER_INFO(Packet *p) override;
|
bool Receive_SERVER_INFO(Packet &p) override;
|
||||||
bool Receive_SERVER_CONTENT(Packet *p) override;
|
bool Receive_SERVER_CONTENT(Packet &p) override;
|
||||||
|
|
||||||
ContentInfo *GetContent(ContentID cid) const;
|
ContentInfo *GetContent(ContentID cid) const;
|
||||||
void DownloadContentInfo(ContentID cid);
|
void DownloadContentInfo(ContentID cid);
|
||||||
|
|
|
@ -124,10 +124,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet &p)
|
||||||
{
|
{
|
||||||
NetworkCoordinatorErrorType error = (NetworkCoordinatorErrorType)p->Recv_uint8();
|
NetworkCoordinatorErrorType error = (NetworkCoordinatorErrorType)p.Recv_uint8();
|
||||||
std::string detail = p->Recv_string(NETWORK_ERROR_DETAIL_LENGTH);
|
std::string detail = p.Recv_string(NETWORK_ERROR_DETAIL_LENGTH);
|
||||||
|
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case NETWORK_COORDINATOR_ERROR_UNKNOWN:
|
case NETWORK_COORDINATOR_ERROR_UNKNOWN:
|
||||||
|
@ -174,14 +174,14 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet &p)
|
||||||
{
|
{
|
||||||
/* Schedule sending an update. */
|
/* Schedule sending an update. */
|
||||||
this->next_update = std::chrono::steady_clock::now();
|
this->next_update = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
_settings_client.network.server_invite_code = p->Recv_string(NETWORK_INVITE_CODE_LENGTH);
|
_settings_client.network.server_invite_code = p.Recv_string(NETWORK_INVITE_CODE_LENGTH);
|
||||||
_settings_client.network.server_invite_code_secret = p->Recv_string(NETWORK_INVITE_CODE_SECRET_LENGTH);
|
_settings_client.network.server_invite_code_secret = p.Recv_string(NETWORK_INVITE_CODE_SECRET_LENGTH);
|
||||||
_network_server_connection_type = (ConnectionType)p->Recv_uint8();
|
_network_server_connection_type = (ConnectionType)p.Recv_uint8();
|
||||||
|
|
||||||
if (_network_server_connection_type == CONNECTION_TYPE_ISOLATED) {
|
if (_network_server_connection_type == CONNECTION_TYPE_ISOLATED) {
|
||||||
ShowErrorMessage(STR_NETWORK_ERROR_COORDINATOR_ISOLATED, STR_NETWORK_ERROR_COORDINATOR_ISOLATED_DETAIL, WL_ERROR);
|
ShowErrorMessage(STR_NETWORK_ERROR_COORDINATOR_ISOLATED, STR_NETWORK_ERROR_COORDINATOR_ISOLATED_DETAIL, WL_ERROR);
|
||||||
|
@ -230,9 +230,9 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet *p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet &p)
|
||||||
{
|
{
|
||||||
uint8_t servers = p->Recv_uint16();
|
uint8_t servers = p.Recv_uint16();
|
||||||
|
|
||||||
/* End of list; we can now remove all expired items from the list. */
|
/* End of list; we can now remove all expired items from the list. */
|
||||||
if (servers == 0) {
|
if (servers == 0) {
|
||||||
|
@ -241,11 +241,11 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; servers > 0; servers--) {
|
for (; servers > 0; servers--) {
|
||||||
std::string connection_string = p->Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
std::string connection_string = p.Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
||||||
|
|
||||||
/* Read the NetworkGameInfo from the packet. */
|
/* Read the NetworkGameInfo from the packet. */
|
||||||
NetworkGameInfo ngi = {};
|
NetworkGameInfo ngi = {};
|
||||||
DeserializeNetworkGameInfo(*p, ngi, &this->newgrf_lookup_table);
|
DeserializeNetworkGameInfo(p, ngi, &this->newgrf_lookup_table);
|
||||||
|
|
||||||
/* Now we know the connection string, we can add it to our list. */
|
/* Now we know the connection string, we can add it to our list. */
|
||||||
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
||||||
|
@ -266,10 +266,10 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
std::string invite_code = p->Recv_string(NETWORK_INVITE_CODE_LENGTH);
|
std::string invite_code = p.Recv_string(NETWORK_INVITE_CODE_LENGTH);
|
||||||
|
|
||||||
/* Find the connecter based on the invite code. */
|
/* Find the connecter based on the invite code. */
|
||||||
auto connecter_pre_it = this->connecter_pre.find(invite_code);
|
auto connecter_pre_it = this->connecter_pre.find(invite_code);
|
||||||
|
@ -285,20 +285,20 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECTING(Packet *p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECT_FAILED(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_CONNECT_FAILED(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
this->CloseToken(token);
|
this->CloseToken(token);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_DIRECT_CONNECT(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_DIRECT_CONNECT(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
uint8_t tracking_number = p->Recv_uint8();
|
uint8_t tracking_number = p.Recv_uint8();
|
||||||
std::string hostname = p->Recv_string(NETWORK_HOSTNAME_LENGTH);
|
std::string hostname = p.Recv_string(NETWORK_HOSTNAME_LENGTH);
|
||||||
uint16_t port = p->Recv_uint16();
|
uint16_t port = p.Recv_uint16();
|
||||||
|
|
||||||
/* Ensure all other pending connection attempts are killed. */
|
/* Ensure all other pending connection attempts are killed. */
|
||||||
if (this->game_connecter != nullptr) {
|
if (this->game_connecter != nullptr) {
|
||||||
|
@ -310,22 +310,22 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_DIRECT_CONNECT(Packet *p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_REQUEST(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_REQUEST(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
|
|
||||||
this->stun_handlers[token][AF_INET6] = ClientNetworkStunSocketHandler::Stun(token, AF_INET6);
|
this->stun_handlers[token][AF_INET6] = ClientNetworkStunSocketHandler::Stun(token, AF_INET6);
|
||||||
this->stun_handlers[token][AF_INET] = ClientNetworkStunSocketHandler::Stun(token, AF_INET);
|
this->stun_handlers[token][AF_INET] = ClientNetworkStunSocketHandler::Stun(token, AF_INET);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
uint8_t tracking_number = p->Recv_uint8();
|
uint8_t tracking_number = p.Recv_uint8();
|
||||||
uint8_t family = p->Recv_uint8();
|
uint8_t family = p.Recv_uint8();
|
||||||
std::string host = p->Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
std::string host = p.Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
||||||
uint16_t port = p->Recv_uint16();
|
uint16_t port = p.Recv_uint16();
|
||||||
|
|
||||||
/* Check if we know this token. */
|
/* Check if we know this token. */
|
||||||
auto stun_it = this->stun_handlers.find(token);
|
auto stun_it = this->stun_handlers.find(token);
|
||||||
|
@ -353,24 +353,24 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet *p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP(Packet &p)
|
||||||
{
|
{
|
||||||
this->newgrf_lookup_table_cursor = p->Recv_uint32();
|
this->newgrf_lookup_table_cursor = p.Recv_uint32();
|
||||||
|
|
||||||
uint16_t newgrfs = p->Recv_uint16();
|
uint16_t newgrfs = p.Recv_uint16();
|
||||||
for (; newgrfs> 0; newgrfs--) {
|
for (; newgrfs> 0; newgrfs--) {
|
||||||
uint32_t index = p->Recv_uint32();
|
uint32_t index = p.Recv_uint32();
|
||||||
DeserializeGRFIdentifierWithName(*p, this->newgrf_lookup_table[index]);
|
DeserializeGRFIdentifierWithName(p, this->newgrf_lookup_table[index]);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet *p)
|
bool ClientNetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet &p)
|
||||||
{
|
{
|
||||||
std::string token = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
uint8_t tracking_number = p->Recv_uint8();
|
uint8_t tracking_number = p.Recv_uint8();
|
||||||
std::string ticket = p->Recv_string(NETWORK_TOKEN_LENGTH);
|
std::string ticket = p.Recv_string(NETWORK_TOKEN_LENGTH);
|
||||||
std::string connection_string = p->Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
std::string connection_string = p.Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
|
||||||
|
|
||||||
/* Ensure all other pending connection attempts are killed. */
|
/* Ensure all other pending connection attempts are killed. */
|
||||||
if (this->game_connecter != nullptr) {
|
if (this->game_connecter != nullptr) {
|
||||||
|
|
|
@ -63,16 +63,16 @@ private:
|
||||||
GameInfoNewGRFLookupTable newgrf_lookup_table; ///< Table to look up NewGRFs in the GC_LISTING packets.
|
GameInfoNewGRFLookupTable newgrf_lookup_table; ///< Table to look up NewGRFs in the GC_LISTING packets.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Receive_GC_ERROR(Packet *p) override;
|
bool Receive_GC_ERROR(Packet &p) override;
|
||||||
bool Receive_GC_REGISTER_ACK(Packet *p) override;
|
bool Receive_GC_REGISTER_ACK(Packet &p) override;
|
||||||
bool Receive_GC_LISTING(Packet *p) override;
|
bool Receive_GC_LISTING(Packet &p) override;
|
||||||
bool Receive_GC_CONNECTING(Packet *p) override;
|
bool Receive_GC_CONNECTING(Packet &p) override;
|
||||||
bool Receive_GC_CONNECT_FAILED(Packet *p) override;
|
bool Receive_GC_CONNECT_FAILED(Packet &p) override;
|
||||||
bool Receive_GC_DIRECT_CONNECT(Packet *p) override;
|
bool Receive_GC_DIRECT_CONNECT(Packet &p) override;
|
||||||
bool Receive_GC_STUN_REQUEST(Packet *p) override;
|
bool Receive_GC_STUN_REQUEST(Packet &p) override;
|
||||||
bool Receive_GC_STUN_CONNECT(Packet *p) override;
|
bool Receive_GC_STUN_CONNECT(Packet &p) override;
|
||||||
bool Receive_GC_NEWGRF_LOOKUP(Packet *p) override;
|
bool Receive_GC_NEWGRF_LOOKUP(Packet &p) override;
|
||||||
bool Receive_GC_TURN_CONNECT(Packet *p) override;
|
bool Receive_GC_TURN_CONNECT(Packet &p) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** The idle timeout; when to close the connection because it's idle. */
|
/** The idle timeout; when to close the connection because it's idle. */
|
||||||
|
|
|
@ -87,7 +87,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::SendGameInfo()
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Query::Receive_SERVER_FULL()");
|
Debug(net, 9, "Query::Receive_SERVER_FULL()");
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *)
|
||||||
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Query::Receive_SERVER_BANNED()");
|
Debug(net, 9, "Query::Receive_SERVER_BANNED()");
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *)
|
||||||
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet &p)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Query::Receive_SERVER_GAME_INFO()");
|
Debug(net, 9, "Query::Receive_SERVER_GAME_INFO()");
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet
|
||||||
/* Clear any existing GRFConfig chain. */
|
/* Clear any existing GRFConfig chain. */
|
||||||
ClearGRFConfigList(&item->info.grfconfig);
|
ClearGRFConfigList(&item->info.grfconfig);
|
||||||
/* Retrieve the NetworkGameInfo from the packet. */
|
/* Retrieve the NetworkGameInfo from the packet. */
|
||||||
DeserializeNetworkGameInfo(*p, item->info);
|
DeserializeNetworkGameInfo(p, item->info);
|
||||||
/* Check for compatability with the client. */
|
/* Check for compatability with the client. */
|
||||||
CheckGameCompatibility(item->info);
|
CheckGameCompatibility(item->info);
|
||||||
/* Ensure we consider the server online. */
|
/* Ensure we consider the server online. */
|
||||||
|
@ -134,9 +134,9 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet
|
||||||
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
|
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet &p)
|
||||||
{
|
{
|
||||||
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
|
NetworkErrorCode error = (NetworkErrorCode)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "Query::Receive_SERVER_ERROR(): error={}", error);
|
Debug(net, 9, "Query::Receive_SERVER_ERROR(): error={}", error);
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ private:
|
||||||
std::string connection_string; ///< Address we are connected to.
|
std::string connection_string; ///< Address we are connected to.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_FULL(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_BANNED(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_ERROR(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p) override;
|
NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p) override;
|
||||||
|
|
||||||
NetworkRecvStatus SendGameInfo();
|
NetworkRecvStatus SendGameInfo();
|
||||||
|
|
||||||
|
|
|
@ -662,7 +662,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke
|
||||||
|
|
||||||
auto p = std::make_unique<Packet>(PACKET_SERVER_COMMAND);
|
auto p = std::make_unique<Packet>(PACKET_SERVER_COMMAND);
|
||||||
|
|
||||||
this->NetworkGameSocketHandler::SendCommand(p.get(), cp);
|
this->NetworkGameSocketHandler::SendCommand(*p, cp);
|
||||||
p->Send_uint32(cp->frame);
|
p->Send_uint32(cp->frame);
|
||||||
p->Send_bool (cp->my_cmd);
|
p->Send_bool (cp->my_cmd);
|
||||||
|
|
||||||
|
@ -836,17 +836,16 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate()
|
||||||
|
|
||||||
/***********
|
/***********
|
||||||
* Receiving functions
|
* Receiving functions
|
||||||
* DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientSocket *cs, Packet *p
|
|
||||||
************/
|
************/
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet *)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_GAME_INFO()", this->client_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_GAME_INFO()", this->client_id);
|
||||||
|
|
||||||
return this->SendGameInfo();
|
return this->SendGameInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet &)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_NEWGRFS_CHECK) {
|
if (this->status != STATUS_NEWGRFS_CHECK) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
|
@ -858,7 +857,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED
|
||||||
return this->SendNeedGamePassword();
|
return this->SendNeedGamePassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_INACTIVE) {
|
if (this->status != STATUS_INACTIVE) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
|
@ -870,8 +869,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||||
return this->SendError(NETWORK_ERROR_FULL);
|
return this->SendError(NETWORK_ERROR_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string client_revision = p->Recv_string(NETWORK_REVISION_LENGTH);
|
std::string client_revision = p.Recv_string(NETWORK_REVISION_LENGTH);
|
||||||
uint32_t newgrf_version = p->Recv_uint32();
|
uint32_t newgrf_version = p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_JOIN(): client_revision={}, newgrf_version={}", this->client_id, client_revision, newgrf_version);
|
Debug(net, 9, "client[{}] Receive_CLIENT_JOIN(): client_revision={}, newgrf_version={}", this->client_id, client_revision, newgrf_version);
|
||||||
|
|
||||||
|
@ -881,8 +880,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||||
return this->SendError(NETWORK_ERROR_WRONG_REVISION);
|
return this->SendError(NETWORK_ERROR_WRONG_REVISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string client_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
std::string client_name = p.Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
||||||
CompanyID playas = (Owner)p->Recv_uint8();
|
CompanyID playas = (Owner)p.Recv_uint8();
|
||||||
|
|
||||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
||||||
|
|
||||||
|
@ -936,7 +935,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||||
return this->SendNewGRFCheck();
|
return this->SendNewGRFCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_AUTH_GAME) {
|
if (this->status != STATUS_AUTH_GAME) {
|
||||||
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
@ -944,7 +943,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(P
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_GAME_PASSWORD()", this->client_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_GAME_PASSWORD()", this->client_id);
|
||||||
|
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
|
|
||||||
/* Check game password. Allow joining if we cleared the password meanwhile */
|
/* Check game password. Allow joining if we cleared the password meanwhile */
|
||||||
if (!_settings_client.network.server_password.empty() &&
|
if (!_settings_client.network.server_password.empty() &&
|
||||||
|
@ -956,7 +955,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(P
|
||||||
return this->SendNeedCompanyPassword();
|
return this->SendNeedCompanyPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_AUTH_COMPANY) {
|
if (this->status != STATUS_AUTH_COMPANY) {
|
||||||
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
@ -964,7 +963,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWOR
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_COMPANY_PASSWORD()", this->client_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_COMPANY_PASSWORD()", this->client_id);
|
||||||
|
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
|
|
||||||
/* Check company password. Allow joining if we cleared the password meanwhile.
|
/* Check company password. Allow joining if we cleared the password meanwhile.
|
||||||
* Also, check the company is still valid - client could be moved to spectators
|
* Also, check the company is still valid - client could be moved to spectators
|
||||||
|
@ -979,7 +978,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWOR
|
||||||
return this->SendWelcome();
|
return this->SendWelcome();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet &)
|
||||||
{
|
{
|
||||||
/* The client was never joined.. so this is impossible, right?
|
/* The client was never joined.. so this is impossible, right?
|
||||||
* Ignore the packet, give the client a warning, and close the connection */
|
* Ignore the packet, give the client a warning, and close the connection */
|
||||||
|
@ -1003,7 +1002,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *
|
||||||
return this->SendMap();
|
return this->SendMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet &)
|
||||||
{
|
{
|
||||||
/* Client has the map, now start syncing */
|
/* Client has the map, now start syncing */
|
||||||
if (this->status == STATUS_DONE_MAP && !this->HasClientQuit()) {
|
if (this->status == STATUS_DONE_MAP && !this->HasClientQuit()) {
|
||||||
|
@ -1053,7 +1052,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *
|
||||||
* The client has done a command and wants us to handle it
|
* The client has done a command and wants us to handle it
|
||||||
* @param p the packet in which the command was sent
|
* @param p the packet in which the command was sent
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet &p)
|
||||||
{
|
{
|
||||||
/* The client was never joined.. so this is impossible, right?
|
/* The client was never joined.. so this is impossible, right?
|
||||||
* Ignore the packet, give the client a warning, and close the connection */
|
* Ignore the packet, give the client a warning, and close the connection */
|
||||||
|
@ -1120,11 +1119,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet &p)
|
||||||
{
|
{
|
||||||
/* This packets means a client noticed an error and is reporting this
|
/* This packets means a client noticed an error and is reporting this
|
||||||
* to us. Display the error and report it to the other clients */
|
* to us. Display the error and report it to the other clients */
|
||||||
NetworkErrorCode errorno = (NetworkErrorCode)p->Recv_uint8();
|
NetworkErrorCode errorno = (NetworkErrorCode)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_ERROR(): errorno={}", this->client_id, errorno);
|
Debug(net, 9, "client[{}] Receive_CLIENT_ERROR(): errorno={}", this->client_id, errorno);
|
||||||
|
|
||||||
|
@ -1151,7 +1150,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p
|
||||||
return this->CloseConnection(NETWORK_RECV_STATUS_CLIENT_QUIT);
|
return this->CloseConnection(NETWORK_RECV_STATUS_CLIENT_QUIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet &)
|
||||||
{
|
{
|
||||||
/* The client was never joined.. thank the client for the packet, but ignore it */
|
/* The client was never joined.. thank the client for the packet, but ignore it */
|
||||||
if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
|
if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
|
||||||
|
@ -1175,14 +1174,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *)
|
||||||
return this->CloseConnection(NETWORK_RECV_STATUS_CLIENT_QUIT);
|
return this->CloseConnection(NETWORK_RECV_STATUS_CLIENT_QUIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_AUTHORIZED) {
|
if (this->status < STATUS_AUTHORIZED) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
|
return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t frame = p->Recv_uint32();
|
uint32_t frame = p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_ACK(): frame={}", this->client_id, frame);
|
Debug(net, 9, "client[{}] Receive_CLIENT_ACK(): frame={}", this->client_id, frame);
|
||||||
|
|
||||||
|
@ -1201,7 +1200,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get, and validate the token. */
|
/* Get, and validate the token. */
|
||||||
uint8_t token = p->Recv_uint8();
|
uint8_t token = p.Recv_uint8();
|
||||||
if (token == this->last_token) {
|
if (token == this->last_token) {
|
||||||
/* We differentiate between last_token_frame and last_frame so the lag
|
/* We differentiate between last_token_frame and last_frame so the lag
|
||||||
* test uses the actual lag of the client instead of the lag for getting
|
* test uses the actual lag of the client instead of the lag for getting
|
||||||
|
@ -1360,21 +1359,21 @@ void NetworkServerSendExternalChat(const std::string &source, TextColour colour,
|
||||||
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
|
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_PRE_ACTIVE) {
|
if (this->status < STATUS_PRE_ACTIVE) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
|
return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkAction action = (NetworkAction)p->Recv_uint8();
|
NetworkAction action = (NetworkAction)p.Recv_uint8();
|
||||||
DestType desttype = (DestType)p->Recv_uint8();
|
DestType desttype = (DestType)p.Recv_uint8();
|
||||||
int dest = p->Recv_uint32();
|
int dest = p.Recv_uint32();
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_CHAT(): action={}, desttype={}, dest={}", this->client_id, action, desttype, dest);
|
Debug(net, 9, "client[{}] Receive_CLIENT_CHAT(): action={}, desttype={}, dest={}", this->client_id, action, desttype, dest);
|
||||||
|
|
||||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
|
||||||
int64_t data = p->Recv_uint64();
|
int64_t data = p.Recv_uint64();
|
||||||
|
|
||||||
NetworkClientInfo *ci = this->GetInfo();
|
NetworkClientInfo *ci = this->GetInfo();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
@ -1390,7 +1389,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) {
|
if (this->status != STATUS_ACTIVE) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
|
@ -1399,14 +1398,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Pa
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_SET_PASSWORD()", this->client_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_SET_PASSWORD()", this->client_id);
|
||||||
|
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
const NetworkClientInfo *ci = this->GetInfo();
|
const NetworkClientInfo *ci = this->GetInfo();
|
||||||
|
|
||||||
NetworkServerSetCompanyPassword(ci->client_playas, password);
|
NetworkServerSetCompanyPassword(ci->client_playas, password);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) {
|
if (this->status != STATUS_ACTIVE) {
|
||||||
/* Illegal call, return error and ignore the packet */
|
/* Illegal call, return error and ignore the packet */
|
||||||
|
@ -1417,7 +1416,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
|
||||||
|
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
|
|
||||||
std::string client_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
std::string client_name = p.Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
||||||
ci = this->GetInfo();
|
ci = this->GetInfo();
|
||||||
|
|
||||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
||||||
|
@ -1440,7 +1439,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
|
@ -1448,8 +1447,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_RCON()", this->client_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_RCON()", this->client_id);
|
||||||
|
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
std::string command = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
std::string command = p.Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
||||||
|
|
||||||
if (_settings_client.network.rcon_password.compare(password) != 0) {
|
if (_settings_client.network.rcon_password.compare(password) != 0) {
|
||||||
Debug(net, 1, "[rcon] Wrong password from client-id {}", this->client_id);
|
Debug(net, 1, "[rcon] Wrong password from client-id {}", this->client_id);
|
||||||
|
@ -1464,11 +1463,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet &p)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||||
|
|
||||||
CompanyID company_id = (Owner)p->Recv_uint8();
|
CompanyID company_id = (Owner)p.Recv_uint8();
|
||||||
|
|
||||||
Debug(net, 9, "client[{}] Receive_CLIENT_MOVE(): company_id={}", this->client_id, company_id);
|
Debug(net, 9, "client[{}] Receive_CLIENT_MOVE(): company_id={}", this->client_id, company_id);
|
||||||
|
|
||||||
|
@ -1478,7 +1477,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p)
|
||||||
/* Check if we require a password for this company */
|
/* Check if we require a password for this company */
|
||||||
if (company_id != COMPANY_SPECTATOR && !_network_company_states[company_id].password.empty()) {
|
if (company_id != COMPANY_SPECTATOR && !_network_company_states[company_id].password.empty()) {
|
||||||
/* we need a password from the client - should be in this packet */
|
/* we need a password from the client - should be in this packet */
|
||||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
std::string password = p.Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||||
|
|
||||||
/* Incorrect password sent, return! */
|
/* Incorrect password sent, return! */
|
||||||
if (_network_company_states[company_id].password.compare(password) != 0) {
|
if (_network_company_states[company_id].password.compare(password) != 0) {
|
||||||
|
|
|
@ -23,22 +23,22 @@ extern NetworkClientSocketPool _networkclientsocket_pool;
|
||||||
/** Class for handling the server side of the game connection. */
|
/** Class for handling the server side of the game connection. */
|
||||||
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
|
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
|
||||||
protected:
|
protected:
|
||||||
NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_JOIN(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_GETMAP(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_ACK(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_ACK(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_COMMAND(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_CHAT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_QUIT(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_ERROR(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_RCON(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_RCON(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet &p) override;
|
||||||
NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;
|
NetworkRecvStatus Receive_CLIENT_MOVE(Packet &p) override;
|
||||||
|
|
||||||
NetworkRecvStatus SendGameInfo();
|
NetworkRecvStatus SendGameInfo();
|
||||||
NetworkRecvStatus SendNewGRFCheck();
|
NetworkRecvStatus SendNewGRFCheck();
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ClientNetworkTurnSocketHandler::Receive_TURN_ERROR(Packet *)
|
bool ClientNetworkTurnSocketHandler::Receive_TURN_ERROR(Packet &)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Receive_TURN_ERROR()");
|
Debug(net, 9, "Receive_TURN_ERROR()");
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ bool ClientNetworkTurnSocketHandler::Receive_TURN_ERROR(Packet *)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientNetworkTurnSocketHandler::Receive_TURN_CONNECTED(Packet *p)
|
bool ClientNetworkTurnSocketHandler::Receive_TURN_CONNECTED(Packet &p)
|
||||||
{
|
{
|
||||||
Debug(net, 9, "Receive_TURN_CONNECTED()");
|
Debug(net, 9, "Receive_TURN_CONNECTED()");
|
||||||
|
|
||||||
std::string hostname = p->Recv_string(NETWORK_HOSTNAME_LENGTH);
|
std::string hostname = p.Recv_string(NETWORK_HOSTNAME_LENGTH);
|
||||||
|
|
||||||
/* Act like we no longer have a socket, as we are handing it over to the
|
/* Act like we no longer have a socket, as we are handing it over to the
|
||||||
* game handler. */
|
* game handler. */
|
||||||
|
|
|
@ -20,8 +20,8 @@ private:
|
||||||
std::string connection_string; ///< The connection string of the TURN server we are connecting to.
|
std::string connection_string; ///< The connection string of the TURN server we are connecting to.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Receive_TURN_ERROR(Packet *p) override;
|
bool Receive_TURN_ERROR(Packet &p) override;
|
||||||
bool Receive_TURN_CONNECTED(Packet *p) override;
|
bool Receive_TURN_CONNECTED(Packet &p) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<TCPConnecter> connecter{}; ///< Connecter instance.
|
std::shared_ptr<TCPConnecter> connecter{}; ///< Connecter instance.
|
||||||
|
|
Loading…
Reference in New Issue