ForceKick now takes in TSPlayer instead of int
Removed Tools.GetPlayerIP, use TSPlayer.IP instead
This commit is contained in:
parent
921f8ad4ee
commit
a976c51101
3 changed files with 53 additions and 51 deletions
|
|
@ -25,15 +25,14 @@ namespace TShockAPI
|
||||||
public class TSPlayer
|
public class TSPlayer
|
||||||
{
|
{
|
||||||
public static readonly TSPlayer Server = new ServerPlayer();
|
public static readonly TSPlayer Server = new ServerPlayer();
|
||||||
public static readonly TSPlayer All = new TSPlayer(new Player { name = "All", whoAmi = -1 });
|
public static readonly TSPlayer All = new TSPlayer("All");
|
||||||
public uint TileThreshold { get; set; }
|
public uint TileThreshold { get; set; }
|
||||||
public Dictionary<Vector2, Tile> TilesDestroyed { get; set; }
|
public Dictionary<Vector2, Tile> TilesDestroyed { get; set; }
|
||||||
public bool SyncHP { get; set; }
|
public bool SyncHP { get; set; }
|
||||||
public bool SyncMP { get; set; }
|
public bool SyncMP { get; set; }
|
||||||
public Group Group { get; set; }
|
public Group Group { get; set; }
|
||||||
public bool ReceivedInfo { get; set; }
|
public bool ReceivedInfo { get; set; }
|
||||||
|
public int Index { get; protected set; }
|
||||||
public int Index { get { return TPlayer.whoAmi; } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Terraria Player
|
/// Terraria Player
|
||||||
|
|
@ -44,14 +43,14 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
get { return TPlayer.name; }
|
get { return TPlayer.name; }
|
||||||
}
|
}
|
||||||
|
public string IP
|
||||||
|
{
|
||||||
|
get { return Tools.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()); }
|
||||||
|
}
|
||||||
public bool Active
|
public bool Active
|
||||||
{
|
{
|
||||||
get { return TPlayer.active; }
|
get { return TPlayer.active; }
|
||||||
}
|
}
|
||||||
public string IP
|
|
||||||
{
|
|
||||||
get { return Tools.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()); }
|
|
||||||
}
|
|
||||||
public int Team
|
public int Team
|
||||||
{
|
{
|
||||||
get { return TPlayer.team; }
|
get { return TPlayer.team; }
|
||||||
|
|
@ -74,10 +73,19 @@ namespace TShockAPI
|
||||||
get { return (int)(X / 16); }
|
get { return (int)(X / 16); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSPlayer(Player ply)
|
public TSPlayer(int index)
|
||||||
{
|
{
|
||||||
TilesDestroyed = new Dictionary<Vector2, Tile>();
|
TilesDestroyed = new Dictionary<Vector2, Tile>();
|
||||||
TPlayer = ply;
|
Index = index;
|
||||||
|
TPlayer = Main.player[index];
|
||||||
|
Group = new Group("null");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TSPlayer(String playerName)
|
||||||
|
{
|
||||||
|
TilesDestroyed = new Dictionary<Vector2, Tile>();
|
||||||
|
Index = -1;
|
||||||
|
TPlayer = new Player { name = playerName, whoAmi = -1 };
|
||||||
Group = new Group("null");
|
Group = new Group("null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,8 +109,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public class ServerPlayer : TSPlayer
|
public class ServerPlayer : TSPlayer
|
||||||
{
|
{
|
||||||
public ServerPlayer()
|
public ServerPlayer() : base("Server")
|
||||||
: base(new Player { name = "Server" })
|
|
||||||
{
|
{
|
||||||
Group = new SuperAdminGroup();
|
Group = new SuperAdminGroup();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -313,41 +313,42 @@ namespace TShockAPI
|
||||||
|
|
||||||
bool HandlePlayerInfo(MemoryStream data, GetDataEventArgs e)
|
bool HandlePlayerInfo(MemoryStream data, GetDataEventArgs e)
|
||||||
{
|
{
|
||||||
var ban = Bans.GetBanByName(Main.player[e.Msg.whoAmI].name);
|
var player = Players[e.Msg.whoAmI];
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
Tools.ForceKick(new TSPlayer(e.Msg.whoAmI), "Player doesn't exist");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var ban = Bans.GetBanByName(player.Name);
|
||||||
if (ban != null)
|
if (ban != null)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(e.Msg.whoAmI, string.Format("You are banned: {0}", ban.Reason));
|
Tools.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
byte hair = e.Msg.readBuffer[e.Index + 1];
|
byte hair = e.Msg.readBuffer[e.Index + 1];
|
||||||
if (hair > 0x10)
|
if (hair > 0x10)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(e.Msg.whoAmI, "Hair crash exploit.");
|
Tools.ForceKick(player, "Hair crash exploit.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 23, (e.Length - (e.Index + 23)) + e.Index - 1);
|
string name = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 23, (e.Length - (e.Index + 23)) + e.Index - 1);
|
||||||
if (name.Length > 32)
|
if (name.Length > 32)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(e.Msg.whoAmI, "Name exceeded 32 characters.");
|
Tools.ForceKick(player, "Name exceeded 32 characters.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (name.Trim().Length == 0)
|
if (name.Trim().Length == 0)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(e.Msg.whoAmI, "Empty Name.");
|
Tools.ForceKick(player, "Empty Name.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Players[e.Msg.whoAmI] == null)
|
if (player.ReceivedInfo)
|
||||||
{
|
|
||||||
Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Players[e.Msg.whoAmI].ReceivedInfo)
|
|
||||||
{
|
{
|
||||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Sent client info more than once");
|
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Sent client info more than once");
|
||||||
}
|
}
|
||||||
|
|
||||||
Players[e.Msg.whoAmI].ReceivedInfo = true;
|
player.ReceivedInfo = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -624,7 +625,7 @@ namespace TShockAPI
|
||||||
tilex, tiley,
|
tilex, tiley,
|
||||||
Main.tile[tilex, tiley].type
|
Main.tile[tilex, tiley].type
|
||||||
));
|
));
|
||||||
Tools.ForceKick(e.Msg.whoAmI, string.Format("Tile Kill abuse ({0})", Main.tile[tilex, tiley].type));
|
Tools.ForceKick(Players[e.Msg.whoAmI], string.Format("Tile Kill abuse ({0})", Main.tile[tilex, tiley].type));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -636,7 +637,7 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TSPlayer player = Players[who];
|
TSPlayer player = Players[who];
|
||||||
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", player.Name, Tools.GetPlayerIP(who), player.Group.Name));
|
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", player.Name, player.IP, player.Group.Name));
|
||||||
|
|
||||||
Tools.ShowFileToUser(player, "motd.txt");
|
Tools.ShowFileToUser(player, "motd.txt");
|
||||||
if (HackedHealth(who))
|
if (HackedHealth(who))
|
||||||
|
|
@ -728,31 +729,31 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ip = Tools.GetPlayerIP(ply);
|
var player = new TSPlayer(ply);
|
||||||
Players[ply] = new TSPlayer(Main.player[ply]);
|
player.Group = Tools.GetGroupForIP(player.IP);
|
||||||
Players[ply].Group = Tools.GetGroupForIP(ip);
|
|
||||||
|
|
||||||
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots &&
|
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots &&
|
||||||
!Players[ply].Group.HasPermission("reservedslot"))
|
!player.Group.HasPermission("reservedslot"))
|
||||||
{
|
{
|
||||||
Tools.ForceKick(ply, "Server is full");
|
Tools.ForceKick(player, "Server is full");
|
||||||
handler.Handled = true;
|
handler.Handled = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ban = Bans.GetBanByIp(ip);
|
var ban = Bans.GetBanByIp(player.IP);
|
||||||
if (ban != null)
|
if (ban != null)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(ply, string.Format("You are banned: {0}", ban.Reason));
|
Tools.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
|
||||||
handler.Handled = true;
|
handler.Handled = true;
|
||||||
}
|
}
|
||||||
else if (!FileTools.OnWhitelist(ip))
|
else if (!FileTools.OnWhitelist(player.IP))
|
||||||
{
|
{
|
||||||
Tools.ForceKick(ply, "Not on whitelist.");
|
Tools.ForceKick(player, "Not on whitelist.");
|
||||||
handler.Handled = true;
|
handler.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Players[ply] = player;
|
||||||
Netplay.serverSock[ply].spamCheck = ConfigurationManager.SpamChecks;
|
Netplay.serverSock[ply].spamCheck = ConfigurationManager.SpamChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -764,6 +765,8 @@ namespace TShockAPI
|
||||||
var tsplr = Players[ply];
|
var tsplr = Players[ply];
|
||||||
if (tsplr != null && tsplr.ReceivedInfo)
|
if (tsplr != null && tsplr.ReceivedInfo)
|
||||||
Log.Info(string.Format("{0} left.", tsplr.Name));
|
Log.Info(string.Format("{0} left.", tsplr.Name));
|
||||||
|
|
||||||
|
Players[ply] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostInit()
|
private void OnPostInit()
|
||||||
|
|
|
||||||
|
|
@ -45,16 +45,6 @@ namespace TShockAPI
|
||||||
return mess.Split(':')[0];
|
return mess.Split(':')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the IP from a player index
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="plr">Player Index</param>
|
|
||||||
/// <returns>IP</returns>
|
|
||||||
public static string GetPlayerIP(int plr)
|
|
||||||
{
|
|
||||||
return GetRealIP(Netplay.serverSock[plr].tcpClient.Client.RemoteEndPoint.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used for some places where a list of players might be used.
|
/// Used for some places where a list of players might be used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -206,9 +196,9 @@ namespace TShockAPI
|
||||||
/// <param name="reason">string reason</param>
|
/// <param name="reason">string reason</param>
|
||||||
public static void ForceKickAll(string reason)
|
public static void ForceKickAll(string reason)
|
||||||
{
|
{
|
||||||
for (int player = 0; player < Main.maxPlayers; player++)
|
foreach(TSPlayer player in TShock.Players)
|
||||||
{
|
{
|
||||||
if (Main.player[player].active)
|
if (player != null && player.TPlayer.active)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(player, reason);
|
Tools.ForceKick(player, reason);
|
||||||
}
|
}
|
||||||
|
|
@ -220,11 +210,13 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ply">int player</param>
|
/// <param name="ply">int player</param>
|
||||||
/// <param name="reason">string reason</param>
|
/// <param name="reason">string reason</param>
|
||||||
public static void ForceKick(int ply, string reason)
|
public static void ForceKick(TSPlayer player, string reason)
|
||||||
{
|
{
|
||||||
string ip = GetPlayerIP(ply);
|
Log.Info("ForceKick Pre : " + player.Index + " status " + Main.player[player.Index].active + " " + player.TPlayer.active + " " + Main.player[player.Index].name + " " + player.TPlayer.name);
|
||||||
NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f);
|
if (!Netplay.serverSock[player.Index].active || Netplay.serverSock[player.Index].kill)
|
||||||
Log.Info(string.Format("{0} was force kicked for : {1}", ip, reason));
|
return;
|
||||||
|
NetMessage.SendData(0x2, player.Index, -1, reason, 0x0, 0f, 0f, 0f);
|
||||||
|
Log.Info(string.Format("{0} was force kicked for : {1}", player.IP, reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -261,7 +253,7 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
if (!player.Group.HasPermission("immunetoban"))
|
if (!player.Group.HasPermission("immunetoban"))
|
||||||
{
|
{
|
||||||
string ip = GetPlayerIP(player.Index);
|
string ip = player.IP;
|
||||||
string playerName = player.Name;
|
string playerName = player.Name;
|
||||||
TShock.Bans.AddBan(ip, playerName, reason);
|
TShock.Bans.AddBan(ip, playerName, reason);
|
||||||
NetMessage.SendData(0x2, player.Index, -1, string.Format("Banned: {0}", reason), 0x0, 0f, 0f, 0f);
|
NetMessage.SendData(0x2, player.Index, -1, string.Format("Banned: {0}", reason), 0x0, 0f, 0f, 0f);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue