OpenTTD
network_client.h
Go to the documentation of this file.
1 /* $Id: network_client.h 24900 2013-01-08 22:46:42Z planetmaker $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef NETWORK_CLIENT_H
13 #define NETWORK_CLIENT_H
14 
15 #ifdef ENABLE_NETWORK
16 
17 #include "network_internal.h"
18 
21 private:
23  byte token;
24 
26  enum ServerStatus {
38  };
39 
41 
42 protected:
43  friend void NetworkExecuteLocalCommandQueue();
44  friend void NetworkClose(bool close_admins);
46 
74 
78  void CheckConnection();
79 public:
82 
85 
87 
88  static NetworkRecvStatus SendJoin();
91  static NetworkRecvStatus SendQuit();
92  static NetworkRecvStatus SendAck();
93 
94  static NetworkRecvStatus SendGamePassword(const char *password);
95  static NetworkRecvStatus SendCompanyPassword(const char *password);
96 
97  static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
98  static NetworkRecvStatus SendSetPassword(const char *password);
99  static NetworkRecvStatus SendSetName(const char *name);
100  static NetworkRecvStatus SendRCon(const char *password, const char *command);
101  static NetworkRecvStatus SendMove(CompanyID company, const char *password);
102 
103  static bool IsConnected();
104 
105  static void Send();
106  static bool Receive();
107  static bool GameLoop();
108 };
109 
112 
114 void NetworkClientSetCompanyPassword(const char *password);
115 
117 
118 extern const char *_network_join_server_password;
119 extern const char *_network_join_company_password;
120 
121 #endif /* ENABLE_NETWORK */
122 
123 #endif /* NETWORK_CLIENT_H */
We are trying to get company information.
The client is not connected nor active.
Must ALWAYS be on the end of this list!! (period)
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p)
Notification that another client is currently receiving the map: uint8 Number of clients waiting in f...
struct PacketReader * savegame
Packet reader for reading the savegame.
Internal entity of a packet.
Definition: packet.h:44
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
static bool Receive()
Check whether we received/can send some data from/to the server and when that&#39;s the case handle it ap...
The client is authorized at the server.
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p)
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
ServerStatus
Status of the connection with the server.
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p)
Let the clients know that the server is closing.
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p)
Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p)
Let the clients know that the server is loading a new map.
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:104
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p)
Notification that the server is full.
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p)
Send information about a client: uint32 ID of the client (always unique on a server.
const char * _network_join_server_password
Login password from -p argument.
ClientNetworkGameSocketHandler(SOCKET s)
Create a new socket for the client side of the game connection.
static NetworkRecvStatus SendSetPassword(const char *password)
Tell the server that we like to change the password of the company.
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p)
Notification that a client left the game: uint32 ID of the client.
Class for handling the client side of the game connection.
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p)
Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repe...
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p)
The client is joined and ready to receive his map: uint32 Own client ID.
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p)
The client made an error: uint8 Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p)
Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
CompanyID _network_join_as
Who would we like to join as.
~ClientNetworkGameSocketHandler()
Clear whatever we assigned.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server&#39;s ticks.
void NetworkClientSetCompanyPassword(const char *password)
Set/Reset company password on the client side.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
Read some packets, and when do use that data as initial load filter.
void CheckConnection()
Check the connection&#39;s state, i.e.
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
The client is waiting as someone else is downloading the map.
friend void NetworkClose(bool close_admins)
Close current connections.
Definition: network.cpp:530
static ClientNetworkGameSocketHandler * my_client
This is us!
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:26
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p)
Sends information about the companies (one packet per company): uint8 Version of the structure of thi...
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p)
Update the clients knowledge of which company is password protected: uint16 Bitwise representation of...
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p)
Sends the data of the map to the client: Contains a part of the map (until max size of packet)...
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:150
ServerStatus status
Status of the connection with the server.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status)
Close the network connection due to the given status.
static NetworkRecvStatus SendRCon(const char *password, const char *command)
Send a console command.
static NetworkRecvStatus SendMove(CompanyID company, const char *password)
Ask the server to move us.
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p)
Indication to the client that the server needs a company password: uint32 Generation seed...
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p)
Notification that the client trying to join is banned.
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p)
Move a client from one company into another: uint32 ID of the client.
static NetworkRecvStatus SendCompanyInformationQuery()
Query the server for company information.
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p)
Sends a sync-check to the client: uint32 Frame counter.
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p)
Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of th...
Variables and function used internally.
void NetworkClient_Connected()
Is called after a client is connected to the server.
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p)
Indication to the client that the server needs a game password.
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p)
Sends that the server will begin with sending the map to the client: uint32 Current frame...
The client is active within in the game.
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p)
Send the result of an issues RCon command back to the client: uint16 Colour code. ...
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
We are trying to join a server.
Everything we need to know about a command to be able to execute it.
static void Send()
Send the packets of this socket handler.
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p)
Sends that all data of the map are sent to the client:
const char * _network_join_company_password
Company password from -P argument.
ClientNetworkGameSocketHandler MyClient
Helper to make the code look somewhat nicer.
static NetworkRecvStatus SendSetName(const char *name)
Tell the server that we like to change the name of the client.
The client is downloading the map.
static NetworkRecvStatus SendGetMap()
Request the map from the server.
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
Last action was requesting game (server) password.
Base socket handler for all TCP sockets.
Definition: tcp_game.h:152
Owner
Enum for all companies/owners.
Definition: company_type.h:20
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p)
Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far...
Last action was requesting company password.
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat-packet over the network.
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p)
Sends the size of the map to the client.
static bool GameLoop()
Actual game loop for the client.
byte token
The token we need to send back to the server to prove we&#39;re the right client.
DestType
Destination of our chat messages.
Definition: network_type.h:82
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:89
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p)
Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed...