OpenTTD Source: NetworkSocketHandler Class Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Protected Attributes | Private Attributes | Friends
NetworkSocketHandler Class Reference

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

`#include <core.h>`

Inheritance diagram for NetworkSocketHandler:

## Public Member Functions
| NetworkSocketHandler ()
| Create a new unbound socket.
virtual | ~NetworkSocketHandler ()=default
| Close the socket when destructing the socket handler.
void | MarkClosed ()
| Mark the connection as closed.
bool | HasClientQuit () const
| Whether the current client connected to the socket has quit.
void | Reopen ()
| Reopen the socket so we can send/receive stuff again.

## Protected Attributes
std::unique_ptr< class NetworkEncryptionHandler > | receive_encryption_handler
| The handler for decrypting received packets.
std::unique_ptr< class NetworkEncryptionHandler > | send_encryption_handler
| The handler for encrypting sent packets.

## Private Attributes
bool | has_quit
| Whether the current client has quit/send a bad packet.

## Friends
struct | Packet

## Detailed Description

SocketHandler for all network sockets in OpenTTD.

Definition at line 43 of file core.h.

## Constructor & Destructor Documentation

## ◆ NetworkSocketHandler()

NetworkSocketHandler::NetworkSocketHandler | ( |  | ) |
| inline

Create a new unbound socket.

Definition at line 54 of file core.h.

## Member Function Documentation

## ◆ HasClientQuit()

bool NetworkSocketHandler::HasClientQuit | ( |  | ) | const
| inline

Whether the current client connected to the socket has quit.

In the case of UDP, for example, once a client quits (send bad data), the socket in not closed; only the packet is dropped.

Returns
  true when the current client has quit, false otherwise

Definition at line 74 of file core.h.

References has_quit.

Referenced by Packet::CanReadFromPacket(), ClientNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::CloseConnection(), NetworkAdminSocketHandler::HandlePacket(), NetworkContentSocketHandler::HandlePacket(), NetworkGameSocketHandler::HandlePacket(), NetworkUDPSocketHandler::HandleUDPPacket(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(), ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(), and ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO().

## ◆ MarkClosed()

void NetworkSocketHandler::MarkClosed | ( |  | ) |
| inline

Mark the connection as closed.

This doesn't mean the actual connection is closed, but just that we act like it is. This is useful for UDP, which doesn't normally close a socket, but its handler might need to pretend it does.

Definition at line 66 of file core.h.

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

## ◆ Reopen()

void NetworkSocketHandler::Reopen | ( |  | ) |
| inline

Reopen the socket so we can send/receive stuff again.

Definition at line 79 of file core.h.

Referenced by NetworkUDPSocketHandler::HandleUDPPacket(), and NetworkContentConnecter::OnConnect().

## Friends And Related Symbol Documentation

## ◆ Packet

friend struct Packet
| friend

Definition at line 48 of file core.h.

## Field Documentation

## ◆ has_quit

bool NetworkSocketHandler::has_quit
| private

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

Definition at line 45 of file core.h.

Referenced by HasClientQuit().

## ◆ receive_encryption_handler

std::unique_ptr<class NetworkEncryptionHandler> NetworkSocketHandler::receive_encryption_handler
| protected

The handler for decrypting received packets.

Definition at line 49 of file core.h.

Referenced by Packet::PrepareToRead(), ServerNetworkAdminSocketHandler::Receive_ADMIN_AUTH_RESPONSE(), ServerNetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE(), and ClientNetworkGameSocketHandler::Receive_SERVER_ENABLE_ENCRYPTION().

## ◆ send_encryption_handler

std::unique_ptr<class NetworkEncryptionHandler> NetworkSocketHandler::send_encryption_handler
| protected

The handler for encrypting sent packets.

Definition at line 50 of file core.h.

Referenced by Packet::GetPacketType(), Packet::Packet(), Packet::PrepareToSend(), ServerNetworkAdminSocketHandler::Receive_ADMIN_AUTH_RESPONSE(), ServerNetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE(), and ClientNetworkGameSocketHandler::Receive_SERVER_ENABLE_ENCRYPTION().

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

- src/network/core/core.h