Changed the TSPlayer class.

This commit is contained in:
high 2011-06-14 16:54:30 -04:00
parent 17b2ed7eea
commit c3bf304c0c
5 changed files with 53 additions and 58 deletions

View file

@ -71,16 +71,16 @@ namespace TShockAPI
public bool Run(string msg, TSPlayer ply, List<string> parms) public bool Run(string msg, TSPlayer ply, List<string> parms)
{ {
if (!ply.group.HasPermission(permission)) if (!ply.Group.HasPermission(permission))
{ {
return false; return false;
} }
CommandArgs args = new CommandArgs(); CommandArgs args = new CommandArgs();
args.Message = msg; args.Message = msg;
args.PlayerX = (int)ply.GetPlayer().position.X; args.PlayerX = (int)ply.Player.position.X;
args.PlayerY = (int)ply.GetPlayer().position.Y; args.PlayerY = (int)ply.Player.position.Y;
args.PlayerID = ply.GetPlayerID(); args.PlayerID = ply.Index;
args.Parameters = parms; args.Parameters = parms;
command(args); command(args);
@ -94,7 +94,7 @@ namespace TShockAPI
public bool CanRun(TSPlayer ply) public bool CanRun(TSPlayer ply)
{ {
if (!ply.group.HasPermission(permission)) if (!ply.Group.HasPermission(permission))
{ {
return false; return false;
} }

View file

@ -22,27 +22,22 @@ namespace TShockAPI
{ {
public class TSPlayer public class TSPlayer
{ {
public uint tileThreshold; public uint TileThreshold { get; set; }
public Dictionary<TShock.Position, Tile> tilesDestroyed = new Dictionary<TShock.Position, Tile>(); public Dictionary<TShock.Position, Tile> TilesDestroyed { get; set; }
public bool syncHP; public bool SyncHP { get; set; }
public bool syncMP; public bool SyncMP { get; set; }
public Group group; public Group Group { get; set; }
public bool receivedInfo; public bool ReceivedInfo { get; set; }
private int player;
public int Index {get;private set;}
public Player Player
{
get { return Main.player[Index]; }
}
public TSPlayer(int ply) public TSPlayer(int ply)
{ {
player = ply; TilesDestroyed = new Dictionary<TShock.Position, Tile>();
}
public Player GetPlayer()
{
return Main.player[player];
}
public int GetPlayerID()
{
return player;
} }
} }
} }

View file

@ -280,12 +280,12 @@ namespace TShockAPI
Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist"); Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist");
return true; return true;
} }
if (players[e.Msg.whoAmI].receivedInfo) if (players[e.Msg.whoAmI].ReceivedInfo)
{ {
return Tools.HandleGriefer(e.Msg.whoAmI, "Sent client info more than once"); return Tools.HandleGriefer(e.Msg.whoAmI, "Sent client info more than once");
} }
players[e.Msg.whoAmI].receivedInfo = true; players[e.Msg.whoAmI].ReceivedInfo = true;
return false; return false;
} }
@ -341,7 +341,7 @@ namespace TShockAPI
} }
if (ConfigurationManager.disableBuild) if (ConfigurationManager.disableBuild)
{ {
if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "World protected from changes.", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "World protected from changes.", Color.Red);
RevertPlayerChanges(e.Msg.whoAmI, type, x, y); RevertPlayerChanges(e.Msg.whoAmI, type, x, y);
@ -350,7 +350,7 @@ namespace TShockAPI
} }
if (ConfigurationManager.spawnProtect) if (ConfigurationManager.spawnProtect)
{ {
if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
var flag = CheckSpawn(x, y); var flag = CheckSpawn(x, y);
if (flag) if (flag)
@ -364,8 +364,8 @@ namespace TShockAPI
if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active) if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active)
{ {
players[e.Msg.whoAmI].tileThreshold++; players[e.Msg.whoAmI].TileThreshold++;
players[e.Msg.whoAmI].tilesDestroyed.Add(new Position(x, y), Main.tile[x, y]); players[e.Msg.whoAmI].TilesDestroyed.Add(new Position(x, y), Main.tile[x, y]);
} }
return false; return false;
@ -495,14 +495,14 @@ namespace TShockAPI
} }
} }
if (lava && !players[e.Msg.whoAmI].group.HasPermission("canlava")) if (lava && !players[e.Msg.whoAmI].Group.HasPermission("canlava"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use lava", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use lava", Color.Red);
Tools.SendLogs(string.Format("{0} tried using lava", Main.player[e.Msg.whoAmI].name), Color.Red); Tools.SendLogs(string.Format("{0} tried using lava", Main.player[e.Msg.whoAmI].name), Color.Red);
return true; return true;
} }
if (!lava && !players[e.Msg.whoAmI].group.HasPermission("canwater")) if (!lava && !players[e.Msg.whoAmI].Group.HasPermission("canwater"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use water", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use water", Color.Red);
Tools.SendLogs(string.Format("{0} tried using water", Main.player[e.Msg.whoAmI].name), Color.Red); Tools.SendLogs(string.Format("{0} tried using water", Main.player[e.Msg.whoAmI].name), Color.Red);
@ -533,7 +533,7 @@ namespace TShockAPI
if (ConfigurationManager.spawnProtect) if (ConfigurationManager.spawnProtect)
{ {
if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
var flag = CheckSpawn(x, y); var flag = CheckSpawn(x, y);
if (flag) if (flag)
@ -570,7 +570,7 @@ namespace TShockAPI
if (Main.netMode != 2) if (Main.netMode != 2)
return; return;
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].group.GetName())); Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.GetName()));
Tools.ShowMOTD(who); Tools.ShowMOTD(who);
if (HackedHealth(who)) if (HackedHealth(who))
@ -582,7 +582,7 @@ namespace TShockAPI
Main.player[who].hostile = true; Main.player[who].hostile = true;
NetMessage.SendData(30, -1, -1, "", who); NetMessage.SendData(30, -1, -1, "", who);
} }
if (players[who].group.HasPermission("causeevents") && ConfigurationManager.infiniteInvasion) if (players[who].Group.HasPermission("causeevents") && ConfigurationManager.infiniteInvasion)
{ {
StartInvasion(); StartInvasion();
} }
@ -600,7 +600,7 @@ namespace TShockAPI
return; return;
} }
if (players[ply].group.HasPermission("adminchat") && !text.StartsWith("/")) if (players[ply].Group.HasPermission("adminchat") && !text.StartsWith("/"))
{ {
Tools.Broadcast(ConfigurationManager.adminChatPrefix + "<" + Main.player[ply].name + "> " + text, (byte)ConfigurationManager.adminChatRGB[0], (byte)ConfigurationManager.adminChatRGB[1], (byte)ConfigurationManager.adminChatRGB[2]); Tools.Broadcast(ConfigurationManager.adminChatPrefix + "<" + Main.player[ply].name + "> " + text, (byte)ConfigurationManager.adminChatRGB[0], (byte)ConfigurationManager.adminChatRGB[1], (byte)ConfigurationManager.adminChatRGB[2]);
e.Handled = true; e.Handled = true;
@ -660,10 +660,10 @@ namespace TShockAPI
string ip = Tools.GetPlayerIP(ply); string ip = Tools.GetPlayerIP(ply);
players[ply] = new TSPlayer(ply); players[ply] = new TSPlayer(ply);
players[ply].group = Tools.GetGroupForIP(ip); players[ply].Group = Tools.GetGroupForIP(ip);
if (Tools.activePlayers() + 1 > ConfigurationManager.maxSlots && if (Tools.ActivePlayers() + 1 > ConfigurationManager.maxSlots &&
!players[ply].group.HasPermission("reservedslot")) !players[ply].Group.HasPermission("reservedslot"))
{ {
Tools.ForceKick(ply, "Server is full"); Tools.ForceKick(ply, "Server is full");
handler.Handled = true; handler.Handled = true;
@ -726,24 +726,24 @@ namespace TShockAPI
{ {
if (Main.player[i].active == false) if (Main.player[i].active == false)
continue; continue;
if (players[i].tileThreshold >= 20) if (players[i].TileThreshold >= 20)
{ {
if (Tools.HandleTntUser(i, "Kill tile abuse detected.")) if (Tools.HandleTntUser(i, "Kill tile abuse detected."))
{ {
RevertKillTile(i); RevertKillTile(i);
players[i].tileThreshold = 0; players[i].TileThreshold = 0;
players[i].tilesDestroyed.Clear(); players[i].TilesDestroyed.Clear();
} }
else if (players[i].tileThreshold > 0) else if (players[i].TileThreshold > 0)
{ {
players[i].tileThreshold = 0; players[i].TileThreshold = 0;
players[i].tilesDestroyed.Clear(); players[i].TilesDestroyed.Clear();
} }
} }
else if (players[i].tileThreshold > 0) else if (players[i].TileThreshold > 0)
{ {
players[i].tileThreshold = 0; players[i].TileThreshold = 0;
} }
} }
} }
@ -779,7 +779,7 @@ namespace TShockAPI
} }
else else
{ {
Main.invasionSize = 100 + (ConfigurationManager.invasionMultiplier * Tools.activePlayers()); Main.invasionSize = 100 + (ConfigurationManager.invasionMultiplier * Tools.ActivePlayers());
} }
Main.invasionWarn = 0; Main.invasionWarn = 0;
@ -913,11 +913,11 @@ namespace TShockAPI
public static void RevertKillTile(int ply) public static void RevertKillTile(int ply)
{ {
Tile[] tiles = new Tile[players[ply].tilesDestroyed.Count]; Tile[] tiles = new Tile[players[ply].TilesDestroyed.Count];
players[ply].tilesDestroyed.Values.CopyTo(tiles, 0); players[ply].TilesDestroyed.Values.CopyTo(tiles, 0);
Position[] positions = new Position[players[ply].tilesDestroyed.Count]; Position[] positions = new Position[players[ply].TilesDestroyed.Count];
players[ply].tilesDestroyed.Keys.CopyTo(positions, 0); players[ply].TilesDestroyed.Keys.CopyTo(positions, 0);
for (int i = (players[ply].tilesDestroyed.Count - 1); i >= 0; i--) for (int i = (players[ply].TilesDestroyed.Count - 1); i >= 0; i--)
{ {
Main.tile[(int)positions[i].X, (int)positions[i].Y] = tiles[i]; Main.tile[(int)positions[i].X, (int)positions[i].Y] = tiles[i];
NetMessage.SendData(17, -1, -1, "", 1, positions[i].X, positions[i].Y, (float)0); NetMessage.SendData(17, -1, -1, "", 1, positions[i].X, positions[i].Y, (float)0);

View file

@ -141,7 +141,7 @@ namespace TShockAPI
{ {
if (TShock.players[i] == null) if (TShock.players[i] == null)
continue; continue;
if (!TShock.players[i].group.HasPermission("logs")) if (!TShock.players[i].Group.HasPermission("logs"))
continue; continue;
SendMessage(i, log, color); SendMessage(i, log, color);
@ -162,7 +162,7 @@ namespace TShockAPI
/// The number of active players on the server. /// The number of active players on the server.
/// </summary> /// </summary>
/// <returns>int playerCount</returns> /// <returns>int playerCount</returns>
public static int activePlayers() public static int ActivePlayers()
{ {
int num = 0; int num = 0;
for (int i = 0; i < Main.maxPlayers; i++) for (int i = 0; i < Main.maxPlayers; i++)
@ -265,7 +265,7 @@ namespace TShockAPI
{ {
if (!Netplay.serverSock[ply].active || Netplay.serverSock[ply].kill) if (!Netplay.serverSock[ply].active || Netplay.serverSock[ply].kill)
return true; return true;
if (!TShock.players[ply].group.HasPermission("immunetokick")) if (!TShock.players[ply].Group.HasPermission("immunetokick"))
{ {
string playerName = Main.player[ply].name; string playerName = Main.player[ply].name;
NetMessage.SendData(0x2, ply, -1, string.Format("Kicked: {0}", reason), 0x0, 0f, 0f, 0f); NetMessage.SendData(0x2, ply, -1, string.Format("Kicked: {0}", reason), 0x0, 0f, 0f, 0f);
@ -288,7 +288,7 @@ namespace TShockAPI
{ {
if (!Netplay.serverSock[plr].active || Netplay.serverSock[plr].kill) if (!Netplay.serverSock[plr].active || Netplay.serverSock[plr].kill)
return true; return true;
if (!TShock.players[plr].group.HasPermission("immunetoban")) if (!TShock.players[plr].Group.HasPermission("immunetoban"))
{ {
string ip = GetPlayerIP(plr); string ip = GetPlayerIP(plr);
string playerName = Main.player[plr].name; string playerName = Main.player[plr].name;
@ -326,7 +326,7 @@ namespace TShockAPI
private static bool HandleBadPlayer(int ply, string overridePermission, bool ban, bool kick, string reason) private static bool HandleBadPlayer(int ply, string overridePermission, bool ban, bool kick, string reason)
{ {
if (!TShock.players[ply].group.HasPermission(overridePermission)) if (!TShock.players[ply].Group.HasPermission(overridePermission))
{ {
if (ban) if (ban)
{ {

View file

@ -77,7 +77,7 @@ namespace TShockAPI
{ {
if (Main.player[i].active) if (Main.player[i].active)
{ {
if (!TShock.players[i].group.HasPermission("maintenance")) if (!TShock.players[i].Group.HasPermission("maintenance"))
return; return;
Tools.SendMessage(i, "The server is out of date. To update, type /updatenow."); Tools.SendMessage(i, "The server is out of date. To update, type /updatenow.");
for (int j = 4; j < changes.Length; j++) for (int j = 4; j < changes.Length; j++)