Changed whole project structure (split client and server into separat projects)

This commit is contained in:
hydrant
2019-02-25 22:12:05 +01:00
parent d2181c4987
commit 33abb3d04f
185 changed files with 282 additions and 596 deletions

View File

@@ -0,0 +1,82 @@
using GTANetworkAPI;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.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 reallife_gamemode.Server.Services
{
class ChatService
{
public static void NotAuthorized(Client player)
{
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
}
public static void PlayerNotFound(Client player)
{
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
}
public static void PlayerNotLoggedIn(Client player)
{
player.SendChatMessage("~r~[FEHLER]~s~ Du bist nicht eingeloggt.");
}
public static void ErrorMsg(Client player)
{
player.SendChatMessage("~r~[FEHLER]~s~ Die Aktion wurde nicht ausgeführt.");
}
/// <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 (Client c in NAPI.Pools.GetAllPlayers())
{
Faction f = c.GetUser()?.GetFaction();
if (f != null)
{
if (factions.Find(fT => fT.Id == f.Id) != null)
{
c.SendChatMessage(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 BroadcastAdmin(string message, AdminLevel minLevel)
{
NAPI.Pools.GetAllPlayers().ForEach(p =>
{
if(p.GetUser()?.IsAdmin(minLevel) ?? false)
{
p.SendChatMessage(message);
}
});
}
}
}

View File

@@ -0,0 +1,44 @@
using GTANetworkAPI;
using System;
using System.Collections.Generic;
using System.Text;
/**
* @overview Life of German Reallife - Client Service (ClientService.cs)
* @author hydrant
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Services
{
class ClientService
{
/// <summary>
/// Gibt einen Client anhand seines Namens oder der ID zurück
/// </summary>
/// <param name="nameOrId">Die ID oder der Name, nach dem gesucht werden soll</param>
/// <returns></returns>
public static Client GetClientByNameOrId(string nameOrId)
{
Client toReturn = null;
nameOrId = nameOrId.ToLower();
List<Client> playerList = NAPI.Pools.GetAllPlayers();
if(int.TryParse(nameOrId, out int id))
{
toReturn = playerList.Find(p => p.Handle.Value == id);
return toReturn;
}
toReturn = playerList.Find(p => p.Name.ToLower() == nameOrId);
if(toReturn == null)
{
toReturn = playerList.Find(p => p.Name.ToLower().StartsWith(nameOrId));
}
return toReturn;
}
}
}