本文整理汇总了C#中RestVerbs类的典型用法代码示例。如果您正苦于以下问题:C# RestVerbs类的具体用法?C# RestVerbs怎么用?C# RestVerbs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestVerbs类属于命名空间,在下文中一共展示了RestVerbs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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." } };
}
示例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);
}
示例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}};
}
示例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;
}
示例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}
};
}
示例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);
}
示例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);
}
示例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},
}) } };
}
示例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");
}
示例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)) } };
}
示例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)}
};
}
示例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 } };
}
示例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)) } };
}