mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix disable network / disable http builds
This commit is contained in:
parent
20f52a8cbe
commit
4b0f2bbceb
|
@ -100,10 +100,12 @@ public:
|
||||||
return window_save_prompt_open();
|
return window_save_prompt_open();
|
||||||
case WC_SCENERY:
|
case WC_SCENERY:
|
||||||
return window_scenery_open();
|
return window_scenery_open();
|
||||||
|
#ifndef DISABLE_NETWORK
|
||||||
case WC_SERVER_LIST:
|
case WC_SERVER_LIST:
|
||||||
return window_server_list_open();
|
return window_server_list_open();
|
||||||
case WC_SERVER_START:
|
case WC_SERVER_START:
|
||||||
return window_server_start_open();
|
return window_server_start_open();
|
||||||
|
#endif
|
||||||
case WC_KEYBOARD_SHORTCUT_LIST:
|
case WC_KEYBOARD_SHORTCUT_LIST:
|
||||||
return window_shortcut_keys_open();
|
return window_shortcut_keys_open();
|
||||||
case WC_STAFF_LIST:
|
case WC_STAFF_LIST:
|
||||||
|
|
|
@ -7,35 +7,33 @@
|
||||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include <algorithm>
|
#ifndef DISABLE_NETWORK
|
||||||
#include <chrono>
|
|
||||||
#include <openrct2-ui/interface/Dropdown.h>
|
|
||||||
#include <openrct2-ui/interface/Widget.h>
|
|
||||||
#include <openrct2-ui/windows/Window.h>
|
|
||||||
#include <openrct2/Context.h>
|
|
||||||
#include <openrct2/config/Config.h>
|
|
||||||
#include <openrct2/core/Json.hpp>
|
|
||||||
#include <openrct2/core/String.hpp>
|
|
||||||
#include <openrct2/drawing/Drawing.h>
|
|
||||||
#include <openrct2/interface/Colour.h>
|
|
||||||
#include <openrct2/localisation/Localisation.h>
|
|
||||||
#include <openrct2/network/Http.h>
|
|
||||||
#include <openrct2/network/ServerList.h>
|
|
||||||
#include <openrct2/network/network.h>
|
|
||||||
#include <openrct2/platform/platform.h>
|
|
||||||
#include <openrct2/sprites.h>
|
|
||||||
#include <openrct2/util/Util.h>
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#ifndef DISABLE_HTTP
|
# include <algorithm>
|
||||||
using namespace OpenRCT2::Network;
|
# include <chrono>
|
||||||
#endif
|
# include <openrct2-ui/interface/Dropdown.h>
|
||||||
|
# include <openrct2-ui/interface/Widget.h>
|
||||||
|
# include <openrct2-ui/windows/Window.h>
|
||||||
|
# include <openrct2/Context.h>
|
||||||
|
# include <openrct2/config/Config.h>
|
||||||
|
# include <openrct2/core/Json.hpp>
|
||||||
|
# include <openrct2/core/String.hpp>
|
||||||
|
# include <openrct2/drawing/Drawing.h>
|
||||||
|
# include <openrct2/interface/Colour.h>
|
||||||
|
# include <openrct2/localisation/Localisation.h>
|
||||||
|
# include <openrct2/network/Http.h>
|
||||||
|
# include <openrct2/network/ServerList.h>
|
||||||
|
# include <openrct2/network/network.h>
|
||||||
|
# include <openrct2/platform/platform.h>
|
||||||
|
# include <openrct2/sprites.h>
|
||||||
|
# include <openrct2/util/Util.h>
|
||||||
|
# include <tuple>
|
||||||
|
|
||||||
#define WWIDTH_MIN 500
|
# define WWIDTH_MIN 500
|
||||||
#define WHEIGHT_MIN 300
|
# define WHEIGHT_MIN 300
|
||||||
#define WWIDTH_MAX 1200
|
# define WWIDTH_MAX 1200
|
||||||
#define WHEIGHT_MAX 800
|
# define WHEIGHT_MAX 800
|
||||||
#define ITEM_HEIGHT (3 + 9 + 3)
|
# define ITEM_HEIGHT (3 + 9 + 3)
|
||||||
|
|
||||||
static char _playerName[32 + 1];
|
static char _playerName[32 + 1];
|
||||||
static ServerList _serverList;
|
static ServerList _serverList;
|
||||||
|
@ -613,3 +611,5 @@ static void server_list_fetch_servers_check(rct_window* w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -7,18 +7,20 @@
|
||||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "../interface/Theme.h"
|
#ifndef DISABLE_NETWORK
|
||||||
|
|
||||||
#include <openrct2-ui/interface/Widget.h>
|
# include "../interface/Theme.h"
|
||||||
#include <openrct2-ui/windows/Window.h>
|
|
||||||
#include <openrct2/Context.h>
|
# include <openrct2-ui/interface/Widget.h>
|
||||||
#include <openrct2/ParkImporter.h>
|
# include <openrct2-ui/windows/Window.h>
|
||||||
#include <openrct2/config/Config.h>
|
# include <openrct2/Context.h>
|
||||||
#include <openrct2/interface/Chat.h>
|
# include <openrct2/ParkImporter.h>
|
||||||
#include <openrct2/localisation/Localisation.h>
|
# include <openrct2/config/Config.h>
|
||||||
#include <openrct2/network/network.h>
|
# include <openrct2/interface/Chat.h>
|
||||||
#include <openrct2/util/Util.h>
|
# include <openrct2/localisation/Localisation.h>
|
||||||
#include <openrct2/windows/Intent.h>
|
# include <openrct2/network/network.h>
|
||||||
|
# include <openrct2/util/Util.h>
|
||||||
|
# include <openrct2/windows/Intent.h>
|
||||||
|
|
||||||
static char _port[7];
|
static char _port[7];
|
||||||
static char _name[65];
|
static char _name[65];
|
||||||
|
@ -345,3 +347,5 @@ static void window_server_start_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||||
gfx_draw_string_left(dpi, STR_PASSWORD, nullptr, w->colours[1], w->x + 6, w->y + w->widgets[WIDX_PASSWORD_INPUT].top);
|
gfx_draw_string_left(dpi, STR_PASSWORD, nullptr, w->colours[1], w->x + 6, w->y + w->widgets[WIDX_PASSWORD_INPUT].top);
|
||||||
gfx_draw_string_left(dpi, STR_MAX_PLAYERS, nullptr, w->colours[1], w->x + 6, w->y + w->widgets[WIDX_MAXPLAYERS].top);
|
gfx_draw_string_left(dpi, STR_MAX_PLAYERS, nullptr, w->colours[1], w->x + 6, w->y + w->widgets[WIDX_MAXPLAYERS].top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -43,8 +43,10 @@ rct_window* window_news_open();
|
||||||
rct_window* window_news_options_open();
|
rct_window* window_news_options_open();
|
||||||
rct_window* window_options_open();
|
rct_window* window_options_open();
|
||||||
rct_window* window_save_prompt_open();
|
rct_window* window_save_prompt_open();
|
||||||
|
#ifndef DISABLE_NETWORK
|
||||||
rct_window* window_server_list_open();
|
rct_window* window_server_list_open();
|
||||||
rct_window* window_server_start_open();
|
rct_window* window_server_start_open();
|
||||||
|
#endif
|
||||||
rct_window* window_shortcut_change_open(int32_t selected_key);
|
rct_window* window_shortcut_change_open(int32_t selected_key);
|
||||||
rct_window* window_shortcut_keys_open();
|
rct_window* window_shortcut_keys_open();
|
||||||
rct_window* window_staff_list_open();
|
rct_window* window_staff_list_open();
|
||||||
|
|
|
@ -32,10 +32,6 @@
|
||||||
# include <memory>
|
# include <memory>
|
||||||
# include <string>
|
# include <string>
|
||||||
|
|
||||||
# ifndef DISABLE_HTTP
|
|
||||||
|
|
||||||
using namespace OpenRCT2::Network;
|
|
||||||
|
|
||||||
enum MASTER_SERVER_STATUS
|
enum MASTER_SERVER_STATUS
|
||||||
{
|
{
|
||||||
MASTER_SERVER_STATUS_OK = 200,
|
MASTER_SERVER_STATUS_OK = 200,
|
||||||
|
@ -52,7 +48,12 @@ class NetworkServerAdvertiser final : public INetworkServerAdvertiser
|
||||||
private:
|
private:
|
||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
|
|
||||||
|
std::unique_ptr<IUdpSocket> _lanListener;
|
||||||
|
uint32_t _lastListenTime{};
|
||||||
|
|
||||||
ADVERTISE_STATUS _status = ADVERTISE_STATUS::UNREGISTERED;
|
ADVERTISE_STATUS _status = ADVERTISE_STATUS::UNREGISTERED;
|
||||||
|
|
||||||
|
# ifndef DISABLE_HTTP
|
||||||
uint32_t _lastAdvertiseTime = 0;
|
uint32_t _lastAdvertiseTime = 0;
|
||||||
uint32_t _lastHeartbeatTime = 0;
|
uint32_t _lastHeartbeatTime = 0;
|
||||||
|
|
||||||
|
@ -64,16 +65,16 @@ private:
|
||||||
|
|
||||||
// See https://github.com/OpenRCT2/OpenRCT2/issues/6277 and 4953
|
// See https://github.com/OpenRCT2/OpenRCT2/issues/6277 and 4953
|
||||||
bool _forceIPv4 = false;
|
bool _forceIPv4 = false;
|
||||||
|
# endif
|
||||||
std::unique_ptr<IUdpSocket> _lanListener;
|
|
||||||
uint32_t _lastListenTime{};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NetworkServerAdvertiser(uint16_t port)
|
explicit NetworkServerAdvertiser(uint16_t port)
|
||||||
{
|
{
|
||||||
_port = port;
|
_port = port;
|
||||||
_key = GenerateAdvertiseKey();
|
|
||||||
_lanListener = CreateUdpSocket();
|
_lanListener = CreateUdpSocket();
|
||||||
|
# ifndef DISABLE_HTTP
|
||||||
|
_key = GenerateAdvertiseKey();
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ADVERTISE_STATUS GetStatus() const override
|
ADVERTISE_STATUS GetStatus() const override
|
||||||
|
@ -84,10 +85,12 @@ public:
|
||||||
void Update() override
|
void Update() override
|
||||||
{
|
{
|
||||||
UpdateLAN();
|
UpdateLAN();
|
||||||
|
# ifndef DISABLE_HTTP
|
||||||
if (gConfigNetwork.advertise)
|
if (gConfigNetwork.advertise)
|
||||||
{
|
{
|
||||||
UpdateWAN();
|
UpdateWAN();
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -106,24 +109,34 @@ private:
|
||||||
size_t recievedBytes{};
|
size_t recievedBytes{};
|
||||||
std::unique_ptr<INetworkEndpoint> endpoint;
|
std::unique_ptr<INetworkEndpoint> endpoint;
|
||||||
auto p = _lanListener->ReceiveData(buffer, sizeof(buffer) - 1, &recievedBytes, &endpoint);
|
auto p = _lanListener->ReceiveData(buffer, sizeof(buffer) - 1, &recievedBytes, &endpoint);
|
||||||
if (p == NETWORK_READPACKET_SUCCESS && String::Equals(buffer, NETWORK_LAN_BROADCAST_MSG))
|
if (p == NETWORK_READPACKET_SUCCESS)
|
||||||
{
|
{
|
||||||
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, NETWORK_LAN_BROADCAST_MSG))
|
||||||
auto body = GetBroadcastJson();
|
{
|
||||||
auto bodyDump = json_dumps(body, JSON_COMPACT);
|
auto body = GetBroadcastJson();
|
||||||
size_t sendLen = strlen(bodyDump) + 1;
|
auto bodyDump = json_dumps(body, JSON_COMPACT);
|
||||||
log_verbose("Sending %zu bytes back to %s", sendLen, sender.c_str());
|
size_t sendLen = strlen(bodyDump) + 1;
|
||||||
_lanListener->SendData(*endpoint, bodyDump, sendLen);
|
log_verbose("Sending %zu bytes back to %s", sendLen, sender.c_str());
|
||||||
free(bodyDump);
|
_lanListener->SendData(*endpoint, bodyDump, sendLen);
|
||||||
json_decref(body);
|
free(bodyDump);
|
||||||
|
json_decref(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lastListenTime = ticks;
|
_lastListenTime = ticks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_t* GetBroadcastJson()
|
||||||
|
{
|
||||||
|
auto root = network_get_server_info_as_json();
|
||||||
|
json_object_set(root, "port", json_integer(_port));
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifndef DISABLE_HTTP
|
||||||
void UpdateWAN()
|
void UpdateWAN()
|
||||||
{
|
{
|
||||||
switch (_status)
|
switch (_status)
|
||||||
|
@ -148,6 +161,8 @@ private:
|
||||||
|
|
||||||
void SendRegistration(bool forceIPv4)
|
void SendRegistration(bool forceIPv4)
|
||||||
{
|
{
|
||||||
|
using namespace OpenRCT2::Network;
|
||||||
|
|
||||||
_lastAdvertiseTime = platform_get_ticks();
|
_lastAdvertiseTime = platform_get_ticks();
|
||||||
|
|
||||||
// Send the registration request
|
// Send the registration request
|
||||||
|
@ -181,6 +196,8 @@ private:
|
||||||
|
|
||||||
void SendHeartbeat()
|
void SendHeartbeat()
|
||||||
{
|
{
|
||||||
|
using namespace OpenRCT2::Network;
|
||||||
|
|
||||||
Http::Request request;
|
Http::Request request;
|
||||||
request.url = GetMasterServerUrl();
|
request.url = GetMasterServerUrl();
|
||||||
request.method = Http::Method::PUT;
|
request.method = Http::Method::PUT;
|
||||||
|
@ -284,13 +301,6 @@ private:
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* GetBroadcastJson()
|
|
||||||
{
|
|
||||||
auto root = network_get_server_info_as_json();
|
|
||||||
json_object_set(root, "port", json_integer(_port));
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string GenerateAdvertiseKey()
|
static std::string GenerateAdvertiseKey()
|
||||||
{
|
{
|
||||||
// Generate a string of 16 random hex characters (64-integer key as a hex formatted string)
|
// Generate a string of 16 random hex characters (64-integer key as a hex formatted string)
|
||||||
|
@ -316,6 +326,7 @@ private:
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port)
|
std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port)
|
||||||
|
@ -323,23 +334,4 @@ std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port)
|
||||||
return std::make_unique<NetworkServerAdvertiser>(port);
|
return std::make_unique<NetworkServerAdvertiser>(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
# else // DISABLE_HTTP
|
|
||||||
|
|
||||||
class DummyNetworkServerAdvertiser final : public INetworkServerAdvertiser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ADVERTISE_STATUS GetStatus() const override
|
|
||||||
{
|
|
||||||
return ADVERTISE_STATUS::DISABLED;
|
|
||||||
};
|
|
||||||
virtual void Update() override{};
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<INetworkServerAdvertiser> CreateServerAdvertiser(uint16_t port)
|
|
||||||
{
|
|
||||||
return std::make_unique<DummyNetworkServerAdvertiser>();
|
|
||||||
}
|
|
||||||
|
|
||||||
# endif // DISABLE_HTTP
|
|
||||||
|
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
|
|
|
@ -7,26 +7,27 @@
|
||||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "ServerList.h"
|
#ifndef DISABLE_NETWORK
|
||||||
|
|
||||||
#include "../Context.h"
|
# include "ServerList.h"
|
||||||
#include "../PlatformEnvironment.h"
|
|
||||||
#include "../config/Config.h"
|
|
||||||
#include "../core/FileStream.hpp"
|
|
||||||
#include "../core/Json.hpp"
|
|
||||||
#include "../core/Memory.hpp"
|
|
||||||
#include "../core/Path.hpp"
|
|
||||||
#include "../core/String.hpp"
|
|
||||||
#include "../network/Http.h"
|
|
||||||
#include "../platform/platform.h"
|
|
||||||
#include "Socket.h"
|
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
# include "../Context.h"
|
||||||
#include <numeric>
|
# include "../PlatformEnvironment.h"
|
||||||
|
# include "../config/Config.h"
|
||||||
|
# include "../core/FileStream.hpp"
|
||||||
|
# include "../core/Json.hpp"
|
||||||
|
# include "../core/Memory.hpp"
|
||||||
|
# include "../core/Path.hpp"
|
||||||
|
# include "../core/String.hpp"
|
||||||
|
# include "../network/Http.h"
|
||||||
|
# include "../platform/platform.h"
|
||||||
|
# include "Socket.h"
|
||||||
|
# include "network.h"
|
||||||
|
|
||||||
|
# include <algorithm>
|
||||||
|
# include <numeric>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
using namespace OpenRCT2;
|
||||||
using namespace OpenRCT2::Network;
|
|
||||||
|
|
||||||
int32_t ServerListEntry::CompareTo(const ServerListEntry& other) const
|
int32_t ServerListEntry::CompareTo(const ServerListEntry& other) const
|
||||||
{
|
{
|
||||||
|
@ -243,7 +244,7 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
|
||||||
std::string_view msg = NETWORK_LAN_BROADCAST_MSG;
|
std::string_view msg = NETWORK_LAN_BROADCAST_MSG;
|
||||||
auto udpSocket = CreateUdpSocket();
|
auto udpSocket = CreateUdpSocket();
|
||||||
|
|
||||||
log_verbose("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress);
|
log_verbose("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress.c_str());
|
||||||
auto len = udpSocket->SendData(broadcastAddress, NETWORK_LAN_BROADCAST_PORT, msg.data(), msg.size());
|
auto len = udpSocket->SendData(broadcastAddress, NETWORK_LAN_BROADCAST_PORT, msg.data(), msg.size());
|
||||||
if (len != msg.size())
|
if (len != msg.size())
|
||||||
{
|
{
|
||||||
|
@ -318,9 +319,11 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
|
||||||
|
|
||||||
std::future<std::vector<ServerListEntry>> ServerList::FetchOnlineServerListAsync()
|
std::future<std::vector<ServerListEntry>> ServerList::FetchOnlineServerListAsync()
|
||||||
{
|
{
|
||||||
#ifdef DISABLE_HTTP
|
# ifdef DISABLE_HTTP
|
||||||
return std::async(std::launch::deferred, [] { return std::vector<ServerListEntry>(); });
|
return std::async(std::launch::deferred, [] { return std::vector<ServerListEntry>(); });
|
||||||
#else
|
# else
|
||||||
|
using namespace OpenRCT2::Network;
|
||||||
|
|
||||||
auto p = std::make_shared<std::promise<std::vector<ServerListEntry>>>();
|
auto p = std::make_shared<std::promise<std::vector<ServerListEntry>>>();
|
||||||
auto f = p->get_future();
|
auto f = p->get_future();
|
||||||
|
|
||||||
|
@ -386,7 +389,7 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchOnlineServerListAsync
|
||||||
json_decref(root);
|
json_decref(root);
|
||||||
});
|
});
|
||||||
return f;
|
return f;
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ServerList::GetTotalPlayerCount() const
|
uint32_t ServerList::GetTotalPlayerCount() const
|
||||||
|
@ -395,3 +398,5 @@ uint32_t ServerList::GetTotalPlayerCount() const
|
||||||
return acc + entry.players;
|
return acc + entry.players;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue