/// <summary> /// Kill a specific player. /// </summary> /// <param name="source"></param> /// <param name="target"></param> private void KillPlayer([FromSource] Player source, int target) { if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Kill") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything") || IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All")) { Player targetPlayer = Players[target]; if (targetPlayer != null) { // Trigger the client event on the target player to make them kill themselves. R.I.P. TriggerClientEvent(player: targetPlayer, eventName: "vMenu:KillMe", args: source.Name); return; } TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "An unknown error occurred. Report it here: vespura.com/vmenu"); } else { BanManager.BanCheater(source); } }
/// <summary> /// Teleport a specific player to another player. /// </summary> /// <param name="source"></param> /// <param name="target"></param> private void SummonPlayer([FromSource] Player source, int target) { if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Summon") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything") || IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All")) { // Trigger the client event on the target player to make them teleport to the source player. Player targetPlayer = new PlayerList()[target]; if (targetPlayer != null) { TriggerClientEvent(player: targetPlayer, eventName: "vMenu:GoToPlayer", args: source.Handle); return; } TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "An unknown error occurred. Report it here: vespura.com/vmenu"); } else { BanManager.BanCheater(source); } }
/// <summary> /// Kick a specific player. /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="kickReason"></param> private void KickPlayer([FromSource] Player source, int target, string kickReason = "You have been kicked from the server.") { if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Kick") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything") || IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All")) { // If the player is allowed to be kicked. Player targetPlayer = Players[target]; if (targetPlayer != null) { if (!IsPlayerAceAllowed(targetPlayer.Handle, "vMenu.DontKickMe")) { TriggerEvent("vMenu:KickSuccessful", source.Name, kickReason, targetPlayer.Name); KickLog($"Player: {source.Name} has kicked: {targetPlayer.Name} for: {kickReason}."); TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: $"The target player (<C>{targetPlayer.Name}</C>) has been kicked."); TriggerEvent("ex_logger:SendLogBot", new { source = int.Parse(source.Handle), target = target, channel = 635764211284180999, content = $"**Wyrzucono z serwera, powod:** {kickReason}", scriptName = "vMenu", functionName = "KickPlayer", }); // Kick the player from the server using the specified reason. DropPlayer(targetPlayer.Handle, kickReason); return; } // Trigger the client event on the source player to let them know that kicking this player is not allowed. TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "Sorry, this player can ~r~not ~w~be kicked."); return; } TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: "An unknown error occurred. Report it here: vespura.com/vmenu"); } else { BanManager.BanCheater(source); } }
/// <summary> /// Kick a specific player. /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="kickReason"></param> private void KickPlayer([FromSource] Player source, int target, string kickReason = "You have been kicked from the server.") { if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Kick") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything") || IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All")) { // If the player is allowed to be kicked. var targetPlayer = new PlayerList()[target]; if (!IsPlayerAceAllowed(targetPlayer.Handle, "vMenu.DontKickMe")) { TriggerEvent("vMenu:KickSuccessful", source.Name, kickReason, targetPlayer.Name); // Kick the player from the server using the specified reason. DropPlayer(targetPlayer.Handle, kickReason); KickLog($"Player: {source.Name} has kicked: {targetPlayer.Name} for: {kickReason}."); return; } // Trigger the client event on the source player to let them know that kicking this player is not allowed. TriggerClientEvent(player: source, eventName: "vMenu:KickCallback", args: "Sorry, this player can ~r~not ~w~be kicked."); } else { BanManager.BanCheater(new PlayerList()[target]); } }
private void ServerCommandHandler(int source, List <object> args, string rawCommand) { if (args != null) { if (args.Count > 0) { if (args[0].ToString().ToLower() == "debug") { DebugMode = !DebugMode; if (source < 1) { Debug.WriteLine($"Debug mode is now set to: {DebugMode}."); } else { Players[source].TriggerEvent("chatMessage", $"aMenu Debug mode is now set to: {DebugMode}."); } return; } else if (args[0].ToString().ToLower() == "unban" && (source < 1)) { if (args.Count() > 1 && !string.IsNullOrEmpty(args[1].ToString())) { var uuid = args[1].ToString().Trim(); var bans = BanManager.GetBanList(); var banRecord = bans.Find(b => { return(b.uuid.ToString() == uuid); }); if (banRecord != null) { BanManager.RemoveBan(banRecord); Debug.WriteLine("Player has been successfully unbanned."); } else { Debug.WriteLine($"Could not find a banned player with the provided uuid '{uuid}'."); } } else { Debug.WriteLine("You did not specify a player to unban, you must enter the FULL playername. Usage: vmenuserver unban \"playername\""); } return; } else if (args[0].ToString().ToLower() == "weather") { if (args.Count < 2 || string.IsNullOrEmpty(args[1].ToString())) { Debug.WriteLine("[aMenu] Invalid command syntax. Use 'vmenuserver weather <weatherType>' instead."); } else { string wtype = args[1].ToString().ToUpper(); if (WeatherTypes.Contains(wtype)) { TriggerEvent("vMenu:UpdateServerWeather", wtype, BlackoutEnabled, DynamicWeatherEnabled); Debug.WriteLine($"[aMenu] Weather is now set to: {wtype}"); } else if (wtype.ToLower() == "dynamic") { if (args.Count == 3 && !string.IsNullOrEmpty(args[2].ToString())) { if ((args[2].ToString().ToLower() ?? $"{DynamicWeatherEnabled}") == "true") { TriggerEvent("vMenu:UpdateServerWeather", CurrentWeather, BlackoutEnabled, true); Debug.WriteLine("[aMenu] Dynamic weather is now turned on."); } else if ((args[2].ToString().ToLower() ?? $"{DynamicWeatherEnabled}") == "false") { TriggerEvent("vMenu:UpdateServerWeather", CurrentWeather, BlackoutEnabled, false); Debug.WriteLine("[aMenu] Dynamic weather is now turned off."); } else { Debug.WriteLine("[aMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[aMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[aMenu] This weather type is not valid!"); } } } else if (args[0].ToString().ToLower() == "time") { if (args.Count == 2) { if (args[1].ToString().ToLower() == "freeze") { TriggerEvent("vMenu:UpdateServerTime", CurrentHours, CurrentMinutes, !FreezeTime); Debug.WriteLine($"Time is now {(FreezeTime ? "frozen" : "not frozen")}."); } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else if (args.Count > 2) { if (int.TryParse(args[1].ToString(), out int hour)) { if (int.TryParse(args[2].ToString(), out int minute)) { if (hour >= 0 && hour < 24) { if (minute >= 0 && minute < 60) { TriggerEvent("vMenu:UpdateServerTime", hour, minute, FreezeTime); Debug.WriteLine($"Time is now {(hour < 10 ? ("0" + hour.ToString()) : hour.ToString())}:{(minute < 10 ? ("0" + minute.ToString()) : minute.ToString())}."); } else { Debug.WriteLine("Invalid minute provided. Value must be between 0 and 59."); } } else { Debug.WriteLine("Invalid hour provided. Value must be between 0 and 23."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else if (args[0].ToString().ToLower() == "ban" && source < 1) // only do this via server console (server id < 1) { if (args.Count > 3) { Player p = null; bool findByServerId = args[1].ToString().ToLower() == "id"; string identifier = args[2].ToString().ToLower(); if (findByServerId) { if (Players.Any(player => player.Handle == identifier)) { p = Players.Single(pl => pl.Handle == identifier); } else { Debug.WriteLine("[aMenu] Could not find this player, make sure they are online."); return; } } else { if (Players.Any(player => player.Name.ToLower() == identifier.ToLower())) { p = Players.Single(pl => pl.Name.ToLower() == identifier.ToLower()); } else { Debug.WriteLine("[aMenu] Could not find this player, make sure they are online."); return; } } string reason = "Banned by staff for:"; args.GetRange(3, args.Count - 3).ForEach(arg => reason += " " + arg); if (p != null) { BanManager.BanRecord ban = new BanManager.BanRecord( BanManager.GetSafePlayerName(p.Name), p.Identifiers.ToList(), new DateTime(3000, 1, 1), reason, "Server Console", new Guid() ); BanManager.AddBan(ban); BanManager.BanLog($"[aMenu] Player {p.Name}^7 has been banned by Server Console for [{reason}]."); TriggerEvent("vMenu:BanSuccessful", JsonConvert.SerializeObject(ban).ToString()); string timeRemaining = BanManager.GetRemainingTimeMessage(ban.bannedUntil.Subtract(DateTime.Now)); p.Drop($"You are banned from this server. Ban time remaining: {timeRemaining}. Banned by: {ban.bannedBy}. Ban reason: {ban.banReason}. Additional information: {vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_default_ban_message_information)}."); } else { Debug.WriteLine("[aMenu] Player not found, could not ban player."); } } else { Debug.WriteLine("[aMenu] Not enough arguments, syntax: ^5vmenuserver ban <id|name> <server id|username> <reason>^7."); } } else if (args[0].ToString().ToLower() == "help") { Debug.WriteLine("Available commands:"); Debug.WriteLine("(server console only): vmenuserver ban <id|name> <server id|username> <reason> (player must be online!)"); Debug.WriteLine("(server console only): vmenuserver unban <uuid>"); Debug.WriteLine("vmenuserver weather <new weather type | dynamic <true | false>>"); Debug.WriteLine("vmenuserver time <freeze|<hour> <minute>>"); Debug.WriteLine("vmenuserver migrate (This copies all banned players in the bans.json file to the new ban system in vMenu v3.3.0, you only need to do this once)"); } else if (args[0].ToString().ToLower() == "migrate" && source < 1) { string file = LoadResourceFile(GetCurrentResourceName(), "bans.json"); if (string.IsNullOrEmpty(file) || file == "[]") { Debug.WriteLine("&1[aMenu] [ERROR]^7 No bans.json file found or it's empty."); return; } Debug.WriteLine("^5[aMenu] [INFO]^7 Importing all ban records from the bans.json file into the new storage system. ^3This may take some time...^7"); var bans = JsonConvert.DeserializeObject <List <BanManager.BanRecord> >(file); bans.ForEach((br) => { var record = new BanManager.BanRecord(br.playerName, br.identifiers, br.bannedUntil, br.banReason, br.bannedBy, Guid.NewGuid()); BanManager.AddBan(record); }); Debug.WriteLine("^2[aMenu] [SUCCESS]^7 All ban records have been imported. You now no longer need the bans.json file."); } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } }
/// <summary> /// Constructor. /// </summary> public MainServer() { #region command RegisterCommand("vmenuserver", new Action <int, List <object>, string>(async(int source, List <object> args, string rawCommand) => { if (args != null) { if (args.Count > 0) { if (args[0].ToString().ToLower() == "debug") { DebugMode = !DebugMode; if (source < 1) { Debug.WriteLine($"Debug mode is now set to: {DebugMode}."); } else { Players[source].TriggerEvent("chatMessage", $"vMenu Debug mode is now set to: {DebugMode}."); } return; } else if (args[0].ToString().ToLower() == "unban" && (source < 1)) { if (args.Count() > 1 && !string.IsNullOrEmpty(args[1].ToString())) { string name = args[1].ToString().Trim(); name = name.Replace("\"", ""); name = BanManager.GetSafePlayerName(name); var bans = await BanManager.GetBanList(); var banRecord = bans.Find(b => { return(b.playerName == name); }); if (banRecord.playerName != null) { if (await BanManager.RemoveBan(banRecord)) { Debug.WriteLine("Player has been successfully unbanned."); } else { Debug.WriteLine("Could not unban the player, are you sure this player is actually banned?"); } } else { Debug.WriteLine($"Could not find a banned player by the name of '{name}'."); } bans = null; } else { Debug.WriteLine("You did not specify a player to unban, you must enter the FULL playername. Usage: vmenuserver unban \"playername\""); } return; } else if (args[0].ToString().ToLower() == "weather") { if (args.Count < 2 || string.IsNullOrEmpty(args[1].ToString())) { Debug.WriteLine("[vMenu] Invalid command syntax. Use 'vmenuserver weather <weatherType>' instead."); } else { string wtype = args[1].ToString().ToUpper(); if (weatherTypes.Contains(wtype)) { TriggerEvent("vMenu:UpdateServerWeather", wtype, blackout, dynamicWeather); Debug.WriteLine($"[vMenu] Weather is now set to: {wtype}"); } else if (wtype.ToLower() == "dynamic") { if (args.Count == 3 && !string.IsNullOrEmpty(args[2].ToString())) { if ((args[2].ToString().ToLower() ?? $"{dynamicWeather}") == "true") { TriggerEvent("vMenu:UpdateServerWeather", currentWeather, blackout, true); Debug.WriteLine("[vMenu] Dynamic weather is now turned on."); } else if ((args[2].ToString().ToLower() ?? $"{dynamicWeather}") == "false") { TriggerEvent("vMenu:UpdateServerWeather", currentWeather, blackout, false); Debug.WriteLine("[vMenu] Dynamic weather is now turned off."); } else { Debug.WriteLine("[vMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[vMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[vMenu] This weather type is not valid!"); } } } else if (args[0].ToString().ToLower() == "time") { if (args.Count == 2) { if (args[1].ToString().ToLower() == "freeze") { TriggerEvent("vMenu:UpdateServerTime", currentHours, currentMinutes, !freezeTime); Debug.WriteLine($"Time is now {(freezeTime ? "frozen" : "not frozen")}."); } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else if (args.Count > 2) { if (int.TryParse(args[1].ToString(), out int hour)) { if (int.TryParse(args[2].ToString(), out int minute)) { if (hour >= 0 && hour < 24) { if (minute >= 0 && minute < 60) { TriggerEvent("vMenu:UpdateServerTime", hour, minute, freezeTime); Debug.WriteLine($"Time is now {(hour < 10 ? ("0" + hour.ToString()) : hour.ToString())}:{(minute < 10 ? ("0" + minute.ToString()) : minute.ToString())}."); } else { Debug.WriteLine("Invalid minute provided. Value must be between 0 and 59."); } } else { Debug.WriteLine("Invalid hour provided. Value must be between 0 and 23."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else if (args[0].ToString().ToLower() == "ban" && source < 1) // only do this via server console (server id < 1) { if (args.Count > 3) { Player p = null; bool findByServerId = args[1].ToString().ToLower() == "id"; string identifier = args[2].ToString().ToLower(); if (findByServerId) { if (Players.Any(player => player.Handle == identifier)) { p = Players.Single(pl => pl.Handle == identifier); } else { Debug.WriteLine("[vMenu] Could not find this player, make sure they are online."); return; } } else { if (Players.Any(player => player.Name.ToLower() == identifier.ToLower())) { p = Players.Single(pl => pl.Name.ToLower() == identifier.ToLower()); } else { Debug.WriteLine("[vMenu] Could not find this player, make sure they are online."); return; } } string reason = "Banned by staff for:"; args.GetRange(3, args.Count - 3).ForEach(arg => reason += " " + arg); if (p != null) { var ban = new BanManager.BanRecord() { bannedBy = "Server Console", bannedUntil = new DateTime(3000, 1, 1), banReason = reason, identifiers = p.Identifiers.ToList(), playerName = BanManager.GetSafePlayerName(p.Name) }; if (await BanManager.AddBan(ban)) { BanManager.BanLog($"[vMenu] Player {p.Name}^7 has been banned by Server Console for [{reason}]."); TriggerEvent("vMenu:BanSuccessful", JsonConvert.SerializeObject(ban).ToString()); string timeRemaining = BanManager.GetRemainingTimeMessage(ban.bannedUntil.Subtract(DateTime.Now)); p.Drop($"You are banned from this server. Ban time remaining: {timeRemaining}. Banned by: {ban.bannedBy}. Ban reason: {ban.banReason}. Additional information: {vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_default_ban_message_information)}."); } else { // ban failed Debug.WriteLine("[vMenu] Banning player failed, reason unknown."); } } else { Debug.WriteLine("[vMenu] Player not found, could not ban player."); } } else { Debug.WriteLine("[vMenu] Not enough arguments, syntax: ^5vmenuserver ban <id|name> <server id|username> <reason>^7."); } } else if (args[0].ToString().ToLower() == "help") { Debug.WriteLine("Available commands:"); Debug.WriteLine("(server console only): vmenuserver ban <id|name> <server id|username> <reason>"); Debug.WriteLine("(server console only): vmenuserver unban <\"player name\">"); Debug.WriteLine("vmenuserver weather <new weather type | dynamic <true | false>>"); Debug.WriteLine("vmenuserver time <freeze|<hour> <minute>>"); } else if (args[0].ToString().ToLower() == "migrate" && source < 1) { BanManager.MigrateBansToDatabase(); } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}. Try ^5vmenuserver help^7 for info."); } }), true); #endregion // name check if (GetCurrentResourceName() != "vMenu") { Exception InvalidNameException = new Exception("\r\n\r\n^1[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. " + "Please change the folder name from '^3" + GetCurrentResourceName() + "^1' to '^2vMenu^1' (case sensitive) instead!\r\n\r\n\r\n^7"); try { throw InvalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { // Add event handlers. EventHandlers.Add("vMenu:SummonPlayer", new Action <Player, int>(SummonPlayer)); EventHandlers.Add("vMenu:KillPlayer", new Action <Player, int>(KillPlayer)); EventHandlers.Add("vMenu:KickPlayer", new Action <Player, int, string>(KickPlayer)); EventHandlers.Add("vMenu:RequestPermissions", new Action <Player>(vMenuShared.PermissionsManager.SetPermissionsForPlayer)); EventHandlers.Add("vMenu:UpdateServerWeather", new Action <string, bool, bool>(UpdateWeather)); EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action <bool>(UpdateWeatherCloudsType)); EventHandlers.Add("vMenu:UpdateServerTime", new Action <int, int, bool>(UpdateTime)); //EventHandlers.Add("vMenu:DisconnectSelf", new Action<Player>(DisconnectSource)); EventHandlers.Add("vMenu:ClearArea", new Action <float, float, float>(ClearAreaNearPos)); EventHandlers.Add("vMenu:GetPlayerIdentifiers", new Action <int, NetworkCallbackDelegate>((TargetPlayer, CallbackFunction) => { List <string> data = new List <string>(); Players[TargetPlayer].Identifiers.ToList().ForEach(e => { if (!e.Contains("ip:")) { data.Add(e); } }); CallbackFunction(JsonConvert.SerializeObject(data)); })); EventHandlers.Add("vMenu:GetOutOfCar", new Action <Player, int, int>(GetOutOfCar)); EventHandlers.Add("vMenu:SendMessageToPlayer", new Action <Player, int, string>(SendPrivateMessage)); EventHandlers.Add("vMenu:PmsDisabled", new Action <Player, string>(NotifySenderThatDmsAreDisabled)); EventHandlers.Add("vMenu:SaveTeleportLocation", new Action <Player, string>(AddTeleportLocation)); // check addons file for errors string addons = LoadResourceFile(GetCurrentResourceName(), "config/addons.json") ?? "{}"; try { JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(addons); // If the above crashes, then the json is invalid and it'll throw warnings in the console. } catch (JsonReaderException ex) { Debug.WriteLine($"\n\n^1[vMenu] [ERROR] ^7Your addons.json file contains a problem! Error details: {ex.Message}\n\n"); } // check if permissions are setup (correctly) if (!GetSettingsBool(Setting.vmenu_use_permissions)) { Debug.WriteLine("^3[vMenu] [WARNING] vMenu is set up to ignore permissions!\nIf you did this on purpose then you can ignore this warning.\nIf you did not set this on purpose, then you must have made a mistake while setting up vMenu.\nPlease read the vMenu documentation (^5https://docs.vespura.com/vmenu^3).\nMost likely you are not executing the permissions.cfg (correctly).^7"); } // manage weather and time sync stuff for first setup. dynamicWeather = GetSettingsBool(Setting.vmenu_enable_dynamic_weather); if (GetSettingsInt(Setting.vmenu_dynamic_weather_timer) != -1) { dynamicWeatherMinutes = GetSettingsInt(Setting.vmenu_dynamic_weather_timer); } string defaultWeather = GetSettingsString(Setting.vmenu_default_weather); if (!string.IsNullOrEmpty(defaultWeather)) { if (weatherTypes.Contains(defaultWeather)) { currentWeather = defaultWeather; } } currentHours = GetSettingsInt(Setting.vmenu_default_time_hour); currentHours = (currentHours >= 0 && currentHours < 24) ? currentHours : 9; currentMinutes = GetSettingsInt(Setting.vmenu_default_time_min); currentMinutes = (currentMinutes >= 0 && currentMinutes < 60) ? currentMinutes : 0; minuteClockSpeed = GetSettingsInt(Setting.vmenu_ingame_minute_duration); minuteClockSpeed = (minuteClockSpeed > 0) ? minuteClockSpeed : 2000; // Start the loops Tick += WeatherLoop; Tick += TimeLoop; if (GetSettingsBool(Setting.vmenu_bans_use_database) && !string.IsNullOrEmpty(LoadResourceFile(GetCurrentResourceName(), "bans.json"))) { Log("^3You have setup vMenu to use the SQLite database for storing banned players, however you also have a bans.json file!\nPlease check your configuration and only use ONE of these methods at a time.\nIf you no longer want to use the bans.json file, feel free to delete it after migrating to the database!^7", LogLevel.warning); } } }
/// <summary> /// Constructor. /// </summary> public MainServer() { RegisterCommand("vmenuserver", new Action <int, List <object>, string>(async(int source, List <object> args, string rawCommand) => { if (args != null) { if (args.Count > 0) { if (args[0].ToString().ToLower() == "debug") { DebugMode = !DebugMode; if (source < 1) { Debug.WriteLine($"Debug mode is now set to: {DebugMode}."); } else { new PlayerList()[source].TriggerEvent("chatMessage", $"vMenu Debug mode is now set to: {DebugMode}."); } return; } else if (args[0].ToString().ToLower() == "unban" && (source < 1)) { if (args.Count() > 1 && !string.IsNullOrEmpty(args[1].ToString())) { string name = args[1].ToString().Trim(); name = name.Replace("\"", ""); name = BanManager.GetSafePlayerName(name); var bans = await BanManager.GetBanList(); var banRecord = bans.Find(b => { return(b.playerName == name); }); if (banRecord.playerName != null) { if (await BanManager.RemoveBan(banRecord)) { Debug.WriteLine("Player has been successfully unbanned."); } else { Debug.WriteLine("Could not unban the player, are you sure this player is actually banned?"); } } else { Debug.WriteLine($"Could not find a banned player by the name of '{name}'."); } bans = null; } else { Debug.WriteLine("You did not specify a player to unban, you must enter the FULL playername. Usage: vmenuserver unban \"playername\""); } return; } } } Debug.WriteLine($"vMenu is currently running version: {Version}."); }), true); if (GetCurrentResourceName() != "vMenu") { Exception InvalidNameException = new Exception("\r\n\r\n^1[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. " + "Please change the folder name from '^3" + GetCurrentResourceName() + "^1' to '^2vMenu^1' (case sensitive) instead!\r\n\r\n\r\n^0"); try { throw InvalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { //InitializeConfig(); // Add event handlers. EventHandlers.Add("vMenu:SummonPlayer", new Action <Player, int>(SummonPlayer)); EventHandlers.Add("vMenu:KillPlayer", new Action <Player, int>(KillPlayer)); EventHandlers.Add("vMenu:KickPlayer", new Action <Player, int, string>(KickPlayer)); EventHandlers.Add("vMenu:RequestPermissions", new Action <Player>(SendPermissionsAsync)); EventHandlers.Add("vMenu:UpdateServerWeather", new Action <string, bool, bool>(UpdateWeather)); EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action <bool>(UpdateWeatherCloudsType)); EventHandlers.Add("vMenu:UpdateServerTime", new Action <int, int, bool>(UpdateTime)); EventHandlers.Add("vMenu:DisconnectSelf", new Action <Player>(DisconnectSource)); string addons = LoadResourceFile(GetCurrentResourceName(), "addons.json") ?? LoadResourceFile(GetCurrentResourceName(), "config/addons.json") ?? "{}"; try { Dictionary <string, List <string> > json = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(addons); if (json.ContainsKey("vehicles")) { foreach (var modelName in json["vehicles"]) { Log("Addon vehicle loaded: " + modelName); addonVehicles.Add(modelName); } } if (json.ContainsKey("peds")) { foreach (var modelName in json["peds"]) { Log("Addon ped loaded:" + modelName); addonPeds.Add(modelName); } } if (json.ContainsKey("weapons")) { foreach (var modelName in json["weapons"]) { Log("Addon weapon loaded:" + modelName); addonWeapons.Add(modelName); } } } catch (JsonReaderException ex) { Debug.WriteLine($"\n\n^1[vMenu] [ERROR] ^0Your addons.json file contains a problem! Error details: {ex.Message}\n\n"); } dynamicWeather = GetSettingsBool(Setting.vmenu_enable_dynamic_weather); if (GetSettingsInt(Setting.vmenu_dynamic_weather_timer) != -1) { dynamicWeatherMinutes = GetSettingsInt(Setting.vmenu_dynamic_weather_timer); //dynamicWeatherTimeLeft = 5 * 12 * dynamicWeatherMinutes; } string defaultWeather = GetSettingsString(Setting.vmenu_default_weather); if (!string.IsNullOrEmpty(defaultWeather)) { if (weatherTypes.Contains(defaultWeather)) { currentWeather = defaultWeather; } } currentHours = GetSettingsInt(Setting.vmenu_default_time_hour); currentHours = (currentHours >= 0 && currentHours < 24) ? currentHours : 9; currentMinutes = GetSettingsInt(Setting.vmenu_default_time_min); currentMinutes = (currentMinutes >= 0 && currentMinutes < 60) ? currentMinutes : 0; minuteClockSpeed = GetSettingsInt(Setting.vmenu_ingame_minute_duration); minuteClockSpeed = (minuteClockSpeed > 0) ? minuteClockSpeed : 2000; Tick += WeatherLoop; Tick += TimeLoop; } }
/// <summary> /// Constructor. /// </summary> public MainServer() { RegisterCommand("vmenuserver", new Action <int, List <object>, string>((int source, List <object> args, string rawCommand) => { if (args != null) { if (args.Count > 0) { if (args[0].ToString().ToLower() == "debug") { DebugMode = !DebugMode; if (source < 1) { Debug.WriteLine($"Debug mode is now set to: {DebugMode}."); } else { new PlayerList()[source].TriggerEvent("chatMessage", $"vMenu Debug mode is now set to: {DebugMode}."); } return; } else if (args[0].ToString().ToLower() == "unban" && (source < 1)) { if (args.Count() > 1 && !string.IsNullOrEmpty(args[1].ToString())) { string name = args[1].ToString().Trim(); name = name.Replace("\"", ""); name = BanManager.GetSafePlayerName(name); var bans = BanManager.GetBanList(); var banRecord = bans.Find(b => { return(b.playerName == name); }); if (banRecord.playerName != null) { if (BanManager.RemoveBan(banRecord)) { Debug.WriteLine("Player has been successfully unbanned."); } else { Debug.WriteLine("Could not unban the player, are you sure this player is actually banned?"); } } else { Debug.WriteLine($"Could not find a banned player by the name of '{name}'."); } bans = null; } else { Debug.WriteLine("You did not specify a player to unban, you must enter the FULL playername. Usage: vmenuserver unban \"playername\""); } return; } } } Debug.WriteLine($"vMenu is currently running version: {Version}."); }), true); if (GetCurrentResourceName() != "vMenu") { Exception InvalidNameException = new Exception("\r\n\r\n[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. " + "Please change the folder name from '" + GetCurrentResourceName() + "' to 'vMenu' (case sensitive) instead!\r\n\r\n\r\n"); try { throw InvalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { // Add event handlers. EventHandlers.Add("vMenu:SummonPlayer", new Action <Player, int>(SummonPlayer)); EventHandlers.Add("vMenu:KillPlayer", new Action <Player, int>(KillPlayer)); EventHandlers.Add("vMenu:KickPlayer", new Action <Player, int, string>(KickPlayer)); EventHandlers.Add("vMenu:RequestPermissions", new Action <Player>(SendPermissionsAsync)); EventHandlers.Add("vMenu:UpdateServerWeather", new Action <string, bool, bool>(UpdateWeather)); EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action <bool>(UpdateWeatherCloudsType)); EventHandlers.Add("vMenu:UpdateServerTime", new Action <int, int, bool>(UpdateTime)); EventHandlers.Add("vMenu:DisconnectSelf", new Action <Player>(DisconnectSource)); string addons = LoadResourceFile(GetCurrentResourceName(), "addons.json") ?? LoadResourceFile(GetCurrentResourceName(), "config/addons.json") ?? "{}"; var json = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(addons); if (json.ContainsKey("vehicles")) { foreach (var modelName in json["vehicles"]) { Log("Addon vehicle loaded: " + modelName); addonVehicles.Add(modelName); } } if (json.ContainsKey("peds")) { foreach (var modelName in json["peds"]) { Log("Addon ped loaded:" + modelName); addonPeds.Add(modelName); } } if (json.ContainsKey("weapons")) { foreach (var modelName in json["weapons"]) { Log("Addon weapon loaded:" + modelName); addonWeapons.Add(modelName); } } if ((GetConvar("vMenuDisableDynamicWeather", "false") ?? "false").ToLower() == "true") { dynamicWeather = false; } Tick += WeatherLoop; Tick += TimeLoop; } }
/// <summary> /// Constructor. /// </summary> public MainServer() { RegisterCommand("vmenuserver", new Action <int, List <object>, string>(async(int source, List <object> args, string rawCommand) => { if (args != null) { if (args.Count > 0) { if (args[0].ToString().ToLower() == "debug") { DebugMode = !DebugMode; if (source < 1) { Debug.WriteLine($"Debug mode is now set to: {DebugMode}."); } else { Players[source].TriggerEvent("chatMessage", $"vMenu Debug mode is now set to: {DebugMode}."); } return; } else if (args[0].ToString().ToLower() == "unban" && (source < 1)) { if (args.Count() > 1 && !string.IsNullOrEmpty(args[1].ToString())) { string name = args[1].ToString().Trim(); name = name.Replace("\"", ""); name = BanManager.GetSafePlayerName(name); var bans = await BanManager.GetBanList(); var banRecord = bans.Find(b => { return(b.playerName == name); }); if (banRecord.playerName != null) { if (await BanManager.RemoveBan(banRecord)) { Debug.WriteLine("Player has been successfully unbanned."); } else { Debug.WriteLine("Could not unban the player, are you sure this player is actually banned?"); } } else { Debug.WriteLine($"Could not find a banned player by the name of '{name}'."); } bans = null; } else { Debug.WriteLine("You did not specify a player to unban, you must enter the FULL playername. Usage: vmenuserver unban \"playername\""); } return; } else if (args[0].ToString().ToLower() == "weather") { if (args.Count < 2 || string.IsNullOrEmpty(args[1].ToString())) { Debug.WriteLine("[vMenu] Invalid command syntax. Use 'vmenuserver weather <weatherType>' instead."); } else { string wtype = args[1].ToString().ToUpper(); if (weatherTypes.Contains(wtype)) { TriggerEvent("UpdateServerWeather", wtype, blackout, dynamicWeather); Debug.WriteLine($"[vMenu] Weather is now set to: {wtype}"); } else if (wtype.ToLower() == "dynamic") { if (args.Count == 3 && !string.IsNullOrEmpty(args[2].ToString())) { if ((args[2].ToString().ToLower() ?? $"{dynamicWeather.ToString()}") == "true") { TriggerEvent("UpdateServerWeather", currentWeather, blackout, true); Debug.WriteLine("[vMenu] Dynamic weather is now turned on."); } else if ((args[2].ToString().ToLower() ?? $"{dynamicWeather.ToString()}") == "false") { TriggerEvent("UpdateServerWeather", currentWeather, blackout, false); Debug.WriteLine("[vMenu] Dynamic weather is now turned off."); } else { Debug.WriteLine("[vMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[vMenu] Invalid command usage. Correct syntax: vmenuserver weather dynamic <true|false>"); } } else { Debug.WriteLine("[vMenu] This weather type is not valid!"); } } } else if (args[0].ToString().ToLower() == "time") { if (args.Count == 2) { if (args[1].ToString().ToLower() == "freeze") { TriggerEvent("vMenu:UpdateServerTime", currentHours, currentMinutes, !freezeTime); Debug.WriteLine($"Time is now {(freezeTime ? "frozen" : "not frozen")}."); } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else if (args.Count > 2) { if (int.TryParse(args[1].ToString(), out int hour)) { if (int.TryParse(args[2].ToString(), out int minute)) { if (hour >= 0 && hour < 24) { if (minute >= 0 && minute < 60) { TriggerEvent("vMenu:UpdateServerTime", hour, minute, freezeTime); Debug.WriteLine($"Time is now {(hour < 10 ? ("0" + hour.ToString()) : hour.ToString())}:{(minute < 10 ? ("0" + minute.ToString()) : minute.ToString())}."); } else { Debug.WriteLine("Invalid minute provided. Value must be between 0 and 59."); } } else { Debug.WriteLine("Invalid hour provided. Value must be between 0 and 23."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine("Invalid syntax. Use: ^5vmenuserver time <freeze|<hour> <minute>>^7 instead."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}."); } } else { Debug.WriteLine($"vMenu is currently running version: {Version}."); } }), true); if (GetCurrentResourceName() != "vMenu") { Exception InvalidNameException = new Exception("\r\n\r\n^1[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. " + "Please change the folder name from '^3" + GetCurrentResourceName() + "^1' to '^2vMenu^1' (case sensitive) instead!\r\n\r\n\r\n^7"); try { throw InvalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { // Add event handlers. EventHandlers.Add("vMenu:SummonPlayer", new Action <Player, int>(SummonPlayer)); EventHandlers.Add("vMenu:KillPlayer", new Action <Player, int>(KillPlayer)); EventHandlers.Add("vMenu:KickPlayer", new Action <Player, int, string>(KickPlayer)); EventHandlers.Add("vMenu:RequestPermissions", new Action <Player>(vMenuShared.PermissionsManager.SetPermissionsForPlayer)); EventHandlers.Add("vMenu:UpdateServerWeather", new Action <string, bool, bool>(UpdateWeather)); EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action <bool>(UpdateWeatherCloudsType)); EventHandlers.Add("vMenu:UpdateServerTime", new Action <int, int, bool>(UpdateTime)); EventHandlers.Add("vMenu:DisconnectSelf", new Action <Player>(DisconnectSource)); EventHandlers.Add("vMenu:ClearArea", new Action <float, float, float>(ClearAreaNearPos)); EventHandlers.Add("vMenu:GetPlayerIdentifiers", new Action <int, NetworkCallbackDelegate>((TargetPlayer, CallbackFunction) => { CallbackFunction(JsonConvert.SerializeObject(Players[TargetPlayer].Identifiers)); })); string addons = LoadResourceFile(GetCurrentResourceName(), "config/addons.json") ?? "{}"; try { JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(addons); // If the above crashes, then the json is invalid and it'll throw warnings in the console. } catch (JsonReaderException ex) { Debug.WriteLine($"\n\n^1[vMenu] [ERROR] ^7Your addons.json file contains a problem! Error details: {ex.Message}\n\n"); } if (!GetSettingsBool(Setting.vmenu_use_permissions)) { Debug.WriteLine("^3[vMenu] [WARNING] vMenu is set up to ignore permissions!\nIf you did this on purpose then you can ignore this warning.\nIf you did not set this on purpose, then you must have made a mistake while setting up vMenu.\nPlease read the vMenu documentation (^5https://docs.vespura.com/vmenu^3).\nMost likely you are not executing the permissions.cfg (correctly).^7"); } dynamicWeather = GetSettingsBool(Setting.vmenu_enable_dynamic_weather); if (GetSettingsInt(Setting.vmenu_dynamic_weather_timer) != -1) { dynamicWeatherMinutes = GetSettingsInt(Setting.vmenu_dynamic_weather_timer); } string defaultWeather = GetSettingsString(Setting.vmenu_default_weather); if (!string.IsNullOrEmpty(defaultWeather)) { if (weatherTypes.Contains(defaultWeather)) { currentWeather = defaultWeather; } } currentHours = GetSettingsInt(Setting.vmenu_default_time_hour); currentHours = (currentHours >= 0 && currentHours < 24) ? currentHours : 9; currentMinutes = GetSettingsInt(Setting.vmenu_default_time_min); currentMinutes = (currentMinutes >= 0 && currentMinutes < 60) ? currentMinutes : 0; minuteClockSpeed = GetSettingsInt(Setting.vmenu_ingame_minute_duration); minuteClockSpeed = (minuteClockSpeed > 0) ? minuteClockSpeed : 2000; Tick += WeatherLoop; Tick += TimeLoop; } }