Proper Echelon Handling

This commit is contained in:
raphaeIl 2024-05-30 02:53:43 +08:00
parent c393dace7c
commit adf06a75d5
3 changed files with 26 additions and 3 deletions

View File

@ -65,5 +65,16 @@
return [.. gears]; return [.. gears];
} }
public static List<EchelonDB> AddEchelons(this AccountDB account, SCHALEContext context, params EchelonDB[] echelons)
{
foreach (var echelon in echelons)
{
echelon.AccountServerId = account.ServerId;
context.Echelons.Add(echelon);
}
return [.. echelons];
}
} }
} }

View File

@ -1194,7 +1194,9 @@ namespace SCHALE.Common.Database
[JsonIgnore] [JsonIgnore]
public virtual AccountDB Account { get; set; } public virtual AccountDB Account { get; set; }
[JsonIgnore]
public long AccountServerId { get; set; } public long AccountServerId { get; set; }
public EchelonType EchelonType { get; set; } public EchelonType EchelonType { get; set; }
public long EchelonNumber { get; set; } public long EchelonNumber { get; set; }
public EchelonExtensionType ExtensionType { get; set; } public EchelonExtensionType ExtensionType { get; set; }

View File

@ -31,9 +31,19 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
[ProtocolHandler(Protocol.Echelon_Save)] [ProtocolHandler(Protocol.Echelon_Save)]
public ResponsePacket SaveHandler(EchelonSaveRequest req) public ResponsePacket SaveHandler(EchelonSaveRequest req)
{ {
var db = req.EchelonDB; var account = sessionKeyService.GetAccount(req.SessionKey);
context.Echelons.Add(db); 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(); context.SaveChanges();
return new EchelonSaveResponse() { EchelonDB = req.EchelonDB, }; return new EchelonSaveResponse() { EchelonDB = req.EchelonDB, };