コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: main.cs プロジェクト: UB1AFU/ExtraRest
        public static RestObject Staff(RestRequestArgs args)
        {
            GroupManager groupmanager = new GroupManager(TShock.DB);
            UserManager usermanager = new UserManager(TShock.DB);

            List<string> groups = groupmanager.groups.FindAll(g => g.HasPermission("tshock.admin.kick")).Select(g => g.Name).ToList();

            List<User> users = usermanager.GetUsers().Where(u => groups.Contains(u.Group)).ToList();
            Dictionary<string, List<string>> RestGroups = new Dictionary<string, List<string>>();

            for (int i = 0; i < groups.Count; i++)
                RestGroups[groups[i]] = users.Where(u => u.Group == groups[i]).Select(u => u.Name).ToList();

            return new RestObject()
            {
                { "StaffList",  RestGroups },
            };
        }
コード例 #3
0
ファイル: main.cs プロジェクト: UB1AFU/ExtraRest
        public static RestObject WhiteList(RestRequestArgs args)
        {
            string[] whitelist = new[] { "" };
            try
            {
                using (StreamReader sr = new StreamReader(File.Open(Path.Combine(TShock.SavePath, "whitelist.txt"), FileMode.Open)))
                {
                    whitelist = sr.ReadToEnd().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                }

            }
            catch
            {
                whitelist = new[] { "Whitelist not found!" };
            }
            return new RestObject()
            {
                    { "WhiteList", whitelist}
            };
        }
コード例 #4
0
ファイル: VersionInfo.cs プロジェクト: Grandpa-G/VersionInfo
        private object getPlugins(RestRequestArgs args)
        {
            List<PluginList> pluginList = new List<PluginList>();
            PluginList rec = null;

            for (int i = 0; i < ServerApi.Plugins.Count; i++)
            {
                PluginContainer pc = ServerApi.Plugins.ElementAt(i);
                Console.WriteLine(String.Format("{0} {1} {2} {3}", pc.Plugin.Name, pc.Plugin.Description, pc.Plugin.Author, pc.Plugin.Version), Color.LightSalmon);
                rec = new PluginList(pc.Plugin.Name, pc.Plugin.Description, pc.Plugin.Author, pc.Plugin.Version.ToString());
                pluginList.Add(rec);
            }

            /*
            string ServerPluginsDirectoryPath = Path.Combine(Environment.CurrentDirectory, TerrariaApi.Server.ServerApi.PluginsPath);

            string[] plugins = Directory.GetFiles(ServerPluginsDirectoryPath, "*.DLL");
            Console.WriteLine(ServerPluginsDirectoryPath);
            string excludeDLL = "bcrypt.net.dllhttpserver.dllmono.data.sqlite.dllmysql.data.dllmysql.web.dllnewtonsoft.json.dlltshockapi.dll";
            string version;
            string fileName;
            Assembly asembly = null;
            string pluginName = "";
            Version APIversion = null;
            CustomAttributeData VersionAttribute;
            foreach (string path in plugins)
            {
                fileName = Path.GetFileName(path);
                Console.WriteLine(path);
                if (!excludeDLL.Contains(fileName.ToLower()))
                {
                    asembly = Assembly.LoadFrom(path);
                    Console.Write(fileName);
                    try
                    {
                        version = asembly.FullName;
                        Console.WriteLine(version);
                        IEnumerable<TypeInfo> df = asembly.DefinedTypes;// CustomAttributes.First(Attr => Attr.AttributeType.Name == "ApiVersionAttribute");
                        VersionAttribute = asembly.GetType(df.First().ToString()).CustomAttributes.First(Attr => Attr.AttributeType.Name == "ApiVersionAttribute");

                        APIversion = new Version((int)VersionAttribute.ConstructorArguments[0].Value, (int)VersionAttribute.ConstructorArguments[1].Value);
                        Console.WriteLine(df.First().ToString() + ":" + APIversion.ToString());
                    }
                    catch (Exception ex)
                    {
                        TShock.Log.Error(ex.ToString());
                        Console.WriteLine(ex.StackTrace);
                        version = "??";
                    }
                    Console.WriteLine(fileName + ":" + version);
                 }
            }
            */
            return new RestObject() { { "Plugins", pluginList } };
        }
コード例 #5
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object ServerTokenTest(RestRequestArgs args)
 {
     return new RestObject()
     {
         {"response", "Token is valid and was passed through correctly."},
         {"associateduser", args.TokenData.Username}
     };
 }
コード例 #6
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object ServerStatus(RestRequestArgs args)
 {
     var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
     return new RestObject()
     {
         {"name", TShock.Config.ServerName},
         {"port", Convert.ToString(Netplay.ListenPort)},
         {"playercount", Convert.ToString(activeplayers.Count())},
         {"players", string.Join(", ", activeplayers.Select(p => p.name))},
     };
 }
