private object ServerStatusV2(RestRequestArgs args) { var ret = new RestObject() { { "name", TShock.Config.ServerName }, { "serverversion", Main.versionNumber }, { "tshockversion", TShock.VersionNum }, { "port", TShock.Config.ServerPort }, { "playercount", Main.player.Where(p => null != p && p.active).Count() }, { "maxplayers", TShock.Config.MaxSlots }, { "world", Main.worldName }, { "uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss") }, { "serverpassword", !string.IsNullOrEmpty(TShock.Config.ServerPassword) } }; if (GetBool(args.Parameters["players"], false)) { var players = new ArrayList(); foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p)) { var p = PlayerFilter(tsPlayer, args.Parameters, ((args.TokenData.UserGroupName) != "" && TShock.Utils.GetGroup(args.TokenData.UserGroupName).HasPermission(RestPermissions.viewips))); if (null != p) { players.Add(p); } } ret.Add("players", players); } if (GetBool(args.Parameters["rules"], false)) { var rules = new Dictionary <string, object>(); rules.Add("AutoSave", TShock.Config.AutoSave); rules.Add("DisableBuild", TShock.Config.DisableBuild); rules.Add("DisableClownBombs", TShock.Config.DisableClownBombs); rules.Add("DisableDungeonGuardian", TShock.Config.DisableDungeonGuardian); rules.Add("DisableInvisPvP", TShock.Config.DisableInvisPvP); rules.Add("DisableSnowBalls", TShock.Config.DisableSnowBalls); rules.Add("DisableTombstones", TShock.Config.DisableTombstones); rules.Add("EnableWhitelist", TShock.Config.EnableWhitelist); rules.Add("HardcoreOnly", TShock.Config.HardcoreOnly); rules.Add("PvPMode", TShock.Config.PvPMode); rules.Add("SpawnProtection", TShock.Config.SpawnProtection); rules.Add("SpawnProtectionRadius", TShock.Config.SpawnProtectionRadius); rules.Add("ServerSideInventory", Main.ServerSideCharacter); ret.Add("rules", rules); } return(ret); }
private object ServerStatusV2(RestVerbs verbs, IParameterCollection parameters) { if (TShock.Config.EnableTokenEndpointAuthentication) { return(RestError("Server settings require a token for this API call")); } var ret = new RestObject() { { "name", TShock.Config.ServerName }, { "port", TShock.Config.ServerPort }, { "playercount", Main.player.Where(p => null != p && p.active).Count() }, { "maxplayers", TShock.Config.MaxSlots }, { "world", Main.worldName } }; if (GetBool(parameters["players"], false)) { var players = new ArrayList(); foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p)) { var p = PlayerFilter(tsPlayer, parameters); if (null != p) { players.Add(p); } } ret.Add("players", players); } if (GetBool(parameters["rules"], false)) { var rules = new Dictionary <string, object>(); rules.Add("AutoSave", TShock.Config.AutoSave); rules.Add("DisableBuild", TShock.Config.DisableBuild); rules.Add("DisableClownBombs", TShock.Config.DisableClownBombs); rules.Add("DisableDungeonGuardian", TShock.Config.DisableDungeonGuardian); rules.Add("DisableInvisPvP", TShock.Config.DisableInvisPvP); rules.Add("DisableSnowBalls", TShock.Config.DisableSnowBalls); rules.Add("DisableTombstones", TShock.Config.DisableTombstones); rules.Add("EnableWhitelist", TShock.Config.EnableWhitelist); rules.Add("HardcoreOnly", TShock.Config.HardcoreOnly); rules.Add("PvPMode", TShock.Config.PvPMode); rules.Add("SpawnProtection", TShock.Config.SpawnProtection); rules.Add("SpawnProtectionRadius", TShock.Config.SpawnProtectionRadius); ret.Add("rules", rules); } return(ret); }
private object UserUpdateV2(RestVerbs verbs, IParameterCollection parameters) { var ret = UserFind(parameters); if (ret is RestObject) { return(ret); } var password = parameters["password"]; var group = parameters["group"]; if (string.IsNullOrWhiteSpace(group) && string.IsNullOrWhiteSpace(password)) { return(RestMissingParam("group", "password")); } User user = (User)ret; var response = new RestObject(); if (!string.IsNullOrWhiteSpace(password)) { try { TShock.Users.SetUserPassword(user, password); response.Add("password-response", "Password updated successfully"); } catch (Exception e) { return(RestError("Failed to update user password (" + e.Message + ")")); } } if (!string.IsNullOrWhiteSpace(group)) { try { TShock.Users.SetUserGroup(user, group); response.Add("group-response", "Group updated successfully"); } catch (Exception e) { return(RestError("Failed to update user group (" + e.Message + ")")); } } return(response); }
private object PlayerKills(RestRequestArgs args) { var Name = args.Parameters["name"]; // Checks if parameters exists if (string.IsNullOrWhiteSpace(Name)) { return(RestMissingParam("name")); } // Gets and checks if result (kills) are not empty var Kills = DB.GetKills(Name); if (Kills == null) { return(RestError("Invalid name")); } var Result = new RestObject(); foreach (var Row in Kills) { Result.Add(Row.Key, Row.Value); } return(Result); }
private object AllPlayersKills(RestRequestArgs args) { // Gets and checks if result (kills) are not empty var AllKills = DB.GetAllKills(); if (AllKills == null) { return RestError("Empty database"); } var Result = new RestObject(); foreach (var Row in AllKills) { Result.Add(Row.Key, Row.Value); } return Result; }
private object AllPlayersKills(RestRequestArgs args) { // Gets and checks if result (kills) are not empty var AllKills = DB.GetAllKills(); if (AllKills == null) { return(RestError("Empty database")); } var Result = new RestObject(); foreach (var Row in AllKills) { Result.Add(Row.Key, Row.Value); } return(Result); }
private object ServerCommand(RestVerbs verbs, IParameterCollection parameters) { if (parameters["cmd"] != null && parameters["cmd"].Trim() != "") { TSRestPlayer tr = new TSRestPlayer(); RestObject ro = new RestObject("200"); Commands.HandleCommand(tr, parameters["cmd"]); foreach (string s in tr.GetCommandOutput()) { ro.Add("response", s); } return(ro); } RestObject fail = new RestObject("400"); fail["response"] = "Missing or blank cmd parameter."; return(fail); }
private object AllPlayersStats(RestRequestArgs args) { // Gets and checks if result (stats) are not empty var AllStats = DB.GetAllStats(); if (AllStats == null) { return(RestError("Empty database")); } var Result = new RestObject(); foreach (var Row in AllStats) { Result.Add(Row.Key, new Dictionary <string, int>() { { "tiles_destroyed", Row.Value[0] }, { "tiles_placed", Row.Value[1] }, { "deaths", Row.Value[2] } }); } return(Result); }
private object UserUpdateV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData) { var ret = UserFind(parameters); if (ret is RestObject) return ret; var password = parameters["password"]; var group = parameters["group"]; if (string.IsNullOrWhiteSpace(group) && string.IsNullOrWhiteSpace(password)) return RestMissingParam("group", "password"); User user = (User)ret; var response = new RestObject(); if (!string.IsNullOrWhiteSpace(password)) { try { TShock.Users.SetUserPassword(user, password); response.Add("password-response", "Password updated successfully"); } catch (Exception e) { return RestError("Failed to update user password (" + e.Message + ")"); } } if (!string.IsNullOrWhiteSpace(group)) { try { TShock.Users.SetUserGroup(user, group); response.Add("group-response", "Group updated successfully"); } catch (Exception e) { return RestError("Failed to update user group (" + e.Message + ")"); } } return response; }
private object ServerStatusV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData) { var ret = new RestObject() { {"name", TShock.Config.ServerName}, {"port", TShock.Config.ServerPort}, {"playercount", Main.player.Where(p => null != p && p.active).Count()}, {"maxplayers", TShock.Config.MaxSlots}, {"world", Main.worldName}, {"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")}, {"serverpassword", !string.IsNullOrEmpty(TShock.Config.ServerPassword)} }; if (GetBool(parameters["players"], false)) { var players = new ArrayList(); foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p)) { var p = PlayerFilter(tsPlayer, parameters, ((tokenData.UserGroupName) != "" && TShock.Utils.GetGroup(tokenData.UserGroupName).HasPermission(RestPermissions.viewips))); if (null != p) players.Add(p); } ret.Add("players", players); } if (GetBool(parameters["rules"], false)) { var rules = new Dictionary<string,object>(); rules.Add("AutoSave", TShock.Config.AutoSave); rules.Add("DisableBuild", TShock.Config.DisableBuild); rules.Add("DisableClownBombs", TShock.Config.DisableClownBombs); rules.Add("DisableDungeonGuardian", TShock.Config.DisableDungeonGuardian); rules.Add("DisableInvisPvP", TShock.Config.DisableInvisPvP); rules.Add("DisableSnowBalls", TShock.Config.DisableSnowBalls); rules.Add("DisableTombstones", TShock.Config.DisableTombstones); rules.Add("EnableWhitelist", TShock.Config.EnableWhitelist); rules.Add("HardcoreOnly", TShock.Config.HardcoreOnly); rules.Add("PvPMode", TShock.Config.PvPMode); rules.Add("SpawnProtection", TShock.Config.SpawnProtection); rules.Add("SpawnProtectionRadius", TShock.Config.SpawnProtectionRadius); rules.Add("ServerSideInventory", TShock.Config.ServerSideCharacter); ret.Add("rules", rules); } return ret; }
private object ServerStatusV2(RestVerbs verbs, IParameterCollection parameters) { if (TPulse.Config.EnableTokenEndpointAuthentication) return RestError("Server settings require a token for this API call"); var ret = new RestObject() { {"name", TPulse.Config.ServerName}, {"port", TPulse.Config.ServerPort}, {"playercount", Main.player.Where(p => null != p && p.active).Count()}, {"maxplayers", TPulse.Config.MaxSlots}, {"world", Main.worldName} }; if (GetBool(parameters["players"], false)) { var players = new ArrayList(); foreach (TPPlayer tsPlayer in TPulse.Players.Where(p => null != p)) { var p = PlayerFilter(tsPlayer, parameters); if (null != p) players.Add(p); } ret.Add("players", players); } if (GetBool(parameters["rules"], false)) { var rules = new Dictionary<string,object>(); rules.Add("AutoSave", TPulse.Config.AutoSave); rules.Add("DisableBuild", TPulse.Config.DisableBuild); rules.Add("DisableClownBombs", TPulse.Config.DisableClownBombs); rules.Add("DisableDungeonGuardian", TPulse.Config.DisableDungeonGuardian); rules.Add("DisableInvisPvP", TPulse.Config.DisableInvisPvP); rules.Add("DisableSnowBalls", TPulse.Config.DisableSnowBalls); rules.Add("DisableTombstones", TPulse.Config.DisableTombstones); rules.Add("EnableWhitelist", TPulse.Config.EnableWhitelist); rules.Add("HardcoreOnly", TPulse.Config.HardcoreOnly); rules.Add("PvPMode", TPulse.Config.PvPMode); rules.Add("SpawnProtection", TPulse.Config.SpawnProtection); rules.Add("SpawnProtectionRadius", TPulse.Config.SpawnProtectionRadius); ret.Add("rules", rules); } return ret; }
private object AllPlayersStats(RestRequestArgs args) { // Gets and checks if result (stats) are not empty var AllStats = DB.GetAllStats(); if (AllStats == null) { return RestError("Empty database"); } var Result = new RestObject(); foreach (var Row in AllStats) { Result.Add(Row.Key, new Dictionary<string, int>(){ {"tiles_destroyed", Row.Value[0]}, {"tiles_placed", Row.Value[1]}, {"deaths", Row.Value[2]}}); } return Result; }
private object PlayerKills(RestRequestArgs args) { var Name = args.Parameters["name"]; // Checks if parameters exists if (string.IsNullOrWhiteSpace(Name)) { return RestMissingParam("name"); } // Gets and checks if result (kills) are not empty var Kills = DB.GetKills(Name); if (Kills == null) { return RestError("Invalid name"); } var Result = new RestObject(); foreach (var Row in Kills) { Result.Add(Row.Key, Row.Value); } return Result; }
private object ServerCommand(RestVerbs verbs, IParameterCollection parameters) { if (parameters["cmd"] != null && parameters["cmd"].Trim() != "") { TSRestPlayer tr = new TSRestPlayer(); RestObject ro = new RestObject("200"); Commands.HandleCommand(tr, parameters["cmd"]); foreach (string s in tr.GetCommandOutput()) { ro.Add("response", s); } return ro; } RestObject fail = new RestObject("400"); fail["response"] = "Missing or blank cmd parameter."; return fail; }