mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
6.2 KiB
6.2 KiB
Minecraft.Server Developer Guide (English)
This document is for contributors who are new to Minecraft.Server and need a practical map for adding or modifying features safely.
1. What This Server Does
Minecraft.Server is the dedicated-server executable entry for this codebase.
Core responsibilities:
- Read and normalize
server.properties - Initialize Windows/network/runtime systems
- Load or create the target world
- Run the dedicated main loop (network tick, XUI actions, autosave, CLI command processing)
- Perform safe save and shutdown
2. Important Files
Startup and Runtime
Windows64/ServerMain.cpp- Process entry (
main) - CLI argument parsing
- Runtime setup and shutdown flow
- Main loop + autosave scheduler
- Process entry (
World Selection and Save Load
WorldManager.hWorldManager.cpp- Finds matching save by
level-idfirst, then world-name fallback - Applies storage title + save ID consistently
- Wait helpers for async storage/server action completion
- Finds matching save by
Server Properties
ServerProperties.hServerProperties.cpp- Default values
- Parse/normalize/write
server.properties - Exposes
ServerPropertiesConfig
Logging
ServerLogger.hServerLogger.cpp- Log level parsing
- Colored/timestamped console logs
- Standard categories (
startup,world-io,console, etc.)
Console Command System
Console/ServerCli.cpp(facade)Console/ServerCliInput.cpp(linenoise input thread + completion bridge)Console/ServerCliParser.cpp(tokenization/quoted args/completion context)Console/ServerCliEngine.cpp(dispatch, completion, helpers)Console/ServerCliRegistry.cpp(command registration + lookup)Console/commands/*(individual commands)
3. End-to-End Startup Flow
Main flow in Windows64/ServerMain.cpp:
- Load
server.propertiesviaLoadServerPropertiesConfig() - Apply CLI argument overrides (
-port,-bind,-name,-seed,-loglevel) - Initialize runtime systems (window/device/profile/network/thread storage)
- Set host/game options from
ServerPropertiesConfig - Bootstrap world with
BootstrapWorldForServer(...) - Start hosted game thread (
RunNetworkGameThreadProc) - Enter main loop:
TickCoreSystems()HandleXuiActions()serverCli.Poll()- autosave scheduling
- On shutdown:
- wait for action idle
- request final save
- halt server and terminate network/device subsystems
4. Common Development Tasks
4.1 Add a New CLI Command
Use this pattern when adding commands like /kick, /time, etc.
- Add files under
Console/commands/CliCommandYourCommand.hCliCommandYourCommand.cpp
- Implement
IServerCliCommandName(),Usage(),Description(),Execute(...)- Optional:
Aliases()andComplete(...)
- Register command in
ServerCliEngine::RegisterDefaultCommands() - Add source/header to build definitions:
CMakeLists.txt(MINECRAFT_SERVER_SOURCES)Minecraft.Server/Minecraft.Server.vcxproj(<ClCompile>/<ClInclude>)
- Manual verify:
- command appears in
help - command executes correctly
- completion behavior is correct for both
cmdand/cmd
- command appears in
Implementation references:
CliCommandHelp.cppfor simple no-arg commandCliCommandTp.cppfor multi-arg + completion + runtime checksCliCommandGamemode.cppfor argument parsing and mode validation
4.2 Add or Change a server.properties Key
- Add/update field in
ServerPropertiesConfig(ServerProperties.h) - Add default value to
kServerPropertyDefaults(ServerProperties.cpp) - Load and normalize value in
LoadServerPropertiesConfig()- Use existing read helpers for bool/int/string/int64/log level
- If this value should be persisted on save, update
SaveServerPropertiesConfig() - Apply to runtime where needed:
ApplyServerPropertiesToDedicatedConfig(...)- host options in
ServerMain.cpp(app.SetGameHostOption(...))
- Manual verify:
- file regeneration when key is missing
- invalid values are normalized
- runtime behavior reflects the new value
4.3 Change World Load/Create Behavior
Primary code is in WorldManager.cpp.
Current matching policy:
- Match by
level-id(UTF8SaveFilename) first - Fallback to world-name match on title/file name
When changing this logic:
- Keep
ApplyWorldStorageTarget(...)usage consistent (title + save ID together) - Preserve periodic ticking in wait loops (
tickProc) to avoid async deadlocks - Keep timeout/error logs specific enough for diagnosis
- Verify:
- existing world is reused correctly
- no accidental new save directory creation
- shutdown save still succeeds
4.4 Add Logging for New Feature Work
Use ServerLogger helpers:
LogDebug,LogInfo,LogWarn,LogError- or formatted variants
LogInfof, etc.
Recommended categories:
startupfor init/shutdown lifecycleworld-iofor save/world operationsconsolefor CLI command handling
5. Build and Run
From repository root:
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Debug --target MinecraftServer
cd .\build\Debug
.\Minecraft.Server.exe -port 25565 -bind 0.0.0.0 -name DedicatedServer
Notes:
- Launch from output directory so relative assets/files resolve correctly
server.propertiesis loaded from current working directory- For Visual Studio workflow, see root
COMPILE.md
6. Safety Checklist Before Commit
- The server starts without crash on a clean
server.properties - Existing world loads by expected
level-id - New world creation path still performs initial save
- CLI still accepts input and completion is responsive
- No busy wait path removed from async wait loops
- Both CMake and
.vcxprojinclude newly added source files
7. Quick Troubleshooting
- Unknown command not found:
- check
RegisterDefaultCommands()and build-file entries
- check
- Autosave or shutdown save timing out:
- confirm wait loops still call
TickCoreSystems()andHandleXuiActions()where required
- confirm wait loops still call
- World not reused on restart:
- inspect
level-idnormalization and matching logic inWorldManager.cpp
- inspect
- Settings not applied:
- confirm value is loaded into
ServerPropertiesConfigand then applied inServerMain.cpp
- confirm value is loaded into