OpenTTD
Public Member Functions | Protected Member Functions | Protected Attributes
NetworkContentSocketHandler Class Reference

Base socket handler for all Content TCP sockets. More...

#include <tcp_content.h>

Inheritance diagram for NetworkContentSocketHandler:
NetworkTCPSocketHandler NetworkSocketHandler ClientNetworkContentSocketHandler

Public Member Functions

 NetworkContentSocketHandler (SOCKET s=INVALID_SOCKET, const NetworkAddress &address=NetworkAddress())
 Create a new cs socket handler for a given cs. More...
 
virtual ~NetworkContentSocketHandler ()
 On destructing of this class, the socket needs to be closed.
 
bool ReceivePackets ()
 Receive a packet at TCP level. More...
 
- Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket. More...
 
virtual NetworkRecvStatus CloseConnection (bool error=true)
 Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped. More...
 
virtual void SendPacket (Packet *packet)
 This function puts the packet in the send-queue and it is send as soon as possible. More...
 
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this client. More...
 
virtual PacketReceivePacket ()
 Receives a packet for the given client. More...
 
bool CanSendReceive ()
 Check whether this socket can send or receive something. More...
 
bool HasSendQueue ()
 Whether there is something pending in the send queue. More...
 
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
 Construct a socket handler for a TCP connection. More...
 
- Public Member Functions inherited from NetworkSocketHandler
 NetworkSocketHandler ()
 Create a new unbound socket.
 
virtual ~NetworkSocketHandler ()
 Close the socket when destructing the socket handler.
 
bool HasClientQuit () const
 Whether the current client connected to the socket has quit. More...
 
void Reopen ()
 Reopen the socket so we can send/receive stuff again.
 
void SendGRFIdentifier (Packet *p, const GRFIdentifier *grf)
 Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet. More...
 
void ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
 Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet. More...
 
void SendCompanyInformation (Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len=NETWORK_COMPANY_NAME_LENGTH)
 Package some generic company information into a packet. More...
 

Protected Member Functions

virtual void Close ()
 Really close the socket.
 
bool ReceiveInvalidPacket (PacketContentType type)
 Helper for logging receiving invalid packets. More...
 
virtual bool Receive_CLIENT_INFO_LIST (Packet *p)
 Client requesting a list of content info: byte type uint32 openttd version. More...
 
virtual bool Receive_CLIENT_INFO_ID (Packet *p)
 Client requesting a list of content info: uint16 count of ids uint32 id (count times) More...
 
virtual bool Receive_CLIENT_INFO_EXTID (Packet *p)
 Client requesting a list of content info based on an external 'unique' id; GRF ID for NewGRFS, shortname and for base graphics and AIs. More...
 
virtual bool Receive_CLIENT_INFO_EXTID_MD5 (Packet *p)
 Client requesting a list of content info based on an external 'unique' id; GRF ID + MD5 checksum for NewGRFS, shortname and xor-ed MD5 checksums for base graphics and AIs. More...
 
virtual bool Receive_SERVER_INFO (Packet *p)
 Server sending list of content info: byte type (invalid ID == does not exist) uint32 id uint32 file_size string name (max 32 characters) string version (max 16 characters) uint32 unique id uint8 md5sum (16 bytes) uint8 dependency count uint32 unique id of dependency (dependency count times) uint8 tag count string tag (max 32 characters for tag count times) More...
 
virtual bool Receive_CLIENT_CONTENT (Packet *p)
 Client requesting the actual content: uint16 count of unique ids uint32 unique id (count times) More...
 
virtual bool Receive_SERVER_CONTENT (Packet *p)
 Server sending list of content info: uint32 unique id uint32 file size (0 == does not exist) string file name (max 48 characters) After this initial packet, packets with the actual data are send using the same packet type. More...
 
bool HandlePacket (Packet *p)
 Handle the given packet, i.e. More...
 

Protected Attributes

NetworkAddress client_addr
 The address we're connected to.
 

Additional Inherited Members

- Data Fields inherited from NetworkTCPSocketHandler
SOCKET sock
 The socket currently connected to.
 
bool writable
 Can we write to this socket?
 

Detailed Description

Base socket handler for all Content TCP sockets.

Definition at line 100 of file tcp_content.h.

Constructor & Destructor Documentation

◆ NetworkContentSocketHandler()

NetworkContentSocketHandler::NetworkContentSocketHandler ( SOCKET  s = INVALID_SOCKET,
const NetworkAddress address = NetworkAddress() 
)
inline

Create a new cs socket handler for a given cs.

Parameters
sthe socket we are connected with
addressIP etc. of the client

Definition at line 200 of file tcp_content.h.

