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);
|
Equips.Add(equipData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
collection.ReplaceOne(Builders<Character>.Filter.Eq(x => x.Id, Id), this);
|
||||||
|
}
|
||||||
|
|
||||||
[BsonId]
|
[BsonId]
|
||||||
public ObjectId Id { get; set; }
|
public ObjectId Id { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using AscNet.Common.MsgPack;
|
using AscNet.Common.MsgPack;
|
||||||
using MongoDB.Bson.Serialization;
|
|
||||||
using MongoDB.Bson.Serialization.Options;
|
using MongoDB.Bson.Serialization.Options;
|
||||||
|
|
||||||
namespace AscNet.Common.Database
|
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]
|
[BsonId]
|
||||||
public ObjectId Id { get; set; }
|
public ObjectId Id { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,11 @@ namespace AscNet.Common.Database
|
||||||
Stages.Add(stageData.StageId, stageData);
|
Stages.Add(stageData.StageId, stageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
collection.ReplaceOne(Builders<Stage>.Filter.Eq(x => x.Id, Id), this);
|
||||||
|
}
|
||||||
|
|
||||||
[BsonId]
|
[BsonId]
|
||||||
public ObjectId Id { get; set; }
|
public ObjectId Id { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,25 @@ namespace AscNet.GameServer.Handlers
|
||||||
public List<dynamic>? RewardGoodsList;
|
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
|
internal class GuideModule
|
||||||
{
|
{
|
||||||
[RequestPacketHandler("GuideOpenRequest")]
|
[RequestPacketHandler("GuideOpenRequest")]
|
||||||
|
@ -30,5 +49,15 @@ namespace AscNet.GameServer.Handlers
|
||||||
{
|
{
|
||||||
session.SendResponse(new GuideGroupFinishResponse(), packet.Id);
|
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)
|
if (Server.Instance.Sessions.GetValueOrDefault(id) is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// DB save on disconnect
|
||||||
|
log.Info($"saving session state...");
|
||||||
|
player?.Save();
|
||||||
|
character?.Save();
|
||||||
|
stage?.Save();
|
||||||
|
|
||||||
log.Warn($"{id} disconnected");
|
log.Warn($"{id} disconnected");
|
||||||
client.Close();
|
client.Close();
|
||||||
Server.Instance.Sessions.Remove(id);
|
Server.Instance.Sessions.Remove(id);
|
||||||
|
|
Loading…
Reference in New Issue