Maintain a circular buffer of recent commands, add to crashlog.
[openttd-joker.git] / src / network / core / core.h
blob7952e438e97d248a793499378f1486700741eca2
1 /* $Id: core.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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 */
10 /**
11 * @file core.h Base for all network types (UDP and TCP)
14 #ifndef NETWORK_CORE_CORE_H
15 #define NETWORK_CORE_CORE_H
17 #include "../../newgrf_config.h"
18 #include "config.h"
20 #ifdef ENABLE_NETWORK
22 bool NetworkCoreInitialize();
23 void NetworkCoreShutdown();
25 /** Status of a network client; reasons why a client has quit */
26 enum NetworkRecvStatus {
27 NETWORK_RECV_STATUS_OKAY, ///< Everything is okay
28 NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur
29 NETWORK_RECV_STATUS_NEWGRF_MISMATCH, ///< We did not have the required NewGRFs
30 NETWORK_RECV_STATUS_SAVEGAME, ///< Something went wrong (down)loading the savegame
31 NETWORK_RECV_STATUS_CONN_LOST, ///< The connection is 'just' lost
32 NETWORK_RECV_STATUS_MALFORMED_PACKET, ///< We apparently send a malformed packet
33 NETWORK_RECV_STATUS_SERVER_ERROR, ///< The server told us we made an error
34 NETWORK_RECV_STATUS_SERVER_FULL, ///< The server is full
35 NETWORK_RECV_STATUS_SERVER_BANNED, ///< The server has banned us
36 NETWORK_RECV_STATUS_CLOSE_QUERY, ///< Done querying the server
39 /** Forward declaration due to circular dependencies */
40 struct Packet;
42 /**
43 * SocketHandler for all network sockets in OpenTTD.
45 class NetworkSocketHandler {
46 bool has_quit; ///< Whether the current client has quit/send a bad packet
47 public:
48 /** Create a new unbound socket */
49 NetworkSocketHandler() { this->has_quit = false; }
51 /** Close the socket when destructing the socket handler */
52 virtual ~NetworkSocketHandler() { this->Close(); }
54 /** Really close the socket */
55 virtual void Close() {}
57 /**
58 * Close the current connection; for TCP this will be mostly equivalent
59 * to Close(), but for UDP it just means the packet has to be dropped.
60 * @param error Whether we quit under an error condition or not.
61 * @return new status of the connection.
63 virtual NetworkRecvStatus CloseConnection(bool error = true) { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
65 /**
66 * Whether the current client connected to the socket has quit.
67 * In the case of UDP, for example, once a client quits (send bad
68 * data), the socket in not closed; only the packet is dropped.
69 * @return true when the current client has quit, false otherwise
71 bool HasClientQuit() const { return this->has_quit; }
73 /**
74 * Reopen the socket so we can send/receive stuff again.
76 void Reopen() { this->has_quit = false; }
78 void SendGRFIdentifier(Packet *p, const GRFIdentifier *grf);
79 void ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf);
80 void SendCompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len = NETWORK_COMPANY_NAME_LENGTH);
83 #endif /* ENABLE_NETWORK */
85 #endif /* NETWORK_CORE_CORE_H */