diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 012ae19bd..20aa0b273 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -202,6 +202,10 @@ static bool ExecuteConsoleCommand(MinecraftServer *server, const wstring &rawCom if (action == L"stop") { + server->info(L"Saving before stopping..."); + if (playerList != NULL) + playerList->saveAll(NULL, false); + server->saveAllChunks(); server->info(L"Stopping server..."); MinecraftServer::HaltServer(); return true; @@ -238,6 +242,7 @@ static bool ExecuteConsoleCommand(MinecraftServer *server, const wstring &rawCom { playerList->saveAll(NULL, false); } + server->saveAllChunks(); server->info(L"World saved."); return true; } @@ -2437,4 +2442,4 @@ bool MinecraftServer::flagEntitiesToBeRemoved(unsigned int *flags) } } return removedFound; -} +} \ No newline at end of file diff --git a/Minecraft.Client/MinecraftServer.h b/Minecraft.Client/MinecraftServer.h index 7fa8c7522..c60c7f333 100644 --- a/Minecraft.Client/MinecraftServer.h +++ b/Minecraft.Client/MinecraftServer.h @@ -138,7 +138,6 @@ private: bool loadLevel(LevelStorageSource *storageSource, const wstring& name, __int64 levelSeed, LevelType *pLevelType, NetworkGameInitData *initData); void setProgress(const wstring& status, int progress); void endProgress(); - void saveAllChunks(); void saveGameRules(); void stopServer(bool didInit); #ifdef _LARGE_WORLDS @@ -152,6 +151,7 @@ public: PlayerList *getPlayers(); void setPlayers(PlayerList *players); ServerConnection *getConnection(); + void saveAllChunks(); bool isAnimals(); void setAnimals(bool animals); bool isNpcsEnabled(); @@ -276,4 +276,4 @@ public: bool IsSuspending(); // 4J Stu - A load of functions were all added in 1.0.1 in the ServerInterface, but I don't think we need any of them -}; +}; \ No newline at end of file diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 0d827a0bf..e56e9ff0d 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1,3 +1,6 @@ +// Minecraft.cpp : Defines the entry point for the application. +// + #include "stdafx.h" #include @@ -6,6 +9,7 @@ #include #include "GameConfig\Minecraft.spa.h" #include "..\MinecraftServer.h" +#include "..\PlayerList.h" #include "..\LocalPlayer.h" #include "..\..\Minecraft.World\ItemInstance.h" #include "..\..\Minecraft.World\MapItem.h" @@ -986,6 +990,7 @@ static Minecraft* InitialiseMinecraftRuntime() 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.StoreTMSPathName(); @@ -1092,6 +1097,12 @@ static int RunHeadlessServer() app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 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(); g_NetworkManager.HostGame(0, false, true, MINECRAFT_NET_MAX_PLAYERS, 0); @@ -1107,6 +1118,14 @@ static int RunHeadlessServer() param->seed = 0; 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.ServerReadyCreate(true); @@ -1158,6 +1177,20 @@ static int RunHeadlessServer() printf("Stopping server...\n"); 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; MinecraftServer::HaltServer(); g_NetworkManager.LeaveGame(false); diff --git a/Minecraft.World/ConsoleSaveFileOutputStream.cpp b/Minecraft.World/ConsoleSaveFileOutputStream.cpp index 3fd9c0c50..b7098860a 100644 --- a/Minecraft.World/ConsoleSaveFileOutputStream.cpp +++ b/Minecraft.World/ConsoleSaveFileOutputStream.cpp @@ -127,4 +127,4 @@ void ConsoleSaveFileOutputStream::close() // Stop the dtor from trying to close it again m_saveFile = NULL; } -} +} \ No newline at end of file