Fix disable network / disable http builds

This commit is contained in:
Ted John 2019-05-06 11:19:35 +00:00
parent 20f52a8cbe
commit 4b0f2bbceb
6 changed files with 106 additions and 101 deletions

View File

@ -100,10 +100,12 @@ public:
return window_save_prompt_open();
case WC_SCENERY:
return window_scenery_open();
#ifndef DISABLE_NETWORK
case WC_SERVER_LIST:
return window_server_list_open();
case WC_SERVER_START:
return window_server_start_open();
#endif
case WC_KEYBOARD_SHORTCUT_LIST:
return window_shortcut_keys_open();
case WC_STAFF_LIST:

View File

@ -7,35 +7,33 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#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_NETWORK
#ifndef DISABLE_HTTP
using namespace OpenRCT2::Network;
#endif
# include <algorithm>
# 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>
#define WWIDTH_MIN 500
#define WHEIGHT_MIN 300
#define WWIDTH_MAX 1200
#define WHEIGHT_MAX 800
#define ITEM_HEIGHT (3 + 9 + 3)
# define WWIDTH_MIN 500
# define WHEIGHT_MIN 300
# define WWIDTH_MAX 1200
# define WHEIGHT_MAX 800
# define ITEM_HEIGHT (3 + 9 + 3)
static char _playerName[32 + 1];
static ServerList _serverList;
@ -613,3 +611,5 @@ static void server_list_fetch_servers_check(rct_window* w)
}
}
}
#endif

View File

@ -7,18 +7,20 @@
* 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 <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/ParkImporter.h>
#include <openrct2/config/Config.h>
#include <openrct2/interface/Chat.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/network/network.h>
#include <openrct2/util/Util.h>
#include <openrct2/windows/Intent.h>
# include "../interface/Theme.h"
# include <openrct2-ui/interface/Widget.h>
# include <openrct2-ui/windows/Window.h>
# include <openrct2/Context.h>
# include <openrct2/ParkImporter.h>
# include <openrct2/config/Config.h>
# include <openrct2/interface/Chat.h>
# include <openrct2/localisation/Localisation.h>
# include <openrct2/network/network.h>
# include <openrct2/util/Util.h>
# include <openrct2/windows/Intent.h>
static char _port[7];
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_MAX_PLAYERS, nullptr, w->colours[1], w->x + 6, w->y + w->widgets[WIDX_MAXPLAYERS].top);
}
#endif

View File

@ -43,8 +43,10 @@ rct_window* window_news_open();
rct_window* window_news_options_open();
rct_window* window_options_open();
rct_window* window_save_prompt_open();
#ifndef DISABLE_NETWORK
rct_window* window_server_list_open();
rct_window* window_server_start_open();
#endif
rct_window* window_shortcut_change_open(int32_t selected_key);
rct_window* window_shortcut_keys_open();
rct_window* window_staff_list_open();

View File

@ -32,10 +32,6 @@
# include <memory>
# include <string>
# ifndef DISABLE_HTTP
using namespace OpenRCT2::Network;
enum MASTER_SERVER_STATUS
{
MASTER_SERVER_STATUS_OK = 200,
@ -52,7 +48,12 @@ class NetworkServerAdvertiser final : public INetworkServerAdvertiser
private:
uint16_t _port;
std::unique_ptr<IUdpSocket> _lanListener;
uint32_t _lastListenTime{};
ADVERTISE_STATUS _status = ADVERTISE_STATUS::UNREGISTERED;
# ifndef DISABLE_HTTP
uint32_t _lastAdvertiseTime = 0;
uint32_t _lastHeartbeatTime = 0;
@ -64,16 +65,16 @@ private:
// See https://github.com/OpenRCT2/OpenRCT2/issues/6277 and 4953
bool _forceIPv4 = false;
std::unique_ptr<IUdpSocket> _lanListener;
uint32_t _lastListenTime{};
# endif
public:
explicit NetworkServerAdvertiser(uint16_t port)
{
_port = port;
_key = GenerateAdvertiseKey();
_lanListener = CreateUdpSocket();
# ifndef DISABLE_HTTP
_key = GenerateAdvertiseKey();
# endif
}
ADVERTISE_STATUS GetStatus() const override
@ -84,10 +85,12 @@ public:
void Update() override
{
UpdateLAN();
# ifndef DISABLE_HTTP
if (gConfigNetwork.advertise)
{
UpdateWAN();
}
# endif
}
private:
@ -106,24 +109,34 @@ private:
size_t recievedBytes{};
std::unique_ptr<INetworkEndpoint> 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();
log_verbose("Received %zu bytes from %s on LAN broadcast port", recievedBytes, sender.c_str());
auto body = GetBroadcastJson();
auto bodyDump = json_dumps(body, JSON_COMPACT);
size_t sendLen = strlen(bodyDump) + 1;
log_verbose("Sending %zu bytes back to %s", sendLen, sender.c_str());
_lanListener->SendData(*endpoint, bodyDump, sendLen);
free(bodyDump);
json_decref(body);
if (String::Equals(buffer, NETWORK_LAN_BROADCAST_MSG))
{
auto body = GetBroadcastJson();
auto bodyDump = json_dumps(body, JSON_COMPACT);
size_t sendLen = strlen(bodyDump) + 1;
log_verbose("Sending %zu bytes back to %s", sendLen, sender.c_str());
_lanListener->SendData(*endpoint, bodyDump, sendLen);
free(bodyDump);
json_decref(body);
}
}
}
_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()
{
switch (_status)
@ -148,6 +161,8 @@ private:
void SendRegistration(bool forceIPv4)
{
using namespace OpenRCT2::Network;
_lastAdvertiseTime = platform_get_ticks();
// Send the registration request
@ -181,6 +196,8 @@ private:
void SendHeartbeat()
{
using namespace OpenRCT2::Network;
Http::Request request;
request.url = GetMasterServerUrl();
request.method = Http::Method::PUT;
@ -284,13 +301,6 @@ private:
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()
{
// Generate a string of 16 random hex characters (64-integer key as a hex formatted string)
@ -316,6 +326,7 @@ private:
}
return result;
}
# endif
};
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);
}
# 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

View File

@ -7,26 +7,27 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "ServerList.h"
#ifndef DISABLE_NETWORK
#include "../Context.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 "ServerList.h"
#include <algorithm>
#include <numeric>
# include "../Context.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 <numeric>
using namespace OpenRCT2;
using namespace OpenRCT2::Network;
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;
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());
if (len != msg.size())
{
@ -318,9 +319,11 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
std::future<std::vector<ServerListEntry>> ServerList::FetchOnlineServerListAsync()
{
#ifdef DISABLE_HTTP
# ifdef DISABLE_HTTP
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 f = p->get_future();
@ -386,7 +389,7 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchOnlineServerListAsync
json_decref(root);
});
return f;
#endif
# endif
}
uint32_t ServerList::GetTotalPlayerCount() const
@ -395,3 +398,5 @@ uint32_t ServerList::GetTotalPlayerCount() const
return acc + entry.players;
});
}
#endif