From 49a0cc0cc50deeb28314e41a6aabf846c18b08a2 Mon Sep 17 00:00:00 2001 From: DogooFalchion Date: Sun, 23 Oct 2016 19:59:57 -0400 Subject: [PATCH] Add permission for uploading other's SSC data. Allow this to run from console. Allow command to upload remote user's data. --- TShockAPI/Commands.cs | 56 +++++++++++++++++++++++++++++++++++----- TShockAPI/Permissions.cs | 3 +++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 25641be2..846825fa 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -300,8 +300,7 @@ namespace TShockAPI }); add(new Command(Permissions.uploaddata, UploadJoinData, "uploadssc") { - HelpText = "Upload the account information when you joined the server as your Server Side Character data.", - AllowServer = false + HelpText = "Upload the account information when you joined the server as your Server Side Character data." }); add(new Command(Permissions.settempgroup, TempGroup, "tempgroup") { @@ -1698,13 +1697,58 @@ namespace TShockAPI private static void UploadJoinData(CommandArgs args) { - if (TShock.CharacterDB.InsertSpecificPlayerData(args.Player, args.Player.DataWhenJoined)) { - args.Player.DataWhenJoined.RestoreCharacter(args.Player); - args.Player.SendSuccessMessage("Your Join Data has been uploaded to the server."); + TSPlayer targetPlayer = args.Player; + if (args.Parameters.Count == 1 && args.Player.HasPermission(Permissions.uploadothersdata)) + { + List players = TShock.Utils.FindPlayer(args.Parameters[0]); + if (players.Count > 1) + { + TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name)); + return; + } + else if (players.Count == 0) + { + args.Player.SendErrorMessage("No player was found matching'{0}'", args.Parameters[0]); + return; + } + else + { + targetPlayer = players[0]; + } + } + else if (args.Parameters.Count == 1) + { + args.Player.SendErrorMessage("You do not have permission to upload another player's data."); + return; + } + else if (args.Parameters.Count > 0) + { + args.Player.SendErrorMessage("Usage: /uploadssc [playername]"); + return; + } + else if (args.Parameters.Count == 0 && args.Player is TSServerPlayer) + { + args.Player.SendErrorMessage("A console can not upload their player data."); + args.Player.SendErrorMessage("Usage: /uploadssc [playername]"); + return; + } + + if (targetPlayer.IsLoggedIn) + { + if (TShock.CharacterDB.InsertSpecificPlayerData(targetPlayer, targetPlayer.DataWhenJoined)) + { + targetPlayer.DataWhenJoined.RestoreCharacter(targetPlayer); + targetPlayer.SendSuccessMessage("Your Join Data has been uploaded to the server."); + args.Player.SendSuccessMessage("The player's data was successfully uploaded."); + } + else + { + args.Player.SendErrorMessage("Failed to upload your data, are you logged in to an account?"); + } } else { - args.Player.SendErrorMessage("Failed to upload your data, please find an admin."); + args.Player.SendErrorMessage("The target player has not logged in yet."); } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index fef9683d..3d3734e4 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -91,6 +91,9 @@ namespace TShockAPI [Description("User can upload their joined character data as SSC data.")] public static readonly string uploaddata = "tshock.ssc.upload"; + [Description("User can upload other players join data to the SSC database.")] + public static readonly string uploadothersdata = "tshock.ssc.upload.others"; + [Description("User can elevate other users' groups temporarily.")] public static readonly string settempgroup = "tshock.admin.tempgroup";