From 7eeac8b5730bc6afece58706b61d10af90f8a2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Tue, 20 May 2025 03:35:52 -0300 Subject: [PATCH 1/2] Set all characters offline on server start to ensure consistent state --- Maple2.Database/Storage/Game/GameStorage.User.cs | 10 ++++++++++ Maple2.Server.World/WorldServer.cs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/Maple2.Database/Storage/Game/GameStorage.User.cs b/Maple2.Database/Storage/Game/GameStorage.User.cs index 1500226bc..68a960970 100644 --- a/Maple2.Database/Storage/Game/GameStorage.User.cs +++ b/Maple2.Database/Storage/Game/GameStorage.User.cs @@ -70,6 +70,16 @@ public bool UpdateMachineId(long accountId, Guid machineId) { return (model, characters); } + public void SetAllCharacterToOffline() { + List characters = Context.Character.ToList(); + + foreach (Character character in characters) { + character.Channel = -1; + Context.Character.Update(character); + } + Context.SaveChanges(); + } + // If accountId is specified, only characters for the account will be returned. public Character? GetCharacter(long characterId, long accountId = -1) { if (accountId < 0) { diff --git a/Maple2.Server.World/WorldServer.cs b/Maple2.Server.World/WorldServer.cs index 5b278487e..f1db9ca0f 100644 --- a/Maple2.Server.World/WorldServer.cs +++ b/Maple2.Server.World/WorldServer.cs @@ -45,6 +45,8 @@ public WorldServer(GameStorage gameStorage, ChannelClientLookup channelClients, scheduler.Start(); memoryStringBoards = []; + SetAllCharacterToOffline(); + StartDailyReset(); StartWorldEvents(); ScheduleGameEvents(); @@ -55,6 +57,11 @@ public WorldServer(GameStorage gameStorage, ChannelClientLookup channelClients, heartbeatThread.Start(); } + private void SetAllCharacterToOffline() { + using GameStorage.Request db = gameStorage.Context(); + db.SetAllCharacterToOffline(); + } + private void Heartbeat() { while (!tokenSource.Token.IsCancellationRequested) { try { From 4f422cce883a223861cf267593dadf0fab4357bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Tue, 20 May 2025 04:41:52 -0300 Subject: [PATCH 2/2] suggestion --- Maple2.Database/Storage/Game/GameStorage.User.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Maple2.Database/Storage/Game/GameStorage.User.cs b/Maple2.Database/Storage/Game/GameStorage.User.cs index 68a960970..03e68ac66 100644 --- a/Maple2.Database/Storage/Game/GameStorage.User.cs +++ b/Maple2.Database/Storage/Game/GameStorage.User.cs @@ -71,13 +71,7 @@ public bool UpdateMachineId(long accountId, Guid machineId) { } public void SetAllCharacterToOffline() { - List characters = Context.Character.ToList(); - - foreach (Character character in characters) { - character.Channel = -1; - Context.Character.Update(character); - } - Context.SaveChanges(); + Context.Database.ExecuteSqlRaw("UPDATE `character` SET Channel = -1"); } // If accountId is specified, only characters for the account will be returned.