forked from PGR/ascnet
GuideCompleteRequest impl and saving progression
This commit is contained in:
parent
8d808170a5
commit
23bbbd8d16
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -53,7 +53,12 @@ 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; }
|
||||
|
||||
|
|
|
@ -15,6 +15,25 @@ namespace AscNet.GameServer.Handlers
|
|||
public int Code;
|
||||
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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue