Removed redundant debug break

Cleaned up the binary readers
This commit is contained in:
high 2011-06-05 16:35:36 -04:00
parent 6fdb7e028c
commit 5d504edbaa

View file

@ -51,6 +51,7 @@ namespace TShockAPI
static TShock() static TShock()
{ {
//Tools.LoadGroups(); //Tools.LoadGroups();
#region Blacklisted tiles #region Blacklisted tiles
BlacklistTiles = new bool[0x80]; BlacklistTiles = new bool[0x80];
@ -133,9 +134,6 @@ namespace TShockAPI
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
if (Main.worldPathName != null) if (Main.worldPathName != null)
{ {
Main.worldPathName += ".crash"; Main.worldPathName += ".crash";
@ -211,13 +209,11 @@ namespace TShockAPI
} }
else if (e.MsgID == 0x1e) else if (e.MsgID == 0x1e)
{ {
byte id;
bool pvp;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
id = br.ReadByte(); int id = br.ReadByte();
pvp = br.ReadBoolean(); bool pvp = br.ReadBoolean();
}
Main.player[e.Msg.whoAmI].hostile = pvp; Main.player[e.Msg.whoAmI].hostile = pvp;
if (id != e.Msg.whoAmI) if (id != e.Msg.whoAmI)
Main.player[e.Msg.whoAmI].hostile = true; Main.player[e.Msg.whoAmI].hostile = true;
@ -227,6 +223,7 @@ namespace TShockAPI
e.Handled = true; e.Handled = true;
return; return;
} }
}
else if (e.MsgID == 0x0A) //SendSection else if (e.MsgID == 0x0A) //SendSection
{ {
Tools.Broadcast(string.Format("{0}({1}) attempted sending a section", Main.player[e.Msg.whoAmI].name, e.Msg.whoAmI)); Tools.Broadcast(string.Format("{0}({1}) attempted sending a section", Main.player[e.Msg.whoAmI].name, e.Msg.whoAmI));
@ -250,51 +247,55 @@ namespace TShockAPI
} }
else if (e.MsgID == 0x10) else if (e.MsgID == 0x10)
{ {
byte ply;
Int16 life, maxLife;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
ply = br.ReadByte(); byte ply = br.ReadByte();
life = br.ReadInt16(); short life = br.ReadInt16();
maxLife = br.ReadInt16(); short maxLife = br.ReadInt16();
}
if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife) if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife)
{
if (players[ply].syncHP) if (players[ply].syncHP)
{ {
if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife) if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife)
Tools.HandleCheater(ply); Tools.HandleCheater(ply);
} }
else else
{
players[ply].syncHP = true; players[ply].syncHP = true;
} }
}
}
}
else if (e.MsgID == 0x2a) else if (e.MsgID == 0x2a)
{ {
byte ply;
Int16 mana, maxmana;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
ply = br.ReadByte(); byte ply = br.ReadByte();
mana = br.ReadInt16(); short mana = br.ReadInt16();
maxmana = br.ReadInt16(); short 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)
{ {
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"); Log.Info(Tools.FindPlayer(ply) +
" had increased max mana by more than 20 or increased mana more than max");
} }
else else
{
players[ply].syncMP = true; players[ply].syncMP = true;
} }
} }
}
}
else if (e.MsgID == 0x19) // Chat Text else if (e.MsgID == 0x19) // Chat Text
{ {
byte ply;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
ply = br.ReadByte(); byte ply = br.ReadByte();
}
if (e.Msg.whoAmI != ply) if (e.Msg.whoAmI != ply)
{ {
//fuck you faggot //fuck you faggot
@ -302,29 +303,21 @@ namespace TShockAPI
Tools.HandleCheater(ply); Tools.HandleCheater(ply);
} }
} }
}
else if (e.MsgID == 0x1B) // New Projectile else if (e.MsgID == 0x1B) // New Projectile
{ {
Int16 ident;
float posx;
float posy;
float velx;
float vely;
float knockback;
Int16 dmg;
byte owner;
byte type;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
ident = br.ReadInt16(); short ident = br.ReadInt16();
posx = br.ReadSingle(); float posx = br.ReadSingle();
posy = br.ReadSingle(); float posy = br.ReadSingle();
velx = br.ReadSingle(); float velx = br.ReadSingle();
vely = br.ReadSingle(); float vely = br.ReadSingle();
knockback = br.ReadSingle(); float knockback = br.ReadSingle();
dmg = br.ReadInt16(); short dmg = br.ReadInt16();
owner = br.ReadByte(); byte owner = br.ReadByte();
type = br.ReadByte(); byte type = br.ReadByte();
}
if (type == 29 || type == 28) if (type == 29 || type == 28)
{ {
if (!players[e.Msg.whoAmI].group.HasPermission("ignoregriefdetection")) if (!players[e.Msg.whoAmI].group.HasPermission("ignoregriefdetection"))
@ -335,45 +328,42 @@ namespace TShockAPI
if (ConfigurationManager.banBoom) if (ConfigurationManager.banBoom)
FileTools.WriteGrief((int)i); FileTools.WriteGrief((int)i);
Tools.Kick((int)i, "Explosives was thrown."); Tools.Kick((int)i, "Explosives was thrown.");
Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banBoom ? "banned" : "kicked") + " for throwing an explosive device."); Tools.Broadcast(Main.player[i].name + " was " +
(ConfigurationManager.banBoom ? "banned" : "kicked") +
" for throwing an explosive device.");
e.Handled = true; e.Handled = true;
} }
} }
} }
} }
}
else if (e.MsgID == 0x2C) // KillMe 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))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
id = br.ReadByte(); byte id = br.ReadByte();
hitdirection = br.ReadByte(); byte hitdirection = br.ReadByte();
dmg = br.ReadInt16(); short dmg = br.ReadInt16();
pvp = br.ReadBoolean(); bool pvp = br.ReadBoolean();
}
if (id != e.Msg.whoAmI) if (id != e.Msg.whoAmI)
{ {
Tools.HandleGriefer(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."); Log.Info(Tools.FindPlayer(e.Msg.whoAmI) +
" was kicked for trying to execute KillMe on someone else.");
e.Handled = true; e.Handled = true;
} }
} }
}
else if (e.MsgID == 0x30) else if (e.MsgID == 0x30)
{ {
int x;
int y;
byte liquid;
bool lava;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{ {
x = br.ReadInt32(); int x = br.ReadInt32();
y = br.ReadInt32(); int y = br.ReadInt32();
liquid = br.ReadByte(); byte liquid = br.ReadByte();
lava = br.ReadBoolean(); bool 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"))
@ -392,6 +382,7 @@ namespace TShockAPI
} }
} }
} }
}
void OnGreetPlayer(int who, HandledEventArgs e) void OnGreetPlayer(int who, HandledEventArgs e)
{ {