Eintoo/GameServer/Server/Hotfix/Outter/Gate/JWT/Helper/GateJwtComponentHelper.cs
2025-04-22 15:31:25 +08:00

37 lines
941 B
C#

using System.IdentityModel.Tokens.Jwt;
using Fantasy;
namespace Hotfix;
public static class GateJwtComponentHelper
{
private static bool ValidateToken(Scene scene, string token,out JwtPayload payload)
{
return scene.GetComponent<GateJWTComponent>().ValidateToken(token, out payload);
}
public static bool ValidateToken(Scene scene, string token, out long accountId)
{
accountId = 0;
if (!ValidateToken(scene, token, out JwtPayload payload))
{
return false;
}
try
{
var sceneConfigId = Convert.ToInt64(payload["sceneId"]);
accountId = Convert.ToInt64(payload["aid"]);
if (sceneConfigId == scene.SceneConfigId)
{
return false;
}
return true;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}