Fix: Data races on cursor state in OpenGL backends
[openttd-github.git] / src / network / core / core.h
blobbf83adc72cefb963406ed22cc4bcbae8e834c973
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /**
9 * @file core.h Base for all network types (UDP and TCP)
12 #ifndef NETWORK_CORE_CORE_H
13 #define NETWORK_CORE_CORE_H
15 #include "../../newgrf_config.h"
16 #include "config.h"
18 bool NetworkCoreInitialize();
19 void NetworkCoreShutdown();
21 /** Status of a network client; reasons why a client has quit */
22 enum NetworkRecvStatus {
23 NETWORK_RECV_STATUS_OKAY, ///< Everything is okay
24 NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur
25 NETWORK_RECV_STATUS_NEWGRF_MISMATCH, ///< We did not have the required NewGRFs
26 NETWORK_RECV_STATUS_SAVEGAME, ///< Something went wrong (down)loading the savegame
27 NETWORK_RECV_STATUS_CONN_LOST, ///< The connection is 'just' lost
28 NETWORK_RECV_STATUS_MALFORMED_PACKET, ///< We apparently send a malformed packet
29 NETWORK_RECV_STATUS_SERVER_ERROR, ///< The server told us we made an error
30 NETWORK_RECV_STATUS_SERVER_FULL, ///< The server is full
31 NETWORK_RECV_STATUS_SERVER_BANNED, ///< The server has banned us
32 NETWORK_RECV_STATUS_CLOSE_QUERY, ///< Done querying the server
35 /** Forward declaration due to circular dependencies */
36 struct Packet;
38 /**
39 * SocketHandler for all network sockets in OpenTTD.
41 class NetworkSocketHandler {
42 bool has_quit; ///< Whether the current client has quit/send a bad packet
43 public:
44 /** Create a new unbound socket */
45 NetworkSocketHandler() { this->has_quit = false; }
47 /** Close the socket when destructing the socket handler */
48 virtual ~NetworkSocketHandler() { this->Close(); }
50 /** Really close the socket */
51 virtual void Close() {}
53 /**
54 * Close the current connection; for TCP this will be mostly equivalent
55 * to Close(), but for UDP it just means the packet has to be dropped.
56 * @param error Whether we quit under an error condition or not.
57 * @return new status of the connection.
59 virtual NetworkRecvStatus CloseConnection(bool error = true) { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
61 /**
62 * Whether the current client connected to the socket has quit.
63 * In the case of UDP, for example, once a client quits (send bad
64 * data), the socket in not closed; only the packet is dropped.
65 * @return true when the current client has quit, false otherwise
67 bool HasClientQuit() const { return this->has_quit; }
69 /**
70 * Reopen the socket so we can send/receive stuff again.
72 void Reopen() { this->has_quit = false; }
74 void SendGRFIdentifier(Packet *p, const GRFIdentifier *grf);
75 void ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf);
76 void SendCompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len = NETWORK_COMPANY_NAME_LENGTH);
79 #endif /* NETWORK_CORE_CORE_H */