/*
TShock, a server mod for Terraria
Copyright (C) 2011-2013 Nyx Studios (fka. The TShock Team)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Streams;
using System.Linq;
using System.Text;
using TShockAPI.DB;
using Terraria;
using TShockAPI.Net;
namespace TShockAPI
{
public delegate bool GetDataHandlerDelegate(GetDataHandlerArgs args);
public class GetDataHandlerArgs : EventArgs
{
public TSPlayer Player { get; private set; }
public MemoryStream Data { get; private set; }
public Player TPlayer
{
get { return Player.TPlayer; }
}
public GetDataHandlerArgs(TSPlayer player, MemoryStream data)
{
Player = player;
Data = data;
}
}
public static class GetDataHandlers
{
private static Dictionary GetDataHandlerDelegates;
public static int[] WhitelistBuffMaxTime;
#region Events
///
/// Used when a TileEdit event is called.
///
public class TileEditEventArgs : HandledEventArgs
{
///
/// The TSPlayer who made the tile edit
///
public TSPlayer Player { get; set; }
///
/// The tile coordinate on the X plane
///
public int X { get; set; }
///
/// The tile coordinate on the Y plane
///
public int Y { get; set; }
///
/// The Tile ID being edited.
///
public byte EditData { get; set; }
///
/// The EditType.
/// (KillTile = 0, PlaceTile = 1, KillWall = 2, PlaceWall = 3, KillTileNoItem = 4, PlaceWire = 5, KillWire = 6)
///
public EditAction Action { get; set; }
///
/// Did the tile get destroyed successfully.
///
public EditType editDetail { get; set; }
///
/// Used when a tile is placed to denote a subtype of tile. (e.g. for tile id 21: Chest = 0, Gold Chest = 1)
///
public byte Style { get; set; }
}
///
/// TileEdit - called when a tile is placed or destroyed
///
public static HandlerList TileEdit;
private static bool OnTileEdit(TSPlayer ply, int x, int y, EditAction action, EditType editDetail, byte editData, byte style)
{
if (TileEdit == null)
return false;
var args = new TileEditEventArgs
{
Player = ply,
X = x,
Y = y,
Action = action,
EditData = editData,
editDetail = editDetail,
Style = style
};
TileEdit.Invoke(null, args);
return args.Handled;
}
///
/// For use in a TogglePvp event
///
public class TogglePvpEventArgs : HandledEventArgs
{
///
/// The Terraria player ID of the player
///
public byte PlayerId { get; set; }
///
/// Enable/disable pvp?
///
public bool Pvp { get; set; }
}
///
/// TogglePvp - called when a player toggles pvp
///
public static HandlerList TogglePvp;
private static bool OnPvpToggled(byte _id, bool _pvp)
{
if (TogglePvp == null)
return false;
var args = new TogglePvpEventArgs
{
PlayerId = _id,
Pvp = _pvp,
};
TogglePvp.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerTeam event
///
public class PlayerTeamEventArgs : HandledEventArgs
{
///
/// The Terraria player ID of the player
///
public byte PlayerId { get; set; }
///
/// Enable/disable pvp?
///
public byte Team { get; set; }
}
///
/// TogglePvp - called when a player toggles pvp
///
public static HandlerList PlayerTeam;
private static bool OnPlayerTeam(byte _id, byte _team)
{
if (PlayerTeam == null)
return false;
var args = new PlayerTeamEventArgs
{
PlayerId = _id,
Team = _team,
};
PlayerTeam.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerSlot event
///
public class PlayerSlotEventArgs : HandledEventArgs
{
///
/// The Terraria playerID
///
public byte PlayerId { get; set; }
///
/// The slot edited
///
public byte Slot { get; set; }
///
/// The stack edited
///
public byte Stack { get; set; }
///
/// The item prefix
///
public byte Prefix { get; set; }
///
/// Item type
///
public short Type { get; set; }
}
///
/// PlayerSlot - called at a PlayerSlot event
///
public static HandlerList PlayerSlot;
private static bool OnPlayerSlot(byte _plr, byte _slot, byte _stack, byte _prefix, short _type)
{
if (PlayerSlot == null)
return false;
var args = new PlayerSlotEventArgs
{
PlayerId = _plr,
Slot = _slot,
Stack = _stack,
Prefix = _prefix,
Type = _type
};
PlayerSlot.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerHP event
///
public class PlayerHPEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte PlayerId { get; set; }
///
/// Current HP
///
public short Current { get; set; }
///
/// Maximum HP
///
public short Max { get; set; }
}
///
/// PlayerHP - called at a PlayerHP event
///
public static HandlerList PlayerHP;
private static bool OnPlayerHP(byte _plr, short _cur, short _max)
{
if (PlayerHP == null)
return false;
var args = new PlayerHPEventArgs
{
PlayerId = _plr,
Current = _cur,
Max = _max,
};
PlayerHP.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerMana event
///
public class PlayerManaEventArgs : HandledEventArgs
{
public byte PlayerId { get; set; }
public short Current { get; set; }
public short Max { get; set; }
}
///
/// PlayerMana - called at a PlayerMana event
///
public static HandlerList PlayerMana;
private static bool OnPlayerMana(byte _plr, short _cur, short _max)
{
if (PlayerMana == null)
return false;
var args = new PlayerManaEventArgs
{
PlayerId = _plr,
Current = _cur,
Max = _max,
};
PlayerMana.Invoke(null, args);
return args.Handled;
}
public class PlayerInfoEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte PlayerId { get; set; }
///
/// Hair color
///
public byte Hair { get; set; }
///
/// Gender (male = true)
///
public bool Male { get; set; }
///
/// Character difficulty
///
public byte Difficulty { get; set; }
///
/// Player/character name
///
public string Name { get; set; }
}
///
/// PlayerInfo - called at a PlayerInfo event
/// If this is cancelled, the server will ForceKick the player. If this should be changed in the future, let someone know.
///
public static HandlerList PlayerInfo;
private static bool OnPlayerInfo(byte _plrid, byte _hair, bool _male, byte _difficulty, string _name)
{
if (PlayerInfo == null)
return false;
var args = new PlayerInfoEventArgs
{
PlayerId = _plrid,
Hair = _hair,
Male = _male,
Difficulty = _difficulty,
Name = _name,
};
PlayerInfo.Invoke(null, args);
return args.Handled;
}
///
/// For use in a TileKill event
///
public class TileKillEventArgs : HandledEventArgs
{
///
/// The X coordinate that is being killed
///
public int TileX { get; set; }
///
/// The Y coordinate that is being killed
///
public int TileY { get; set; }
}
///
/// TileKill - When a tile is removed fromt he world
///
public static HandlerList TileKill;
private static bool OnTileKill(int tilex, int tiley)
{
if (TileKill == null)
return false;
var args = new TileKillEventArgs
{
TileX = tilex,
TileY = tiley,
};
TileKill.Invoke(null, args);
return args.Handled;
}
///
/// For use in a KillMe event
///
public class KillMeEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte PlayerId { get; set; }
///
/// The direction the damage is coming from (?)
///
public byte Direction { get; set; }
///
/// Amount of damage delt
///
public short Damage { get; set; }
///
/// Player's current pvp setting
///
public bool Pvp { get; set; }
}
///
/// KillMe - Terraria's crappy way of handling damage from players
///
public static HandlerList KillMe;
private static bool OnKillMe(byte plr, byte direction, short damage, bool pvp)
{
if (KillMe == null)
return false;
var args = new KillMeEventArgs
{
PlayerId = plr,
Direction = direction,
Damage = damage,
Pvp = pvp,
};
KillMe.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerUpdate event
///
public class PlayerUpdateEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte PlayerId { get; set; }
///
/// ???
///
public byte Control { get; set; }
///
/// Current item?
///
public byte Item { get; set; }
///
/// Position of the player
///
public Vector2 Position { get; set; }
///
/// Velocity of the player
///
public Vector2 Velocity { get; set; }
public byte Pulley { get; set; }
}
///
/// PlayerUpdate - When the player sends it's updated information to the server
///
public static HandlerList PlayerUpdate;
private static bool OnPlayerUpdate(byte player, byte control, byte item, Vector2 position, Vector2 velocity, byte pulley)
{
if (PlayerUpdate == null)
return false;
var args = new PlayerUpdateEventArgs
{
PlayerId = player,
Control = control,
Item = item,
Position = position,
Velocity = velocity,
Pulley = pulley
};
PlayerUpdate.Invoke(null, args);
return args.Handled;
}
public static bool TSCheckNoclip(Vector2 Position, int Width, int Height)
{
int num = (int)(Position.X / 16f);
int num2 = (int)((Position.X + (float)Width) / 16f);
int num3 = (int)(Position.Y / 16f);
int num4 = (int)((Position.Y + (float)Height) / 16f);
if (num < 0)
{
num = 0;
}
if (num2 > Main.maxTilesX)
{
num2 = Main.maxTilesX;
}
if (num3 < 0)
{
num3 = 0;
}
if (num4 > Main.maxTilesY)
{
num4 = Main.maxTilesY;
}
for (int c = num; c < num2; c++)
{
for (int d = num3; d< num4; d++)
{
if (Main.tile[c,d].liquid != 0)
return false;
}
}
for (int i = num; i < num2; i++)
{
for (int j = num3; j < num4; j++)
{
if (Main.tile[i, j] == null || !Main.tile[i, j].active() || !Main.tileSolid[(int) Main.tile[i, j].type] || Main.tileSolidTop[(int) Main.tile[i, j].type] || (((int) Main.tile[i, j].type == 53) || ((int) Main.tile[i, j].type == 112) || ((int) Main.tile[i, j].type == 116) || ((int) Main.tile[i, j].type == 123)) || Main.tile[i, j].lava() || ((Main.tile[i, j].tileHeader2 & 16) == 16) || ((Main.tile[i, j].tileHeader2 & 32) == 32) || ((Main.tile[i, j].tileHeader & 32) == 32) || Main.tile[i, j].honey() || !Main.tileSolid[(int) Main.tile[i + 1, j].type] || !Main.tileSolid[(int) Main.tile[i - 1, j].type] || !Main.tileSolid[(int) Main.tile[i, j + 1].type] || !Main.tileSolid[(int) Main.tile[i, j - 1].type] || !Main.tileSolid[(int) Main.tile[i - 1, j - 1].type] || !Main.tileSolid[(int) Main.tile[i - 1, j + 1].type] || !Main.tileSolid[(int) Main.tile[i + 1, j - 1].type] || !Main.tileSolid[(int) Main.tile[i + 1, j + 1].type] || Main.tileSand[(int) Main.tile[i, j].type])
{
continue;
}
Vector2 vector;
vector.X = (float) (i*16);
vector.Y = (float) (j*16);
if (Position.X + (float) Width > vector.X && Position.X < vector.X + 16f && Position.Y + (float) Height > vector.Y && Position.Y < vector.Y + 16f)
{
return true;
}
}
}
return false;
}
///
/// For use in a SendTileSquare event
///
public class SendTileSquareEventArgs : HandledEventArgs
{
///
/// Size of the area
///
public short Size { get; set; }
///
/// A corner of the section
///
public int TileX { get; set; }
///
/// A corner of the section
///
public int TileY { get; set; }
}
///
/// SendTileSquare - When the player sends a tile square
///
public static HandlerList SendTileSquare;
private static bool OnSendTileSquare(short size, int tilex, int tiley)
{
if (SendTileSquare == null)
return false;
var args = new SendTileSquareEventArgs
{
Size = size,
TileX = tilex,
TileY = tiley,
};
SendTileSquare.Invoke(null, args);
return args.Handled;
}
///
/// For use in a NewProjectile event
///
public class NewProjectileEventArgs : HandledEventArgs
{
///
/// ???
///
public short Identity { get; set; }
///
/// Location of the projectile
///
public Vector2 Position { get; set; }
///
/// Velocity of the projectile
///
public Vector2 Velocity { get; set; }
///
/// Knockback
///
public float Knockback { get; set; }
///
/// Damage from the projectile
///
public short Damage { get; set; }
///
/// Terraria playerID owner of the projectile
///
public byte Owner { get; set; }
///
/// Type of projectile
///
public byte Type { get; set; }
///
/// ???
///
public int Index { get; set; }
}
///
/// NewProjectile - Called when a client creates a new projectile
///
public static HandlerList NewProjectile;
private static bool OnNewProjectile(short ident, Vector2 pos, Vector2 vel, float knockback, short dmg, byte owner, byte type, int index)
{
if (NewProjectile == null)
return false;
var args = new NewProjectileEventArgs
{
Identity = ident,
Position = pos,
Velocity = vel,
Knockback = knockback,
Damage = dmg,
Owner = owner,
Type = type,
Index = index,
};
NewProjectile.Invoke(null, args);
return args.Handled;
}
///
/// For use in a LiquidSet event
///
public class LiquidSetEventArgs : HandledEventArgs
{
///
/// X location of the tile
///
public int TileX { get; set; }
///
/// Y location of the tile
///
public int TileY { get; set; }
///
/// ???
///
public byte Liquid { get; set;}
///
/// True if lava
///
public bool Lava { get; set; }
}
///
/// LiquidSet - When ever a liquid is set
///
public static HandlerList LiquidSet;
private static bool OnLiquidSet(int tilex, int tiley, byte liquid, bool lava)
{
if (LiquidSet == null)
return false;
var args = new LiquidSetEventArgs
{
TileX = tilex,
TileY = tiley,
Liquid = liquid,
Lava = lava,
};
LiquidSet.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerSpawn event
///
public class SpawnEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte Player { get; set; }
///
/// X location of the player's spawn
///
public int SpawnX { get; set; }
///
/// Y location of the player's spawn
///
public int SpawnY { get; set; }
}
///
/// PlayerSpawn - When a player spawns
///
public static HandlerList PlayerSpawn;
private static bool OnPlayerSpawn(byte player, int spawnX, int spawnY)
{
if (PlayerSpawn == null)
return false;
var args = new SpawnEventArgs
{
Player = player,
SpawnX = spawnX,
SpawnY = spawnY,
};
PlayerSpawn.Invoke(null, args);
return args.Handled;
}
///
/// For use with a ChestOpen event
///
public class ChestOpenEventArgs : HandledEventArgs
{
///
/// X location of said chest
///
public int X { get; set; }
///
/// Y location of said chest
///
public int Y { get; set; }
}
///
/// ChestOpen - Called when any chest is opened
///
public static HandlerList ChestOpen;
private static bool OnChestOpen(int x, int y)
{
if (ChestOpen == null)
return false;
var args = new ChestOpenEventArgs
{
X = x,
Y = y,
};
ChestOpen.Invoke(null, args);
return args.Handled;
}
///
/// For use in a ChestItemChange event
///
public class ChestItemEventArgs : HandledEventArgs
{
///
/// ChestID
///
public short ID { get; set; }
///
/// Slot of the item
///
public byte Slot { get; set; }
///
/// How many?
///
public byte Stacks { get; set; }
///
/// Item prefix
///
public byte Prefix { get; set; }
///
/// Item type
///
public short Type { get; set; }
}
///
/// ChestItemChange - Called when an item in a chest changes
///
public static HandlerList ChestItemChange;
private static bool OnChestItemChange(short id, byte slot, byte stacks, byte prefix, short type)
{
if (ChestItemChange == null)
return false;
var args = new ChestItemEventArgs
{
ID = id,
Slot = slot,
Stacks = stacks,
Prefix = prefix,
Type = type,
};
ChestItemChange.Invoke(null, args);
return args.Handled;
}
///
/// For use in a Sign event
///
public class SignEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public short ID { get; set; }
///
/// X location of the sign
///
public int X { get; set; }
///
/// Y location of the sign
///
public int Y { get; set; }
}
///
/// Sign - Called when a sign is changed
///
public static HandlerList Sign;
private static bool OnSignEvent(short id, int x, int y)
{
if (Sign == null)
return false;
var args = new SignEventArgs
{
ID = id,
X = x,
Y = y,
};
Sign.Invoke(null, args);
return args.Handled;
}
///
/// For use in a NPCHome event
///
public class NPCHomeChangeEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public short ID { get; set; }
///
/// X location of the NPC home change
///
public short X { get; set; }
///
/// Y location of the NPC home change
///
public short Y { get; set; }
///
/// ByteBool homeless
///
public byte Homeless { get; set; }
}
///
/// NPCHome - Called when an NPC's home is changed
///
public static HandlerList NPCHome;
private static bool OnUpdateNPCHome(short id, short x, short y, byte homeless)
{
if (NPCHome == null)
return false;
var args = new NPCHomeChangeEventArgs
{
ID = id,
X = x,
Y = y,
Homeless = homeless,
};
NPCHome.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerBuff event
///
public class PlayerBuffEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte ID { get; set; }
///
/// Buff Type
///
public byte Type { get; set; }
///
/// Time the buff lasts
///
public short Time { get; set; }
}
///
/// PlayerBuff - Called when a player is buffed
///
public static HandlerList PlayerBuff;
private static bool OnPlayerBuff(byte id, byte type, short time)
{
if (PlayerBuff == null)
return false;
var args = new PlayerBuffEventArgs
{
ID = id,
Type = type,
Time = time,
};
PlayerBuff.Invoke(null, args);
return args.Handled;
}
///
/// For use in an ItemDrop event
///
public class ItemDropEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public short ID { get; set; }
///
/// Position of the item
///
public Vector2 Position { get; set; }
///
/// Velocity at which the item is deployed
///
public Vector2 Velocity { get; set; }
///
/// Stacks
///
public byte Stacks { get; set; }
///
/// Prefix of the item
///
public byte Prefix { get; set; }
///
/// Item type
///
public short Type { get; set; }
}
///
/// ItemDrop - Called when an item is dropped
///
public static HandlerList ItemDrop;
private static bool OnItemDrop(short id, Vector2 pos, Vector2 vel, byte stacks, byte prefix, short type)
{
if (ItemDrop == null)
return false;
var args = new ItemDropEventArgs
{
ID = id,
Position = pos,
Velocity = vel,
Stacks = stacks,
Prefix = prefix,
Type = type,
};
ItemDrop.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerDamage event
///
public class PlayerDamageEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte ID { get; set; }
///
/// The direction the damage is occuring from
///
public byte Direction { get; set; }
///
/// Amount of damage
///
public short Damage { get; set; }
///
/// If the player has PVP on
///
public byte PVP { get; set; }
///
/// Is the damage critical?
///
public byte Critical { get; set; }
}
///
/// PlayerDamage - Called when a player is damaged
///
public static HandlerList PlayerDamage;
private static bool OnPlayerDamage(byte id, byte dir, short dmg, byte pvp, byte crit)
{
if (PlayerDamage == null)
return false;
var args = new PlayerDamageEventArgs
{
ID = id,
Direction = dir,
Damage = dmg,
PVP = pvp,
Critical = crit,
};
PlayerDamage.Invoke(null, args);
return args.Handled;
}
///
/// For use with a NPCStrike event
///
public class NPCStrikeEventArgs : HandledEventArgs
{
///
/// ???
///
public byte ID { get; set; }
///
/// Direction the damage occurred from
///
public byte Direction { get; set; }
///
/// Amount of damage
///
public short Damage { get; set; }
///
/// Is PVP enabled...?
///
public byte PVP { get; set; }
///
/// Critical?
///
public byte Critical { get; set; }
}
///
/// NPCStrike - Called when an NPC is attacked
///
public static HandlerList NPCStrike;
private static bool OnNPCStrike(byte id, byte dir, short dmg, byte pvp, byte crit)
{
if (NPCStrike == null)
return false;
var args = new NPCStrikeEventArgs
{
ID = id,
Direction = dir,
Damage = dmg,
PVP = pvp,
Critical = crit,
};
NPCStrike.Invoke(null, args);
return args.Handled;
}
///
/// For use with a NPCSpecial event
///
public class NPCSpecialEventArgs : HandledEventArgs
{
///
/// ???
///
public byte ID { get; set; }
///
/// Type...?
///
public byte Type { get; set; }
}
///
/// NPCSpecial - Called at some point
///
public static HandlerList NPCSpecial;
private static bool OnNPCSpecial(byte id, byte type)
{
if (NPCSpecial == null)
return false;
var args = new NPCSpecialEventArgs
{
ID = id,
Type = type,
};
NPCSpecial.Invoke(null, args);
return args.Handled;
}
///
/// For use with a PlayerAnimation event
///
public class PlayerAnimationEventArgs : HandledEventArgs
{
}
///
/// PlayerAnimation - Called when a player animates
///
public static HandlerList PlayerAnimation;
private static bool OnPlayerAnimation()
{
if (PlayerAnimation == null)
return false;
var args = new PlayerAnimationEventArgs {};
PlayerAnimation.Invoke(null, args);
return args.Handled;
}
///
/// For use in a PlayerBuffUpdate event
///
public class PlayerBuffUpdateEventArgs : HandledEventArgs
{
///
/// The Terraria playerID of the player
///
public byte ID { get; set; }
}
///
/// PlayerBuffUpdate - Called when a player updates buffs
///
public static HandlerList PlayerBuffUpdate;
private static bool OnPlayerBuffUpdate(byte id)
{
if (PlayerBuffUpdate == null)
return false;
var args = new PlayerBuffUpdateEventArgs
{
ID = id,
};
PlayerBuffUpdate.Invoke(null, args);
return args.Handled;
}
///
/// For use with a NPCStrike event
///
public class TeleportEventArgs : HandledEventArgs
{
///
/// ???
///
public Int16 ID { get; set; }
///
/// Flag is a bit field
/// if the first bit is set -> 0 = player, 1 = NPC
/// if the second bit is set, ignore this packet
/// if the third bit is set, style +1
/// if the fourth bit is set, style +1
///
public byte Flag { get; set; }
///
/// X Location
///
public float X { get; set; }
///
/// Y Location
///
public float Y { get; set; }
}
///
/// NPCStrike - Called when an NPC is attacked
///
public static HandlerList Teleport;
private static bool OnTeleport(Int16 id, byte f, float x, float y)
{
if (Teleport == null)
return false;
var args = new TeleportEventArgs
{
ID = id,
Flag = f,
X = x,
Y = y
};
Teleport.Invoke(null, args);
return args.Handled;
}
#endregion
public static void InitGetDataHandler()
{
#region Blacklists
WhitelistBuffMaxTime = new int[Main.maxBuffs];
WhitelistBuffMaxTime[20] = 600;
WhitelistBuffMaxTime[0x18] = 1200;
WhitelistBuffMaxTime[0x1f] = 120;
WhitelistBuffMaxTime[0x27] = 420;
#endregion Blacklists
GetDataHandlerDelegates = new Dictionary
{
{PacketTypes.PlayerInfo, HandlePlayerInfo},
{PacketTypes.PlayerUpdate, HandlePlayerUpdate},
{PacketTypes.Tile, HandleTile},
{PacketTypes.TileSendSquare, HandleSendTileSquare},
{PacketTypes.ProjectileNew, HandleProjectileNew},
{PacketTypes.TogglePvp, HandleTogglePvp},
{PacketTypes.PlayerTeam, HandlePlayerTeam},
{PacketTypes.TileKill, HandleTileKill},
{PacketTypes.PlayerKillMe, HandlePlayerKillMe},
{PacketTypes.LiquidSet, HandleLiquidSet},
{PacketTypes.PlayerSpawn, HandleSpawn},
{PacketTypes.ChestGetContents, HandleChestOpen},
{PacketTypes.ChestItem, HandleChestItem},
{PacketTypes.SignNew, HandleSign},
{PacketTypes.PlayerSlot, HandlePlayerSlot},
{PacketTypes.TileGetSection, HandleGetSection},
{PacketTypes.UpdateNPCHome, UpdateNPCHome},
{PacketTypes.PlayerAddBuff, HandlePlayerBuff},
{PacketTypes.ItemDrop, HandleItemDrop},
{PacketTypes.PlayerHp, HandlePlayerHp},
{PacketTypes.PlayerMana, HandlePlayerMana},
{PacketTypes.PlayerDamage, HandlePlayerDamage},
{PacketTypes.NpcStrike, HandleNpcStrike},
{PacketTypes.NpcSpecial, HandleSpecial},
{PacketTypes.PlayerAnimation, HandlePlayerAnimation},
{PacketTypes.PlayerBuff, HandlePlayerBuffUpdate},
{PacketTypes.PasswordSend, HandlePassword},
{PacketTypes.ContinueConnecting2, HandleConnecting},
{PacketTypes.ProjectileDestroy, HandleProjectileKill},
{PacketTypes.SpawnBossorInvasion, HandleSpawnBoss},
{PacketTypes.Teleport, HandleTeleport}
};
}
public static bool HandlerGetData(PacketTypes type, TSPlayer player, MemoryStream data)
{
GetDataHandlerDelegate handler;
if (GetDataHandlerDelegates.TryGetValue(type, out handler))
{
try
{
return handler(new GetDataHandlerArgs(player, data));
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
}
return false;
}
private static bool HandlePlayerSlot(GetDataHandlerArgs args)
{
byte plr = args.Data.ReadInt8();
byte slot = args.Data.ReadInt8();
byte stack = args.Data.ReadInt8();
byte prefix = args.Data.ReadInt8();
short type = args.Data.ReadInt16();
// Players send a slot update packet for each inventory slot right after they've joined.
bool bypassTrashCanCheck = false;
if (plr == args.Player.Index && !args.Player.HasSentInventory && slot == NetItem.maxNetInventory)
{
args.Player.HasSentInventory = true;
bypassTrashCanCheck = true;
}
if (OnPlayerSlot(plr, slot, stack, prefix, type))
return true;
if (plr != args.Player.Index)
{
return true;
}
if (slot < 0 || slot > NetItem.maxNetInventory)
{
return true;
}
// Garabage? Or will it cause some internal initialization or whatever?
var item = new Item();
item.netDefaults(type);
item.Prefix(prefix);
if (args.Player.IsLoggedIn)
{
args.Player.PlayerData.StoreSlot(slot, type, prefix, stack);
}
else if (
TShock.Config.ServerSideInventory && TShock.Config.DisableLoginBeforeJoin && !bypassTrashCanCheck &&
args.Player.HasSentInventory && !args.Player.Group.HasPermission(Permissions.bypassinventorychecks)
) {
// The player might have moved an item to their trash can before they performed a single login attempt yet.
args.Player.IgnoreActionsForClearingTrashCan = true;
}
return false;
}
public static bool HandlePlayerHp(GetDataHandlerArgs args)
{
var plr = args.Data.ReadInt8();
var cur = args.Data.ReadInt16();
var max = args.Data.ReadInt16();
if (OnPlayerHP(plr, cur, max))
return true;
if (args.Player.FirstMaxHP == 0)
args.Player.FirstMaxHP = max;
if ((max > TShock.Config.MaxHealth && max > args.Player.FirstMaxHP) && !args.Player.Group.HasPermission(Permissions.ignorestathackdetection))
{
TShock.Utils.ForceKick(args.Player, "Hacked Client Detected.", true);
return false;
}
if (args.Player.IsLoggedIn)
{
args.Player.PlayerData.maxHealth = max;
}
return false;
}
private static bool HandlePlayerMana(GetDataHandlerArgs args)
{
var plr = args.Data.ReadInt8();
var cur = args.Data.ReadInt16();
var max = args.Data.ReadInt16();
if (OnPlayerMana(plr, cur, max))
return true;
if (args.Player.FirstMaxMP == 0)
args.Player.FirstMaxMP = max;
if (max > TShock.Config.MaxMana && max > args.Player.FirstMaxMP)
{
TShock.Utils.ForceKick(args.Player, "Hacked Client Detected.", true);
return false;
}
return false;
}
private static bool HandlePlayerInfo(GetDataHandlerArgs args)
{
var playerid = args.Data.ReadInt8();
var hair = args.Data.ReadInt8();
var male = args.Data.ReadBoolean();
args.Data.Position += 21;
var difficulty = args.Data.ReadInt8();
string name = Encoding.UTF8.GetString(args.Data.ReadBytes((int) (args.Data.Length - args.Data.Position - 1)));
if (OnPlayerInfo(playerid, hair, male, difficulty, name))
{
TShock.Utils.ForceKick(args.Player, "A plugin cancelled the event.", true);
return true;
}
if (name.Trim().Length == 0)
{
TShock.Utils.ForceKick(args.Player, "Empty Name.", true);
return true;
}
if (args.Player.ReceivedInfo)
{
return true;
}
if (TShock.Config.MediumcoreOnly && difficulty < 1)
{
TShock.Utils.ForceKick(args.Player, "Server is set to mediumcore and above characters only!", true);
return true;
}
if (TShock.Config.HardcoreOnly && difficulty < 2)
{
TShock.Utils.ForceKick(args.Player, "Server is set to hardcore characters only!", true);
return true;
}
args.Player.Difficulty = difficulty;
args.TPlayer.name = name;
args.Player.ReceivedInfo = true;
return false;
}
private static bool HandleConnecting(GetDataHandlerArgs args)
{
var user = TShock.Users.GetUserByName(args.Player.Name);
if (user != null && !TShock.Config.DisableLoginBeforeJoin)
{
args.Player.RequiresPassword = true;
NetMessage.SendData((int) PacketTypes.PasswordRequired, args.Player.Index);
return true;
}
else if (!string.IsNullOrEmpty(TShock.Config.ServerPassword))
{
args.Player.RequiresPassword = true;
NetMessage.SendData((int) PacketTypes.PasswordRequired, args.Player.Index);
return true;
}
if (args.Player.State == 1)
args.Player.State = 2;
NetMessage.SendData((int) PacketTypes.WorldInfo, args.Player.Index);
return true;
}
private static bool HandlePassword(GetDataHandlerArgs args)
{
if (!args.Player.RequiresPassword)
return true;
string password = Encoding.UTF8.GetString(args.Data.ReadBytes((int) (args.Data.Length - args.Data.Position - 1)));
if (Hooks.PlayerHooks.OnPlayerPreLogin(args.Player, args.Player.Name, password))
return true;
var user = TShock.Users.GetUserByName(args.Player.Name);
if (user != null && !TShock.Config.DisableLoginBeforeJoin)
{
string encrPass = TShock.Utils.HashPassword(password);
if (user.Password.ToUpper() == encrPass.ToUpper())
{
args.Player.RequiresPassword = false;
args.Player.PlayerData = TShock.InventoryDB.GetPlayerData(args.Player, TShock.Users.GetUserID(args.Player.Name));
if (args.Player.State == 1)
args.Player.State = 2;
NetMessage.SendData((int) PacketTypes.WorldInfo, args.Player.Index);
var group = TShock.Utils.GetGroup(user.Group);
if (TShock.Config.ServerSideInventory)
{
if (group.HasPermission(Permissions.bypassinventorychecks))
{
args.Player.IgnoreActionsForClearingTrashCan = false;
}
else if (!TShock.CheckInventory(args.Player))
{
args.Player.LoginFailsBySsi = true;
args.Player.SendMessage("Login Failed, Please fix the above errors then /login again.", Color.Cyan);
args.Player.IgnoreActionsForClearingTrashCan = true;
return true;
}
}
args.Player.LoginFailsBySsi = false;
if (group.HasPermission(Permissions.ignorestackhackdetection))
args.Player.IgnoreActionsForCheating = "none";
if (group.HasPermission(Permissions.usebanneditem))
args.Player.IgnoreActionsForDisabledArmor = "none";
args.Player.Group = group;
args.Player.tempGroup = null;
args.Player.UserAccountName = args.Player.Name;
args.Player.UserID = TShock.Users.GetUserID(args.Player.UserAccountName);
args.Player.IsLoggedIn = true;
args.Player.IgnoreActionsForInventory = "none";
if (!args.Player.IgnoreActionsForClearingTrashCan)
{
args.Player.PlayerData.CopyInventory(args.Player);
TShock.InventoryDB.InsertPlayerData(args.Player);
}
args.Player.SendMessage("Authenticated as " + args.Player.Name + " successfully.", Color.LimeGreen);
Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + ".");
Hooks.PlayerHooks.OnPlayerPostLogin(args.Player);
return true;
}
TShock.Utils.ForceKick(args.Player, "Invalid user account password.", true);
return true;
}
if (!string.IsNullOrEmpty(TShock.Config.ServerPassword))
{
if (TShock.Config.ServerPassword == password)
{
args.Player.RequiresPassword = false;
if (args.Player.State == 1)
args.Player.State = 2;
NetMessage.SendData((int) PacketTypes.WorldInfo, args.Player.Index);
return true;
}
TShock.Utils.ForceKick(args.Player, "Incorrect server password", true);
return true;
}
TShock.Utils.ForceKick(args.Player, "Bad password attempt", true);
return true;
}
private static bool HandleGetSection(GetDataHandlerArgs args)
{
if (args.Player.RequestedSection)
return true;
args.Player.RequestedSection = true;
if (String.IsNullOrEmpty(args.Player.Name))
{
TShock.Utils.ForceKick(args.Player, "Blank name.", true);
return true;
}
if (TShock.HackedStats(args.Player) && !args.Player.Group.HasPermission(Permissions.ignorestathackdetection))
{
TShock.Utils.ForceKick(args.Player, "You have hacked health/mana, please use a different character.", true);
return true;
}
if (!args.Player.Group.HasPermission(Permissions.ignorestackhackdetection))
{
TShock.HackedInventory(args.Player);
}
if (TShock.Utils.ActivePlayers() + 1 > TShock.Config.MaxSlots &&
!args.Player.Group.HasPermission(Permissions.reservedslot))
{
TShock.Utils.ForceKick(args.Player, TShock.Config.ServerFullReason, true);
return true;
}
NetMessage.SendData((int) PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
if (TShock.Config.EnableGeoIP && TShock.Geo != null)
{
Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", args.Player.Name, args.Player.IP,
args.Player.Group.Name, args.Player.Country, TShock.Utils.ActivePlayers(),
TShock.Config.MaxSlots));
if (!args.Player.SilentJoinInProgress)
TShock.Utils.Broadcast(string.Format("{0} ({1}) has joined.", args.Player.Name, args.Player.Country), Color.Yellow);
}
else
{
Log.Info(string.Format("{0} ({1}) from '{2}' group joined. ({3}/{4})", args.Player.Name, args.Player.IP,
args.Player.Group.Name, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots));
if (!args.Player.SilentJoinInProgress)
TShock.Utils.Broadcast(args.Player.Name + " has joined.", Color.Yellow);
}
if (TShock.Config.DisplayIPToAdmins)
TShock.Utils.SendLogs(string.Format("{0} has joined. IP: {1}", args.Player.Name, args.Player.IP), Color.Blue);
return false;
}
private static bool HandleSendTileSquare(GetDataHandlerArgs args)
{
if (args.Player.Group.HasPermission(Permissions.allowclientsideworldedit))
return false;
var size = args.Data.ReadInt16();
var tileX = args.Data.ReadInt32();
var tileY = args.Data.ReadInt32();
if (OnSendTileSquare(size, tileX, tileY))
return true;
if (size > 5)
return true;
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendTileSquare(tileX, tileY, size);
return true;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
var tiles = new NetTile[size,size];
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
tiles[x, y] = new NetTile(args.Data);
}
}
bool changed = false;
for (int x = 0; x < size; x++)
{
int realx = tileX + x;
if (realx < 0 || realx >= Main.maxTilesX)
continue;
for (int y = 0; y < size; y++)
{
int realy = tileY + y;
if (realy < 0 || realy >= Main.maxTilesY)
continue;
var tile = Main.tile[realx, realy];
var newtile = tiles[x, y];
if (TShock.CheckTilePermission(args.Player, realx, realy))
{
continue;
}
// Server now has a range check built in
if (TShock.CheckRangePermission(args.Player, realx, realy))
{
continue;
}
if ((tile.type == 128 && newtile.Type == 128) || (tile.type == 105 && newtile.Type == 105) || (tile.type == 139 && newtile.Type == 139))
{
if (TShock.Config.EnableInsecureTileFixes)
{
return false;
}
}
if (tile.type == 0x17 && newtile.Type == 0x2)
{
tile.type = 0x2;
changed = true;
}
else if (tile.type == 0x19 && newtile.Type == 0x1)
{
tile.type = 0x1;
changed = true;
}
else if ((tile.type == 0xF && newtile.Type == 0xF) ||
(tile.type == 0x4F && newtile.Type == 0x4F))
{
tile.frameX = newtile.FrameX;
tile.frameY = newtile.FrameY;
changed = true;
}
// Holy water/Unholy water
else if (tile.type == 1 && newtile.Type == 117)
{
tile.type = 117;
changed = true;
}
else if (tile.type == 1 && newtile.Type == 25)
{
tile.type = 25;
changed = true;
}
else if (tile.type == 117 && newtile.Type == 25)
{
tile.type = 25;
changed = true;
}
else if (tile.type == 25 && newtile.Type == 117)
{
tile.type = 117;
changed = true;
}
else if (tile.type == 2 && newtile.Type == 23)
{
tile.type = 23;
changed = true;
}
else if (tile.type == 2 && newtile.Type == 109)
{
tile.type = 109;
changed = true;
}
else if (tile.type == 23 && newtile.Type == 109)
{
tile.type = 109;
changed = true;
}
else if (tile.type == 109 && newtile.Type == 23)
{
tile.type = 23;
changed = true;
}
else if (tile.type == 23 && newtile.Type == 109)
{
tile.type = 109;
changed = true;
}
else if (tile.type == 53 && newtile.Type == 116)
{
tile.type = 116;
changed = true;
}
else if (tile.type == 53 && newtile.Type == 112)
{
tile.type = 112;
changed = true;
}
else if (tile.type == 112 && newtile.Type == 116)
{
tile.type = 116;
changed = true;
}
else if (tile.type == 116 && newtile.Type == 112)
{
tile.type = 112;
changed = true;
}
else if (tile.type == 112 && newtile.Type == 53)
{
tile.type = 53;
changed = true;
}
else if (tile.type == 109 && newtile.Type == 2)
{
tile.type = 2;
changed = true;
}
else if (tile.type == 116 && newtile.Type == 53)
{
tile.type = 53;
changed = true;
}
else if (tile.type == 117 && newtile.Type == 1)
{
tile.type = 1;
changed = true;
}
}
}
if (changed)
{
TSPlayer.All.SendTileSquare(tileX, tileY, size);
WorldGen.RangeFrame(tileX, tileY, tileX + size, tileY + size);
}
else
{
args.Player.SendTileSquare(tileX, tileY, size);
}
return true;
}
public enum EditAction
{
KillTile = 0,
PlaceTile,
KillWall,
PlaceWall,
KillTileNoItem,
PlaceWire,
KillWire,
PoundTile
}
public enum EditType
{
Fail = 0,
Type,
Slope,
}
private static bool HandleTile(GetDataHandlerArgs args)
{
EditAction action = (EditAction)args.Data.ReadInt8();
var tileX = args.Data.ReadInt32();
var tileY = args.Data.ReadInt32();
var editData = args.Data.ReadInt8();
EditType type = (action == EditAction.KillTile || action == EditAction.KillWall ||
action == EditAction.KillTileNoItem)
? EditType.Fail
: (action == EditAction.PlaceTile || action == EditAction.PlaceWall)
? EditType.Type
: EditType.Slope;
var style = args.Data.ReadInt8();
if (OnTileEdit(args.Player, tileX, tileY, action, type, editData, style))
return true;
if (!TShock.Utils.TilePlacementValid(tileX, tileY))
return false;
if (args.Player.Dead && TShock.Config.PreventDeadModification)
return true;
if (args.Player.AwaitingName)
{
Debug.Assert(args.Player.AwaitingNameParameters != null);
bool includeUnprotected = false;
bool includeZIndexes = false;
bool persistentMode = false;
foreach (string parameter in args.Player.AwaitingNameParameters)
{
if (parameter.Equals("-u", StringComparison.InvariantCultureIgnoreCase))
includeUnprotected = true;
if (parameter.Equals("-z", StringComparison.InvariantCultureIgnoreCase))
includeZIndexes = true;
if (parameter.Equals("-p", StringComparison.InvariantCultureIgnoreCase))
persistentMode = true;
}
List outputRegions = new List();
foreach (Region region in TShock.Regions.Regions.OrderBy(r => r.Z).Reverse())
{
if (!includeUnprotected && !region.DisableBuild)
continue;
if (tileX < region.Area.Left || tileX > region.Area.Right)
continue;
if (tileY < region.Area.Top || tileY > region.Area.Bottom)
continue;
string format = "{1}";
if (includeZIndexes)
format = "{1} (z:{0})";
outputRegions.Add(string.Format(format, region.Z, region.Name));
}
if (outputRegions.Count == 0)
{
if (includeUnprotected)
args.Player.SendMessage("There are no regions at this point.", Color.Yellow);
else
args.Player.SendMessage("There are no regions at this point or they are not protected.", Color.Yellow);
}
else
{
if (includeUnprotected)
args.Player.SendSuccessMessage("Regions at this point:");
else
args.Player.SendSuccessMessage("Protected regions at this point:");
foreach (string line in PaginationTools.BuildLinesFromTerms(outputRegions))
args.Player.SendMessage(line, Color.White);
}
if (!persistentMode)
{
args.Player.AwaitingName = false;
args.Player.AwaitingNameParameters = null;
}
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (args.Player.AwaitingTempPoint > 0)
{
args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = tileX;
args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = tileY;
args.Player.SendMessage("Set Temp Point " + args.Player.AwaitingTempPoint, Color.Yellow);
args.Player.SendTileSquare(tileX, tileY);
args.Player.AwaitingTempPoint = 0;
return true;
}
byte[] rightClickKill = new byte[] { 4, 13, 33, 49, 50, 128};
Item selectedItem = args.TPlayer.inventory[args.TPlayer.selectedItem];
if (type == 0 && Main.tile[tileX, tileY].type != 127 && !Main.tileCut[Main.tile[tileX, tileY].type] && !rightClickKill.Contains(Main.tile[tileX, tileY].type))
{
// If the tile is an axe tile and they aren't selecting an axe, they're hacking.
if (Main.tileAxe[Main.tile[tileX, tileY].type] && (selectedItem.axe == 0 && selectedItem.explosive == 0 && args.Player.RecentFuse == 0))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
// If the tile is a hammer tile and they aren't selecting an hammer, they're hacking.
else if (Main.tileHammer[Main.tile[tileX, tileY].type] && (selectedItem.hammer == 0 && selectedItem.explosive == 0 && args.Player.RecentFuse == 0))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
// If the tile is a pickaxe tile and they aren't selecting an pickaxe, they're hacking.
else if ((!Main.tileAxe[Main.tile[tileX, tileY].type] && !Main.tileHammer[Main.tile[tileX, tileY].type]) && (selectedItem.pick == 0 && selectedItem.explosive == 0 && args.Player.RecentFuse == 0))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
else if (action == EditAction.KillWall)
{
// If they aren't selecting an hammer, they're hacking.
if (selectedItem.hammer == 0 && selectedItem.explosive == 0 && args.Player.RecentFuse == 0)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
else if (action == EditAction.PlaceTile || action == EditAction.PlaceWall)
{
if (action == EditAction.PlaceTile && TShock.Config.PreventInvalidPlaceStyle && ((editData == 4 && style > 8) ||
(editData == 13 && style > 4) || (editData == 15 && style > 1) || (editData == 21 && style > 6) ||
(editData == 82 && style > 5) || (editData == 91 && style > 3) || (editData == 105 && style > 42) ||
(editData == 135 && style > 3) || (editData == 139 && style > 12) || (editData == 144 && style > 2) ||
(editData == 149 && style > 2)))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
// If they aren't selecting the item which creates the tile or wall, they're hacking.
if (editData != 127 && editData != (action == EditAction.PlaceTile ? selectedItem.createTile : selectedItem.createWall))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.Itembans.ItemIsBanned(selectedItem.name, args.Player) || editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (action == EditAction.PlaceTile && (editData == 29 || editData == 97) && TShock.Config.ServerSideInventory && TShock.Config.DisablePiggybanksOnSSI)
{
args.Player.SendMessage("You cannot place this tile because server side inventory is enabled.", Color.Red);
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (action == EditAction.PlaceTile && editData == 21)
{
if (TShock.Utils.MaxChests())
{
args.Player.SendMessage("The world's chest limit has been reached - unable to place more.", Color.Red);
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((TShock.Utils.TilePlacementValid(tileX, tileY + 1) && Main.tile[tileX, tileY + 1].type == 138) ||
(TShock.Utils.TilePlacementValid(tileX + 1, tileY + 1) && Main.tile[tileX + 1, tileY + 1].type == 138))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
}
else if (action == EditAction.PlaceWire)
{
// If they aren't selecting the wrench, they're hacking.
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 509)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
else if (action == EditAction.KillWire)
{
// If they aren't selecting the wire cutter, they're hacking.
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 510)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckTilePermission(args.Player, tileX, tileY, editData, action))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((editData == 127 || Main.tileCut[editData]) && (action ==EditAction.KillTile || action == EditAction.KillTileNoItem))
{
return false;
}
if (TShock.CheckRangePermission(args.Player, tileX, tileY))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (args.Player.TileKillThreshold >= TShock.Config.TileKillThreshold)
{
args.Player.Disable("Reached TileKill threshold.");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (args.Player.TilePlaceThreshold >= TShock.Config.TilePlaceThreshold)
{
args.Player.Disable("Reached TilePlace threshold.");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ( ( action == EditAction.PlaceTile || action == EditAction.PlaceWall ) && !args.Player.Group.HasPermission(Permissions.ignoreplacetiledetection))
{
args.Player.TilePlaceThreshold++;
var coords = new Vector2(tileX, tileY);
if (!args.Player.TilesCreated.ContainsKey(coords))
args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]);
}
if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.KillWall) && Main.tileSolid[Main.tile[tileX, tileY].type] &&
!args.Player.Group.HasPermission(Permissions.ignorekilltiledetection))
{
args.Player.TileKillThreshold++;
var coords = new Vector2(tileX, tileY);
if (!args.Player.TilesDestroyed.ContainsKey(coords))
args.Player.TilesDestroyed.Add(coords, Main.tile[tileX, tileY]);
}
return false;
}
private static bool HandleTogglePvp(GetDataHandlerArgs args)
{
byte id = args.Data.ReadInt8();
bool pvp = args.Data.ReadBoolean();
if (OnPvpToggled(id, pvp))
return true;
if (id != args.Player.Index)
{
return true;
}
if (TShock.Config.PvPMode == "disabled")
{
return true;
}
if (args.TPlayer.hostile != pvp)
{
long seconds = (long) (DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
if (seconds > 5)
{
TSPlayer.All.SendMessage(string.Format("{0} has {1} PvP!", args.Player.Name, pvp ? "enabled" : "disabled"),
Main.teamColor[args.Player.Team]);
}
args.Player.LastPvpChange = DateTime.UtcNow;
}
args.TPlayer.hostile = pvp;
if (TShock.Config.PvPMode == "always")
{
if (!pvp)
args.Player.Spawn();
}
NetMessage.SendData((int) PacketTypes.TogglePvp, -1, -1, "", args.Player.Index);
return true;
}
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
{
byte id = args.Data.ReadInt8();
byte team = args.Data.ReadInt8();
if (OnPlayerTeam(id, team))
return true;
if (id != args.Player.Index)
{
return true;
}
args.TPlayer.team = team;
NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, "", args.Player.Index);
return true;
}
private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
{
var plr = args.Data.ReadInt8();
var control = args.Data.ReadInt8();
var item = args.Data.ReadInt8();
var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
byte pulley = args.Data.ReadInt8();
if (OnPlayerUpdate(plr, control, item, pos, vel, pulley))
return true;
if (item < 0 || item >= args.TPlayer.inventory.Length)
{
return true;
}
if (pulley > 2)
{
return true;
}
if (args.Player.LastNetPosition == Vector2.Zero)
{
return true;
}
if (!pos.Equals(args.Player.LastNetPosition))
{
float distance = Vector2.Distance(new Vector2(pos.X/16f, pos.Y/16f),
new Vector2(args.Player.LastNetPosition.X/16f, args.Player.LastNetPosition.Y/16f));
if (TShock.CheckIgnores(args.Player))
{
if (distance > TShock.Config.MaxRangeForDisabled)
{
if (args.Player.IgnoreActionsForCheating != "none")
{
args.Player.SendMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating,
Color.Red);
}
else if (args.Player.IgnoreActionsForDisabledArmor != "none")
{
args.Player.SendMessage(
"Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor, Color.Red);
}
else if (args.Player.IgnoreActionsForInventory != "none")
{
args.Player.SendMessage(
"Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory,
Color.Red);
}
else if (TShock.Config.RequireLogin && !args.Player.IsLoggedIn)
{
args.Player.SendMessage("Please /register or /login to play!", Color.Red);
}
else if (args.Player.IgnoreActionsForClearingTrashCan)
{
args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red);
}
else if (TShock.Config.PvPMode == "always" && !args.TPlayer.hostile)
{
args.Player.SendMessage("PvP is forced! Enable PvP or else you can't do anything!",
Color.Red);
}
var lastTileX = args.Player.LastNetPosition.X;
var lastTileY = args.Player.LastNetPosition.Y;
if (!args.Player.Teleport(lastTileX, lastTileY))
{
args.Player.Spawn();
}
return true;
}
return true;
}
if (args.Player.Dead)
{
return true;
}
if (!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) &&
TSCheckNoclip(pos, args.TPlayer.width, args.TPlayer.height) && !TShock.Config.IgnoreNoClip
&& !args.TPlayer.tongued)
{
var lastTileX = args.Player.LastNetPosition.X;
var lastTileY = args.Player.LastNetPosition.Y;
if (!args.Player.Teleport(lastTileX, lastTileY + 48))
{
args.Player.SendErrorMessage("You got stuck in a solid object, Sent to spawn point.");
args.Player.Spawn();
}
return true;
}
args.Player.LastNetPosition = pos;
}
if ((control & 32) == 32)
{
if (!args.Player.Group.HasPermission(Permissions.usebanneditem) &&
TShock.Itembans.ItemIsBanned(args.TPlayer.inventory[item].name, args.Player))
{
control -= 32;
args.Player.Disable("Using banned item");
args.Player.SendMessage(
string.Format("You cannot use {0} on this server. Your actions are being ignored.",
args.TPlayer.inventory[item].name), Color.Red);
}
}
args.TPlayer.selectedItem = item;
args.TPlayer.position = pos;
args.TPlayer.velocity = vel;
args.TPlayer.oldVelocity = args.TPlayer.velocity;
args.TPlayer.fallStart = (int) (pos.Y/16f);
args.TPlayer.controlUp = false;
args.TPlayer.controlDown = false;
args.TPlayer.controlLeft = false;
args.TPlayer.controlRight = false;
args.TPlayer.controlJump = false;
args.TPlayer.controlUseItem = false;
args.TPlayer.pulley = pulley != 0;
args.TPlayer.pulleyDir = pulley;
args.TPlayer.direction = -1;
if ((control & 1) == 1)
{
args.TPlayer.controlUp = true;
}
if ((control & 2) == 2)
{
args.TPlayer.controlDown = true;
}
if ((control & 4) == 4)
{
args.TPlayer.controlLeft = true;
}
if ((control & 8) == 8)
{
args.TPlayer.controlRight = true;
}
if ((control & 16) == 16)
{
args.TPlayer.controlJump = true;
}
if ((control & 32) == 32)
{
args.TPlayer.controlUseItem = true;
}
if ((control & 64) == 64)
{
args.TPlayer.direction = 1;
}
NetMessage.SendData((int) PacketTypes.PlayerUpdate, -1, args.Player.Index, "", args.Player.Index);
return true;
}
private static bool HandleProjectileNew(GetDataHandlerArgs args)
{
var ident = args.Data.ReadInt16();
var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var knockback = args.Data.ReadSingle();
var dmg = args.Data.ReadInt16();
var owner = args.Data.ReadInt8();
var type = args.Data.ReadInt8();
owner = (byte)args.Player.Index;
var index = TShock.Utils.SearchProjectile(ident, owner);
if (OnNewProjectile(ident, pos, vel, knockback, dmg, owner, type, index))
return true;
if (index > Main.maxProjectiles || index < 0)
{
return false;
}
// Server now checks owner + ident, if owner is different, server will create new projectile.
/*if (args.Player.Index != owner)
{
args.Player.Disable(String.Format("Owner ({0}) and player ID ({1}) does not match to update projectile", owner, args.Player.Index));
args.Player.RemoveProjectile(ident, owner);
return true;
}*/
if (dmg > TShock.Config.MaxProjDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap))
{
args.Player.Disable(String.Format("Projectile damage is higher than {0}.", TShock.Config.MaxProjDamage));
args.Player.RemoveProjectile(ident, owner);
return true;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.RemoveProjectile(ident, owner);
return true;
}
bool hasPermission = !TShock.CheckProjectilePermission(args.Player, index, type);
if (!TShock.Config.IgnoreProjUpdate && !hasPermission)
{
if (type == 100)
{ //fix for skele prime
Log.Debug("Skeletron Prime's death laser ignored for cheat detection..");
}
else
{
args.Player.Disable("Does not have projectile permission to update projectile.");
args.Player.RemoveProjectile(ident, owner);
}
return true;
}
if (args.Player.ProjectileThreshold >= TShock.Config.ProjectileThreshold)
{
args.Player.Disable("Reached projectile update threshold.");
args.Player.RemoveProjectile(ident, owner);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.RemoveProjectile(ident, owner);
return true;
}
if (!args.Player.Group.HasPermission(Permissions.ignoreprojectiledetection))
{
if ((type == 90) && (TShock.Config.ProjIgnoreShrapnel))// ignore shrapnel
{
Log.Debug("Ignoring shrapnel per config..");
}
else
{
args.Player.ProjectileThreshold++;
}
}
// force all explosives server-side. -- DOES NOT WORK DUE TO LATENCY
if (hasPermission && (type == 28 || type == 29 || type == 37))
{
// Denotes that the player has recently set a fuse - used for cheat detection.
args.Player.RecentFuse = 10;
// args.Player.RemoveProjectile(ident, owner);
// Projectile.NewProjectile(pos.X, pos.Y, vel.X, vel.Y, type, dmg, knockback);
// return true;
}
return false;
}
private static bool HandleProjectileKill(GetDataHandlerArgs args)
{
var ident = args.Data.ReadInt16();
var owner = args.Data.ReadInt8();
owner = (byte)args.Player.Index;
var index = TShock.Utils.SearchProjectile(ident, owner);
if (index > Main.maxProjectiles || index < 0)
{
return false;
}
var type = Main.projectile[index].type;
// Players can no longer destroy projectiles that are not theirs as of 1.1.2
/*if (args.Player.Index != Main.projectile[index].owner && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill) // workaround for skeletron prime projectiles
{
args.Player.Disable(String.Format("Owner ({0}) and player ID ({1}) does not match to kill projectile of type: {3}", Main.projectile[index].owner, args.Player.Index, type));
args.Player.RemoveProjectile(ident, owner);
return true;
}*/
if (TShock.CheckIgnores(args.Player))
{
args.Player.RemoveProjectile(ident, owner);
return true;
}
if (TShock.CheckProjectilePermission(args.Player, index, type) && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill)
{
args.Player.Disable("Does not have projectile permission to kill projectile.");
args.Player.RemoveProjectile(ident, owner);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.RemoveProjectile(ident, owner);
return true;
}
return false;
}
private static bool HandlePlayerKillMe(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
var direction = args.Data.ReadInt8();
var dmg = args.Data.ReadInt16();
var pvp = args.Data.ReadInt8() == 0;
if (OnKillMe(id, direction, dmg, pvp))
return true;
int textlength = (int) (args.Data.Length - args.Data.Position - 1);
string deathtext = "";
if (textlength > 0)
{
deathtext = Encoding.UTF8.GetString(args.Data.ReadBytes(textlength));
/*if (!TShock.Utils.ValidString(deathtext))
{
return true;
}*/
}
args.Player.LastDeath = DateTime.Now;
args.Player.Dead = true;
return false;
}
private static bool HandleLiquidSet(GetDataHandlerArgs args)
{
int tileX = args.Data.ReadInt32();
int tileY = args.Data.ReadInt32();
byte liquid = args.Data.ReadInt8();
bool lava = args.Data.ReadBoolean();
if (OnLiquidSet(tileX, tileY, liquid, lava))
return true;
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false;
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (args.Player.TileLiquidThreshold >= TShock.Config.TileLiquidThreshold)
{
args.Player.Disable("Reached TileLiquid threshold.");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (!args.Player.Group.HasPermission(Permissions.ignoreliquidsetdetection))
{
args.Player.TileLiquidThreshold++;
}
if (liquid != 0)
{
int bucket = 0;
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 206)
{
bucket = 1;
}
else if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 207)
{
bucket = 2;
}
if(lava && bucket != 2)
{
args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Spreading lava without holding a lava bucket");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if(lava && (!args.Player.Group.HasPermission(Permissions.usebanneditem) &&
TShock.Itembans.ItemIsBanned("Lava Bucket", args.Player)))
{
args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Using banned lava bucket without permissions");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (!lava && bucket != 1)
{
args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Spreading water without holding a water bucket");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (!lava && (!args.Player.Group.HasPermission(Permissions.usebanneditem) &&
TShock.Itembans.ItemIsBanned("Water Bucket", args.Player)))
{
args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Using banned water bucket without permissions");
args.Player.SendTileSquare(tileX, tileY);
return true;
}
}
if (TShock.CheckTilePermission(args.Player, tileX, tileY))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckRangePermission(args.Player, tileX, tileY, 16))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
return false;
}
private static bool HandleTileKill(GetDataHandlerArgs args)
{
var tileX = args.Data.ReadInt32();
var tileY = args.Data.ReadInt32();
if (OnTileKill(tileX, tileY))
return true;
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false;
if (args.Player.Dead && TShock.Config.PreventDeadModification)
return true;
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (Main.tile[tileX, tileY].type != 0x15 && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != 0)) //Chest
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckTilePermission(args.Player, tileX, tileY))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckRangePermission(args.Player, tileX, tileY))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
return false;
}
private static bool HandleSpawn(GetDataHandlerArgs args)
{
var player = args.Data.ReadInt8();
var spawnx = args.Data.ReadInt32();
var spawny = args.Data.ReadInt32();
if (OnPlayerSpawn(player, spawnx, spawny))
return true;
if (args.Player.InitSpawn && args.TPlayer.inventory[args.TPlayer.selectedItem].type != 50)
{
if (args.TPlayer.difficulty == 1 && (TShock.Config.KickOnMediumcoreDeath || TShock.Config.BanOnMediumcoreDeath))
{
if (args.TPlayer.selectedItem != 50)
{
if (TShock.Config.BanOnMediumcoreDeath)
{
if (!TShock.Utils.Ban(args.Player, TShock.Config.MediumcoreBanReason, false, "mediumcore-death"))
TShock.Utils.ForceKick(args.Player, "Death results in a ban, but can't ban you.", true);
}
else
{
TShock.Utils.ForceKick(args.Player, TShock.Config.MediumcoreKickReason, true, false);
}
return true;
}
}
}
else
args.Player.InitSpawn = true;
args.Player.Dead = false;
return false;
}
private static bool HandleChestOpen(GetDataHandlerArgs args)
{
var x = args.Data.ReadInt32();
var y = args.Data.ReadInt32();
if (OnChestOpen(x, y))
return true;
if (TShock.CheckIgnores(args.Player))
{
return true;
}
if (TShock.CheckRangePermission(args.Player, x, y))
{
return true;
}
if (TShock.CheckTilePermission(args.Player, x, y) && TShock.Config.RegionProtectChests)
{
return true;
}
return false;
}
private static bool HandleChestItem(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt16();
var slot = args.Data.ReadInt8();
var stacks = args.Data.ReadInt8();
var prefix = args.Data.ReadInt8();
var type = args.Data.ReadInt16();
if (OnChestItemChange(id, slot, stacks, prefix, type))
return true;
if (args.TPlayer.chest != id)
{
return false;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
return true;
}
Item item = new Item();
item.netDefaults(type);
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name, args.Player))
{
return false;
}
if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y) && TShock.Config.RegionProtectChests)
{
return false;
}
if (TShock.CheckRangePermission(args.Player, Main.chest[id].x, Main.chest[id].y))
{
return false;
}
return false;
}
private static bool HandleSign(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt16();
var x = args.Data.ReadInt32();
var y = args.Data.ReadInt32();
if (OnSignEvent(id, x, y))
return true;
if (TShock.CheckTilePermission(args.Player, x, y))
{
args.Player.SendData(PacketTypes.SignNew, "", id);
return true;
}
if (TShock.CheckRangePermission(args.Player, x, y))
{
args.Player.SendData(PacketTypes.SignNew, "", id);
return true;
}
return false;
}
private static bool UpdateNPCHome(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt16();
var x = args.Data.ReadInt16();
var y = args.Data.ReadInt16();
var homeless = args.Data.ReadInt8();
if (OnUpdateNPCHome(id, x, y, homeless))
return true;
if (!args.Player.Group.HasPermission(Permissions.movenpc))
{
args.Player.SendMessage("You do not have permission to relocate NPCs.", Color.Red);
args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY,
Convert.ToByte(Main.npc[id].homeless));
return true;
}
if (TShock.CheckTilePermission(args.Player, x, y))
{
args.Player.SendMessage( "You do not have access to modify this area.", Color.Red);
args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY,
Convert.ToByte(Main.npc[id].homeless));
return true;
}
//removed until NPC Home packet actually sends their home coords.
/*if (TShock.CheckRangePermission(args.Player, x, y))
{
args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY,
Convert.ToByte(Main.npc[id].homeless));
return true;
}*/
return false;
}
private static bool HandlePlayerBuff(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
var type = args.Data.ReadInt8();
var time = args.Data.ReadInt16();
if (OnPlayerBuff(id, type, time))
return true;
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if (!TShock.Players[id].TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50))
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
{
return false;
}
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
private static bool HandleItemDrop(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt16();
var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var stacks = args.Data.ReadInt8();
var prefix = args.Data.ReadInt8();
var type = args.Data.ReadInt16();
if (OnItemDrop(id, pos, vel, stacks, prefix, type))
return true;
// player is attempting to crash clients
if (type < -24 || type >= Main.maxItemTypes)
{
return true;
}
if (type == 0) //Item removed, let client do this to prevent item duplication client side
{
return false;
}
if (TShock.CheckRangePermission(args.Player, (int) (pos.X/16f), (int) (pos.Y/16f)))
{
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
Item item = new Item();
item.netDefaults(type);
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name, args.Player))
{
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
if ((TShock.Config.ServerSideInventory) && (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - args.Player.LoginMS < TShock.Config.LogonDiscardThreshold))
{
//Player is probably trying to sneak items onto the server in their hands!!!
Log.ConsoleInfo(string.Format("Player {0} tried to sneak {1} onto the server!", args.Player.Name, item.name));
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
return false;
}
private static bool HandlePlayerDamage(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
var direction = args.Data.ReadInt8();
var dmg = args.Data.ReadInt16();
var pvp = args.Data.ReadInt8();
var crit = args.Data.ReadInt8();
if (OnPlayerDamage(id, direction, dmg, pvp, crit))
return true;
int textlength = (int) (args.Data.Length - args.Data.Position - 1);
string deathtext = "";
if (textlength > 0)
{
deathtext = Encoding.UTF8.GetString(args.Data.ReadBytes(textlength));
/*if (!TShock.Utils.ValidString(deathtext))
{
return true;
}*/
}
if (TShock.Players[id] == null)
return true;
if (dmg > TShock.Config.MaxDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap) && id != args.Player.Index)
{
args.Player.Disable(String.Format("Player damage exceeded {0}.", TShock.Config.MaxDamage));
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if (!TShock.Players[id].TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 100))
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
return false;
}
private static bool HandleNpcStrike(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
var direction = args.Data.ReadInt8();
var dmg = args.Data.ReadInt16();
var pvp = args.Data.ReadInt8();
var crit = args.Data.ReadInt8();
if (OnNPCStrike(id, direction, dmg, pvp, crit))
return true;
if (Main.npc[id] == null)
return true;
if (dmg > TShock.Config.MaxDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap))
{
args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage ) );
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if (Main.npc[id].townNPC && !args.Player.Group.HasPermission(Permissions.movenpc))
{
args.Player.SendMessage( "You don't have permission to move this NPC.", Color.Yellow);
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if (TShock.Config.RangeChecks &&
TShock.CheckRangePermission(args.Player, (int) (Main.npc[id].position.X/16f), (int) (Main.npc[id].position.Y/16f),
128))
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
return false;
}
private static bool HandleSpecial(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
var type = args.Data.ReadInt8();
if (OnNPCSpecial(id, type))
return true;
if (type == 1 && TShock.Config.DisableDungeonGuardian)
{
args.Player.SendMessage("The Dungeon Guardian returned you to your spawn point", Color.Purple);
args.Player.Spawn();
return true;
}
return false;
}
private static bool HandlePlayerAnimation(GetDataHandlerArgs args)
{
if (OnPlayerAnimation())
return true;
if (TShock.CheckIgnores(args.Player))
{
args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index);
return true;
}
return false;
}
private static bool HandlePlayerBuffUpdate(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt8();
if (OnPlayerBuffUpdate(id))
return true;
for (int i = 0; i < 10; i++)
{
var buff = args.Data.ReadInt8();
if (buff == 10)
{
if (!args.Player.Group.HasPermission(Permissions.usebanneditem) &&
TShock.Itembans.ItemIsBanned("Invisibility Potion", args.Player))
buff = 0;
else if (TShock.Config.DisableInvisPvP && args.TPlayer.hostile)
buff = 0;
}
args.TPlayer.buffType[i] = buff;
if (args.TPlayer.buffType[i] > 0)
{
args.TPlayer.buffTime[i] = 60;
}
else
{
args.TPlayer.buffTime[i] = 0;
}
}
NetMessage.SendData((int) PacketTypes.PlayerBuff, -1, args.Player.Index, "", args.Player.Index);
return true;
}
private static bool HandleSpawnBoss(GetDataHandlerArgs args)
{
var spawnboss = false;
var invasion = -1;
var plr = args.Data.ReadInt32();
var Type = args.Data.ReadInt32();
spawnboss = (Type == 4 || Type == 13 || (Type == 50 || Type == 125) || (Type == 126 || Type == 134 || (Type == (int) sbyte.MaxValue || Type == 128)));
if (!spawnboss)
{
switch (Type)
{
case -1:
invasion = 1;
break;
case -2:
invasion = 2;
break;
}
}
if (spawnboss && !args.Player.Group.HasPermission(Permissions.summonboss))
{
args.Player.SendMessage("You don't have permission to summon a boss.", Color.Red);
return true;
}
if (invasion != -1 && !args.Player.Group.HasPermission(Permissions.startinvasion))
{
args.Player.SendMessage("You don't have permission to start an invasion.", Color.Red);
return true;
}
if (!spawnboss && invasion == -1)
return true;
if (plr != args.Player.Index)
return true;
string boss;
switch (Type)
{
case -2:
boss = "the Snow Legion";
break;
case -1:
boss = "a Goblin Invasion";
break;
case 4:
boss = "the Eye of Cthulhu";
break;
case 13:
boss = "the Eater of Worlds";
break;
case 50:
boss = "the King Slime";
break;
case 125:
boss = "Retinazer";
break;
case 126:
boss = "Spazmatism";
break;
case 134:
boss = "the Destroyer";
break;
case sbyte.MaxValue:
boss = "Skeleton Prime";
break;
case 128:
boss = "Skeleton Prime";
break;
default:
boss = "error";
break;
}
TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.PaleVioletRed, args.Player);
return false;
}
private static bool HandleTeleport(GetDataHandlerArgs args)
{
var flag = args.Data.ReadInt8();
var id = args.Data.ReadInt16();
var x = args.Data.ReadSingle();
var y = args.Data.ReadSingle();
if (OnTeleport(id, flag, x, y))
return true;
var style = 0;
var isNPC = false;
if ((flag & 1) == 1)
{
isNPC = true;
}
if ((flag & 2) != 2)
{
if ((flag & 4) == 4)
{
style++;
}
if ((flag & 8) == 8)
{
style++;
}
if (id > (isNPC ? 200 : 255))
{
return true;
}
if (x > Main.rightWorld - 500)
{
x = Main.rightWorld - 500;
}
if (x < 500)
{
x = 500;
}
if (y > Main.bottomWorld - 500)
{
y = Main.bottomWorld - 500;
}
if (y < 500)
{
y = 500;
}
if (Main.player[id] == null || TShock.Players[id] == null)
{
return true;
}
if (!args.Player.Group.HasPermission(Permissions.tp))
{
args.Player.SendErrorMessage("You do not have permission to teleport.");
Main.player[id].Teleport(new Vector2(Main.player[id].position.X, Main.player[id].position.Y), style);
NetMessage.SendData(65, -1, -1, "", 0, (float)id, Main.player[id].position.X, Main.player[id].position.Y, style);
return true;
}
Main.player[id].Teleport(new Vector2(x, y), style);
NetMessage.SendData(65, -1, -1, "", 0, (float)id, x, y, style);
}
return true;
}
}
}