using GTANetworkAPI; using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Job; using ReallifeGamemode.Server.Util; using System.Collections.Generic; /** * @overview Life of German Reallife - Chat Service (ChatService.cs) * @author hydrant, xSprite * @copyright (c) 2008 - 2018 Life of German */ namespace ReallifeGamemode.Server.Services { class ChatService { public static void NotAuthorized(Client player) { ChatService.ErrorMessage(player, "Du kannst diesen Befehl nicht ausführen"); } public static void PlayerNotFound(Client player) { ChatService.ErrorMessage(player, "Der Spieler wurde nicht gefunden"); } public static void ErrorMessage(Client player, string message) { ChatService.SendMessage(player, $"~r~[FEHLER]~s~ {message}~s~."); } public static void SendMessage(Client player, string message) { if (player == null) return; player.SendChatMessage(message); } /// /// Sendet eine Nachricht an eine Liste von Fraktionen /// /// Die Nachricht, die gesendet werden soll /// Die Liste an Fraktionen, die diese Nachricht bekommen sollen public static void BroadcastFaction(string message, List factions) { foreach (Client c in NAPI.Pools.GetAllPlayers()) { Faction f = c.GetUser()?.Faction; if (f != null) { if (factions.Find(fT => fT.Id == f.Id) != null) { ChatService.SendMessage(c, message); } } } } /// /// Sendet eine Nachricht an eine Fraktion /// /// Die Nachricht, die gesendet werden soll /// Die Fraktion, die diese Nachricht bekommen soll public static void BroadcastFaction(string message, Faction f) { BroadcastFaction(message, new List() { f }); } /// /// Sendet eine Nachricht an alle Spieler mit einem bestimmten Admin Level /// /// Die Nachricht, die gesendet werden soll /// Das mindest Admin Level, das für das Erhalten dieser Nachricht benötigt wird public static void BroadcastAdmin(string message, AdminLevel minLevel) { NAPI.Pools.GetAllPlayers().ForEach(p => { if (p.GetUser()?.IsAdmin(minLevel) ?? false) { ChatService.SendMessage(p, message); } }); } public static void BroadcastGroup(string message, Group group) { message = $"!{{FF8080}}** Gruppe: {message}"; NAPI.Pools.GetAllPlayers().ForEach(p => { Group pGroup = p.GetUser()?.Group; if (pGroup?.Id == group.Id) { ChatService.SendMessage(p, message); } }); } public static void BroadcastJob(string message, JobBase job) { job.GetUsersInJob().ForEach(c => ChatService.SendMessage(c, message)); } } }