Coder Social home page Coder Social logo

archipelagomw / archipelago.multiclient.net Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 9.0 4.89 MB

A client library for use with .NET based prog-langs for interfacing with Archipelago hosts.

License: MIT License

C# 99.44% PowerShell 0.55% Batchfile 0.01%
archipelago client-library

archipelago.multiclient.net's Introduction

Archipelago.MultiClient.Net

A client library for use with .NET based applications for interfacing with Archipelago hosts. This client conforms with the latest stable Archipelago Network Protocol Specification.

Documentation

Create Session Instance

var session = ArchipelagoSessionFactory.CreateSession("localhost", 38281);

// alternatively...
var session = ArchipelagoSessionFactory.CreateSession(new Uri("ws://localhost:38281"));
var session = ArchipelagoSessionFactory.CreateSession("localhost:38281");
var session = ArchipelagoSessionFactory.CreateSession("localhost");

The freshly created ArchipelagoSession object is the entrypoint for all incoming and outgoing interactions with the server. Keep it in scope for at least the lifetime of the connection. If the room changes ports, or the user needs to connect to a different room, then a new session needs to be created at the new host and port.

Connect to Room

Connect to a server at a specific room slot using the following method:

LoginResult TryConnectAndLogin(
        string game, // Name of the game implemented by this client, SHOULD match what is used in the world implementation
        string name, // Name of the slot to connect as (a.k.a player name)
        ItemsHandlingFlags itemsHandlingFlags, /* One of the following (see AP docs for details):
                NoItems
                RemoteItems
                IncludeOwnItems
                IncludeStartingInventory
                AllItems
            */
        Version version = null, // Minimum Archipelago world specification version which this client can successfuly interface with
        string[] tags = null, /* One of the following (see AP docs for details)
                "DeathLink"
                "Tracker"
                "TextOnly"
            */
        string uuid = null, // Unique identifier for this player/client, if null randomly generated
        string password = null, // Password that was set when the room was created
	bool requestSlotData = true // If the LoginResult should contain the slot data
    );

For example,

LoginResult result = session.TryConnectAndLogin("Risk of Rain 2", "Ijwu", ItemsHandlingFlags.AllItems);

Would attempt to connect to a password-less room at the slot Ijwu, and report the game Risk of Rain 2 with a minimum apworld version of v2.1.0.

Once connected, you have access to a suite of helper objects which provide an interface for sending/receiving information with the server.

Example Connection

private static void Connect(string server, string user, string pass)
{
    LoginResult result;

    try
    {
        // handle TryConnectAndLogin attempt here and save the returned object to `result`
    }
    catch (Exception e)
    {
        result = new LoginFailure(e.GetBaseException().Message);
    }

    if (!result.Successful)
    {
        LoginFailure failure = (LoginFailure)result;
        string errorMessage = $"Failed to Connect to {server} as {user}:";
        foreach (string error in failure.Errors)
        {
            errorMessage += $"\n    {error}";
        }
        foreach (ConnectionRefusedError error in failure.ErrorCodes)
        {
            errorMessage += $"\n    {error}";
        }

        return; // Did not connect, show the user the contents of `errorMessage`
    }
    
    // Successfully connected, `ArchipelagoSession` (assume statically defined as `session` from now on) can now be used to interact with the server and the returned `LoginSuccessful` contains some useful information about the initial connection (e.g. a copy of the slot data as `loginSuccess.SlotData`)
    var loginSuccess = (LoginSuccessful)result;
}

If using .net 4.0 or higher, you can use ConnectAsync and LoginAsync to prevent hitching for injection-based implementations like harmony.

Helper Overview

session.Socket         // Payload-agnostic interface for sending/receving the most basic transmission units between client/server
session.Items          // Helpers for handling receipt of items
session.Locations      // Helpers for reporting visited locations to the servers
session.Players        // Helpers for translating player number, alias, name etc.
session.DataStorage    // Helpers for reading/writing globally accessible to any client connected in the room
session.ConnectionInfo // Helpers for reading/handling useful information on the current connection
session.RoomState      // Information on the state of the room
session.MessageLog     // Interface for the server to push info messages to the user

Players

The player helper provides methods for accessing details about the other players currently connected to the Archipelago session.

Get All Player Names

var sortedPlayerNames = session.Players.AllPlayers.Select(x => x.Name).OrderBy(x => x);

Get Current Player Name

