Skip to content

Commit 3de3338

Browse files
committed
Add auth fallback for use in offline servers
1 parent 99f1662 commit 3de3338

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using HarmonyLib;
7+
8+
namespace MultiplayerCore.Patches
9+
{
10+
[HarmonyPatch]
11+
internal class PlatformAuthenticationTokenProviderPatch
12+
{
13+
public static readonly string DummyAuth = "77686f5f69735f72656d5f3f";
14+
15+
[HarmonyPostfix]
16+
[HarmonyPatch(typeof(PlatformAuthenticationTokenProvider), nameof(PlatformAuthenticationTokenProvider.GetAuthenticationToken))]
17+
private static void GetAuthenticationToken(PlatformAuthenticationTokenProvider __instance, ref Task<AuthenticationToken> __result)
18+
{
19+
__result = __result.ContinueWith<AuthenticationToken>(task =>
20+
{
21+
AuthenticationToken result;
22+
if (task.IsFaulted || string.IsNullOrWhiteSpace((result = task.Result).sessionToken))
23+
{
24+
Plugin.Logger.Error("An error occurred while attempting to get the auth token: " + task.Exception);
25+
Plugin.Logger.Warn("Failed to get auth token, returning custom authentication token!");
26+
return new AuthenticationToken(__instance.platform, __instance.hashedUserId, __instance.userName, DummyAuth);
27+
}
28+
Plugin.Logger.Debug("Successfully got auth token!");
29+
return result;
30+
});
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)