diff --git a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs index 1272911..450c252 100644 --- a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs +++ b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs @@ -65,5 +65,16 @@ return [.. gears]; } + + public static List AddEchelons(this AccountDB account, SCHALEContext context, params EchelonDB[] echelons) + { + foreach (var echelon in echelons) + { + echelon.AccountServerId = account.ServerId; + context.Echelons.Add(echelon); + } + + return [.. echelons]; + } } } diff --git a/SCHALE.Common/Database/dbs.cs b/SCHALE.Common/Database/dbs.cs index e3f8e43..ac2e5a9 100644 --- a/SCHALE.Common/Database/dbs.cs +++ b/SCHALE.Common/Database/dbs.cs @@ -1194,7 +1194,9 @@ namespace SCHALE.Common.Database [JsonIgnore] public virtual AccountDB Account { get; set; } + [JsonIgnore] public long AccountServerId { get; set; } + public EchelonType EchelonType { get; set; } public long EchelonNumber { get; set; } public EchelonExtensionType ExtensionType { get; set; } diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs index 8a286e1..cbdbe6e 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs @@ -31,9 +31,19 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers [ProtocolHandler(Protocol.Echelon_Save)] public ResponsePacket SaveHandler(EchelonSaveRequest req) { - var db = req.EchelonDB; - - context.Echelons.Add(db); + var account = sessionKeyService.GetAccount(req.SessionKey); + + var newEchelon = req.EchelonDB; + var existingEchelon = context.Echelons.FirstOrDefault(e => e.AccountServerId == newEchelon.AccountServerId && e.EchelonType == newEchelon.EchelonType && + e.EchelonNumber == newEchelon.EchelonNumber && e.ExtensionType == newEchelon.ExtensionType); + + if (existingEchelon != null) + { + context.Echelons.Remove(existingEchelon); + context.SaveChanges(); + } + + account.AddEchelons(context, [newEchelon]); context.SaveChanges(); return new EchelonSaveResponse() { EchelonDB = req.EchelonDB, };