This commit is contained in:
troglodyte9 2026-03-06 21:34:14 +02:00
parent b28f1ce89d
commit 83f8a6fdd4
4 changed files with 42 additions and 4 deletions

View file

@ -202,6 +202,10 @@ static bool ExecuteConsoleCommand(MinecraftServer *server, const wstring &rawCom
if (action == L"stop") if (action == L"stop")
{ {
server->info(L"Saving before stopping...");
if (playerList != NULL)
playerList->saveAll(NULL, false);
server->saveAllChunks();
server->info(L"Stopping server..."); server->info(L"Stopping server...");
MinecraftServer::HaltServer(); MinecraftServer::HaltServer();
return true; return true;
@ -238,6 +242,7 @@ static bool ExecuteConsoleCommand(MinecraftServer *server, const wstring &rawCom
{ {
playerList->saveAll(NULL, false); playerList->saveAll(NULL, false);
} }
server->saveAllChunks();
server->info(L"World saved."); server->info(L"World saved.");
return true; return true;
} }

View file

@ -138,7 +138,6 @@ private:
bool loadLevel(LevelStorageSource *storageSource, const wstring& name, __int64 levelSeed, LevelType *pLevelType, NetworkGameInitData *initData); bool loadLevel(LevelStorageSource *storageSource, const wstring& name, __int64 levelSeed, LevelType *pLevelType, NetworkGameInitData *initData);
void setProgress(const wstring& status, int progress); void setProgress(const wstring& status, int progress);
void endProgress(); void endProgress();
void saveAllChunks();
void saveGameRules(); void saveGameRules();
void stopServer(bool didInit); void stopServer(bool didInit);
#ifdef _LARGE_WORLDS #ifdef _LARGE_WORLDS
@ -152,6 +151,7 @@ public:
PlayerList *getPlayers(); PlayerList *getPlayers();
void setPlayers(PlayerList *players); void setPlayers(PlayerList *players);
ServerConnection *getConnection(); ServerConnection *getConnection();
void saveAllChunks();
bool isAnimals(); bool isAnimals();
void setAnimals(bool animals); void setAnimals(bool animals);
bool isNpcsEnabled(); bool isNpcsEnabled();

View file

@ -1,3 +1,6 @@
// Minecraft.cpp : Defines the entry point for the application.
//
#include "stdafx.h" #include "stdafx.h"
#include <assert.h> #include <assert.h>
@ -6,6 +9,7 @@
#include <shellapi.h> #include <shellapi.h>
#include "GameConfig\Minecraft.spa.h" #include "GameConfig\Minecraft.spa.h"
#include "..\MinecraftServer.h" #include "..\MinecraftServer.h"
#include "..\PlayerList.h"
#include "..\LocalPlayer.h" #include "..\LocalPlayer.h"
#include "..\..\Minecraft.World\ItemInstance.h" #include "..\..\Minecraft.World\ItemInstance.h"
#include "..\..\Minecraft.World\MapItem.h" #include "..\..\Minecraft.World\MapItem.h"
@ -986,6 +990,7 @@ static Minecraft* InitialiseMinecraftRuntime()
ProfileManager.SetDebugFullOverride(true); ProfileManager.SetDebugFullOverride(true);
// Initialise storage manager — was accidentally left inside #if 0 in original code
StorageManager.Init(0, app.GetString(IDS_DEFAULT_SAVENAME), "savegame.dat", FIFTY_ONE_MB, &CConsoleMinecraftApp::DisplaySavingMessage, (LPVOID)&app, ""); StorageManager.Init(0, app.GetString(IDS_DEFAULT_SAVENAME), "savegame.dat", FIFTY_ONE_MB, &CConsoleMinecraftApp::DisplaySavingMessage, (LPVOID)&app, "");
StorageManager.StoreTMSPathName(); StorageManager.StoreTMSPathName();
@ -1092,6 +1097,12 @@ static int RunHeadlessServer()
app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 1); app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 1);
app.SetGameHostOption(eGameHostOption_DoDaylightCycle, 1); app.SetGameHostOption(eGameHostOption_DoDaylightCycle, 1);
// World size: 0=classic, 1=small, 2=medium, 3=large
int worldSizeSetting = serverSettings.getInt(L"world-size", 3);
if (worldSizeSetting < 0) worldSizeSetting = 0;
if (worldSizeSetting > 3) worldSizeSetting = 3;
app.SetGameHostOption(eGameHostOption_WorldSize, worldSizeSetting + 1);
MinecraftServer::resetFlags(); MinecraftServer::resetFlags();
g_NetworkManager.HostGame(0, false, true, MINECRAFT_NET_MAX_PLAYERS, 0); g_NetworkManager.HostGame(0, false, true, MINECRAFT_NET_MAX_PLAYERS, 0);
@ -1107,6 +1118,14 @@ static int RunHeadlessServer()
param->seed = 0; param->seed = 0;
param->settings = app.GetGameHostOption(eGameHostOption_All); param->settings = app.GetGameHostOption(eGameHostOption_All);
switch (worldSizeSetting)
{
case 0: param->xzSize = LEVEL_WIDTH_CLASSIC; param->hellScale = HELL_LEVEL_SCALE_CLASSIC; break;
case 1: param->xzSize = LEVEL_WIDTH_SMALL; param->hellScale = HELL_LEVEL_SCALE_SMALL; break;
case 2: param->xzSize = LEVEL_WIDTH_MEDIUM; param->hellScale = HELL_LEVEL_SCALE_MEDIUM; break;
case 3: param->xzSize = LEVEL_WIDTH_LARGE; param->hellScale = HELL_LEVEL_SCALE_LARGE; break;
}
g_NetworkManager.ServerStoppedCreate(true); g_NetworkManager.ServerStoppedCreate(true);
g_NetworkManager.ServerReadyCreate(true); g_NetworkManager.ServerReadyCreate(true);
@ -1158,6 +1177,20 @@ static int RunHeadlessServer()
printf("Stopping server...\n"); printf("Stopping server...\n");
fflush(stdout); fflush(stdout);
// Force save before shutdown — headless mode has no UI to trigger save-on-exit
MinecraftServer* shutdownServer = MinecraftServer::getInstance();
if (shutdownServer != NULL)
{
printf("Saving world...\n");
fflush(stdout);
PlayerList* pl = shutdownServer->getPlayers();
if (pl != NULL)
pl->saveAll(NULL, false);
shutdownServer->saveAllChunks();
printf("World saved.\n");
fflush(stdout);
}
app.m_bShutdown = true; app.m_bShutdown = true;
MinecraftServer::HaltServer(); MinecraftServer::HaltServer();
g_NetworkManager.LeaveGame(false); g_NetworkManager.LeaveGame(false);