Skip to content

Commit

Permalink
Fix for .net client failing to connect in AP 0.4
Browse files Browse the repository at this point in the history
Proposed changes to AP: ArchipelagoMW/Archipelago#757
  • Loading branch information
Jarno458 committed Jul 8, 2022
1 parent 5edd48d commit 866ad42
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Archipelago.MultiClient.Net/Helpers/PlayerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Archipelago.MultiClient.Net.Models;
using Archipelago.MultiClient.Net.Enums;
using Archipelago.MultiClient.Net.Models;
using Archipelago.MultiClient.Net.Packets;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

Expand Down Expand Up @@ -87,20 +89,13 @@ private void PacketReceived(ArchipelagoPacketBase packet)
case RoomUpdatePacket roomUpdatePacket:
OnRoomUpdatedPacketReceived(roomUpdatePacket);
break;
case RoomInfoPacket roomInfoPacket:
OnRoomInfoPacketReceived(roomInfoPacket);
break;
}
}

private void OnRoomInfoPacketReceived(RoomInfoPacket packet)
{
UpdateGames(packet.Games);
}

private void OnConnectedPacketReceived(ConnectedPacket packet)
{
UpdatePlayerInfo(packet.Players);
AddSlotInformation(packet.Team, packet.SlotInfo);
}

private void OnRoomUpdatedPacketReceived(RoomUpdatePacket packet)
Expand All @@ -111,18 +106,25 @@ private void OnRoomUpdatedPacketReceived(RoomUpdatePacket packet)
}
}

private void UpdateGames(string[] games)
private void AddSlotInformation(int team, Dictionary<int, NetworkSlot> slotInfos)
{
if (players == null)
{
players = games.Select(g => new PlayerInfo { Game = g }).ToArray();
return;
}
else

foreach (var player in players)
{
for (int i = 0; i < games.Length; i++)
if (player.Team != team)
{
players[i].Game = games[i];
continue;
}

var slotInfoForPlayer = slotInfos[player.Slot];

player.Game = slotInfoForPlayer.Game;
player.SlotType = slotInfoForPlayer.Type;
player.SlotName = slotInfoForPlayer.Name;
}
}

Expand Down Expand Up @@ -157,5 +159,7 @@ public class PlayerInfo
public string Alias { get; internal set; }
public string Name { get; internal set; }
public string Game { get; internal set; }
public string SlotName { get; internal set; }
public SlotType SlotType { get; internal set; }
}
}

0 comments on commit 866ad42

Please sign in to comment.