12 #ifndef NETWORK_SERVER_H 13 #define NETWORK_SERVER_H 19 #include "../thread/thread.h" 86 void GetClientName(
char *client_name,
const char *last)
const;
133 #define FOR_ALL_CLIENT_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientSocket, clientsocket_index, var, start) 139 #define FOR_ALL_CLIENT_SOCKETS(var) FOR_ALL_CLIENT_SOCKETS_FROM(var, 0) NetworkRecvStatus SendMap()
This sends the map to the client.
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p)
Tell the server we are done with this frame: uint32 Current frame counter of the client.
The client is catching up the delayed frames.
static bool AllowConnection()
Whether an connection is allowed or not at this moment.
NetworkRecvStatus SendNeedCompanyPassword()
Request the company password.
NetworkRecvStatus SendCompanyUpdate()
Send an update about the company password states.
Container for all information known about a client.
The client has downloaded the map.
NetworkRecvStatus SendJoin(ClientID client_id)
Tell that a client joined.
Internal entity of a packet.
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p)
Send an RCon command to the server: string RCon password.
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p)
Request the map from the server.
NetworkRecvStatus SendError(NetworkErrorCode error)
Send an error to the client, and close its connection.
byte last_token
The last random token we did send to verify the client is listening.
ServerNetworkGameSocketHandler(SOCKET s)
Create a new socket for the server side of the game connection.
int receive_limit
Amount of bytes that we can receive at this moment.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status)
Close the network connection due to the given status.
NetworkErrorCode
The error codes we send around in the protocols.
NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the client to execute.
The client is downloading the map.
ServerNetworkGameSocketHandler NetworkClientSocket
Make the code look slightly nicer/simpler.
ClientStatus status
Status of this client.
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci)
Send the client information about a client.
NetworkRecvStatus SendWait()
Tell the client that its put in a waiting queue.
Template for TCP listeners.
The client is authorizing with company password.
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p)
The client is quitting the game.
The client is active within in the game.
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
Send a chat message.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p)
Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p)
Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
NetworkRecvStatus SendRConResult(uint16 colour, const char *command)
Send the result of a console action.
NetworkRecvStatus SendNewGRFCheck()
Send the check for the NewGRFs.
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p)
Tell the server that we have the required GRFs.
Class for handling the server side of the game connection.
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p)
Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
The client is not connected nor active.
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p)
Try to join the server: string OpenTTD revision (norev000 if no revision).
A queue of CommandPackets.
void GetClientName(char *client_name, const char *last) const
Get the name of the client, if the user did not send it yet, Client #<no> is used.
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p)
Gives the client a new name: string New name of the client.
NetworkAddress client_address
IP-address of the client (so he can be banned)
static ServerNetworkGameSocketHandler * GetByClientID(ClientID client_id)
Return the client state given it's client-identifier.
void NetworkServerYearlyLoop()
Yearly "callback".
The client is waiting as someone else is downloading the map.
Basic functions to listen for TCP connections.
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the accepting of a connection to the server.
NetworkRecvStatus SendNeedGamePassword()
Request the game password.
The client is authorizing with game (server) password.
Must ALWAYS be on the end of this list!! (period).
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Writing a savegame directly to a number of packets.
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded)
Tell that a particular company is (not) passworded.
The client is checking NewGRFs.
byte lag_test
Byte used for lag-testing the client.
NetworkRecvStatus SendFrame()
Tell the client that they may run to a particular frame.
Base class for all PoolItems.
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p)
The client has done a command and wants us to handle it.
ClientStatus
Status of a client.
NetworkRecvStatus SendNewGame()
Tell the client we're starting a new game.
Base class for all pools.
NetworkRecvStatus SendQuit(ClientID client_id)
Tell the client another client quit.
ClientID client_id
Client identifier.
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p)
The client made an error and is quitting the game.
NetworkRecvStatus SendSync()
Request the client to sync.
NetworkRecvStatus SendWelcome()
Send the client a welcome message with some basic information.
static const char * GetName()
Get the name used by the listener.
NetworkRecvStatus SendCompanyInfo()
Send the client information about the companies.
void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed=true)
Set/Reset a company password on the server end.
Variables and function used internally.
NetworkRecvStatus SendConfigUpdate()
Send an update about the max company/spectator counts.
const char * GetClientIP()
Get the IP address/hostname of the connected client.
The client is authorized.
ClientID
'Unique' identifier to be given to clients
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p)
Request company information (in detail).
NetworkRecvStatus SendShutdown()
Tell the client we're shutting down.
NetworkClientSocketPool _networkclientsocket_pool
The pool with clients.
Everything we need to know about a command to be able to execute it.
NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id)
Tell that a client moved to another company.
NetworkRecvStatus SendErrorQuit(ClientID client_id, NetworkErrorCode errorno)
Tell the client another client quit with an error.
uint32 last_token_frame
The last frame we received the right token.
void NetworkServer_Tick(bool send_frame)
This is called every tick if this is a _network_server.
void NetworkServerMonthlyLoop()
Monthly "callback".
Base socket handler for all TCP sockets.
Owner
Enum for all companies/owners.
~ServerNetworkGameSocketHandler()
Clear everything related to this client.
Pool< NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT > NetworkClientSocketPool
Pool with all client sockets.
static void Send()
Send the packets for the server sockets.
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p)
Request the server to move this client into another company: uint8 ID of the company the client wants...
NetworkAction
Actions that can be used for NetworkTextMessage.
virtual Packet * ReceivePacket()
Receives a packet for the given client.
struct PacketWriter * savegame
Writer used to write the savegame.
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p)
Tell the server that we are done receiving/loading the map.
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p)
Set the password for the clients current company: string The password.
CommandQueue outgoing_queue
The command-queue awaiting delivery.