Skip to content

Implementation of Dedicated Server in Isolation#498

Open
kuwacom wants to merge 65 commits intosmartcmd:mainfrom
kuwacom:feature/dedicated-server
Open

Implementation of Dedicated Server in Isolation#498
kuwacom wants to merge 65 commits intosmartcmd:mainfrom
kuwacom:feature/dedicated-server

Conversation

@kuwacom
Copy link
Contributor

@kuwacom kuwacom commented Mar 4, 2026

Description

This PR introduces a Windows64 dedicated server executable (Minecraft.Server) and expands the dedicated-server runtime/build pipeline.

Compared to the initial pull request description, the following features have been newly added:

  • interactive server console (linenoise + command completion),
  • broader server.properties support (including LAN advertise and host options),
  • world bootstrap/load behavior based on level-id,
  • Docker (Wine) runtime support and helper scripts.

Minecraft.Client changes remain focused on dedicated-server bridge compatibility.
#65

image

Changes

Dedicated Server Executable / Startup

  • Added dedicated server entrypoint and project:
    • Minecraft.Server/Windows64/ServerMain.cpp
    • Minecraft.Server/Minecraft.Server.vcxproj (+ filters)
  • Dedicated startup flow now:
    • loads server.properties defaults,
    • applies CLI overrides,
    • bootstraps world by level-id / level-name,
    • performs initial save for newly created worlds,
    • runs periodic autosave and graceful shutdown save.
  • Dedicated launch options:
    • -port, -ip/-bind, -name, -maxplayers, -seed, -loglevel, -help
    • Since the arguments can basically override server.properties, it can also be integrated into fully autonomous deployment systems like Kubernetes.

Dedicated Runtime Modules

  • Added/expanded:
    • ServerProperties (defaulting, normalization, persistence for dedicated options)
    • WorldManager (load existing world by level-id, fallback by name, or create new world)
    • ServerLogger (debug|info|warn|error)
  • Added shared server string utility layer:
    • Minecraft.Server/Common/StringUtils
    • used by logger/properties/world/console paths to avoid duplicated conversion/normalize logic.

Interactive Server Console

  • Added console runtime:
    • ServerCli, ServerCliInput, ServerCliParser, ServerCliEngine, ServerCliRegistry
    • linenoise-based input/history/completion support.
  • Added built-in commands:
    • help (?)
    • stop
    • list
    • tp (teleport)
    • gamemode (gm)
  • Added completion behavior:
    • command/alias completion,
    • player name completion,
    • gamemode token completion (survival|creative|s|c|0|1).

Minecraft.Client Bridge Changes (Dedicated Compatibility Scope)

Only dedicated-server compatibility behavior was changed in client networking paths:

  1. Minecraft.Client/MinecraftServer.h

    • Added NetworkGameInitData::dedicatedNoLocalHostPlayer.
  2. Minecraft.Client/Common/Network/GameNetworkManager.cpp

    • Added dedicated host path to skip local host ClientConnection creation.
    • Preserved host telemetry and multiplayer mode initialization behavior.
  3. Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp

    • Dedicated host startup now uses configured bind IP/port globals.
    • LAN advertising is now controlled by dedicated config (lan-advertise).
  4. Minecraft.Client/Windows64/Network/WinsockNetLayer.h/.cpp

    • Added dedicated LAN advertise global.
    • In dedicated mode, LAN discovery thread is not started.

Build / Tooling / Docs

  • Added CMake target and wiring:
    • CMakeLists.txt: MinecraftServer target + post-build asset copy
    • cmake/CopyServerAssets.cmake: minimal dedicated runtime asset copy
  • Updated solution/docs/ignore:
    • MinecraftConsoles.sln
    • COMPILE.md
    • .gitignore
  • Added Docker runtime support (Wine):
    • docker/dedicated-server/Dockerfile
    • docker/dedicated-server/entrypoint.sh
    • docker-compose.dedicated-server.yml
    • docker-build-dedicated-server.sh
    • start-dedicated-server.sh
    • README.md dedicated Docker section

kuwacom added 4 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.
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 4, 2026

I hadn’t been merging upstream changes while implementing, so I’m in the middle of merging them now...

# Conflicts:
#	Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp
#	Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp
#	Minecraft.Client/Windows64/Network/WinsockNetLayer.h
@gizmogoat
Copy link

gizmogoat commented Mar 4, 2026

Some things have changed in the past day-ish, watch out for incompatibilities/redundant re-implementations of these:

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 4, 2026

So -server has been added, I see.
From a quick look at the issues, it seems there are still a few world-related bugs remaining.

servers.txt is a nice addition as well.
It’s more user-friendly than -target.

kuwacom added 2 commits March 5, 2026 09:38
Since 31881af56936aeef38ff322b975fd0 , `skinHud.swf` for 720 is not included in `MediaWindows64.arc`,
the app crashes unless the virtual screen is set to HD.
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

