diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a4ddb549..2fcfa3c7 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -244,6 +244,10 @@ namespace TShockAPI DoLog = false, HelpText = "Registers you an account." }); + add(new Command(Permissions.checkaccountinfo, ViewAccountInfo, "accountinfo", "ai") + { + HelpText = "Shows information about a user." + }); #endregion #region Admin Commands add(new Command(Permissions.ban, Ban, "ban") @@ -300,7 +304,7 @@ namespace TShockAPI }); add(new Command(Permissions.userinfo, GrabUserUserInfo, "userinfo", "ui") { - HelpText = "Shows information about a user." + HelpText = "Shows information about a player." }); #endregion #region Annoy Commands @@ -1205,6 +1209,43 @@ namespace TShockAPI } } + private static void ViewAccountInfo(CommandArgs args) + { + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}accountinfo ", Specifier); + return; + } + + string username = String.Join(" ", args.Parameters); + if (!string.IsNullOrWhiteSpace(username)) + { + var user = TShock.Users.GetUserByName(username); + if (user != null) + { + DateTime LastSeen = DateTime.Parse(user.LastAccessed).ToLocalTime(); + string Timezone = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours.ToString("+#;-#"); + + args.Player.SendSuccessMessage("{0}'s last login occured {1} {2} UTC{3}.", user.Name, LastSeen.ToShortDateString(), + LastSeen.ToShortTimeString(), Timezone); + + if (args.Player.Group.HasPermission(Permissions.advaccountinfo)) + { + List KnownIps = JsonConvert.DeserializeObject>(user.KnownIps); + string ip = KnownIps[KnownIps.Count - 1]; + DateTime Registered = DateTime.Parse(user.Registered).ToLocalTime(); + + args.Player.SendSuccessMessage("{0}'s group is {1}.", user.Name, user.Group); + args.Player.SendSuccessMessage("{0}'s last known IP is {1}.", user.Name, ip); + args.Player.SendSuccessMessage("{0}'s register date is {1} {2} UTC{3}.", user.Name, Registered.ToShortDateString(), Registered.ToShortTimeString(), Timezone); + } + } + else + args.Player.SendErrorMessage("User {0} does not exist.", username); + } + else args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}accountinfo ", Specifier); + } + private static void Kick(CommandArgs args) { if (args.Parameters.Count < 1) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 35ac2b60..7aaf6f86 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -388,6 +388,12 @@ namespace TShockAPI [Description("Player can place banned tiles.")] public static readonly string canusebannedtiles = "tshock.tiles.usebanned"; + + [Description("Player can check if a username is registered and see its last login time.")] + public static readonly string checkaccountinfo = "tshock.accountinfo.check"; + + [Description("Player can see advanced information about any user account.")] + public static readonly string advaccountinfo = "tshock.accountinfo.details"; /// /// Lists all commands associated with a given permission /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index be37a462..2d3c4026 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -412,8 +412,8 @@ namespace TShockAPI KnownIps = JsonConvert.DeserializeObject>(args.Player.User.KnownIps); } - bool found = KnownIps.Any(s => s.Equals(args.Player.IP)); - if (!found) + bool last = KnownIps.Last() == args.Player.IP; + if (!last) { if (KnownIps.Count == 100) { @@ -1467,9 +1467,15 @@ namespace TShockAPI /// The CommandEventArgs object private void ServerHooks_OnCommand(CommandEventArgs args) { - if (args.Handled || string.IsNullOrWhiteSpace(args.Command)) + if (args.Handled) return; + if (string.IsNullOrWhiteSpace(args.Command)) + { + args.Handled = true; + return; + } + // Damn you ThreadStatic and Redigit if (Main.rand == null) {