[HOTFIX] Fix server crash on gangwar end
This commit is contained in:
@@ -40,12 +40,12 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
|
||||
foreach (var l in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
if (!l.IsLoggedIn() && !l.GetUser().FactionLeader)
|
||||
return;
|
||||
|
||||
if (l.IsLoggedIn() && l.GetUser()?.FactionLeader == true)
|
||||
{
|
||||
l.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void GangwarKill(Player killer, Player victim)
|
||||
{
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
{
|
||||
foreach (Player gangwarPlayer in this.playerInGangwar)
|
||||
{
|
||||
if(!gangwarPlayer.IsLoggedIn())
|
||||
if (!gangwarPlayer.IsLoggedIn())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
{
|
||||
foreach (Player gangwarPlayer in this.playerInGangwar)
|
||||
{
|
||||
if(!gangwarPlayer.IsLoggedIn())
|
||||
if (!gangwarPlayer.IsLoggedIn())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -242,10 +242,22 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
this.timer = null;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction?.Name == this.Owner).ToArray();
|
||||
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction?.Name == this.Attacker).ToArray();
|
||||
|
||||
Faction ownerFaction = dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Name == getOwner()).FirstOrDefault();
|
||||
Faction attackerFaction = dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Name == getOwner()).FirstOrDefault();
|
||||
|
||||
if (ownerFaction == null || attackerFaction == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (getOwner() == FactionName)
|
||||
{
|
||||
Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray();
|
||||
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigt.", ownerFaction);
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat den Angrif auf das Gebiet ~r~" + getName() + "~w~ verloren.", attackerFaction);
|
||||
|
||||
foreach (var o in owners)
|
||||
{
|
||||
o.TriggerEvent("CLIENT:win");
|
||||
@@ -254,15 +266,12 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
{
|
||||
a.TriggerEvent("CLIENT:loose");
|
||||
}
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat erfolgreich das Gebiet ~g~" + getName() + "~w~ verteidigt.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion hat den Angrif auf das Gebiet ~r~" + getName() + "~w~ verloren.", dbContext.Factions.Where(f => f.Name == getAttacker()).FirstOrDefault());
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Name == getOwner()).First().BankAccount.Balance += 15000;
|
||||
ownerFaction.BankAccount.Balance += 15000;
|
||||
}
|
||||
else if (getOwner() != FactionName)
|
||||
{
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
|
||||
Player[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray();
|
||||
Player[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", ownerFaction);
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte erfolgreich das Gebiet ~g~" + getName() + "~w~ erobern.", attackerFaction);
|
||||
foreach (var o in owners)
|
||||
{
|
||||
if (o != null)
|
||||
@@ -274,11 +283,10 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
a.TriggerEvent("CLIENT:win");
|
||||
}
|
||||
this.Owner = FactionName;
|
||||
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte erfolgreich das Gebiet ~g~" + getName() + "~w~ erobern.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
|
||||
dbContext.Factions.Include(f => f.BankAccount).Where(f => f.Name == getOwner()).First().BankAccount.Balance += 10000;
|
||||
attackerFaction.BankAccount.Balance += 10000;
|
||||
Turfs turf = dbContext.Turfs.Where(t => t.Id == getId()).FirstOrDefault();
|
||||
turf.Owner = this.Owner;
|
||||
turf.FactionId = dbContext.Factions.Where(f => f.Name == this.Owner).FirstOrDefault().Id;
|
||||
turf.FactionId = attackerFaction.Id;
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user