mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-22 07:13:07 +01:00
Move network units to OpenRCT2::Network namespace
This commit is contained in:
@@ -24,16 +24,13 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <discord_rpc.h>
|
#include <discord_rpc.h>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
constexpr const char* kApplicationID = "378612438200877056";
|
constexpr const char* kApplicationID = "378612438200877056";
|
||||||
constexpr const char* kSteamAppID = nullptr;
|
constexpr const char* kSteamAppID = nullptr;
|
||||||
constexpr auto kRefreshInterval = 5.0s;
|
constexpr auto kRefreshInterval = 5.0s;
|
||||||
} // namespace
|
|
||||||
|
|
||||||
static void OnReady([[maybe_unused]] const DiscordUser* request)
|
static void OnReady([[maybe_unused]] const DiscordUser* request)
|
||||||
{
|
{
|
||||||
@@ -149,5 +146,6 @@ void DiscordService::RefreshPresence() const
|
|||||||
|
|
||||||
Discord_UpdatePresence(&discordPresence);
|
Discord_UpdatePresence(&discordPresence);
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class DiscordService final
|
class DiscordService final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -29,5 +31,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void RefreshPresence() const;
|
void RefreshPresence() const;
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,12 +19,6 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
constexpr uint16_t kNetworkDefaultPort = 11753;
|
|
||||||
constexpr uint16_t kNetworkLanBroadcastPort = 11754;
|
|
||||||
constexpr const char* kNetworkLanBroadcastMsg = "openrct2.server.query";
|
|
||||||
constexpr const char* kMasterServerURL = "https://servers.openrct2.io";
|
|
||||||
constexpr uint16_t kMaxServerDescriptionLength = 256;
|
|
||||||
|
|
||||||
struct Peep;
|
struct Peep;
|
||||||
struct CoordsXYZ;
|
struct CoordsXYZ;
|
||||||
|
|
||||||
@@ -36,6 +30,14 @@ namespace OpenRCT2::GameActions
|
|||||||
class Result;
|
class Result;
|
||||||
} // namespace OpenRCT2::GameActions
|
} // namespace OpenRCT2::GameActions
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
|
constexpr uint16_t kNetworkDefaultPort = 11753;
|
||||||
|
constexpr uint16_t kNetworkLanBroadcastPort = 11754;
|
||||||
|
constexpr const char* kNetworkLanBroadcastMsg = "openrct2.server.query";
|
||||||
|
constexpr const char* kMasterServerURL = "https://servers.openrct2.io";
|
||||||
|
constexpr uint16_t kMaxServerDescriptionLength = 256;
|
||||||
|
|
||||||
enum class NetworkPermission : uint32_t;
|
enum class NetworkPermission : uint32_t;
|
||||||
|
|
||||||
void NetworkReconnect();
|
void NetworkReconnect();
|
||||||
@@ -118,3 +120,4 @@ void NetworkAppendServerLog(const utf8* text);
|
|||||||
[[nodiscard]] NetworkStats NetworkGetStats();
|
[[nodiscard]] NetworkStats NetworkGetStats();
|
||||||
[[nodiscard]] NetworkServerState NetworkGetServerState();
|
[[nodiscard]] NetworkServerState NetworkGetServerState();
|
||||||
[[nodiscard]] json_t NetworkGetServerInfoAsJson();
|
[[nodiscard]] json_t NetworkGetServerInfoAsJson();
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
NetworkPermission NetworkActions::FindCommand(GameCommand command)
|
NetworkPermission NetworkActions::FindCommand(GameCommand command)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(Actions.begin(), Actions.end(), [&command](NetworkAction const& action) {
|
auto it = std::find_if(Actions.begin(), Actions.end(), [&command](NetworkAction const& action) {
|
||||||
@@ -265,5 +267,6 @@ const std::array<NetworkAction, static_cast<size_t>(NetworkPermission::Count)> N
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum class NetworkPermission : uint32_t
|
enum class NetworkPermission : uint32_t
|
||||||
{
|
{
|
||||||
Chat,
|
Chat,
|
||||||
@@ -61,3 +63,4 @@ public:
|
|||||||
static NetworkPermission FindCommand(GameCommand command);
|
static NetworkPermission FindCommand(GameCommand command);
|
||||||
static NetworkPermission FindCommandByPermissionName(const std::string& permission_name);
|
static NetworkPermission FindCommandByPermissionName(const std::string& permission_name);
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -43,8 +43,6 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
|
||||||
|
|
||||||
// This string specifies which version of network stream current build uses.
|
// This string specifies which version of network stream current build uses.
|
||||||
// It is used for making sure only compatible builds get connected, even within
|
// It is used for making sure only compatible builds get connected, even within
|
||||||
// single OpenRCT2 version.
|
// single OpenRCT2 version.
|
||||||
@@ -567,7 +565,8 @@ void NetworkBase::UpdateClient()
|
|||||||
|
|
||||||
auto intent = Intent(WindowClass::NetworkStatus);
|
auto intent = Intent(WindowClass::NetworkStatus);
|
||||||
intent.PutExtra(INTENT_EXTRA_MESSAGE, std::string{ str_resolving });
|
intent.PutExtra(INTENT_EXTRA_MESSAGE, std::string{ str_resolving });
|
||||||
intent.PutExtra(INTENT_EXTRA_CALLBACK, []() -> void { ::GetContext()->GetNetwork().Close(); });
|
intent.PutExtra(
|
||||||
|
INTENT_EXTRA_CALLBACK, []() -> void { OpenRCT2::GetContext()->GetNetwork().Close(); });
|
||||||
ContextOpenIntent(&intent);
|
ContextOpenIntent(&intent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -582,7 +581,8 @@ void NetworkBase::UpdateClient()
|
|||||||
|
|
||||||
auto intent = Intent(WindowClass::NetworkStatus);
|
auto intent = Intent(WindowClass::NetworkStatus);
|
||||||
intent.PutExtra(INTENT_EXTRA_MESSAGE, std::string{ str_connecting });
|
intent.PutExtra(INTENT_EXTRA_MESSAGE, std::string{ str_connecting });
|
||||||
intent.PutExtra(INTENT_EXTRA_CALLBACK, []() -> void { ::GetContext()->GetNetwork().Close(); });
|
intent.PutExtra(
|
||||||
|
INTENT_EXTRA_CALLBACK, []() -> void { OpenRCT2::GetContext()->GetNetwork().Close(); });
|
||||||
ContextOpenIntent(&intent);
|
ContextOpenIntent(&intent);
|
||||||
|
|
||||||
server_connect_time = Platform::GetTicks();
|
server_connect_time = Platform::GetTicks();
|
||||||
@@ -635,7 +635,8 @@ void NetworkBase::UpdateClient()
|
|||||||
if (_serverConnection->GetLastDisconnectReason())
|
if (_serverConnection->GetLastDisconnectReason())
|
||||||
{
|
{
|
||||||
const char* disconnect_reason = _serverConnection->GetLastDisconnectReason();
|
const char* disconnect_reason = _serverConnection->GetLastDisconnectReason();
|
||||||
FormatStringLegacy(str_disconnected, 256, STR_MULTIPLAYER_DISCONNECTED_WITH_REASON, &disconnect_reason);
|
FormatStringLegacy(
|
||||||
|
str_disconnected, 256, STR_MULTIPLAYER_DISCONNECTED_WITH_REASON, &disconnect_reason);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -790,8 +791,8 @@ void NetworkBase::SendPacketToClients(const NetworkPacket& packet, bool front, b
|
|||||||
{
|
{
|
||||||
// If marked as game command we can not send the packet to connections that are not fully connected.
|
// If marked as game command we can not send the packet to connections that are not fully connected.
|
||||||
// Sending the packet would cause the client to store a command that is behind the tick where he starts,
|
// Sending the packet would cause the client to store a command that is behind the tick where he starts,
|
||||||
// which would be essentially never executed. The clients do not require commands before the server has not sent the
|
// which would be essentially never executed. The clients do not require commands before the server has not sent
|
||||||
// map data.
|
// the map data.
|
||||||
if (client_connection->Player == nullptr)
|
if (client_connection->Player == nullptr)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -826,7 +827,8 @@ bool NetworkBase::CheckSRAND(uint32_t tick, uint32_t srand0)
|
|||||||
std::string clientSpriteHash = checksum.ToString();
|
std::string clientSpriteHash = checksum.ToString();
|
||||||
if (clientSpriteHash != storedTick.spriteHash)
|
if (clientSpriteHash != storedTick.spriteHash)
|
||||||
{
|
{
|
||||||
LOG_INFO("Sprite hash mismatch, client = %s, server = %s", clientSpriteHash.c_str(), storedTick.spriteHash.c_str());
|
LOG_INFO(
|
||||||
|
"Sprite hash mismatch, client = %s, server = %s", clientSpriteHash.c_str(), storedTick.spriteHash.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -994,8 +996,8 @@ uint8_t NetworkBase::GetGroupIDByHash(const std::string& keyhash)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_WARNING(
|
LOG_WARNING(
|
||||||
"User %s is assigned to non-existent group %u. Assigning to default group (%u)", keyhash.c_str(), assignedGroup,
|
"User %s is assigned to non-existent group %u. Assigning to default group (%u)", keyhash.c_str(),
|
||||||
groupId);
|
assignedGroup, groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return groupId;
|
return groupId;
|
||||||
@@ -1120,7 +1122,8 @@ void NetworkBase::LoadGroups()
|
|||||||
group_list.at(0)->ActionsAllowed.fill(0xFF);
|
group_list.at(0)->ActionsAllowed.fill(0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NetworkBase::BeginLog(const std::string& directory, const std::string& midName, const std::string& filenameFormat)
|
std::string NetworkBase::BeginLog(
|
||||||
|
const std::string& directory, const std::string& midName, const std::string& filenameFormat)
|
||||||
{
|
{
|
||||||
utf8 filename[256];
|
utf8 filename[256];
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@@ -2556,7 +2559,8 @@ void NetworkBase::Client_Handle_GAMESTATE(NetworkConnection& connection, Network
|
|||||||
{
|
{
|
||||||
GameStateCompareData cmpData = snapshots->Compare(serverSnapshot, *desyncSnapshot);
|
GameStateCompareData cmpData = snapshots->Compare(serverSnapshot, *desyncSnapshot);
|
||||||
|
|
||||||
std::string outputPath = GetContext().GetPlatformEnvironment().GetDirectoryPath(DirBase::user, DirId::desyncLogs);
|
std::string outputPath = GetContext().GetPlatformEnvironment().GetDirectoryPath(
|
||||||
|
DirBase::user, DirId::desyncLogs);
|
||||||
|
|
||||||
Path::CreateDirectory(outputPath);
|
Path::CreateDirectory(outputPath);
|
||||||
|
|
||||||
@@ -3657,7 +3661,8 @@ GameActions::Result NetworkModifyGroups(
|
|||||||
{
|
{
|
||||||
if (groupId == 0)
|
if (groupId == 0)
|
||||||
{
|
{
|
||||||
return GameActions::Result(GameActions::Status::Disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
|
return GameActions::Result(
|
||||||
|
GameActions::Status::Disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
|
||||||
}
|
}
|
||||||
for (const auto& it : network.player_list)
|
for (const auto& it : network.player_list)
|
||||||
{
|
{
|
||||||
@@ -3677,7 +3682,8 @@ GameActions::Result NetworkModifyGroups(
|
|||||||
{
|
{
|
||||||
if (groupId == 0)
|
if (groupId == 0)
|
||||||
{ // can't change admin group permissions
|
{ // can't change admin group permissions
|
||||||
return GameActions::Result(GameActions::Status::Disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
|
return GameActions::Result(
|
||||||
|
GameActions::Status::Disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
|
||||||
}
|
}
|
||||||
NetworkGroup* mygroup = nullptr;
|
NetworkGroup* mygroup = nullptr;
|
||||||
NetworkPlayer* player = network.GetPlayerByID(actionPlayerId);
|
NetworkPlayer* player = network.GetPlayerByID(actionPlayerId);
|
||||||
@@ -3780,7 +3786,8 @@ GameActions::Result NetworkKickPlayer(NetworkPlayerId_t playerId, bool isExecuti
|
|||||||
{
|
{
|
||||||
// Player might be already removed by the PLAYERLIST command, need to refactor non-game commands executing too
|
// Player might be already removed by the PLAYERLIST command, need to refactor non-game commands executing too
|
||||||
// early.
|
// early.
|
||||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PLAYER_NOT_FOUND);
|
return GameActions::Result(
|
||||||
|
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PLAYER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->Flags & NETWORK_PLAYER_FLAG_ISSERVER)
|
if (player->Flags & NETWORK_PLAYER_FLAG_ISSERVER)
|
||||||
@@ -4086,7 +4093,13 @@ json_t NetworkGetServerInfoAsJson()
|
|||||||
auto& network = GetContext()->GetNetwork();
|
auto& network = GetContext()->GetNetwork();
|
||||||
return network.GetServerInfoAsJson();
|
return network.GetServerInfoAsJson();
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
|
#else // DISABLE_NETWORK
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
int32_t NetworkGetMode()
|
int32_t NetworkGetMode()
|
||||||
{
|
{
|
||||||
return NETWORK_MODE_NONE;
|
return NETWORK_MODE_NONE;
|
||||||
@@ -4353,4 +4366,6 @@ json_t NetworkGetServerInfoAsJson()
|
|||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif /* DISABLE_NETWORK */
|
#endif /* DISABLE_NETWORK */
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace OpenRCT2
|
|||||||
struct IContext;
|
struct IContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class NetworkBase : public OpenRCT2::System
|
class NetworkBase : public OpenRCT2::System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -140,7 +142,8 @@ public: // Client
|
|||||||
void Client_Send_RequestGameState(uint32_t tick);
|
void Client_Send_RequestGameState(uint32_t tick);
|
||||||
void Client_Send_TOKEN();
|
void Client_Send_TOKEN();
|
||||||
void Client_Send_AUTH(
|
void Client_Send_AUTH(
|
||||||
const std::string& name, const std::string& password, const std::string& pubkey, const std::vector<uint8_t>& signature);
|
const std::string& name, const std::string& password, const std::string& pubkey,
|
||||||
|
const std::vector<uint8_t>& signature);
|
||||||
void Client_Send_CHAT(const char* text);
|
void Client_Send_CHAT(const char* text);
|
||||||
void Client_Send_GAME_ACTION(const OpenRCT2::GameActions::GameAction* action);
|
void Client_Send_GAME_ACTION(const OpenRCT2::GameActions::GameAction* action);
|
||||||
void Client_Send_PING();
|
void Client_Send_PING();
|
||||||
@@ -252,5 +255,6 @@ private: // Client Data
|
|||||||
bool _clientMapLoaded = false;
|
bool _clientMapLoaded = false;
|
||||||
ServerScriptsData _serverScriptsData{};
|
ServerScriptsData _serverScriptsData{};
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -4,9 +4,12 @@
|
|||||||
|
|
||||||
#ifndef DISABLE_NETWORK
|
#ifndef DISABLE_NETWORK
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class NetworkClient final : public NetworkBase
|
class NetworkClient final : public NetworkBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include <sfl/small_vector.hpp>
|
#include <sfl/small_vector.hpp>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
static constexpr size_t kNetworkDisconnectReasonBufSize = 256;
|
static constexpr size_t kNetworkDisconnectReasonBufSize = 256;
|
||||||
static constexpr size_t kNetworkBufferSize = (1024 * 64) - 1; // 64 KiB, maximum packet size.
|
static constexpr size_t kNetworkBufferSize = (1024 * 64) - 1; // 64 KiB, maximum packet size.
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
@@ -231,5 +231,6 @@ void NetworkConnection::RecordPacketStats(const NetworkPacket& packet, bool send
|
|||||||
Stats.bytesReceived[EnumValue(NetworkStatisticsGroup::Total)] += packetSize;
|
Stats.bytesReceived[EnumValue(NetworkStatisticsGroup::Total)] += packetSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,13 +20,15 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class NetworkPlayer;
|
|
||||||
|
|
||||||
namespace OpenRCT2
|
namespace OpenRCT2
|
||||||
{
|
{
|
||||||
struct ObjectRepositoryItem;
|
struct ObjectRepositoryItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
|
class NetworkPlayer;
|
||||||
|
|
||||||
class NetworkConnection final
|
class NetworkConnection final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,5 +68,6 @@ private:
|
|||||||
|
|
||||||
void RecordPacketStats(const NetworkPacket& packet, bool sending);
|
void RecordPacketStats(const NetworkPacket& packet, bool sending);
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
#include "NetworkAction.h"
|
#include "NetworkAction.h"
|
||||||
#include "NetworkTypes.h"
|
#include "NetworkTypes.h"
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
NetworkGroup NetworkGroup::FromJson(const json_t& jsonData)
|
NetworkGroup NetworkGroup::FromJson(const json_t& jsonData)
|
||||||
{
|
{
|
||||||
Guard::Assert(jsonData.is_object(), "NetworkGroup::FromJson expects parameter jsonData to be object");
|
Guard::Assert(jsonData.is_object(), "NetworkGroup::FromJson expects parameter jsonData to be object");
|
||||||
@@ -129,5 +129,6 @@ bool NetworkGroup::CanPerformCommand(GameCommand command) const
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum class NetworkPermission : uint32_t;
|
enum class NetworkPermission : uint32_t;
|
||||||
|
|
||||||
class NetworkGroup final
|
class NetworkGroup final
|
||||||
@@ -52,3 +54,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
NetworkKey::NetworkKey() = default;
|
NetworkKey::NetworkKey() = default;
|
||||||
NetworkKey::~NetworkKey() = default;
|
NetworkKey::~NetworkKey() = default;
|
||||||
|
|
||||||
@@ -213,5 +213,6 @@ bool NetworkKey::Verify(const uint8_t* md, const size_t len, const std::vector<u
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ namespace OpenRCT2::Crypt
|
|||||||
class RsaKey;
|
class RsaKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class NetworkKey final
|
class NetworkKey final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -45,5 +47,6 @@ private:
|
|||||||
NetworkKey(const NetworkKey&) = delete;
|
NetworkKey(const NetworkKey&) = delete;
|
||||||
std::unique_ptr<OpenRCT2::Crypt::RsaKey> _key;
|
std::unique_ptr<OpenRCT2::Crypt::RsaKey> _key;
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
NetworkPacket::NetworkPacket(NetworkCommand id) noexcept
|
NetworkPacket::NetworkPacket(NetworkCommand id) noexcept
|
||||||
: Header{ 0, id }
|
: Header{ 0, id }
|
||||||
{
|
{
|
||||||
@@ -107,5 +109,6 @@ std::string_view NetworkPacket::ReadString()
|
|||||||
|
|
||||||
return std::string_view(str, stringLen);
|
return std::string_view(str, stringLen);
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <sfl/small_vector.hpp>
|
#include <sfl/small_vector.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct PacketHeader
|
struct PacketHeader
|
||||||
{
|
{
|
||||||
@@ -81,3 +83,4 @@ public:
|
|||||||
size_t BytesTransferred = 0;
|
size_t BytesTransferred = 0;
|
||||||
size_t BytesRead = 0;
|
size_t BytesRead = 0;
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#include "../ui/WindowManager.h"
|
#include "../ui/WindowManager.h"
|
||||||
#include "NetworkPacket.h"
|
#include "NetworkPacket.h"
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
void NetworkPlayer::SetName(std::string_view name)
|
void NetworkPlayer::SetName(std::string_view name)
|
||||||
{
|
{
|
||||||
// 36 == 31 + strlen(" #255");
|
// 36 == 31 + strlen(" #255");
|
||||||
@@ -25,15 +27,15 @@ void NetworkPlayer::Read(NetworkPacket& packet)
|
|||||||
{
|
{
|
||||||
auto name = packet.ReadString();
|
auto name = packet.ReadString();
|
||||||
SetName(name);
|
SetName(name);
|
||||||
packet >> Id >> Flags >> Group >> LastAction >> LastActionCoord.x >> LastActionCoord.y >> LastActionCoord.z >> MoneySpent
|
packet >> Id >> Flags >> Group >> LastAction >> LastActionCoord.x >> LastActionCoord.y >> LastActionCoord.z
|
||||||
>> CommandsRan;
|
>> MoneySpent >> CommandsRan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPlayer::Write(NetworkPacket& packet)
|
void NetworkPlayer::Write(NetworkPacket& packet)
|
||||||
{
|
{
|
||||||
packet.WriteString(Name);
|
packet.WriteString(Name);
|
||||||
packet << Id << Flags << Group << LastAction << LastActionCoord.x << LastActionCoord.y << LastActionCoord.z << MoneySpent
|
packet << Id << Flags << Group << LastAction << LastActionCoord.x << LastActionCoord.y << LastActionCoord.z
|
||||||
<< CommandsRan;
|
<< MoneySpent << CommandsRan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPlayer::IncrementNumCommands()
|
void NetworkPlayer::IncrementNumCommands()
|
||||||
@@ -49,5 +51,6 @@ void NetworkPlayer::AddMoneySpent(money64 cost)
|
|||||||
auto* windowMgr = OpenRCT2::Ui::GetWindowManager();
|
auto* windowMgr = OpenRCT2::Ui::GetWindowManager();
|
||||||
windowMgr->InvalidateByNumber(WindowClass::Player, Id);
|
windowMgr->InvalidateByNumber(WindowClass::Player, Id);
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,9 +17,12 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
struct NetworkPacket;
|
|
||||||
struct Peep;
|
struct Peep;
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
|
struct NetworkPacket;
|
||||||
|
|
||||||
class NetworkPlayer final
|
class NetworkPlayer final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -48,3 +51,4 @@ public:
|
|||||||
void IncrementNumCommands();
|
void IncrementNumCommands();
|
||||||
void AddMoneySpent(money64 cost);
|
void AddMoneySpent(money64 cost);
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -4,9 +4,12 @@
|
|||||||
|
|
||||||
#ifndef DISABLE_NETWORK
|
#ifndef DISABLE_NETWORK
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class NetworkServer final : public NetworkBase
|
class NetworkServer final : public NetworkBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -34,8 +34,8 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum class MasterServerStatus
|
enum class MasterServerStatus
|
||||||
{
|
{
|
||||||
Ok = 200,
|
Ok = 200,
|
||||||
@@ -359,5 +359,6 @@ std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port)
|
|||||||
{
|
{
|
||||||
return std::make_unique<NetworkServerAdvertiser>(port);
|
return std::make_unique<NetworkServerAdvertiser>(port);
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum class AdvertiseStatus
|
enum class AdvertiseStatus
|
||||||
{
|
{
|
||||||
disabled,
|
disabled,
|
||||||
@@ -29,3 +31,4 @@ struct INetworkServerAdvertiser
|
|||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port);
|
[[nodiscard]] std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port);
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include "../core/EnumUtils.hpp"
|
#include "../core/EnumUtils.hpp"
|
||||||
#include "../ride/RideTypes.h"
|
#include "../ride/RideTypes.h"
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SERVER_EVENT_PLAYER_JOINED,
|
SERVER_EVENT_PLAYER_JOINED,
|
||||||
@@ -146,3 +148,4 @@ struct NetworkStats
|
|||||||
uint64_t bytesReceived[EnumValue(NetworkStatisticsGroup::Max)];
|
uint64_t bytesReceived[EnumValue(NetworkStatisticsGroup::Max)];
|
||||||
uint64_t bytesSent[EnumValue(NetworkStatisticsGroup::Max)];
|
uint64_t bytesSent[EnumValue(NetworkStatisticsGroup::Max)];
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
constexpr const utf8* kUserStoreFilename = "users.json";
|
constexpr const utf8* kUserStoreFilename = "users.json";
|
||||||
|
|
||||||
std::unique_ptr<NetworkUser> NetworkUser::FromJson(const json_t& jsonData)
|
std::unique_ptr<NetworkUser> NetworkUser::FromJson(const json_t& jsonData)
|
||||||
@@ -215,5 +215,6 @@ u8string NetworkUserManager::GetStorePath()
|
|||||||
auto& env = OpenRCT2::GetContext()->GetPlatformEnvironment();
|
auto& env = OpenRCT2::GetContext()->GetPlatformEnvironment();
|
||||||
return Path::Combine(env.GetDirectoryPath(OpenRCT2::DirBase::user), kUserStoreFilename);
|
return Path::Combine(env.GetDirectoryPath(OpenRCT2::DirBase::user), kUserStoreFilename);
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
class NetworkUser final
|
class NetworkUser final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -65,3 +67,4 @@ private:
|
|||||||
|
|
||||||
static u8string GetStorePath();
|
static u8string GetStorePath();
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -31,8 +31,8 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
int32_t ServerListEntry::CompareTo(const ServerListEntry& other) const
|
int32_t ServerListEntry::CompareTo(const ServerListEntry& other) const
|
||||||
{
|
{
|
||||||
const auto& a = *this;
|
const auto& a = *this;
|
||||||
@@ -155,8 +155,9 @@ void ServerList::AddOrUpdateRange(const std::vector<ServerListEntry>& entries)
|
|||||||
{
|
{
|
||||||
for (auto& existsEntry : _serverEntries)
|
for (auto& existsEntry : _serverEntries)
|
||||||
{
|
{
|
||||||
auto match = std::find_if(
|
auto match = std::find_if(entries.begin(), entries.end(), [&](const ServerListEntry& entry) {
|
||||||
entries.begin(), entries.end(), [&](const ServerListEntry& entry) { return existsEntry.Address == entry.Address; });
|
return existsEntry.Address == entry.Address;
|
||||||
|
});
|
||||||
if (match != entries.end())
|
if (match != entries.end())
|
||||||
{
|
{
|
||||||
// Keep favourites
|
// Keep favourites
|
||||||
@@ -264,7 +265,8 @@ bool ServerList::WriteFavourites(const std::vector<ServerListEntry>& entries) co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(const INetworkEndpoint& broadcastEndpoint) const
|
std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
|
||||||
|
const INetworkEndpoint& broadcastEndpoint) const
|
||||||
{
|
{
|
||||||
auto broadcastAddress = broadcastEndpoint.GetHostname();
|
auto broadcastAddress = broadcastEndpoint.GetHostname();
|
||||||
return std::async(std::launch::async, [broadcastAddress] {
|
return std::async(std::launch::async, [broadcastAddress] {
|
||||||
@@ -438,5 +440,6 @@ const char* MasterServerException::what() const noexcept
|
|||||||
static std::string localisedStatusText = LanguageGetString(StatusText);
|
static std::string localisedStatusText = LanguageGetString(StatusText);
|
||||||
return localisedStatusText.c_str();
|
return localisedStatusText.c_str();
|
||||||
}
|
}
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
struct INetworkEndpoint;
|
struct INetworkEndpoint;
|
||||||
|
|
||||||
struct ServerListEntry
|
struct ServerListEntry
|
||||||
@@ -83,3 +85,4 @@ public:
|
|||||||
|
|
||||||
const char* what() const noexcept override;
|
const char* what() const noexcept override;
|
||||||
};
|
};
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|||||||
@@ -73,6 +73,8 @@
|
|||||||
|
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
constexpr auto kConnectTimeout = std::chrono::milliseconds(3000);
|
constexpr auto kConnectTimeout = std::chrono::milliseconds(3000);
|
||||||
|
|
||||||
// RAII WSA initialisation needed for Windows
|
// RAII WSA initialisation needed for Windows
|
||||||
@@ -959,7 +961,8 @@ std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses()
|
|||||||
{
|
{
|
||||||
ifreq r;
|
ifreq r;
|
||||||
strcpy(r.ifr_name, req->ifr_name);
|
strcpy(r.ifr_name, req->ifr_name);
|
||||||
if (ioctl(sock, SIOCGIFFLAGS, &r) != -1 && (r.ifr_flags & IFF_BROADCAST) && ioctl(sock, SIOCGIFBRDADDR, &r) != -1)
|
if (ioctl(sock, SIOCGIFFLAGS, &r) != -1 && (r.ifr_flags & IFF_BROADCAST)
|
||||||
|
&& ioctl(sock, SIOCGIFBRDADDR, &r) != -1)
|
||||||
{
|
{
|
||||||
baddresses.push_back(std::make_unique<NetworkEndpoint>(&r.ifr_broadaddr, sizeof(sockaddr)));
|
baddresses.push_back(std::make_unique<NetworkEndpoint>(&r.ifr_broadaddr, sizeof(sockaddr)));
|
||||||
}
|
}
|
||||||
@@ -974,6 +977,8 @@ std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses()
|
|||||||
return baddresses;
|
return baddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
namespace OpenRCT2::Convert
|
namespace OpenRCT2::Convert
|
||||||
{
|
{
|
||||||
uint16_t HostToNetwork(uint16_t value)
|
uint16_t HostToNetwork(uint16_t value)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Network
|
||||||
|
{
|
||||||
enum class SocketStatus
|
enum class SocketStatus
|
||||||
{
|
{
|
||||||
Closed,
|
Closed,
|
||||||
@@ -100,6 +102,7 @@ public:
|
|||||||
[[nodiscard]] std::unique_ptr<ITcpSocket> CreateTcpSocket();
|
[[nodiscard]] std::unique_ptr<ITcpSocket> CreateTcpSocket();
|
||||||
[[nodiscard]] std::unique_ptr<IUdpSocket> CreateUdpSocket();
|
[[nodiscard]] std::unique_ptr<IUdpSocket> CreateUdpSocket();
|
||||||
[[nodiscard]] std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses();
|
[[nodiscard]] std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses();
|
||||||
|
} // namespace OpenRCT2::Network
|
||||||
|
|
||||||
namespace OpenRCT2::Convert
|
namespace OpenRCT2::Convert
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user