📓

GameConnection

public enum ConnectionType
{
    unassigned, server, client, masterServer, masterServerClient
}; //add more if you need it

//this is the base class for CLIENT and HOST
//and carries any SHARED code those 2 bastards need
public class GameConnection
{

    public static string connection_key = "putYourGamesUniqueKeyHERE";

    public int port;
    public EventBasedNetListener listener;
    public NetManager netManager;
    public ConnectionType connectionType = ConnectionType.unassigned;
    public NetDataWriter netDataWriter;

    public float latency = 0; //in seconds (but likely 0.1 or something)
    public int latencyFrames = 0;

    public string currentGameScene = "";//use different approach if users can be in multiple scenes
//...

This is the base type for each type of connection the game supports(listed above in ConnectionType enum). Being the base class, it has attributes and methods useful to all types of connections.

To make sure other people using LiteNetLib are unable to join your games with their own programs, ensure to set connection_key to something fairly unique. This is used when making connections between your clients, servers and master servers and passed along to determine if they are allowed to connect.

Here is a quick run down of the other attributes of interest here:

Methods

public GameConnection()

Constructor which calls the Setup method (below)

public void Setup()

Sets up the listener, netManager and netDataWriter ready for first time use but does not kick off any connections yet

public virtual void Update()

Call this to poll the netManager for any incoming events e.g packets, connections, Nat Punch event etc

public void OpenPort(int port)

Let netManager know what port to start listening on

public void Stop()

Tell netManager to stop listening for events

public void SendChangeSceneMessage(NetPeer peer, string newScene)

Let a specific client know what scene to change to by sending them a message

public void SendChangeSceneMessageToAll(string newScene)

Let all clients know what scene to change to by sending them a message

public virtual void CleanUpBeforeSceneChange()

Nothing in here by default, but can be overridden in children classes to do any clean up necessary, e.g destroying objects, saving game etc