ascnet/AscNet.GameServer/Handlers/AccountModule.cs

228 lines
9.2 KiB
C#
Raw Normal View History

2023-10-16 09:50:49 +00:00
using AscNet.Common.Database;
using AscNet.Common.MsgPack;
2023-11-15 01:01:16 +00:00
using AscNet.Common.Util;
using AscNet.Table.share.chat;
using AscNet.Table.share.guide;
2023-11-15 01:01:16 +00:00
using AscNet.Table.share.item;
using MessagePack;
using System.Diagnostics;
2023-10-10 09:56:08 +00:00
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
2023-10-10 09:56:08 +00:00
internal class AccountModule
{
[RequestPacketHandler("HandshakeRequest")]
public static void HandshakeRequestHandler(Session session, Packet.Request packet)
2023-10-10 09:56:08 +00:00
{
// TODO: make this somehow universal, look into better architecture to handle packets
// and automatically log their deserialized form
2023-10-10 09:56:08 +00:00
HandshakeResponse response = new()
{
Code = 0,
UtcOpenTime = 0,
Sha1Table = null
};
session.SendResponse(response, packet.Id);
2023-10-10 09:56:08 +00:00
}
2023-10-10 13:59:08 +00:00
[RequestPacketHandler("LoginRequest")]
public static void LoginRequestHandler(Session session, Packet.Request packet)
2023-10-10 13:59:08 +00:00
{
2023-10-16 09:50:49 +00:00
LoginRequest request = MessagePackSerializer.Deserialize<LoginRequest>(packet.Content);
Player? player = Player.FromToken(request.Token);
if (player is null)
{
session.SendResponse(new LoginResponse
{
Code = 1007 // LoginInvalidLoginToken
}, packet.Id);
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();
}
2023-10-16 09:53:53 +00:00
session.player = player;
2023-10-19 07:07:48 +00:00
session.character = Character.FromUid(player.PlayerData.Id);
session.stage = Stage.FromUid(player.PlayerData.Id);
2023-11-15 01:01:16 +00:00
session.inventory = Inventory.FromUid(player.PlayerData.Id);
2023-10-10 13:59:08 +00:00
session.SendResponse(new LoginResponse
{
Code = 0,
2023-10-16 09:50:49 +00:00
ReconnectToken = player.Token,
2023-10-10 13:59:08 +00:00
UtcOffset = 0,
UtcServerTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
}, packet.Id);
2023-10-10 18:22:41 +00:00
2023-10-11 18:32:25 +00:00
DoLogin(session);
}
[RequestPacketHandler("ReconnectRequest")]
public static void ReconnectRequestHandler(Session session, Packet.Request packet)
{
2023-10-16 09:50:49 +00:00
ReconnectRequest request = MessagePackSerializer.Deserialize<ReconnectRequest>(packet.Content);
2023-10-19 07:07:48 +00:00
Player? player;
if (session.player is not null)
player = session.player;
else
{
player = Player.FromToken(request.Token);
2023-11-15 01:01:16 +00:00
if (player is not null && (session.character is null || session.stage is null || session.inventory is null))
2023-10-19 07:07:48 +00:00
{
session.character = Character.FromUid(player.PlayerData.Id);
session.stage = Stage.FromUid(player.PlayerData.Id);
2023-11-15 01:01:16 +00:00
session.inventory = Inventory.FromUid(player.PlayerData.Id);
2023-10-19 07:07:48 +00:00
}
}
2023-10-16 09:50:49 +00:00
if (player?.PlayerData.Id != request.PlayerId)
{
session.SendResponse(new ReconnectResponse()
{
Code = 1029 // ReconnectInvalidToken
}, packet.Id);
return;
}
2023-10-16 09:53:53 +00:00
session.player = player;
session.SendResponse(new ReconnectResponse()
{
2023-10-16 09:50:49 +00:00
ReconnectToken = request.Token
}, packet.Id);
}
/* TODO
[RequestPacketHandler("ReconnectAck")]
public static void ReconnectAckHandler(Session session, Packet.Request packet)
{
}
*/
// TODO: Move somewhere else, also split.
2023-10-11 18:32:25 +00:00
static void DoLogin(Session session)
{
2023-10-19 07:07:48 +00:00
NotifyLogin notifyLogin = new()
{
PlayerData = session.player.PlayerData,
TeamGroupData = session.player.TeamGroups,
BaseEquipLoginData = new(),
FubenData = new()
{
2023-11-13 12:10:02 +00:00
StageData = session.stage.Stages.ToDictionary(x => x.Key, x => x.Value),
2023-10-19 07:07:48 +00:00
FubenBaseData = new()
},
FubenMainLineData = new(),
FubenChapterExtraLoginData = new(),
FubenUrgentEventData = new(),
2023-11-15 01:01:16 +00:00
ItemList = session.inventory.Items,
2023-10-19 07:07:48 +00:00
UseBackgroundId = 14000001 // main ui theme, table still failed to dump
};
2023-11-12 06:00:44 +00:00
if (notifyLogin.PlayerData.DisplayCharIdList.Count < 1)
notifyLogin.PlayerData.DisplayCharIdList.Add(notifyLogin.PlayerData.DisplayCharId);
2023-10-19 07:07:48 +00:00
notifyLogin.FashionList.AddRange(session.character.Fashions);
#if DEBUG
notifyLogin.PlayerData.GuideData = GuideGroupTableReader.Instance.All.Select(x => (long)x.Id).ToList();
#endif
2023-10-19 07:07:48 +00:00
NotifyCharacterDataList notifyCharacterData = new();
notifyCharacterData.CharacterDataList.AddRange(session.character.Characters);
NotifyEquipDataList notifyEquipData = new();
notifyEquipData.EquipDataList.AddRange(session.character.Equips);
NotifyAssistData notifyAssistData = new()
{
AssistData = new()
{
AssistCharacterId = session.character.Characters.First().Id
}
};
NotifyChatLoginData notifyChatLoginData = new()
{
RefreshTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
UnlockEmojis = EmojiTableReader.Instance.All.Select(x => new NotifyChatLoginData.NotifyChatLoginDataUnlockEmoji() { Id = (uint)x.Id }).ToList()
};
session.SendPush(notifyLogin);
2023-10-19 07:07:48 +00:00
session.SendPush(notifyCharacterData);
session.SendPush(notifyEquipData);
session.SendPush(notifyAssistData);
session.SendPush(notifyChatLoginData);
2023-10-14 17:16:45 +00:00
2023-11-19 07:44:27 +00:00
#region DisclamerMail
NotifyMails notifyMails = new();
notifyMails.NewMailList.Add(new NotifyMails.NotifyMailsNewMailList()
{
Id = "0",
Status = 0, // MAIL_STATUS_UNREAD
SendName = "AscNet Developers",
Title = "[IMPORTANT] Important Info Regarding This Server Software",
Content = @"Hello Commandant!
Welcome to AscNet, we are happy that you are using this Server Software.
This Server Software is always free and if you are paying to gain access to this you are being SCAMMED, we encourage you to help prevent another buyer like you by making a PSA or telling others whom you may see as potential users.
Sorry for the inconvinience.
AscNet使
使
便",
CreateTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
SendTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
ExpireTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2,
IsForbidDelete = true
});
session.SendPush(notifyMails);
#endregion
2023-11-11 11:08:20 +00:00
// NEEDED to not softlock!
session.SendPush(new NotifyFubenPrequelData() { FubenPrequelData = new() });
session.SendPush(new NotifyPrequelChallengeRefreshTime() { NextRefreshTime = (uint)DateTimeOffset.Now.ToUnixTimeSeconds() + 3600 * 24 });
session.SendPush(new NotifyMainLineActivity() { EndTime = 0 });
session.SendPush(new NotifyDailyFubenLoginData() { RefreshTime = (uint)DateTimeOffset.Now.ToUnixTimeSeconds() + 3600 * 24 });
session.SendPush(new NotifyBriefStoryData());
session.SendPush(new NotifyFubenBossSingleData()
{
FubenBossSingleData = new()
{
ActivityNo = 1,
TotalScore = 0,
MaxScore = 0,
OldLevelType = 0,
LevelType = 1,
ChallengeCount = 0,
RemainTime = 100000,
AutoFightCount = 0,
CharacterPoints = new {},
RankPlatform = 0
}
});
session.SendPush(new NotifyBfrtData() { BfrtData = new() });
2023-10-10 13:59:08 +00:00
}
2023-10-10 09:56:08 +00:00
}
}