mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-22 23:33:04 +01:00
Drop 'Network' from namespaced network constants
This commit is contained in:
@@ -547,7 +547,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
void JoinServer(std::string address)
|
void JoinServer(std::string address)
|
||||||
{
|
{
|
||||||
int32_t port = Network::kNetworkDefaultPort;
|
int32_t port = Network::kDefaultPort;
|
||||||
auto endBracketIndex = address.find(']');
|
auto endBracketIndex = address.find(']');
|
||||||
auto colonIndex = address.find_last_of(':');
|
auto colonIndex = address.find_last_of(':');
|
||||||
if (colonIndex != std::string::npos)
|
if (colonIndex != std::string::npos)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ using namespace OpenRCT2;
|
|||||||
#ifndef DISABLE_NETWORK
|
#ifndef DISABLE_NETWORK
|
||||||
Network::Mode gNetworkStart = Network::Mode::none;
|
Network::Mode gNetworkStart = Network::Mode::none;
|
||||||
std::string gNetworkStartHost;
|
std::string gNetworkStartHost;
|
||||||
int32_t gNetworkStartPort = Network::kNetworkDefaultPort;
|
int32_t gNetworkStartPort = Network::kDefaultPort;
|
||||||
std::string gNetworkStartAddress;
|
std::string gNetworkStartAddress;
|
||||||
|
|
||||||
static uint32_t _port = 0;
|
static uint32_t _port = 0;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ static exitcode_t HandleUriJoin(const std::vector<std::string>& args)
|
|||||||
{
|
{
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
int32_t port;
|
int32_t port;
|
||||||
if (args.size() > 1 && TryParseHostnamePort(args[1], &hostname, &port, Network::kNetworkDefaultPort))
|
if (args.size() > 1 && TryParseHostnamePort(args[1], &hostname, &port, Network::kDefaultPort))
|
||||||
{
|
{
|
||||||
// Set the network start configuration
|
// Set the network start configuration
|
||||||
gNetworkStart = Network::Mode::client;
|
gNetworkStart = Network::Mode::client;
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ namespace OpenRCT2::Config
|
|||||||
|
|
||||||
auto model = &_config.network;
|
auto model = &_config.network;
|
||||||
model->PlayerName = std::move(playerName);
|
model->PlayerName = std::move(playerName);
|
||||||
model->DefaultPort = reader->GetInt32("default_port", ::Network::kNetworkDefaultPort);
|
model->DefaultPort = reader->GetInt32("default_port", ::Network::kDefaultPort);
|
||||||
model->ListenAddress = reader->GetString("listen_address", "");
|
model->ListenAddress = reader->GetString("listen_address", "");
|
||||||
model->DefaultPassword = reader->GetString("default_password", "");
|
model->DefaultPassword = reader->GetString("default_password", "");
|
||||||
model->StayConnected = reader->GetBoolean("stay_connected", true);
|
model->StayConnected = reader->GetBoolean("stay_connected", true);
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ namespace OpenRCT2::GameActions
|
|||||||
|
|
||||||
namespace OpenRCT2::Network
|
namespace OpenRCT2::Network
|
||||||
{
|
{
|
||||||
constexpr uint16_t kNetworkDefaultPort = 11753;
|
constexpr uint16_t kDefaultPort = 11753;
|
||||||
constexpr uint16_t kNetworkLanBroadcastPort = 11754;
|
constexpr uint16_t kLanBroadcastPort = 11754;
|
||||||
constexpr const char* kNetworkLanBroadcastMsg = "openrct2.server.query";
|
constexpr const char* kLanBroadcastMsg = "openrct2.server.query";
|
||||||
constexpr const char* kMasterServerURL = "https://servers.openrct2.io";
|
constexpr const char* kMasterServerURL = "https://servers.openrct2.io";
|
||||||
constexpr uint16_t kMaxServerDescriptionLength = 256;
|
constexpr uint16_t kMaxServerDescriptionLength = 256;
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,9 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
constexpr uint8_t kNetworkStreamVersion = 1;
|
constexpr uint8_t kStreamVersion = 1;
|
||||||
|
|
||||||
const std::string kNetworkStreamID = std::string(kOpenRCT2Version) + "-" + std::to_string(kNetworkStreamVersion);
|
const std::string kStreamID = std::string(kOpenRCT2Version) + "-" + std::to_string(kStreamVersion);
|
||||||
|
|
||||||
static Peep* _pickup_peep = nullptr;
|
static Peep* _pickup_peep = nullptr;
|
||||||
static int32_t _pickup_peep_old_x = kLocationNull;
|
static int32_t _pickup_peep_old_x = kLocationNull;
|
||||||
@@ -4073,7 +4073,7 @@ namespace OpenRCT2::Network
|
|||||||
|
|
||||||
std::string GetVersion()
|
std::string GetVersion()
|
||||||
{
|
{
|
||||||
return kNetworkStreamID;
|
return kStreamID;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stats GetStats()
|
Stats GetStats()
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
namespace OpenRCT2::Network
|
namespace OpenRCT2::Network
|
||||||
{
|
{
|
||||||
static constexpr size_t kNetworkDisconnectReasonBufSize = 256;
|
static constexpr size_t kDisconnectReasonBufSize = 256;
|
||||||
static constexpr size_t kNetworkBufferSize = (1024 * 64) - 1; // 64 KiB, maximum packet size.
|
static constexpr size_t kBufferSize = (1024 * 64) - 1; // 64 KiB, maximum packet size.
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
static constexpr size_t kNetworkNoDataTimeout = 20; // Seconds.
|
static constexpr size_t kNoDataTimeout = 20; // Seconds.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static_assert(kNetworkBufferSize <= std::numeric_limits<uint16_t>::max(), "kNetworkBufferSize too big, uint16_t is max.");
|
static_assert(kBufferSize <= std::numeric_limits<uint16_t>::max(), "kBufferSize too big, uint16_t is max.");
|
||||||
|
|
||||||
NetworkConnection::NetworkConnection() noexcept
|
NetworkConnection::NetworkConnection() noexcept
|
||||||
{
|
{
|
||||||
@@ -75,11 +75,11 @@ namespace OpenRCT2::Network
|
|||||||
// NOTE: BytesTransfered includes the header length, this will not underflow.
|
// NOTE: BytesTransfered includes the header length, this will not underflow.
|
||||||
const size_t missingLength = header.Size - (InboundPacket.BytesTransferred - sizeof(header));
|
const size_t missingLength = header.Size - (InboundPacket.BytesTransferred - sizeof(header));
|
||||||
|
|
||||||
uint8_t buffer[kNetworkBufferSize];
|
uint8_t buffer[kBufferSize];
|
||||||
|
|
||||||
if (missingLength > 0)
|
if (missingLength > 0)
|
||||||
{
|
{
|
||||||
NetworkReadPacket status = Socket->ReceiveData(buffer, std::min(missingLength, kNetworkBufferSize), &bytesRead);
|
NetworkReadPacket status = Socket->ReceiveData(buffer, std::min(missingLength, kBufferSize), &bytesRead);
|
||||||
if (status != NetworkReadPacket::success)
|
if (status != NetworkReadPacket::success)
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
@@ -176,7 +176,7 @@ namespace OpenRCT2::Network
|
|||||||
bool NetworkConnection::ReceivedPacketRecently() const noexcept
|
bool NetworkConnection::ReceivedPacketRecently() const noexcept
|
||||||
{
|
{
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
constexpr auto kTimeoutMs = kNetworkNoDataTimeout * 1000;
|
constexpr auto kTimeoutMs = kNoDataTimeout * 1000;
|
||||||
if (Platform::GetTicks() > _lastPacketTime + kTimeoutMs)
|
if (Platform::GetTicks() > _lastPacketTime + kTimeoutMs)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -197,8 +197,8 @@ namespace OpenRCT2::Network
|
|||||||
|
|
||||||
void NetworkConnection::SetLastDisconnectReason(const StringId string_id, void* args)
|
void NetworkConnection::SetLastDisconnectReason(const StringId string_id, void* args)
|
||||||
{
|
{
|
||||||
char buffer[kNetworkDisconnectReasonBufSize];
|
char buffer[kDisconnectReasonBufSize];
|
||||||
FormatStringLegacy(buffer, kNetworkDisconnectReasonBufSize, string_id, args);
|
FormatStringLegacy(buffer, kDisconnectReasonBufSize, string_id, args);
|
||||||
SetLastDisconnectReason(buffer);
|
SetLastDisconnectReason(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace OpenRCT2::Network
|
|||||||
{
|
{
|
||||||
if (_lanListener->GetStatus() != SocketStatus::listening)
|
if (_lanListener->GetStatus() != SocketStatus::listening)
|
||||||
{
|
{
|
||||||
_lanListener->Listen(kNetworkLanBroadcastPort);
|
_lanListener->Listen(kLanBroadcastPort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -120,7 +120,7 @@ namespace OpenRCT2::Network
|
|||||||
{
|
{
|
||||||
std::string sender = endpoint->GetHostname();
|
std::string sender = endpoint->GetHostname();
|
||||||
LOG_VERBOSE("Received %zu bytes from %s on LAN broadcast port", recievedBytes, sender.c_str());
|
LOG_VERBOSE("Received %zu bytes from %s on LAN broadcast port", recievedBytes, sender.c_str());
|
||||||
if (String::equals(buffer, kNetworkLanBroadcastMsg))
|
if (String::equals(buffer, kLanBroadcastMsg))
|
||||||
{
|
{
|
||||||
auto body = GetBroadcastJson();
|
auto body = GetBroadcastJson();
|
||||||
auto bodyDump = body.dump();
|
auto bodyDump = body.dump();
|
||||||
|
|||||||
@@ -273,11 +273,11 @@ namespace OpenRCT2::Network
|
|||||||
constexpr auto kReceiveDelayInMs = 10;
|
constexpr auto kReceiveDelayInMs = 10;
|
||||||
constexpr auto kReceiveWaitInMs = 2000;
|
constexpr auto kReceiveWaitInMs = 2000;
|
||||||
|
|
||||||
std::string_view msg = kNetworkLanBroadcastMsg;
|
std::string_view msg = kLanBroadcastMsg;
|
||||||
auto udpSocket = CreateUdpSocket();
|
auto udpSocket = CreateUdpSocket();
|
||||||
|
|
||||||
LOG_VERBOSE("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress.c_str());
|
LOG_VERBOSE("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress.c_str());
|
||||||
auto len = udpSocket->SendData(broadcastAddress, kNetworkLanBroadcastPort, msg.data(), msg.size());
|
auto len = udpSocket->SendData(broadcastAddress, kLanBroadcastPort, msg.data(), msg.size());
|
||||||
if (len != msg.size())
|
if (len != msg.size())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Unable to broadcast server query.");
|
throw std::runtime_error("Unable to broadcast server query.");
|
||||||
|
|||||||
Reference in New Issue
Block a user