Member Function Documentation

◆ HandlePacket()

bool NetworkContentSocketHandler::HandlePacket ( Packet p)
protected

Handle the given packet, i.e.

pass it to the right parser receive command.

Parameters
pthe packet to handle
Returns
true if we should immediately handle further packets, false otherwise

Definition at line 163 of file tcp_content.cpp.

References DEBUG, PACKET_CONTENT_CLIENT_CONTENT, PACKET_CONTENT_CLIENT_INFO_EXTID, PACKET_CONTENT_CLIENT_INFO_EXTID_MD5, PACKET_CONTENT_CLIENT_INFO_ID, PACKET_CONTENT_CLIENT_INFO_LIST, PACKET_CONTENT_END, PACKET_CONTENT_SERVER_CONTENT, PACKET_CONTENT_SERVER_INFO, Packet::Recv_uint8(), and ContentInfo::type.

◆ Receive_CLIENT_CONTENT()

bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT ( Packet p)
protectedvirtual

Client requesting the actual content: uint16 count of unique ids uint32 unique id (count times)

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 240 of file tcp_content.cpp.

References PACKET_CONTENT_CLIENT_CONTENT.

◆ Receive_CLIENT_INFO_EXTID()

bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID ( Packet p)
protectedvirtual

Client requesting a list of content info based on an external 'unique' id; GRF ID for NewGRFS, shortname and for base graphics and AIs.

Scenarios and AI libraries are not supported uint8 count of requests for each request: uint8 type unique id (uint32)

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 237 of file tcp_content.cpp.

References PACKET_CONTENT_CLIENT_INFO_EXTID.

◆ Receive_CLIENT_INFO_EXTID_MD5()

bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5 ( Packet p)
protectedvirtual

Client requesting a list of content info based on an external 'unique' id; GRF ID + MD5 checksum for NewGRFS, shortname and xor-ed MD5 checksums for base graphics and AIs.

Scenarios and AI libraries are not supported uint8 count of requests for each request: uint8 type unique id (uint32) md5 (16 bytes)

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 238 of file tcp_content.cpp.

References PACKET_CONTENT_CLIENT_INFO_EXTID_MD5.

◆ Receive_CLIENT_INFO_ID()

bool NetworkContentSocketHandler::Receive_CLIENT_INFO_ID ( Packet p)
protectedvirtual

Client requesting a list of content info: uint16 count of ids uint32 id (count times)

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 236 of file tcp_content.cpp.

References PACKET_CONTENT_CLIENT_INFO_ID.

◆ Receive_CLIENT_INFO_LIST()

bool NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST ( Packet p)
protectedvirtual

Client requesting a list of content info: byte type uint32 openttd version.

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 235 of file tcp_content.cpp.

References PACKET_CONTENT_CLIENT_INFO_LIST.

◆ Receive_SERVER_CONTENT()

bool NetworkContentSocketHandler::Receive_SERVER_CONTENT ( Packet p)
protectedvirtual

Server sending list of content info: uint32 unique id uint32 file size (0 == does not exist) string file name (max 48 characters) After this initial packet, packets with the actual data are send using the same packet type.

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Reimplemented in ClientNetworkContentSocketHandler.

Definition at line 241 of file tcp_content.cpp.

References PACKET_CONTENT_SERVER_CONTENT.

◆ Receive_SERVER_INFO()

bool NetworkContentSocketHandler::Receive_SERVER_INFO ( Packet p)
protectedvirtual

Server sending list of content info: byte type (invalid ID == does not exist) uint32 id uint32 file_size string name (max 32 characters) string version (max 16 characters) uint32 unique id uint8 md5sum (16 bytes) uint8 dependency count uint32 unique id of dependency (dependency count times) uint8 tag count string tag (max 32 characters for tag count times)

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Reimplemented in ClientNetworkContentSocketHandler.

Definition at line 239 of file tcp_content.cpp.

References PACKET_CONTENT_SERVER_INFO.

◆ ReceiveInvalidPacket()

bool NetworkContentSocketHandler::ReceiveInvalidPacket ( PacketContentType  type)
protected

Helper for logging receiving invalid packets.

Parameters
typeThe received packet type.
Returns
Always false, as it's an error.

Definition at line 229 of file tcp_content.cpp.

References DEBUG.

◆ ReceivePackets()

bool NetworkContentSocketHandler::ReceivePackets ( )

Receive a packet at TCP level.

Returns
Whether at least one packet was received.

Definition at line 190 of file tcp_content.cpp.

Referenced by ClientNetworkContentSocketHandler::SendReceive().


The documentation for this class was generated from the following files: