Client-Server communications
This page describes how to handle various things related to client-server communications. This includes sending messages, implementing prediction, etc.
Core Keeper is a server authoritative game. This means for an action to occur, the server must be aware of it and approve. When we write mods we must be able to create logic that allows for Client-Server communication to occur.
Ghost Components
Ghost component is one of the simplest ways to transfer data between Client and server. In its essence Ghost Component is just a normal ECS component that is synced over network.
To make a Ghost Component first Create IComponentData deriving ECS component:
public struct ExampleCD : IComponentData
{
public int importantField;
public float normalField;
}To make this component a Ghost Component all you have to do is add a GhostComponent attribute to it. Additionally you must mark every field you want to be synced with GhostField attribute:
[GhostComponent]
public struct ExampleCD : IComponentData
{
// This field will end up synced
[GhostField]
public int importantField;
// This field isn't marked, so it won't be synced
public float normalField;
}Making Ghost Components is just as easy as this. Now any data set to this component of the server will be automatically replicated to all clients. Refer to this guide to learn more
Remote Procedure Calls
Remote Procedure Calls (or RPC's) are a way to send information to the Server or clients in one-shot manner. They allow you to send arbitrary data or commands to the other side, be it requests or data
This example will focus on Client to Server communication, as that is the most common scenario, however you can send RPC from Server to Clients or even both ways
To make a RPC first add RPC command data definition:
Now define two systems. One for Clients:
And one for Server:
Now to use these systems you just have to add this code in your IMod class:
Now you can use MyMod.clientSystem.DoVeryImportantThing() from anywhere in your code
Prediction
This guide has not been written yet! If you know how to do this, add it!
Last updated
Was this helpful?