Simplified /cleaned some code parts
This commit is contained in:
@@ -19,9 +19,7 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
if(context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
@@ -39,45 +37,5 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
public static void UnbanPlayer(Client admin, Client target)
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Bans.FirstOrDefault(u => u.Id == target.GetUser(unbanUser).BanId);
|
||||
unbanUser.Bans.Remove(targetUser);
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
admin.SendChatMessage(target.Name + " wurde entbannt.");
|
||||
//TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static FactionBankAccount GetFactionBankAccount(this Faction faction, DatabaseContext context = null)
|
||||
{
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static UserBankAccount GetUserBankAccount(this User user, DatabaseContext context = null)
|
||||
{
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
|
||||
@@ -18,10 +18,9 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class VehicleExtension
|
||||
{
|
||||
public static bool IsFactionVehicle(Vehicle vehicle)
|
||||
public static bool IsFactionVehicle(this Vehicle vehicle)
|
||||
{
|
||||
bool containsVehicle = LoadManager.FactionVehicleList.Contains(vehicle);
|
||||
return containsVehicle;
|
||||
return LoadManager.FactionVehicleList.Contains(vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user