OpenTTD
Public Member Functions | Private Attributes
NetworkSocketHandler Class Reference

SocketHandler for all network sockets in OpenTTD. More...

#include <core.h>

Inheritance diagram for NetworkSocketHandler:
NetworkHTTPSocketHandler NetworkTCPSocketHandler NetworkUDPSocketHandler NetworkAdminSocketHandler NetworkContentSocketHandler NetworkGameSocketHandler ClientNetworkUDPSocketHandler MasterNetworkUDPSocketHandler ServerNetworkUDPSocketHandler ServerNetworkAdminSocketHandler ClientNetworkContentSocketHandler ClientNetworkGameSocketHandler ServerNetworkGameSocketHandler

Public Member Functions

 NetworkSocketHandler ()
 Create a new unbound socket.
 
virtual ~NetworkSocketHandler ()
 Close the socket when destructing the socket handler.
 
virtual void Close ()
 Really close the socket.
 
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...
 
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...
 

Private Attributes

bool has_quit
 Whether the current client has quit/send a bad packet.
 

Detailed Description

SocketHandler for all network sockets in OpenTTD.

Definition at line 45 of file core.h.

Member Function Documentation

◆ CloseConnection()

virtual NetworkRecvStatus NetworkSocketHandler::CloseConnection ( bool  error = true)
inlinevirtual

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.

Parameters
errorWhether we quit under an error condition or not.
Returns
new status of the connection.

Reimplemented in NetworkGameSocketHandler, NetworkAdminSocketHandler, NetworkHTTPSocketHandler, NetworkUDPSocketHandler, and NetworkTCPSocketHandler.

Definition at line 63 of file core.h.

References NETWORK_RECV_STATUS_OKAY.

Referenced by ClientNetworkGameSocketHandler::ClientError(), NetworkTCPSocketHandler::CloseConnection(), NetworkUDPSocketHandler::CloseConnection(), and NetworkHTTPSocketHandler::CloseConnection().

◆ HasClientQuit()

bool NetworkSocketHandler::HasClientQuit ( ) const
inline

◆ ReceiveGRFIdentifier()

void NetworkSocketHandler::ReceiveGRFIdentifier ( Packet p,
GRFIdentifier grf 
)

Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.

Parameters
pthe packet to read the data from
grfthe GRFIdentifier to deserialize

Definition at line 122 of file core.cpp.

References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Recv_uint32(), and Packet::Recv_uint8().

Referenced by ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), NetworkUDPSocketHandler::ReceiveNetworkGameInfo(), and Reopen().

◆ SendCompanyInformation()

void NetworkSocketHandler::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.

Parameters
pThe packet that will contain the data.
cThe company to put the of into the packet.
statsThe statistics to put in the packet.
max_lenThe maximum length of the company name.

Definition at line 1515 of file network_server.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, NETWORK_COMPANY_NAME_LENGTH, and SetDParam().

Referenced by Reopen().

◆ SendGRFIdentifier()

void NetworkSocketHandler::SendGRFIdentifier ( Packet p,
const GRFIdentifier grf 
)

Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.

Parameters
pthe packet to write the data to
grfthe GRFIdentifier to serialize

Definition at line 108 of file core.cpp.

References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Send_uint32(), and Packet::Send_uint8().

Referenced by Reopen(), NetworkUDPSocketHandler::SendNetworkGameInfo(), and ServerNetworkGameSocketHandler::SendNewGRFCheck().


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