Skip to content

Commit

Permalink
Better login error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterparty committed Dec 20, 2023
1 parent dfda619 commit 3fc4c68
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
65 changes: 46 additions & 19 deletions OC2Modding/ArchipelagoClient/ArchipelagoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ private static LoginResult ConnectionAttempt(string server, string user, string
}

cachedConnectionResult = null;

if (!OC2Helpers.HasLeaderboardScores())
{
OC2Helpers.BuildLeaderboardScores(false);
Expand All @@ -430,6 +431,8 @@ private static LoginResult ConnectionAttempt(string server, string user, string
// Derrive the full uri, accounting for every possible variation of user stupidity
serverUrl = server.ToLower();

var wsFirst = serverUrl.StartsWith("ws://");

// remove the protocol
if (serverUrl.Contains("://"))
{
Expand All @@ -452,27 +455,51 @@ private static LoginResult ConnectionAttempt(string server, string user, string
password = pass;

LoginResult result = null;
foreach(string prefix in new string[] {"wss://", "ws://"})

string[] prefixes;
if (wsFirst)
{
prefixes = new string[] {"ws://", "wss://", ""};
}
else
{
prefixes = new string[] {"wss://", "ws://", ""};
}

foreach(string prefix in prefixes)
{
var url = prefix + serverUrl;
var uri = new Uri(url);
session = ArchipelagoSessionFactory.CreateSession(uri);

OC2Modding.Log.LogInfo($"Connecting to {url}");

result = session.TryConnectAndLogin(
"Overcooked! 2",
userName,
REMOTE_INVENTORY ? ItemsHandlingFlags.AllItems : ItemsHandlingFlags.RemoteItems,
MinimumProtocolVersion,
tags: new string[0],
uuid: null,
password: password
);

if (result is LoginSuccessful)
try
{
break;
var url = prefix + serverUrl;
var uri = new Uri(url);
session = ArchipelagoSessionFactory.CreateSession(uri);

OC2Modding.Log.LogInfo($"Connecting to {url}");

var tempResult = session.TryConnectAndLogin(
"Overcooked! 2",
userName,
REMOTE_INVENTORY ? ItemsHandlingFlags.AllItems : ItemsHandlingFlags.RemoteItems,
MinimumProtocolVersion,
tags: new string[0],
uuid: null,
password: password
);

if (tempResult is LoginSuccessful)
{
result = tempResult;
break;
}
}
catch (Exception e)
{
OC2Modding.Log.LogWarning($"{e.Message}");

if (result == null)
{
result = new LoginFailure(e.GetBaseException().Message);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion OC2Modding/OC2Modding.csproj.epic
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net46</TargetFramework>
<AssemblyName>com.github.toasterparty.oc2modding.epic</AssemblyName>
<Description>Overcooked! 2 Modding</Description>
<Version>1.9.2</Version>
<Version>1.9.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion OC2Modding/OC2Modding.csproj.steam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net35</TargetFramework>
<AssemblyName>com.github.toasterparty.oc2modding.steam</AssemblyName>
<Description>Overcooked! 2 Modding</Description>
<Version>1.9.2</Version>
<Version>1.9.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 3fc4c68

Please sign in to comment.