using System; using System.Linq; using System.Reflection; using System.Collections; using System.Collections.Generic; using UnityEngine; using Oxide.Core; using Oxide.Core.Plugins; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Facepunch; using Rust; #region Changelogs and ToDo /********************************************************************** * 1.0.0 : * 1.0.1 : Added consolecommand : position.all * Added consolecommand : position.sleepers * Added consolecheck * 1.0.2 : Placed the calls under coroutines for performance * Added Logfile online * Added logfile sleepers * 1.0.3 : Belated patch for dec rust update * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("MyLocation", "Krungh Crow", "1.0.3")] [Description("Prints players current locations to console/chat/logfile")] class MyLocation : RustPlugin { #region Variables const ulong chaticon = 0; const string prefix = "[MyLocation] "; bool IsAdmin { get; } #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["All"] = "Printing all online players and current locations to console", ["Commands"] = "Current commands to use :\n/position : Your position\n/position.all : Online players\n/position.sleepers : All sleepers", ["NoPermission"] = "You do not have permission to use that command!", ["NoSleepersFound"] = "No sleepers found!", ["Personal"] = "Printed to console\n{0} : location = {1} Grid : {2}", ["Sleepers"] = "Printing all sleeping players and current locations to console", }, this); } #endregion #region ConsoleCommands private bool Consolesafe(ConsoleSystem.Arg arg) { if (arg.Connection != null && (arg.Connection.authLevel < 1)) { SendReply(arg, msg($"NoPermission", null)); return false; } return true; } [ConsoleCommand("position.all")] private void consolePositionAll(ConsoleSystem.Arg arg) { if (!Consolesafe(arg)) return; SendReply(arg, msg($"All", null)); ServerMgr.Instance.StartCoroutine(PutAll()); } [ConsoleCommand("position.sleepers")] private void consolePositionSleep(ConsoleSystem.Arg arg) { if (!Consolesafe(arg)) return; if (BasePlayer.sleepingPlayerList.Count() == 0) { SendReply(arg, msg($"NoSleepersFound", null)); return; } SendReply(arg, msg($"Sleepers", null)); ServerMgr.Instance.StartCoroutine(PutSleepers()); } #endregion #region ChatCommands [ChatCommand("position")] private void cmdPosition(BasePlayer player, string command, string[] args) { if(player.IsAdmin == true) { Puts($"Personal : {player.displayName} : location = {player.transform.position} Grid : {GetGrid(player.transform.position)}"); Player.Message(player, prefix + string.Format(msg($"Personal", player.UserIDString), player.displayName, player.transform.position, GetGrid(player.transform.position)), chaticon); Player.Message(player, prefix + string.Format(msg($"Commands", player.UserIDString), player.displayName, player.transform.position, GetGrid(player.transform.position)), chaticon); return; } if (!IsAdmin) { Player.Message(player,prefix + string.Format(msg("NoPermission", player.UserIDString)), chaticon); return; } } [ChatCommand("position.all")] private void cmdPositionAll(BasePlayer player, string command, string[] args) { if (player.IsAdmin == true) { Player.Message(player, prefix + string.Format(msg($"All", player.UserIDString)), chaticon); ServerMgr.Instance.StartCoroutine(PutAll()); return; } if (!IsAdmin) { Player.Message(player, prefix + string.Format(msg("NoPermission", player.UserIDString)), chaticon); return; } } [ChatCommand("position.sleepers")] private void cmdPositionSleep(BasePlayer player, string command, string[] args) { if (player.IsAdmin == true) { if (BasePlayer.sleepingPlayerList.Count() == 0) { Player.Message(player, prefix + string.Format(msg($"NoSleepersFound", player.UserIDString)), chaticon); return; } Player.Message(player, prefix + string.Format(msg($"Sleepers", player.UserIDString)), chaticon); ServerMgr.Instance.StartCoroutine(PutSleepers()); return; } if (!IsAdmin) { Player.Message(player, prefix + string.Format(msg("NoPermission", player.UserIDString)), chaticon); return; } } #endregion #region Methods private IEnumerator PutSleepers() { if (BasePlayer.sleepingPlayerList.Count() == 0) { Puts("No sleepers found !"); yield break ; } LogToFile("sleepers", $"\n----------------------------\n{DateTime.Now}\n----------------------------\n", this); foreach (var players in BasePlayer.sleepingPlayerList) { var MSG = $"Sleeper : {players} : location = {players.transform.position} Grid : {GetGrid(players.transform.position)}"; if (players != null) { Puts(MSG); LogToFile("sleepers", MSG, this); } yield return CoroutineEx.waitForSeconds(0.01f); } } private IEnumerator PutAll() { if (BasePlayer.activePlayerList.Count() == 0) { Puts("No online players found !"); yield break; } LogToFile("online", $"\n----------------------------\n{DateTime.Now}\n----------------------------\n", this); foreach (var players in BasePlayer.activePlayerList) { var MSG = $"Online : {players} : location = {players.transform.position} Grid : {GetGrid(players.transform.position)}"; if (players != null) { Puts(MSG); LogToFile("online", MSG, this); } yield return CoroutineEx.waitForSeconds(0.01f); } } private string msg(string key, string id = null) => lang.GetMessage(key, this, id); private static string GetGrid(Vector3 position) => MapHelper.PositionToString(position); #endregion } }