Change login-process for Ban-System
This commit is contained in:
@@ -25,8 +25,8 @@ namespace reallife_gamemode.Server.Entities
|
||||
|
||||
public string Reason { get; set; }
|
||||
public string BannedBy { get; set; }
|
||||
[Timestamp]
|
||||
public byte[] Applied { get; set; }
|
||||
public byte[] UntilDateTime { get; set; }
|
||||
|
||||
public int Applied { get; set; }
|
||||
public int UntilDateTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,36 @@ namespace reallife_gamemode.Server.Events
|
||||
player.Position = new Vector3(-1883.736, -781.4911, -10);
|
||||
player.FreezePosition = true;
|
||||
}
|
||||
|
||||
[RemoteEvent("IsPlayerBanned")]
|
||||
public void IsPlayerBanned(Client player)
|
||||
{
|
||||
using (var loginUser = new Model.DatabaseContext())
|
||||
{
|
||||
var user = loginUser.Users.SingleOrDefault(b => b.Name == player.Name);
|
||||
if (user.BanId != null)
|
||||
{
|
||||
using (var banUser = new DatabaseContext())
|
||||
{
|
||||
|
||||
var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
var bannedUser = banUser.Bans.SingleOrDefault(u => u.Id == user.BanId);
|
||||
if (bannedUser.Applied == bannedUser.UntilDateTime)
|
||||
{
|
||||
player.SendChatMessage("!{#FF4040}Du wurdest permanent gebannt! [" + bannedUser.Reason + "]");
|
||||
//player.Kick();
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeStamp = bannedUser.UntilDateTime;
|
||||
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
|
||||
//player.Kick();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else player.TriggerEvent("showLogin");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
@@ -36,7 +38,7 @@ namespace reallife_gamemode.Server.Events
|
||||
if (user.Password != NAPI.Util.GetHashSha256(password))
|
||||
{
|
||||
player.TriggerEvent("loginFail", "Passwort inkorrekt!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("loginSuccess");
|
||||
|
||||
@@ -31,23 +31,30 @@ namespace reallife_gamemode.Server.Extensions
|
||||
|
||||
public static void BanPlayer(Client admin, Client target, string reason, int mins)
|
||||
{
|
||||
if(mins == 0)
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + target.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
//user.Kick();
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + target.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
//user.Kick();
|
||||
}
|
||||
|
||||
using (var banUser = new DatabaseContext())
|
||||
{
|
||||
var user = new Ban { UserId = GetUser(target).Id, Reason = reason, BannedBy = admin.Name, UntilDateTime = BitConverter.GetBytes(DateTime.Now.Ticks - mins)};
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban user;
|
||||
if (mins == 0)
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + target.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
user = new Ban { UserId = GetUser(target).Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp};
|
||||
//TODO user.Kick();
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + target.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
user = new Ban { UserId = GetUser(target).Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||
//TODO user.Kick();
|
||||
}
|
||||
|
||||
banUser.Bans.Add(user);
|
||||
banUser.SaveChanges();
|
||||
|
||||
var targetUser = banUser.Users.FirstOrDefault(u => u.Name == target.Name);
|
||||
targetUser.BanId = user.Id;
|
||||
banUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user