diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-25 13:11:17 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-25 13:11:17 -0400 |
commit | 189fcfc1087764961e61c470ffea642ff46d164d (patch) | |
tree | 77890701aeb8e8e89b1dffb7084559dc6c8e7364 /AnodyneArchipelago/ArchipelagoManager.cs | |
parent | ca34b22c8dbeecda5ac5f66ca24fbe69a617b4dd (diff) | |
download | anodyne-archipelago-189fcfc1087764961e61c470ffea642ff46d164d.tar.gz anodyne-archipelago-189fcfc1087764961e61c470ffea642ff46d164d.tar.bz2 anodyne-archipelago-189fcfc1087764961e61c470ffea642ff46d164d.zip |
You can connect now!
Diffstat (limited to 'AnodyneArchipelago/ArchipelagoManager.cs')
-rw-r--r-- | AnodyneArchipelago/ArchipelagoManager.cs | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs index 0b7c478..7c67114 100644 --- a/AnodyneArchipelago/ArchipelagoManager.cs +++ b/AnodyneArchipelago/ArchipelagoManager.cs | |||
@@ -11,53 +11,48 @@ using Archipelago.MultiClient.Net.Packets; | |||
11 | using System; | 11 | using System; |
12 | using System.Collections.Generic; | 12 | using System.Collections.Generic; |
13 | using System.Linq; | 13 | using System.Linq; |
14 | using System.Threading.Tasks; | ||
14 | 15 | ||
15 | namespace AnodyneArchipelago | 16 | namespace AnodyneArchipelago |
16 | { | 17 | { |
17 | internal class ArchipelagoManager | 18 | public class ArchipelagoManager |
18 | { | 19 | { |
19 | private static ArchipelagoSession _session; | 20 | private ArchipelagoSession _session; |
20 | private static int _itemIndex = 0; | 21 | private int _itemIndex = 0; |
22 | private string _seedName; | ||
21 | 23 | ||
22 | private static readonly Queue<NetworkItem> _itemsToCollect = new(); | 24 | private readonly Queue<NetworkItem> _itemsToCollect = new(); |
23 | 25 | ||
24 | public static void Connect(string url, string slotName, string password) | 26 | public async Task<LoginResult> Connect(string url, string slotName, string password) |
25 | { | 27 | { |
26 | LoginResult result; | 28 | LoginResult result; |
27 | try | 29 | try |
28 | { | 30 | { |
29 | _session = ArchipelagoSessionFactory.CreateSession(url); | 31 | _session = ArchipelagoSessionFactory.CreateSession(url); |
30 | _session.MessageLog.OnMessageReceived += OnMessageReceived; | 32 | _session.MessageLog.OnMessageReceived += OnMessageReceived; |
31 | result = _session.TryConnectAndLogin("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); | 33 | |
34 | RoomInfoPacket roomInfoPacket = await _session.ConnectAsync(); | ||
35 | _seedName = roomInfoPacket.SeedName; | ||
36 | |||
37 | result = await _session.LoginAsync("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); | ||
32 | } | 38 | } |
33 | catch (Exception e) | 39 | catch (Exception e) |
34 | { | 40 | { |
35 | result = new LoginFailure(e.GetBaseException().Message); | 41 | result = new LoginFailure(e.GetBaseException().Message); |
36 | } | 42 | } |
37 | 43 | ||
38 | if (!result.Successful) | ||
39 | { | ||
40 | LoginFailure failure = result as LoginFailure; | ||
41 | string errorMessage = $"Failed to connect to {url} as {slotName}:"; | ||
42 | foreach (string error in failure.Errors) | ||
43 | { | ||
44 | errorMessage += $"\n {error}"; | ||
45 | } | ||
46 | foreach (ConnectionRefusedError error in failure.ErrorCodes) | ||
47 | { | ||
48 | errorMessage += $"\n {error}"; | ||
49 | } | ||
50 | |||
51 | Plugin.Instance.Log.LogError(errorMessage); | ||
52 | |||
53 | return; | ||
54 | } | ||
55 | |||
56 | _itemIndex = 0; | 44 | _itemIndex = 0; |
57 | _itemsToCollect.Clear(); | 45 | _itemsToCollect.Clear(); |
46 | |||
47 | return result; | ||
48 | } | ||
49 | |||
50 | ~ArchipelagoManager() | ||
51 | { | ||
52 | Disconnect(); | ||
58 | } | 53 | } |
59 | 54 | ||
60 | public static void Disconnect() | 55 | public void Disconnect() |
61 | { | 56 | { |
62 | if (_session == null) | 57 | if (_session == null) |
63 | { | 58 | { |
@@ -68,7 +63,17 @@ namespace AnodyneArchipelago | |||
68 | _session = null; | 63 | _session = null; |
69 | } | 64 | } |
70 | 65 | ||
71 | public static void SendLocation(string location) | 66 | public string GetSeed() |
67 | { | ||
68 | return _seedName; | ||
69 | } | ||
70 | |||
71 | public int GetPlayer() | ||
72 | { | ||
73 | return _session.ConnectionInfo.Slot; | ||
74 | } | ||
75 | |||
76 | public void SendLocation(string location) | ||
72 | { | 77 | { |
73 | if (_session == null) | 78 | if (_session == null) |
74 | { | 79 | { |
@@ -79,7 +84,7 @@ namespace AnodyneArchipelago | |||
79 | _session.Locations.CompleteLocationChecks(_session.Locations.GetLocationIdFromName("Anodyne", location)); | 84 | _session.Locations.CompleteLocationChecks(_session.Locations.GetLocationIdFromName("Anodyne", location)); |
80 | } | 85 | } |
81 | 86 | ||
82 | public static void Update() | 87 | public void Update() |
83 | { | 88 | { |
84 | if (_session == null) | 89 | if (_session == null) |
85 | { | 90 | { |
@@ -104,7 +109,7 @@ namespace AnodyneArchipelago | |||
104 | } | 109 | } |
105 | } | 110 | } |
106 | 111 | ||
107 | if (_itemsToCollect.Count > 0 && (GlobalState.Dialogue == null || GlobalState.Dialogue == "") && !GlobalState.ScreenTransition) | 112 | if (_itemsToCollect.Count > 0 && (GlobalState.Dialogue == null || GlobalState.Dialogue == "") && !GlobalState.ScreenTransition && Plugin.Player != null && GlobalState.black_overlay.alpha == 0f) |
108 | { | 113 | { |
109 | NetworkItem item = _itemsToCollect.Dequeue(); | 114 | NetworkItem item = _itemsToCollect.Dequeue(); |
110 | HandleItem(item); | 115 | HandleItem(item); |
@@ -125,7 +130,7 @@ namespace AnodyneArchipelago | |||
125 | } | 130 | } |
126 | } | 131 | } |
127 | 132 | ||
128 | private static void HandleItem(NetworkItem item) | 133 | private void HandleItem(NetworkItem item) |
129 | { | 134 | { |
130 | if (item.Player == _session.ConnectionInfo.Slot) | 135 | if (item.Player == _session.ConnectionInfo.Slot) |
131 | { | 136 | { |
@@ -223,7 +228,7 @@ namespace AnodyneArchipelago | |||
223 | GlobalState.Dialogue = message; | 228 | GlobalState.Dialogue = message; |
224 | } | 229 | } |
225 | 230 | ||
226 | private static void OnMessageReceived(LogMessage message) | 231 | private void OnMessageReceived(LogMessage message) |
227 | { | 232 | { |
228 | switch (message) | 233 | switch (message) |
229 | { | 234 | { |