Removed User.GetFaction()

This commit is contained in:
hydrant
2019-03-10 13:02:03 +01:00
parent f732f053a8
commit ed069fd1d7
8 changed files with 39 additions and 43 deletions

View File

@@ -12,7 +12,7 @@ let globalData = {
}; };
mp.game.gameplay.enableMpDlcMaps(true); mp.game.gameplay.enableMpDlcMaps(true);
mp.game.vehicle.defaultEngineBehaviour = true; mp.game.vehicle.defaultEngineBehaviour = false;
//ALPHABETISCH SORTIERT UND ZUSAMMENGEFÜGT //ALPHABETISCH SORTIERT UND ZUSAMMENGEFÜGT

View File

@@ -23,7 +23,7 @@ using ReallifeGamemode.Server.Models;
namespace ReallifeGamemode.Server.Commands namespace ReallifeGamemode.Server.Commands
{ {
public class Admin : Script public class AdminCommands : Script
{ {
#region Test #region Test
[Command("eat", "~m~Benutzung: ~s~/eat [Item]")] [Command("eat", "~m~Benutzung: ~s~/eat [Item]")]
@@ -1550,7 +1550,7 @@ namespace ReallifeGamemode.Server.Commands
case "fvehicle": case "fvehicle":
if (player.IsInVehicle) if (player.IsInVehicle)
{ {
if (player.GetUser().GetFaction() == null) if (player.GetUser().Faction == null)
{ {
player.SendChatMessage("~m~Du bist in keiner Fraktion! Invite dich erst mit ~y~/ainvite"); player.SendChatMessage("~m~Du bist in keiner Fraktion! Invite dich erst mit ~y~/ainvite");
return; return;
@@ -2118,7 +2118,7 @@ namespace ReallifeGamemode.Server.Commands
using(var dbContext = new DatabaseContext()) using(var dbContext = new DatabaseContext())
{ {
Entities.User owner = business.GetOwner(dbContext); User owner = business.GetOwner(dbContext);
if(owner == null) if(owner == null)
{ {
player.SendChatMessage("~r~[FEHLER]~s~ Dieses Business hat momentan keinen Besitzer."); player.SendChatMessage("~r~[FEHLER]~s~ Dieses Business hat momentan keinen Besitzer.");
@@ -2128,7 +2128,7 @@ namespace ReallifeGamemode.Server.Commands
owner.BusinessId = null; owner.BusinessId = null;
business.GetBankAccount(dbContext).Balance = 0; business.GetBankAccount(dbContext).Balance = 0;
owner.GetClient()?.SendChatMessage("~b~[ADMIN]~s~ Dir wurde von ~y~" + player.Name + "~s~ dein Business entzogen."); owner.Client?.SendChatMessage("~b~[ADMIN]~s~ Dir wurde von ~y~" + player.Name + "~s~ dein Business entzogen.");
player.SendChatMessage("~b~[ADMIN]~s~ Du hast ~y~" + owner.Name + "~s~ sein Business ~o~" + business.Name + "~s~ entzogen."); player.SendChatMessage("~b~[ADMIN]~s~ Du hast ~y~" + owner.Name + "~s~ sein Business ~o~" + business.Name + "~s~ entzogen.");
dbContext.SaveChanges(); dbContext.SaveChanges();

View File

@@ -15,14 +15,14 @@ using System.Text.RegularExpressions;
namespace ReallifeGamemode.Server.Commands namespace ReallifeGamemode.Server.Commands
{ {
class Faction : Script class FactionCommands : Script
{ {
#region Chat Commands #region Chat Commands
[Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)] [Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)]
public void CmdFactionF(Client player, string message) public void CmdFactionF(Client player, string message)
{ {
Entities.Faction f = player.GetUser()?.GetFaction(); Faction f = player.GetUser()?.Faction;
if (f == null || f.StateOwned) if (f == null || f.StateOwned)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -38,7 +38,7 @@ namespace ReallifeGamemode.Server.Commands
[Command("r", "~m~Benutzung: ~s~/r [Nachricht]", GreedyArg = true)] [Command("r", "~m~Benutzung: ~s~/r [Nachricht]", GreedyArg = true)]
public void CmdFactionR(Client player, string message) public void CmdFactionR(Client player, string message)
{ {
Entities.Faction f = player.GetUser()?.GetFaction(); Entities.Faction f = player.GetUser()?.Faction;
if (f == null || !f.StateOwned) if (f == null || !f.StateOwned)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -54,7 +54,7 @@ namespace ReallifeGamemode.Server.Commands
[Command("d", "~m~Benutzung: ~s~/d [Nachricht]", GreedyArg = true)] [Command("d", "~m~Benutzung: ~s~/d [Nachricht]", GreedyArg = true)]
public void CmdFactionD(Client player, string message) public void CmdFactionD(Client player, string message)
{ {
Entities.Faction f = player.GetUser()?.GetFaction(); Faction f = player.GetUser()?.Faction;
if (f == null || !f.StateOwned) if (f == null || !f.StateOwned)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -97,7 +97,7 @@ namespace ReallifeGamemode.Server.Commands
target.SetData("accept_invite", player.Handle); target.SetData("accept_invite", player.Handle);
player.SendChatMessage("!{02FCFF}Du hast dem Spieler " + target.Name + " eine Einladung in deine Fraktion gesendet."); player.SendChatMessage("!{02FCFF}Du hast dem Spieler " + target.Name + " eine Einladung in deine Fraktion gesendet.");
target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " eine Einladung in die Fraktion \"" + player.GetUser().GetFaction().Name + "\" erhalten."); target.SendChatMessage("!{02FCFF}Du hast von " + player.Name + " eine Einladung in die Fraktion \"" + player.GetUser().Faction.Name + "\" erhalten.");
target.SendChatMessage("!{02FCFF}Benutze '/accept invite', um die Einladung anzunehmen"); target.SendChatMessage("!{02FCFF}Benutze '/accept invite', um die Einladung anzunehmen");
return; return;
@@ -201,7 +201,7 @@ namespace ReallifeGamemode.Server.Commands
message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", ""); message = Regex.Replace(message, "(~[a-zA-Z]~{1})|(!{(.*)})", "");
string broadcastMsg = "~y~[" + player.GetUser().GetFaction().Name + "] " + player.Name + ": " + message; string broadcastMsg = "~y~[" + player.GetUser().Faction.Name + "] " + player.Name + ": " + message;
NAPI.Pools.GetAllPlayers().ForEach(p => NAPI.Pools.GetAllPlayers().ForEach(p =>
{ {

View File

@@ -7,7 +7,7 @@ using System.Linq;
namespace ReallifeGamemode.Server.Commands namespace ReallifeGamemode.Server.Commands
{ {
class User : Script class UserCommands : Script
{ {
[Command("accept", "~m~Benutzung: ~s~/accept [invite]")] [Command("accept", "~m~Benutzung: ~s~/accept [invite]")]
public void CmdUserAccept(Client player, string option) public void CmdUserAccept(Client player, string option)
@@ -38,14 +38,16 @@ namespace ReallifeGamemode.Server.Commands
return; return;
} }
Entities.User u = leader.GetUser(dbContext); User u = leader.GetUser(dbContext);
Entities.User own = player.GetUser(dbContext); User own = player.GetUser(dbContext);
own.FactionId = u.FactionId; own.FactionId = u.FactionId;
own.FactionLeader = false; own.FactionLeader = false;
own.FactionRankId = dbContext.FactionRanks. own.FactionRankId = dbContext
OrderBy(x => x.Order) .FactionRanks
.FirstOrDefault(r => r.FactionId == own.FactionId)?.Id ?? null; .OrderBy(x => x.Order)
.Where(r => r.FactionId == own.FactionId)
.FirstOrDefault()?.Id ?? null;
leader.SendChatMessage("!{02FCFF}" + player.Name + " hat die Einladung angenommen."); leader.SendChatMessage("!{02FCFF}" + player.Name + " hat die Einladung angenommen.");
player.SendChatMessage("!{02FCFF}Du hast die Einladung angenommen."); player.SendChatMessage("!{02FCFF}Du hast die Einladung angenommen.");

View File

@@ -57,24 +57,14 @@ namespace ReallifeGamemode.Server.Entities
public int? FactionRankId { get; set; } public int? FactionRankId { get; set; }
public FactionRank FactionRank { get; set; } public FactionRank FactionRank { get; set; }
public int? BusinessId { get; set; }
public Faction GetFaction()
{
using(var context = new DatabaseContext())
{
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
}
}
public FactionRank GetFactionRank() public FactionRank GetFactionRank()
{ {
using (var context = new DatabaseContext()) using (var dbContext = new DatabaseContext())
{ {
FactionRank toReturn = context.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId); FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId);
if (toReturn == null) if (toReturn == null)
{ {
toReturn = context.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId); toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId);
} }
if (toReturn == null) if (toReturn == null)
@@ -89,6 +79,8 @@ namespace ReallifeGamemode.Server.Entities
} }
} }
public int? BusinessId { get; set; }
public void BanPlayer(Client admin, string reason, int mins) public void BanPlayer(Client admin, string reason, int mins)
{ {
using (var banUserContext = new DatabaseContext()) using (var banUserContext = new DatabaseContext())
@@ -101,7 +93,7 @@ namespace ReallifeGamemode.Server.Entities
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]"); NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp }; banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
GetClient()?.Kick(); this.Client?.Kick();
mins--; mins--;
} }
@@ -109,7 +101,7 @@ namespace ReallifeGamemode.Server.Entities
{ {
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]"); NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 }; banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
GetClient()?.Kick(); this.Client?.Kick();
} }
banUserContext.Bans.Add(banUser); banUserContext.Bans.Add(banUser);
@@ -138,6 +130,7 @@ namespace ReallifeGamemode.Server.Entities
return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id); return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id);
} }
} }
public bool IsAdmin(AdminLevel level) => AdminLevel >= level; public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null) public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
@@ -155,9 +148,10 @@ namespace ReallifeGamemode.Server.Entities
} }
} }
public Client GetClient() [NotMapped]
public Client Client
{ {
return NAPI.Player.GetPlayerFromName(Name); get => NAPI.Player.GetPlayerFromName(this.Name);
} }
} }
} }

View File

@@ -87,7 +87,7 @@ namespace ReallifeGamemode.Server.Events
{ {
//LSFD //LSFD
case 2: case 2:
player.TriggerEvent("showFactionInteraction", user.FactionId, player.GetData("duty"), user.GetFaction().Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString()); player.TriggerEvent("showFactionInteraction", user.FactionId, player.GetData("duty"), user.Faction.Name, user.FactionLeader, Medic.ReviveTasks.Count.ToString(), Medic.HealTasks.Count.ToString(), Medic.FireTasks.Count.ToString());
break; break;
} }
} }
@@ -115,7 +115,7 @@ namespace ReallifeGamemode.Server.Events
int medicCount = 0; int medicCount = 0;
foreach(Client c in NAPI.Pools.GetAllPlayers()) foreach(Client c in NAPI.Pools.GetAllPlayers())
{ {
if((c.GetUser()?.GetFaction().Id ?? 0) == 2) if((c.GetUser()?.Faction.Id ?? 0) == 2)
{ {
medicCount++; medicCount++;
} }
@@ -132,7 +132,7 @@ namespace ReallifeGamemode.Server.Events
player.NametagColor = nameTagColor; player.NametagColor = nameTagColor;
using (var context = new DatabaseContext()) using (var context = new DatabaseContext())
{ {
List<CharacterCloth> clothes = context.CharacterClothes.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true); List<CharacterCloth> clothes = context.CharacterClothes.Where(u => u.UserId == user.Id && u.Duty == true).ToList();
foreach(var cloth in clothes) foreach(var cloth in clothes)
{ {

View File

@@ -21,7 +21,7 @@ namespace ReallifeGamemode.Server.Inventory.Items
public void Use(UserItem uItem) public void Use(UserItem uItem)
{ {
Client player = uItem.GetUser().GetClient(); Client player = uItem.GetUser().Client;
int amountToAdd = HpAmount; int amountToAdd = HpAmount;
if(player.Health + amountToAdd > 100) if(player.Health + amountToAdd > 100)

View File

@@ -42,7 +42,7 @@ namespace ReallifeGamemode.Server.Services
{ {
foreach (Client c in NAPI.Pools.GetAllPlayers()) foreach (Client c in NAPI.Pools.GetAllPlayers())
{ {
Faction f = c.GetUser()?.GetFaction(); Faction f = c.GetUser()?.Faction;
if (f != null) if (f != null)
{ {
if (factions.Find(fT => fT.Id == f.Id) != null) if (factions.Find(fT => fT.Id == f.Id) != null)