• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RestVerbs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RestVerbs的典型用法代码示例。如果您正苦于以下问题:C# RestVerbs类的具体用法?C# RestVerbs怎么用?C# RestVerbs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RestVerbs类属于命名空间,在下文中一共展示了RestVerbs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: NewToken

        object NewToken(RestVerbs verbs, IParameterCollection parameters)
        {
            var user = verbs["username"];
            var pass = verbs["password"];

            RestObject obj = null;
            if (Verify != null)
                obj = Verify(user, pass);

            if (obj == null)
                obj = new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };

            if (obj.Error != null)
                return obj;

            string hash;
            var rand = new Random();
            var randbytes = new byte[32];
            do
            {
                rand.NextBytes(randbytes);
                hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2"));
            } while (Tokens.ContainsKey(hash));

            Tokens.Add(hash, user);

            obj["token"] = hash;
            return obj;
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:29,代码来源:SecureRest.cs


示例2: RestRequestArgs

		public RestRequestArgs(RestVerbs verbs, IParameterCollection param, IRequest request, SecureRest.TokenData tokenData, IHttpContext context)
		{
			Verbs = verbs;
			Parameters = param;
			Request = request;
			TokenData = tokenData;
			Context = context;
		}
开发者ID:sliekasirdis79,项目名称:TShock,代码行数:8,代码来源:Rest.cs


示例3: DestroyToken

 object DestroyToken(RestVerbs verbs, IParameterCollection parameters)
 {
     var token = verbs["token"];
     try
     {
         Tokens.Remove(token);
     }
     catch (Exception)
     {
         return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified token queued for destruction failed to be deleted." } };
     }
     return new Dictionary<string, string> { { "status", "200" }, { "response", "Requested token was successfully destroyed." } };
 }
开发者ID:pfchrono,项目名称:Toaria,代码行数:13,代码来源:SecureRest.cs


示例4: ExecuteCommand

        protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
        {
            if (cmd.RequiresToken)
            {
                var strtoken = parms["token"];
                if (strtoken == null)
                    return new Dictionary<string, string> { { "status", "401" }, { "error", "Not authorized. The specified API endpoint requires a token." } };

                object token;
                if (!Tokens.TryGetValue(strtoken, out token))
                    return new Dictionary<string, string> { { "status", "403" }, { "error", "Not authorized. The specified API endpoint requires a token, but the provided token was not valid." } };
            }
            return base.ExecuteCommand(cmd, verbs, parms);
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:14,代码来源:SecureRest.cs


示例5: GetInventory

        private object GetInventory(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            List<TSPlayer> players = TShock.Utils.FindPlayer(verbs["user"]);
            if (players.Count > 1)
            {
                return new RestObject("400") {Response = "Found more than one match."};
            }
            else if (players.Count < 1)
            {
                return new RestObject("400") {Response = "Found no matches."};
            }

            string inventory = players[0].PlayerData.inventory.ToString();
            return new RestObject{{"inventory", inventory}};
        }
开发者ID:NyxStudios,项目名称:serverside-terraria,代码行数:15,代码来源:ServerSideExtensions.cs


示例6: BanCreate

        object BanCreate(RestVerbs verbs, IParameterCollection parameters)
        {
            var returnBlock = new Dictionary<string, string>();
            var ip = parameters["ip"];
            var name = parameters["name"];
            var reason = parameters["reason"];

            if (ip == null && name == null)
            {
                returnBlock.Add("status", "400");
                returnBlock.Add("error", "Required parameters were missing from this API endpoint.");
                return returnBlock;
            }

            if (ip == null)
            {
                ip = "";
            }

            if (name == null)
            {
                name = "";
            }

            if (reason == null)
            {
                reason = "";
            }

            try
            {
                TShock.Bans.AddBan(ip, name, reason);
            }
            catch (Exception)
            {
                returnBlock.Add("status", "400");
                returnBlock.Add("error", "The specified ban was unable to be created.");
                return returnBlock;
            }
            returnBlock.Add("status", "200");
            returnBlock.Add("response", "Ban created successfully.");
            return returnBlock;
        }
开发者ID:pfchrono,项目名称:Toaria,代码行数:43,代码来源:RestManager.cs


示例7: WorldRead

 private object WorldRead(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject()
     {
         {"name", Main.worldName},
         {"size", Main.maxTilesX + "*" + Main.maxTilesY},
         {"time", Main.time},
         {"daytime", Main.dayTime},
         {"bloodmoon", Main.bloodMoon},
         {"invasionsize", Main.invasionSize}
     };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:12,代码来源:RestManager.cs


示例8: WorldChangeSaveSettings

        private object WorldChangeSaveSettings(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            bool autoSave;
            if (!bool.TryParse(verbs["bool"], out autoSave))
                return RestInvalidParam("state");
            TShock.Config.AutoSave = autoSave;

            return RestResponse("AutoSave has been set to " + autoSave);
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:9,代码来源:RestManager.cs


示例9: WorldBloodmoon

        private object WorldBloodmoon(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            bool bloodmoon;
            if (!bool.TryParse(verbs["bool"], out bloodmoon))
                return RestInvalidParam("bloodmoon");
            Main.bloodMoon = bloodmoon;

            return RestResponse("Blood Moon has been set to " + bloodmoon);
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:9,代码来源:RestManager.cs


示例10: UserListV2

 private object UserListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject() { { "users", TShock.Users.GetUsers().Select(p => new Dictionary<string,object>(){
         {"name", p.Name},
         {"id", p.ID},
         {"group", p.Group},
     }) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:8,代码来源:RestManager.cs


示例11: UserDestroyV2

        private object UserDestroyV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            var ret = UserFind(parameters);
            if (ret is RestObject)
                return ret;

            try
            {
                TShock.Users.RemoveUser((User)ret);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("User deleted successfully");
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:17,代码来源:RestManager.cs


示例12: UserActiveListV2

 private object UserActiveListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject() { { "activeusers", string.Join("\t", TShock.Players.Where(p => null != p && null != p.UserAccountName && p.Active).Select(p => p.UserAccountName)) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:4,代码来源:RestManager.cs


示例13: PlayerReadV2

        private object PlayerReadV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            var ret = PlayerFind(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.UserAccountName ? "" : player.UserAccountName},
                {"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)}
            };
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:19,代码来源:RestManager.cs


示例14: PlayerListV2

 private object PlayerListV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     var playerList = new ArrayList();
     foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p))
     {
         var p = PlayerFilter(tsPlayer, parameters);
         if (null != p)
             playerList.Add(p);
     }
     return new RestObject() { { "players", playerList } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:11,代码来源:RestManager.cs


示例15: PlayerList

 private object PlayerList(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
     return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:5,代码来源:RestManager.cs


示例16: ServerStatusV2

        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;
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:46,代码来源:RestManager.cs


示例17: ServerTokenTest

 private object ServerTokenTest(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return new RestObject()
     {
         {"response", "Token is valid and was passed through correctly."},
         {"associateduser", tokenData.Username}
     };
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:8,代码来源:RestManager.cs


示例18: PlayerUnMute

 private object PlayerUnMute(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     return PlayerSetMute(parameters, false);
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:4,代码来源:RestManager.cs


示例19: UserCreateV2

        private object UserCreateV2(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
        {
            var username = parameters["user"];
            if (string.IsNullOrWhiteSpace(username))
                return RestMissingParam("user");

            var group = parameters["group"];
            if (string.IsNullOrWhiteSpace(group))
                group = TShock.Config.DefaultRegistrationGroupName;

            var password = parameters["password"];
            if (string.IsNullOrWhiteSpace(password))
                return RestMissingParam("password");

            // NOTE: ip can be blank
            User user = new User(username, password, "", group, "", "", "");
            try
            {
                TShock.Users.AddUser(user);
            }
            catch (Exception e)
            {
                return RestError(e.Message);
            }

            return RestResponse("User was successfully created");
        }
开发者ID:CoderCow,项目名称:TShock,代码行数:27,代码来源:RestManager.cs


示例20: ServerBroadcast

 private object ServerBroadcast(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
 {
     var msg = parameters["msg"];
     if (string.IsNullOrWhiteSpace(msg))
         return RestMissingParam("msg");
     TShock.Utils.Broadcast(msg);
     return RestResponse("The message was broadcasted successfully");
 }
开发者ID:CoderCow,项目名称:TShock,代码行数:8,代码来源:RestManager.cs



注:本文中的RestVerbs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Result类代码示例发布时间:2022-05-24
下一篇:
C# RestTestHarness类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap