1 /***************************************************************************** 2 * Copyright (c) 2014-2020 OpenRCT2 developers 3 * 4 * For a complete list of all authors, please refer to contributors.md 5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 6 * 7 * OpenRCT2 is licensed under the GNU General Public License version 3. 8 *****************************************************************************/ 9 10 #pragma once 11 12 #include "../common.h" 13 #include "../core/Endianness.h" 14 #include "../ride/RideTypes.h" 15 #include "../util/Util.h" 16 17 enum 18 { 19 SERVER_EVENT_PLAYER_JOINED, 20 SERVER_EVENT_PLAYER_DISCONNECTED, 21 }; 22 23 enum 24 { 25 NETWORK_TICK_FLAG_CHECKSUMS = 1 << 0, 26 }; 27 28 enum 29 { 30 NETWORK_MODE_NONE, 31 NETWORK_MODE_CLIENT, 32 NETWORK_MODE_SERVER 33 }; 34 35 enum 36 { 37 NETWORK_PLAYER_FLAG_ISSERVER = 1 << 0, 38 }; 39 40 enum 41 { 42 NETWORK_STATUS_NONE, 43 NETWORK_STATUS_READY, 44 NETWORK_STATUS_CONNECTING, 45 NETWORK_STATUS_CONNECTED 46 }; 47 48 enum class NetworkAuth : int32_t 49 { 50 None, 51 Requested, 52 Ok, 53 BadVersion, 54 BadName, 55 BadPassword, 56 VerificationFailure, 57 Full, 58 RequirePassword, 59 Verified, 60 UnknownKeyDisallowed 61 }; 62 63 enum class NetworkCommand : uint32_t 64 { 65 Auth, 66 Map, 67 Chat, 68 Tick = 4, 69 PlayerList, 70 Ping, 71 PingList, 72 DisconnectMessage, 73 GameInfo, 74 ShowError, 75 GroupList, 76 Event, 77 Token, 78 ObjectsList, 79 MapRequest, 80 GameAction, 81 PlayerInfo, 82 RequestGameState, 83 GameState, 84 Scripts, 85 Heartbeat, 86 Max, 87 Invalid = static_cast<uint32_t>(-1), 88 }; 89 90 static_assert(NetworkCommand::GameInfo == static_cast<NetworkCommand>(9), "Master server expects this to be 9"); 91 92 enum class NetworkServerState 93 { 94 Ok, 95 Desynced 96 }; 97 98 struct NetworkServerState_t 99 { 100 NetworkServerState state = NetworkServerState::Ok; 101 uint32_t desyncTick = 0; 102 uint32_t tick = 0; 103 uint32_t srand0 = 0; 104 bool gamestateSnapshotsEnabled = false; 105 }; 106 107 // Structure is used for networking specific fields with meaning, 108 // this structure can be used in combination with DataSerialiser 109 // to provide extra details with template specialization. 110 #pragma pack(push, 1) 111 template<typename T, size_t _TypeID> struct NetworkObjectId_t 112 { NetworkObjectId_tNetworkObjectId_t113 NetworkObjectId_t(T v) 114 : id(v) 115 { 116 } NetworkObjectId_tNetworkObjectId_t117 NetworkObjectId_t() 118 : id(T(-1)) 119 { 120 } TNetworkObjectId_t121 operator T() const 122 { 123 return id; 124 } 125 T id; 126 }; 127 #pragma pack(pop) 128 129 using NetworkRideId_t = ride_id_t; 130 131 // NOTE: When adding new types make sure to have no duplicate _TypeID's otherwise 132 // there is no way to specialize templates if they have the exact symbol. 133 using NetworkPlayerId_t = NetworkObjectId_t<int32_t, 0>; 134 using NetworkCheatType_t = NetworkObjectId_t<int32_t, 2>; 135 136 enum class NetworkStatisticsGroup : uint32_t 137 { 138 Total = 0, // Entire network traffic. 139 Base, // Messages such as Tick, Ping 140 Commands, // Command / Game actions 141 MapData, 142 Max, 143 }; 144 145 struct NetworkStats_t 146 { 147 uint64_t bytesReceived[EnumValue(NetworkStatisticsGroup::Max)]; 148 uint64_t bytesSent[EnumValue(NetworkStatisticsGroup::Max)]; 149 }; 150