62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
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);
|
|
}
|
|
}
|
|
|
|
public static bool IsLoggedIn(Client player)
|
|
{
|
|
return player.GetData("isLoggedIn");
|
|
}
|
|
|
|
public static void BanPlayer(Client admin, Client target, string reason, int mins)
|
|
{
|
|
using (var banUser = new DatabaseContext())
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|