REST status or v2/server/status now checks for a permission to display ips to the caller. The only way to get this enabled is to use securetokenendpoint config option.
Refactored a tsplayer method.
This commit is contained in:
parent
4c5c2ba0de
commit
ec9cb09cd8
3 changed files with 52 additions and 38 deletions
|
|
@ -236,7 +236,7 @@ namespace TShockAPI
|
||||||
var players = new ArrayList();
|
var players = new ArrayList();
|
||||||
foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p))
|
foreach (TSPlayer tsPlayer in TShock.Players.Where(p => null != p))
|
||||||
{
|
{
|
||||||
var p = PlayerFilter(tsPlayer, parameters);
|
var p = PlayerFilter(tsPlayer, parameters, ((tokenData.UserGroupName) != "" && TShock.Utils.GetGroup(tokenData.UserGroupName).HasPermission(RestPermissions.viewips)));
|
||||||
if (null != p)
|
if (null != p)
|
||||||
players.Add(p);
|
players.Add(p);
|
||||||
}
|
}
|
||||||
|
|
@ -859,18 +859,22 @@ namespace TShockAPI
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, object> PlayerFilter(TSPlayer tsPlayer, IParameterCollection parameters)
|
private Dictionary<string, object> PlayerFilter(TSPlayer tsPlayer, IParameterCollection parameters, bool viewips = false)
|
||||||
{
|
{
|
||||||
var player = new Dictionary<string, object>
|
var player = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{"nickname", tsPlayer.Name},
|
{"nickname", tsPlayer.Name},
|
||||||
{"username", null == tsPlayer.UserAccountName ? "" : tsPlayer.UserAccountName},
|
{"username", tsPlayer.UserAccountName ?? ""},
|
||||||
{"ip", tsPlayer.IP},
|
|
||||||
{"group", tsPlayer.Group.Name},
|
{"group", tsPlayer.Group.Name},
|
||||||
{"active", tsPlayer.Active},
|
{"active", tsPlayer.Active},
|
||||||
{"state", tsPlayer.State},
|
{"state", tsPlayer.State},
|
||||||
{"team", tsPlayer.Team},
|
{"team", tsPlayer.Team},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (viewips)
|
||||||
|
{
|
||||||
|
player.Add("ip", tsPlayer.IP);
|
||||||
|
}
|
||||||
foreach (IParameter filter in parameters)
|
foreach (IParameter filter in parameters)
|
||||||
{
|
{
|
||||||
if (player.ContainsKey(filter.Name) && !player[filter.Name].Equals(filter.Value))
|
if (player.ContainsKey(filter.Name) && !player[filter.Name].Equals(filter.Value))
|
||||||
|
|
|
||||||
|
|
@ -83,5 +83,8 @@ namespace Rests
|
||||||
|
|
||||||
[Description("REST user can run raw TShock commands (the raw command permissions are also checked though).")]
|
[Description("REST user can run raw TShock commands (the raw command permissions are also checked though).")]
|
||||||
public static readonly string restrawcommand = "tshock.rest.command";
|
public static readonly string restrawcommand = "tshock.rest.command";
|
||||||
|
|
||||||
|
[Description("REST user can view the ips of players.")]
|
||||||
|
public static readonly string viewips = "tshock.rest.viewips";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -647,45 +647,52 @@ namespace TShockAPI
|
||||||
|
|
||||||
public virtual bool SendTileSquare(int x, int y, int size = 10)
|
public virtual bool SendTileSquare(int x, int y, int size = 10)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int num = (size - 1)/2;
|
int num = (size - 1)/2;
|
||||||
int m_x=0;
|
int m_x = 0;
|
||||||
int m_y=0;
|
int m_y = 0;
|
||||||
|
|
||||||
if (x - num <0){
|
if (x - num < 0)
|
||||||
m_x=0;
|
{
|
||||||
}else{
|
m_x = 0;
|
||||||
m_x = x - num;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
m_x = x - num;
|
||||||
|
}
|
||||||
|
|
||||||
if (y - num <0){
|
if (y - num < 0)
|
||||||
m_y=0;
|
{
|
||||||
}else{
|
m_y = 0;
|
||||||
m_y = y - num;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
m_y = y - num;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_x + size > Main.maxTilesX){
|
if (m_x + size > Main.maxTilesX)
|
||||||
m_x=Main.maxTilesX - size;
|
{
|
||||||
}
|
m_x = Main.maxTilesX - size;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_y + size > Main.maxTilesY){
|
if (m_y + size > Main.maxTilesY)
|
||||||
m_y=Main.maxTilesY - size;
|
{
|
||||||
}
|
m_y = Main.maxTilesY - size;
|
||||||
|
}
|
||||||
|
|
||||||
SendData(PacketTypes.TileSendSquare, "", size, m_x, m_y);
|
SendData(PacketTypes.TileSendSquare, "", size, m_x, m_y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (IndexOutOfRangeException)
|
catch (IndexOutOfRangeException)
|
||||||
{
|
{
|
||||||
|
// This is expected if square exceeds array.
|
||||||
// This is expected if square exceeds array.
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
Log.Error(ex.ToString());
|
||||||
Log.Error(ex.ToString());
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0)
|
public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue