mirror of https://github.com/OpenTTD/OpenTTD
Codechange: add accessor for the packet type to Packet and make the internal state of Packet private
parent
3abefdf561
commit
450178d780
|
@ -296,6 +296,16 @@ void Packet::PrepareToRead()
|
||||||
this->pos = sizeof(PacketSize);
|
this->pos = sizeof(PacketSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the \c PacketType from this packet.
|
||||||
|
* @return The packet type.
|
||||||
|
*/
|
||||||
|
PacketType Packet::GetPacketType() const
|
||||||
|
{
|
||||||
|
assert(this->Size() >= sizeof(PacketSize) + sizeof(PacketType));
|
||||||
|
return static_cast<PacketType>(buffer[sizeof(PacketSize)]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a boolean from the packet.
|
* Read a boolean from the packet.
|
||||||
* @return The read data.
|
* @return The read data.
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef uint8 PacketType; ///< Identifier for the packet
|
||||||
* (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))
|
* (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))
|
||||||
*/
|
*/
|
||||||
struct Packet {
|
struct Packet {
|
||||||
|
private:
|
||||||
/** The next packet. Used for queueing packets before sending. */
|
/** The next packet. Used for queueing packets before sending. */
|
||||||
Packet *next;
|
Packet *next;
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +53,6 @@ struct Packet {
|
||||||
PacketSize pos;
|
PacketSize pos;
|
||||||
/** The buffer of this packet, of basically variable length up to SEND_MTU. */
|
/** The buffer of this packet, of basically variable length up to SEND_MTU. */
|
||||||
byte *buffer;
|
byte *buffer;
|
||||||
|
|
||||||
private:
|
|
||||||
/** Socket we're associated with. */
|
/** Socket we're associated with. */
|
||||||
NetworkSocketHandler *cs;
|
NetworkSocketHandler *cs;
|
||||||
|
|
||||||
|
@ -82,6 +81,7 @@ public:
|
||||||
bool ParsePacketSize();
|
bool ParsePacketSize();
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
void PrepareToRead();
|
void PrepareToRead();
|
||||||
|
PacketType GetPacketType() const;
|
||||||
|
|
||||||
bool CanReadFromPacket(size_t bytes_to_read, bool close_connection = false);
|
bool CanReadFromPacket(size_t bytes_to_read, bool close_connection = false);
|
||||||
bool Recv_bool ();
|
bool Recv_bool ();
|
||||||
|
|
|
@ -626,7 +626,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
|
|
||||||
for (uint i = 0; (has_packets = this->savegame->HasPackets()) && i < sent_packets; i++) {
|
for (uint i = 0; (has_packets = this->savegame->HasPackets()) && i < sent_packets; i++) {
|
||||||
Packet *p = this->savegame->PopPacket();
|
Packet *p = this->savegame->PopPacket();
|
||||||
last_packet = p->buffer[2] == PACKET_SERVER_MAP_DONE;
|
last_packet = p->GetPacketType() == PACKET_SERVER_MAP_DONE;
|
||||||
|
|
||||||
this->SendPacket(p);
|
this->SendPacket(p);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue