From 162a3a4094d72a94f4d4ea63978ad29df677d1b0 Mon Sep 17 00:00:00 2001 From: hydrant Date: Tue, 16 Oct 2018 23:46:16 +0200 Subject: [PATCH] Added /uninvite Command --- Server/Commands/Faction.cs | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Server/Commands/Faction.cs b/Server/Commands/Faction.cs index 095a3da1..aacce988 100644 --- a/Server/Commands/Faction.cs +++ b/Server/Commands/Faction.cs @@ -135,5 +135,53 @@ namespace reallife_gamemode.Server.Commands dbContext.SaveChanges(); } } + + [Command("uninvite", "~m~Benutzung: ~s~/uninvite [Name]")] + public void CmdFactionUninvite(Client player, string name) + { + if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false) + { + ChatService.NotAuthorized(player); + return; + } + + Client target = ClientService.GetClientByName(name); + if (target == null || !target.IsLoggedIn()) + { + ChatService.PlayerNotFound(player); + return; + } + + if (target.GetUser()?.FactionId != player.GetUser()?.FactionId) + { + player.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht in deiner Fraktion."); + return; + } + + if(player.Handle == target.Handle) + { + player.SendChatMessage("~r~[FEHLER]~s~ Du kannst dich nicht selber uninviten."); + return; + } + + if(target.GetUser()?.FactionLeader ?? false) + { + player.SendChatMessage("~r~[FEHLER]~s~ Du kannst keinen Leader uninviten."); + return; + } + + using (var dbContext = new DatabaseContext()) + { + + target.GetUser(dbContext).FactionRankId = null; + target.GetUser(dbContext).FactionId = null; + + player.SendChatMessage("!{02FCFF}Du hast " + target.Name + " aus der Fraktion geworfen."); + target.SendChatMessage("!{02FCFF}Du wurdest von " + player.Name + " aus der Fraktion geworfen."); + + dbContext.SaveChanges(); + } + } + } }