string playerName = session.Players.GetPlayerAliasAndName(session.ConnectionInfo.Slot);

Locations

Report Collected Location(s)

Call the following method to inform the server of locations whose items have been "found", and therefore should be distributed (if neccessary):

// Report multiple at once
session.Locations.CompleteLocationChecks(new []{1,3,8});

// Or report one at a time
session.Locations.CompleteLocationChecks(3);

The location ID used is of that defined in the AP world.

Location ID <--> Name

string locationName = session.Locations.GetLocationNameFromId(42) ?? $"Location: {locationId}";
long locationId = session.Locations.GetLocationIdFromName(locationName);

Scout Location Checks

Scouting means asking the server what is stored in a specific location without collecting it:

session.Locations.ScoutLocationsAsync(locationInfoPacket => Console.WriteLine(locationInfoPacket.Locations.Count));

Items

Item ID --> Name

string itemName = session.Items.GetItemName(88) ?? $"Item: {itemId}";

Access Received Items

At any time, you can access the current inventory for the active session/slot via the Items helper like so:

foreach(NetworkItem item in session.Items.AllItemsReceived)
{
    long itemId = item.Item;
}

Note: The list of received items will never shrink and the collection is guaranteed to be in the order that the server sent the items. Because of this, it is safe to assume that if the size of this collection has changed it's because new items were received and appended to the end of the collection.

Received Item Callback Handler (Asynchronous)

// Must go AFTER a successful connection attempt
session.Items.ItemReceived += (receivedItemsHelper) => {
	var itemReceivedName = receivedItemsHelper.PeekItemName() ?? $"Item: {itemId}";

	// ... Handle item receipt here

	receivedItemsHelper.DequeueItem();
};

Note: This callback event will occur for every item on connection and reconnection. Whether or not it includes the first batch of remote items depends on your ItemHandlingFlags when connecting.

RoomState

The roomstate helper provides access to values that represent the current state of the multiworld room, with information such as the cost of a hint and or your current accumulated amount of hint point or the permissions for things like forfeiting

Console.WriteLine($"You have {session.RoomState.HintPoints}, and need {session.RoomState.HintCost} for a hint");

ConnectionInfo

The conection info helper provides access to values under which you are currently connected, such as your slot number or your currently used tags and item handling flags

Console.WriteLine($"You are connected on slot {session.ConnectionInfo.Slot}, on team {session.ConnectionInfo.Team}");

ArchipelagoSocket

The socket helper is a lower level API allowing for direct access to the socket which the session object uses to communicate with the Archipelago server. You may use this object to hook onto when messages are received or you may use it to send any packets defined in the library. Various events are exposed to allow for receipt of errors or notifying of socket close.

session.Socket.SendPacket(new SayPacket(){Text = "Woof woof!"});

DeathLink

DeathLink support is included in the library. You may enable it by using the CreateDeathLinkService in the DeathLinkProvider class, and the EnableDeathlink method on the service. Deathlink can be toggled on an off by the the EnableDeathlink and DisableDeathlink methods on the service

var session = ArchipelagoSessionFactory.CreateSession("localhost", 38281);

var deathLinkService = session.CreateDeathLinkService().EnableDeathlink();
session.TryConnectAndLogin("Risk of Rain 2", "Ijwu", ItemsHandlingFlags.AllItems);

deathLinkService.OnDeathLinkReceived += (deathLinkObject) => {
	// ... Kill your player(s).
};

// ... On death:
deathLinkService.SendDeathLink(new DeathLink("Ijwu", "Died to exposure."));

DataStorage

DataStorage support is included in the library. You may save values on the archipelago server in order to share them across other player's sessions or to simply keep track of values outside of your game's state.

The DataStorage provides an interface based on keys and their scope. By assigning a value to a key, that value is stored on the server and by reading from a key a value is retrieved from the server. Assigning and reading values from the store can be done using simple assignments =:

  • = session.DataStorage["Key"], read value from the data storage synchronously
  • session.DataStorage["Key"] =, write value to the data storage asynchronously
  • Complex objects need to be stored and retrieved in the form of a JObject, therefor you must wrap them into a JObject.FromObject()

The DataStorage also provides methods to retrieve the value of a key asynchronously using [key].GetAsync. To set the initial value of a key without overriding any existing value the [key].Initialize method can be used. If you're interested in keeping track of when a value of a certain key is changed by any client you can use the [key].OnValueChanged handler to register a callback for when the value gets updated.

