Made handle checks consistent. Also some of us don't have a lot of horizontal space.

This commit is contained in:
high 2011-08-07 03:01:29 -04:00
parent b061a6c085
commit 80af1c52ca

View file

@ -448,58 +448,58 @@ namespace TShockAPI
private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e) private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e)
{ {
if (!e.Handled) if (e.Handled)
return;
var tsplr = Players[msg.whoAmI];
if (tsplr == null)
{ {
var tsplr = Players[msg.whoAmI]; e.Handled = true;
if (tsplr == null) return;
{ }
e.Handled = true;
return;
}
if (!Tools.ValidString(text)) if (!Tools.ValidString(text))
{ {
Tools.Kick(tsplr, "Unprintable character in chat"); Tools.Kick(tsplr, "Unprintable character in chat");
e.Handled = true; e.Handled = true;
return; return;
} }
if (msg.whoAmI != ply) if (msg.whoAmI != ply)
{ {
e.Handled = Tools.HandleGriefer(tsplr, "Faking Chat"); e.Handled = Tools.HandleGriefer(tsplr, "Faking Chat");
return; return;
} }
if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/") && Config.AdminChatEnabled) if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/") && Config.AdminChatEnabled)
{ {
Tools.Broadcast(Config.AdminChatPrefix + "<" + tsplr.Name + "> " + text, Tools.Broadcast(Config.AdminChatPrefix + "<" + tsplr.Name + "> " + text,
tsplr.Group.R, tsplr.Group.G, tsplr.Group.R, tsplr.Group.G,
tsplr.Group.B); tsplr.Group.B);
e.Handled = true; e.Handled = true;
return; return;
} }
if (text.StartsWith("/")) if (text.StartsWith("/"))
{
try
{ {
try e.Handled = Commands.HandleCommand(tsplr, text);
{
e.Handled = Commands.HandleCommand(tsplr, text);
}
catch (Exception ex)
{
Log.ConsoleError("Command exception");
Log.Error(ex.ToString());
}
} }
else catch (Exception ex)
{ {
Tools.Broadcast("{2}<{0}> {1}".SFormat(tsplr.Name, text, Config.ChatDisplayGroup ? "[{0}] ".SFormat(tsplr.Group.Name) : ""), Log.ConsoleError("Command exception");
tsplr.Group.R, tsplr.Group.G, Log.Error(ex.ToString());
tsplr.Group.B);
//Log.Info(string.Format("{0} said: {1}", tsplr.Name, text));
e.Handled = true;
} }
} }
else
{
Tools.Broadcast("{2}<{0}> {1}".SFormat(tsplr.Name, text, Config.ChatDisplayGroup ? "[{0}] ".SFormat(tsplr.Group.Name) : ""),
tsplr.Group.R, tsplr.Group.G,
tsplr.Group.B);
//Log.Info(string.Format("{0} said: {1}", tsplr.Name, text));
e.Handled = true;
}
} }
/// <summary> /// <summary>
@ -560,45 +560,45 @@ namespace TShockAPI
private void GetData(GetDataEventArgs e) private void GetData(GetDataEventArgs e)
{ {
if (!e.Handled) if (e.Handled)
return;
PacketTypes type = e.MsgID;
var player = Players[e.Msg.whoAmI];
if (player == null)
{ {
PacketTypes type = e.MsgID; e.Handled = true;
var player = Players[e.Msg.whoAmI]; return;
if (player == null) }
{
e.Handled = true;
return;
}
if (!player.ConnectionAlive) if (!player.ConnectionAlive)
{ {
e.Handled = true; e.Handled = true;
return; return;
} }
//if (type == PacketTypes.SyncPlayers) //if (type == PacketTypes.SyncPlayers)
//Debug.WriteLine("Recv: {0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type.ToString()); //Debug.WriteLine("Recv: {0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
// Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions) // Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions)
if ((Config.BanKillTileAbusers || Config.KickKillTileAbusers) && if ((Config.BanKillTileAbusers || Config.KickKillTileAbusers) &&
player.TileThreshold >= Config.TileThreshold && !player.Group.HasPermission("ignoregriefdetection")) player.TileThreshold >= Config.TileThreshold && !player.Group.HasPermission("ignoregriefdetection"))
{
Log.Debug("Rejecting " + type + " from " + player.Name + " as this player is about to be kicked");
e.Handled = true;
}
else
{
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
{ {
Log.Debug("Rejecting " + type + " from " + player.Name + " as this player is about to be kicked"); try
e.Handled = true;
}
else
{
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
{ {
try if (GetDataHandlers.HandlerGetData(type, player, data))
{ e.Handled = true;
if (GetDataHandlers.HandlerGetData(type, player, data)) }
e.Handled = true; catch (Exception ex)
} {
catch (Exception ex) Log.Error(ex.ToString());
{
Log.Error(ex.ToString());
}
} }
} }
} }