Skip to content

JustPyrrha/Py.LibNetwork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Static Badge Discord GitHub release (with filter) GitHub all releases

Py.LibNetwork

Channel based networking for Demeo mods.

Installation

Download the latest stable release's Py.LibNetwork-version.zip file and extract it into your Demeo game folder.

You should have a folder structure that looks like this:

Demeo (or Demeo - PC Edition)/
├─ DemeoMods/
│  ├─ Py.LibNetwork/
│  │  ├─ Py.LibNetwork.dll

Developer Guide

Setup

Add dependencies for ResolutionGames.Singleton.dll (which can be found in Demeo's demeo_Data/Managed folder) and Py.LibNetwork.dll

Usage

  1. Add an event handler.

    [!NOTE] Channel names can be anything, but it's recommended to include basic information such as mod name and a data version. Since theres no mod version enforcement, you may need to apply data migrations.
    See Py.LibNetwork/RemoteModListHandler.cs for a basic example.

    using Py.LibNetwork;
    const string ChannelName = "MyMod/MyChannel";
    
    ModNetwork.Instance.OnMessage += (channel, data, sender) =>
    {
        if(channel != ChannelName) return;
        using var dataStream = new MemoryStream(data);
        using (var reader = new BinaryReader(dataStream))
        {
            var str = reader.ReadString();
            DemeoLog.Log("MyMod", $"Player {sender.Value} says {str}!");
        }
    };
  2. Send a message to a specific player.

    using var output = new MemoryStream();
    using (var writer = new BinaryWriter(output))
    {
        writer.Write("Hello World");
    }
    // You can get playerData from vairous PlayerHub methods.
    ModNetwork.Instance.SendMessage(ChannelName, output.ToArray(), playerData.PlayerId);
  3. Broadcast a message

    using var output = new MemoryStream();
    using (var writer = new BinaryWriter(output))
    {
        writer.Write("Hello World");
    }
    ModNetwork.Instance.BroadcastMessage(ChannelName, output.ToArray());

Remote Mod Lists

As a basic example we provide RemoteModListHandler.cs but it can also be used to check which mods a remote player has installed.
RemoteModListHandler.RemoteModLists is a static Dictionary keyed by the player's PlayerId, it'll only contain a key for a player if we receive a mod list from them. It can contain an empty list if we receive a mod list with a newer protocol version than ours and we'll apply data migrations if it's an older known version.