It was partially affected by #495, but I was able to merge it without any issues.

@haychk
Copy link

haychk commented Mar 5, 2026

is it still only LAN multiplayer only? or can worlds be opened up to more people?

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

It can be accessed from anywhere if you have a suitable network that can be accessed from the global internet (a network line that can open the specified TCP port).

In short, it's a regular server app.

@haychk
Copy link

haychk commented Mar 5, 2026

oh damn. so i could run this on a vps?

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

Yes, but since it still uses a lot of Windows API internally (to maintain compatibility), it requires a Windows system or a system that includes Windows API to run.

I would like to eventually release a Linux version and put it into Docker.

@haychk
Copy link

haychk commented Mar 5, 2026

i mean, i've tried it on linux and it works fine. i could try and create a docker image if you'd like

@gizmogoat
Copy link

I would like to eventually release a Linux version and put it into Docker.

You can run it fine on Linux without a GUI launcher via umu

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

i mean, i've tried it on linux and it works fine. i could try and create a docker image if you'd like

seriously!
That's nice.

@haychk
Copy link

haychk commented Mar 5, 2026

wine also works really well. tried lutris and has similar results to umu

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

Which one has a smaller image size?
wine or umu

@haychk
Copy link

haychk commented Mar 5, 2026

wine iirc

@void2012 void2012 marked this pull request as draft March 5, 2026 07:45
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

Currently there are two approaches: the separated version (this pull request) and the -server option version (merged yesterday) that starts the client directly as a server. Which one should be prioritized?

The separated version modifies the world-saving logic and changes the startup logic, so integrating it into the client side would be a bit tricky.

Alternatively, it would also be possible to keep both.

@codeHusky
Copy link
Collaborator

Realistically speaking a completely separate Server executable should be our preferred way for this to work. The -server command line option is moreso jank and this is far cleaner.

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 5, 2026

If we're planning to merge the separated server in the future, I was considering removing the -server option and the unnecessary client-side logic as well. Would it be okay to leave them as they are for now?

@smartcmd
Copy link
Owner

smartcmd commented Mar 5, 2026

If we're planning to merge the separated server in the future, I was considering removing the -server option and the unnecessary client-side logic as well. Would it be okay to leave them as they are for now?

Yeah

@haychk
Copy link

haychk commented Mar 6, 2026

seems to be a bug where i cannot change the game's difficulty and enable some settings (trust players, pvp etc)
image
image
doing this all on a vps too

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 6, 2026

Sorry, that’s not written in the description, but it’s still a dummy for now.
It’s only included in the default server.properties generation ahead of time (so it can be implemented later).

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 6, 2026

doing this all on a vps too

Would it be possible to send the Dockerfile and docker-compose.yml?

@haychk
Copy link

haychk commented Mar 6, 2026

doing this all on a vps too

Would it be possible to send the Dockerfile and docker-compose.yml?

not using a docker image, which is surprising. i took your pr build and ran it on my vps. works REALLY well, minus the default server settings being awful (peaceful mode, no pvp etc)

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 13, 2026

Are you using the latest build and the Docker Compose YAML?
Also, do other commands and text input not respond as well?

Previously, it only used key event–driven input via the Windows API, but I recently added FileSystem stdin support for Linux systems.
This requires starting with an option enabled.

@puff25

@puff25
Copy link

puff25 commented Mar 13, 2026

I am using the latest release that came out 4 hours ago, and also yes other commands and text input does not respond as well.

What option do you need to enable when starting to use the stdin support?

@puff25
Copy link

puff25 commented Mar 13, 2026

Oh forgot to mention I am using the latest yaml as well as I pulled the PR within the last few hours.

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 13, 2026

I am using the latest release that came out 4 hours ago, and also yes other commands and text input does not respond as well.

What option do you need to enable when starting to use the stdin support?

The option is already included in the latest YAML.
It looks like this will require further investigation.

@puff25
Copy link

puff25 commented Mar 13, 2026

Oh wait no! I figured it out by reading your commit.

By setting the SERVER_CLI_INPUT_MODE environment variable to true, it enables the input!

Sorry about that, I should've read the yaml file before posting.

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 13, 2026

It is not true.
In the YAML, it should default to stream.

image image

@puff25
Copy link

puff25 commented Mar 13, 2026

Oh sorry I guess I misunderstood how it works. Strange though that it's not working out of the box, seems like it's returning false by default for some reason.

@puff25
Copy link

puff25 commented Mar 13, 2026

Ok if you saw my last comment, forget it. I hadn't attached my tty to the docker container so of course it didn't work 😅. I'm not sure why this is happening.

…tion

Added the following anti-cheat measures and add spawn protection to `server.properties`.
- instant break
- speed
- reach
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 13, 2026

