aboutsummaryrefslogtreecommitdiff
path: root/backends/networking
diff options
context:
space:
mode:
Diffstat (limited to 'backends/networking')
-rw-r--r--backends/networking/sdl_net/localwebserver.cpp20
-rw-r--r--backends/networking/sdl_net/localwebserver.h4
2 files changed, 18 insertions, 6 deletions
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp
index 1480418b70..7c3edfc17f 100644
--- a/backends/networking/sdl_net/localwebserver.cpp
+++ b/backends/networking/sdl_net/localwebserver.cpp
@@ -30,6 +30,7 @@
#include "common/timer.h"
#include "common/translation.h"
#include <SDL/SDL_net.h>
+#include <common/config-manager.h>
#ifdef POSIX
#include <sys/types.h>
@@ -48,7 +49,7 @@ DECLARE_SINGLETON(Networking::LocalWebserver);
namespace Networking {
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("/files", _filesPageHandler.getHandler());
addPathHandler("/create", _createDirectoryHandler.getHandler());
@@ -84,6 +85,7 @@ void LocalWebserver::stopTimer() {
void LocalWebserver::start() {
_handleMutex.lock();
+ _serverPort = getPort();
_stopOnIdle = false;
if (_timerStarted) {
_handleMutex.unlock();
@@ -93,7 +95,7 @@ void LocalWebserver::start() {
// Create a listening TCP socket
IPaddress ip;
- if (SDLNet_ResolveHost(&ip, NULL, SERVER_PORT) == -1) {
+ if (SDLNet_ResolveHost(&ip, NULL, _serverPort) == -1) {
error("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
}
@@ -166,6 +168,14 @@ bool LocalWebserver::isRunning() {
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() {
_handleMutex.lock();
int numready = SDLNet_CheckSockets(_set, 0);
@@ -241,7 +251,7 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
IPaddress *ip = (IPaddress *)ipAddress;
// 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)
const char *name = SDLNet_ResolveIP(ip);
@@ -249,13 +259,13 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
} else {
IPaddress localIp;
- if (SDLNet_ResolveHost(&localIp, name, SERVER_PORT) == -1) {
+ if (SDLNet_ResolveHost(&localIp, name, _serverPort) == -1) {
warning("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
} else {
_address = Common::String::format(
"http://%u.%u.%u.%u:%u/",
localIp.host & 0xFF, (localIp.host >> 8) & 0xFF, (localIp.host >> 16) & 0xFF, (localIp.host >> 24) & 0xFF,
- SERVER_PORT
+ _serverPort
);
}
}
diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h
index 1185cda890..3512583605 100644
--- a/backends/networking/sdl_net/localwebserver.h
+++ b/backends/networking/sdl_net/localwebserver.h
@@ -50,7 +50,7 @@ namespace Networking {
class LocalWebserver : public Common::Singleton<LocalWebserver> {
static const uint32 FRAMES_PER_SECOND = 20;
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;
friend void localWebserverTimer(void *); //calls handle()
@@ -73,6 +73,7 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
uint32 _idlingFrames;
Common::Mutex _handleMutex;
Common::String _address;
+ uint32 _serverPort;
void startTimer(int interval = TIMER_INTERVAL);
void stopTimer();
@@ -95,6 +96,7 @@ public:
Common::String getAddress();
IndexPageHandler &indexPageHandler();
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::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);