141 lines
4.2 KiB
C#
141 lines
4.2 KiB
C#
using GTANetworkAPI;
|
|
using ReallifeGamemode.Database;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Job;
|
|
using ReallifeGamemode.Server.Types;
|
|
using ReallifeGamemode.Server.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
/**
|
|
* @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(Player player)
|
|
{
|
|
ChatService.ErrorMessage(player, "Du kannst diesen Befehl nicht ausführen");
|
|
}
|
|
|
|
public static void PlayerNotFound(Player player)
|
|
{
|
|
ChatService.ErrorMessage(player, "Der Spieler wurde nicht gefunden");
|
|
}
|
|
|
|
public static void ErrorMessage(Player player, string message)
|
|
{
|
|
if (message.EndsWith("."))
|
|
{
|
|
message.Substring(0, message.Length - 1);
|
|
}
|
|
|
|
ChatService.SendMessage(player, $"~r~[FEHLER]~s~ {message}~s~.");
|
|
}
|
|
|
|
public static void SendMessage(Player player, string message)
|
|
{
|
|
if (player == null) return;
|
|
if (player.GetData<bool>("isDead") == true && (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)) return;
|
|
player.SendChatMessage(message);
|
|
}
|
|
|
|
public static void Broadcast(string message) => NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn()).ToList().ForEach(c => SendMessage(c, message));
|
|
|
|
/// <summary>
|
|
/// Sendet eine Nachricht an eine Liste von Fraktionen
|
|
/// </summary>
|
|
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
|
/// <param name="factions">Die Liste an Fraktionen, die diese Nachricht bekommen sollen</param>
|
|
public static void BroadcastFaction(string message, List<Faction> factions)
|
|
{
|
|
foreach (Player 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sendet eine Nachricht an eine Fraktion
|
|
/// </summary>
|
|
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
|
/// <param name="f">Die Fraktion, die diese Nachricht bekommen soll</param>
|
|
public static void BroadcastFaction(string message, Faction f)
|
|
{
|
|
BroadcastFaction(message, new List<Faction>() { f });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sendet eine Nachricht an alle Spieler mit einem bestimmten Admin Level
|
|
/// </summary>
|
|
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
|
|
/// <param name="minLevel">Das mindest Admin Level, das für das Erhalten dieser Nachricht benötigt wird</param>
|
|
public static void HQMessage(string message)
|
|
{
|
|
BroadcastFaction("!{#8181E9}HQ: " + message, new List<int>() { 1, 3 });
|
|
}
|
|
|
|
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 BroadcastDutyAdmin(string message)
|
|
{
|
|
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
|
{
|
|
if (p.IsAdminDuty())
|
|
{
|
|
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));
|
|
}
|
|
|
|
internal static void BroadcastFaction(string message, List<int> factionIds)
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
BroadcastFaction(message, dbContext.Factions.Where(f => factionIds.Contains(f.Id)).ToList());
|
|
}
|
|
}
|
|
}
|
|
}
|