OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
12 #include "../../stdafx.h"
13 #include "../../string_func.h"
17 #include "../../safeguards.h"
25 assert(
cs !=
nullptr);
63 assert(this->
cs ==
nullptr && this->
next ==
nullptr);
150 assert(data !=
nullptr);
153 while ((this->
buffer[this->
size++] = *data++) !=
'\0') {}
175 if (this->
pos + bytes_to_read > this->
size) {
176 this->
cs->NetworkSocketHandler::CloseConnection();
188 assert(this->
cs !=
nullptr && this->
next ==
nullptr);
238 n += (uint16)this->
buffer[this->
pos++] << 8;
253 n += (uint32)this->
buffer[this->
pos++] << 8;
254 n += (uint32)this->
buffer[this->
pos++] << 16;
255 n += (uint32)this->
buffer[this->
pos++] << 24;
270 n += (uint64)this->
buffer[this->
pos++] << 8;
271 n += (uint64)this->
buffer[this->
pos++] << 16;
272 n += (uint64)this->
buffer[this->
pos++] << 24;
273 n += (uint64)this->
buffer[this->
pos++] << 32;
274 n += (uint64)this->
buffer[this->
pos++] << 40;
275 n += (uint64)this->
buffer[this->
pos++] << 48;
276 n += (uint64)this->
buffer[this->
pos++] << 56;
296 while (--size > 0 && pos < this->
size && (*
buffer++ = this->buffer[
pos++]) !=
'\0') {}
298 if (
size == 0 ||
pos == this->size) {
302 while (pos < this->
size && this->buffer[
pos] !=
'\0')
pos++;
void PrepareToSend()
Writes the packet size from the raw packet from packet->size.
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
byte * buffer
The buffer of this packet, of basically variable length up to SEND_MTU.
SocketHandler for all network sockets in OpenTTD.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
uint8 PacketType
Identifier for the packet.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
void Send_string(const char *data)
Sends a string over the network.
void PrepareToRead()
Prepares the packet so it can be read.
PacketSize size
The size of the whole packet for received packets.
static const uint16 SEND_MTU
Number of bytes we can pack in a single packet.
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
fluid_settings_t * settings
FluidSynth settings handle.
Packet * next
The next packet.
bool CanReadFromPacket(uint bytes_to_read)
Is it safe to read from the packet, i.e.
void ReadRawPacketSize()
Reads the packet size from the raw packet and stores it in the packet->size.
StringValidationSettings
Settings for the string validation.
void Send_bool(bool data)
Package a boolean in the packet.
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
~Packet()
Free the buffer of this packet.
uint16 PacketSize
Size of the whole packet.
bool Recv_bool()
Read a boolean from the packet.
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
NetworkSocketHandler * cs
Socket we're associated with.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Packet(NetworkSocketHandler *cs)
Create a packet that is used to read from a network socket.
uint64 Recv_uint64()
Read a 64 bits integer from the packet.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
PacketSize pos
The current read/write position in the packet.