public static void Run(SvPlayer player) { if (CheckBannedEnabled) { try { if (player.player.admin || string.IsNullOrEmpty(player.connection.IP.Trim())) { return; } foreach (var line in File.ReadAllLines(BansFile)) { if (string.IsNullOrEmpty(line) || !line.StartsWith("# " + player.player.username, StringComparison.CurrentCulture)) { continue; } } Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] {player.player.username} Joined while banned! IP: {player.connection.IP}"); player.svManager.AddBanned(player.player); player.svManager.Disconnect(player.connection, DisconnectTypes.Banned); } catch (Exception ex) { ErrorLogging.Run(ex); } } }
public static void Run(string json, string link, bool enabled) { try { if (!enabled) { return; } if (DebugLevel >= 2) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Creating POST request to {link}"); } var formData = Encoding.UTF8.GetBytes(json); var www = new WWW(link, formData); SvMan.StartCoroutine(WaitForRequest(www)); if (DebugLevel >= 2) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Post request sent!"); } } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static void Run(SvPlayer player) { try { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] [JOIN] {player.player.username} IP is: {player.connection.IP}"); int tries = 0; while (tries < 2) { try { if (!File.ReadAllText(IpListFile).Contains(player.player.username + ": " + player.connection.IP)) { File.AppendAllText(IpListFile, player.player.username + ": " + player.connection.IP + Environment.NewLine); } break; } catch (IOException) { ++tries; } } } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static bool Run(SvPlayer player, string message) { if (MessagesAllowedPerSecond != -1 && MessagesAllowedPerSecond < 50) { if (PlayerList.TryGetValue(player.player.ID, out var currObj)) { if (currObj.MessagesSent >= MessagesAllowedPerSecond) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] {player.player.username} got kicked for spamming! {currObj.MessagesSent}/s (max: {MessagesAllowedPerSecond}) messages sent."); player.svManager.Kick(player.connection); return(true); } PlayerList[player.player.ID].MessagesSent++; if (!currObj.IsCurrentlyAwaiting) { PlayerList[player.player.ID].IsCurrentlyAwaiting = true; Task.Factory.StartNew(async() => { await Task.Delay(TimeBetweenDelay); if (PlayerList.ContainsKey(player.player.ID)) { PlayerList[player.player.ID].MessagesSent = 0; PlayerList[player.player.ID].IsCurrentlyAwaiting = false; } }); } } } return(false); }
public static bool SvBan(SvPlayer player, ref int otherID) { if (player.player.admin) { return(true); } if (BlockBanButtonTabMenu) { player.SendChatMessage($"<color={errorColor}>This button has been disabled. Please use the ban commands. ID: {otherID}</color>"); return(true); } var targetPlayer = player.entity.manager.FindByID <ShPlayer>(otherID); if (!targetPlayer || targetPlayer.svPlayer.serverside) { player.SendChatMessage("Cannot ban NPC"); return(true); } LogMessage.LogOther($"{PlaceholderParser.ParseTimeStamp()} [INFO] {targetPlayer.username} Got banned by {player.playerData.username}"); player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"<color={argColor}>{targetPlayer.username}</color> <color={warningColor}>Just got banned by</color> <color={argColor}>{player.player.username}</color>"); SendDiscordMessage.BanMessage(targetPlayer.username, player.playerData.username); player.svManager.AddBanned(targetPlayer); player.svManager.Disconnect(targetPlayer.svPlayer.connection, DisconnectTypes.Banned); return(true); }
public static void Run(SvPlayer player, string message, string prefix = "") { try { var mssge = $"{PlaceholderParser.ParseTimeStamp()} {prefix}[{(message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture) ? "COMMAND" : "MESSAGE")}] {player.playerData.username}: {message}"; Debug.Log(mssge); int tries = 0; while (tries < 2) { try { if (!message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture)) { File.AppendAllText(ChatLogFile, mssge + Environment.NewLine); } else { File.AppendAllText(CommandLogFile, mssge + Environment.NewLine); } File.AppendAllText(LogFile, mssge + Environment.NewLine); break; } catch (IOException) { Thread.Sleep(50); ++tries; } } } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static void Destroy(SvPlayer player) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] [LEAVE] {player.player.username}"); if (!PlayerList.ContainsKey(player.player.ID)) { return; } PlayerList.Remove(player.player.ID); }
static IEnumerator WaitForRequest(WWW www) { yield return(www); if (DebugLevel >= 2) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Post request response received: {(www.text ?? $"[HTTP-ERROR] {www.error}")}"); } www.Dispose(); }
public static void StartServer(SvManager svManager) { Debug.Log("[INFO] Essentials - Starting up.."); try { SvMan = svManager; Methods.Utils.FunctionMenu.RegisterMenus(); Reload.Run(true, null, true); CheckAutoReloadFile.Run(AutoReloader); if (Variables.Version != LocalVersion) { Debug.Log("[ERROR] Essentials - Versions do not match!"); Debug.Log("[ERROR] Essentials - Essentials assembly version: " + Variables.Version); Debug.Log("[ERROR] Essentials - Settings file version: " + LocalVersion); Debug.Log(""); Debug.Log(""); Debug.Log("[ERROR] Essentials - Recreating settings file!"); string date = DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss"); if (File.Exists(SettingsFile + "." + date + ".OLD")) { File.Delete(SettingsFile + "." + date + ".OLD"); } File.Move(SettingsFile, $"{SettingsFile}.{date}.OLD"); Reload.Run(true); } Save.StartSaveTimer(); Variables.WarpHandler = new WarpHandler(); Variables.WarpHandler.LoadAll(true); Variables.KitsHandler = new KitsHandler(); Variables.KitsHandler.LoadAll(true); Debug.Log("-------------------------------------------------------------------------------"); Debug.Log($"[INFO] Essentials - Version: {LocalVersion} {(IsPreRelease ? "[PRE-RELEASE] " : "")}Loaded in successfully!"); Debug.Log("-------------------------------------------------------------------------------"); } catch (Exception ex) { Debug.Log("-------------------------------------------------------------------------------"); Debug.Log(" "); Debug.Log("[ERROR] Essentials - Whoopsie doopsie, something went wrong."); Debug.Log("[ERROR] Essentials - Please check the error below for more info,"); Debug.Log("[ERROR] Essentials - And it would be highly appreciated if you would send the error to the developers of this plugin!"); Debug.Log(" "); Debug.Log(ex); Debug.Log(ex.ToString()); Debug.Log("-------------------------------------------------------------------------------"); } Debug.Log("[INFO] Essentials - Ready."); if (Variables.Announcer.Announcements.Count == 0) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] No announcements found in the file!"); return; } Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Announcer started successfully!"); }
public static void Run(List <_Command> cmdlist) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registering commands.."); CommandList.Clear(); foreach (var command in cmdlist) { if (DebugLevel >= 1) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registering command: {command.CommandName}.."); } Action <SvPlayer, string> rMethod = null; try { rMethod = (Action <SvPlayer, string>) Delegate.CreateDelegate(typeof(Action <SvPlayer, string>), Type.GetType($"BP_Essentials.Commands.{command.CommandName}") .GetMethod(nameof(Run))); } catch (ArgumentException) { rMethod = null; } if (command.CommandName == "ToggleReceiveStaffChat") { CmdStaffChatExecutableBy = command.ExecutableBy; } if (command.CommandName == "Confirm") { CmdConfirm = command.Commands[0]; } if (command.CommandName == "ToggleChat") { CmdToggleChat = command.Commands[0]; } if (command.CommandName == "TpaAccept") { CmdTpaaccept = command.Commands[0]; } CommandList.Add(CommandList.Count + 1, new _CommandList { RunMethod = rMethod, commandGroup = command.ExecutableBy ?? "everyone", commandName = command.CommandName, commandCmds = command.Commands.Select(x => $"{CmdCommandCharacter}{x}").ToList(), commandDisabled = command.Disabled ?? false, commandWantedAllowed = command.AllowWithCrimes ?? true, commandHandcuffedAllowed = command.AllowWhileCuffed ?? true, commandWhileJailedAllowed = command.AllowWhileJailed ?? true }); } Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Registered commands! ({CommandList.Count} commands loaded in.)"); }
public static bool SvTimescale(SvPlayer player, ref float timescale) { if (!player.player.admin) { return(true); } if (TimescaleDisabled) { player.SendChatMessage($"<color={errorColor}>You cannot set the timescale because the server owner disabled this.</color>"); return(true); } Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.player.username} set the timescale to {timescale}"); return(false); }
public static bool OnCommand(SvPlayer player, ref string message) { var tempMessage = message; var command = GetArgument.Run(0, false, false, message); // CustomCommands var customCommand = CustomCommands.FirstOrDefault(x => tempMessage.StartsWith(CmdCommandCharacter + x.Command, StringComparison.CurrentCulture)); if (customCommand != null) { foreach (string line in customCommand.Response.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) { player.SendChatMessage(PlaceholderParser.ParseUserMessage(player.player, line, message)); } PlayerList.Where(x => x.Value.SpyEnabled && x.Value.ShPlayer.svPlayer != player).ToList().ForEach(x => x.Value.ShPlayer.svPlayer.SendChatMessage($"<color=#f4c242>[SPYCHAT]</color> {player.playerData.username}: {tempMessage}")); return(true); } // Go through all registered commands and check if the command that the user entered matches foreach (var cmd in CommandList.Values) { if (cmd.commandCmds.Contains(command)) { if (cmd.commandDisabled) { player.SendChatMessage(DisabledCommand); return(true); } if (HasPermission.Run(player, cmd.commandGroup, true, player.player.job.jobIndex) && HasWantedLevel.Run(player, cmd.commandWantedAllowed) && IsCuffed.Run(player, cmd.commandHandcuffedAllowed) && IsJailed.Run(player, cmd.commandWhileJailedAllowed)) { PlayerList.Where(x => x.Value.SpyEnabled && x.Value.ShPlayer.svPlayer != player).ToList().ForEach(x => x.Value.ShPlayer.svPlayer.SendChatMessage($"<color=#f4c242>[SPYCHAT]</color> {player.playerData.username}: {tempMessage}")); cmd.RunMethod.Invoke(player, message); } return(true); } } if (AfkPlayers.Contains(player.playerData.username)) { Commands.Afk.Run(player, message); } if (MsgUnknownCommand) { player.SendChatMessage($"<color={errorColor}>Unknown command. Type</color><color={argColor}> {CmdCommandCharacter}essentials cmds </color><color={errorColor}>for more info.</color>"); return(true); } return(false); }
public static IEnumerator GetContentWWW(string link, Action <string> callback) { using (var www = new WWW(link)) { yield return(www); if (www.error != null) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [ERROR] {link} responded with HTTP error code: {www.error}!"); callback?.Invoke(null); yield break; } callback?.Invoke(www.text); yield break; } }
public static void Run() { try { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Saving game.."); foreach (var shPlayer in SvMan.players.Values.ToList()) { if (!shPlayer.svPlayer.serverside) { shPlayer.svPlayer.SendChatMessage("<color=#DCDADA>Saving game.. This can take up to 5 seconds.</color>"); shPlayer.svPlayer.Save(); } } } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static bool SvStartVote(SvPlayer player, ref byte voteIndex, ref int ID) { switch (voteIndex) { case VoteIndex.Mission: if (!BlockMissions) { return(false); } player.SendChatMessage($"<color={errorColor}>All missions have been disabled on this server.</color>"); return(true); case VoteIndex.Kick: if (VoteKickDisabled) { player.SendChatMessage($"<color={errorColor}>Vote kicking has been disabled on this server.</color>"); return(true); } if (!PlayerList.TryGetValue(ID, out var shPlayer)) { return(true); } if (player.svManager.vote != null || voteIndex >= player.player.manager.votes.Length || player.svManager.startedVote.OverLimit(player.player)) { return(true); } player.svManager.startedVote.Add(player.player); player.svManager.vote = player.player.manager.votes[voteIndex]; if (!player.svManager.vote.CheckVote(ID)) { player.svManager.vote = null; } player.Send(SvSendType.All, Channel.Reliable, 60, voteIndex, ID); player.svManager.StartCoroutine(player.svManager.StartVote()); Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] {player.playerData.username} Has issued a votekick against {player.player.username}"); player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"<color={argColor}>{player.playerData.username} </color><color={warningColor}>Has issued a vote kick against</color><color={argColor}> {shPlayer.ShPlayer.username}</color>"); LatestVotePeople.Clear(); return(true); default: return(false); } }
public static void Run() { try { Groups.Clear(); _RootObject m = JsonConvert.DeserializeObject <_RootObject>(FilterComments.Run(CustomGroupsFile)); foreach (var group in m.Groups) { if (Groups.ContainsKey(group.Name)) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [ERROR] Cannot add group {group.Name} To dictionary because it already exists!"); continue; } Groups.Add(group.Name, new _Group { Message = group.Message, Name = group.Name, Users = group.Usernames }); } } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static void Run(string file) { try { var watcher = new FileSystemWatcher { Path = Path.GetDirectoryName(file), Filter = Path.GetFileName(file), NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName, EnableRaisingEvents = true }; watcher.Changed += (sender, e) => { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [INFO] Found a change in file {file}, reloading all files..."); Debug.Log(" "); Reload.Run(true); }; } catch (Exception ex) { ErrorLogging.Run(ex); } }
public static bool SvGlobalChatMessage(SvPlayer player, ref string message) { try { var tempMessage = message; if (HandleSpam.Run(player, tempMessage)) { return(true); } //Message Logging if (!MutePlayers.Contains(player.playerData.username)) { LogMessage.Run(player, message); } if (message.StartsWith(CmdCommandCharacter, StringComparison.CurrentCulture)) { if (OnCommand(player, ref message)) { return(true); } } //Checks if the player is muted. if (MutePlayers.Contains(player.playerData.username)) { player.SendChatMessage(SelfIsMuted); return(true); } //Checks if the message contains a username that is AFK. if (AfkPlayers.Any(message.Contains)) { player.SendChatMessage(PlayerIsAFK); } var shPlayer = player.player; if (!PlayerList[shPlayer.ID].ChatEnabled) { player.SendChatMessage($"<color={warningColor}>Please enable your chat again by typing</color> <color={argColor}>{CmdCommandCharacter}{CmdToggleChat}</color><color={warningColor}>.</color>"); return(true); } if (PlayerList[shPlayer.ID].StaffChatEnabled) { SendChatMessageToAdmins.Run(PlaceholderParser.ParseUserMessage(shPlayer, AdminChatMessage, message)); return(true); } foreach (var curr in Groups) { if (curr.Value.Users.Contains(player.playerData.username)) { SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, curr.Value.Message, message)); return(true); } } if (player.player.admin) { SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, AdminMessage, message)); return(true); } SendChatMessage.Run(PlaceholderParser.ParseUserMessage(shPlayer, PlayerMessage, message)); } catch (Exception ex) { ErrorLogging.Run(ex); } return(true); }
public static void Run(string fileName) { try { IdListObject idlist; switch (fileName) { case SettingsFile: var m = JsonConvert.DeserializeObject <__RootObject>(FilterComments.Run(SettingsFile)); LocalVersion = m.General.Version; CmdCommandCharacter = m.General.CommandCharacter; DownloadIdList = m.General.DownloadIDList; TimestampFormat = m.General.TimestapFormat; MsgSayColor = m.General.MsgSayColor; MsgUnknownCommand = m.General.DisplayUnknownCommandMessage; VoteKickDisabled = m.General.VoteKickDisabled; ShowDMGMessage = m.General.ShowDMGMessage; DebugLevel = m.General.DebugLevel; EnableDiscordWebhook_Ban = m.General.EnableDiscordWebhook_Ban; if (EnableDiscordWebhook_Ban && string.IsNullOrEmpty(m.General.DiscordWebhook_Ban.Trim())) { Debug.Log("[ERROR] Discord webhook_Ban is empty but EnableDiscordWebhook_Ban is true! Disabling webhook_Ban."); EnableDiscordWebhook_Ban = false; } else { DiscordWebhook_Ban = m.General.DiscordWebhook_Ban; } EnableDiscordWebhook_Report = m.General.EnableDiscordWebhook_Report; if (EnableDiscordWebhook_Report && string.IsNullOrEmpty(m.General.DiscordWebhook_Report.Trim())) { Debug.Log("[ERROR] Discord webhook_Report is empty but EnableDiscordWebhook_Report is true! Disabling webhook_Report."); EnableDiscordWebhook_Report = false; } else { DiscordWebhook_Report = m.General.DiscordWebhook_Report; } BlockBanButtonTabMenu = m.General.BlockBanButtonTabMenu; blockLicenseRemoved = m.General.BlockLicenseRemoved; MessagesAllowedPerSecond = m.General.MessagesAllowedPerSecond; TimeBetweenDelay = m.General.TimeBetweenDelay; WipePassword = m.General.WipePassword; infoColor = m.MessageColors.Info; errorColor = m.MessageColors.Error; warningColor = m.MessageColors.Warning; argColor = m.MessageColors.Arg; MsgNoPerm = m.Messages.NoPerm; MsgDiscord = m.Messages.DiscordLink; MsgSayPrefix = m.Messages.MsgSayPrefix; DisabledCommand = $"<color={errorColor}>{m.Messages.DisabledCommand}</color>"; PlayerIsAFK = $"<color={warningColor}>{m.Messages.PlayerIsAFK}</color>"; SelfIsMuted = $"<color={errorColor}>{m.Messages.SelfIsMuted}</color>"; ArgRequired = $"<color={errorColor}>{m.Messages.ArgRequired}</color>"; NotFoundOnline = $"<color={errorColor}>{m.Messages.NotFoundOnline}</color>"; NotFoundOnlineIdOnly = $"<color={errorColor}>{m.Messages.NotFoundOnlineIdOnly}</color>"; AdminSearchingInv = $"<color={errorColor}>{m.Messages.AdminSearchingInv}</color>"; PlayerMessage = m.Messages.PlayerMessage; AdminMessage = m.Messages.AdminMessage; AdminChatMessage = m.Messages.AdminChatMessage; MsgNoPermJob = $"<color={errorColor}>{m.Messages.MsgNoPermJob}</color>"; BlockedItemMessage = $"<color={errorColor}>{m.Messages.BlockedItem}</color>"; MsgNoWantedAllowed = $"<color={errorColor}>{m.Messages.MsgNoWantedAllowed}</color>"; MsgNoCuffedAllowed = $"<color={errorColor}>{m.Messages.MsgNoCuffedAllowed}</color>"; MsgNoJailAllowed = $"<color={errorColor}>{m.Messages.MsgNoJailAllowed}</color>"; MeMessage = m.Messages.MeMessage; AccessMoneyMenu = m.FunctionUI.AccessMoneyMenu; AccessItemMenu = m.FunctionUI.AccessItemMenu; AccessSetHPMenu = m.FunctionUI.AccessSetHPMenu; AccessSetStatsMenu = m.FunctionUI.AccessSetStatsMenu; AccessCWMenu = m.FunctionUI.AccessCWMenu; ReportReasons = new string[] { m.ReportOptions.F2, m.ReportOptions.F3, m.ReportOptions.F4, m.ReportOptions.F5, m.ReportOptions.F6, m.ReportOptions.F7, m.ReportOptions.F8, m.ReportOptions.F9, m.ReportOptions.F10 }; // Softcode this someday Jobs = new string[] { m.JobIndexArray.Citizen, m.JobIndexArray.Criminal, m.JobIndexArray.Prisoner, m.JobIndexArray.Police, m.JobIndexArray.Paramedic, m.JobIndexArray.Firefighter, m.JobIndexArray.Rojo_Loco, m.JobIndexArray.Green_St_Fam, m.JobIndexArray.Borgata_Blue, m.JobIndexArray.Mayor, m.JobIndexArray.DeliveryDriver, m.JobIndexArray.TaxiDriver, m.JobIndexArray.SpecOps }; BlockedItems = m.BlockedItems; EnableBlockSpawnBot = m.Misc.EnableBlockSpawnBot; LanguageBlock = m.Misc.EnableLanguageBlock; ChatBlock = m.Misc.EnableChatBlock; CheckBannedEnabled = m.Misc.CheckBannedEnabled; TimeBetweenAnnounce = m.Misc.TimeBetweenAnnounce; Variables.Announcer.Interval = TimeBetweenAnnounce; TimescaleDisabled = m.Misc.TimescaleDisabled; if (m.Misc.EnableBlockSpawnBot) { BlockedSpawnIds = m.Misc.BlockSpawnBot.Split(',').Select(int.Parse).ToArray(); } GodModeLevel = m.Misc.GodModeLevel; ShowJailMessage = m.Misc.ShowJailMessage; BlockSuicide = m.Misc.BlockSuicide; BlockMissions = m.Misc.BlockMissions; ProximityChat = m.Misc.ProximityChat; LocalChatMute = m.Misc.LocalChatMute; LocalChatMe = m.Misc.LocalChatMe; foreach (var currJob in m.WhitelistedJobs) { if (WhitelistedJobs.ContainsKey(currJob.JobIndex)) { Debug.Log($"{PlaceholderParser.ParseTimeStamp()} [WARNING] WhitelistedJobs already contains a item with the key '{currJob.JobIndex}'! (Did you make two objects with the same JobIndex?)"); continue; } WhitelistedJobs.Add(currJob.JobIndex, currJob.Whitelisted); } RegisterCommands.Run(m.Commands); break; case IdListItemsFile: idlist = JsonConvert.DeserializeObject <IdListObject>(FilterComments.Run(IdListItemsFile)); IDs_Items = idlist.items.Select(x => x.gameid).ToArray(); break; case IdListVehicleFile: idlist = JsonConvert.DeserializeObject <IdListObject>(FilterComments.Run(IdListVehicleFile)); IDs_Vehicles = idlist.items.Select(x => x.gameid).ToArray(); break; case AnnouncementsFile: Variables.Announcer.Announcements = File.ReadAllLines(fileName).ToList(); break; case RulesFile: Rules = File.ReadAllText(fileName); break; case GodListFile: GodListPlayers = File.ReadAllLines(fileName).ToList(); break; case AfkListFile: AfkPlayers = File.ReadAllLines(fileName).ToList(); break; case MuteListFile: MutePlayers = File.ReadAllLines(fileName).ToList(); break; default: break; } } catch (Exception ex) { ErrorLogging.Run(ex); } }