I plan to try restoring these implementations later and see how they behave.

Implemented basic minimum anti-cheat measures.(this video introduces instant break)
Spawn protection has also been added.

There still seem to be other areas that could be improved.

anti-cheat.mp4

@puff25
Copy link

puff25 commented Mar 14, 2026

I discovered the issue I think, in docker-compose.dedicated-server.ghcr.yml the image is set to the test image which was created before the stdin commit:

image

@puff25
Copy link

puff25 commented Mar 14, 2026

If you pull the latest image then commands work, so I think this might have been it.

There is still a bug where the output will overlap what you are typing though

@puff25
Copy link

puff25 commented Mar 14, 2026

There is still a bug where the output will overlap what you are typing though

Here's a video to show what I mean:
Screencast_20260314_014325.webm

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 14, 2026

If you pull the latest image then commands work, so I think this might have been it.

There is still a bug where the output will overlap what you are typing though

This is currently expected, as the display control is not working properly.
This update adds basic support for entering commands.

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 14, 2026

I’m considering integrating this into main soon as a base server feature.
Please let me know if you have any feedback or concerns.

Please also perform at least basic verification in advance.

The additional features that were previously added in this repository (such as the C# plugin and MS Auth) will be separated into their own branches and submitted again as pull requests.

The same approach will be used for other additional features as well.

@codeHusky @smartcmd

@codeHusky
Copy link
Collaborator

I’m fully behind reviewing and merging this if you think it’s ready. Just switch it off draft and I’ll give it a once over

@kuwacom kuwacom marked this pull request as ready for review March 14, 2026 17:35
@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 14, 2026

I’m fully behind reviewing and merging this if you think it’s ready. Just switch it off draft and I’ll give it a once over

ok, please

@puff25
Copy link

puff25 commented Mar 14, 2026

If you pull the latest image then commands work, so I think this might have been it.
There is still a bug where the output will overlap what you are typing though

This is currently expected, as the display control is not working properly. This update adds basic support for entering commands.

Ah okay I see, well good to know. It's a little annoying but I can deal with it. I'd rather have working commands than nothing. But btw shouldn't you change the image that gets pulled in the docker compose yaml to the nightly one instead of the test one?

@puff25
Copy link

puff25 commented Mar 14, 2026

I discovered the issue I think, in docker-compose.dedicated-server.ghcr.yml the image is set to the test image which was created before the stdin commit:
image

^

@puff25
Copy link

puff25 commented Mar 14, 2026

Oh wait I guess if it's potentially getting merged soon then that will just be handled after its merged since a new image will be made on the main repo. So nvm.

@kuwacom
Copy link
Contributor Author

kuwacom commented Mar 14, 2026

If you pull the latest image then commands work, so I think this might have been it.
There is still a bug where the output will overlap what you are typing though

This is currently expected, as the display control is not working properly. This update adds basic support for entering commands.

Ah okay I see, well good to know. It's a little annoying but I can deal with it. I'd rather have working commands than nothing. But btw shouldn't you change the image that gets pulled in the docker compose yaml to the nightly one instead of the test one?

You're right—
I completely forgot to fix this!!!!

I'll commit the fixes for this.
If possible, please also let others know on Discord.

@puff25
Copy link

puff25 commented Mar 14, 2026

I put a message about it in the discord 👍

@puff25
Copy link

puff25 commented Mar 14, 2026

Ok there seems to be a new issue, for some reason after a while it starts giving the error Failed to create window instance. when starting the docker container. It keeps restarting and getting the same error. I tried stopping and starting it manually and recreating the container but it still happens.

Here's a video:
Screencast_20260314_211200.webm

@puff25
Copy link

puff25 commented Mar 14, 2026

Ok hold on now it's working again? Not sure what happened but I think it might have to do with the DISPLAY environment variable. I'm gonna test around a bit.

@puff25
Copy link

puff25 commented Mar 14, 2026

Okay from testing around it seems like I must've set the DISPLAY environment variable to some value, which causes this if statement in entrypoint.sh to not run which will cause the error since it needs the virtual screen:

image

I don't remember setting it to anything though, but maybe I did it on accident. I'm not sure. I hope this was just an error on my end :P

@puff25
Copy link

puff25 commented Mar 14, 2026

Okay from further testing it seems like if I try to edit server.properties in any way it causes that error to happen. Not sure why that is but I'm guessing it's something in entrypoint.sh. I'm going to try find what it is.

@puff25
Copy link

puff25 commented Mar 14, 2026

So I tested a bit and if I edit server.properties inside the server-data folder while the server is running, it'll launch properly if I restart the container. But if I stop the server and try to edit server.properties and then start the container it gives that error until I delete the server.properties file and restart it.

@codeHusky codeHusky self-requested a review March 14, 2026 22:21
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.