Implementation of Dedicated Server in Isolation#498
Implementation of Dedicated Server in Isolation#498kuwacom wants to merge 26 commits intosmartcmd:mainfrom
Conversation
- 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.
|
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
|
Some things have changed in the past day-ish, watch out for incompatibilities/redundant re-implementations of these:
|
|
So
|
Since 31881af56936aeef38ff322b975fd0 , `skinHud.swf` for 720 is not included in `MediaWindows64.arc`, the app crashes unless the virtual screen is set to HD.
|
It was partially affected by #495, but I was able to merge it without any issues. |
|
is it still only LAN multiplayer only? or can worlds be opened up to more people? |
|
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. |
|
oh damn. so i could run this on a vps? |
|
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. |
|
i mean, i've tried it on linux and it works fine. i could try and create a docker image if you'd like |
You can run it fine on Linux without a GUI launcher via umu |
seriously! |
|
wine also works really well. tried lutris and has similar results to umu |
|
Which one has a smaller image size? |
|
wine iirc |
|
Currently there are two approaches: the separated version (this pull request) and the 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. |
|
Realistically speaking a completely separate Server executable should be our preferred way for this to work. The |
|
If we're planning to merge the separated server in the future, I was considering removing the |
Yeah |
|
Sorry, that’s not written in the description, but it’s still a dummy for now. |
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) |
Like most command line tools, it highlights predictions in gray.
I’ve basically implemented all the features I had in mind! Also, there are some messy cases where reusable utility functions like |
|
update pullrequest description newer |
Unified the scattered utility functions.
…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.
|
Could you implement an IP ban feature too? We’ve had a number of servers struggling with griefers and trolls so having the ability to 1) identify who’s connected from what IP and 2) IP Ban them would be super helpful for them |
|
Sounds good! |
|
I noticed a new issue. When the client opens a world in host mode, LAN advertising doesn’t seem to work. Even with logs added throughout for debugging, it seems to be working, so it might be an environment issue rather than the code. |
|
@kuwacom when you will be ready to merge, let me know, I will review the code |
Would it be better to merge once we reach a certain point? |
|
Personally, I would like to see a very stable support for a feature like this. So if you feel this PR is enough for your needs, decide it yourself. |
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.
In the end, there’s a 99% chance this issue is specific to my environment. |
|
Saw this claim on discord
Could the protection against this be implemented? |
After looking through the code, it seems that the // 4J-PB - removing this one for now /*if (dist > 100.0f)
{
// logger.warning(player->name + " moved too quickly!");
disconnect(DisconnectPacket::eDisconnect_MovedTooQuickly);
// System.out.println("Moved too quickly at " + xt + ", " + yt + ", " + zt);
// teleport(player->x, player->y, player->z, player->yRot, player->xRot);
return;
}
*/ |
|
The same applies to the instant break. It seems that the server-side block breaking timer check was intentionally commented out by 4J. Tile *tile = Tile::tiles[t];
// MGH - removed checking for the destroy progress here, it has already been checked on the client before it sent the packet.
// fixes issues with this failing to destroy because of packets bunching up
// float destroyProgress = tile->getDestroyProgress(player, player->level, x, y, z) * (ticksSpentDestroying + 1);
// if (destroyProgress >= .7f || bIgnoreDestroyProgress)
{
isDestroyingBlock = false;
level->destroyTileProgress(player->entityId, x, y, z, -1);
destroyBlock(x, y, z);
}
// else if (!hasDelayedDestroy)
// {
// isDestroyingBlock = false;
// hasDelayedDestroy = true;
// delayedDestroyX = x;
// delayedDestroyY = y;
// delayedDestroyZ = z;
// delayedTickStart = destroyProgressStart;
// } |
|
Are we able to change the autosave interval? Every minute gets kind of annoying and intrusive to gameplay having that screen pop up every minute. |
Please check |
Very nice, thanks a bunch, hooefully ban ip and kick player commands next :) |
|
Considering we’re not in 2012 anymore, I think we can ignore the network instability thing and just prefer something safer that avoids as much cheating. Also pretty classic console game dev to write something like “well we already validated this on the client side so why would we do it server side” lmao I’d imagine the moving too fast checks might not work 100% properly with creative mode but they’d probably work fine with survival. Regarding block breaking, there’s definitely some sort of maximum speed you can break blocks at in LCE creative. If there isn’t it wouldn’t be too hard to implement a same clicks-per-second limit before we start rejecting their block breaks |
|
I plan to try restoring these implementations later and see how they behave. |





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:
server.propertiessupport (including LAN advertise and host options),level-id,Minecraft.Clientchanges remain focused on dedicated-server bridge compatibility.#65
Changes
Dedicated Server Executable / Startup
Minecraft.Server/Windows64/ServerMain.cppMinecraft.Server/Minecraft.Server.vcxproj(+ filters)server.propertiesdefaults,level-id/level-name,-port,-ip/-bind,-name,-maxplayers,-seed,-loglevel,-helpserver.properties, it can also be integrated into fully autonomous deployment systems like Kubernetes.Dedicated Runtime Modules
ServerProperties(defaulting, normalization, persistence for dedicated options)WorldManager(load existing world bylevel-id, fallback by name, or create new world)ServerLogger(debug|info|warn|error)Minecraft.Server/Common/StringUtilsInteractive Server Console
ServerCli,ServerCliInput,ServerCliParser,ServerCliEngine,ServerCliRegistryhelp(?)stoplisttp(teleport)gamemode(gm)survival|creative|s|c|0|1).Minecraft.Client Bridge Changes (Dedicated Compatibility Scope)
Only dedicated-server compatibility behavior was changed in client networking paths:
Minecraft.Client/MinecraftServer.hNetworkGameInitData::dedicatedNoLocalHostPlayer.Minecraft.Client/Common/Network/GameNetworkManager.cppClientConnectioncreation.Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpplan-advertise).Minecraft.Client/Windows64/Network/WinsockNetLayer.h/.cppBuild / Tooling / Docs
CMakeLists.txt:MinecraftServertarget + post-build asset copycmake/CopyServerAssets.cmake: minimal dedicated runtime asset copyMinecraftConsoles.slnCOMPILE.md.gitignoredocker/dedicated-server/Dockerfiledocker/dedicated-server/entrypoint.shdocker-compose.dedicated-server.ymldocker-build-dedicated-server.shstart-dedicated-server.shREADME.mddedicated Docker section