コード例 #7
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object ServerRestart(RestRequestArgs args)
        {
            if (!GetBool(args.Parameters["confirm"], false))
                return RestInvalidParam("confirm");

            // Inform players the server is shutting down
            var reason = string.IsNullOrWhiteSpace(args.Parameters["message"]) ? "Server is restarting" : args.Parameters["message"];
            TShock.Utils.RestartServer(!GetBool(args.Parameters["nosave"], false), reason);

            return RestResponse("The server is shutting down and will attempt to restart");
        }
コード例 #8
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object ServerMotd(RestRequestArgs args)
        {
            string motdFilePath = Path.Combine(TShock.SavePath, "motd.txt");
            if (!File.Exists(motdFilePath))
                return this.RestError("The motd.txt was not found.", "500");

            return new RestObject()
            {
                {"motd", File.ReadAllLines(motdFilePath)}
            };
        }
コード例 #9
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object ServerBroadcast(RestRequestArgs args)
 {
     var msg = args.Parameters["msg"];
     if (string.IsNullOrWhiteSpace(msg))
         return RestMissingParam("msg");
     TSPlayer.All.SendInfoMessage(msg);
     return RestResponse("The message was broadcasted successfully");
 }
コード例 #10
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object GroupList(RestRequestArgs args)
 {
     var groups = new ArrayList();
     foreach (Group group in TShock.Groups)
     {
         groups.Add(new Dictionary<string, object> {{"name", group.Name}, {"parent", group.ParentName}, {"chatcolor", group.ChatColor}});
     }
     return new RestObject() { { "groups", groups } };
 }
コード例 #11
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object GroupInfo(RestRequestArgs args)
        {
            var ret = GroupFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            Group group = (Group)ret;
            return new RestObject() {
                {"name", group.Name},
                {"parent", group.ParentName},
                {"chatcolor", string.Format("{0},{1},{2}", group.R, group.G, group.B)},
                {"permissions", group.permissions},
                {"negatedpermissions", group.negatedpermissions},
                {"totalpermissions", group.TotalPermissions}
            };
        }
コード例 #12
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object GroupDestroy(RestRequestArgs args)
        {
            var ret = GroupFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            Group group = (Group)ret;
            try
            {
                TShock.Groups.DeleteGroup(group.Name, true);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("Group '" + group.Name + "' deleted successfully");
        }
コード例 #13
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object GroupCreate(RestRequestArgs args)
        {
            var name = args.Parameters["group"];
            if (string.IsNullOrWhiteSpace(name))
                return RestMissingParam("group");
            try
            {
                TShock.Groups.AddGroup(name, args.Parameters["parent"], args.Parameters["permissions"], args.Parameters["chatcolor"]);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("Group '" + name + "' created successfully");
        }
コード例 #14
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object BanListV2(RestRequestArgs args)
        {
            var banList = new ArrayList();
            foreach (var ban in TShock.Bans.GetBans())
            {
                banList.Add(
                    new Dictionary<string, string>
                    {
                        {"name", null == ban.Name ? "" : ban.Name},
                        {"ip", null == ban.IP ? "" : ban.IP},
                        {"reason", null == ban.Reason ? "" : ban.Reason},
                    }
                );
            }

            return new RestObject() { { "bans", banList } };
        }
コード例 #15
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object BanInfoV2(RestRequestArgs args)
        {
            var ret = BanFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            Ban ban = (Ban)ret;
            return new RestObject() {
                {"name", null == ban.Name ? "" : ban.Name},
                {"ip", null == ban.IP ? "" : ban.IP},
                {"reason", null == ban.Reason ? "" : ban.Reason},
            };
        }
コード例 #16
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object PlayerReadV3(RestRequestArgs args)
        {
            var ret = PlayerFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            var inventory = player.TPlayer.inventory.Where(p => p.active).ToList();
            var equipment = player.TPlayer.armor.Where(p => p.active).ToList();
            var dyes = player.TPlayer.dye.Where(p => p.active).ToList();
            return new RestObject()
            {
                {"nickname", player.Name},
                {"username", null == player.User ? "" : player.User.Name},
                {"ip", player.IP},
                {"group", player.Group.Name},
                {"position", player.TileX + "," + player.TileY},
                {"inventory", string.Join(", ", inventory.Select(p => (p.name + ":" + p.stack)))},
                {"armor", string.Join(", ", equipment.Select(p => (p.netID + ":" + p.prefix)))},
                {"dyes", string.Join(", ", dyes.Select(p => (p.name)))},
                {"buffs", string.Join(", ", player.TPlayer.buffType)}
            };
        }
コード例 #17
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object PlayerUnMute(RestRequestArgs args)
 {
     return PlayerSetMute(args.Parameters, false);
 }
コード例 #18
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object GroupUpdate(RestRequestArgs args)
        {
            var ret = GroupFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            Group group = (Group)ret;
            var parent = (null == args.Parameters["parent"]) ? group.ParentName : args.Parameters["parent"];
            var chatcolor = (null == args.Parameters["chatcolor"]) ? string.Format("{0}.{1}.{2}", group.R, group.G, group.B) : args.Parameters["chatcolor"];
            var permissions = (null == args.Parameters["permissions"]) ? group.Permissions : args.Parameters["permissions"];
            try
            {
                TShock.Groups.UpdateGroup(group.Name, parent, permissions, chatcolor, group.Suffix, group.Prefix);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("Group '" + group.Name + "' updated successfully");
        }
コード例 #19
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object ServerCommandV3(RestRequestArgs args)
        {
            if (string.IsNullOrWhiteSpace(args.Parameters["cmd"]))
                return RestMissingParam("cmd");

            Group restPlayerGroup;
            // TODO: Get rid of this when the old REST permission model is removed.
            if (TShock.Config.RestUseNewPermissionModel)
                restPlayerGroup = TShock.Groups.GetGroupByName(args.TokenData.UserGroupName);
            else
                restPlayerGroup = new SuperAdminGroup();

            TSRestPlayer tr = new TSRestPlayer(args.TokenData.Username, restPlayerGroup);
            Commands.HandleCommand(tr, args.Parameters["cmd"]);
            return new RestObject()
            {
                {"response", tr.GetCommandOutput()}
            };
        }
コード例 #20
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object PlayerBanV2(RestRequestArgs args)
        {
            var ret = PlayerFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            var reason = null == args.Parameters["reason"] ? "Banned via web" : args.Parameters["reason"];
            TShock.Bans.AddBan(player.IP, player.Name, "", reason);
            TShock.Utils.ForceKick(player, reason, false, true);
            return RestResponse("Player " + player.Name + " was banned");
        }
コード例 #21
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object ServerReload(RestRequestArgs args)
        {
            TShock.Utils.Reload(new TSRestPlayer(args.TokenData.Username, TShock.Groups.GetGroupByName(args.TokenData.UserGroupName)));

            return RestResponse("Configuration, permissions, and regions reload complete. Some changes may require a server restart.");
        }
コード例 #22
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object PlayerKickV2(RestRequestArgs args)
        {
            var ret = PlayerFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            TShock.Utils.ForceKick(player, null == args.Parameters["reason"] ? "Kicked via web" : args.Parameters["reason"], false, true);
            return RestResponse("Player " + player.Name + " was kicked");
        }
コード例 #23
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object ServerRules(RestRequestArgs args)
        {
            string rulesFilePath = Path.Combine(TShock.SavePath, "rules.txt");
            if (!File.Exists(rulesFilePath))
                return this.RestError("The rules.txt was not found.", "500");

            return new RestObject()
            {
                {"rules", File.ReadAllLines(rulesFilePath)}
            };
        }
コード例 #24
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object PlayerKill(RestRequestArgs args)
        {
            var ret = PlayerFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            player.DamagePlayer(999999);
            var from = string.IsNullOrWhiteSpace(args.Parameters["from"]) ? "Server Admin" : args.Parameters["from"];
            player.SendInfoMessage(string.Format("{0} just killed you!", from));
            return RestResponse("Player " + player.Name + " was killed");
        }
コード例 #25
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        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", (TShock.Config.UseServerName ? TShock.Config.ServerName : 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;
        }
コード例 #26
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object PlayerList(RestRequestArgs args)
 {
     var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
     return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } };
 }
