Skip to content

Fix DedicatedServer several issues#1266

Merged
codeHusky merged 73 commits intosmartcmd:mainfrom
kuwacom:feature/dedicated-server
Mar 15, 2026
Merged

Fix DedicatedServer several issues#1266
codeHusky merged 73 commits intosmartcmd:mainfrom
kuwacom:feature/dedicated-server

Conversation

@kuwacom
Copy link
Contributor

@kuwacom kuwacom commented Mar 15, 2026

Description

This PR contains small follow-up fixes that were not fully included in #498.

Changes

  • Respect allow-flight server config in non-debug builds.
  • Reduce dedicated-server chunk send throttling and increase chunk update capacity for higher player counts.
  • Add a dedicated-only fallback path when small entity ID allocation is exhausted.
  • Fix incorrect zero-initialization size for removed-entity flag buffers.
  • Adjust dedicated autosave handling path so it runs without console UI/profiling assumptions.
  • Add robust Xvfb startup readiness flow in Docker entrypoint:
  • Validate DISPLAY format.
  • Remove stale X11 socket/lock files.
  • Wait until Xvfb socket is ready.

Previous Behavior

  • allow-flight could be unintentionally forced to true outside actual debug runtime conditions.
  • Chunk delivery became heavily delayed under dedicated server load (especially with more players).
  • Small entity ID exhaustion could trigger a hard stop (__debugbreak) on dedicated.
  • Removed-entity bitflag buffer initialization could leave part of the buffer uninitialized.
  • Dedicated container startup could race Xvfb readiness and fail with Failed to create window instance.

Root Cause

  • Legacy debug override condition was too broad for modern build/runtime combinations.
  • Legacy chunk throttling assumptions were too conservative for dedicated server networking.
  • Small-ID pool is fixed-size (0..2047) and exhaustion path was fail-stop.
  • memset length used element count bytes instead of total byte size.
  • Headless startup launched app before X server handshake/socket was fully ready; stale X11 artifacts could remain across restarts.

New Behavior

  • allow-flight now follows server config unless true debug conditions are met.
  • Dedicated server sends chunk data more aggressively and handles larger pending chunk update sets.
  • Dedicated server no longer hard-stops immediately on small-ID exhaustion; it uses a fallback ID path to continue running.
  • Removed-entity flags are fully zero-initialized before use.
  • Container startup reliably waits for a valid X display before launching the server process, with clearer diagnostics on failure.

Fix Implementation

  • Minecraft.Client/MinecraftServer.cpp
  • Tighten debug guard for flight override.
  • Dedicated-specific chunk packet send gate adjustment.
  • Dedicated autosave path compile-time handling improvements.
  • Minecraft.Client/ServerPlayer.cpp
  • Correct memset size for removal flags.
  • Dedicated-specific relaxed chunk-send condition.
  • Minecraft.World/Entity.cpp
  • Add dedicated fallback allocation path in Entity::getSmallId() when 0..2047 pool is exhausted.
  • Minecraft.World/Level.h
  • Increase LEVEL_CHUNKS_TO_UPDATE_MAX for dedicated builds.
  • docker/dedicated-server/entrypoint.sh
  • Add wait_for_xvfb_ready() with process/socket checks, timeout, and log dump.
  • Validate display number parsing.
  • Clean stale /tmp/.X11-unix/X* and /tmp/.X*-lock before startup.
  • Log readiness and skip Xvfb startup when external DISPLAY is already provided.

AI Use Disclosure

No
For translating and compiling messages

kuwacom added 30 commits March 4, 2026 18:12
- Introduced `ServerMain.cpp` for the dedicated server logic, handling command-line arguments, server initialization, and network management.
- Created `postbuild_server.ps1` script for post-build tasks, including copying necessary resources and DLLs for the dedicated server.
- Added `CopyServerAssets.cmake` to manage the copying of server assets during the build process, ensuring required files are available for the dedicated server.
- Defined project filters in `Minecraft.Server.vcxproj.filters` for better organization of server-related files.
- Introduced ServerLogger for logging startup steps and world I/O operations.
- Implemented ServerProperties for loading and saving server configuration from `server.properties`.
- Added WorldManager to handle world loading and creation based on server properties.
- Updated ServerMain to integrate server properties loading and world management.
- Enhanced project files to include new source and header files for the server components.
# Conflicts:
#	Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp
#	Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp
#	Minecraft.Client/Windows64/Network/WinsockNetLayer.h
Since 31881af56936aeef38ff322b975fd0 , `skinHud.swf` for 720 is not included in `MediaWindows64.arc`,
the app crashes unless the virtual screen is set to HD.
…erver

# Conflicts:
#	.gitignore
#	CMakeLists.txt
#	Minecraft.Client/Common/Network/GameNetworkManager.cpp
…ing sources

- remove stale Windows64 Miles (mss64) link/copy references from server build
- add Common/Filesystem/Filesystem.cpp to Minecraft.Server.vcxproj
- add Windows64/PostProcesser.cpp to Minecraft.Server.vcxproj
- fix unresolved externals (PostProcesser::*, FileExists) in dedicated server build
Since the crash caused by the 720p `skinHud.swf` not being included in `MediaWindows64.arc` has been resolved, switching back to 720p to reduce resource usage.
add with entrypoint and build scripts
…ft-LegacyConsoleEdition into feature/dedicated-server
on the server side, I fixed the behavior introduced after commit aadb511, where newly created worlds are intentionally not saved to disk immediately.
LAN-Discovery, which isn’t needed in server mode and could potentially be a security risk, has also been disabled(only server mode).
- Integrated linenoise library for line editing and completion in the server console.
- Updated ServerLogger to handle external writes safely during logging.
- Modified ServerMain to initialize and manage the ServerCli for command input.
- The implementation is separate from everything else, so it doesn't affect anything else.
- The command input section and execution section are separated into threads.
Like most command line tools, it highlights predictions in gray.
…down race

Before this change, server/host shutdown closed sockets directly in
ServerConnection::stop(), which bypassed the normal disconnect flow.
As a result, clients could be dropped without receiving a proper
DisconnectPacket during stop/kill/world-close paths.

Also, WinsockNetLayer::Shutdown() could destroy synchronization objects
while host-side recv threads were still exiting, causing a crash in
RecvThreadProc (access violation on world close in host mode).
- Add client-side host disconnect handling in CPlatformNetworkManagerStub::DoWork() for _WINDOWS64.
- When in QNET_STATE_GAME_PLAY as a non-host and WinsockNetLayer::IsConnected() becomes false, trigger g_NetworkManager.HandleDisconnect(false) to enter the normal disconnect/UI flow.
- Use m_bLeaveGameOnTick as a one-shot guard to prevent repeated disconnect handling while the link remains down.
- Reset m_bLeaveGameOnTick on LeaveGame(), HostGame(), and JoinGame() to avoid stale state across sessions.
Conflict resolution summary:

- .gitignore: kept dedicated-server-specific ignore entries (tmp*/, _server_asset_probe/, server-data/) and also kept main-side entries (*.user, /out).

- Minecraft.Client/Common/Network/GameNetworkManager.cpp: kept int64_t seed from main and preserved dedicatedNoLocalHostPlayer logic from dedicated-server.

- Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp: preserved dedicated-server shutdown flow and also included main-side cleanup for s_smallIdToSocketLock.
Moved file operations to `utils`.
…P bans

- add Access frontend that publishes thread-safe ban manager snapshots for dedicated server use
- add BanManager storage for banned-players.json and banned-ips.json with load/save/update flows
- add persistent player and IP ban checks during dedicated server connection handling
- add UTF-8 BOM-safe JSON parsing and shared file helpers backed by nlohmann/json
- add Unicode-safe ban file read/write and safer atomic replacement behavior on Windows
- add active-ban snapshot APIs and expiry-aware filtering for expires metadata
- add RAII-based dedicated access shutdown handling during server startup and teardown
- As a side effect, saving has become faster!
kuwacom and others added 22 commits March 12, 2026 02:59
Add random seed picker for newly created worlds
As the number of commands has increased and become harder to navigate, each command has been organized into separate folders.
Support for the stream (file stdin) required when attaching a tty to a Docker container on Linux.
Most of these commands are executed using the command dispatcher implemented on the `Minecraft.World` side. When registering them with the dispatcher, the sender uses a permission-enabled configuration that treats the CLI as a player.

- default game.
- enchant
- experience.
- give
- kill(currently, getting a permission error for some reason)
- time
- weather.
- update tp & gamemode command
# Conflicts:
#	Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp
…tion

Added the following anti-cheat measures and add spawn protection to `server.properties`.
- instant break
- speed
- reach
Wait for Xvfb to be fully ready before starting.
 Fix flight, entity ids, chunk loading speeds, and autosave ui for dedi removal
# Conflicts:
#	docker/dedicated-server/entrypoint.sh
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 15, 2026

Please excuse the poor appearance due to creating a pull request before merging the latest information from main.

@kuwacom kuwacom marked this pull request as ready for review March 15, 2026 13:29
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 15, 2026

The issue when starting Docker should probably be fixed as soon as possible.
The server sometimes fails to start intermittently.

@codeHusky
Copy link
Collaborator

your README put the docker stuff way at the top for some reason. please use the current public order to avoid conflicts. merging this

@codeHusky
Copy link
Collaborator

also in the future, we should switch to using a runtime global like IsDedicated() instead of preprocessor checks IMO

@codeHusky codeHusky merged commit e9f5b4b into smartcmd:main Mar 15, 2026
1 check passed
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 16, 2026

your README put the docker stuff way at the top for some reason. please use the current public order to avoid conflicts. merging this

Thank you for the corrections.
When I wrote to the readme, I accidentally wrote it above the keyboard and mouse instructions, and I left before I could incorporate the corrections #ab9b034, which is probably the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants