forked from PGR/ascnet
graceful shutdown kill protocol + double session checking
This commit is contained in:
parent
726af535e1
commit
e850a18d54
|
@ -214,10 +214,10 @@ namespace AscNet.Common.MsgPack
|
|||
[MessagePackObject(true)]
|
||||
public partial class ItemList
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public long Count { get; set; }
|
||||
public long BuyTimes { get; set; }
|
||||
public long TotalBuyTimes { get; set; }
|
||||
public int BuyTimes { get; set; }
|
||||
public int TotalBuyTimes { get; set; }
|
||||
public long LastBuyTime { get; set; }
|
||||
public long RefreshTime { get; set; }
|
||||
public long CreateTime { get; set; }
|
||||
|
|
|
@ -1,12 +1,25 @@
|
|||
using AscNet.Common.Database;
|
||||
using AscNet.Common.MsgPack;
|
||||
using AscNet.Table.share.fuben;
|
||||
using AscNet.Table.share.guide;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace AscNet.GameServer.Handlers
|
||||
{
|
||||
#region MsgPackScheme
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
[MessagePackObject(true)]
|
||||
public class ForceLogoutNotify
|
||||
{
|
||||
public int Code;
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class ShutdownNotify
|
||||
{
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
#endregion
|
||||
|
||||
internal class AccountModule
|
||||
{
|
||||
[RequestPacketHandler("HandshakeRequest")]
|
||||
|
@ -40,6 +53,14 @@ namespace AscNet.GameServer.Handlers
|
|||
return;
|
||||
}
|
||||
|
||||
Session? previousSession = Server.Instance.Sessions.Select(x => x.Value).Where(x => x.GetHashCode() != session.GetHashCode()).FirstOrDefault(x => x.player.PlayerData.Id == player.PlayerData.Id);
|
||||
if (previousSession is not null)
|
||||
{
|
||||
// GateServerForceLogoutByAnotherLogin
|
||||
previousSession.SendPush(new ForceLogoutNotify() { Code = 1018 });
|
||||
previousSession.DisconnectProtocol();
|
||||
}
|
||||
|
||||
session.player = player;
|
||||
session.character = Character.FromUid(player.PlayerData.Id);
|
||||
session.stage = Stage.FromUid(player.PlayerData.Id);
|
||||
|
@ -110,6 +131,7 @@ namespace AscNet.GameServer.Handlers
|
|||
FubenMainLineData = new(),
|
||||
FubenChapterExtraLoginData = new(),
|
||||
FubenUrgentEventData = new(),
|
||||
// ItemList = ItemTableReader.Instance.All.Select(x => new ItemList() { Id = x.Id, Count = 6969696969 }).ToList(),
|
||||
UseBackgroundId = 14000001 // main ui theme, table still failed to dump
|
||||
};
|
||||
if (notifyLogin.PlayerData.DisplayCharIdList.Count < 1)
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace AscNet.GameServer
|
|||
|
||||
public Session? SessionFromUID(long uid)
|
||||
{
|
||||
return Sessions.FirstOrDefault(x => x.Value.player.PlayerData.Id == uid).Value;
|
||||
return Sessions.Select(x => x.Value).FirstOrDefault(x => x.player.PlayerData.Id == uid);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using AscNet.GameServer;
|
||||
using AscNet.GameServer.Handlers;
|
||||
using AscNet.GameServer.Commands;
|
||||
using AscNet.Logging;
|
||||
|
||||
|
@ -22,6 +23,17 @@ namespace AscNet
|
|||
|
||||
Task.Run(Server.Instance.Start);
|
||||
SDKServer.SDKServer.Main(args);
|
||||
|
||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler(KillProtocol);
|
||||
}
|
||||
|
||||
static void KillProtocol(object? sender, EventArgs e)
|
||||
{
|
||||
foreach (var session in Server.Instance.Sessions)
|
||||
{
|
||||
session.Value.SendPush(new ShutdownNotify());
|
||||
session.Value.DisconnectProtocol();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue