forked from PGR/ascnet
1
0
Fork 0

GuideCompleteRequest impl and saving progression

This commit is contained in:
rfi 2023-11-11 08:12:11 +07:00
parent 8d808170a5
commit 23bbbd8d16
5 changed files with 51 additions and 2 deletions

View File

@ -104,6 +104,11 @@ namespace AscNet.Common.Database
Equips.Add(equipData);
}
public void Save()
{
collection.ReplaceOne(Builders<Character>.Filter.Eq(x => x.Id, Id), this);
}
[BsonId]
public ObjectId Id { get; set; }

View File

@ -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<Player>.Filter.Eq(x => x.Id, Id), this);
}
[BsonId]
public ObjectId Id { get; set; }

View File

@ -54,6 +54,11 @@ namespace AscNet.Common.Database
Stages.Add(stageData.StageId, stageData);
}
public void Save()
{
collection.ReplaceOne(Builders<Stage>.Filter.Eq(x => x.Id, Id), this);
}
[BsonId]
public ObjectId Id { get; set; }

View File

@ -16,6 +16,25 @@ namespace AscNet.GameServer.Handlers
public List<dynamic>? 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<dynamic>? RewardGoodsList;
}
internal class GuideModule
{
[RequestPacketHandler("GuideOpenRequest")]
@ -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<GuideCompleteRequest>(packet.Content);
session.player.PlayerData.GuideData.Add(request.GuideGroupId);
session.SendPush(new NotifyGuide() { GuideGroupId = request.GuideGroupId });
session.SendResponse(new GuideCompleteResponse(), packet.Id);
}
}
}

View File

@ -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);