mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
update: add LAN advertising configuration for server.properties
LAN-Discovery, which isn’t needed in server mode and could potentially be a security risk, has also been disabled(only server mode).
This commit is contained in:
parent
31bfb7e428
commit
9e4052ece5
|
|
@ -379,9 +379,23 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame,
|
|||
|
||||
if (WinsockNetLayer::IsActive())
|
||||
{
|
||||
const wchar_t* hostName = IQNet::m_player[0].m_gamertag;
|
||||
unsigned int settings = app.GetGameHostOption(eGameHostOption_All);
|
||||
WinsockNetLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION);
|
||||
// For Dedicated Server, refer to `lan-advertise` in `server.properties`
|
||||
bool enableLanAdvertising = true;
|
||||
if (g_Win64DedicatedServer)
|
||||
{
|
||||
enableLanAdvertising = g_Win64DedicatedServerLanAdvertise;
|
||||
}
|
||||
|
||||
if (enableLanAdvertising)
|
||||
{
|
||||
const wchar_t* hostName = IQNet::m_player[0].m_gamertag;
|
||||
unsigned int settings = app.GetGameHostOption(eGameHostOption_All);
|
||||
WinsockNetLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
WinsockNetLayer::StopAdvertising();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//#endif
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ char g_Win64MultiplayerIP[256] = "127.0.0.1";
|
|||
bool g_Win64DedicatedServer = false;
|
||||
int g_Win64DedicatedServerPort = WIN64_NET_DEFAULT_PORT;
|
||||
char g_Win64DedicatedServerBindIP[256] = "";
|
||||
bool g_Win64DedicatedServerLanAdvertise = true;
|
||||
|
||||
bool WinsockNetLayer::Initialize()
|
||||
{
|
||||
|
|
@ -76,7 +77,11 @@ bool WinsockNetLayer::Initialize()
|
|||
|
||||
s_initialized = true;
|
||||
|
||||
StartDiscovery();
|
||||
// Dedicated Server does not use LAN session discovery and therefore does not initiate discovery.
|
||||
if (!g_Win64DedicatedServer)
|
||||
{
|
||||
StartDiscovery();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,5 +150,6 @@ extern char g_Win64MultiplayerIP[256];
|
|||
extern bool g_Win64DedicatedServer;
|
||||
extern int g_Win64DedicatedServerPort;
|
||||
extern char g_Win64DedicatedServerBindIP[256];
|
||||
extern bool g_Win64DedicatedServerLanAdvertise;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ static const int kDefaultServerPort = 25565;
|
|||
static const int kDefaultMaxPlayers = 8;
|
||||
static const int kMaxDedicatedPlayers = 8;
|
||||
static const int kDefaultAutosaveIntervalSeconds = 60;
|
||||
static const char *kLanAdvertisePropertyKey = "lan-advertise";
|
||||
|
||||
static const ServerPropertyDefault kServerPropertyDefaults[] =
|
||||
{
|
||||
|
|
@ -63,6 +64,7 @@ static const ServerPropertyDefault kServerPropertyDefaults[] =
|
|||
{ "server-ip", "0.0.0.0" },
|
||||
{ "server-name", "DedicatedServer" },
|
||||
{ "server-port", "25565" },
|
||||
{ "lan-advertise", "false" },
|
||||
{ "spawn-animals", "true" },
|
||||
{ "spawn-monsters", "true" },
|
||||
{ "spawn-npcs", "true" },
|
||||
|
|
@ -677,6 +679,7 @@ ServerPropertiesConfig LoadServerPropertiesConfig()
|
|||
|
||||
config.serverPort = ReadNormalizedIntProperty(&merged, "server-port", kDefaultServerPort, 1, 65535, &shouldWrite);
|
||||
config.serverIp = ReadNormalizedStringProperty(&merged, "server-ip", "0.0.0.0", 255, &shouldWrite);
|
||||
config.lanAdvertise = ReadNormalizedBoolProperty(&merged, kLanAdvertisePropertyKey, false, &shouldWrite);
|
||||
config.serverName = ReadNormalizedStringProperty(&merged, "server-name", "DedicatedServer", 16, &shouldWrite);
|
||||
config.maxPlayers = ReadNormalizedIntProperty(&merged, "max-players", kDefaultMaxPlayers, 1, kMaxDedicatedPlayers, &shouldWrite);
|
||||
config.seed = 0;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ namespace ServerRuntime
|
|||
int serverPort;
|
||||
/** `server-ip` */
|
||||
std::string serverIp;
|
||||
/** `lan-advertise` */
|
||||
bool lanAdvertise;
|
||||
/** `server-name` (max 16 chars at runtime) */
|
||||
std::string serverName;
|
||||
/** `max-players` */
|
||||
|
|
|
|||
|
|
@ -328,6 +328,11 @@ int main(int argc, char **argv)
|
|||
g_Win64MultiplayerJoin = false;
|
||||
g_Win64MultiplayerPort = config.port;
|
||||
strncpy_s(g_Win64MultiplayerIP, sizeof(g_Win64MultiplayerIP), config.bindIP, _TRUNCATE);
|
||||
g_Win64DedicatedServer = true;
|
||||
g_Win64DedicatedServerPort = config.port;
|
||||
strncpy_s(g_Win64DedicatedServerBindIP, sizeof(g_Win64DedicatedServerBindIP), config.bindIP, _TRUNCATE);
|
||||
g_Win64DedicatedServerLanAdvertise = serverProperties.lanAdvertise;
|
||||
LogInfof("startup", "LAN advertise: %s", serverProperties.lanAdvertise ? "enabled" : "disabled");
|
||||
|
||||
LogStartupStep("registering hidden window class");
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
|
|
|||
Loading…
Reference in a new issue