Merge branch 'develop' of ssh://development.life-of-german.org:451/log-gtav/reallife-gamemode into develop
This commit is contained in:
@@ -2,15 +2,202 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
|
||||
namespace reallife_gamemode.Server.Command
|
||||
/**
|
||||
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Commands
|
||||
{
|
||||
public class Admin : Script
|
||||
{
|
||||
[Command("o")]
|
||||
public void sendOChat(Client player, string message)
|
||||
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
|
||||
public void CmdAdminO(Client player, string message)
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("~r~" + player.Name + " sagt:~w~ " + message);
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
string publicMessage = "~b~(( " + player.Name + ": " + message + " ))";
|
||||
NAPI.Chat.SendChatMessageToAll(publicMessage);
|
||||
}
|
||||
|
||||
[Command("veh", "~m~Benutzung: ~s~/veh [Fahrzeug] (Farbe 1) (Farbe 2)")]
|
||||
public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
Vehicle v = NAPI.Vehicle.CreateVehicle(hash, player.Position, player.Rotation.Z, color1, color2);
|
||||
|
||||
player.SetIntoVehicle(v.Handle, -1);
|
||||
}
|
||||
|
||||
[Command("fixveh")]
|
||||
public void CmdAdminFixveh(Client player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.IsInVehicle) // Man darf keine Autos erstellen, wenn man selbst in einem sitzt (verhindert Bugs)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du sitzt momentan nicht in einem Fahrzeug.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Vehicle.Repair();
|
||||
}
|
||||
|
||||
[Command("delveh")]
|
||||
public void CmdAdminDelveh(Client player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.IsInVehicle) // Man darf keine Autos erstellen, wenn man selbst in einem sitzt (verhindert Bugs)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du sitzt momentan nicht in einem Fahrzeug.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
||||
player.Vehicle.Delete();
|
||||
}
|
||||
|
||||
[Command("goto", "~m~Benutzung: ~s~/goto [Name]")]
|
||||
public void CmdAdminGoto(Client player, string name)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
|
||||
if(target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.Position = target.Position;
|
||||
}
|
||||
|
||||
[Command("gotoxyz", "~m~Benutzung: ~s~/gotoxyz [X] [Y] [Z]")]
|
||||
public void CmdAdminGotoxyz(Client player, float x, float y, float z)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.Position = new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
[Command("gethere", "~m~Benutzung: ~s~/goto [Name]")]
|
||||
public void CmdAdminGethere(Client player, string name)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
target.Position = player.Position;
|
||||
}
|
||||
|
||||
[Command("ipl", "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]")]
|
||||
public void CmdAdminIpl(Client player, string option, string name)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
option = option.ToLower();
|
||||
|
||||
if(option == "load")
|
||||
{
|
||||
NAPI.World.RequestIpl(name);
|
||||
player.SendChatMessage("~g~Das IPL ~s~" + name + " ~g~wurde erfolgreich geladen");
|
||||
}
|
||||
else if(option == "remove")
|
||||
{
|
||||
NAPI.World.RemoveIpl(name);
|
||||
player.SendChatMessage("~g~Das IPL ~s~" + name + " ~g~wurde erfolgreich entladen");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendChatMessage("~m~Benutzung: ~s~/ipl [Load / Remove] [Name]");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")]
|
||||
public void CmdAdminGiveweapon(Client player, string name, string weapon, int ammo)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ammo <= 0)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Es muss mindestens 1 Munition vergeben werden.");
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
if (target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(target);
|
||||
return;
|
||||
}
|
||||
|
||||
WeaponHash wHash = NAPI.Util.WeaponNameToModel(weapon);
|
||||
|
||||
if(wHash == default(WeaponHash))
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Waffe existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
target.GiveWeapon(wHash, ammo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class Character
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public byte Gender { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
using System;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Entities User (User.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Entities
|
||||
{
|
||||
public class User
|
||||
@@ -22,5 +29,8 @@ namespace reallife_gamemode.Server.Entities
|
||||
[EmailAddress]
|
||||
[StringLength(64)]
|
||||
public string Email { get; set; }
|
||||
public AdminLevel AdminLevel { get; set; }
|
||||
|
||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ using Microsoft.EntityFrameworkCore;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Connect : Script
|
||||
|
||||
@@ -3,6 +3,12 @@ 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
|
||||
{
|
||||
public class Login : Script
|
||||
|
||||
@@ -6,6 +6,12 @@ using GTANetworkAPI;
|
||||
using GTANetworkMethods;
|
||||
using reallife_gamemode.Model;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Spawn (Spawn.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Event
|
||||
{
|
||||
public class Spawn : Script
|
||||
|
||||
27
Server/Extensions/ClientExtension.cs
Normal file
27
Server/Extensions/ClientExtension.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class ClientExtension
|
||||
{
|
||||
public static User GetUser(this Client client)
|
||||
{
|
||||
using(DatabaseContext dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Server/Managers/.gitkeep
Normal file
10
Server/Managers/.gitkeep
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
class _
|
||||
{
|
||||
}
|
||||
}
|
||||
26
Server/Services/ChatService.cs
Normal file
26
Server/Services/ChatService.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Chat Service (ChatService.cs)
|
||||
* @author hydrant
|
||||
* @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.");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Server/Util/AdminLevel.cs
Normal file
21
Server/Util/AdminLevel.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Admin Levels (AdminLevel.cs)
|
||||
* @author VegaZ, hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Util
|
||||
{
|
||||
public enum AdminLevel : int
|
||||
{
|
||||
|
||||
|
||||
PLAYER,
|
||||
SUPPORTER,
|
||||
ADMIN
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user