merged master into permissions-devel

This commit is contained in:
Maverick Motherfucker 2011-06-05 12:12:48 -07:00
commit 7c2f62d1be
6 changed files with 156 additions and 44 deletions

View file

@ -101,20 +101,66 @@ namespace TShockAPI
commands.Add(new Command("help", "", new CommandDelegate(Help))); commands.Add(new Command("help", "", new CommandDelegate(Help)));
commands.Add(new Command("slap", "pvpfun", new CommandDelegate(Slap))); commands.Add(new Command("slap", "pvpfun", new CommandDelegate(Slap)));
commands.Add(new Command("off-nosave", "maintenance", new CommandDelegate(OffNoSave))); commands.Add(new Command("off-nosave", "maintenance", new CommandDelegate(OffNoSave)));
commands.Add(new Command("protectspawn", "cfg", new CommandDelegate(ProtectSpawn))); commands.Add(new Command("protectspawn", "editspawn", new CommandDelegate(ProtectSpawn)));
commands.Add(new Command("debug-config", "cfg", new CommandDelegate(DebugConfiguration)));
commands.Add(new Command("playing", "", new CommandDelegate(Playing)));
//TShock.admincommandList.Add("debug-config", new CommandDelegate(DebugConfiguration));
//TShock.admincommandList.Add("playing", new CommandDelegate(Playing));
//TShock.commandList.Add("help", new CommandDelegate(Help));
//TShock.commandList.Add("playing", new CommandDelegate(Playing));
if (ConfigurationManager.distributationAgent != "terraria-online")
{
TShock.admincommandList.Add("kill", new CommandDelegate(Kill));
TShock.admincommandList.Add("item", new CommandDelegate(Item));
TShock.admincommandList.Add("give", new CommandDelegate(Give));
TShock.admincommandList.Add("heal", new CommandDelegate(Heal));
}
} }
#region Command Methods #region Command Methods
public static void Playing(CommandArgs args)
{
Tools.SendMessage(args.PlayerID, Tools.GetPlayers());
}
public static void DebugConfiguration(CommandArgs args)
{
int ply = args.PlayerID;
Tools.SendMessage(ply, "TShock Config:");
string lineOne = "";
lineOne += "KickCheater : " + ConfigurationManager.kickCheater + ", ";
lineOne += "BanCheater : " + ConfigurationManager.banCheater + ", ";
lineOne += "KickGriefer : " + ConfigurationManager.kickGriefer + ", ";
lineOne += "BanGriefer : " + ConfigurationManager.banGriefer;
Tools.SendMessage(ply, lineOne, new float[] { 255f, 255f, 0f });
string lineTwo = "";
lineTwo += "BanTnt : " + ConfigurationManager.banTnt + ", ";
lineTwo += "KickTnt : " + ConfigurationManager.kickTnt + ", ";
lineTwo += "BanBoom : " + ConfigurationManager.banBoom + ", ";
lineTwo += "KickBoom : " + ConfigurationManager.kickBoom;
Tools.SendMessage(ply, lineTwo, new float[] { 255f, 255f, 0f });
string lineThree = "";
lineThree += "InvMultiplier : " + ConfigurationManager.invasionMultiplier + ", ";
lineThree += "ProtectS : " + ConfigurationManager.spawnProtect + ", ";
lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", ";
lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", ";
lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate + ", ";
Tools.SendMessage(ply, lineThree, new float[] { 255f, 255f, 0f});
}
public static void Kick(CommandArgs args) public static void Kick(CommandArgs args)
{ {
string plStr = args.Message.Remove(0, 5).Trim(); string plStr = args.Message.Remove(0, 5).Trim();
int ply = args.PlayerID; int ply = args.PlayerID;
if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == "")) int player = Tools.FindPlayer(plStr);
if (!(player == -1 || player == -2 || plStr == ""))
{ {
if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetokick")) if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetokick"))
{ {
Tools.Kick(Tools.FindPlayer(plStr), "You were kicked."); Tools.Kick(player, "You were kicked.");
Tools.Broadcast(plStr + " was kicked by " + Tools.FindPlayer(ply)); Tools.Broadcast(Tools.FindPlayer(player) + " was kicked by " + Tools.FindPlayer(ply));
} }
else else
Tools.SendMessage(ply, "You can't kick another admin!", new float[] { 255f, 0f, 0f }); Tools.SendMessage(ply, "You can't kick another admin!", new float[] { 255f, 0f, 0f });
@ -129,12 +175,14 @@ namespace TShockAPI
{ {
string plStr = args.Message.Remove(0, 4).Trim(); string plStr = args.Message.Remove(0, 4).Trim();
int ply = args.PlayerID; int ply = args.PlayerID;
if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == "")) int player = Tools.FindPlayer(plStr);
if (!(player == -1 || player == -2 || plStr == ""))
{ {
if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetoban")) if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetoban"))
{ {
FileTools.WriteBan(Tools.FindPlayer(plStr)); FileTools.WriteBan(player);
Tools.Kick(Tools.FindPlayer(plStr), "You were banned."); Tools.Kick(player, "You were banned.");
Tools.Broadcast(Tools.FindPlayer(ply) + " banned " + Tools.FindPlayer(player) + "!");
} }
else else
Tools.SendMessage(ply, "You can't ban another admin!", new float[] { 255f, 0f, 0f }); Tools.SendMessage(ply, "You can't ban another admin!", new float[] { 255f, 0f, 0f });
@ -274,7 +322,7 @@ namespace TShockAPI
{ {
int ply = args.PlayerID; int ply = args.PlayerID;
string player = args.Message.Remove(0, 3).Trim(); string player = args.Message.Remove(0, 3).Trim();
if (Tools.FindPlayer(player) != -1 && player != "") if (Tools.FindPlayer(player) != -1 && Tools.FindPlayer(player) != -2 && player != "")
{ {
TShock.Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y); TShock.Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y);
Tools.SendMessage(ply, "Teleported to " + player); Tools.SendMessage(ply, "Teleported to " + player);
@ -287,7 +335,7 @@ namespace TShockAPI
{ {
int ply = args.PlayerID; int ply = args.PlayerID;
string player = args.Message.Remove(0, 7).Trim(); string player = args.Message.Remove(0, 7).Trim();
if (Tools.FindPlayer(player) != -1 && player != "") if (Tools.FindPlayer(player) != -1 && Tools.FindPlayer(player) != -2 && player != "")
{ {
TShock.Teleport(Tools.FindPlayer(player), Main.player[ply].position.X, Main.player[ply].position.Y); TShock.Teleport(Tools.FindPlayer(player), Main.player[ply].position.X, Main.player[ply].position.Y);
Tools.SendMessage(Tools.FindPlayer(player), "You were teleported to " + Tools.FindPlayer(ply) + "."); Tools.SendMessage(Tools.FindPlayer(player), "You were teleported to " + Tools.FindPlayer(ply) + ".");
@ -465,18 +513,18 @@ namespace TShockAPI
public static void MaxSpawns(CommandArgs args) public static void MaxSpawns(CommandArgs args)
{ {
int ply = args.PlayerID; int ply = args.PlayerID;
int amount = 4;//Convert.ToInt32(args.Message.Remove(0, 10)); int amount = Convert.ToInt32(args.Message.Remove(0, 10));
int.TryParse(args.Message.Remove(0, 10), out amount); int.TryParse(args.Message.Remove(0, 10), out amount);
NPC.maxSpawns = amount; NPC.defaultSpawnRate = amount;
Tools.Broadcast(Tools.FindPlayer(ply) + " changed the maximum spawns to: " + amount); Tools.Broadcast(Tools.FindPlayer(ply) + " changed the maximum spawns to: " + amount);
} }
public static void SpawnRate(CommandArgs args) public static void SpawnRate(CommandArgs args)
{ {
int ply = args.PlayerID; int ply = args.PlayerID;
int amount = 700;//Convert.ToInt32(args.Message.Remove(0, 10)); int amount = Convert.ToInt32(args.Message.Remove(0, 10));
int.TryParse(args.Message.Remove(0, 10), out amount); int.TryParse(args.Message.Remove(0, 10), out amount);
NPC.spawnRate = amount; NPC.defaultSpawnRate = amount;
Tools.Broadcast(Tools.FindPlayer(ply) + " changed the spawn rate to: " + amount); Tools.Broadcast(Tools.FindPlayer(ply) + " changed the spawn rate to: " + amount);
} }

View file

@ -25,5 +25,6 @@ namespace TShockAPI
public bool KickExplosives = true; public bool KickExplosives = true;
public bool SpawnProtection = true; public bool SpawnProtection = true;
public int SpawnProtectionRadius = 5; public int SpawnProtectionRadius = 5;
public string DistributationAgent = "facepunch";
} }
} }

View file

@ -31,6 +31,7 @@ namespace TShockAPI
public static bool kickBoom = true; public static bool kickBoom = true;
public static bool spawnProtect = true; public static bool spawnProtect = true;
public static int spawnProtectRadius = 5; public static int spawnProtectRadius = 5;
public static string distributationAgent = "facepunch";
public enum NPCList : int public enum NPCList : int
{ {
@ -62,6 +63,9 @@ namespace TShockAPI
kickBoom = cfg.KickExplosives; kickBoom = cfg.KickExplosives;
spawnProtect = cfg.SpawnProtection; spawnProtect = cfg.SpawnProtection;
spawnProtectRadius = cfg.SpawnProtectionRadius; spawnProtectRadius = cfg.SpawnProtectionRadius;
distributationAgent = cfg.DistributationAgent;
Terraria.NPC.maxSpawns = defaultMaxSpawns;
Terraria.NPC.defaultSpawnRate = defaultSpawnRate;
} }
public static void WriteJsonConfiguration() public static void WriteJsonConfiguration()

View file

@ -84,7 +84,7 @@ namespace TShockAPI
String text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " - " + caller + message; String text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " - " + caller + message;
Console.WriteLine(text); //Console.WriteLine(text);
if (!MayWriteType(level)) if (!MayWriteType(level))
{ {

View file

@ -8,6 +8,7 @@ namespace TShockAPI
public class TSPlayer public class TSPlayer
{ {
public uint tileThreshold; public uint tileThreshold;
public Dictionary<TShock.Position, Terraria.Tile> tilesDestroyed = new Dictionary<TShock.Position, Terraria.Tile>();
public bool syncHP = false; public bool syncHP = false;
public bool syncMP = false; public bool syncMP = false;
public Group group; public Group group;

View file

@ -15,7 +15,9 @@ namespace TShockAPI
public static string saveDir = "./tshock/"; public static string saveDir = "./tshock/";
public static Version VersionNum = new Version(1, 6, 0, 0); public static Version VersionNum = new Version(1, 7, 0, 0);
public static string VersionCodename = "Facepunch";
public static bool shownVersion = false; public static bool shownVersion = false;
@ -112,6 +114,7 @@ namespace TShockAPI
{ {
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
Console.WriteLine("TShock Version " + Version.Major + "." + Version.Minor + "." + Version.Build + "." + Version.Revision + " (" + VersionCodename + ") now running.");
Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, true); Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, true);
Log.Info("Starting..."); Log.Info("Starting...");
GameHooks.OnPreInitialize += OnPreInit; GameHooks.OnPreInitialize += OnPreInit;
@ -190,9 +193,10 @@ 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((float)x, (float)y), Main.tile[x, y]);
} }
return;
} }
return;
} }
else if (e.MsgID == 0x1e) else if (e.MsgID == 0x1e)
{ {
@ -262,14 +266,16 @@ namespace TShockAPI
mana = br.ReadInt16(); mana = br.ReadInt16();
maxmana = br.ReadInt16(); maxmana = br.ReadInt16();
} }
if (maxmana > Main.player[ply].statManaMax + 20 || mana > maxmana) if (maxmana > Main.player[ply].statManaMax + 20 || mana > maxmana)
if (players[ply].syncMP) {
{ if (players[ply].syncMP)
if (maxmana > Main.player[ply].statManaMax + 20 || mana > maxmana) {
Tools.HandleCheater(ply); Tools.HandleCheater(ply);
} Log.Info(Tools.FindPlayer(ply) + " had increased max mana by more than 20 or increased mana more than max");
else }
players[ply].syncMP = true; else
players[ply].syncMP = true;
}
} }
else if (e.MsgID == 0x19) // Chat Text else if (e.MsgID == 0x19) // Chat Text
{ {
@ -281,6 +287,7 @@ namespace TShockAPI
if (e.Msg.whoAmI != ply) if (e.Msg.whoAmI != ply)
{ {
//fuck you faggot //fuck you faggot
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + " was kicked for trying to fake chat as someone else.");
Tools.HandleCheater(ply); Tools.HandleCheater(ply);
} }
} }
@ -323,6 +330,26 @@ namespace TShockAPI
} }
} }
} }
else if (e.MsgID == 0x2C) // KillMe
{
byte id;
byte hitdirection;
short dmg;
bool pvp;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{
id = br.ReadByte();
hitdirection = br.ReadByte();
dmg = br.ReadInt16();
pvp = br.ReadBoolean();
}
if (id != e.Msg.whoAmI)
{
Tools.HandleGriefer(e.Msg.whoAmI);
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + " was kicked for trying to execute KillMe on someone else.");
e.Handled = true;
}
}
else if (e.MsgID == 0x30) else if (e.MsgID == 0x30)
{ {
int x; int x;
@ -337,6 +364,7 @@ namespace TShockAPI
lava = br.ReadBoolean(); lava = br.ReadBoolean();
} }
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);
@ -346,23 +374,10 @@ namespace TShockAPI
e.Handled = true; e.Handled = true;
} }
} }
}
else if (e.MsgID == 0x2C) // KillMe
{
byte id;
byte hitdirection;
short dmg;
bool pvp;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{
id = br.ReadByte();
hitdirection = br.ReadByte();
dmg = br.ReadInt16();
pvp = br.ReadBoolean();
} }
if (id != e.Msg.whoAmI) else if (e.MsgID == 0x22) // Client only KillTile
{ {
Tools.HandleCheater(e.Msg.whoAmI); e.Handled = true; // Client only uses it for chests, but sends regular 17 as well.
} }
} }
} }
@ -431,6 +446,11 @@ namespace TShockAPI
{ {
Tools.Kick(ply, "You are banned."); Tools.Kick(ply, "You are banned.");
} }
else if (Tools.FindPlayer(ply).Length > 32)
{
Tools.Kick(ply, "Your name was too long.");
Tools.Broadcast(ip + " was kicked because their name exceeded 32 characters.");
}
else if (FileTools.CheckCheat(ip)) else if (FileTools.CheckCheat(ip))
{ {
Tools.Kick(ply, "You were flagged for cheating."); Tools.Kick(ply, "You were flagged for cheating.");
@ -476,9 +496,14 @@ namespace TShockAPI
FileTools.WriteGrief((int)i); FileTools.WriteGrief((int)i);
Tools.Kick((int)i, "Kill tile abuse detected."); Tools.Kick((int)i, "Kill tile abuse detected.");
Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banTnt ? "banned" : "kicked") + " for kill tile abuse."); Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banTnt ? "banned" : "kicked") + " for kill tile abuse.");
RevertKillTile((int)i);
}
else if (players[i].tileThreshold > 0)
{
players[i].tileThreshold = 0;
players[i].tilesDestroyed.Clear();
} }
} }
players[i].tileThreshold = 0;
} }
else if (players[i].tileThreshold > 0) else if (players[i].tileThreshold > 0)
{ {
@ -525,17 +550,22 @@ namespace TShockAPI
public static void Teleport(int ply, int x, int y) public static void Teleport(int ply, int x, int y)
{ {
Main.player[ply].velocity = new Vector2(0, 0); /*Main.player[ply].velocity = new Vector2(0, 0);
NetMessage.SendData(0x0d, -1, -1, "", ply); NetMessage.SendData(0x0d, -1, -1, "", ply);
Main.player[ply].position.X = x; Main.player[ply].position.X = x;
Main.player[ply].position.Y = y - 0x2a; Main.player[ply].position.Y = y - 0x2a;
NetMessage.SendData(0x0d, -1, -1, "", ply); NetMessage.SendData(0x0d, -1, -1, "", ply);
UpdatePlayers(); UpdatePlayers();*/
Main.player[ply].position.X = (float)x;
Main.player[ply].position.Y = (float)y;
NetMessage.SendData(0x0d, -1, ply, "", ply);
NetMessage.SendData(0x0d, -1, -1, "", ply);
NetMessage.syncPlayers();
} }
public static void Teleport(int ply, float x, float y) public static void Teleport(int ply, float x, float y)
{ {
Main.player[ply].position.X = x; /*Main.player[ply].position.X = x;
Main.player[ply].position.Y = y - 0x2a; Main.player[ply].position.Y = y - 0x2a;
NetMessage.SendData(0x14, -1, -1, "", 10, x, y); NetMessage.SendData(0x14, -1, -1, "", 10, x, y);
NetMessage.SendData(0x0d, -1, -1, "", ply); NetMessage.SendData(0x0d, -1, -1, "", ply);
@ -546,7 +576,12 @@ namespace TShockAPI
NetMessage.SendData(0xC, -1, -1, "", ply); NetMessage.SendData(0xC, -1, -1, "", ply);
Main.player[ply].SpawnX = oldx; Main.player[ply].SpawnX = oldx;
Main.player[ply].SpawnY = oldy; Main.player[ply].SpawnY = oldy;
UpdatePlayers(); UpdatePlayers();*/
Main.player[ply].position.X = x;
Main.player[ply].position.Y = y;
NetMessage.SendData(0x0d, -1, ply, "", ply);
NetMessage.SendData(0x0d, -1, -1, "", ply);
NetMessage.syncPlayers();
} }
public static void StartInvasion() public static void StartInvasion()
@ -679,7 +714,10 @@ namespace TShockAPI
for (int i = 0; i < 44; i++) for (int i = 0; i < 44; i++)
{ {
if (Main.player[plr].inventory[i].stack > Main.player[plr].inventory[i].maxStack) if (Main.player[plr].inventory[i].stack > Main.player[plr].inventory[i].maxStack)
{
Log.Info(Tools.FindPlayer(plr) + " had " + Main.player[plr].inventory[i].stack.ToString() + " of " + Main.player[plr].inventory[i].name + " which has a max stack of " + Main.player[plr].inventory[i].maxStack.ToString());
return true; return true;
}
} }
return false; return false;
} }
@ -694,5 +732,25 @@ namespace TShockAPI
else else
return true; return true;
} }
public class Position
{
public float X;
public float Y;
public Position(float x, float y) { X = x; Y = y; }
}
public static void RevertKillTile(int ply)
{
Tile[] tiles = new Tile[players[ply].tilesDestroyed.Count];
players[ply].tilesDestroyed.Values.CopyTo(tiles, 0);
Position[] positions = new Position[players[ply].tilesDestroyed.Count];
players[ply].tilesDestroyed.Keys.CopyTo(positions, 0);
for (int i = (players[ply].tilesDestroyed.Count - 1); i >= 0; 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);
}
}
} }
} }