LCEMP commit: prepare code for dedicated server support

This commit is contained in:
2026-08-14 13:32:11 +03:00
parent 67a8111974
commit f404e4b4e4
13 changed files with 150 additions and 23 deletions
+44 -16
View File
@@ -35,7 +35,11 @@
#include "..\Minecraft.World\net.minecraft.world.entity.h"
#include "ProgressRenderer.h"
#include "ServerPlayer.h"
#include "PlayerConnection.h"
#include "GameRenderer.h"
#if defined(_WINDOWS64) || defined(DISABLE_PSN) || defined(_DISABLE_XBLIVE)
#include "Common\Network\NetworkSocketLayer.h"
#endif
#include "..\Minecraft.World\ThreadName.h"
#include "..\Minecraft.World\IntCache.h"
#include "..\Minecraft.World\CompressedTileStorage.h"
@@ -47,6 +51,11 @@
#endif
#include "PS3\PS3Extras\ShutdownManager.h"
#include "ServerCommandDispatcher.h"
#ifdef _DEDICATED_SERVER
#include "..\Minecraft.Server\ServerCommands.h"
#endif
#include "..\Minecraft.World\BiomeSource.h"
#include "PlayerChunkMap.h"
#include "Common\Telemetry\TelemetryManager.h"
@@ -150,13 +159,11 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW
#endif
settings = new Settings(new File(L"server.properties"));
app.DebugPrintf("\n*** SERVER SETTINGS ***\n");
app.DebugPrintf("ServerSettings: host-friends-only is %s\n",(app.GetGameHostOption(eGameHostOption_FriendsOfFriends)>0)?"on":"off");
app.DebugPrintf("ServerSettings: game-type is %s\n",(app.GetGameHostOption(eGameHostOption_GameType)==0)?"Survival Mode":"Creative Mode");
app.DebugPrintf("ServerSettings: pvp is %s\n",(app.GetGameHostOption(eGameHostOption_PvP)>0)?"on":"off");
app.DebugPrintf("ServerSettings: fire spreads is %s\n",(app.GetGameHostOption(eGameHostOption_FireSpreads)>0)?"on":"off");
app.DebugPrintf("ServerSettings: tnt explodes is %s\n",(app.GetGameHostOption(eGameHostOption_TNT)>0)?"on":"off");
app.DebugPrintf("\n");
app.DebugPrintf("host-friends-only is %s",(app.GetGameHostOption(eGameHostOption_FriendsOfFriends)>0)?"on":"off");
app.DebugPrintf("game-type is %s",(app.GetGameHostOption(eGameHostOption_GameType)==0)?"Survival Mode":"Creative Mode");
app.DebugPrintf("pvp is %s",(app.GetGameHostOption(eGameHostOption_PvP)>0)?"on":"off");
app.DebugPrintf("fire-spreads is %s",(app.GetGameHostOption(eGameHostOption_FireSpreads)>0)?"on":"off");
app.DebugPrintf("tnt-explodes is %s",(app.GetGameHostOption(eGameHostOption_TNT)>0)?"on":"off");
// TODO 4J Stu - Init a load of settings based on data passed as params
//settings->setBooleanAndSave( L"host-friends-only", (app.GetGameHostOption(eGameHostOption_FriendsOfFriends)>0) );
@@ -283,6 +290,14 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW
}
g_NetworkManager.ServerReady(); // 4J added
#ifdef _DEDICATED_SERVER
{
extern QNET_STATE _iQNetStubState;
_iQNetStubState = QNET_STATE_GAME_PLAY;
}
#endif
return m_bLoaded;
}
@@ -405,7 +420,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
int gameTypeId = settings->getInt(L"gamemode", app.GetGameHostOption(eGameHostOption_GameType));//LevelSettings::GAMETYPE_SURVIVAL);
GameType *gameType = LevelSettings::validateGameType(gameTypeId);
app.DebugPrintf("Default game type: %d\n" , gameTypeId);
app.DebugPrintf("Default game type: %d" , gameTypeId);
LevelSettings *levelSettings = new LevelSettings(levelSeed, gameType, app.GetGameHostOption(eGameHostOption_Structures)>0?true:false, isHardcore(), true, pLevelType, initData->xzSize, initData->hellScale);
if( app.GetGameHostOption(eGameHostOption_BonusChest ) ) levelSettings->enableStartingBonusItems();
@@ -497,7 +512,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
Minecraft *pMinecraft = Minecraft::GetInstance();
// m_lastSentDifficulty = pMinecraft->options->difficulty;
levels[i]->difficulty = app.GetGameHostOption(eGameHostOption_Difficulty); //pMinecraft->options->difficulty;
app.DebugPrintf("MinecraftServer::loadLevel - Difficulty = %d\n",levels[i]->difficulty);
app.DebugPrintf("MinecraftServer::loadLevel - Difficulty = %d",levels[i]->difficulty);
#if DEBUG_SERVER_DONT_SPAWN_MOBS
levels[i]->setSpawnSettings(false, false);
@@ -571,6 +586,13 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
csf->closeHandle(fe);
}
#ifdef _DEDICATED_SERVER
{
__int64 doneTime = System::currentTimeMillis();
app.DebugPrintf("Done! For help, type \"help\" or \"?\"");
}
#endif
__int64 lastTime = System::currentTimeMillis();
#ifdef _LARGE_WORLDS
if(app.GetGameNewWorldSize() > levels[0]->getLevelData()->getXZSizeOld())
@@ -693,9 +715,6 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
// stronghold position?
if(levels[0]->dimension->id==0)
{
app.DebugPrintf("===================================\n");
if(!levels[0]->getLevelData()->getHasStronghold())
{
int x,z;
@@ -705,20 +724,19 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
levels[0]->getLevelData()->setZStronghold(z);
levels[0]->getLevelData()->setHasStronghold();
app.DebugPrintf("=== FOUND stronghold in terrain features list\n");
app.DebugPrintf("FOUND stronghold in terrain features list\n");
}
else
{
// can't find the stronghold position in the terrain feature list. Do we have to run a post-process?
app.DebugPrintf("=== Can't find stronghold in terrain features list\n");
app.DebugPrintf("Can't find stronghold in terrain features list\n");
}
}
else
{
app.DebugPrintf("=== Leveldata has stronghold position\n");
app.DebugPrintf("Leveldata has stronghold position\n");
}
app.DebugPrintf("===================================\n");
}
// printf("Post processing complete at %dms\n",System::currentTimeMillis() - startTime);
@@ -1683,6 +1701,10 @@ void MinecraftServer::tick()
}
}
Entity::tickExtraWandering(); // 4J added
#ifdef _DEDICATED_SERVER
g_NetworkManager.DoWork();
NetworkSocketLayer::FlushPendingData();
#endif
PIXBeginNamedEvent(0,"Connection tick");
connection->tick();
@@ -1717,6 +1739,12 @@ void MinecraftServer::handleConsoleInputs()
AUTO_VAR(it, consoleInput.begin());
ConsoleInput *input = *it;
consoleInput.erase(it);
#ifdef _DEDICATED_SERVER
HandleServerCommand(input->msg, input->source, this);
delete input;
#else
delete input;
#endif
// commands->handleCommand(input); // 4J - removed - TODO - do we want equivalent of console commands?
}
}