summaryrefslogtreecommitdiffhomepage
path: root/Stars45
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-02-03 22:57:49 +0100
committerAki <please@ignore.pl>2022-02-03 22:57:49 +0100
commitfaeef00bb63623089d706c0c5b411b344d92bd9e (patch)
treebd6131a5d2f9a379b1468abb9c16976e1a82faa4 /Stars45
parent975a232cfb08410177af2ba06251e4c553780e7b (diff)
downloadstarshatter-faeef00bb63623089d706c0c5b411b344d92bd9e.zip
starshatter-faeef00bb63623089d706c0c5b411b344d92bd9e.tar.gz
starshatter-faeef00bb63623089d706c0c5b411b344d92bd9e.tar.bz2
Added hostname to the server configuration
This is in order to avoid default lookup for local address, which usually caused the game to bind to a LAN address hence effectively disallowing any other traffic in. For now there is no option in GUI to configure the hostname. Menus definitions are in the game files, so I should avoid any changes that can cause the binary to be incompatible with currently available resource packs.
Diffstat (limited to 'Stars45')
-rw-r--r--Stars45/NetGameServer.cpp10
-rw-r--r--Stars45/NetLobbyServer.cpp5
-rw-r--r--Stars45/NetServerConfig.cpp8
-rw-r--r--Stars45/NetServerConfig.h3
4 files changed, 21 insertions, 5 deletions
diff --git a/Stars45/NetGameServer.cpp b/Stars45/NetGameServer.cpp
index f2293a4..42e770f 100644
--- a/Stars45/NetGameServer.cpp
+++ b/Stars45/NetGameServer.cpp
@@ -58,6 +58,7 @@
#include "Hangar.h"
#include "FlightDeck.h"
#include "Mission.h"
+#include "Text.h"
#include "NetLayer.h"
#include "NetHost.h"
@@ -77,12 +78,15 @@ NetGameServer::NetGameServer()
{
Print("Constructing NetGameServer\n");
+ Text hostname = "0.0.0.0";
WORD server_port = 11101;
- if (NetServerConfig::GetInstance())
- server_port = NetServerConfig::GetInstance()->GetGamePort();
+ if (NetServerConfig::GetInstance()) {
+ hostname = NetServerConfig::GetInstance()->Hostname();
+ server_port = NetServerConfig::GetInstance()->GetGamePort();
+ }
- NetAddr server(NetHost().Address().IPAddr(), server_port);
+ NetAddr server(hostname.data(), server_port);
link = new(__FILE__,__LINE__) NetLink(server);
diff --git a/Stars45/NetLobbyServer.cpp b/Stars45/NetLobbyServer.cpp
index 90ee02b..c3817c8 100644
--- a/Stars45/NetLobbyServer.cpp
+++ b/Stars45/NetLobbyServer.cpp
@@ -51,6 +51,7 @@
#include "StarServer.h"
#include "ShipDesign.h"
#include "Sim.h"
+#include "Text.h"
#include "ModConfig.h"
#include "ModInfo.h"
@@ -83,17 +84,19 @@ NetLobbyServer::NetLobbyServer()
selected_mission = 0;
+ Text hostname = "0.0.0.0";
WORD server_port = 11100;
server_config = NetServerConfig::GetInstance();
if (server_config) {
+ hostname = server_config->Hostname();
server_name = server_config->Name();
server_port = server_config->GetLobbyPort();
server_mission = server_config->GetMission();
NetAuth::SetAuthLevel(server_config->GetAuthLevel());
- server_addr = NetAddr(NetHost().Address().IPAddr(), server_port);
+ server_addr = NetAddr(hostname.data(), server_port);
link = new(__FILE__,__LINE__) NetLink(server_addr);
}
diff --git a/Stars45/NetServerConfig.cpp b/Stars45/NetServerConfig.cpp
index 90b7e0d..cab2f79 100644
--- a/Stars45/NetServerConfig.cpp
+++ b/Stars45/NetServerConfig.cpp
@@ -63,6 +63,7 @@ NetServerConfig::NetServerConfig()
{
instance = this;
+ hostname = "0.0.0.0";
name = "Starshatter ";
admin_name = "system";
admin_pass = "manager";
@@ -161,7 +162,11 @@ NetServerConfig::Load()
if (term) {
TermDef* def = term->isDef();
if (def) {
- if (def->name()->value() == "name") {
+ if (def->name()->value() == "hostname") {
+ GetDefText(instance->hostname, def, filename);
+ }
+
+ else if (def->name()->value() == "name") {
GetDefText(instance->name, def, filename);
}
@@ -271,6 +276,7 @@ NetServerConfig::Save()
fopen_s(&f, "server.cfg", "w");
if (f) {
fprintf(f, "SERVER_CONFIG\n\n");
+ fprintf(f, "hostname: \"%s\"\n", instance->hostname.data());
fprintf(f, "name: \"%s\"\n", instance->name.data());
fprintf(f, "admin_name: \"%s\"\n", instance->admin_name.data());
fprintf(f, "admin_pass: \"%s\"\n", instance->admin_pass.data());
diff --git a/Stars45/NetServerConfig.h b/Stars45/NetServerConfig.h
index a81c4fd..da740cb 100644
--- a/Stars45/NetServerConfig.h
+++ b/Stars45/NetServerConfig.h
@@ -60,6 +60,7 @@ public:
NET_GAME_PUBLIC
};
+ const Text& Hostname() const { return hostname; }
const Text& Name() const { return name; }
const Text& GetAdminName() const { return admin_name; }
const Text& GetAdminPass() const { return admin_pass; }
@@ -73,6 +74,7 @@ public:
int GetGameType() const { return game_type; }
int GetAuthLevel() const { return auth_level; }
+ void SetHostname(const char* s) { hostname = Clean(s); }
void SetName(const char* s) { name = Clean(s); }
void SetAdminName(const char* s){ admin_name = Clean(s); }
void SetAdminPass(const char* s){ admin_pass = Clean(s); }
@@ -100,6 +102,7 @@ private:
void LoadBanList();
Text Clean(const char* s);
+ Text hostname;
Text name;
Text admin_name;
Text admin_pass;