private static bool HandlePlayerBuff(GetDataHandlerArgs args) { var id = args.Data.ReadInt8(); var type = args.Data.ReadInt8(); var time = args.Data.ReadInt16(); 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.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 64) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 64))) { 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 HandlePlayerSlot(GetDataHandlerArgs args) { int plr = args.Data.ReadInt8(); int slot = args.Data.ReadInt8(); int stack = args.Data.ReadInt8(); int namelength = (int)(args.Data.Length - args.Data.Position - 1); if (namelength > 0) { string itemname = Encoding.ASCII.GetString(args.Data.ReadBytes(namelength)); if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(itemname)) { args.Player.Disconnect("Using banned item: " + itemname + ", remove it and rejoin"); } if (itemname == "KANNIBALE BLADE" || itemname == "Super Gel") { return(Tools.HandleCheater(args.Player, string.Format(TShock.Config.GriefClientReason, "KANNIBALE"))); } if (Tools.GetItemByName(itemname).Count == 0 && !args.Player.Group.HasPermission(Permissions.ignorecheatdetection) && TShock.Config.KickCustomItems) { args.Player.Disconnect("Using custom item: " + itemname + ", remove it and region"); } } return(false); }
private static bool HandleTileKill(GetDataHandlerArgs args) { var tileX = args.Data.ReadInt32(); var tileY = args.Data.ReadInt32(); 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 (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); } return(false); }
private static bool HandlePlayerSlot(GetDataHandlerArgs args) { int plr = args.Data.ReadInt8(); int slot = args.Data.ReadInt8(); int stack = args.Data.ReadInt8(); short prefix = (short)args.Data.ReadInt8(); int type = (int)args.Data.ReadInt16(); if (plr != args.Player.Index) { return(true); } if (slot < 0 || slot > NetItem.maxNetInventory) { return(true); } var item = new Item(); item.netDefaults(type); item.Prefix(prefix); if (stack > item.maxStack && type != 0) { args.Player.IgnoreActionsForCheating = true; } if (args.Player.IsLoggedIn) { args.Player.PlayerData.StoreSlot(slot, type, prefix, stack); } 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; int textlength = (int)(args.Data.Length - args.Data.Position - 1); string deathtext = ""; if (textlength > 0) { deathtext = Encoding.ASCII.GetString(args.Data.ReadBytes(textlength)); if (!TShock.Utils.ValidString(deathtext)) { return(true); } } args.Player.LastDeath = DateTime.Now; if (args.Player.Difficulty != 2) { args.Player.ForceSpawn = true; } return(false); }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { byte plr = args.Data.ReadInt8(); byte control = args.Data.ReadInt8(); byte item = args.Data.ReadInt8(); float posx = args.Data.ReadSingle(); float posy = args.Data.ReadSingle(); float velx = args.Data.ReadSingle(); float vely = args.Data.ReadSingle(); if (Main.verboseNetplay) { Debug.WriteLine("Update: {{{0},{1}}} {{{2}, {3}}}", (int)posx, (int)posy, (int)velx, (int)vely); } if (plr != args.Player.Index) { return(Tools.HandleGriefer(args.Player, TShock.Config.UpdatePlayerAbuseReason)); } if (item < 0 || item >= args.TPlayer.inventory.Length) { Tools.HandleGriefer(args.Player, TShock.Config.UpdatePlayerAbuseReason); 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 (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)) { TShock.Utils.ForceKick(args.Player, "Death results in a ban, but can't ban you"); } } else { TShock.Utils.ForceKick(args.Player, TShock.Config.MediumcoreKickReason); } return(true); } } } else { args.Player.InitSpawn = true; } return(false); }
private static bool HandleGetSection(GetDataHandlerArgs args) { if (args.Player.RequestedSection) { return(true); } args.Player.RequestedSection = true; return(false); }
private static bool HandlePlayerInfo(GetDataHandlerArgs args) { byte playerid = args.Data.ReadInt8(); byte hair = args.Data.ReadInt8(); byte male = args.Data.ReadInt8(); args.Data.Position += 21; byte difficulty = args.Data.ReadInt8(); string name = Encoding.ASCII.GetString(args.Data.ReadBytes((int)(args.Data.Length - args.Data.Position - 1))); if (hair >= Main.maxHair) { Tools.ForceKick(args.Player, "Hair crash exploit."); return(true); } if (!Tools.ValidString(name)) { Tools.ForceKick(args.Player, "Unprintable character in name"); return(true); } if (name.Length > 32) { Tools.ForceKick(args.Player, "Name exceeded 32 characters."); return(true); } if (name.Trim().Length == 0) { Tools.ForceKick(args.Player, "Empty Name."); return(true); } var ban = TShock.Bans.GetBanByName(name); if (ban != null) { Tools.ForceKick(args.Player, string.Format("You are banned: {0}", ban.Reason)); return(true); } if (args.Player.ReceivedInfo) { return(Tools.HandleGriefer(args.Player, "Sent client info more than once")); } if (TShock.Config.MediumcoreOnly && difficulty < 1) { Tools.ForceKick(args.Player, "Server is set to mediumcore and above characters only!"); return(true); } if (TShock.Config.HardcoreOnly && difficulty < 2) { Tools.ForceKick(args.Player, "Server is set to hardcore characters only!"); return(true); } args.Player.Difficulty = difficulty; args.Player.ReceivedInfo = true; return(false); }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { byte playerid = args.Data.ReadInt8(); if (TShock.Players[playerid] == null) { return(true); } return(!TShock.Players[playerid].TPlayer.hostile); }
private static bool HandleChest(GetDataHandlerArgs args) { var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32))) { return(Tools.HandleGriefer(args.Player, TShock.Config.RangeCheckBanReason)); } return(false); }
private static bool HandleTileKill(GetDataHandlerArgs args) { int tilex = args.Data.ReadInt32(); int tiley = args.Data.ReadInt32(); if (tilex < 0 || tilex >= Main.maxTilesX || tiley < 0 || tiley >= Main.maxTilesY) { return(false); } if (Main.tile[tilex, tiley].type != 0x15 && (!Tools.MaxChests() && Main.tile[tilex, tiley].type != 0)) //Chest { Log.Debug(string.Format("TileKill(TileXY:{0}_{1}, Type:{2})", tilex, tiley, Main.tile[tilex, tiley].type)); Tools.ForceKick(args.Player, string.Format(TShock.Config.TileKillAbuseReason, Main.tile[tilex, tiley].type)); return(true); } if (!args.Player.Group.HasPermission(Permissions.canbuild)) { args.Player.SendMessage("You do not have permission to build!", Color.Red); args.Player.SendTileSquare(tilex, tiley); return(true); } if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tilex, tiley, args.Player) && TShock.Regions.InArea(tilex, tiley)) { args.Player.SendMessage("Region protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return(true); } if (TShock.Config.DisableBuild) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { args.Player.SendMessage("World protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return(true); } } if (TShock.Config.SpawnProtection) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { var flag = TShock.CheckSpawn(tilex, tiley); if (flag) { args.Player.SendMessage("Spawn protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return(true); } } } return(false); }
private static bool HandleSign(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (TShock.CheckTilePermission(args.Player, x, y)) { args.Player.SendData(PacketTypes.SignNew, "", id); return(true); } return(false); }
private static bool HandleGetSection(GetDataHandlerArgs args) { var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (args.Player.RequestedSection) { Tools.ForceKick(args.Player, "Requested sections more than once."); return(true); } args.Player.RequestedSection = true; return(false); }
private static bool HandleSpecial(GetDataHandlerArgs args) { var id = args.Data.ReadInt8(); var type = args.Data.ReadInt8(); 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 HandleProjectileNew(GetDataHandlerArgs args) { short ident = args.Data.ReadInt16(); float posx = args.Data.ReadSingle(); float posy = args.Data.ReadSingle(); float velx = args.Data.ReadSingle(); float vely = args.Data.ReadSingle(); float knockback = args.Data.ReadSingle(); short dmg = args.Data.ReadInt16(); byte owner = args.Data.ReadInt8(); byte type = args.Data.ReadInt8(); if (ident > Main.maxProjectiles || ident < 0) { Tools.HandleGriefer(args.Player, TShock.Config.ExplosiveAbuseReason); return(true); } if (type == 23) { if (velx == 0f && vely == 0f && dmg == 99) { Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason); return(true); } else if (velx == 0f || vely == 0f) { return(true); } } if (type == 29 || type == 28 || type == 37) { Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})", args.Player.TileX, args.Player.TileY, type)); if (TShock.Config.DisableExplosives && (!args.Player.Group.HasPermission(Permissions.useexplosives) || !args.Player.Group.HasPermission(Permissions.ignoregriefdetection))) { Main.projectile[ident].type = 0; args.Player.SendData(PacketTypes.ProjectileNew, "", ident); args.Player.SendMessage("Explosives are disabled!", Color.Red); args.Player.LastExplosive = DateTime.UtcNow; //return true; } else { return(Tools.HandleExplosivesUser(args.Player, TShock.Config.ExplosiveAbuseReason)); } } return(false); }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { byte id = args.Data.ReadInt8(); if (id != args.Player.Index) { return(Tools.HandleGriefer(args.Player, TShock.Config.KillMeAbuseReason)); } args.Player.LastDeath = DateTime.Now; if (args.Player.Difficulty != 2) { args.Player.ForceSpawn = true; } return(false); }
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()); if (item < 0 || item >= args.TPlayer.inventory.Length) { return(true); } if ((control & 32) == 32) { if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(args.TPlayer.inventory[item].name)) { args.Player.LastThreat = DateTime.UtcNow; args.Player.SendMessage(string.Format("You cannot use {0} on this server. Your actions are being ignored.", args.TPlayer.inventory[item].name), Color.Red); return(true); } } if (!pos.Equals(args.Player.LastNetPosition)) { float distance = Vector2.Distance(new Vector2((pos.X / 16f), (pos.Y / 16f)), new Vector2(Main.spawnTileX, Main.spawnTileY)); if (TShock.CheckIgnores(args.Player) && distance > 6f) { if (args.Player.IgnoreActionsForCheating) { args.Player.SendMessage("You have been disabled for cheating! Please login with a new character!", Color.Red); } else if (TShock.Config.ServerSideInventory && !args.Player.IsLoggedIn) { args.Player.SendMessage("Server Side Inventory is enabled! Please /register or /login to play!", Color.Red); } else if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile) { args.Player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red); } args.Player.Spawn(); return(true); } } args.Player.LastNetPosition = pos; return(false); }
private static bool HandleChestOpen(GetDataHandlerArgs args) { var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (TShock.CheckIgnores(args.Player)) { return(true); } if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32))) { return(true); } return(false); }
private static bool HandlePlayerAnimation(GetDataHandlerArgs args) { 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 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 (Main.npc[id] == null) { return(true); } if (dmg > 175) { 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.SendData(PacketTypes.NpcUpdate, "", id); return(true); } if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - (Main.npc[id].position.X / 16f)) > 128) || (Math.Abs(args.Player.TileY - (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 HandlePlayerMana(GetDataHandlerArgs args) { int plr = args.Data.ReadInt8(); int cur = args.Data.ReadInt16(); int max = args.Data.ReadInt16(); if (cur > 600 || max > 600) { args.Player.IgnoreActionsForCheating = true; } if (args.Player.IsLoggedIn) { args.Player.PlayerData.maxMana = max; } return(false); }
private static bool HandleTogglePvp(GetDataHandlerArgs args) { int id = args.Data.ReadByte(); bool pvp = args.Data.ReadBoolean(); long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds; if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle) { args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", TShock.Config.PvpThrottle - seconds), 255, 0, 0); args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : args.TPlayer.hostile); } else { args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : pvp); } 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(); var index = TShock.Utils.SearchProjectile(ident); if (index > Main.maxProjectiles || index < 0) { return(true); } if (args.Player.Index != owner) { args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } if (dmg > 175) { args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } if (TShock.CheckIgnores(args.Player)) { args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } if (TShock.CheckProjectilePermission(args.Player, index, type)) { args.Player.LastThreat = DateTime.UtcNow; args.Player.SendData(PacketTypes.ProjectileNew, "", index); 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 (!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.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 HandleProjectileKill(GetDataHandlerArgs args) { var ident = args.Data.ReadInt16(); var owner = args.Data.ReadInt8(); if (args.Player.Index != owner) { return(true); } var index = TShock.Utils.SearchProjectile(ident); if (index > Main.maxProjectiles || index < 0) { return(true); } int type = Main.projectile[index].type; if (args.Player.Index != Main.projectile[index].owner) { args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } if (TShock.CheckIgnores(args.Player)) { args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } if (TShock.CheckProjectilePermission(args.Player, index, type)) { args.Player.LastThreat = DateTime.UtcNow; args.Player.SendData(PacketTypes.ProjectileNew, "", index); return(true); } return(false); }
private static bool HandleTogglePvp(GetDataHandlerArgs args) { int id = args.Data.ReadByte(); bool pvp = args.Data.ReadBoolean(); if (id != args.Player.Index) { 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.AlwaysPvP) { if (pvp == true) { args.Player.IgnoreActionsForPvP = false; } else { args.Player.Spawn(); args.Player.IgnoreActionsForPvP = true; } } NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", args.Player.Index); 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 (type == 0) //Item removed, let client do this to prevent item duplication client side { return(false); } if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - (pos.X / 16f)) > 64) || (Math.Abs(args.Player.TileY - (pos.Y / 16f)) > 64))) { 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.SendData(PacketTypes.ItemDrop, "", id); return(true); } if (TShock.CheckIgnores(args.Player)) { args.Player.SendData(PacketTypes.ItemDrop, "", id); 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 (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.SendData(PacketTypes.ChestItem, "", id, slot); return(false); } if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y)) { args.Player.SendData(PacketTypes.ChestItem, "", id, slot); return(false); } return(false); }
private static bool HandleSendSection(GetDataHandlerArgs args) { return Tools.HandleGriefer(args.Player, TShock.Config.SendSectionAbuseReason); }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { byte plr = args.Data.ReadInt8(); byte control = args.Data.ReadInt8(); byte item = args.Data.ReadInt8(); float posx = args.Data.ReadSingle(); float posy = args.Data.ReadSingle(); float velx = args.Data.ReadSingle(); float vely = args.Data.ReadSingle(); if (Main.verboseNetplay) Debug.WriteLine("Update: {{{0},{1}}} {{{2}, {3}}}", (int)posx, (int)posy, (int)velx, (int)vely); if (plr != args.Player.Index) { return Tools.HandleGriefer(args.Player, TShock.Config.UpdatePlayerAbuseReason); } if (item < 0 || item >= args.TPlayer.inventory.Length) { Tools.HandleGriefer(args.Player, TShock.Config.UpdatePlayerAbuseReason); return true; } return false; }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { byte id = args.Data.ReadInt8(); if (id != args.Player.Index) { return Tools.HandleGriefer(args.Player, TShock.Config.KillMeAbuseReason); } args.Player.LastDeath = DateTime.Now; if (args.Player.Difficulty != 2) args.Player.ForceSpawn = true; return false; }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { byte playerid = args.Data.ReadInt8(); if (TShock.Players[playerid] == null) return true; return !TShock.Players[playerid].TPlayer.hostile; }
private static bool HandleLiquidSet(GetDataHandlerArgs args) { int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); byte liquid = args.Data.ReadInt8(); bool lava = args.Data.ReadBoolean(); //The liquid was picked up. if (liquid == 0) return false; int plyX = Math.Abs(args.Player.TileX); int plyY = Math.Abs(args.Player.TileY); int tileX = Math.Abs(x); int tileY = Math.Abs(y); bool bucket = false; for (int i = 0; i < 44; i++) { if (args.TPlayer.inventory[i].type >= 205 && args.TPlayer.inventory[i].type <= 207) { bucket = true; break; } } if (!args.Player.Group.HasPermission(Permissions.canbuild)) { args.Player.SendMessage("You do not have permission to build!", Color.Red); args.Player.SendTileSquare(x, y); return true; } if (lava && !args.Player.Group.HasPermission(Permissions.canlava)) { args.Player.SendMessage("You do not have permission to use lava", Color.Red); Tools.SendLogs(string.Format("{0} tried using lava", args.Player.Name), Color.Red); args.Player.SendTileSquare(x, y); return true; } if (!lava && !args.Player.Group.HasPermission(Permissions.canwater)) { args.Player.SendMessage("You do not have permission to use water", Color.Red); Tools.SendLogs(string.Format("{0} tried using water", args.Player.Name), Color.Red); args.Player.SendTileSquare(x, y); return true; } if (!bucket) { Log.Debug(string.Format("{0}(PlyXY:{1}_{2}, TileXY:{3}_{4}, Result:{5}_{6}, Amount:{7})", lava ? "Lava" : "Water", plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid)); return Tools.HandleGriefer(args.Player, TShock.Config.IllogicalLiquidUseReason); ; } if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32))) { Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})", plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid)); return Tools.HandleGriefer(args.Player, TShock.Config.LiquidAbuseReason); } if (TShock.Config.SpawnProtection) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { var flag = TShock.CheckSpawn(x, y); if (flag) { args.Player.SendMessage("The spawn is protected!", Color.Red); args.Player.SendTileSquare(x, y); return true; } } } return false; }
private static bool HandleNpcStrike(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var dmg = args.Data.ReadInt16(); var knockback = args.Data.ReadSingle(); var direction = (byte)(args.Data.ReadInt8() - 1); var crit = args.Data.ReadInt8(); if (OnNPCStrike(id, direction, dmg, knockback, crit)) return true; if (Main.npc[id] == null) return true; if (dmg > TShock.Config.MaxDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap)) { if (TShock.Config.KickOnDamageThresholdBroken) { TShock.Utils.Kick(args.Player, string.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage)); return true; } else { args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage), DisableFlags.WriteToLogAndConsole); } 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.hurttownnpc)) { args.Player.SendErrorMessage("You do not have permission to hurt this NPC."); 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 HandleTileKill(GetDataHandlerArgs args) { int tilex = args.Data.ReadInt32(); int tiley = args.Data.ReadInt32(); if (tilex < 0 || tilex >= Main.maxTilesX || tiley < 0 || tiley >= Main.maxTilesY) return false; if (Main.tile[tilex, tiley].type != 0x15 && (!Tools.MaxChests() && Main.tile[tilex, tiley].type != 0)) //Chest { Log.Debug(string.Format("TileKill(TileXY:{0}_{1}, Type:{2})", tilex, tiley, Main.tile[tilex, tiley].type)); Tools.ForceKick(args.Player, string.Format(TShock.Config.TileKillAbuseReason, Main.tile[tilex, tiley].type)); return true; } if (!args.Player.Group.HasPermission(Permissions.canbuild)) { args.Player.SendMessage("You do not have permission to build!", Color.Red); args.Player.SendTileSquare(tilex, tiley); return true; } if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tilex, tiley, args.Player) && TShock.Regions.InArea(tilex, tiley)) { args.Player.SendMessage("Region protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return true; } if (TShock.Config.DisableBuild) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { args.Player.SendMessage("World protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return true; } } if (TShock.Config.SpawnProtection) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { var flag = TShock.CheckSpawn(tilex, tiley); if (flag) { args.Player.SendMessage("Spawn protected from changes.", Color.Red); args.Player.SendTileSquare(tilex, tiley); return true; } } } return false; }
private static bool HandleSign(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32))) { return Tools.HandleGriefer(args.Player, TShock.Config.RangeCheckBanReason); } 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) || cur <= 0 || max <= 0 || args.Player.IgnoreSSCPackets) return true; if (max > TShock.Config.MaxHP && !args.Player.Group.HasPermission(Permissions.ignorehp)) { args.Player.Disable("Maximum HP beyond limit", DisableFlags.WriteToLogAndConsole); return true; } if (args.Player.IsLoggedIn) { args.Player.TPlayer.statLife = cur; args.Player.TPlayer.statLifeMax = max; args.Player.PlayerData.maxHealth = max; } if (args.Player.GodMode && (cur < max)) { args.Player.Heal(args.TPlayer.statLifeMax2); } return false; }
private static bool HandleSync(GetDataHandlerArgs args) { return TShock.Config.EnableAntiLag; }
private static bool HandleChestActive(GetDataHandlerArgs args) { //chest ID var id = args.Data.ReadInt16(); //chest x var x = args.Data.ReadInt16(); //chest y var y = args.Data.ReadInt16(); //chest name length var nameLen = args.Data.ReadInt8(); if (nameLen != 0 && nameLen <= 20) args.Data.ReadString(); // Ignore the name args.Player.ActiveChest = id; if (TShock.CheckTilePermission(args.Player, x, y) && TShock.Config.RegionProtectChests) { args.Player.SendData(PacketTypes.ChestOpen, "", -1); return true; } return false; }
private static bool HandleLiquidSet(GetDataHandlerArgs args) { int tileX = args.Data.ReadInt16(); int tileY = args.Data.ReadInt16(); byte amount = args.Data.ReadInt8(); byte type = args.Data.ReadInt8(); if (OnLiquidSet(tileX, tileY, amount, type)) return true; if (!TShock.Utils.TilePlacementValid(tileX, tileY) || (args.Player.Dead && TShock.Config.PreventDeadModification)) return true; if (TShock.CheckIgnores(args.Player)) { args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (args.Player.TileLiquidThreshold >= TShock.Config.TileLiquidThreshold) { args.Player.Disable("Reached TileLiquid threshold.", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (!args.Player.Group.HasPermission(Permissions.ignoreliquidsetdetection)) { args.Player.TileLiquidThreshold++; } if (amount != 0) { int bucket = -1; if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 205) { bucket = 0; } else if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 206) { bucket = 1; } else if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 207) { bucket = 2; } else if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 1128) { bucket = 3; } else if (args.TPlayer.inventory[args.TPlayer.selectedItem].type == 3031 || args.TPlayer.inventory[args.TPlayer.selectedItem].type == 3032) { bucket = 4; } if (type == 1 && !(bucket == 2 || bucket == 0)) { args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.Disable("Spreading lava without holding a lava bucket", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (type == 1 && 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", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (type == 0 && !(bucket == 1 || bucket == 0 || bucket == 4)) { args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.Disable("Spreading water without holding a water bucket", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (type == 0 && 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", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (type == 2 && !(bucket == 3 || bucket == 0)) { args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.Disable("Spreading honey without holding a honey bucket", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (type == 2 && TShock.Itembans.ItemIsBanned("Honey Bucket", args.Player)) { args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.Disable("Using banned honey bucket without permissions", DisableFlags.WriteToLogAndConsole); args.Player.SendTileSquare(tileX, tileY, 1); return true; } } if (TShock.CheckTilePermission(args.Player, tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 1); return true; } if (TShock.CheckRangePermission(args.Player, tileX, tileY, 16)) { args.Player.SendTileSquare(tileX, tileY, 1); return true; } if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000) { args.Player.SendTileSquare(tileX, tileY, 1); return true; } return false; }
private static bool HandleChestItem(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var slot = args.Data.ReadInt8(); var stacks = args.Data.ReadInt16(); 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 HandleGetSection(GetDataHandlerArgs args) { var x = args.Data.ReadInt32(); var y = args.Data.ReadInt32(); if (args.Player.RequestedSection) { Tools.ForceKick(args.Player, "Requested sections more than once."); return true; } args.Player.RequestedSection = true; return false; }
private static bool HandleChestOpen(GetDataHandlerArgs args) { var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); if (OnChestOpen(x, y, args.Player)) 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; } int id = Chest.FindChest(x, y); args.Player.ActiveChest = id; return false; }
private static bool HandleNpcUpdate(GetDataHandlerArgs args) { return Tools.HandleGriefer(args.Player, TShock.Config.NPCSpawnAbuseReason); }
private static bool HandleCompleteAnglerQuest(GetDataHandlerArgs args) { // Since packet 76 is NEVER sent to us, we actually have to rely on this to get the true count args.TPlayer.anglerQuestsFinished++; return false; }
private static bool HandlePlayerInfo(GetDataHandlerArgs args) { byte playerid = args.Data.ReadInt8(); byte hair = args.Data.ReadInt8(); byte male = args.Data.ReadInt8(); args.Data.Position += 21; byte difficulty = args.Data.ReadInt8(); string name = Encoding.ASCII.GetString(args.Data.ReadBytes((int)(args.Data.Length - args.Data.Position - 1))); if (hair >= Main.maxHair) { Tools.ForceKick(args.Player, "Hair crash exploit."); return true; } if (!Tools.ValidString(name)) { Tools.ForceKick(args.Player, "Unprintable character in name"); return true; } if (name.Length > 32) { Tools.ForceKick(args.Player, "Name exceeded 32 characters."); return true; } if (name.Trim().Length == 0) { Tools.ForceKick(args.Player, "Empty Name."); return true; } var ban = TShock.Bans.GetBanByName(name); if (ban != null) { Tools.ForceKick(args.Player, string.Format("You are banned: {0}", ban.Reason)); return true; } if (args.Player.ReceivedInfo) { return Tools.HandleGriefer(args.Player, "Sent client info more than once"); } if (TShock.Config.MediumcoreOnly && difficulty < 1) { Tools.ForceKick(args.Player, "Server is set to mediumcore and above characters only!"); return true; } if (TShock.Config.HardcoreOnly && difficulty < 2) { Tools.ForceKick(args.Player, "Server is set to hardcore characters only!"); return true; } args.Player.Difficulty = difficulty; 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.DisableUUIDLogin) { if (user.UUID == args.Player.UUID) { if (args.Player.State == 1) args.Player.State = 2; NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index); args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, user.ID); var group = TShock.Utils.GetGroup(user.Group); if (Main.ServerSideCharacter) { if (!group.HasPermission(Permissions.bypassssc)) { args.Player.PlayerData.RestoreCharacter(args.Player); } } 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.User = user; args.Player.IsLoggedIn = true; args.Player.IgnoreActionsForInventory = "none"; if (!args.Player.IgnoreActionsForClearingTrashCan && Main.ServerSideCharacter) { args.Player.PlayerData.CopyCharacter(args.Player); TShock.CharacterDB.InsertPlayerData(args.Player); } args.Player.SendSuccessMessage("Authenticated as " + user.Name + " successfully."); TShock.Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + "."); Hooks.PlayerHooks.OnPlayerPostLogin(args.Player); return true; } } else 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 HandlePlayerSlot(GetDataHandlerArgs args) { int plr = args.Data.ReadInt8(); int slot = args.Data.ReadInt8(); int stack = args.Data.ReadInt8(); int namelength = (int)(args.Data.Length - args.Data.Position - 1); if (namelength > 0) { string itemname = Encoding.ASCII.GetString(args.Data.ReadBytes(namelength)); if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(itemname)) args.Player.Disconnect("Using banned item: " + itemname + ", remove it and rejoin"); if (itemname == "KANNIBALE BLADE" || itemname == "Super Gel") return Tools.HandleCheater(args.Player, string.Format(TShock.Config.GriefClientReason, "KANNIBALE")); if (Tools.GetItemByName(itemname).Count == 0 && !args.Player.Group.HasPermission(Permissions.ignorecheatdetection) && TShock.Config.KickCustomItems) args.Player.Disconnect("Using custom item: " + itemname + ", remove it and region"); } return false; }
private static bool HandleDoorUse(GetDataHandlerArgs args) { byte type = (byte)args.Data.ReadByte(); short x = args.Data.ReadInt16(); short y = args.Data.ReadInt16(); args.Data.ReadByte(); //Ignore direction if (x >= Main.maxTilesX || y >= Main.maxTilesY || x < 0 || y < 0) // Check for out of range { return true; } if (type < 0 || type > 5) { return true; } ushort tileType = Main.tile[x, y].type; if (tileType != TileID.ClosedDoor && tileType != TileID.OpenDoor && tileType != TileID.TallGateClosed && tileType != TileID.TallGateOpen && tileType != TileID.TrapdoorClosed && tileType != TileID.TrapdoorOpen) { return true; } return false; }
private static bool HandleProjectileNew(GetDataHandlerArgs args) { short ident = args.Data.ReadInt16(); float posx = args.Data.ReadSingle(); float posy = args.Data.ReadSingle(); float velx = args.Data.ReadSingle(); float vely = args.Data.ReadSingle(); float knockback = args.Data.ReadSingle(); short dmg = args.Data.ReadInt16(); byte owner = args.Data.ReadInt8(); byte type = args.Data.ReadInt8(); if (ident > Main.maxProjectiles || ident < 0) { Tools.HandleGriefer(args.Player, TShock.Config.ExplosiveAbuseReason); return true; } if (type == 23 && (vely == 0f || velx == 0f)) //float.IsNaN((float)Math.Sqrt((double)(velx * velx + vely * vely)))) { Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason); return true; } if (type == 29 || type == 28 || type == 37) { Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})", args.Player.TileX, args.Player.TileY, type)); if (TShock.Config.DisableExplosives && (!args.Player.Group.HasPermission(Permissions.useexplosives) || !args.Player.Group.HasPermission(Permissions.ignoregriefdetection))) { Main.projectile[ident].type = 0; args.Player.SendData(PacketTypes.ProjectileNew, "", ident); args.Player.SendMessage("Explosives are disabled!", Color.Red); args.Player.LastExplosive = DateTime.UtcNow; //return true; } else return Tools.HandleExplosivesUser(args.Player, TShock.Config.ExplosiveAbuseReason); } return false; }
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 (!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, "", Main.dayTime ? 1 : 0, (int)Main.time, Main.sunModY, Main.moonModY); return false; }
private static bool HandleSendTileSquare(GetDataHandlerArgs args) { short size = args.Data.ReadInt16(); int tilex = args.Data.ReadInt32(); int tiley = args.Data.ReadInt32(); if (size > 5) 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 (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; } } } if (changed) TSPlayer.All.SendTileSquare(tilex, tiley, 3); 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.ReadInt16(); var prefix = args.Data.ReadInt8(); var noDelay = args.Data.ReadInt8() == 1; var type = args.Data.ReadInt16(); if (OnItemDrop(id, pos, vel, stacks, prefix, noDelay, type)) return true; // player is attempting to crash clients if (type < -48 || type >= Main.maxItemTypes) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if (prefix > Item.maxPrefixes) //make sure the prefix is a legit value { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if (type == 0) //Item removed, let client do this to prevent item duplication client side (but only if it passed the range check) { if (TShock.CheckRangePermission(args.Player, (int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } return false; } if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if (Main.item[id].active && Main.item[id].netID != type) //stop the client from changing the item type of a drop but only if the client isn't picking up the item { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } Item item = new Item(); item.netDefaults(type); if ((stacks > item.maxStack || stacks <= 0) || (TShock.Itembans.ItemIsBanned(item.name, args.Player) && !args.Player.Group.HasPermission(Permissions.allowdroppingbanneditems))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if ((Main.ServerSideCharacter) && (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - args.Player.LoginMS < TShock.ServerSideCharacterConfig.LogonDiscardThreshold)) { //Player is probably trying to sneak items onto the server in their hands!!! TShock.Log.ConsoleInfo("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 HandleSpawn(GetDataHandlerArgs args) { byte player = args.Data.ReadInt8(); int spawnx = args.Data.ReadInt32(); int spawny = args.Data.ReadInt32(); 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 (!Tools.Ban(args.Player, TShock.Config.MediumcoreBanReason)) Tools.ForceKick(args.Player, "Death results in a ban, but can't ban you"); } else { Tools.ForceKick(args.Player, TShock.Config.MediumcoreKickReason); } return true; } } } else args.Player.InitSpawn = true; return false; }
private static bool HandleItemOwner(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var owner = args.Data.ReadInt8(); if (id < 0 || id > 400) return true; if (id == 400 && owner == 255) { args.Player.IgnoreSSCPackets = false; return true; } return false; }
private static bool HandleTile(GetDataHandlerArgs args) { byte type = args.Data.ReadInt8(); int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); byte tiletype = args.Data.ReadInt8(); if (args.Player.AwaitingName) { if (TShock.Regions.InAreaRegionName(x, y) == null) { args.Player.SendMessage("Region is not protected", Color.Yellow); } else { args.Player.SendMessage("Region Name: " + TShock.Regions.InAreaRegionName(x, y), Color.Yellow); } args.Player.SendTileSquare(x, y); args.Player.AwaitingName = false; return true; } if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x; args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y; args.Player.SendMessage("Set Temp Point " + args.Player.AwaitingTempPoint, Color.Yellow); args.Player.SendTileSquare(x, y); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission(Permissions.canbuild)) { if (!args.Player.HasBeenSpammedWithBuildMessage) { args.Player.SendMessage("You do not have permission to build!", Color.Red); args.Player.HasBeenSpammedWithBuildMessage = true; } args.Player.SendTileSquare(x, y); return true; } if (type == 1 || type == 3) { int plyX = Math.Abs(args.Player.TileX); int plyY = Math.Abs(args.Player.TileY); int tileX = Math.Abs(x); int tileY = Math.Abs(y); if (tiletype >= ((type == 1) ? Main.maxTileSets : Main.maxWallTypes)) { Tools.HandleGriefer(args.Player, string.Format(TShock.Config.TileAbuseReason, "Invalid tile type")); return true; } if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32))) { if (!(type == 1 && ((tiletype == 0 && args.Player.TPlayer.selectedItem == 114) || (tiletype == 53 && args.Player.TPlayer.selectedItem == 266)))) { Log.Debug(string.Format("TilePlaced(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Type:{6})", plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), tiletype)); return Tools.HandleGriefer(args.Player, TShock.Config.RangeCheckBanReason); } } if (tiletype == 48 && !args.Player.Group.HasPermission(Permissions.canspike)) { args.Player.SendMessage("You do not have permission to place spikes.", Color.Red); Tools.SendLogs(string.Format("{0} tried to place spikes", args.Player.Name), Color.Red); args.Player.SendTileSquare(x, y); return true; } } if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(x, y, args.Player) && TShock.Regions.InArea(x, y)) { if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000) { args.Player.SendMessage("Region Name: " + TShock.Regions.InAreaRegionName(x, y) + " protected from changes.", Color.Red); args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); return true; } if (TShock.Config.DisableBuild) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000) { args.Player.SendMessage("World protected from changes.", Color.Red); args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); return true; } } if (TShock.Config.SpawnProtection) { if (!args.Player.Group.HasPermission(Permissions.editspawn)) { var flag = TShock.CheckSpawn(x, y); if (flag) { if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000) { args.Player.SendMessage("Spawn protected from changes.", Color.Red); args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); return true; } } } if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && args.Player.Active) { args.Player.TileThreshold++; var coords = new PointF(x, y); if (!args.Player.TilesDestroyed.ContainsKey(coords)) args.Player.TilesDestroyed.Add(coords, Main.tile[x, y]); } if ((DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds < 1000) { args.Player.SendMessage("Please wait another " + (1000 - (DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds) + " milliseconds before placing/destroying tiles", Color.Red); args.Player.SendTileSquare(x, y); return 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(); //The liquid was picked up. if (liquid == 0) { return(false); } 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 ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000) { args.Player.SendTileSquare(tileX, tileY); return(true); } bool bucket = false; for (int i = 0; i < 49; i++) { if (args.TPlayer.inventory[i].type >= 205 && args.TPlayer.inventory[i].type <= 207) { bucket = true; break; } } if (!bucket) { args.Player.SendTileSquare(tileX, tileY); return(true); } if (lava && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Lava Bucket")) { args.Player.SendTileSquare(tileX, tileY); return(true); } if (!lava && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Water Bucket")) { args.Player.SendTileSquare(tileX, tileY); return(true); } if (TShock.CheckTilePermission(args.Player, tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY); return(true); } return(false); }
private static bool HandleTogglePvp(GetDataHandlerArgs args) { int id = args.Data.ReadByte(); bool pvp = args.Data.ReadBoolean(); long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds; if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle) { args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", TShock.Config.PvpThrottle - seconds), 255, 0, 0); args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : args.TPlayer.hostile); } else { args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : pvp); } return true; }
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.SendErrorMessage("You do not have permission to relocate NPCs."); 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.SendErrorMessage("You do not have access to modify this area."); 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; }