Cleand up code, fixed unban
This commit is contained in:
@@ -9,7 +9,9 @@ mp.events.add('saveBlip', () => {
|
||||
|
||||
saveBrowser = mp.browsers.new('package://Save/save.html');
|
||||
mp.gui.chat.activate(false);
|
||||
mp.gui.cursor.show(true, true);
|
||||
setTimeout(() => {
|
||||
mp.gui.cursor.visible = true
|
||||
}, 500);
|
||||
});
|
||||
|
||||
mp.events.add('saveData', (blipSprite, blipName, blipScale, blipColor, blipAlpha, blipDrawDistance, blipShortRange, blipRotation, blipDimension) => {
|
||||
|
||||
@@ -27,11 +27,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
|
||||
public void CmdAdminO(Client player, string message)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -45,11 +40,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("veh", "~m~Benutzung: ~s~/veh [Fahrzeug] (Farbe 1) (Farbe 2)")]
|
||||
public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -70,11 +60,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("fv")]
|
||||
public void CmdAdminFixveh(Client player)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -93,11 +78,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("vdestroy")]
|
||||
public void CmdAdminDelveh(Client player)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -119,11 +99,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("to", "~m~Benutzung: ~s~/to [Name]")]
|
||||
public void CmdAdminGoto(Client player, string name)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -144,11 +119,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("position")]
|
||||
public void CmdAdminShowPos(Client player)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -161,11 +131,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("gotox", "~m~Benutzung: ~s~/gotox [X] [Y] [Z]")]
|
||||
public void CmdAdminGotoxyz(Client player, float x, float y, float z)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -178,11 +143,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("gh", "~m~Benutzung: ~s~/gh [Name]")]
|
||||
public void CmdAdminGethere(Client player, string name)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -204,11 +164,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("ipl", "~m~Benutzung: ~s~/ipl [Load / Remove] [Name]")]
|
||||
public void CmdAdminIpl(Client player, string option, string name)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -236,11 +191,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")]
|
||||
public void CmdAdminGiveweapon(Client player, string name, string weapon, int ammo)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -276,11 +226,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("sethp", "~m~Benutzung: ~s~/sethp [Spieler] (Leben)")]
|
||||
public void CmdAdminSetHp(Client player, string name, int hp = 100)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -302,11 +247,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("setarmor", "~m~Benutzung: ~s~/setarmor [Spieler] (Armor)")]
|
||||
public void CmdAdminSetArmor(Client player, string name, int armor = 100)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -328,11 +268,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("setskin", "~m~Benutzung: ~s~/setskin [Spieler] [Skin]")]
|
||||
public void CmdAdminSetSkin(Client player, string name, string Skin)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -355,11 +290,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("vcolor", "~m~Benutzung: ~s~/vcolor [Farb-ID1] [Farb-ID2]")]
|
||||
public void CmdAdminColor(Client player, int color1, int color2)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -380,27 +310,25 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("aw", "~m~Benutzung: ~s~/aw [Spieler] [Nachricht]")]
|
||||
public void CmdAdminMsg(Client player, string name, string msg)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
if (target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == player)
|
||||
{
|
||||
ChatService.ErrorMsg(player);
|
||||
return;
|
||||
}
|
||||
|
||||
target.SendChatMessage("~y~PM von " + player.Name + ": " + msg + " ");
|
||||
player.SendChatMessage("~y~PM an " + target.Name + ": " + msg + " ");
|
||||
}
|
||||
@@ -408,11 +336,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("takeweapon", "~m~Benutzung: ~s~/takeweapon [Spieler]")]
|
||||
public void CmdAdminTakeWeapon(Client player, string name)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -432,11 +355,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("rsethp", "~m~Benutzung: ~s~/rsethp [Radius] (Leben)")]
|
||||
public void CmdAdminRangeSetHP(Client player, float radius, int hp = 100)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -455,11 +373,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("rsetarmor", "~m~Benutzung: ~s~/rsetarmor [Radius] (Armor)")]
|
||||
public void CmdAdminRangeSetArmor(Client player, float radius, int Armor = 100)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -478,11 +391,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("time", "~m~Benutzung: ~s~/time [Stunde] (Minuten) (Sekunden)")]
|
||||
public void CmdAdminSetTime(Client player, int hour, int min = 0, int sec = 0)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -496,24 +404,23 @@ namespace reallife_gamemode.Server.Commands
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
[Command("val")]
|
||||
public void Val(Client player)
|
||||
{
|
||||
// TODO: Remove on release
|
||||
NAPI.Chat.SendChatMessageToAll("Value of " + player.Name + ": " + player.Handle.Value);
|
||||
}
|
||||
|
||||
[Command("rgiveweapon", "~m~Benutzung: ~s~/rgiveweapon [Radius] [Waffe] [Munition]")]
|
||||
public void CmdAdminRangeGiveWeapon(Client player, float radius, string weapon, int munition)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
WeaponHash wHash = NAPI.Util.WeaponNameToModel(weapon);
|
||||
|
||||
if (wHash == default(WeaponHash))
|
||||
@@ -575,8 +482,8 @@ namespace reallife_gamemode.Server.Commands
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||
return;
|
||||
}
|
||||
|
||||
User u = dbContext.Users.SingleOrDefault(x => x.Name == target.Name);
|
||||
|
||||
User u = target.GetUser(dbContext);
|
||||
|
||||
if (faction != 0)
|
||||
{
|
||||
@@ -627,7 +534,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
User u = dbContext.Users.SingleOrDefault(x => x.Name == target.Name);
|
||||
User u = target.GetUser(dbContext);
|
||||
|
||||
u.FactionId = f.Id;
|
||||
u.FactionRankId = dbContext.FactionRanks.
|
||||
@@ -645,22 +552,17 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle")]
|
||||
public void CmdAdminSave(Client player, string typ)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
switch (typ)
|
||||
switch (typ.ToLower())
|
||||
{
|
||||
case "Blip":
|
||||
case "blip":
|
||||
player.TriggerEvent("saveBlip");
|
||||
break;
|
||||
case "Vehicle":
|
||||
case "vehicle":
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
Vehicle vehicle = player.Vehicle;
|
||||
@@ -675,35 +577,74 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("ban", "~m~Benutzung: ~s~/ban [User] [Zeit in Minuten(0 für Permanent)] [Grund] ", GreedyArg = true)]
|
||||
public void CmdAdminBan(Client admin, string user, int mins, string reason)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(admin) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(admin);
|
||||
return;
|
||||
}
|
||||
if (!admin.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(admin);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(user);
|
||||
ClientExtension.BanPlayer(admin, target, reason, mins);
|
||||
|
||||
if(target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(admin);
|
||||
return;
|
||||
}
|
||||
|
||||
target.GetUser().BanPlayer(admin, reason, mins);
|
||||
}
|
||||
|
||||
[Command("unban", "~m~Benutzung: ~s~/unban [User] ", GreedyArg = true)]
|
||||
public void CmdAdminUnban(Client admin, string user)
|
||||
[Command("unban", "~m~Benutzung: ~s~/unban [Name] ", GreedyArg = true)]
|
||||
public void CmdAdminUnban(Client admin, string userName)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(admin) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(admin);
|
||||
return;
|
||||
}
|
||||
if (!admin.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(admin);
|
||||
return;
|
||||
}
|
||||
Client target = ClientService.GetClientByName(user);
|
||||
ClientExtension.UnbanPlayer(admin, target);
|
||||
|
||||
User user;
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
user = dbContext.Users.FirstOrDefault(u => u.Name == userName);
|
||||
if(user == null)
|
||||
{
|
||||
admin.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.BanId == null)
|
||||
{
|
||||
admin.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht gebannt.");
|
||||
return;
|
||||
}
|
||||
|
||||
Ban ban = dbContext.Bans.FirstOrDefault(b => b.Id == user.BanId);
|
||||
if(ban == null)
|
||||
{
|
||||
admin.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht gebannt.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ban.Applied == ban.UntilDateTime)
|
||||
{
|
||||
user.UnbanPlayer(admin);
|
||||
}
|
||||
else
|
||||
{
|
||||
int currentTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
if(ban.UntilDateTime < currentTimestamp)
|
||||
{
|
||||
admin.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist nicht gebannt.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
user.UnbanPlayer(admin);
|
||||
}
|
||||
|
||||
string message = "~y~INFO: ~s~Der Spieler ~y~" + user.Name + " ~s~wurde von ~y~" + admin.Name + " ~s~entbannt.";
|
||||
ChatService.BroadcastAdmin(message, AdminLevel.ADMIN);
|
||||
}
|
||||
|
||||
[Command("managefactionranks", "~m~Benutzung: ~s~/managefactionranks [Fraktions-ID]")]
|
||||
@@ -741,6 +682,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
FactionId = f.Id,
|
||||
Ranks = rankList
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(helper, Formatting.None);
|
||||
Console.WriteLine(json);
|
||||
player.TriggerEvent("manageFactionRanks", json);
|
||||
@@ -752,11 +694,6 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("own")]
|
||||
public void CmdAdminOwn(Client player)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -766,9 +703,9 @@ namespace reallife_gamemode.Server.Commands
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
Vehicle playerVehicle = player.Vehicle;
|
||||
using (var saveVehicle = new Model.DatabaseContext())
|
||||
using (var saveVehicle = new DatabaseContext())
|
||||
{
|
||||
var dataSet = new Entities.UserVehicle
|
||||
var dataSet = new UserVehicle
|
||||
{
|
||||
UserId = player.GetUser().Id,
|
||||
Model = (VehicleHash) playerVehicle.Model,
|
||||
@@ -841,6 +778,22 @@ namespace reallife_gamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
foreach(string w in Enum.GetNames(typeof(Weather)))
|
||||
{
|
||||
if (w.ToLower() == weather)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Dieses Wetter existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
Weather weatherBefore = NAPI.World.GetWeather();
|
||||
NAPI.World.SetWeather(weather);
|
||||
Weather weatherAfter = NAPI.World.GetWeather();
|
||||
@@ -870,6 +823,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
target.Freeze(true);
|
||||
}
|
||||
|
||||
@@ -888,6 +842,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
target.Freeze(false);
|
||||
}
|
||||
|
||||
@@ -906,6 +861,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
string targetPlayername = NAPI.Player.GetPlayerName(target);
|
||||
string adminPlayername = NAPI.Player.GetPlayerName(player);
|
||||
|
||||
@@ -1087,28 +1043,33 @@ namespace reallife_gamemode.Server.Commands
|
||||
}
|
||||
player.SendChatMessage("IP von " + NAPI.Player.GetPlayerName(target) + ": " + target.Address);
|
||||
}
|
||||
|
||||
//TEST COMMAND
|
||||
[Command("myvehicles")]
|
||||
public void CmdAdminMyVehicles(Client player)
|
||||
{
|
||||
if (ClientExtension.IsLoggedIn(player) == false)
|
||||
{
|
||||
ChatService.PlayerNotLoggedIn(player);
|
||||
return;
|
||||
}
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
player.SendChatMessage("Deine Fahrzeuge: ");
|
||||
|
||||
int userID = player.GetUser().Id;
|
||||
using (var loadData = new DatabaseContext())
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("myID = " + userID);
|
||||
foreach (Entities.UserVehicle v in loadData.UserVehicles)
|
||||
{
|
||||
if (v.UserId == ClientExtension.GetUser(player).Id)
|
||||
NAPI.Util.ConsoleOutput("Found vehicle: " + v.Model + " | userid = " + v.UserId);
|
||||
if (v.UserId == userID)
|
||||
{
|
||||
player.SendChatMessage("~b~" + NAPI.Vehicle.GetVehicleDisplayName(v.Model));
|
||||
NAPI.Util.ConsoleOutput("Fahrzeug gehört dir (" + v.UserId + " ist " + userID + ")");
|
||||
player.SendChatMessage("~b~" + v.Model);
|
||||
}
|
||||
else
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Fahrzeug gehört nicht dir. (" + v.UserId + " ist nicht " + userID + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionF(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetFaction();
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if(f == null || f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -37,7 +37,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("r", "~m~Benutzung: ~s~/r [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionR(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetFaction();
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if (f == null || !f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
@@ -51,7 +51,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
[Command("d", "~m~Benutzung: ~s~/d [Nachricht]", GreedyArg = true)]
|
||||
public void CmdFactionD(Client player, string message)
|
||||
{
|
||||
Entities.Faction f = player.GetFaction();
|
||||
Entities.Faction f = player.GetUser()?.GetFaction();
|
||||
if (f == null || !f.StateOwned)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
|
||||
@@ -83,6 +83,48 @@ namespace reallife_gamemode.Server.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public void BanPlayer(Client admin, string reason, int mins)
|
||||
{
|
||||
using (var banUserContext = new DatabaseContext())
|
||||
{
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban banUser;
|
||||
|
||||
if (mins == 0)
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
||||
//TODO user.Kick();
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||
//TODO user.Kick();
|
||||
}
|
||||
|
||||
banUserContext.Bans.Add(banUser);
|
||||
banUserContext.SaveChanges();
|
||||
|
||||
var targetUser = banUserContext.Users.FirstOrDefault(u => u.Name == this.Name);
|
||||
targetUser.BanId = banUser.Id;
|
||||
banUserContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnbanPlayer(Client admin)
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Bans.FirstOrDefault(u => u.Id == BanId);
|
||||
unbanUser.Bans.Remove(targetUser);
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
admin.SendChatMessage(this.Name + " wurde entbannt.");
|
||||
//TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt.
|
||||
}
|
||||
|
||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,34 +37,40 @@ namespace reallife_gamemode.Server.Events
|
||||
player.SendChatMessage("~m~*** "+player.Name+"["+player.SocialClubName+"] [ID:"+player.Handle.Value+"] ("+player.Address+")");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("IsPlayerBanned")]
|
||||
public void IsPlayerBanned(Client player)
|
||||
{
|
||||
using (var loginUser = new Model.DatabaseContext())
|
||||
using (var loginUser = new 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 = loginUser.Bans.SingleOrDefault(u => u.Id == user.BanId);
|
||||
if (bannedUser.Applied == bannedUser.UntilDateTime)
|
||||
{
|
||||
|
||||
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;
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
|
||||
if(timeStamp > unixTimestamp)
|
||||
{
|
||||
player.SendChatMessage("!{#FF4040}Du wurdest permanent gebannt! [" + bannedUser.Reason + "]");
|
||||
//player.Kick();
|
||||
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeStamp = bannedUser.UntilDateTime;
|
||||
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
|
||||
//player.Kick();
|
||||
loginUser.Bans.Remove(bannedUser);
|
||||
loginUser.SaveChanges();
|
||||
player.TriggerEvent("showLogin");
|
||||
}
|
||||
|
||||
//player.Kick();
|
||||
}
|
||||
}
|
||||
else player.TriggerEvent("showLogin");
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
NAPI.Util.ConsoleOutput(player.Name + " Timeoutet");
|
||||
}
|
||||
/*
|
||||
|
||||
using (var saveUser = new Model.DatabaseContext())
|
||||
{
|
||||
var user = saveUser.Users.SingleOrDefault(u => u.Name == player.Name);
|
||||
@@ -38,7 +38,7 @@ namespace reallife_gamemode.Server.Events
|
||||
user.PositionY = player.Position.Y;
|
||||
user.PositionZ = player.Position.Z;
|
||||
saveUser.SaveChanges();
|
||||
}*/
|
||||
}
|
||||
player.SetData("isLoggedIn", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,9 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
=======
|
||||
if(context == null)
|
||||
>>>>>>> feature/faction-system
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
@@ -36,68 +34,9 @@ namespace reallife_gamemode.Server.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
public static Faction GetFaction(this Client client, DatabaseContext context = null)
|
||||
public static bool IsLoggedIn(this Client player)
|
||||
{
|
||||
if(context == null)
|
||||
{
|
||||
using(context = new DatabaseContext())
|
||||
{
|
||||
User u = client.GetUser();
|
||||
if (u == null) return null;
|
||||
return u.GetFaction();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
User u = client.GetUser();
|
||||
if (u == null) return null;
|
||||
return u.GetFaction();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
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.
|
||||
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -26,8 +27,7 @@ namespace reallife_gamemode.Server.Services
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
public static void PlayerNotLoggedIn(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Du bist nicht eingeloggt.");
|
||||
@@ -35,20 +35,18 @@ namespace reallife_gamemode.Server.Services
|
||||
public static void ErrorMsg(Client player)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Die Aktion wurde nicht ausgeführt.");
|
||||
=======
|
||||
}
|
||||
|
||||
public static void BroadcastFaction(string message, List<Faction> factions)
|
||||
{
|
||||
using (var dbCon = new DatabaseContext())
|
||||
foreach (Client c in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
foreach (Client c in NAPI.Pools.GetAllPlayers())
|
||||
Faction f = c.GetUser()?.GetFaction();
|
||||
if (f != null)
|
||||
{
|
||||
Faction f = c.GetFaction();
|
||||
if (f != null)
|
||||
if (factions.Find(fT => fT.Id == f.Id) != null)
|
||||
{
|
||||
if (factions.Find(fT => fT.Id == f.Id) != null)
|
||||
{
|
||||
c.SendChatMessage(message);
|
||||
}
|
||||
c.SendChatMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +55,17 @@ namespace reallife_gamemode.Server.Services
|
||||
public static void BroadcastFaction(string message, Faction faction)
|
||||
{
|
||||
BroadcastFaction(message, new List<Faction> { faction });
|
||||
>>>>>>> feature/faction-system
|
||||
}
|
||||
|
||||
public static void BroadcastAdmin(string message, AdminLevel minLevel)
|
||||
{
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
||||
{
|
||||
if(p.GetUser()?.IsAdmin(minLevel) ?? false)
|
||||
{
|
||||
p.SendChatMessage(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user