From e40032518408e4ca23362602295f84da8f3b14ef Mon Sep 17 00:00:00 2001 From: Kyle Belanger Date: Thu, 11 Apr 2024 05:11:34 -0400 Subject: [PATCH] Long overdue save command --- AscNet.GameServer/Commands/SaveCommand.cs | 15 +++++++++++++++ AscNet.GameServer/Session.cs | 16 +++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 AscNet.GameServer/Commands/SaveCommand.cs diff --git a/AscNet.GameServer/Commands/SaveCommand.cs b/AscNet.GameServer/Commands/SaveCommand.cs new file mode 100644 index 00000000..38b6abe9 --- /dev/null +++ b/AscNet.GameServer/Commands/SaveCommand.cs @@ -0,0 +1,15 @@ +namespace AscNet.GameServer.Commands +{ + [CommandName("save")] + internal class SaveCommand : Command + { + public SaveCommand(Session session, string[] args, bool validate = true) : base(session, args, validate) { } + + public override string Help => "Command to save the current session state to the database"; + + public override void Execute() + { + session.Save(); + } + } +} diff --git a/AscNet.GameServer/Session.cs b/AscNet.GameServer/Session.cs index b2535ed4..7e639549 100644 --- a/AscNet.GameServer/Session.cs +++ b/AscNet.GameServer/Session.cs @@ -227,15 +227,21 @@ namespace AscNet.GameServer return; // DB save on disconnect - log.Info($"Saving session state..."); - player?.Save(); - character?.Save(); - stage?.Save(); - inventory?.Save(); + Save(); log.Warn($"{id} disconnected"); client.Close(); Server.Instance.Sessions.Remove(id); } + + public void Save() + { + player?.Save(); + character?.Save(); + stage?.Save(); + inventory?.Save(); + + log.Info($"Saving session state..."); + } } }