Kazzypoo

Untitled

May 9th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.51 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. using System.Collections.Generic;
  3. using Oxide.Game.Rust.Libraries;
  4. using Newtonsoft.Json.Linq;
  5. using Newtonsoft.Json;
  6. using UnityEngine;
  7. using System.Linq;
  8. using Oxide.Core;
  9. using System;
  10.  
  11.  
  12. namespace Oxide.Plugins
  13. {
  14. [Info("Notifier", "SkinN", "3.0.8", ResourceId = 797)]
  15. [Description("Server administration tool with chat based notifications")]
  16.  
  17. class Notifier : RustPlugin
  18. {
  19. #region Plugin Resources
  20.  
  21. // Developer Variables
  22. private readonly bool Dev = false;
  23. private readonly string Seperator = string.Join("-", new string[50 + 1]);
  24. private readonly string DatabaseFile = "Notifier_PlayersData";
  25.  
  26. // Plugin Variables
  27. private Dictionary<string, PlayerCache> Players;
  28. private System.Random AdvertsLoop = new System.Random();
  29. private int LastAdvert = 0;
  30. private List<string> WM_Queue = new List<string>();
  31.  
  32. // Avalailable Rules Countries Dictionary
  33. private Dictionary<string, string> Countries = new Dictionary<string, string>
  34. {
  35. { "EN", "English" },
  36. { "PT", "Portuguese" },
  37. { "ES", "Spanish" },
  38. { "FR", "French" },
  39. { "DE", "German" },
  40. { "TR", "Turk" },
  41. { "IT", "Italian" },
  42. { "DK", "Danish" },
  43. { "RU", "Russian" },
  44. { "UA", "Ukrainian" },
  45. { "NL", "Dutch" },
  46. { "RO", "Romanian" },
  47. { "HU", "Hungarian" },
  48. { "JP", "Japanese" },
  49. { "CZ", "Czech" }
  50. };
  51.  
  52. // HTML default colors
  53. private List<string> HTMLColors = new List<string> {
  54. "white", "silver", "gray", "black", "red", "maroon",
  55. "yellow", "orange", "olive", "lime", "green", "aqua",
  56. "teal", "blue", "navy", "fuchsia", "purple", "cyan",
  57. "grey", "lightblue", "dimgrey", "lightgreen", "pink", "magenta"
  58. };
  59.  
  60. // Player Database Class
  61. public class PlayerCache
  62. {
  63. public bool isadmin = false;
  64. public string steamid = "STEAM_ID_UNKOWN";
  65. public string ipaddress = "Unknown";
  66. public string country = "Unknown";
  67. public string username = "Unknown";
  68. public string countrycode = "Unknown";
  69.  
  70. public PlayerCache()
  71. {
  72. }
  73.  
  74. internal PlayerCache(BasePlayer player)
  75. {
  76. steamid = player.UserIDString;
  77. this.Update(player);
  78. }
  79.  
  80. internal void Update(BasePlayer player)
  81. {
  82. username = player.displayName;
  83. ipaddress = player.net.connection.ipaddress.Split(':')[0];
  84. isadmin = player.IsAdmin();
  85. }
  86. };
  87.  
  88. // Configuration Variables
  89. private string Motd;
  90. private string Prefix;
  91. private string IconProfile;
  92. private string RulesDefaultLanguage;
  93. private string TimeFormat;
  94. private string DateFormat;
  95. private int AdvertsInterval;
  96. private bool EnableIconProfile;
  97. private bool EnableJoinMessage;
  98. private bool EnableLeaveMessage;
  99. private bool EnableScheduledMessages;
  100. private bool BroadcastToConsole;
  101. private bool EnablePluginPrefix;
  102. private bool EnableAdvertMessages;
  103. private bool EnableWelcomeMessage;
  104. private bool NotifyHelicopter;
  105. private bool NotifyAirdrop;
  106. private bool HideAdmins;
  107. private bool EnableChatSeparators;
  108.  
  109. #endregion
  110.  
  111. #region Configuration
  112.  
  113. protected override void LoadDefaultConfig()
  114. {
  115. }
  116.  
  117. private void LoadVariables()
  118. {
  119. // Force Clear Configuration On Developer Mode
  120. //Config.Clear();
  121.  
  122. #region General Settings
  123.  
  124. Prefix = GetConfig<string>("General Settings", "Prefix", "<white>[ <cyan>NOTIFIER<end> ]<end>");
  125. EnablePluginPrefix = GetConfig<bool>("General Settings", "Enable Plugin Prefix", true);
  126. EnableIconProfile = GetConfig<bool>("General Settings", "Enable Icon Profile", false);
  127. IconProfile = GetConfig<string>("General Settings", "Icon Profile", "76561198235146288");
  128. TimeFormat = GetConfig<string>("General Settings", "Time Format", "{hour}:{minute}:{second}");
  129. DateFormat = GetConfig<string>("General Settings", "Date Format", "{day}/{month}/{year}");
  130. RulesDefaultLanguage = GetConfig<string>("General Settings", "Rules Default Language", "auto");
  131. BroadcastToConsole = GetConfig<bool>("General Settings", "Broadcast To Console", true);
  132. EnableScheduledMessages = GetConfig<bool>("General Settings", "Enable Scheduled Messages", false);
  133. EnableJoinMessage = GetConfig<bool>("General Settings", "Enable Join Message", true);
  134. EnableLeaveMessage = GetConfig<bool>("General Settings", "Enable Leave Message", true);
  135. EnableAdvertMessages = GetConfig<bool>("General Settings", "Enable Advert Messages", true);
  136. EnableWelcomeMessage = GetConfig<bool>("General Settings", "Enable Welcome Message", true);
  137. AdvertsInterval = GetConfig<int>("General Settings", "Adverts Interval (In Minutes)", 12);
  138. NotifyHelicopter = GetConfig<bool>("General Settings", "Notify Incoming Helicopter", false);
  139. NotifyAirdrop = GetConfig<bool>("General Settings", "Notify Incoming Airdrop", false);
  140. HideAdmins = GetConfig<bool>("General Settings", "Hide Admins", false);
  141. EnableChatSeparators = GetConfig<bool>("General Settings", "Enable Chat Separators", true);
  142.  
  143. #endregion
  144.  
  145. // MOTD
  146. Motd = GetConfig<string>("Message Of The Day", "We are using <cyan>Notifier<end> <grey>v3.0<end>, type <orange>/notifier help<end> for all its available commands.");
  147.  
  148. #region Advert Messages
  149.  
  150. SetConfig("Advert Messages", new List<object>
  151. {
  152. "<orange>Need help?<end> Try calling for the <cyan>Admins<end> in the chat. Use !admin (your message)",
  153. "Be sure to register on our forums @ <orange>www.pcgamingforum.org!<end>",
  154. "Cheating or abusing of game exploits will result in a <red>permanent<end> ban.",
  155. "You are playing on: <orange>{server.hostname}<end>",
  156. "There are <orange>{players.active}<silver>/<end>{server.maxplayers} <silver>players playing in the server, and<end> {players.sleepers}<end> sleepers.",
  157. "Check <cyan>Notifier's<end> with <orange>/notifier help<end> command."
  158. "This server is running <blue>/clans<end> use /clan help to find out more!"
  159. "This server is a <green>PVE on weekdays (Monday-Friday)<end> <red>PvP on weekends (Saturday-Sunday)!<end>"'
  160. }
  161. );
  162.  
  163. #endregion
  164.  
  165. #region Welcome Messages
  166.  
  167. SetConfig("Welcome Messages", new List<object>
  168. {
  169. "<size=18>Welcome to PCGF Rust! <lightblue>{player.name}<end></size>",
  170. "<orange><size=20>•</size><end> Type <orange>/notifier help<end> for all available commands",
  171. "<orange><size=20>•</size><end> Please respect our server <orange>/rules<end>",
  172. "<orange><size=20>•</size><end> Check our live map at <lime>http://158.69.155.149:28015<end>"
  173. }
  174. );
  175.  
  176. #endregion
  177.  
  178. #region Schedule Messages
  179.  
  180. SetConfig("Schedule Messages", new Dictionary<string, object>
  181. {
  182. {
  183. "22:50", new List<object> {
  184. "It is now <orange>{localtime.now}<end> (Server local time)"
  185. }
  186. },
  187. {
  188. "22:00", new List<object> {
  189. "It is now <orange>{localtime.date} {localtime.now}<end> (Server local time)"
  190. }
  191. }
  192. }
  193. );
  194.  
  195. #endregion
  196.  
  197. #region Rules
  198.  
  199. SetConfig("Rules", "EN", new List<object> {
  200. "Cheating is strictly prohibited.",
  201. "Respect all players",
  202. "Avoid spam in chat.",
  203. "DO NOT ask for free items/ranks/help from Admins.",
  204. "No combat-logging, base-blocking or unsportsmanslike behavior",
  205. "Don't hoard items from the Community Center",
  206. "No building bases near/around Landmarks! (sniper towers, etc.)",
  207. "Have fun!"
  208.  
  209. }
  210. );
  211. SetConfig("Rules", "PT", new List<object> {
  212. "Usar cheats e totalmente proibido.",
  213. "Respeita todos os jogadores.",
  214. "Evita spam no chat.",
  215. "Nao abuses de bugs ou exploits."
  216. }
  217. );
  218. SetConfig("Rules", "FR", new List<object> {
  219. "Tricher est strictement interdit.",
  220. "Respectez tous les joueurs.",
  221. "Évitez le spam dans le chat.",
  222. "Jouer juste et ne pas abuser des bugs / exploits."
  223. }
  224. );
  225. SetConfig("Rules", "ES", new List<object> {
  226. "Los trucos están terminantemente prohibidos.",
  227. "Respeta a todos los jugadores.",
  228. "Evita el Spam en el chat.",
  229. "Juega limpio y no abuses de bugs/exploits."
  230. }
  231. );
  232. SetConfig("Rules", "DE", new List<object> {
  233. "Cheaten ist verboten!",
  234. "Respektiere alle Spieler",
  235. "Spam im Chat zu vermeiden.",
  236. "Spiel fair und missbrauche keine Bugs oder Exploits."
  237. }
  238. );
  239. SetConfig("Rules", "TR", new List<object> {
  240. "Hile kesinlikle yasaktır.",
  241. "Tüm oyuncular Saygı.",
  242. "Sohbet Spam kaçının.",
  243. "Adil oynayın ve böcek / açıkları kötüye yok."
  244. }
  245. );
  246. SetConfig("Rules", "IT", new List<object> {
  247. "Cheating è severamente proibito.",
  248. "Rispettare tutti i giocatori.",
  249. "Evitare lo spam in chat.",
  250. "Fair Play e non abusare di bug / exploit."
  251. }
  252. );
  253. SetConfig("Rules", "DK", new List<object> {
  254. "Snyd er strengt forbudt.",
  255. "Respekter alle spillere.",
  256. "Undgå spam i chatten.",
  257. "Spil fair og misbrug ikke bugs / exploits."
  258. }
  259. );
  260. SetConfig("Rules", "RU", new List<object>{
  261. "Запрещено использовать читы.",
  262. "Запрещено спамить и материться.",
  263. "Уважайте других игроков.",
  264. "Играйте честно и не используйте баги и лазейки."
  265. }
  266. );
  267. SetConfig("Rules", "UA", new List<object> {
  268. "Обман суворо заборонено.",
  269. "Поважайте всіх гравців",
  270. "Щоб уникнути спаму в чаті.",
  271. "Грати чесно і не зловживати помилки / подвиги."
  272. }
  273. );
  274. SetConfig("Rules", "NL", new List<object> {
  275. "Vals spelen is ten strengste verboden.",
  276. "Respecteer alle spelers",
  277. "Vermijd spam in de chat.",
  278. "Speel eerlijk en maak geen misbruik van bugs / exploits."
  279. }
  280. );
  281. SetConfig("Rules", "RO", new List<object> {
  282. "Cheaturile sunt strict interzise!",
  283. "Respectați toți jucătorii!",
  284. "Evitați spamul în chat!",
  285. "Jucați corect și nu abuzați de bug-uri/exploituri!"
  286. }
  287. );
  288. SetConfig("Rules", "HU", new List<object> {
  289. "Csalás szigorúan tilos.",
  290. "Tiszteld minden játékostársad.",
  291. "Kerüld a spammolást a chaten.",
  292. "Játssz tisztességesen és nem élj vissza a hibákkal."
  293. }
  294. );
  295. SetConfig("Rules", "JP", new List<object> {
  296. "チート行為は固く禁じております。",
  297. "全てのプレイヤーに敬意を払って下さい。",
  298. "チャットでスパム行為はしないで下さい。",
  299. "バグの悪用行為や公平なプレイはしないで下さい"
  300. }
  301. );
  302. SetConfig("Rules", "CZ", new List<object> {
  303. "Cheatování je přísně zakázáno.",
  304. "Respektuj a neurážej ostatní hráče.",
  305. "Nespamuj chat zbytečně.",
  306. "Hraj fair play a nezneužívej bugy/exploity."
  307. }
  308. );
  309.  
  310. #endregion
  311.  
  312. #region Commands
  313.  
  314. // Command Triggers
  315. SetConfig("Commands", "Triggers", "Players List", new List<string> { "/players" });
  316. SetConfig("Commands", "Triggers", "Plugins List", new List<string> { "/plugins" });
  317. SetConfig("Commands", "Triggers", "Admins List", new List<string> { "/admins" });
  318. SetConfig("Commands", "Triggers", "Players Count", new List<string> { "/online" });
  319. SetConfig("Commands", "Triggers", "Server MOTD", new List<string> { "/motd" });
  320. SetConfig("Commands", "Triggers", "Server Map", new List<string> { "/map" });
  321. SetConfig("Commands", "Triggers", "Server Rules", new List<string> { "/rules" });
  322.  
  323. // Command Settings
  324. SetConfig("Commands", "Settings", "Players List", true);
  325. SetConfig("Commands", "Settings", "Plugins List", false);
  326. SetConfig("Commands", "Settings", "Admins List", false);
  327. SetConfig("Commands", "Settings", "Server Rules", true);
  328. SetConfig("Commands", "Settings", "Server Map", false);
  329. SetConfig("Commands", "Settings", "Server MOTD", false);
  330. SetConfig("Commands", "Settings", "Players Count", true);
  331.  
  332. #endregion
  333.  
  334. SaveConfig();
  335. }
  336.  
  337. #region Configuration Methods
  338.  
  339. private T GetConfig<T>(params object[] args)
  340. {
  341. string[] stringArgs = GetConfigPath(args);
  342. if (Config.Get(stringArgs) == null)
  343. Config.Set(args);
  344. return (T)Convert.ChangeType(Config.Get(stringArgs), typeof(T));
  345. }
  346.  
  347. private void SetConfig(params object[] args)
  348. {
  349. string[] stringArgs = GetConfigPath(args);
  350. if (Config.Get(stringArgs) == null)
  351. Config.Set(args);
  352. }
  353.  
  354. private List<string> ConvertList(object value)
  355. {
  356. if (value is List<object>)
  357. {
  358. List<object> list = (List<object>) value;
  359. List<string> strings = list.Select(s => (string) s).ToList();
  360. return strings;
  361. }
  362. else { return (List<string>) value; }
  363. }
  364.  
  365. private string[] GetConfigPath(params object[] args)
  366. {
  367. string[] stringArgs = new string[args.Length - 1];
  368. for (var i = 0; i < args.Length - 1; i++)
  369. stringArgs[i] = args[i].ToString();
  370. return stringArgs;
  371. }
  372.  
  373. #endregion
  374.  
  375. private void LoadMessages()
  376. {
  377. lang.RegisterMessages(new Dictionary<string, string> {
  378. { "Join Message", "<lightblue>{player.name} <silver>joined from<end> {player.country}<end>" },
  379. { "Leave Message", "<lightblue>{player.name}<end> left the server (Reason: {reason})" },
  380. { "Incoming Airdrop", "<yellow>Airdrop <silver>incoming, drop coordinates are:<end> {x}, {y}, {z}<end>."},
  381. { "Incoming Helicopter", "<yellow>Patrol Helicopter<end> incoming!" },
  382. { "No Admins Online", "There are no <cyan>Admins<end> currently online" },
  383. { "Players List Description", "List of active players" },
  384. { "Plugins List Description", "List of plugins running in the server" },
  385. { "Admins List Description", "List of active Admins" },
  386. { "Server Rules Description", "Displays server rules (In the player Steam language if set to automatic)" },
  387. { "Server Map Description", "Shows the URL to the server live map (Rust:IO)" },
  388. { "Server MOTD Description", "Shows the Message Of The Day" },
  389. { "Players Count Description", "Counts active players, sleepers and admins of the server" },
  390. { "Players List Title", "Players List" },
  391. { "Plugins List Title", "Plugins List" },
  392. { "Admins List Title", "Admins Online" },
  393. { "Server Rules Title", "Server Rules" },
  394. { "Rules Languages List Title", "Available Rules Languages" },
  395. { "Server MOTD Title", "Message Of The Day" },
  396. { "Server Map Message", "Check our live map at: <yellow>{server.ip}:{server.port}<end>" },
  397. { "Players Count Message", "There are <orange>{players.active} <silver>of<end> {server.maxplayers}<end> <silver>players in the server, and <orange>{players.sleepers}<end> sleepers<end>" },
  398. { "Help Text Message", "For all the <cyan>Notifier<end>'s commands type <orange>/notifier help<end>" }
  399. }, this);
  400. }
  401.  
  402. private string GetMsg(string key) { return lang.GetMessage(key, this, null); }
  403.  
  404. #endregion
  405.  
  406. #region Messages System
  407.  
  408. private void Con(string msg)
  409. {
  410. if (BroadcastToConsole)
  411. Puts(SimpleColorFormat(msg, true));
  412. }
  413.  
  414. private void Say(string msg, string profile = "0", bool prefix = true)
  415. {
  416. Con(msg);
  417. if (!String.IsNullOrEmpty(Prefix) && EnablePluginPrefix && prefix)
  418. msg = Prefix + " " + msg;
  419.  
  420. if (profile == "0" && EnableIconProfile)
  421. profile = IconProfile;
  422.  
  423. rust.BroadcastChat(SimpleColorFormat("<silver>" + msg + "<end>"), null, profile);
  424. }
  425.  
  426. private void Tell(BasePlayer player, string msg, string profile = "0", bool prefix = true)
  427. {
  428. if (!String.IsNullOrEmpty(Prefix) && EnablePluginPrefix && prefix)
  429. msg = Prefix + " " + msg;
  430.  
  431. if (profile == "0" && EnableIconProfile)
  432. profile = IconProfile;
  433.  
  434. rust.SendChatMessage(player, SimpleColorFormat("<silver>" + msg + "<end>"), null, profile);
  435. }
  436.  
  437. public string SimpleColorFormat(string text, bool removeTags = false)
  438. {
  439. /* Simple Color Format ( v3.0 ) */
  440.  
  441. Regex end = new Regex(@"\<(end?)\>"); // End Tags
  442. Regex hex = new Regex(@"\<(#\w+?)\>"); // Hex Codes
  443. Regex names = new Regex(@"\<(\w+?)\>"); // Color Names
  444.  
  445. if (removeTags)
  446. {
  447. // Remove tags
  448. text = end.Replace(text, "");
  449. text = names.Replace(text, "");
  450. text = hex.Replace(text, "");
  451. }
  452. else
  453. {
  454. foreach (Match i in names.Matches(text))
  455. {
  456. string x = i.ToString().Replace("<", "").Replace(">", "");
  457. if (HTMLColors.Contains(x.ToLower()))
  458. text = text.Replace("<" + x + ">", "<color=" + x.ToLower() + ">");
  459. }
  460.  
  461. // Replace tags
  462. text = end.Replace(text, "</color>");
  463. text = hex.Replace(text, "<color=$1>");
  464. }
  465.  
  466. return text;
  467. }
  468.  
  469. #endregion
  470.  
  471. #region Plugin Hooks
  472.  
  473. private void Init()
  474. {
  475. // Load variables and plugin messages
  476. LoadVariables();
  477. LoadMessages();
  478.  
  479. // Get Players database
  480. try
  481. {
  482. Players = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, PlayerCache>>(DatabaseFile);
  483. }
  484. catch { Players = new Dictionary<string, PlayerCache>(); }
  485.  
  486. // Cache all active players
  487. foreach (BasePlayer ply in BasePlayer.activePlayerList)
  488. OnPlayerInit(ply, false);
  489.  
  490. // Plugin Timers
  491. if (EnableAdvertMessages)
  492. {
  493. timer.Repeat(AdvertsInterval * 60, 0, () => SendAdvert());
  494. Puts("Started Advert Messages timer, set to " + AdvertsInterval + " minute/s");
  495. }
  496.  
  497. if (EnableScheduledMessages)
  498. {
  499. timer.Repeat(60, 0, () => CheckScheduledMessages());
  500. Puts("Started Schedule Messages timer");
  501. }
  502.  
  503. // Plugin Commands
  504. var command = Oxide.Core.Interface.Oxide.GetLibrary<Command>();
  505. Dictionary<string, object> Settings = (Dictionary<string, object>) Config.Get("Commands", "Settings");
  506. foreach (var cmd in Settings)
  507. {
  508. if ((bool) cmd.Value)
  509. {
  510. List<string> triggers = ConvertList(Config.Get("Commands", "Triggers", cmd.Key));
  511. foreach (string item in triggers)
  512. command.AddChatCommand(item.Replace("/", String.Empty), this, cmd.Key.Replace(" ", string.Empty) + "_Command");
  513. }
  514. }
  515. }
  516.  
  517. void Unload()
  518. {
  519. // Write database file
  520. Interface.Oxide.DataFileSystem.WriteObject(DatabaseFile, Players);
  521. }
  522.  
  523. #endregion
  524.  
  525. #region Player Hooks
  526.  
  527. void OnPlayerInit(BasePlayer player, bool sendJoinMessages = true)
  528. {
  529. string uid = player.UserIDString;
  530.  
  531. if (!Players.ContainsKey(uid))
  532. Players.Add(uid, new PlayerCache(player));
  533. else
  534. Players[uid].Update(player);
  535.  
  536. string country = Players[uid].country;
  537. string cCode = Players[uid].countrycode;
  538. if ((country == "Unknown" || country == null) || (cCode == "Unknown" || cCode == null))
  539. webrequest.EnqueueGet("http://ip-api.com/json/" + Players[uid].ipaddress + "?fields=3",
  540. (code, response) => WebrequestFilter(code, response, player, sendJoinMessages), this);
  541. else if (sendJoinMessages)
  542. JoinMessages(player);
  543.  
  544. }
  545.  
  546. void OnPlayerDisconnected(BasePlayer player, string reason)
  547. {
  548. string uid = player.UserIDString;
  549.  
  550. if (Players.ContainsKey(uid))
  551. {
  552. string LeaveMessage = GetMsg("Leave Message");
  553.  
  554. if (reason.StartsWith("Kicked: "))
  555. reason = "Kicked: " + reason.Replace(reason.Split()[0], "").Trim();
  556.  
  557. if (EnableLeaveMessage && NotHide(player))
  558. Say(GetNameFormats(LeaveMessage.Replace("{reason}", reason), player));
  559. }
  560. }
  561.  
  562. #endregion
  563.  
  564. #region Entity Hooks
  565.  
  566. void OnAirdrop(CargoPlane plane, Vector3 location)
  567. {
  568. if (NotifyAirdrop)
  569. {
  570. string x = location.x.ToString();
  571. string y = location.y.ToString();
  572. string z = location.z.ToString();
  573. string loc = x + ", " + y + ", " + z;
  574. Say(GetMsg("Incoming Airdrop").Replace("{location}", loc).Replace("{x}", x).Replace("{y}", y).Replace("{z}", z));
  575. }
  576. }
  577.  
  578. void OnEntitySpawned(BaseNetworkable entity)
  579. {
  580. if (NotifyHelicopter && entity.ToString().Contains("/patrolhelicopter.prefab"))
  581. Say(GetMsg("Incoming Helicopter"));
  582. }
  583.  
  584. #endregion
  585.  
  586. #region Plugin Commands
  587.  
  588. void PlayersList_Command(BasePlayer player, string command, string[] args)
  589. {
  590. List<string> Active = GetActivePlayersList();
  591. List<string> PlayerNames = (from ply in Active where (!(Players[ply].isadmin && HideAdmins) || player.IsAdmin()) select "<lightblue>" + Players[ply].username + "<end>").ToList();
  592. List<List<string>> Chuncks = SplitList(PlayerNames);
  593.  
  594. Tell(player, "<white>" + GetMsg("Players List Title") + "<end>");
  595.  
  596. if (EnableChatSeparators)
  597. Tell(player, Seperator, prefix: false);
  598.  
  599. foreach (List<string> lis in Chuncks)
  600. Tell(player, String.Join(", ", lis.ToArray()), prefix: false);
  601. }
  602.  
  603. void AdminsList_Command(BasePlayer player, string command, string[] args)
  604. {
  605. List<string> Active = GetActivePlayersList();
  606. List<string> PlayerNames = (from ply in Active where Players[ply].isadmin select "<cyan>" + Players[ply].username + "<end>").ToList();
  607.  
  608. if (HideAdmins && !(player.IsAdmin()))
  609. Tell(player, GetMsg("No Admins Online"));
  610. else
  611. {
  612. List<List<string>> Chuncks = SplitList(PlayerNames);
  613.  
  614. Tell(player, "<white>" + GetMsg("Admins List Title") + "<end>");
  615.  
  616. if (EnableChatSeparators)
  617. Tell(player, Seperator, prefix: false);
  618.  
  619. foreach (List<string> lis in Chuncks)
  620. Tell(player, String.Join(", ", lis.ToArray()), prefix: false);
  621. }
  622. }
  623.  
  624. void ServerRules_Command(BasePlayer player, string command, string[] args)
  625. {
  626. string arg = string.Join(" ", args).ToUpper();
  627. string lang = GetLanguage(player);
  628. string name = "Unknown";
  629. Dictionary<string, object> Rules = (Dictionary<string, object>) Config.Get("Rules");
  630.  
  631. if (Rules.Count == 0)
  632. return;
  633.  
  634. if (!String.IsNullOrEmpty(arg) && Rules.ContainsKey(arg))
  635. {
  636. lang = arg;
  637. }
  638. else if (arg == "LIST")
  639. {
  640. Tell(player, "<white>" + GetMsg("Rules Languages List Title") + "<end>");
  641.  
  642. if (EnableChatSeparators)
  643. Tell(player, Seperator, prefix: false);
  644.  
  645. List<string> langs = new List<string>();
  646.  
  647. foreach (var item in Rules)
  648. {
  649. if (Countries.ContainsKey(item.Key))
  650. name = Countries[item.Key];
  651. else
  652. name = item.Key;
  653. langs.Add("<orange>" + name + "<end> (" + item.Key + ")");
  654. }
  655.  
  656. List<List<string>> Chuncks = SplitList(langs);
  657.  
  658. foreach (List<string> lis in Chuncks)
  659. Tell(player, String.Join(", ", lis.ToArray()), prefix: false);
  660.  
  661. return;
  662. }
  663.  
  664. if (Countries.ContainsKey(lang))
  665. name = Countries[lang];
  666. else
  667. name = lang.ToUpper();
  668.  
  669. Tell(player, "<white>" + GetMsg("Server Rules Title") + "<end>");
  670.  
  671. if (EnableChatSeparators)
  672. Tell(player, Seperator, prefix: false);
  673.  
  674. List<string> ItemList = ConvertList(Rules[lang]);
  675.  
  676. foreach (string line in ItemList)
  677. Tell(player, "<orange>" + line + "<end>", prefix: false);
  678.  
  679. if (EnableChatSeparators)
  680. Tell(player, Seperator, prefix: false);
  681.  
  682. Tell(player, "<white>Displaying <yellow>" + name + "<end> rules<end>", prefix: false);
  683. }
  684.  
  685. void PluginsList_Command(BasePlayer player, string command, string[] args)
  686. {
  687. Tell(player, "<white>" + GetMsg("Plugins List Title") + "<end>");
  688.  
  689. if (EnableChatSeparators)
  690. Tell(player, Seperator, prefix: false);
  691.  
  692. foreach (var p in plugins.GetAll())
  693. {
  694. if (p.Author != "Oxide Team")
  695. Tell(player, String.Format("<orange>{0}<end> <grey>v{1}<end> <silver>{2}<end>", p.Title, p.Version, p.Author), prefix: false);
  696. }
  697. }
  698.  
  699. void ServerMOTD_Command(BasePlayer player, string command, string[] args)
  700. {
  701. string arg = string.Join(" ", args);
  702.  
  703. if (!String.IsNullOrEmpty(arg))
  704. {
  705. Motd = arg;
  706. SetConfig("Message Of The Day", Motd);
  707. SaveConfig();
  708. Tell(player, "MOTD changed to: <white>" + Motd + "<end>");
  709. return;
  710. }
  711.  
  712. Tell(player, "<white>" + GetMsg("Server MOTD Title") + "<end>");
  713.  
  714. if (EnableChatSeparators)
  715. Tell(player, Seperator, prefix: false);
  716.  
  717. Tell(player, GetNameFormats("<white>" + Motd + "<end>"), prefix: false);
  718. }
  719.  
  720. void PlayersCount_Command(BasePlayer player, string command, string[] args) { Tell(player, GetNameFormats(GetMsg("Players Count Message"))); }
  721.  
  722. void ServerMap_Command(BasePlayer player, string command, string[] args) { Tell(player, GetNameFormats(GetMsg("Server Map Message"))); }
  723.  
  724. [ChatCommand("notifier")]
  725. void Plugin_Command(BasePlayer player, string command, string[] args)
  726. {
  727. string arg = string.Join(" ", args);
  728.  
  729. if (arg == "help")
  730. {
  731. Dictionary<string, object> Settings = (Dictionary<string, object>) Config.Get("Commands", "Settings");
  732.  
  733. foreach (var cmd in Settings)
  734. {
  735. if ((bool)cmd.Value)
  736. {
  737. List<string> triggers = ConvertList(Config.Get("Commands", "Triggers", cmd.Key));
  738. string row = string.Join("<silver>,<end> /", triggers.ToArray());
  739. Tell(player, "<orange>" + row + "<end> - <lightblue>" + GetMsg(cmd.Key + " Description") + "<end>", prefix: false);
  740. }
  741. }
  742. }
  743. else
  744. {
  745. Tell(player, "<cyan><size=18>NOTIFIER</size><end> <grey>v" + this.Version + "<end>", "76561198235146288", false);
  746. Tell(player, this.Description, prefix: false);
  747. Tell(player, "Powered by <orange>Oxide 2<end> and developed by <#9810FF>SkinN<end>", "76561197999302614", false);
  748. }
  749. }
  750.  
  751. #endregion
  752.  
  753. #region Plugin Methods
  754.  
  755. private void WebrequestFilter(int code, string response, BasePlayer player, bool sendJoinMessages)
  756. {
  757. try
  758. {
  759. string uid = player.UserIDString;
  760.  
  761. if (!(response == null || code != 200))
  762. {
  763. if (Players.ContainsKey(uid))
  764. {
  765. var json = JObject.Parse(response);
  766. string country = (string) json["country"];
  767. string cCode = (string) json["countryCode"];
  768. if (country != null)
  769. Players[uid].country = country;
  770. if (cCode != null)
  771. Players[uid].countrycode = cCode;
  772. }
  773. }
  774. } catch {}
  775.  
  776. if (sendJoinMessages)
  777. JoinMessages(player);
  778. }
  779.  
  780. private void JoinMessages(BasePlayer player)
  781. {
  782. try
  783. {
  784. if (EnableJoinMessage && NotHide(player))
  785. {
  786. Say(GetNameFormats(GetMsg("Join Message"), player));
  787. string sep = string.Join("\n", new string[50 + 1]);
  788. Tell(player, sep, prefix: false);
  789. }
  790. if (EnableWelcomeMessage)
  791. {
  792. List<string> WelcomeMessage = ConvertList(Config.Get("Welcome Messages"));
  793. foreach (string line in WelcomeMessage)
  794. Tell(player, GetNameFormats(line, player), prefix: false);
  795. }
  796. } catch {}
  797. }
  798.  
  799. private void SendAdvert()
  800. {
  801. List<string> Adverts = ConvertList(Config.Get("Advert Messages"));
  802. int index = LastAdvert;
  803.  
  804. // Is there more than one Advert?
  805. if (Adverts.Count > 1)
  806. {
  807. // Loop untill it gets a different advert
  808. while (index == LastAdvert)
  809. index = AdvertsLoop.Next(Adverts.Count);
  810. }
  811.  
  812. LastAdvert = index;
  813.  
  814. Say(GetNameFormats((string) Adverts[index]));
  815. }
  816.  
  817. private void CheckScheduledMessages()
  818. {
  819. Dictionary<string, object> ScheduleMessages = (Dictionary<string, object>) Config.Get("Schedule Messages");
  820. DateTime Now = DateTime.Now;
  821. string cur = Pads(Now.Hour.ToString()) + ":" + Pads(Now.Second.ToString());
  822.  
  823. if (ScheduleMessages.ContainsKey(cur))
  824. {
  825. List<string> ItemList = ConvertList(ScheduleMessages[cur]);
  826. foreach (string line in ItemList)
  827. Say(GetNameFormats(line));
  828. }
  829. }
  830.  
  831. private string GetLanguage(BasePlayer player = null)
  832. {
  833. string lang = "EN";
  834. string DefaultLang = RulesDefaultLanguage.ToUpper();
  835. Dictionary<string, object> Rules = (Dictionary<string, object>) Config.Get("Rules");
  836.  
  837. if (player != null && DefaultLang == "AUTO")
  838. {
  839. string PlyLang = Players[player.UserIDString].countrycode;
  840. if (Rules.ContainsKey(PlyLang))
  841. lang = PlyLang;
  842. }
  843. else if (Rules.ContainsKey(DefaultLang))
  844. lang = DefaultLang;
  845.  
  846. return lang;
  847. }
  848.  
  849. private string GetNameFormats(string text, BasePlayer player = null)
  850. {
  851.  
  852. int Active = BasePlayer.activePlayerList.Count;
  853. int Sleepers = BasePlayer.sleepingPlayerList.Count;
  854. DateTime Now = DateTime.Now;
  855. string time = TimeFormat.Replace("{hour}", Pads(Now.Hour.ToString())).Replace("{minute}", Pads(Now.Minute.ToString())).Replace("{second}", Pads(Now.Second.ToString()));
  856. string date = DateFormat.Replace("{year}", Now.Year.ToString()).Replace("{month}", Pads(Now.Month.ToString())).Replace("{day}", Pads(Now.Day.ToString()));
  857.  
  858. #region Server Side
  859. Dictionary<string, object> Dict = new Dictionary<string, object> {
  860. { "{server.ip}", ConVar.Server.ip },
  861. { "{server.port}", ConVar.Server.port },
  862. { "{server.hostname}", ConVar.Server.hostname },
  863. { "{server.description}", ConVar.Server.description},
  864. { "{server.maxplayers}", ConVar.Server.maxplayers },
  865. { "{server.worldsize}", ConVar.Server.worldsize },
  866. { "{server.seed}", ConVar.Server.seed },
  867. { "{server.level}", ConVar.Server.level },
  868. { "{localtime.now}", time},
  869. { "{localtime.date}", date},
  870. { "{players.active}", Active },
  871. { "{players.sleepers}", Sleepers },
  872. { "{players.total}", Active + Sleepers }
  873. };
  874. #endregion
  875.  
  876. #region Player Side
  877.  
  878. if (player != null)
  879. {
  880. string uid = player.UserIDString;
  881. if (Players.ContainsKey(uid))
  882. {
  883. Dict.Add("{player.name}", Players[uid].username);
  884. Dict.Add("{player.country}", Players[uid].country);
  885. Dict.Add("{player.countrycode}", Players[uid].countrycode);
  886. Dict.Add("{player.ip}", Players[uid].ipaddress);
  887. Dict.Add("{player.uid}", Players[uid].steamid);
  888. }
  889. }
  890.  
  891. #endregion
  892.  
  893. foreach (var kvp in Dict)
  894. text = text.Replace(kvp.Key, kvp.Value.ToString());
  895.  
  896. return text;
  897. }
  898.  
  899. private static List<List<string>> SplitList(List<string> names, int nSize = 3)
  900. {
  901. var list = new List<List<string>>();
  902. for (int i = 0; i < names.Count; i += nSize)
  903. list.Add(names.GetRange(i, Math.Min(nSize, names.Count - i)));
  904. return list;
  905. }
  906.  
  907. private bool NotHide(BasePlayer player) { return (!(HideAdmins && player.IsAdmin())); }
  908.  
  909. private List<string> GetActivePlayersList() { return (from ply in BasePlayer.activePlayerList where (Players.ContainsKey(ply.UserIDString)) select ply.UserIDString).ToList(); }
  910.  
  911. private string Pads(string target, int number = 2) { return target.PadLeft(number, '0'); }
  912.  
  913. void SendHelpText(BasePlayer player) { Tell(player, GetMsg("Help Text Message")); }
  914.  
  915. #endregion
  916. }
  917. }
Advertisement
Add Comment
Please, Sign In to add comment