Added dynamic whitelist

This commit is contained in:
hydrant
2018-12-02 16:54:29 +01:00
parent a9d6cef952
commit 4c6fcf8a11
4 changed files with 89 additions and 22 deletions

View File

@@ -21,37 +21,36 @@ namespace reallife_gamemode.Server.Events
{
class Connect : Script
{
private List<string> whitelistNames = new List<string>()
{
"VegasZ",
"datgame_",
"xSprite",
"xPrike",
"xNccPlay",
};
[ServerEvent(Event.PlayerConnected)]
public void OnPlayerConnected(Client player)
{
if(!whitelistNames.Any(x => x == player.SocialClubName))
{
player.TriggerEvent("disableLogin");
player.Kick();
string msg2 = "~m~*** " + player.Name + "[" + player.SocialClubName + "] (" + player.Address + ") hat versucht, sich einzuloggen, steht aber nicht auf der Whitelist.";
ChatService.BroadcastAdmin(msg2, AdminLevel.ADMIN);
return;
}
player.SetData("isLoggedIn", false);
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 + ")";
NAPI.Util.ConsoleOutput(player.SocialClubName);
using (var dbContext = new DatabaseContext())
{
if(!dbContext.WhitelistEntries.Any(w => w.SocialClubName.ToLower() == player.SocialClubName.ToLower()))
{
player.TriggerEvent("disableLogin");
string msg2 = "~m~*** " + player.Name + "[" + player.SocialClubName + "] (" + player.Address + ") hat versucht, sich einzuloggen, steht aber nicht auf der Whitelist.";
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;
}
}
string msg = "~m~*** " + player.Name + " [" + player.SocialClubName + "] [ID:" + player.Handle.Value + "] (" + player.Address + ")";
ChatService.BroadcastAdmin(msg, AdminLevel.ADMIN);
}