Added dynamic whitelist
This commit is contained in:
@@ -91,5 +91,8 @@ namespace reallife_gamemode.Model
|
|||||||
// Server Vehicles
|
// Server Vehicles
|
||||||
public DbSet<Server.Entities.ServerVehicle> ServerVehicles { get; set; }
|
public DbSet<Server.Entities.ServerVehicle> ServerVehicles { get; set; }
|
||||||
public DbSet<Server.Entities.VehicleMod> VehicleMods { get; set; }
|
public DbSet<Server.Entities.VehicleMod> VehicleMods { get; set; }
|
||||||
|
|
||||||
|
// Whitelist
|
||||||
|
public DbSet<Server.Entities.Whitelist> WhitelistEntries { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1883,6 +1883,55 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
|
|
||||||
BankManager.SetMoney(player, business, amount, "Admin");
|
BankManager.SetMoney(player, business, amount, "Admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("whitelist", "~m~Benutzung: ~s~/whitelist [Add / Remove] [Socialclub Name]")]
|
||||||
|
public void CmdAdminWhitelist(Client player, string option, string scName)
|
||||||
|
{
|
||||||
|
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
option = option.ToLower();
|
||||||
|
|
||||||
|
if(option != "add" && option != "remove")
|
||||||
|
{
|
||||||
|
player.SendChatMessage("~m~Benutzung: ~s~/whitelist [Add / Remove] [Socialclub Name]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using(var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
if(option == "add")
|
||||||
|
{
|
||||||
|
if (dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == scName.ToLower()))
|
||||||
|
{
|
||||||
|
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Name ist schon auf der Whitelist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Whitelist whitelist = new Whitelist { SocialClubName = scName.ToLower() };
|
||||||
|
dbContext.WhitelistEntries.Add(whitelist);
|
||||||
|
|
||||||
|
player.SendChatMessage("~b~[ADMIN]~s~ ~y~" + scName + "~s~ wurde erfolgreich zur Whitelist hinzugefügt.");
|
||||||
|
}
|
||||||
|
else if(option == "remove")
|
||||||
|
{
|
||||||
|
if (!dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == scName.ToLower()))
|
||||||
|
{
|
||||||
|
player.SendChatMessage("~r~[FEHLER]~s~ Dieser Name ist nicht auf der Whitelist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Whitelist whitelist = dbContext.WhitelistEntries.FirstOrDefault(w => w.SocialClubName.ToLower() == scName.ToLower());
|
||||||
|
dbContext.WhitelistEntries.Remove(whitelist);
|
||||||
|
|
||||||
|
player.SendChatMessage("~b~[ADMIN]~s~ ~y~" + scName + "~s~ wurde erfolgreich aus der Whitelist entfernt.");
|
||||||
|
}
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ALevel1338
|
#region ALevel1338
|
||||||
|
|||||||
16
Server/Entities/Whitelist.cs
Normal file
16
Server/Entities/Whitelist.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Entities
|
||||||
|
{
|
||||||
|
public class Whitelist
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string SocialClubName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,37 +21,36 @@ namespace reallife_gamemode.Server.Events
|
|||||||
{
|
{
|
||||||
class Connect : Script
|
class Connect : Script
|
||||||
{
|
{
|
||||||
private List<string> whitelistNames = new List<string>()
|
|
||||||
{
|
|
||||||
"VegasZ",
|
|
||||||
"datgame_",
|
|
||||||
"xSprite",
|
|
||||||
"xPrike",
|
|
||||||
"xNccPlay",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
[ServerEvent(Event.PlayerConnected)]
|
[ServerEvent(Event.PlayerConnected)]
|
||||||
public void OnPlayerConnected(Client player)
|
public void OnPlayerConnected(Client player)
|
||||||
{
|
{
|
||||||
if(!whitelistNames.Any(x => x == player.SocialClubName))
|
player.SetData("isLoggedIn", false);
|
||||||
|
player.Position = new Vector3(-1883.736, -781.4911, -10);
|
||||||
|
player.FreezePosition = true;
|
||||||
|
|
||||||
|
NAPI.Util.ConsoleOutput(player.SocialClubName);
|
||||||
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
if(!dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == player.SocialClubName.ToLower()))
|
||||||
{
|
{
|
||||||
player.TriggerEvent("disableLogin");
|
player.TriggerEvent("disableLogin");
|
||||||
player.Kick();
|
|
||||||
|
|
||||||
string msg2 = "~m~*** " + player.Name + "[" + player.SocialClubName + "] (" + player.Address + ") hat versucht, sich einzuloggen, steht aber nicht auf der Whitelist.";
|
string msg2 = "~m~*** " + player.Name + "[" + player.SocialClubName + "] (" + player.Address + ") hat versucht, sich einzuloggen, steht aber nicht auf der Whitelist.";
|
||||||
ChatService.BroadcastAdmin(msg2, AdminLevel.ADMIN);
|
ChatService.BroadcastAdmin(msg2, AdminLevel.ADMIN);
|
||||||
|
|
||||||
|
NAPI.Util.ConsoleOutput(player.Name + " tried to join without whitelist entry");
|
||||||
|
|
||||||
|
player.SendChatMessage("~m~Du stehst nicht auf der Whitelist");
|
||||||
|
|
||||||
|
player.Kick();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
player.SetData("isLoggedIn", false);
|
string msg = "~m~*** " + player.Name + " [" + player.SocialClubName + "] [ID:" + player.Handle.Value + "] (" + player.Address + ")";
|
||||||
player.Position = new Vector3(-1883.736, -781.4911, -10);
|
|
||||||
player.FreezePosition = true;
|
|
||||||
string name = player.Name;
|
|
||||||
List<Client> playerlist = NAPI.Pools.GetAllPlayers();
|
|
||||||
|
|
||||||
string msg = "~m~*** " + player.Name + "[" + player.SocialClubName + "] [ID:" + player.Handle.Value + "] (" + player.Address + ")";
|
|
||||||
ChatService.BroadcastAdmin(msg, AdminLevel.ADMIN);
|
ChatService.BroadcastAdmin(msg, AdminLevel.ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user