Add Header Comments, Add 'null'-Checks on Commands

This commit is contained in:
Lennart Kampshoff
2018-09-19 12:50:43 +02:00
parent cb97b298a6
commit 5fb1127c84
4 changed files with 26 additions and 10 deletions

View File

@@ -19,7 +19,7 @@ namespace reallife_gamemode.Server.Commands
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)] [Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
public void CmdAdminO(Client player, string message) public void CmdAdminO(Client player, string message)
{ {
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER)) if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
return; return;
@@ -32,15 +32,13 @@ namespace reallife_gamemode.Server.Commands
[Command("veh", "~m~Benutzung:~s~ /veh [Fahrzeug] (Farbe 1) (Farbe 2)")] [Command("veh", "~m~Benutzung:~s~ /veh [Fahrzeug] (Farbe 1) (Farbe 2)")]
public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111) public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111)
{ {
// Alternative: siehe O Chat if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
int playerAdminLevel = 1;
if (playerAdminLevel < /* Benötigtes Level */ 1)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
return; return;
} }
if(player.IsInVehicle) // Man darf keine Autos erstellen, wenn man selbst in einem sitzt (verhindert Bugs) if (player.IsInVehicle) // Man darf keine Autos erstellen, wenn man selbst in einem sitzt (verhindert Bugs)
{ {
player.SendChatMessage("~r~[FEHLER]~s~ Du sitzt momentan schon in einem Fahrzeug."); player.SendChatMessage("~r~[FEHLER]~s~ Du sitzt momentan schon in einem Fahrzeug.");
return; return;
@@ -54,7 +52,7 @@ namespace reallife_gamemode.Server.Commands
[Command("fixveh")] [Command("fixveh")]
public void CmdAdminFixveh(Client player) public void CmdAdminFixveh(Client player)
{ {
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER)) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
return; return;
@@ -72,8 +70,7 @@ namespace reallife_gamemode.Server.Commands
[Command("delveh")] [Command("delveh")]
public void CmdAdminDelveh(Client player) public void CmdAdminDelveh(Client player)
{ {
int playerAdminLevel = 1; if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
if (playerAdminLevel < /* Benötigtes Level */ 1)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
return; return;
@@ -94,7 +91,7 @@ namespace reallife_gamemode.Server.Commands
[Command("goto", "~m~Benutzung:~s~ /goto [Name]")] [Command("goto", "~m~Benutzung:~s~ /goto [Name]")]
public void CmdAdminGoto(Client player, string name) public void CmdAdminGoto(Client player, string name)
{ {
if (!player.GetUser().IsAdmin(AdminLevel.SUPPORTER)) if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
return; return;

View File

@@ -3,17 +3,24 @@ using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities; using reallife_gamemode.Server.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace reallife_gamemode.Server.Extensions namespace reallife_gamemode.Server.Extensions
{ {
public static class ClientExtension public static class ClientExtension
{ {
/**
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
* @author VegaZ, hydrant
* @copyright (c) 2008 - 2018 Life of German
*/
public static User GetUser(this Client client) public static User GetUser(this Client client)
{ {
using(DatabaseContext dbContext = new DatabaseContext()) using(DatabaseContext dbContext = new DatabaseContext())
{ {
return dbContext.Users.Find(client.Name); return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
} }
} }
} }

View File

@@ -7,6 +7,12 @@ namespace reallife_gamemode.Server.Services
{ {
class ChatService class ChatService
{ {
/**
* @overview Life of German Reallife - Chat Service (ChatService.cs)
* @author hydrant
* @copyright (c) 2008 - 2018 Life of German
*/
public static void NotAuthorized(Client player) public static void NotAuthorized(Client player)
{ {
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen."); player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");

View File

@@ -6,6 +6,12 @@ namespace reallife_gamemode.Server.Util
{ {
public enum AdminLevel : int public enum AdminLevel : int
{ {
/**
* @overview Life of German Reallife - Admin Levels (AdminLevel.cs)
* @author VegaZ, hydrant
* @copyright (c) 2008 - 2018 Life of German
*/
PLAYER, PLAYER,
SUPPORTER, SUPPORTER,
ADMIN ADMIN