From 23bbbd8d16f13451f446253903bcde0cddccdecd Mon Sep 17 00:00:00 2001 From: rfi Date: Sat, 11 Nov 2023 08:12:11 +0700 Subject: [PATCH] GuideCompleteRequest impl and saving progression --- AscNet.Common/Database/Character.cs | 5 ++++ AscNet.Common/Database/Player.cs | 6 ++++- AscNet.Common/Database/Stage.cs | 7 +++++- AscNet.GameServer/Handlers/GuideModule.cs | 29 +++++++++++++++++++++++ AscNet.GameServer/Session.cs | 6 +++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/AscNet.Common/Database/Character.cs b/AscNet.Common/Database/Character.cs index 2a45ed48..d8cbd8c5 100644 --- a/AscNet.Common/Database/Character.cs +++ b/AscNet.Common/Database/Character.cs @@ -104,6 +104,11 @@ namespace AscNet.Common.Database Equips.Add(equipData); } + public void Save() + { + collection.ReplaceOne(Builders.Filter.Eq(x => x.Id, Id), this); + } + [BsonId] public ObjectId Id { get; set; } diff --git a/AscNet.Common/Database/Player.cs b/AscNet.Common/Database/Player.cs index a0074b6f..8b7590dd 100644 --- a/AscNet.Common/Database/Player.cs +++ b/AscNet.Common/Database/Player.cs @@ -2,7 +2,6 @@ using MongoDB.Bson; using MongoDB.Driver; using AscNet.Common.MsgPack; -using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Options; namespace AscNet.Common.Database @@ -89,6 +88,11 @@ namespace AscNet.Common.Database }); } + public void Save() + { + collection.ReplaceOne(Builders.Filter.Eq(x => x.Id, Id), this); + } + [BsonId] public ObjectId Id { get; set; } diff --git a/AscNet.Common/Database/Stage.cs b/AscNet.Common/Database/Stage.cs index d4b66875..763e6a5b 100644 --- a/AscNet.Common/Database/Stage.cs +++ b/AscNet.Common/Database/Stage.cs @@ -53,7 +53,12 @@ namespace AscNet.Common.Database { Stages.Add(stageData.StageId, stageData); } - + + public void Save() + { + collection.ReplaceOne(Builders.Filter.Eq(x => x.Id, Id), this); + } + [BsonId] public ObjectId Id { get; set; } diff --git a/AscNet.GameServer/Handlers/GuideModule.cs b/AscNet.GameServer/Handlers/GuideModule.cs index da25a978..947a6372 100644 --- a/AscNet.GameServer/Handlers/GuideModule.cs +++ b/AscNet.GameServer/Handlers/GuideModule.cs @@ -15,6 +15,25 @@ namespace AscNet.GameServer.Handlers public int Code; public List? RewardGoodsList; } + + [MessagePackObject(true)] + public class GuideCompleteRequest + { + public int GuideGroupId; + } + + [MessagePackObject(true)] + public class NotifyGuide + { + public int GuideGroupId; + } + + [MessagePackObject(true)] + public class GuideCompleteResponse + { + public int Code; + public List? RewardGoodsList; + } internal class GuideModule { @@ -30,5 +49,15 @@ namespace AscNet.GameServer.Handlers { session.SendResponse(new GuideGroupFinishResponse(), packet.Id); } + + [RequestPacketHandler("GuideCompleteRequest")] + public static void GuideCompleteRequestHandler(Session session, Packet.Request packet) + { + GuideCompleteRequest request = MessagePackSerializer.Deserialize(packet.Content); + + session.player.PlayerData.GuideData.Add(request.GuideGroupId); + session.SendPush(new NotifyGuide() { GuideGroupId = request.GuideGroupId }); + session.SendResponse(new GuideCompleteResponse(), packet.Id); + } } } diff --git a/AscNet.GameServer/Session.cs b/AscNet.GameServer/Session.cs index ad719088..aa54b54f 100644 --- a/AscNet.GameServer/Session.cs +++ b/AscNet.GameServer/Session.cs @@ -204,6 +204,12 @@ namespace AscNet.GameServer if (Server.Instance.Sessions.GetValueOrDefault(id) is null) return; + // DB save on disconnect + log.Info($"saving session state..."); + player?.Save(); + character?.Save(); + stage?.Save(); + log.Warn($"{id} disconnected"); client.Close(); Server.Instance.Sessions.Remove(id);