mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-08 20:07:11 +00:00
CLOUD: Add port override for LocalWebserver
It's enabled only when NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE is defined. It's not defined, because override means we have to reconfigure our redirect links somehow to use the override port.
This commit is contained in:
parent
b1264df120
commit
39865e6e6c
@ -30,6 +30,7 @@
|
|||||||
#include "common/timer.h"
|
#include "common/timer.h"
|
||||||
#include "common/translation.h"
|
#include "common/translation.h"
|
||||||
#include <SDL/SDL_net.h>
|
#include <SDL/SDL_net.h>
|
||||||
|
#include <common/config-manager.h>
|
||||||
|
|
||||||
#ifdef POSIX
|
#ifdef POSIX
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -48,7 +49,7 @@ DECLARE_SINGLETON(Networking::LocalWebserver);
|
|||||||
namespace Networking {
|
namespace Networking {
|
||||||
|
|
||||||
LocalWebserver::LocalWebserver(): _set(nullptr), _serverSocket(nullptr), _timerStarted(false),
|
LocalWebserver::LocalWebserver(): _set(nullptr), _serverSocket(nullptr), _timerStarted(false),
|
||||||
_stopOnIdle(false), _clients(0), _idlingFrames(0) {
|
_stopOnIdle(false), _clients(0), _idlingFrames(0), _serverPort(DEFAULT_SERVER_PORT) {
|
||||||
addPathHandler("/", _indexPageHandler.getHandler());
|
addPathHandler("/", _indexPageHandler.getHandler());
|
||||||
addPathHandler("/files", _filesPageHandler.getHandler());
|
addPathHandler("/files", _filesPageHandler.getHandler());
|
||||||
addPathHandler("/create", _createDirectoryHandler.getHandler());
|
addPathHandler("/create", _createDirectoryHandler.getHandler());
|
||||||
@ -84,6 +85,7 @@ void LocalWebserver::stopTimer() {
|
|||||||
|
|
||||||
void LocalWebserver::start() {
|
void LocalWebserver::start() {
|
||||||
_handleMutex.lock();
|
_handleMutex.lock();
|
||||||
|
_serverPort = getPort();
|
||||||
_stopOnIdle = false;
|
_stopOnIdle = false;
|
||||||
if (_timerStarted) {
|
if (_timerStarted) {
|
||||||
_handleMutex.unlock();
|
_handleMutex.unlock();
|
||||||
@ -93,7 +95,7 @@ void LocalWebserver::start() {
|
|||||||
|
|
||||||
// Create a listening TCP socket
|
// Create a listening TCP socket
|
||||||
IPaddress ip;
|
IPaddress ip;
|
||||||
if (SDLNet_ResolveHost(&ip, NULL, SERVER_PORT) == -1) {
|
if (SDLNet_ResolveHost(&ip, NULL, _serverPort) == -1) {
|
||||||
error("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
error("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +168,14 @@ bool LocalWebserver::isRunning() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 LocalWebserver::getPort() {
|
||||||
|
#ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
|
||||||
|
if (ConfMan.hasKey("local_server_port"))
|
||||||
|
return ConfMan.getInt("local_server_port");
|
||||||
|
#endif
|
||||||
|
return DEFAULT_SERVER_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalWebserver::handle() {
|
void LocalWebserver::handle() {
|
||||||
_handleMutex.lock();
|
_handleMutex.lock();
|
||||||
int numready = SDLNet_CheckSockets(_set, 0);
|
int numready = SDLNet_CheckSockets(_set, 0);
|
||||||
@ -241,7 +251,7 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
|
|||||||
IPaddress *ip = (IPaddress *)ipAddress;
|
IPaddress *ip = (IPaddress *)ipAddress;
|
||||||
|
|
||||||
// not resolved
|
// not resolved
|
||||||
_address = Common::String::format("http://127.0.0.1:%u/ (unresolved)", SERVER_PORT);
|
_address = Common::String::format("http://127.0.0.1:%u/ (unresolved)", _serverPort);
|
||||||
|
|
||||||
// default way (might work everywhere, surely works on Windows)
|
// default way (might work everywhere, surely works on Windows)
|
||||||
const char *name = SDLNet_ResolveIP(ip);
|
const char *name = SDLNet_ResolveIP(ip);
|
||||||
@ -249,13 +259,13 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
|
|||||||
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
||||||
} else {
|
} else {
|
||||||
IPaddress localIp;
|
IPaddress localIp;
|
||||||
if (SDLNet_ResolveHost(&localIp, name, SERVER_PORT) == -1) {
|
if (SDLNet_ResolveHost(&localIp, name, _serverPort) == -1) {
|
||||||
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
|
||||||
} else {
|
} else {
|
||||||
_address = Common::String::format(
|
_address = Common::String::format(
|
||||||
"http://%u.%u.%u.%u:%u/",
|
"http://%u.%u.%u.%u:%u/",
|
||||||
localIp.host & 0xFF, (localIp.host >> 8) & 0xFF, (localIp.host >> 16) & 0xFF, (localIp.host >> 24) & 0xFF,
|
localIp.host & 0xFF, (localIp.host >> 8) & 0xFF, (localIp.host >> 16) & 0xFF, (localIp.host >> 24) & 0xFF,
|
||||||
SERVER_PORT
|
_serverPort
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ namespace Networking {
|
|||||||
class LocalWebserver : public Common::Singleton<LocalWebserver> {
|
class LocalWebserver : public Common::Singleton<LocalWebserver> {
|
||||||
static const uint32 FRAMES_PER_SECOND = 20;
|
static const uint32 FRAMES_PER_SECOND = 20;
|
||||||
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
|
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
|
||||||
static const uint32 SERVER_PORT = 12345;
|
static const uint32 DEFAULT_SERVER_PORT = 12345;
|
||||||
static const uint32 MAX_CONNECTIONS = 10;
|
static const uint32 MAX_CONNECTIONS = 10;
|
||||||
|
|
||||||
friend void localWebserverTimer(void *); //calls handle()
|
friend void localWebserverTimer(void *); //calls handle()
|
||||||
@ -73,6 +73,7 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
|
|||||||
uint32 _idlingFrames;
|
uint32 _idlingFrames;
|
||||||
Common::Mutex _handleMutex;
|
Common::Mutex _handleMutex;
|
||||||
Common::String _address;
|
Common::String _address;
|
||||||
|
uint32 _serverPort;
|
||||||
|
|
||||||
void startTimer(int interval = TIMER_INTERVAL);
|
void startTimer(int interval = TIMER_INTERVAL);
|
||||||
void stopTimer();
|
void stopTimer();
|
||||||
@ -95,6 +96,7 @@ public:
|
|||||||
Common::String getAddress();
|
Common::String getAddress();
|
||||||
IndexPageHandler &indexPageHandler();
|
IndexPageHandler &indexPageHandler();
|
||||||
bool isRunning();
|
bool isRunning();
|
||||||
|
static uint32 getPort();
|
||||||
|
|
||||||
static void setClientGetHandler(Client &client, Common::String response, long code = 200, const char *mimeType = nullptr);
|
static void setClientGetHandler(Client &client, Common::String response, long code = 200, const char *mimeType = nullptr);
|
||||||
static void setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);
|
static void setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "audio/mixer.h"
|
#include "audio/mixer.h"
|
||||||
#include "audio/fmopl.h"
|
#include "audio/fmopl.h"
|
||||||
#include "widgets/scrollcontainer.h"
|
#include "widgets/scrollcontainer.h"
|
||||||
|
#include "widgets/edittext.h"
|
||||||
|
|
||||||
#ifdef USE_LIBCURL
|
#ifdef USE_LIBCURL
|
||||||
#include "backends/cloud/cloudmanager.h"
|
#include "backends/cloud/cloudmanager.h"
|
||||||
@ -1317,6 +1318,10 @@ GlobalOptionsDialog::GlobalOptionsDialog(LauncherDialog *launcher)
|
|||||||
_runServerButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RunServerButton", _("Run server"), _("Run local webserver"), kRunServerCmd);
|
_runServerButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RunServerButton", _("Run server"), _("Run local webserver"), kRunServerCmd);
|
||||||
_serverInfoLabel = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerInfoLabel", _("Not running"));
|
_serverInfoLabel = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerInfoLabel", _("Not running"));
|
||||||
|
|
||||||
|
uint32 port = Networking::LocalWebserver::getPort();
|
||||||
|
_serverPortDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortDesc", _("Server's port:"), _("Which port is used by server"));
|
||||||
|
_serverPort = new EditTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortEditText", Common::String::format("%u", port), 0);
|
||||||
|
|
||||||
setupCloudTab();
|
setupCloudTab();
|
||||||
_redrawCloudTab = false;
|
_redrawCloudTab = false;
|
||||||
#ifdef USE_SDL_NET
|
#ifdef USE_SDL_NET
|
||||||
@ -1489,7 +1494,17 @@ void GlobalOptionsDialog::close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_SDL_NET
|
||||||
|
#ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
|
||||||
|
// save server's port
|
||||||
|
uint32 port = Networking::LocalWebserver::getPort();
|
||||||
|
if (_serverPort) {
|
||||||
|
uint64 contents = _serverPort->getEditString().asUint64();
|
||||||
|
if (contents != 0) port = contents;
|
||||||
|
}
|
||||||
|
ConfMan.setInt("local_server_port", port);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
OptionsDialog::close();
|
OptionsDialog::close();
|
||||||
}
|
}
|
||||||
@ -1647,6 +1662,17 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
|
|||||||
#ifdef USE_SDL_NET
|
#ifdef USE_SDL_NET
|
||||||
case kRunServerCmd:
|
case kRunServerCmd:
|
||||||
{
|
{
|
||||||
|
#ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
|
||||||
|
// save server's port
|
||||||
|
uint32 port = Networking::LocalWebserver::getPort();
|
||||||
|
if (_serverPort) {
|
||||||
|
uint64 contents = _serverPort->getEditString().asUint64();
|
||||||
|
if (contents != 0) port = contents;
|
||||||
|
}
|
||||||
|
ConfMan.setInt("local_server_port", port);
|
||||||
|
ConfMan.flushToDisk();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (LocalServer.isRunning()) LocalServer.stopOnIdle();
|
if (LocalServer.isRunning()) LocalServer.stopOnIdle();
|
||||||
else LocalServer.start();
|
else LocalServer.start();
|
||||||
break;
|
break;
|
||||||
@ -1787,13 +1813,19 @@ void GlobalOptionsDialog::setupCloudTab() {
|
|||||||
//determine original widget's positions
|
//determine original widget's positions
|
||||||
int16 x, y;
|
int16 x, y;
|
||||||
uint16 w, h;
|
uint16 w, h;
|
||||||
int serverButtonY, serverInfoY;
|
int serverButtonY, serverInfoY, serverPortDescY, serverPortY;
|
||||||
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RunServerButton", x, y, w, h))
|
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RunServerButton", x, y, w, h))
|
||||||
warning("GlobalOptions_Cloud_Container.RunServerButton's position is undefined");
|
warning("GlobalOptions_Cloud_Container.RunServerButton's position is undefined");
|
||||||
serverButtonY = y;
|
serverButtonY = y;
|
||||||
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerInfoLabel", x, y, w, h))
|
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerInfoLabel", x, y, w, h))
|
||||||
warning("GlobalOptions_Cloud_Container.ServerInfoLabel's position is undefined");
|
warning("GlobalOptions_Cloud_Container.ServerInfoLabel's position is undefined");
|
||||||
serverInfoY = y;
|
serverInfoY = y;
|
||||||
|
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerPortDesc", x, y, w, h))
|
||||||
|
warning("GlobalOptions_Cloud_Container.ServerPortDesc's position is undefined");
|
||||||
|
serverPortDescY = y;
|
||||||
|
if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerPortEditText", x, y, w, h))
|
||||||
|
warning("GlobalOptions_Cloud_Container.ServerPortEditText's position is undefined");
|
||||||
|
serverPortY = y;
|
||||||
|
|
||||||
bool serverIsRunning = LocalServer.isRunning();
|
bool serverIsRunning = LocalServer.isRunning();
|
||||||
|
|
||||||
@ -1809,9 +1841,26 @@ void GlobalOptionsDialog::setupCloudTab() {
|
|||||||
if (serverIsRunning) _serverInfoLabel->setLabel(LocalServer.getAddress());
|
if (serverIsRunning) _serverInfoLabel->setLabel(LocalServer.getAddress());
|
||||||
else _serverInfoLabel->setLabel(_("Not running"));
|
else _serverInfoLabel->setLabel(_("Not running"));
|
||||||
}
|
}
|
||||||
|
#ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
|
||||||
|
if (_serverPortDesc) {
|
||||||
|
_serverPortDesc->setVisible(true);
|
||||||
|
_serverPortDesc->setPos(_serverPortDesc->getRelX(), serverLabelPosition + serverPortDescY - serverInfoY);
|
||||||
|
_serverPortDesc->setEnabled(!serverIsRunning);
|
||||||
|
}
|
||||||
|
if (_serverPort) {
|
||||||
|
_serverPort->setVisible(true);
|
||||||
|
_serverPort->setPos(_serverPort->getRelX(), serverLabelPosition + serverPortY - serverInfoY);
|
||||||
|
_serverPort->setEnabled(!serverIsRunning);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (_serverPortDesc) _serverPortDesc->setVisible(false);
|
||||||
|
if (_serverPort) _serverPort->setVisible(false);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
if (_runServerButton) _runServerButton->setVisible(false);
|
if (_runServerButton) _runServerButton->setVisible(false);
|
||||||
if (_serverInfoLabel) _serverInfoLabel->setVisible(false);
|
if (_serverInfoLabel) _serverInfoLabel->setVisible(false);
|
||||||
|
if (_serverPortDesc) _serverPortDesc->setVisible(false);
|
||||||
|
if (_serverPort) _serverPort->setVisible(false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,6 +45,7 @@ namespace GUI {
|
|||||||
class LauncherDialog;
|
class LauncherDialog;
|
||||||
|
|
||||||
class CheckboxWidget;
|
class CheckboxWidget;
|
||||||
|
class EditTextWidget;
|
||||||
class PopUpWidget;
|
class PopUpWidget;
|
||||||
class SliderWidget;
|
class SliderWidget;
|
||||||
class StaticTextWidget;
|
class StaticTextWidget;
|
||||||
@ -267,6 +268,8 @@ protected:
|
|||||||
ButtonWidget *_storageDownloadButton;
|
ButtonWidget *_storageDownloadButton;
|
||||||
ButtonWidget *_runServerButton;
|
ButtonWidget *_runServerButton;
|
||||||
StaticTextWidget *_serverInfoLabel;
|
StaticTextWidget *_serverInfoLabel;
|
||||||
|
StaticTextWidget *_serverPortDesc;
|
||||||
|
EditTextWidget *_serverPort;
|
||||||
bool _redrawCloudTab;
|
bool _redrawCloudTab;
|
||||||
#ifdef USE_SDL_NET
|
#ifdef USE_SDL_NET
|
||||||
bool _serverWasRunning;
|
bool _serverWasRunning;
|
||||||
|
@ -583,6 +583,15 @@
|
|||||||
height = 'Globals.Line.Height'
|
height = 'Globals.Line.Height'
|
||||||
/>
|
/>
|
||||||
</layout>
|
</layout>
|
||||||
|
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
|
||||||
|
<widget name = 'ServerPortDesc'
|
||||||
|
type = 'OptionsLabel'
|
||||||
|
/>
|
||||||
|
<widget name = 'ServerPortEditText'
|
||||||
|
width = '70'
|
||||||
|
height = 'Globals.Line.Height'
|
||||||
|
/>
|
||||||
|
</layout>
|
||||||
</layout>
|
</layout>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
@ -596,6 +596,17 @@
|
|||||||
height = 'Globals.Line.Height'
|
height = 'Globals.Line.Height'
|
||||||
/>
|
/>
|
||||||
</layout>
|
</layout>
|
||||||
|
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
|
||||||
|
<widget name = 'ServerPortDesc'
|
||||||
|
width = '80'
|
||||||
|
height = 'Globals.Line.Height'
|
||||||
|
textalign = 'right'
|
||||||
|
/>
|
||||||
|
<widget name = 'ServerPortEditText'
|
||||||
|
width = '60'
|
||||||
|
height = '16'
|
||||||
|
/>
|
||||||
|
</layout>
|
||||||
</layout>
|
</layout>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
@ -597,6 +597,15 @@
|
|||||||
height = 'Globals.Line.Height'
|
height = 'Globals.Line.Height'
|
||||||
/>
|
/>
|
||||||
</layout>
|
</layout>
|
||||||
|
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
|
||||||
|
<widget name = 'ServerPortDesc'
|
||||||
|
type = 'OptionsLabel'
|
||||||
|
/>
|
||||||
|
<widget name = 'ServerPortEditText'
|
||||||
|
width = '70'
|
||||||
|
height = 'Globals.Line.Height'
|
||||||
|
/>
|
||||||
|
</layout>
|
||||||
</layout>
|
</layout>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
@ -594,6 +594,17 @@
|
|||||||
height = 'Globals.Line.Height'
|
height = 'Globals.Line.Height'
|
||||||
/>
|
/>
|
||||||
</layout>
|
</layout>
|
||||||
|
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
|
||||||
|
<widget name = 'ServerPortDesc'
|
||||||
|
width = '80'
|
||||||
|
height = 'Globals.Line.Height'
|
||||||
|
textalign = 'right'
|
||||||
|
/>
|
||||||
|
<widget name = 'ServerPortEditText'
|
||||||
|
width = '60'
|
||||||
|
height = '16'
|
||||||
|
/>
|
||||||
|
</layout>
|
||||||
</layout>
|
</layout>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user