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..."); + } } }