コード例 #27
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object UserActiveListV2(RestRequestArgs args)
 {
     return new RestObject() { { "activeusers", string.Join("\t", TShock.Players.Where(p => null != p && null != p.User && p.Active).Select(p => p.User.Name)) } };
 }
コード例 #28
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
 private object PlayerListV2(RestRequestArgs args)
 {
     var playerList = new ArrayList();
     foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p))
     {
         var p = PlayerFilter(tsPlayer, args.Parameters);
         if (null != p)
             playerList.Add(p);
     }
     return new RestObject() { { "players", playerList } };
 }
コード例 #29
0
ファイル: VersionInfo.cs プロジェクト: Grandpa-G/VersionInfo
 private object getServerVersion(RestRequestArgs args)
 {
     var ret = new RestObject()
     {
         {"name", TShock.Config.ServerName},
         {"serverversion", Main.versionNumber.ToString()},
         {"tshockversion", TShock.VersionNum.ToString()},
         {"port", TShock.Config.ServerPort},
         {"APIversion", TerrariaApi.Server.ServerApi.ApiVersion.Major + "." + TerrariaApi.Server.ServerApi.ApiVersion.Minor}
     };
      return ret;
 }
コード例 #30
0
ファイル: RestManager.cs プロジェクト: sylar605/TshockCN
        private object PlayerReadV2(RestRequestArgs args)
        {
            var ret = PlayerFind(args.Parameters);
            if (ret is RestObject)
                return ret;

            TSPlayer player = (TSPlayer)ret;
            var activeItems = player.TPlayer.inventory.Where(p => p.active).ToList();
            return new RestObject()
            {
                {"nickname", player.Name},
                {"username", null == player.User ? "" : player.User.Name},
                {"ip", player.IP},
                {"group", player.Group.Name},
                {"position", player.TileX + "," + player.TileY},
                {"inventory", string.Join(", ", activeItems.Select(p => (p.name + ":" + p.stack)))},
                {"buffs", string.Join(", ", player.TPlayer.buffType)}
            };
        }