Add Admin Check, Add AdminLevel Column in database
This commit is contained in:
6
Main.cs
6
Main.cs
@@ -5,6 +5,12 @@ namespace reallife_gamemode
|
|||||||
{
|
{
|
||||||
public class Main : Script
|
public class Main : Script
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Main Class (Main.cs)
|
||||||
|
* @author VegaZ, hydrant
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
[ServerEvent(Event.ResourceStart)]
|
[ServerEvent(Event.ResourceStart)]
|
||||||
public void OnResourceStart()
|
public void OnResourceStart()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,32 +2,24 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Server.Extensions;
|
||||||
using reallife_gamemode.Server.Services;
|
using reallife_gamemode.Server.Services;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
|
|
||||||
namespace reallife_gamemode.Server.Commands
|
namespace reallife_gamemode.Server.Commands
|
||||||
{
|
{
|
||||||
public class Admin : Script
|
public class Admin : Script
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Admin.cs
|
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||||
* @author VegaZ, hydrant
|
* @author VegaZ, hydrant
|
||||||
* @copyright (c) 2008 - 2018 Life of German
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
|
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
|
||||||
public void CmdAdminOChat(Client player, string message)
|
public void CmdAdminO(Client player, string message)
|
||||||
{
|
{
|
||||||
/*
|
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER))
|
||||||
* Alternative:
|
|
||||||
* Account playerAccount = AccountManager.GetAccount(player);
|
|
||||||
* if(!playerAccount.IsAdmin(adminLevel))
|
|
||||||
* {
|
|
||||||
* ChatService.NotAuthorized(player);
|
|
||||||
* return;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
int playerAdminLevel = 1;
|
|
||||||
if(playerAdminLevel < /* Benötigtes Level */ 1)
|
|
||||||
{
|
{
|
||||||
ChatService.NotAuthorized(player);
|
ChatService.NotAuthorized(player);
|
||||||
return;
|
return;
|
||||||
@@ -62,9 +54,7 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
[Command("fixveh")]
|
[Command("fixveh")]
|
||||||
public void CmdAdminFixveh(Client player)
|
public void CmdAdminFixveh(Client player)
|
||||||
{
|
{
|
||||||
// Alternative: siehe O Chat
|
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER))
|
||||||
int playerAdminLevel = 1;
|
|
||||||
if (playerAdminLevel < /* Benötigtes Level */ 1)
|
|
||||||
{
|
{
|
||||||
ChatService.NotAuthorized(player);
|
ChatService.NotAuthorized(player);
|
||||||
return;
|
return;
|
||||||
@@ -95,12 +85,28 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* TODO: Checken, ob das Fahrzeug in einem System genutzt wird (Fraktions-Autos / Spieler-Auto)
|
||||||
* TODO: Checken, ob das Fahrzeug in einem System genutzt wird (Fraktions-Autos / Spieler-Auto)
|
* Wenn Ja: Abbrechen und mitteilen, dass man den System-spezifischen Befehl zu nutzen hat */
|
||||||
* Wenn Ja: Abbrechen und mitteilen, dass man den System-spezifischen Befehl zu nutzen hat
|
|
||||||
*/
|
|
||||||
|
|
||||||
player.Vehicle.Delete();
|
player.Vehicle.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("goto", "~m~Benutzung:~s~ /goto [Name]")]
|
||||||
|
public void CmdAdminGoto(Client player, string name)
|
||||||
|
{
|
||||||
|
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER))
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Client target = ClientService.GetClientByName(name);
|
||||||
|
|
||||||
|
if(target == null)
|
||||||
|
{
|
||||||
|
ChatService.PlayerNotFound(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using reallife_gamemode.Server.Util;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
@@ -22,5 +23,8 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
[EmailAddress]
|
[EmailAddress]
|
||||||
[StringLength(64)]
|
[StringLength(64)]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
public AdminLevel AdminLevel { get; set; }
|
||||||
|
|
||||||
|
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,10 @@ namespace reallife_gamemode.Server.Services
|
|||||||
{
|
{
|
||||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
|
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void PlayerNotFound(Client player)
|
||||||
|
{
|
||||||
|
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
Server/Services/ClientService.cs
Normal file
36
Server/Services/ClientService.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Services
|
||||||
|
{
|
||||||
|
class ClientService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Client Service (ClientService.cs)
|
||||||
|
* @author hydrant
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Client GetClientByName(string name)
|
||||||
|
{
|
||||||
|
/* Funktionsaufbau: Prüft erst, ob ein Spieler mit exakt diesem Namen online ist
|
||||||
|
* Wenn Ja: Wird dieser zurückgegeben
|
||||||
|
* Wenn Nein: Wird der erste Spieler zurückgegeben, dessen Namen mit dem eingegebenen Parameter übereinstimmt
|
||||||
|
* Gibt "null" zurück, falls kein Client gefunden wurde
|
||||||
|
*/
|
||||||
|
Client toReturn = null;
|
||||||
|
|
||||||
|
List<Client> playerList = NAPI.Pools.GetAllPlayers();
|
||||||
|
toReturn = playerList.Find(p => p.Name == name);
|
||||||
|
|
||||||
|
if(toReturn == null)
|
||||||
|
{
|
||||||
|
toReturn = playerList.Find(p => p.Name.StartsWith(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user