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();
|
||||
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)
|
||||
players.Add(p);
|
||||
}
|
||||
|
|
@ -859,18 +859,22 @@ namespace TShockAPI
|
|||
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>
|
||||
{
|
||||
{"nickname", tsPlayer.Name},
|
||||
{"username", null == tsPlayer.UserAccountName ? "" : tsPlayer.UserAccountName},
|
||||
{"ip", tsPlayer.IP},
|
||||
{"username", tsPlayer.UserAccountName ?? ""},
|
||||
{"group", tsPlayer.Group.Name},
|
||||
{"active", tsPlayer.Active},
|
||||
{"state", tsPlayer.State},
|
||||
{"team", tsPlayer.Team},
|
||||
};
|
||||
|
||||
if (viewips)
|
||||
{
|
||||
player.Add("ip", tsPlayer.IP);
|
||||
}
|
||||
foreach (IParameter filter in parameters)
|
||||
{
|
||||
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).")]
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
int num = (size - 1)/2;
|
||||
int m_x=0;
|
||||
int m_y=0;
|
||||
try
|
||||
{
|
||||
int num = (size - 1)/2;
|
||||
int m_x = 0;
|
||||
int m_y = 0;
|
||||
|
||||
if (x - num <0){
|
||||
m_x=0;
|
||||
}else{
|
||||
m_x = x - num;
|
||||
}
|
||||
if (x - num < 0)
|
||||
{
|
||||
m_x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_x = x - num;
|
||||
}
|
||||
|
||||
if (y - num <0){
|
||||
m_y=0;
|
||||
}else{
|
||||
m_y = y - num;
|
||||
}
|
||||
if (y - num < 0)
|
||||
{
|
||||
m_y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_y = y - num;
|
||||
}
|
||||
|
||||
if (m_x + size > Main.maxTilesX){
|
||||
m_x=Main.maxTilesX - size;
|
||||
}
|
||||
if (m_x + size > Main.maxTilesX)
|
||||
{
|
||||
m_x = Main.maxTilesX - size;
|
||||
}
|
||||
|
||||
if (m_y + size > Main.maxTilesY){
|
||||
m_y=Main.maxTilesY - size;
|
||||
}
|
||||
if (m_y + size > Main.maxTilesY)
|
||||
{
|
||||
m_y = Main.maxTilesY - size;
|
||||
}
|
||||
|
||||
SendData(PacketTypes.TileSendSquare, "", size, m_x, m_y);
|
||||
return true;
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
|
||||
// This is expected if square exceeds array.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return false;
|
||||
SendData(PacketTypes.TileSendSquare, "", size, m_x, m_y);
|
||||
return true;
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
// This is expected if square exceeds array.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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