Mathematical operations on values stored on the server are supported using the following operators:

  • +, Add right value to left value
  • -, Subtract right value from left value
  • *, Multiply left value by right value
  • /, Divide left value by right value
  • %, Gets remainder after dividing left value by right value
  • ^, Multiply left value by the power of the right value

Bitwise operations on values stored on the server are supported using the following opperations:

  • + Bitwise.Xor(x), apply logical exclusive OR to the left value using value x
  • + Bitwise.Or(x), apply logical OR to the left value using value x
  • + Bitwise.And(x), apply logical AND to the left value using value x
  • + Bitwise.LeftShift(x), binary shift the left value to the left by x
  • + Bitwise.RightShift(x), binary shift the left value to the right by x

Other operations on values stored on the server are supported using the following opperations:

  • + Operation.Min(x), get the lowest value of the left value and x
  • + Operation.Max(x), get the highest value of the left value and x
  • + Operation.Remove(x), when the left value is a list, removes the first element with value x
  • + Operation.Pop(x), when the left value is a list or dictionary, removes the element at index x or key x
  • + Operation.Update(x), when the left value is a list or dictionary, updates the dictionary with the keys/values in x

Operation specific callbacks are supported, these get called only once with the results of the current operation:

  • + Callback.Add((oldValue, newValue) => {});, calls this method after your operation or chain of operations are proccesed by the server

Mathematical operations, bitwise operations and callbacks can be chained, given the extended syntax with () around each operation.

Examples:

var session = ArchipelagoSessionFactory.CreateSession("localhost", 38281);
session.TryConnectAndLogin("Timespinner", "Jarno", ItemsHandlingFlags.AllItems);

//Initializing
session.DataStorage["B"].Initialize(20); //Set initial value for B in global scope if it has no value assigned yet

//Storing/Updating
session.DataStorage[Scope.Slot, "SetPersonal"] = 20; //Set `SetPersonal` to 20, in scope of the current connected user\slot
session.DataStorage[Scope.Global, "SetGlobal"] = 30; //Set `SetGlobal` to 30, in global scope shared among all players (the default scope is global)
session.DataStorage["Add"] += 50; //Add 50 to the current value of `Add`
session.DataStorage["Divide"] /= 2; //Divide current value of `Divide` in half
session.DataStorage["Max"] += + Operation.Max(80); //Set `Max` to 80 if the stored value is lower than 80
session.DataStorage["Dictionary"] = JObject.FromObject(new Dictionary<string, int>()); //Set `Dictionary` to a Dictionary
session.DataStorage["SetObject"] = JObject.FromObject(new SomeClassOrStruct()); //Set `SetObject` to a custom object
session.DataStorage["BitShiftLeft"] += Bitwise.LeftShift(1); //Bitshift current value of `BitShiftLeft` to left by 1
session.DataStorage["Xor"] += Bitwise.Xor(0xFF); //Modify `Xor` using the Bitwise exclusive or operation
session.DataStorage["DifferentKey"] = session.DataStorage["A"] - 30; //Get value of `A`, Assign it to `DifferentKey` and then subtract 30
session.DataStorage["Array"] = new []{ "One", "Two" }; //Arrays can be stored directly, List's needs to be converted ToArray() first 
session.DataStorage["Array"] += new []{ "Three" }; //Append array values to existing array on the server

//Chaining operations
session.DataStorage["Min"] = (session.DataStorage["Min"] + 40) + Operation.Min(100); //Add 40 to `Min`, then Set `Min` to 100 if `Min` is bigger than 100
session.DataStorage["C"] = ((session.DataStorage["C"] - 6) + Bitwise.RightShift(1)) ^ 3; //Subtract 6 from `C`, then multiply `C` by 2 using bitshifting, then take `C` to the power of 3

//Update callbacks
//EnergyLink deplete pattern, subtract 50, then set value to 0 if its lower than 0
session.DataStorage["EnergyLink"] = ((session.DataStorage["EnergyLink"] - 50) + Operation.Min(0)) + Callback.Add((oldData, newData) => {
    var actualDepleted = (float)newData - (float)oldData; //calculate the actual change, might differ if there was less than 50 left on the server
});

//Keeping track of changes
session.DataStorage["OnChangeHandler"].OnValueChanged += (oldData, newData) => {
	var changed = (int)newData - (int)oldData; //Keep track of changes made to `OnChangeHandler` by any client, and calculate the difference
};

//Keeping track of change (but for more complex data structures)
session.DataStorage["OnChangeHandler"].OnValueChanged += (oldData, newData) => {
    var old_dict = oldData.ToObject<Dictionary<int, int>>();
    var new_dict = newData.ToObject<Dictionary<int, int>>();
};

//Retrieving
session.DataStorage["Async"].GetAsync<string>(s => { string r = s }); //Retrieve value of `Async` asynchronously
float f = session.DataStorage["Float"]; //Retrieve value for `Float` synchronously and store it as a float
var d = session.DataStorage["DateTime"].To<DateTime>() //Retrieve value for `DateTime` as a DateTime struct
var array = session.DataStorage["Strings"].To<string[]>() //Retrieve value for `Strings` as string Array

//Handling anonymous object, if the target type is not known you can use `To<JObject>()` and use its interface to access the members
session.DataStorage["Anonymous"] = JObject.FromObject(new { Number = 10, Text = "Hello" }); //Set `Anonymous` to an anonymous object
var obj = session.DataStorage["Anonymous"].To<JObject>(); //Retrieve value for `Anonymous` where an anonymous object was stored
var number = (int)obj["Number"]; //Get value for anonymous object key `Number`
var text = (string)obj["Text"]; //Get value for anonymous object key `Text`

Message Logging

The Archipelago server can send messages to client to be displayed on screen as sort of a log, this is done by handling the PrintJsonPacket packets. This library simplifies this process into a single handler for you to handle.

var session = ArchipelagoSessionFactory.CreateSession("localhost", 38281);
session.MessageLog.OnMessageReceived += OnMessageReceived;
session.TryConnectAndLogin("Timespinner", "Jarno", ItemsHandlingFlags.AllItems, new Version(0,3,5));

static void OnMessageReceived(LogMessage message)
{
	DisplayOnScreen(message.ToString());
}

In some cased you might want extra information that is provided by the server in such cases you can use type checking

static void OnMessageReceived(LogMessage message)
{
	switch (message)
	{
		case ItemHintLogMessage hintLogMessage:
			var receiver = itemSendLogMessage.Receiver;
			var sender = itemSendLogMessage.Sender;
			var networkItem = itemSendLogMessage.Item;
			var found = hintLogMessage.IsFound;
			break;
		case ItemSendLogMessage itemSendLogMessage: 
			var receiver = itemSendLogMessage.Receiver;
			var sender = itemSendLogMessage.Sender;
			var networkItem = itemSendLogMessage.Item;
			break;
	}
	DisplayOnScreen(message.ToString());
}

If you want more control over how the message is displayed, like for example you might want to color certain parts of the message, Then you can use the Parts property. This returns each part of the message in order of appearnce with the Text to be displayed and also the Color it would normally be diplayed in. If IsBackgroundColor is true, then the color should be applied to the message background instead. The MessagePart message can also contain additional information that can be retrieved by type checking.

foreach (part in message.Parts)
{
	switch (part)
	{
		case ItemMessagePart itemMessagePart: 
			var itemId = itemMessagePart.ItemId;
			var flags = itemMessagePart.Flags;
			break;
		case LocationMessagePart locationMessagePart:
			var locationId = locationMessagePart.LocationId;
			break;
		case PlayerMessagePart playerMessagePart:
			var slotId = playerMessagePart.SlotId;
			var isCurrentPlayer = playerMessagePart.IsActivePlayer;
			break;
	}

	DisplayOnScreen(part.Text, part.Color, part.IsBackgroundColor);
}

Send Completion

You can report the completion of the player's goal like so:

public static void send_completion()
{
    var statusUpdatePacket = new StatusUpdatePacket();
    statusUpdatePacket.Status = ArchipelagoClientState.ClientGoal;
    Session.Socket.SendPacket(statusUpdatePacket);
}

archipelago.multiclient.net's People

Contributors

alwaysintreble avatar berserker66 avatar caitsith2 avatar dariof4 avatar ijwu avatar jarno458 avatar sunnybat avatar thephar avatar toasterparty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

archipelago.multiclient.net's Issues

Expose GetDataPackage

As far as I can tell, the GetDataPackage API and the data it returns isn't exposed publicly anywhere in the high-level API, and as a consequence there's no way to get an item or location's name unless it's exactly the item you most recently received. It would be useful to have access to this information one way or another.

Version type deserialization broken in .NET Core 3.1

.NET Core 3.1 introduced a default type converter for the Version type. Serialization still works due to the NamedTupleInterchangeConverter mimicking the previous conversion semantics for serialization. However, there is no deserializer in .NET Core 3.1 which can deserialize a Version object which was serialized with the library. (So the lib can't talk to itself, how funny is that?)

Suggestion: we implement a custom Version class, finally, which meets the spec for AP and use that. Version object seems to have served its purpose and I'm only suggesting we replace it as a result of this issue.

AllLocationsChecked on LocationCheckHelper does not respect server's location_checked

AllLocationsChecked on LocationCheckHelper is only filled with the locations the game reports as checked by calling CompleteLocationChecks or CompleteLocationChecksAsync, however the initial value of locations_checked that is send on the connect package is not taken into account, neither are the updated values of locations_checked as part of RoomUpdated packages. As a result of this, !collect or coop is not properly taken into account

Archipelago.MultiClient.Net for .Net Framework 3.5 or Net Framework 4.0 does not support wss to AP

The versions for .Net Framework 3.5 or Net Framework 4.0 use https://github.com/sta/websocket-sharp
Websocket Sharp
this library is sort of the only option that is available for websockets that also work for unity games
Its widely used in various projects but also not really maintained and WSS support is currently broken

This might also be caused by supported TLS versions, especially for lower .net framework versions TLS support is limited
https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls

GetDataPackage should use new Inclusions rather than outdated exclusions

Currently the Archipelago.MultiClient.Net still uses the old outdated GetDataPackage api, where you specificy which games to exclude from retrieval, this should be change to use the new api where you specify games to query

Optionally, there was a report on discord where a user ended up with a datapackage cache of 0 bytes and this resulted in a crash. we could add additional checks to prevent such crashes and invalidate the cache in such cases

Optionally 2, With an ever growing list of games, it begins to make sense to only load the cache of the games that are actually being played on the server. we instead of the datapackagecache.archipelagocache use a folder, with one file for each game in it with the version number in the filename, so we can avoid loading it into memory when the version does not match as we know we got to update it and at the same time we could selectively only load the games we need to server the current multiworld

Location name encoding can get corrupted

When calling session.Locations.GetLocationNameFromId() for a location whose name is "CD: Siegbräu", I received instead "CD: Siegbr��u". I think maybe some part of the network/JSON infrastructure is losing the encoding information?

Documentation

The example code presented in README.MD leaves first time users with some questions:

  • What does CompleteLocationChecks do? It might seem obvious, but I had to do a double take and look at an example client to know for sure.
  • What's the difference between CompleteLocationChecks and ScoutLocationsAsync?
  • The Item Helper example shows receivedItemsHelper.DequeueItem(), but does not hint to the reader as to what information within the dequeued object might be useful. What is a client responsible for doing with this info?
  • Will the received items helper callback be invoked after a fresh connection for the first batch of remote items?

A minimalistic example class with connection error handling, basic message handler, basic item received callback, and a "report location completion" function would go a long way to helping new devs.

.NET 3.5 OnMessageReceived Errors

  1. The .NET 3.5 distribution of MultiClient.Net does not report System.Drawing.dll as a dependency, causing this runtime error:
[Info   :   Console] 9/1/2022 9:33:06 AM|Error|WebSocket.messagec:0|System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
                          File name: 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
                            at Archipelago.MultiClient.Net.Helpers.MessageLogHelper.Socket_PacketReceived (Archipelago.MultiClient.Net.ArchipelagoPacketBase packet) [0x00000] in <filename unknown>:0
                            at (wrapper delegate-invoke) Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelperDelagates/PacketReceivedHandler:invoke_void__this___ArchipelagoPacketBase (Archipelago.MultiClient.Net.ArchipelagoPacketBase)
                            at (wrapper delegate-invoke) Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelperDelagates/PacketReceivedHandler:invoke_void__this___ArchipelagoPacketBase (Archipelago.MultiClient.Net.ArchipelagoPacketBase)
                            at Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelper.OnMessageReceived (System.Object sender, WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0
                            at WebSocketSharp.Ext.Emit[MessageEventArgs] (System.EventHandler`1 eventHandler, System.Object sender, WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0
                            at WebSocketSharp.WebSocket.messagec (WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0
  1. This error:
[Info   :   Console] 9/1/2022 10:24:41 AM|Error|WebSocket.messagec:0|System.InvalidProgramException: Invalid IL code in System.Drawing.Color:get_White (): method body is empty.

                             at Archipelago.MultiClient.Net.Helpers.MessagePart..ctor (MessagePartType type, Archipelago.MultiClient.Net.Models.JsonMessagePart messagePart, Nullable`1 color) [0x00000] in <filename unknown>:0
                             at Archipelago.MultiClient.Net.Helpers.MessageLogHelper.GetMessagePart (Archipelago.MultiClient.Net.Models.JsonMessagePart part) [0x00000] in <filename unknown>:0
                             at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[Archipelago.MultiClient.Net.Models.JsonMessagePart,Archipelago.MultiClient.Net.Helpers.MessagePart].MoveNext () [0x00000] in <filename unknown>:0
                             at System.Collections.Generic.List`1[Archipelago.MultiClient.Net.Helpers.MessagePart].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
                             at System.Collections.Generic.List`1[Archipelago.MultiClient.Net.Helpers.MessagePart]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
                             at System.Linq.Enumerable.ToArray[MessagePart] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
                             at Archipelago.MultiClient.Net.Helpers.MessageLogHelper.GetParsedData (Archipelago.MultiClient.Net.Packets.PrintJsonPacket packet) [0x00000] in <filename unknown>:0
                             at Archipelago.MultiClient.Net.Helpers.MessageLogHelper.TriggerOnMessageReceived (Archipelago.MultiClient.Net.Packets.PrintJsonPacket printJsonPacket) [0x00000] in <filename unknown>:0
                             at Archipelago.MultiClient.Net.Helpers.MessageLogHelper.Socket_PacketReceived (Archipelago.MultiClient.Net.ArchipelagoPacketBase packet) [0x00000] in <filename unknown>:0
                             at (wrapper delegate-invoke) Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelperDelagates/PacketReceivedHandler:invoke_void__this___ArchipelagoPacketBase (Archipelago.MultiClient.Net.ArchipelagoPacketBase)
                             at (wrapper delegate-invoke) Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelperDelagates/PacketReceivedHandler:invoke_void__this___ArchipelagoPacketBase (Archipelago.MultiClient.Net.ArchipelagoPacketBase)
                             at Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelper.OnMessageReceived (System.Object sender, WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0
                             at WebSocketSharp.Ext.Emit[MessageEventArgs] (System.EventHandler`1 eventHandler, System.Object sender, WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0
                             at WebSocketSharp.WebSocket.messagec (WebSocketSharp.MessageEventArgs e) [0x00000] in <filename unknown>:0

Log WebSocketSharp errors to somewhere... else...

I believe we can set up custom loggers in WebSocketSharp's WebSocket object. We should have it log somewhere other than stderr or wherever it currently goes since in Unity games that almost always ends up in the Unity player logs which is disparate from where other errors typically go (such as stdout, modloader logs, etc.).

We can possibly provide options to allow callers to provide their own loggers and then provide another NuGet package with logger implementations for things like BepInEx or Hollow Knight's ModdingApi, as examples.

Exception during TryConnectAndLogin may be wrong.

Should an exception be raised during the method TryConnectAndLogin, such as if the Connected package coming from the server fails to parse (be it due to intentional destruction or #95), then the Exception that bubbles up out of the library is just a Timeout exception, which is confusing and wrong.

Synchronous data retrievals from the DataStorage inside the websocket thread causes softlock

Using the data storage for Synchronous retrieval in code that runs on websocket thread will cause the thread to wait for a Retrieved packet, but that can never be processes as the thread itself is waiting

you can reproduce this with int x = session.DataStorage["A"] inside a session.Socket.PackedReceived() handler or other code that runs on the websocket thrread like session.Locations.CheckedLocationsUpdated() handler

A workaround is to use asynchronous retreivals in such case like session.DataStorage["A"].GetAsync(x => { })

I propose to add a max timeout to the synchronous retrieval and log and throw an error if this time is exceeded

Datapackage is retreived to late

since the websockets packets are garenteed to preserver order it is highly recommended to requests updates for the data package before sending the connect request, this will ensure that the datapackage response is received before the connection result, and therefor if the connection is sucsesfull the datapackage will be processed before any received item packages

Bug: Session.Items.AllItemsReceived occasionally appears to append a null item

Occasionally AllItemsReceived has a null item appended to it, preventing clients that attempt to update their received items by reading this collection from getting the actual item, while they update their internal index. Unknown what exactly causes the issue, only know that manually tracking received items in the game client and occasionally verifying it against the lib collection would trigger them to be mismatched, despite the index being the same.

Duplicates of the exact same item causes ItemHelper desyncs

I think I've tracked this down to a library issue.

When receiving exact copies of the same item from the exact same location, the produced NetItems compare identical. This causes ReceivedItemHelper:Socket_PacketReceived to skip the duplicate items -- preventing it from being added to the itemQueue, among other things.

The first time this happens, the client is never notified of the new item. The second time it happens, a resync triggers (since Multiclient realizes it only has N items in its list when it should have N+1) and from the caller'sperspective it receives two new items: the first two items ever sent. This behavior is witnessed with ArchipelagoMW-HollowKnight/Archipelago.HollowKnight#79.

This currently can only happen with /send, !getitem, and startinventory -- all of which can have multiple instances of the same item ID, sender, recipient, and location.

Flaky Unitests

The unit tests for the Data Storage are flaky as they regulairly hit the key retreival timeout
such error look like this:
Timed out retrieving data for key "Item". This may be due to an attempt to retrieve a value from the DataStorageHelper in a synchronous fashion from within a PacketReceived handler. When using the DataStorageHelper from within code which runs on the websocket thread then use the asynchronous getters. Ex: "DataStorageHelper["Item"].GetAsync().ContinueWith(x => {});" Be aware that DataStorageHelper calls tend to cause packet responses, so making a call from within a PacketReceived handler may cause an infinite loop.
Workaround: Generally re-run failed jobs on the PR will fix this issue

Exception when retrievieng location name from id

Exception when trying to retrieve item name through session.Locations.GetLocationNameFromId(locationName);
Iterating through location ID's does not result in an error. Checked the spoiler log and there were no locations with the same id.

Exception in IL2CPP-to-Managed trampoline, not passing it to il2cpp: System.ArgumentException: An item with the same key has already been added. Key: 257
  at System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000dd] in <986ed57b9a8f4699a3c59a69eb05944a>:0 
  at System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <986ed57b9a8f4699a3c59a69eb05944a>:0 
  at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] keySelector, System.Func2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer1[T] comparer) [0x0009e] in <c8122f496f05432baca55ffb7d139a58>:0 
  at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] keySelector, System.Func2[T,TResult] elementSelector) [0x00000] in <c8122f496f05432baca55ffb7d139a58>:0 
  at Archipelago.MultiClient.Net.Helpers.LocationCheckHelper.GetLocationNameFromId (System.Int32 locationId) [0x0006b] in <17d96186d9fe43bbb3a20afc3fa3c45d>:0 
  at TunicRandomizer.TunicArchipelagoClient.TunicArchipelagoClient.Connect (System.String host, System.Int32 port, System.String player, System.String password) [0x0013b] in <69b91c7de2bc4ae291624c6da21b8154>:0 
  at TunicRandomizer.Patches.MenuPatches+<>c.<pushDefault_OptionsPatch>b__11_1 () [0x00042] in <69b91c7de2bc4ae291624c6da21b8154>:0 
  at (wrapper dynamic-method) UnhollowerRuntimeLib.DelegateSupport.(il2cpp delegate trampoline) System.Void(intptr,UnhollowerBaseLib.Runtime.Il2CppMethodInfo*)

Support full URL format as overload for creating sessions.

Should support taking in one URL string to attempt to parse.

Format is: [scheme][<user>[:<password>]@]<address>:<port>

If scheme is not provided or is not ws:// then it should be replaced with ws://. If user (and subsequently, optionally, password) is provided then perhaps we can cache that and allow for a streamlined connection process?

Invalid type error when creating session

I recently started working on Inscryption which uses .NET Standard 2.0 and I get this error when calling ArchipelagoSessionFactory.CreateSession:

Invalid type Archipelago.MultiClient.Net.Converters.ArchipelagoPacketConverter for instance field Archipelago.MultiClient.Net.Helpers.ArchipelagoSocketHelper:Converter
  at Archipelago.MultiClient.Net.ArchipelagoSessionFactory.CreateSession (System.String hostname, System.Int32 port) [0x00007] in <608ab731db5a4a4fabc8e725e7273242>:0
  at Archipelago_Inscryption.Archipelago.ArchipelagoClient.CreateSession () [0x00001] in <f39eb8b90aa64a5e967d32da2dda428e>:0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.