Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / network / network_internal.h
blob2c6639961dd0f6129f9f2551c5a33babed47ac76
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 /** @file network_internal.h Variables and function used internally. */
10 #ifndef NETWORK_INTERNAL_H
11 #define NETWORK_INTERNAL_H
13 #include "network_func.h"
14 #include "core/tcp_coordinator.h"
15 #include "core/tcp_game.h"
17 #include "../command_type.h"
19 #ifdef RANDOM_DEBUG
20 /**
21 * If this line is enable, every frame will have a sync test
22 * this is not needed in normal games. Normal is like 1 sync in 100
23 * frames. You can enable this if you have a lot of desyncs on a certain
24 * game.
25 * Remember: both client and server have to be compiled with this
26 * option enabled to make it to work. If one of the two has it disabled
27 * nothing will happen.
29 #define ENABLE_NETWORK_SYNC_EVERY_FRAME
31 /**
32 * In theory sending 1 of the 2 seeds is enough to check for desyncs
33 * so in theory, this next define can be left off.
35 #define NETWORK_SEND_DOUBLE_SEED
36 #endif /* RANDOM_DEBUG */
38 /**
39 * Helper variable to make the dedicated server go fast until the (first) join.
40 * Used to load the desync debug logs, i.e. for reproducing a desync.
41 * There's basically no need to ever enable this, unless you really know what
42 * you are doing, i.e. debugging a desync.
43 * See docs/desync.txt for details.
45 #ifdef DEBUG_DUMP_COMMANDS
46 extern bool _ddc_fastforward;
47 #else
48 #define _ddc_fastforward (false)
49 #endif /* DEBUG_DUMP_COMMANDS */
51 typedef class ServerNetworkGameSocketHandler NetworkClientSocket;
53 /** Status of the clients during joining. */
54 enum NetworkJoinStatus {
55 NETWORK_JOIN_STATUS_CONNECTING,
56 NETWORK_JOIN_STATUS_AUTHORIZING,
57 NETWORK_JOIN_STATUS_WAITING,
58 NETWORK_JOIN_STATUS_DOWNLOADING,
59 NETWORK_JOIN_STATUS_PROCESSING,
60 NETWORK_JOIN_STATUS_REGISTERING,
62 NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
63 NETWORK_JOIN_STATUS_END,
66 extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
67 extern uint32 _frame_counter_max; // To where we may go with our clients
68 extern uint32 _frame_counter;
70 extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
72 /* networking settings */
73 extern NetworkAddressList _broadcast_list;
75 extern uint32 _sync_seed_1;
76 #ifdef NETWORK_SEND_DOUBLE_SEED
77 extern uint32 _sync_seed_2;
78 #endif
79 extern uint32 _sync_frame;
80 extern bool _network_first_time;
81 /* Vars needed for the join-GUI */
82 extern NetworkJoinStatus _network_join_status;
83 extern uint8 _network_join_waiting;
84 extern uint32 _network_join_bytes;
85 extern uint32 _network_join_bytes_total;
86 extern ConnectionType _network_server_connection_type;
87 extern std::string _network_server_invite_code;
89 extern uint8 _network_reconnect;
91 extern CompanyMask _network_company_passworded;
93 void NetworkQueryServer(const std::string &connection_string);
94 void NetworkQueryLobbyServer(const std::string &connection_string);
96 void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
97 struct NetworkGameList *NetworkAddServer(const std::string &connection_string, bool manually = true, bool never_expire = false);
98 void NetworkRebuildHostList();
99 void UpdateNetworkGameWindow();
101 /* From network_command.cpp */
103 * Everything we need to know about a command to be able to execute it.
105 struct CommandPacket : CommandContainer {
106 /** Make sure the pointer is nullptr. */
107 CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
108 CommandPacket *next; ///< the next command packet (if in queue)
109 CompanyID company; ///< company that is executing the command
110 uint32 frame; ///< the frame in which this packet is executed
111 bool my_cmd; ///< did the command originate from "me"
114 void NetworkDistributeCommands();
115 void NetworkExecuteLocalCommandQueue();
116 void NetworkFreeLocalCommandQueue();
117 void NetworkSyncCommandQueue(NetworkClientSocket *cs);
119 void ShowNetworkError(StringID error_string);
120 void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", int64 data = 0);
121 uint NetworkCalculateLag(const NetworkClientSocket *cs);
122 StringID GetNetworkErrorMsg(NetworkErrorCode err);
123 bool NetworkMakeClientNameUnique(std::string &new_name);
124 std::string GenerateCompanyPasswordHash(const std::string &password, const std::string &password_server_id, uint32 password_game_seed);
126 std::string_view ParseCompanyFromConnectionString(const std::string &connection_string, CompanyID *company_id);
127 NetworkAddress ParseConnectionString(const std::string &connection_string, uint16 default_port);
128 std::string NormalizeConnectionString(const std::string &connection_string, uint16 default_port);
130 #endif /* NETWORK_INTERNAL_H */