Add Login Security

This commit is contained in:
VegaZ
2018-09-23 12:16:40 +02:00
parent 1538b41ffb
commit 12486929cf
5 changed files with 46 additions and 3 deletions

View File

@@ -20,6 +20,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 (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -33,6 +34,7 @@ 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)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -53,6 +55,7 @@ namespace reallife_gamemode.Server.Commands
[Command("fixveh")] [Command("fixveh")]
public void CmdAdminFixveh(Client player) public void CmdAdminFixveh(Client player)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -71,6 +74,7 @@ namespace reallife_gamemode.Server.Commands
[Command("delveh")] [Command("delveh")]
public void CmdAdminDelveh(Client player) public void CmdAdminDelveh(Client player)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -92,6 +96,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 (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -112,6 +117,7 @@ namespace reallife_gamemode.Server.Commands
[Command("gotoxyz", "~m~Benutzung: ~s~/gotoxyz [X] [Y] [Z]")] [Command("gotoxyz", "~m~Benutzung: ~s~/gotoxyz [X] [Y] [Z]")]
public void CmdAdminGotoxyz(Client player, float x, float y, float z) public void CmdAdminGotoxyz(Client player, float x, float y, float z)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -124,6 +130,7 @@ namespace reallife_gamemode.Server.Commands
[Command("gethere", "~m~Benutzung: ~s~/goto [Name]")] [Command("gethere", "~m~Benutzung: ~s~/goto [Name]")]
public void CmdAdminGethere(Client player, string name) public void CmdAdminGethere(Client player, string name)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -144,6 +151,7 @@ namespace reallife_gamemode.Server.Commands
[Command("ipl", "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]")] [Command("ipl", "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]")]
public void CmdAdminIpl(Client player, string option, string name) public void CmdAdminIpl(Client player, string option, string name)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -171,6 +179,7 @@ namespace reallife_gamemode.Server.Commands
[Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")] [Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")]
public void CmdAdminGiveweapon(Client player, string name, string weapon, int ammo) public void CmdAdminGiveweapon(Client player, string name, string weapon, int ammo)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{ {
ChatService.NotAuthorized(player); ChatService.NotAuthorized(player);
@@ -204,13 +213,16 @@ namespace reallife_gamemode.Server.Commands
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle")] [Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle")]
public void CmdAdminSave(Client player, string typ) public void CmdAdminSave(Client player, string typ)
{ {
if (ChatService.PlayerLoggedIn(player) == false) return;
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
{
ChatService.NotAuthorized(player);
return;
}
switch (typ) switch (typ)
{ {
case "Blip": case "Blip":
player.TriggerEvent("saveBlip"); player.TriggerEvent("saveBlip");
break;
case "Ped":
break; break;
case "Vehicle": case "Vehicle":
if (player.IsInVehicle) if (player.IsInVehicle)

View File

@@ -20,6 +20,7 @@ namespace reallife_gamemode.Server.Events
[ServerEvent(Event.PlayerConnected)] [ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player) public void OnPlayerConnected(Client player)
{ {
player.SetData("isLoggedIn", false);
player.Position = new Vector3(-1883.736, -781.4911, -10); player.Position = new Vector3(-1883.736, -781.4911, -10);
player.FreezePosition = true; player.FreezePosition = true;
} }

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
/**
* @overview Life of German Reallife - Event Login (Login.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Events
{
class Disconnect : Script
{
[ServerEvent(Event.PlayerDisconnected)]
public void OnPlayerDisconnected(Client player)
{
player.SetData("isLoggedIn", false);
}
}
}

View File

@@ -41,6 +41,7 @@ namespace reallife_gamemode.Server.Events
{ {
player.TriggerEvent("loginSuccess"); player.TriggerEvent("loginSuccess");
NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING); NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING);
player.SetData("isLoggedIn", true);
} }
} }
} }

View File

@@ -22,5 +22,11 @@ namespace reallife_gamemode.Server.Services
{ {
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden."); player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
} }
public static bool PlayerLoggedIn(Client player)
{
if(player.GetData("isLoggedIn") == false) player.SendChatMessage("~r~[FEHLER]~s~ Du bist nicht eingeloggt.");
return player.GetData("isLoggedIn");
}
} }
} }