Proper Echelon Handling
This commit is contained in:
parent
c393dace7c
commit
adf06a75d5
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -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, };
|
||||||
|
|
Loading…
Reference in New Issue