Add /players/{player}/kick
This commit is contained in:
parent
e258f54212
commit
7a2ae6dbf9
2 changed files with 31 additions and 4 deletions
|
|
@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.3.3.0916")]
|
[assembly: AssemblyVersion("3.3.3.0917")]
|
||||||
[assembly: AssemblyFileVersion("3.3.3.0916")]
|
[assembly: AssemblyFileVersion("3.3.3.0917")]
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ namespace TShockAPI
|
||||||
Rest.Register(new RestCommand("/world/bloodmoon/{bool}", WorldBloodmoon) { RequiesToken = true });
|
Rest.Register(new RestCommand("/world/bloodmoon/{bool}", WorldBloodmoon) { RequiesToken = true });
|
||||||
|
|
||||||
Rest.Register(new RestCommand("/players/read/{player}", PlayerRead) { RequiesToken = true });
|
Rest.Register(new RestCommand("/players/read/{player}", PlayerRead) { RequiesToken = true });
|
||||||
|
Rest.Register(new RestCommand("/players/{player}/kick", PlayerKick) { RequiesToken = true });
|
||||||
//RegisterExamples();
|
//RegisterExamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -331,17 +332,18 @@ namespace TShockAPI
|
||||||
if (found.Count == 0)
|
if (found.Count == 0)
|
||||||
{
|
{
|
||||||
returnBlock.Add("status", "400");
|
returnBlock.Add("status", "400");
|
||||||
returnBlock.Add("error", "Player " + playerParam.ToString() + " was not found");
|
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
|
||||||
}
|
}
|
||||||
else if (found.Count > 1)
|
else if (found.Count > 1)
|
||||||
{
|
{
|
||||||
returnBlock.Add("status", "400");
|
returnBlock.Add("status", "400");
|
||||||
returnBlock.Add("error", "Player " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
||||||
}
|
}
|
||||||
else if (found.Count == 1)
|
else if (found.Count == 1)
|
||||||
{
|
{
|
||||||
var player = found[0];
|
var player = found[0];
|
||||||
returnBlock.Add("status", "200");
|
returnBlock.Add("status", "200");
|
||||||
|
returnBlock.Add("nickname", player.Name);
|
||||||
returnBlock.Add("username", player.UserAccountName == null ? "" : player.UserAccountName);
|
returnBlock.Add("username", player.UserAccountName == null ? "" : player.UserAccountName);
|
||||||
returnBlock.Add("ip", player.IP);
|
returnBlock.Add("ip", player.IP);
|
||||||
returnBlock.Add("group", player.Group.Name);
|
returnBlock.Add("group", player.Group.Name);
|
||||||
|
|
@ -352,6 +354,31 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
return returnBlock;
|
return returnBlock;
|
||||||
}
|
}
|
||||||
|
object PlayerKick(RestVerbs verbs, IParameterCollection parameters)
|
||||||
|
{
|
||||||
|
var returnBlock = new Dictionary<string, object>();
|
||||||
|
var playerParam = parameters["player"];
|
||||||
|
var found = Tools.FindPlayer(playerParam.ToString());
|
||||||
|
var reason = verbs["reason"];
|
||||||
|
if (found.Count == 0)
|
||||||
|
{
|
||||||
|
returnBlock.Add("status", "400");
|
||||||
|
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
|
||||||
|
}
|
||||||
|
else if (found.Count > 1)
|
||||||
|
{
|
||||||
|
returnBlock.Add("status", "400");
|
||||||
|
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
||||||
|
}
|
||||||
|
else if (found.Count == 1)
|
||||||
|
{
|
||||||
|
var player = found[0];
|
||||||
|
Tools.ForceKick(player, reason == null ? "Kicked via web" : reason.ToString());
|
||||||
|
returnBlock.Add("status", "200");
|
||||||
|
returnBlock.Add("response", "Player " + player.Name + " was kicked");
|
||||||
|
}
|
||||||
|
return returnBlock;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region RestExampleMethods
|
#region RestExampleMethods
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue