GetData now blocks the server from handling packets from sockets set to die.

This commit is contained in:
high 2011-06-07 10:40:04 -04:00
parent 5902aa7146
commit 5ee04572d6

View file

@ -200,27 +200,37 @@ namespace TShockAPI
private void GetData(GetDataEventArgs e) private void GetData(GetDataEventArgs e)
{ {
e.Handled = HandleGetData(e);
}
private bool HandleGetData(GetDataEventArgs e)
{
if (!Netplay.serverSock[e.Msg.whoAmI].active || Netplay.serverSock[e.Msg.whoAmI].kill)
return true;
if (e.MsgID == 4) if (e.MsgID == 4)
{ {
var ban = Bans.GetBanByName(Main.player[e.Msg.whoAmI].name); var ban = Bans.GetBanByName(Main.player[e.Msg.whoAmI].name);
if (ban != null) if (ban != null)
{ {
Tools.Kick(e.Msg.whoAmI, "You are banned: " + ban.Reason); Tools.Kick(e.Msg.whoAmI, "You are banned: " + ban.Reason);
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.Kick(e.Msg.whoAmI, "Name exceeded 32 characters."); Tools.Kick(e.Msg.whoAmI, "Name exceeded 32 characters.");
return true;
} }
if (players[e.Msg.whoAmI] == null) if (players[e.Msg.whoAmI] == null)
{ {
Tools.Kick(e.Msg.whoAmI, "Player doesn't exist"); Tools.Kick(e.Msg.whoAmI, "Player doesn't exist");
e.Handled = true; return true;
} }
else if (players[e.Msg.whoAmI].receivedInfo) else if (players[e.Msg.whoAmI].receivedInfo)
{ {
Tools.Kick(e.Msg.whoAmI, "Sent client info more than once"); Tools.Kick(e.Msg.whoAmI, "Sent client info more than once");
e.Handled = true; return true;
} }
else else
{ {
@ -241,7 +251,7 @@ namespace TShockAPI
if (size > 5 || Math.Abs(plyX - tileX) > 10 || Math.Abs(plyY - tileY) > 10) if (size > 5 || Math.Abs(plyX - tileX) > 10 || Math.Abs(plyY - tileY) > 10)
{ {
Ban(e.Msg.whoAmI, "Send Tile Square Abuse"); Ban(e.Msg.whoAmI, "Send Tile Square Abuse");
e.Handled = true; return true;
} }
} }
} }
@ -265,12 +275,13 @@ namespace TShockAPI
TShock.Ban(e.Msg.whoAmI, "Placing impossible to place blocks."); TShock.Ban(e.Msg.whoAmI, "Placing impossible to place blocks.");
Tools.Broadcast(Main.player[e.Msg.whoAmI].name + Tools.Broadcast(Main.player[e.Msg.whoAmI].name +
" was banned for placing impossible to place blocks."); " was banned for placing impossible to place blocks.");
e.Handled = true; return true;
} }
} }
if (type == 0 || type == 1) if (type == 0 || type == 1)
{
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);
@ -278,16 +289,17 @@ namespace TShockAPI
{ {
Tools.SendMessage(e.Msg.whoAmI, "Spawn protected from changes.", Tools.SendMessage(e.Msg.whoAmI, "Spawn protected from changes.",
new[] { 255f, 0f, 0f }); new[] { 255f, 0f, 0f });
e.Handled = true; return true;
} }
} }
}
}
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;
} }
} }
else if (e.MsgID == 0x1e) else if (e.MsgID == 0x1e)
@ -303,8 +315,7 @@ namespace TShockAPI
if (ConfigurationManager.permaPvp) if (ConfigurationManager.permaPvp)
Main.player[e.Msg.whoAmI].hostile = true; Main.player[e.Msg.whoAmI].hostile = true;
NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI); NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI);
e.Handled = true; return true;
return;
} }
} }
else if (e.MsgID == 0x0A) //SendSection else if (e.MsgID == 0x0A) //SendSection
@ -312,14 +323,14 @@ namespace TShockAPI
Tools.Broadcast(string.Format("{0}({1}) attempted sending a section", Main.player[e.Msg.whoAmI].name, Tools.Broadcast(string.Format("{0}({1}) attempted sending a section", Main.player[e.Msg.whoAmI].name,
e.Msg.whoAmI)); e.Msg.whoAmI));
Tools.Kick(e.Msg.whoAmI, "SendSection abuse."); Tools.Kick(e.Msg.whoAmI, "SendSection abuse.");
e.Handled = true; return true;
} }
else if (e.MsgID == 0x17) //Npc Data else if (e.MsgID == 0x17) //Npc Data
{ {
Tools.Broadcast(string.Format("{0}({1}) attempted spawning an NPC", Main.player[e.Msg.whoAmI].name, Tools.Broadcast(string.Format("{0}({1}) attempted spawning an NPC", Main.player[e.Msg.whoAmI].name,
e.Msg.whoAmI)); e.Msg.whoAmI));
Tools.Kick(e.Msg.whoAmI, "Spawn NPC abuse"); Tools.Kick(e.Msg.whoAmI, "Spawn NPC abuse");
e.Handled = true; return true;
} }
else if (e.MsgID == 0x0D) //Update Player else if (e.MsgID == 0x0D) //Update Player
{ {
@ -327,7 +338,7 @@ namespace TShockAPI
if (plr != e.Msg.whoAmI) if (plr != e.Msg.whoAmI)
{ {
Tools.Kick(e.Msg.whoAmI, "Update Player abuse"); Tools.Kick(e.Msg.whoAmI, "Update Player abuse");
e.Handled = true; return true;
} }
} }
else if (e.MsgID == 0x10) else if (e.MsgID == 0x10)
@ -352,7 +363,7 @@ namespace TShockAPI
Tools.Kick(ply, "Abnormal life increase"); Tools.Kick(ply, "Abnormal life increase");
Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") + Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") +
" because they gained an abnormal amount of health."); " because they gained an abnormal amount of health.");
e.Handled = true; return true;
} }
} }
} }
@ -385,7 +396,7 @@ namespace TShockAPI
Tools.Kick(ply, "Abnormal mana increase"); Tools.Kick(ply, "Abnormal mana increase");
Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") + Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") +
" because they gained an abnormal amount of mana."); " because they gained an abnormal amount of mana.");
e.Handled = true; return true;
} }
} }
} }
@ -423,7 +434,7 @@ namespace TShockAPI
Tools.Broadcast(Main.player[i].name + " was " + Tools.Broadcast(Main.player[i].name + " was " +
(ConfigurationManager.banBoom ? "banned" : "kicked") + (ConfigurationManager.banBoom ? "banned" : "kicked") +
" for throwing an explosive device."); " for throwing an explosive device.");
e.Handled = true; return true;
} }
} }
} }
@ -443,7 +454,7 @@ namespace TShockAPI
Ban(e.Msg.whoAmI, "Griefer"); Ban(e.Msg.whoAmI, "Griefer");
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + Log.Info(Tools.FindPlayer(e.Msg.whoAmI) +
" was kicked for trying to execute KillMe on someone else."); " was kicked for trying to execute KillMe on someone else.");
e.Handled = true; return true;
} }
} }
} }
@ -457,7 +468,7 @@ namespace TShockAPI
byte pvp = br.ReadByte(); byte pvp = br.ReadByte();
if (!Main.player[playerid].hostile) if (!Main.player[playerid].hostile)
e.Handled = true; return true;
} }
} }
else if (e.MsgID == 0x30) else if (e.MsgID == 0x30)
@ -471,7 +482,7 @@ namespace TShockAPI
//The liquid was picked up. //The liquid was picked up.
if (liquid == 0) if (liquid == 0)
return; return false;
int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16); int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16);
int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16); int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16);
@ -492,19 +503,19 @@ namespace TShockAPI
if (lava && lavacount <= 0) if (lava && lavacount <= 0)
{ {
TShock.Ban(e.Msg.whoAmI, "Placing lava they didn't have."); TShock.Ban(e.Msg.whoAmI, "Placing lava they didn't have.");
e.Handled = true; return true;
} }
else if (!lava && watercount <= 0) else if (!lava && watercount <= 0)
{ {
TShock.Ban(e.Msg.whoAmI, "Placing water they didn't have."); TShock.Ban(e.Msg.whoAmI, "Placing water they didn't have.");
e.Handled = true; return true;
} }
if ((Math.Abs(plyX - tileX) > 6) || (Math.Abs(plyY - tileY) > 6)) if ((Math.Abs(plyX - tileX) > 6) || (Math.Abs(plyY - tileY) > 6))
{ {
TShock.Ban(e.Msg.whoAmI, "Placing impossible to place liquid."); TShock.Ban(e.Msg.whoAmI, "Placing impossible to place liquid.");
Tools.Broadcast(Main.player[e.Msg.whoAmI].name + Tools.Broadcast(Main.player[e.Msg.whoAmI].name +
" was banned for placing impossible to place liquid."); " was banned for placing impossible to place liquid.");
e.Handled = true; return true;
} }
if (ConfigurationManager.spawnProtect) if (ConfigurationManager.spawnProtect)
@ -515,7 +526,7 @@ namespace TShockAPI
if (flag) if (flag)
{ {
Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new[] { 255f, 0f, 0f }); Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new[] { 255f, 0f, 0f });
e.Handled = true; return true;
} }
} }
} }
@ -523,8 +534,10 @@ namespace TShockAPI
} }
else if (e.MsgID == 0x22) // Client only KillTile else if (e.MsgID == 0x22) // Client only KillTile
{ {
e.Handled = true; // Client only uses it for chests, but sends regular 17 as well. return true; // Client only uses it for chests, but sends regular 17 as well.
} }
return false;
} }
private void OnGreetPlayer(int who, HandledEventArgs e) private void OnGreetPlayer(int who, HandledEventArgs e)