Dedicated server
The dedicated server is the same engine as the game without a window or GPU. It loads the level, runs the same physics, animation and navigation, and is the authority over everything that matters.
One engine on both sides
The server composes the level from the engine's own data, physics and animation modules. It collides with the same terrain and colliders the game does and poses hitboxes with the same animator, so client and server agree on what happened. Game rules run on it as C# game modes (or a native game module), and the game's scripts run there too unless they are marked [ClientOnly].
Run it
| Option | Meaning |
|---|---|
--content, --scene | The content folder and the level to load (a server cook's Content, or the project's while developing) |
--script-assembly | The game's script assembly |
--game-mode | The C# GameMode class that owns the rules |
--rule key=value | A session rule, read with GameSession.GetSetting |
--port, --bind | The game port (UDP 7777 by default) and the address to bind; 127.0.0.1 keeps everything on this machine |
--net-sim | Simulated network conditions for testing (Network testing) |
Ctrl+C stops the server in order. KroysServerDebug takes the same options and adds a window showing the level's colliders, the players' hitboxes and the replicated objects.
PowerShell
KroysDedicatedServer --bind 127.0.0.1 --port 7777 --content Content --scene Scenes/Main.kscene `
--script-assembly Content\Scripts\bin\Debug\net10.0\MyGame.dll --game-mode MyGame.ArenaMode `
--rule bots=2 --rule time_limit=300From the editor
Open the Network panel (Debug workspace). On the Server tab, Start Debug Server With Scene runs the debug server on the saved scene; on the Client tab, Connect Editor Client joins it from the editor. The panel keeps the script assembly, server script and game mode type per project. Cook Dedicated Server... writes a deployable server folder (Server cook).
Clients find and join servers
Servers answer broadcasts on the local network, so a game lists them with Network.SearchServers() and Network.GetServers() and joins with Network.Connect(address, name). A shipped game can also skip its menu:
Playing across the internet needs the game port forwarded to the host; broadcasts do not cross the internet, so those players type the address.
PowerShell
KroysPlayer --project MyGame.kproject --connect 192.168.1.20:7777 --name Ana
Server-side scripts
On the server, entities are the replicated network objects. Rendering, input, UI and audio calls return defaults there and each is reported once in the server log, so shared scripts keep running. Server scripts validate what clients ask for and change the authoritative state; clients learn the result from replication or messages.
CraftingServer.cs
[ServerOnly] public sealed class CraftingServer : EntityScript { protected override void OnNetworkMessage(NetworkMessage message) { if (message.Name != "Craft.Start" || message.Sender != Entity) return; NetworkReader reader = message.CreateReader(); string recipe = reader.ReadString(); Vector3 requestedAt = reader.ReadVector3(); // The server checks what the client claims against its own state. NetworkWriter reply = new(); reply.Write(recipe); if (Vector3.Distance(Transform.WorldPosition, requestedAt) > 4.0f) { reply.Write("Too far from the crafting station"); Network.SendToClient(message.SenderClientId, "Craft.Denied", reply, NetworkDelivery.Reliable); return; } reply.Write(2.5f); Network.SendToClient(message.SenderClientId, "Craft.Accepted", reply, NetworkDelivery.Reliable); } }
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.