Add /unban Command

This commit is contained in:
VegaZ
2018-09-26 21:27:47 +02:00
parent b5bdb6f123
commit 6bea1700a0
2 changed files with 29 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ namespace reallife_gamemode.Server.Extensions
{
public static User GetUser(this Client client)
{
using(DatabaseContext dbContext = new DatabaseContext())
using (DatabaseContext dbContext = new DatabaseContext())
{
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
}
@@ -38,7 +38,7 @@ namespace reallife_gamemode.Server.Extensions
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};
user = new Ban { UserId = GetUser(target).Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
//TODO user.Kick();
mins--;
}
@@ -57,5 +57,16 @@ namespace reallife_gamemode.Server.Extensions
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().BanId);
unbanUser.Bans.Remove(targetUser);
unbanUser.SaveChanges();
}
admin.SendChatMessage(target.Name + " wurde entbannt.");
//TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt.
}
}
}