private static void NetHooks_GetData(GetDataEventArgs e)
 {
     if (Main.netMode != 2)
     {
         return;
     }
     if (e.MsgID == PacketTypes.ConnectRequest)
     {
         e.Handled = ServerHooks.OnConnect(e.Msg.whoAmI);
         if (e.Handled)
         {
             Netplay.serverSock[e.Msg.whoAmI].kill = true;
             return;
         }
     }
     else if (e.MsgID == PacketTypes.ContinueConnecting2)
     {
         e.Handled = ServerHooks.OnJoin(e.Msg.whoAmI);
         if (e.Handled)
         {
             Netplay.serverSock[e.Msg.whoAmI].kill = true;
             return;
         }
     }
     else
     {
         if (e.MsgID == PacketTypes.ChatText)
         {
             string @string = Encoding.UTF8.GetString(e.Msg.readBuffer, e.Index + 4, e.Length - 5);
             e.Handled = ServerHooks.OnChat(e.Msg, e.Msg.whoAmI, @string);
         }
     }
 }
Esempio n. 2
0
 private static void NetHooks_GetData(GetDataEventArgs e)
 {
     if (Main.netMode != 2 && e.MsgID == PacketTypes.ChatText && e.Length > 3)
     {
         byte   playerID = e.Msg.readBuffer[e.Index];
         Color  color    = new Color((int)e.Msg.readBuffer[e.Index + 1] << 16, (int)e.Msg.readBuffer[e.Index + 2] << 8, (int)e.Msg.readBuffer[e.Index + 3]);
         string @string  = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 4, e.Length - 5);
         ClientHooks.OnChatReceived(playerID, color, @string);
     }
 }
Esempio n. 3
0
 private static void NetHooks_GetData(GetDataEventArgs e)
 {
     if (Main.netMode != 2 && e.MsgID == PacketTypes.ChatText && e.Length > 3)
     {
         byte playerID = e.Msg.readBuffer[e.Index];
         Color color = new Color((int)e.Msg.readBuffer[e.Index + 1] << 16, (int)e.Msg.readBuffer[e.Index + 2] << 8, (int)e.Msg.readBuffer[e.Index + 3]);
         string @string = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 4, e.Length - 5);
         ClientHooks.OnChatReceived(playerID, color, @string);
     }
 }
Esempio n. 4
0
 public static bool OnGetData(ref byte msgid, messageBuffer msg, ref int idx, ref int length)
 {
     if (NetHooks.GetData == null)
     {
         return false;
     }
     GetDataEventArgs getDataEventArgs = new GetDataEventArgs
     {
         MsgID = (PacketTypes)msgid,
         Msg = msg,
         Index = idx,
         Length = length
     };
     NetHooks.GetData(getDataEventArgs);
     msgid = (byte)getDataEventArgs.MsgID;
     idx = getDataEventArgs.Index;
     length = getDataEventArgs.Length;
     return getDataEventArgs.Handled;
 }
Esempio n. 5
0
        public static bool OnGetData(ref byte msgid, messageBuffer msg, ref int idx, ref int length)
        {
            if (NetHooks.GetData == null)
            {
                return(false);
            }
            GetDataEventArgs getDataEventArgs = new GetDataEventArgs
            {
                MsgID  = (PacketTypes)msgid,
                Msg    = msg,
                Index  = idx,
                Length = length
            };

            NetHooks.GetData(getDataEventArgs);
            msgid  = (byte)getDataEventArgs.MsgID;
            idx    = getDataEventArgs.Index;
            length = getDataEventArgs.Length;
            return(getDataEventArgs.Handled);
        }
        public void GetData(GetDataEventArgs e)
        {
            try
            {
                if (e.Handled || UsingInfiniteSigns) return;
                switch (e.MsgID)
                {
                    #region Sign Edit
                    case PacketTypes.SignNew:
                        {
                            int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 2);
                            int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 6);
                            string text = Encoding.UTF8.GetString(e.Msg.readBuffer, e.Index + 10, e.Length - 11);

                            int id = Terraria.Sign.ReadSign(X, Y);
                            if (id < 0 || Main.sign[id] == null) return;
                            X = Main.sign[id].x;
                            Y = Main.sign[id].y;
                            if (OnSignEdit(X, Y, text, e.Msg.whoAmI))
                            {
                                e.Handled = true;
                                TShock.Players[e.Msg.whoAmI].SendData(PacketTypes.SignNew, "", id);
                            }
                        }
                        break;
                    #endregion

                    #region Tile Modify
                    case PacketTypes.Tile:
                        {
                            int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
                            int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);

                            if (Main.tile[X, Y].type != 55) return;

                            int id = Terraria.Sign.ReadSign(X, Y);
                            if (id < 0 || Main.sign[id] == null) return;
                            X = Main.sign[id].x;
                            Y = Main.sign[id].y;
                            string text = Main.sign[id].text;

                            bool handle = false;
                            if (e.Msg.readBuffer[e.Index] == 0 && e.Msg.readBuffer[e.Index + 9] == 0)
                                handle = OnSignKill(X, Y, text, e.Msg.whoAmI);
                            else
                                handle = OnSignHit(X, Y, text, e.Msg.whoAmI);

                            if (handle)
                            {
                                e.Handled = true;
                                TShock.Players[e.Msg.whoAmI].SendTileSquare(X, Y);
                            }
                        }
                        break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Log.Error("[Sign Commands] Exception:");
                Log.Error(ex.ToString());
            }
        }
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         int index = e.Msg.whoAmI;
         switch (e.MsgID)
         {
             case PacketTypes.ChestGetContents:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 4);
                     GetChest(X, Y, index);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.ChestItem:
                 {
                     byte slot = e.Msg.readBuffer[e.Index + 2];
                     if (slot > 20)
                     {
                         return;
                     }
                     byte stack = e.Msg.readBuffer[e.Index + 3];
                     byte prefix = e.Msg.readBuffer[e.Index + 4];
                     int netID = BitConverter.ToInt16(e.Msg.readBuffer, e.Index + 5);
                     ModChest(index, slot, netID, stack, prefix);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.Tile:
                 {
                     if (e.Msg.readBuffer[e.Index] == 1 && e.Msg.readBuffer[e.Index + 9] == 21)
                     {
                         int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
                         int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
                         if (TShock.Regions.CanBuild(X, Y, TShock.Players[index]))
                         {
                             PlaceChest(X, Y, index);
                             WorldGen.PlaceChest(X, Y, 21, false, e.Msg.readBuffer[e.Index + 10]);
                             NetMessage.SendData((int)PacketTypes.Tile, -1, index, "", 1, X, Y, 21, e.Msg.readBuffer[e.Index + 10]);
                             e.Handled = true;
                         }
                     }
                 }
                 break;
             case PacketTypes.TileKill:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 4);
                     if (TShock.Regions.CanBuild(X, Y, TShock.Players[index]) && Main.tile[X, Y].type == 21)
                     {
                         if (Main.tile[X, Y].frameY != 0)
                         {
                             Y--;
                         }
                         if (Main.tile[X, Y].frameX % 36 != 0)
                         {
                             X--;
                         }
                         KillChest(X, Y, index);
                         TShock.Players[index].SendTileSquare(X, Y, 3);
                         e.Handled = true;
                     }
                 }
                 break;
         }
     }
 }
Esempio n. 8
0
        public void OnGetData(GetDataEventArgs args)
        {
            if (args.Msg.whoAmI == player.Index)
            {
                if (args.MsgID == PacketTypes.NpcStrike)
                {
                    MemoryStream data = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length);
                    int npcID = data.ReadInt16();
                    int damage = data.ReadInt16();
                    if (Main.npc[npcID].life - damage <= 0)
                    {
                        if (toBeKilled.ContainsKey(Main.npc[npcID].name))
                            toBeKilled[Main.npc[npcID].name] -= 1;

                        if (toBeKilled[Main.npc[npcID].name] <= 0)
                            toBeKilled.Remove(Main.npc[npcID].name);
                    }
                }
            }
        }
        public void GetData(GetDataEventArgs e)
        {
            try
            {
                if (e.MsgID != PacketTypes.PlayerTeam || !(getConfig.LockRedTeam || getConfig.LockGreenTeam || getConfig.LockBlueTeam || getConfig.LockYellowTeam)) return;

                var who = e.Msg.readBuffer[e.Index];
                var team = e.Msg.readBuffer[e.Index + 1];

                var ePly = esPlayers[who];
                var tPly = TShock.Players[who];
                if (ePly == null || tPly == null) return;
                switch (team)
                {
                    #region Red
                    case 1:
                        if (getConfig.LockRedTeam && !tPly.Group.HasPermission(getConfig.RedTeamPermission) && (ePly.RedPassword != getConfig.RedTeamPassword || ePly.RedPassword == ""))
                        {
                            e.Handled = true;
                            tPly.SetTeam(tPly.Team);
                            if (getConfig.RedTeamPassword == "")
                                tPly.SendMessage("You do not have permission to join that team!", Color.Red);
                            else
                                tPly.SendMessage("That team is locked, use \'/teamunlock red <password>\' to access it.", Color.Red);

                        }
                        break;
                    #endregion

                    #region Green
                    case 2:
                        if (getConfig.LockGreenTeam && !tPly.Group.HasPermission(getConfig.GreenTeamPermission) && (ePly.GreenPassword != getConfig.GreenTeamPassword || ePly.GreenPassword == ""))
                        {
                            e.Handled = true;
                            tPly.SetTeam(tPly.Team);
                            if (getConfig.GreenTeamPassword == "")
                                tPly.SendMessage("You do not have permission to join that team!", Color.Red);
                            else
                                tPly.SendMessage("That team is locked, use \'/teamunlock green <password>\' to access it.", Color.Red);

                        }
                        break;
                    #endregion

                    #region Blue
                    case 3:
                        if (getConfig.LockBlueTeam && !tPly.Group.HasPermission(getConfig.BlueTeamPermission) && (ePly.BluePassword != getConfig.BlueTeamPassword || ePly.BluePassword == ""))
                        {
                            e.Handled = true;
                            tPly.SetTeam(tPly.Team);
                            if (getConfig.BlueTeamPassword == "")
                                tPly.SendMessage("You do not have permission to join that team!", Color.Red);
                            else
                                tPly.SendMessage("That team is locked, use \'/teamunlock blue <password>\' to access it.", Color.Red);

                        }
                        break;
                    #endregion

                    #region Yellow
                    case 4:
                        if (getConfig.LockYellowTeam && !tPly.Group.HasPermission(getConfig.YellowTeamPermission) && (ePly.YellowPassword != getConfig.YellowTeamPassword || ePly.YellowPassword == ""))
                        {
                            e.Handled = true;
                            tPly.SetTeam(tPly.Team);
                            if (getConfig.YellowTeamPassword == "")
                                tPly.SendMessage("You do not have permission to join that team!", Color.Red);
                            else
                                tPly.SendMessage("That team is locked, use \'/teamunlock yellow <password>\' to access it.", Color.Red);

                        }
                        break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Log.Error("[Essentials] Team Lock Exception:");
                Log.Error(ex.ToString());
            }
        }
        void OnGetData(GetDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.PlayerHp)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var playerID = reader.ReadByte();
                    var theHP = reader.ReadInt16();
                    var theMaxHP = reader.ReadInt16();
                    if (isHeal[playerID])
                    {

                        Item heart = TShockAPI.TShock.Utils.GetItemById(58);
                        Item star = TShockAPI.TShock.Utils.GetItemById(184);
                        if (theHP <= theMaxHP / 2)
                        {

                            for (int i = 0; i < 20; i++)
                                TShock.Players[playerID].GiveItem(heart.type, heart.name, heart.width, heart.height, heart.maxStack);
                            for (int i = 0; i < 10; i++)
                                TShock.Players[playerID].GiveItem(star.type, star.name, star.width, star.height, star.maxStack);
                            TShock.Players[playerID].SendMessage("You just got healed!");
                        }

                    }

                }

            }
            else if (e.MsgID == PacketTypes.PlayerMana)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var playerID = reader.ReadByte();
                    var theMana = reader.ReadInt16();
                    var theMaxMana = reader.ReadInt16();
                    if (isHeal[playerID])
                    {

                        Item heart = TShockAPI.TShock.Utils.GetItemById(58);
                        Item star = TShockAPI.TShock.Utils.GetItemById(184);
                        if (theMana <= theMaxMana / 2)
                        {

                            for (int i = 0; i < 20; i++)
                                TShock.Players[playerID].GiveItem(heart.type, heart.name, heart.width, heart.height, heart.maxStack);
                            for (int i = 0; i < 10; i++)
                                TShock.Players[playerID].GiveItem(star.type, star.name, star.width, star.height, star.maxStack);
                            TShock.Players[playerID].SendMessage("You just got healed!");
                        }

                    }

                }

            }
            else if (e.MsgID == PacketTypes.PlayerDamage)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var ply = reader.ReadByte();
                    var hitDirection = reader.ReadByte();
                    var damage = reader.ReadInt16();
                    if ((damage > maxDamage || damage < 0) && !TShock.Players[e.Msg.whoAmI].Group.HasPermission("ignorecheatdetection") && e.Msg.whoAmI != ply)
                    {

                        if (maxDamageBan)
                        {

                            TShockAPI.TShock.Utils.Ban(TShock.Players[e.Msg.whoAmI], "You have exceeded the max damage limit.");

                        }
                        else if (maxDamageKick)
                        {

                            TShockAPI.TShock.Utils.Kick(TShock.Players[e.Msg.whoAmI], "You have exceeded the max damage limit.");

                        }
                        if (maxDamageIgnore)
                        {

                            e.Handled = true;

                        }

                    }
                    if (viewAll[ply])
                    {

                        e.Handled = true;

                    }

                }

            }
            else if (e.MsgID == PacketTypes.NpcStrike)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var npcID = reader.ReadInt16();
                    var damage = reader.ReadInt16();
                    if ((damage > maxDamage || damage < 0) && !TShock.Players[e.Msg.whoAmI].Group.HasPermission("ignorecheatdetection"))
                    {

                        if (maxDamageBan)
                        {

                            TShockAPI.TShock.Utils.Ban(TShock.Players[e.Msg.whoAmI], "You have exceeded the max damage limit.");

                        }
                        else if (maxDamageKick)
                        {

                            TShockAPI.TShock.Utils.Kick(TShock.Players[e.Msg.whoAmI], "You have exceeded the max damage limit.");

                        }
                        if (maxDamageIgnore)
                        {

                            e.Handled = true;

                        }

                    }

                }

            }
            else if (e.MsgID == PacketTypes.DoorUse)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var Closed = reader.ReadBoolean();
                    var TileX = reader.ReadInt32();
                    var TileY = reader.ReadInt32();
                    if (!Closed)
                    {

                        if (Main.tile[TileX - 1, TileY].type == 10 || Main.tile[TileX + 1, TileY].type == 10)
                        {

                            e.Handled = true;

                        }

                    }

                }

            }
            else if (e.MsgID == PacketTypes.PlayerTeam)
            {

                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var ply = reader.ReadByte();
                    var team = reader.ReadByte();
                    switch (team)
                    {

                        case 1: if ((!accessRed[ply]) && (TShock.Players[ply].Group.Name != "superadmin"))
                            {

                                e.Handled = true;
                                TShock.Players[ply].SendMessage("This team is locked, use /teamunlock red password to access it.", Color.Red);
                                TShock.Players[ply].SetTeam(TShock.Players[ply].Team);

                            } break;
                        case 2: if ((!accessGreen[ply]) && (TShock.Players[ply].Group.Name != "superadmin"))
                            {

                                e.Handled = true;
                                TShock.Players[ply].SendMessage("This team is locked, use /teamunlock green password to access it.", Color.Red);
                                TShock.Players[ply].SetTeam(TShock.Players[ply].Team);

                            } break;
                        case 3: if ((!accessBlue[ply]) && (TShock.Players[ply].Group.Name != "superadmin"))
                            {

                                e.Handled = true;
                                TShock.Players[ply].SendMessage("This team is locked, use /teamunlock blue password to access it.", Color.Red);
                                TShock.Players[ply].SetTeam(TShock.Players[ply].Team);

                            } break;
                        case 4: if ((!accessYellow[ply]) && (TShock.Players[ply].Group.Name != "superadmin"))
                            {

                                e.Handled = true;
                                TShock.Players[ply].SendMessage("This team is locked, use /teamunlock yellow password to access it.", Color.Red);
                                TShock.Players[ply].SetTeam(TShock.Players[ply].Team);

                            } break;

                    }

                }

            }
        }
Esempio n. 11
0
        public void GetData(GetDataEventArgs e)
        {
            try
            {
                switch (e.MsgID)
                {
                    case PacketTypes.PlayerTeam:
                        using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                        {
                            var reader = new BinaryReader(data);
                            var play = reader.ReadByte();
                            var team = reader.ReadByte();
                            reader.Close();
                            esPlayer ply = GetesPlayerByID(play);
                            var tply = TShock.Players[play];
                            if (ply == null || tply == null) return;
                            switch (team)
                            {

                                case 1: if (((getConfig.UsePermissonsForTeams && !tply.Group.HasPermission("jointeamred")) || (!getConfig.UsePermissonsForTeams && ply.redpass != getConfig.RedPassword)) && tply.Group.Name != "superadmin")
                                    {

                                        e.Handled = true;
                                        if (getConfig.UsePermissonsForTeams)
                                            tply.SendMessage("You do not have permission to join this team.", Color.Red);
                                        else
                                            tply.SendMessage("This team is locked, use /teamunlock red <password> to access it.", Color.Red);
                                        tply.SetTeam(tply.Team);

                                    } break;
                                case 2: if (((getConfig.UsePermissonsForTeams && !tply.Group.HasPermission("jointeamgreen")) || (!getConfig.UsePermissonsForTeams && ply.greenpass != getConfig.GreenPassword)) && tply.Group.Name != "superadmin")
                                    {

                                        e.Handled = true;
                                        if (getConfig.UsePermissonsForTeams)
                                            tply.SendMessage("You do not have permission to join this team.", Color.Red);
                                        else
                                            tply.SendMessage("This team is locked, use /teamunlock green <password> to access it.", Color.Red);
                                        tply.SetTeam(tply.Team);

                                    } break;
                                case 3: if (((getConfig.UsePermissonsForTeams && !tply.Group.HasPermission("jointeamblue")) || (!getConfig.UsePermissonsForTeams && ply.bluepass != getConfig.BluePassword)) && tply.Group.Name != "superadmin")
                                    {

                                        e.Handled = true;
                                        if (getConfig.UsePermissonsForTeams)
                                            tply.SendMessage("You do not have permission to join this team.", Color.Red);
                                        else
                                            tply.SendMessage("This team is locked, use /teamunlock blue <password> to access it.", Color.Red);
                                        tply.SetTeam(tply.Team);

                                    } break;
                                case 4: if (((getConfig.UsePermissonsForTeams && !tply.Group.HasPermission("jointeamyellow")) || (!getConfig.UsePermissonsForTeams && ply.yellowpass != getConfig.YellowPassword)) && tply.Group.Name != "superadmin")
                                    {

                                        e.Handled = true;
                                        if (getConfig.UsePermissonsForTeams)
                                            tply.SendMessage("You do not have permission to join this team.", Color.Red);
                                        else
                                            tply.SendMessage("This team is locked, use /teamunlock yellow <password> to access it.", Color.Red);
                                        tply.SetTeam(tply.Team);

                                    } break;

                            }
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                Log.Error("[Essentials] Error with team lock: ");
                Log.Error(ex.ToString());
            }
        }
Esempio n. 12
0
        private void OnGetData(GetDataEventArgs e)
        {
            if ((e.MsgID == PacketTypes.Tile) || (e.MsgID == PacketTypes.TileKill))
            {

                if (awaitingPoint[e.Msg.whoAmI] != 0)
                {

                    List<Point> tempTempPoint = getTempOutline(tempPoints[e.Msg.whoAmI]);
                    /*switch (tempPoints[e.Msg.whoAmI].Count())
                    {

                        case 1: updateTile(tempPoints[e.Msg.whoAmI][0].X, tempPoints[e.Msg.whoAmI][0].Y);

                    }*/
                    using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                    {
                        var reader = new BinaryReader(data);
                        byte action = reader.ReadByte();
                        int tilex = reader.ReadInt32();
                        int tiley = reader.ReadInt32();
                        if (awaitingPoint[e.Msg.whoAmI] <= -1)
                        {

                            tempPoints[e.Msg.whoAmI].Add(new Point(tilex, tiley));
                            TShock.Players[e.Msg.whoAmI].SendMessage("Point #" + tempPoints[e.Msg.whoAmI].Count().ToString() + " set.");

                        }
                        else if (awaitingPoint[e.Msg.whoAmI] - 1 < tempPoints[e.Msg.whoAmI].Count())
                        {

                            try
                            {
                                tempPoints[e.Msg.whoAmI][awaitingPoint[e.Msg.whoAmI] - 1] = new Point(tilex, tiley);
                                TShock.Players[e.Msg.whoAmI].SendMessage("Point #" + awaitingPoint[e.Msg.whoAmI].ToString() + " set.");
                                awaitingPoint[e.Msg.whoAmI] = 0;
                            }
                            catch (Exception)
                            {
                                TShock.Players[e.Msg.whoAmI].SendMessage("There has been an error, please try entering in the /tile set command again.", Color.Red);
                                awaitingPoint[e.Msg.whoAmI] = 0;
                                NetMessage.SendTileSquare(e.Msg.whoAmI, tilex, tiley, 1);
                            }

                        }
                        else if (awaitingPoint[e.Msg.whoAmI] - 1 == tempPoints[e.Msg.whoAmI].Count())
                        {

                            tempPoints[e.Msg.whoAmI].Add(new Point(tilex, tiley));
                            TShock.Players[e.Msg.whoAmI].SendMessage("Point #" + awaitingPoint[e.Msg.whoAmI].ToString() + " set.");
                            awaitingPoint[e.Msg.whoAmI] = 0;

                        }
                        else
                        {

                            TShock.Players[e.Msg.whoAmI].SendMessage("There has been an error, please try entering in the /tile set command again.", Color.Red);
                            awaitingPoint[e.Msg.whoAmI] = 0;
                            NetMessage.SendTileSquare(e.Msg.whoAmI, tilex, tiley, 1);

                        }
                        refreshTempTiles(e.Msg.whoAmI, tempTempPoint);

                    }
                    e.Handled = true;
                }

            }
        }
Esempio n. 13
0
        private void OnGetData(GetDataEventArgs e)
        {
            if (e.Handled)
                return;

            PacketTypes type = e.MsgID;

            Debug.WriteLine("Recv: {0:X}: {2} ({1:XX})", e.Msg.whoAmI, (byte)type, type);

            var player = Players[e.Msg.whoAmI];
            if (player == null)
            {
                e.Handled = true;
                return;
            }

            if (!player.ConnectionAlive)
            {
                e.Handled = true;
                return;
            }

            // Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions)
            if (player.TileThreshold >= Config.TileThreshold && !player.Group.HasPermission(Permissions.ignorekilltiledetection))
            {
                e.Handled = true;
            }
            else
            {
                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    try
                    {
                        if (GetDataHandlers.HandlerGetData(type, player, data))
                            e.Handled = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
            }
        }
 private void OnGetData(GetDataEventArgs e)
 {
     if (e.MsgID == PacketTypes.NpcStrike)
     {
         using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
         {
             var reader = new BinaryReader(data);
             var npcid = reader.ReadInt16();
             var dmg = reader.ReadInt16();
             var knockback = reader.ReadSingle();
             var direction = reader.ReadByte();
             var crit = reader.ReadBoolean();
             int critmultiply = 1;
             if (crit)
                 critmultiply = 2;
             int actualdmg = (dmg - Main.npc[npcid].defense / 2) * critmultiply;
             if (actualdmg < 0)
                 actualdmg = 1;
             if (actualdmg >= Main.npc[npcid].life && Main.npc[npcid].life > 0 && Main.npc[npcid].active)
             {
                 CustomMonster DeadMonster = CustomMonsters.Find(monster => monster.ID == npcid);
                 if (DeadMonster != null)
                 {
                     if (DeadMonster.CMType.MultiplyOnDeath)
                     {
                         int killer = e.Msg.whoAmI;
                         int monstersplit = SpawnCustomMonsterExactPosition(DeadMonster.CMType, TShock.Players[killer].TileX + 1, TShock.Players[killer].TileY, (DeadMonster.MODLevel + 1));
                         int monstersplit2 = SpawnCustomMonsterExactPosition(DeadMonster.CMType, TShock.Players[killer].TileX + 2, TShock.Players[killer].TileY, (DeadMonster.MODLevel + 1));
                     }
                 }
             }
             return;
         }
     }
 }
Esempio n. 15
0
 void OnGetData(GetDataEventArgs e)
 {
     _lHooks.OnGetData(e);
 }
Esempio n. 16
0
 public static void GetData(GetDataEventArgs e)
 {
     try
     {
         if (e.MsgID == PacketTypes.PlayerUpdate)
         {
             byte plyID = e.Msg.readBuffer[e.Index];
             byte flags = e.Msg.readBuffer[e.Index + 1];
             bool up = false;
             bool down = false;
             bool space = false;
             if ((flags & 1) == 1)
                 up = true;
             if ((flags & 2) == 2)
                 down = true;
             if ((flags & 16) == 16)
                 space = true;
             var player = PlayerList[plyID];
             if (player != null)
             {
                 if (player.InMenu)  // HANDLE MENU NAVIGATION
                 {
                     if (up && down)
                     {
                         player.Menu.Close();
                         e.Handled = true;
                         return;
                     }
                     if (up)
                     {
                         player.Menu.MoveUp();
                         e.Handled = true;
                     }
                     if (down)
                     {
                         player.Menu.MoveDown();
                         e.Handled = true;
                     }
                     if (space)
                     {
                         player.Menu.Select();
                         e.Handled = true;
                     }
                 }
                 else
                 {
                     if (up && down) // Show main menu
                     {
                         Menu.DisplayMainMenu(player);
                     }
                 }
             }
         }
     }
     catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
 }
Esempio n. 17
0
 void onGetData(GetDataEventArgs e)
 {
     try
     {
         if (e.MsgID == PacketTypes.TileGetSection && e.Handled == false)
         {
             LastJoinIndex = e.Msg.whoAmI;
         }
     }
     catch { }
 }
Esempio n. 18
0
        private void GetData(GetDataEventArgs e)
        {
            PacketTypes type = e.MsgID;
            var player = TShock.Players[e.Msg.whoAmI];
            if (player == null)
            {
                e.Handled = true;
                return;
            }

            if (!player.ConnectionAlive)
            {
                e.Handled = true;
                return;
            }

            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
            {
                try
                {
                    if (GetDataHandlers.HandlerGetData(type, player, data))
                        e.Handled = true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
        }
Esempio n. 19
0
        public static void GetData(GetDataEventArgs e)
        {
            try
            {
                switch (e.MsgID)
                {
                    #region Item Drop
                    case PacketTypes.ItemDrop:
                        {
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                int itemID = reader.ReadInt16();
                                float posX = reader.ReadSingle();
                                float posY = reader.ReadSingle();
                                float velX = reader.ReadSingle();
                                float velY = reader.ReadSingle();
                                byte stacks = reader.ReadByte();
                                byte prefix = reader.ReadByte();
                                int type = reader.ReadInt16();
                                reader.Dispose();
                                //Console.WriteLine("ItemUpdate: id: {0}, posx: {1}, posy: {2}, velX: {3}, velY: {4}, stack: {5}, prefix: {6}, type: {7}", itemID, posX, posY, velX, velY, stacks, prefix, type);
                                var player = PlayerList[e.Msg.whoAmI];
                                if (player != null)
                                {
                                    if (player.changingMoney && type == 73)
                                    {
                                        int gainpower = stacks * 2;
                                        bool converted = false;
                                        if (gainpower + player.Power > 100)
                                        {
                                            int realgain = 100 - player.Power;
                                            int extragain = gainpower - realgain;
                                            if (realgain != 0 && player.ChangePower(realgain))
                                            {
                                                if (extragain % 2 != 0) // drop 50 silver
                                                {
                                                    extragain--;
                                                    int silverid = Item.NewItem((int)posX, (int)posY, 1, 1, 72, 50, true, 0);
                                                    NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, "", silverid);
                                                }
                                                if (extragain > 0) // drop extra gold
                                                {
                                                    int goldid = Item.NewItem((int)posX, (int)posY, 1, 1, 73, (int)(extragain / 2), true, 0);
                                                    NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, "", goldid);
                                                }
                                                converted = true;
                                                player.changingMoney = false;
                                                gainpower = realgain;
                                            }
                                        }
                                        else if (player.ChangePower(gainpower))
                                            converted = true;
                                        if (converted)
                                        {
                                            e.Handled = true;
                                            if (player.Menu != null)
                                            {
                                                var convtext = player.Menu.GetItemByValue(410);
                                                if (convtext != null)
                                                    convtext.Text = String.Format("> Converted {0} gold into {1} power", gainpower / 2, gainpower);
                                                else
                                                    player.Menu.contents.Insert(3, new MenuItem(String.Format("> Converted {0} gold into {1} power", gainpower / 2, gainpower), 410, false, Color.DarkGreen));
                                                player.Menu.index = 3;
                                                player.Menu.DisplayMenu();
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    #endregion
                    #region Player Update
                    case PacketTypes.PlayerUpdate:
                        {
                            byte plyID, flags;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                plyID = reader.ReadByte();
                                flags = reader.ReadByte();
                                reader.Close();
                                reader.Dispose();
                            }
                            var player = PlayerList[plyID];
                            if (player != null)
                            {
                                if (player.LastState != flags)
                                {
                                    player.LastState = flags;
                                    player.IdleCount = 0;
                                }
                                if ((flags & 32) == 32)
                                    player.CloseMenu();
                            }
                            break;
                        }
                    #endregion
                    #region Tile Edit
                    case PacketTypes.Tile:
                        {
                            byte type, tileType, style;
                            Int32 x, y;
                            bool fail;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                type = reader.ReadByte();
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                tileType = reader.ReadByte();
                                fail = reader.ReadBoolean();
                                style = reader.ReadByte();
                                reader.Close();
                                reader.Dispose();
                            }
                            //    Console.WriteLine("Tileinfo: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.type, tile.frameX, tile.frameY, tile.frameNumber);
                            //   Console.WriteLine("Tiledata: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.Data.type, tile.Data.frameX, tile.Data.frameY, tile.Data.frameNumber);
                            //    Console.WriteLine("type: {0}, Main.tile[].active: {1}, fail: {2}", type, Main.tile[x, y].Data.active, fail);

                            var player = PlayerList[e.Msg.whoAmI];
                            if (player == null)
                                return;

                            if (y < Main.worldSurface)
                            {
                                if (Main.tile[x, y].type == 5)
                                {
                                    if (tileType == 0 && Main.tile[x, y + 1].type == 2)
                                    {
                                        e.Handled = true;
                                        WorldGen.KillTile(x, y);
                                        Main.tile[x, y].type = 20;
                                        WorldGen.PlaceTile(x, y, 20, false, true);
                                        TSPlayer.All.SendTileSquare(x, y, 6);
                                    }
                                }
                                else if (!new int[] { 3, 24, 28, 32, 37, 51, 52, 61, 62, 69, 71, 73, 74, 80, 81, 82, 83, 84, 85, 110, 113, 115, 138 }.Contains(Main.tile[x, y].type))
                                {
                                    var perm = CanBuild(player, new Point(x, y));
                                    if (perm < 0)
                                    {
                                        e.Handled = true;
                                        //player.TSplayer.SendMessage("You can't build on the surface unless you claim the land");
                                        if (perm == -2)
                                        {
                                            player.TSplayer.SendTileSquare(x, y, 4);
                                            player.TSplayer.Disable("tileedit in someone's region");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (CanBuild(player, new Point(x, y)) < 0)
                                {
                                    e.Handled = true;
                                    player.TSplayer.SendTileSquare(x, y, 4);
                                    player.TSplayer.SendMessage("You can't build on this land, it does not belong to you.");
                                    player.TSplayer.Disable("tileedit in someone's region");
                                }
                            }
                            break;
                        }
                    #endregion
                    #region Liquid set
                    case PacketTypes.LiquidSet:
                        {
                            int x, y;
                            byte liquid;
                            //bool lava;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                liquid = reader.ReadByte();
                                //lava = reader.ReadBoolean();
                                reader.Close();
                                reader.Dispose();
                            }
                            //Console.WriteLine("(GetData) Liquid set: x:{0} y:{1} liquid:{2}", x, y, liquid);
                            var player = PlayerList[e.Msg.whoAmI];
                            if (player == null)
                                return;
                            if (CanBuild(player, new Point(x, y)) < 0)
                            {
                                e.Handled = true;
                                player.TSplayer.SendTileSquare(x, y, 4);
                                player.TSplayer.SendMessage("You cannot use bucket in this region");
                                player.TSplayer.Disable("using bucket in no-build zone");
                            }
                            break;
                        }
                    #endregion
                    #region Chest kill
                    case PacketTypes.TileKill:
                        {
                            int x, y;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                reader.Close();
                                reader.Dispose();
                            }
                            var player = PlayerList[e.Msg.whoAmI];
                            if (player == null)
                                break;
                            if (CanBuild(player, new Point(x, y)) < 0)
                            {
                                e.Handled = true;
                                player.TSplayer.SendMessage("You cannot remove this chest");
                                player.TSplayer.Disable("trying to remove chest");
                                player.TSplayer.SendTileSquare(x, y, 4);
                            }
                            break;
                        }
                    #endregion
                    #region Player damage
                    case PacketTypes.PlayerDamage:
                        {
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                var pID = reader.ReadByte();
                                var hitDirection = reader.ReadByte();
                                var dmg = reader.ReadInt16();
                                var PVP = reader.ReadByte();
                                //var crit = reader.ReadByte();
                                //var death = reader.ReadBytes(e.Msg.messageLength - 6);
                                //var deathtext = Encoding.UTF8.GetString(death);
                                //Console.WriteLine("PlayerDamage: pID: {0}, e.whoami: {1}, PVP: {2}", pID, e.Msg.whoAmI, PVP);
                                if (PVP == 1)
                                {
                                    try
                                    {
                                        var player = PlayerList[pID];
                                        var attacker = PlayerList[e.Msg.whoAmI];
                                        if (player != null)
                                        {
                                            if (player.Faction != null && player.Faction.InFactionTerritory(new Point(player.TSplayer.TileX, player.TSplayer.TileY)))
                                            {
                                                if (attacker.Faction == null || (!attacker.Faction.Enemies.Contains(player.Faction.ID) && !player.Faction.Enemies.Contains(attacker.Faction.ID)))
                                                {
                                                    e.Handled = true;
                                                    attacker.TSplayer.SendMessage(String.Format("You cannot attack {0} in their faction territory unless your faction declares war.", player.TSplayer.Name), Color.LightSalmon);
                                                    attacker.TSplayer.Disable("PvP on neutral facton grounds");
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
                                }
                                //Console.WriteLine("deathtext: {0}", deathtext);
                                //e.Handled = true;
                            }
                            break;
                        }
                    #endregion
                    #region Player Death
                    case PacketTypes.PlayerKillMe:
                        {
                            byte pID, hitDirection;
                            //Int16 dmg;
                           // bool PVP;
                           // byte[] death;
                            //string deathtext;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                pID = reader.ReadByte();
                                hitDirection = reader.ReadByte();
                                //dmg = reader.ReadInt16();
                                //PVP = reader.ReadBoolean();
                                //death = reader.ReadBytes(e.Msg.messageLength - 5);
                                //deathtext = Encoding.UTF8.GetString(death);
                                reader.Close();
                                reader.Dispose();
                            }
                            var player = PlayerList[pID];
                            if (player != null)
                            {
                                player.ChangePower(-1);
                            }
                            // Console.WriteLine("PlayerKillMe: who: {0}, dir: {1}, dmg: {2}, PVP: {3}, e.msg.whoami: {4}", pID, hitDirection, dmg, PVP, e.Msg.whoAmI);
                            //Console.WriteLine("deathtext: {0}", deathtext);
                            break;
                        }
                    #endregion
                    #region Player Team change
                    case PacketTypes.PlayerTeam:
                        {
                            if (e.Handled)
                                return;
                            byte pID, teamID;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                pID = reader.ReadByte();
                                teamID = reader.ReadByte();
                                reader.Close();
                                reader.Dispose();
                            }
                            try
                            {
                                var player = PlayerList[pID];
                                if (player != null)
                                {
                                    if (player.Faction != null)
                                    {
                                        player.TSplayer.SendMessage("You cannot change team while in Faction.", Color.LightSalmon);
                                        player.TSplayer.TPlayer.team = player.Faction.Team;
                                        player.TSplayer.SendData(PacketTypes.PlayerTeam, "", player.ID);
                                        e.Handled = true;
                                    }
                                    /*else
                                    {
                                        player.TSplayer.TPlayer.team = teamID;
                                        NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, "", player.ID);
                                    }
                                    e.Handled = true;*/
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.ConsoleError(ex.ToString());
                                Log.ConsoleError(String.Format("playerID: {0}", pID));
                            }
                            break;
                        }
                    #endregion
                    #region Player PVP toggle
                    case PacketTypes.TogglePvp:
                        {
                            byte pID;
                            bool pvp;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                pID = reader.ReadByte();
                                pvp = reader.ReadBoolean();
                                reader.Close();
                                reader.Dispose();
                            }
                            var player = PlayerList[pID];
                            if (player != null && player.Faction != null)
                            {
                                if (!pvp && player.Faction.Hostile)
                                {
                                    player.TSplayer.TPlayer.hostile = true;
                                    player.TSplayer.SendMessage("You cannot turn off your PvP, your Faction status is Hostile.", Color.LightSalmon);
                                    player.TSplayer.SendData(PacketTypes.TogglePvp, "", e.Msg.whoAmI);
                                    e.Handled = true;
                                }
                                else if (pvp && !player.Faction.Hostile)
                                {
                                    player.TSplayer.TPlayer.hostile = false;
                                    player.TSplayer.SendMessage("You cannot turn on your PvP, your Faction status is Peaceful.", Color.LightSalmon);
                                    player.TSplayer.SendData(PacketTypes.TogglePvp, "", e.Msg.whoAmI);
                                    e.Handled = true;
                                }
                            }
                            break;
                        }
                    #endregion
                    case PacketTypes.Status:
                        {
                            Int32 Number;
                            String Status;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                Number = reader.ReadInt32();
                                Status = Encoding.UTF8.GetString(reader.ReadBytes(e.Msg.messageLength - 4));
                                reader.Close();
                                reader.Dispose();
                            }
                            Console.WriteLine("(Get Data) Status: number: {0}, text: {1}", Number, Status);
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                Log.ConsoleError(ex.ToString());
            }
        }
Esempio n. 20
0
        private void ParseData( GetDataEventArgs args )
        {
            try
            {
                PacketTypes packet = args.MsgID;
                using (var data = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length))
                {
                    TSPlayer player = TShock.Players[args.Msg.whoAmI];
                    var name = player.Name;
                    if (player.IsLoggedIn)
                    {
                        name = player.UserAccountName;
                    }
                    switch (packet)
                    {
                        case PacketTypes.Tile:
                            {
                                byte type = data.ReadInt8();
                                int x = data.ReadInt32();
                                int y = data.ReadInt32();
                                bool fail = true;
                                Action act;

                if (type == 0 || type == 2 || type == 4)
                                    act = Action.BREAK;
                                else if (type == 1 || type == 3)
                                    act = Action.PLACE;
                                else
                                    act = Action.ERROR;

                                byte tileType = 0;

                                if (act == Action.BREAK)
                                {
                                    tileType = Main.tile[x, y].type;
                                    fail = data.ReadBoolean();
                                }
                                else if (act == Action.PLACE)
                                {
                                    tileType = data.ReadInt8();
                                    fail = false;
                                }
                                if (act != Action.ERROR && !fail)
                                {
                                    TileEvent evt = new TileEvent(x, y, name, player.IP, act, tileType,
                                                                  LogTile.helper.GetTime());
                                    queue.Enqueue(evt);
                                }
                                break;
                            }
                        case PacketTypes.TileKill:
                            {
                                int x = data.ReadInt32();
                                int y = data.ReadInt32();
                                TileEvent evt = new TileEvent(x, y, name, player.IP, Action.BREAK, 0x15,
                                                              LogTile.helper.GetTime());
                                queue.Enqueue(evt);
                                break;
                            }
            //case PacketTypes.ChestOpen:
            //  {
            //    int chestID = data.ReadInt16();
            //    int x = data.ReadInt32();
            //    int y = data.ReadInt32();
            //    int curChest = 0;
            //    if (!chestMap.TryGetValue(player, out curChest)) // chest being opened
            //    {
            //      //Console.WriteLine( string.Format( "Open:{0}: cId:{1}:", player.Name, chestID ) );
            //      if ( chestID > 0 )  // sometimes, this gets called right after a close
            //      {
            //        chestMap.Add(player, chestID);
            //        itemMap.Add(player, Main.chest[chestID].item);
            //      } // if
            //    }
            //    else // chest is being closed
            //    {
            //      //Console.WriteLine( "Closing: " + player.Name );
            //      chestMap.Remove(player);
            //      itemMap.Remove(player);
            //    }

            //    break;
            //  }
            //case PacketTypes.ChestItem:
            //  {
            //    int chestID = data.ReadInt16();
            //    byte itemSlot = data.ReadInt8();
            //    byte stack = data.ReadInt8();
            //    int curChest = 0;
            //    int type = itemMap[player][itemSlot].type;
            //    if (LogTile.enableDebugOutput)									Console.WriteLine(type);
            //    Item[] curItems = Main.chest[chestID].item;
            //    if (LogTile.enableDebugOutput)									Console.WriteLine(curItems[itemSlot].type);
            //    //Console.WriteLine( "Chest item: " + player.Name );
            //    itemMap.Remove(player);
            //    itemMap.Add(player, curItems);
            //    break;
            //  }
            //case PacketTypes.ChestGetContents:
            //  {
            //    int x = data.ReadInt32();
            //    int y = data.ReadInt32();
            //    if (LogTile.enableDebugOutput)
            //      Console.WriteLine("GETChestContents: (" + x + ", " + y + ")");
            //    break;
            //  }
            //case PacketTypes.SignNew:
            //  {
            //    int id = data.ReadInt16();
            //    int x = data.ReadInt32();
            //    int y = data.ReadInt32();
            //    string text = data.ReadString();
            //    break;
            //  }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine( e.Message + " (" + e.StackTrace + ")" );
            }
        }
Esempio n. 21
0
 private static void NetHooks_GetData(GetDataEventArgs e)
 {
     if (Main.netMode != 2)
     {
         return;
     }
     if (e.MsgID == PacketTypes.ConnectRequest)
     {
         e.Handled = ServerHooks.OnConnect(e.Msg.whoAmI);
         if (e.Handled)
         {
             Netplay.serverSock[e.Msg.whoAmI].kill = true;
             return;
         }
     }
     else if (e.MsgID == PacketTypes.ContinueConnecting2)
     {
         e.Handled = ServerHooks.OnJoin(e.Msg.whoAmI);
         if (e.Handled)
         {
             Netplay.serverSock[e.Msg.whoAmI].kill = true;
             return;
         }
     }
     else
     {
         if (e.MsgID == PacketTypes.ChatText)
         {
             string @string = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 4, e.Length - 5);
             e.Handled = ServerHooks.OnChat(e.Msg, e.Msg.whoAmI, @string);
         }
     }
 }
Esempio n. 22
0
        private void OnGetData(GetDataEventArgs e)
        {
            if (e.Handled)
                return;

            PacketTypes type = e.MsgID;

            Debug.WriteLine("Recv: {0:X}: {2} ({1:XX})", e.Msg.whoAmI, (byte) type, type);

            var player = Players[e.Msg.whoAmI];
            if (player == null)
            {
                e.Handled = true;
                return;
            }

            if (!player.ConnectionAlive)
            {
                e.Handled = true;
                return;
            }

            if (player.RequiresPassword && type != PacketTypes.PasswordSend)
            {
                e.Handled = true;
                return;
            }

            if ((player.State < 10 || player.Dead) && (int) type > 12 && (int) type != 16 && (int) type != 42 && (int) type != 50 &&
                (int) type != 38 && (int) type != 5 && (int) type != 21)
            {
                e.Handled = true;
                return;
            }

            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
            {
                try
                {
                    if (GetDataHandlers.HandlerGetData(type, player, data))
                        e.Handled = true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
        }
Esempio n. 23
0
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         switch (e.MsgID)
         {
             case PacketTypes.SignNew:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 2);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 6);
                     string text = Encoding.UTF8.GetString(e.Msg.readBuffer, e.Index + 10, e.Length - 11);
                     ModSign(X, Y, e.Msg.whoAmI, text);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.SignRead:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 4);
                     GetSign(X, Y, e.Msg.whoAmI);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.Tile:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
                     if (X < 0 || Y < 0 || X >= Main.maxTilesX || Y >= Main.maxTilesY)
                     {
                         return;
                     }
                     if (e.Msg.readBuffer[e.Index] == 0 && Main.tile[X, Y].IsSign())
                     {
                         if (SignHit != null)
                         {
                             Sign sign = null;
                             var signPos = Sign.GetSign(X, Y);
                             using (QueryResult reader = Database.QueryReader("SELECT Account, Text FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2", signPos.X, signPos.Y, Main.worldID))
                             {
                                 if (reader.Read())
                                     sign = new Sign { account = reader.Get<string>("Account"), text = reader.Get<string>("Text") };
                             }
                             if (sign != null)
                             {
                                 SignEventArgs signargs = new SignEventArgs(X, Y, sign.text, sign.account);
                                 SignHit(signargs);
                             }
                         }
                     }
                     if (e.Msg.readBuffer[e.Index] == 0 && e.Msg.readBuffer[e.Index + 9] == 0)
                     {
                         if (Sign.Nearby(X, Y))
                         {
                             KillSign(X, Y, e.Msg.whoAmI);
                             e.Handled = true;
                         }
                     }
                     else if (e.Msg.readBuffer[e.Index] == 1 && (e.Msg.readBuffer[e.Index + 9] == 55 || e.Msg.readBuffer[e.Index + 9] == 85))
                     {
                         if (TShock.Regions.CanBuild(X, Y, TShock.Players[e.Msg.whoAmI]))
                         {
                             WorldGen.PlaceSign(X, Y, e.Msg.readBuffer[e.Index + 9]);
                             if (Main.tile[X, Y].frameY != 0)
                             {
                                 Y--;
                             }
                             if (Main.tile[X, Y].frameX % 36 != 0)
                             {
                                 X--;
                             }
                             PlaceSign(X, Y, e.Msg.whoAmI);
                             e.Handled = true;
                         }
                     }
                 }
                 break;
         }
     }
 }
Esempio n. 24
0
        private void checkItemDrops(GetDataEventArgs args)
        {
            if (args.MsgID == PacketTypes.ItemDrop)
            {
                if (args.Handled)
                    return;

                using (var data = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length))
                {
                    Int16 id = data.ReadInt16();
                    float posx = data.ReadSingle();
                    float posy = data.ReadSingle();
                    float velx = data.ReadSingle();
                    float vely = data.ReadSingle();
                    int stack = data.ReadByte();
                    int prefix = data.ReadByte();
                    Int16 type = data.ReadInt16();

                    Item item = new Item();
                    item.SetDefaults(type);

                    if (id == 0)
                        return;

                    if (toBeCollected.ContainsKey(item.name))
                    {
                        toBeCollected[item.name] -= stack;

                        if (toBeCollected[item.name] < 0)
                        {
                            if (Math.Abs(toBeCollected[item.name]) > 1)
                                player.TSPlayer.SendInfoMessage(string.Format("Returning {0} {1}s", Math.Abs(toBeCollected[item.name]), item.name));
                            else
                                player.TSPlayer.SendInfoMessage(string.Format("Returning {0} {1}", Math.Abs(toBeCollected[item.name]), item.name));
                            args.Handled = true;
                            player.TSPlayer.GiveItem(item.type, item.name, item.width, item.width, Math.Abs(toBeCollected[item.name]));
                            toBeCollected.Remove(item.name);
                        }
                        else if (toBeCollected[item.name] > 0)
                        {
                             if (Math.Abs(toBeCollected[item.name]) > 1)
                                player.TSPlayer.SendInfoMessage(string.Format("Drop another {0} {1}s, to continue", Math.Abs(toBeCollected[item.name]), item.name));
                            else
                                player.TSPlayer.SendInfoMessage(string.Format("Drop {0} {1}, to continue", Math.Abs(toBeCollected[item.name]), item.name));
                            args.Handled = true;
                        }
                        else
                        {
                            if (stack > 1)
                                player.TSPlayer.SendInfoMessage(string.Format("You dropped {0} {1}s", stack, item.name));
                            else
                                player.TSPlayer.SendInfoMessage(string.Format("You dropped {0} {1}", stack, item.name));

                            toBeCollected.Remove(item.name);
                            args.Handled = true;
                        }
                    }
                    args.Handled = true;
                }
            }
        }
Esempio n. 25
0
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         switch (e.MsgID)
         {
             case PacketTypes.SignNew:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 2);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 6);
                     string text = Encoding.UTF8.GetString(e.Msg.readBuffer, e.Index + 10, e.Length - 11);
                     ModSign(X, Y, e.Msg.whoAmI, text);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.SignRead:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 4);
                     GetSign(X, Y, e.Msg.whoAmI);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.Tile:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
                     if (X < 0 || Y < 0 || X >= Main.maxTilesX || Y >= Main.maxTilesY)
                     {
                         return;
                     }
                     if (e.Msg.readBuffer[e.Index] == 0 && e.Msg.readBuffer[e.Index + 9] == 0)
                     {
                         if (Sign.Nearby(X, Y))
                         {
                             e.Handled = KillSign(X, Y, e.Msg.whoAmI);
                         }
                     }
                     else if (e.Msg.readBuffer[e.Index] == 1 && (e.Msg.readBuffer[e.Index + 9] == 55 || e.Msg.readBuffer[e.Index + 9] == 85))
                     {
                         if (TShock.Regions.CanBuild(X, Y, TShock.Players[e.Msg.whoAmI]))
                         {
                             WorldGen.PlaceSign(X, Y, e.Msg.readBuffer[e.Index + 9]);
                             NetMessage.SendData(17, -1, e.Msg.whoAmI, "", 1, X, Y, e.Msg.readBuffer[e.Index + 9]);
                             if (Main.tile[X, Y].frameY != 0)
                             {
                                 Y--;
                             }
                             if (Main.tile[X, Y].frameX % 36 != 0)
                             {
                                 X--;
                             }
                             PlaceSign(X, Y, e.Msg.whoAmI);
                             e.Handled = true;
                         }
                     }
                 }
                 break;
         }
     }
 }
Esempio n. 26
0
 public void OnGetData(GetDataEventArgs e)
 {
     try
     {
         if (e.MsgID == PacketTypes.PlayerUpdate)
         {
             byte plyID = e.Msg.readBuffer[e.Index];
             byte flags = e.Msg.readBuffer[e.Index + 1];
             var player = PlayerList[plyID];
             if (player != null && player.LastState != flags)
             {
                 player.LastState = flags;
                 player.IdleCount = 0;
             }
         }
     }
     catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
 }
Esempio n. 27
0
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled && e.MsgID == PacketTypes.Tile)
     {
         PlayerInfo info = Players[e.Msg.whoAmI];
         if (info.pt != 0)
         {
             int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
             int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
             if (X >= 0 && Y >= 0 && X < Main.maxTilesX && Y < Main.maxTilesY)
             {
                 if (info.pt == 1)
                 {
                     info.x = X;
                     info.y = Y;
                     TShock.Players[e.Msg.whoAmI].SendMessage(String.Format("Set point 1.", X, Y), Color.Yellow);
                 }
                 else
                 {
                     info.x2 = X;
                     info.y2 = Y;
                     TShock.Players[e.Msg.whoAmI].SendMessage(String.Format("Set point 2.", X, Y), Color.Yellow);
                 }
                 info.pt = 0;
                 e.Handled = true;
                 TShock.Players[e.Msg.whoAmI].SendTileSquare(X, Y, 3);
             }
         }
     }
 }
Esempio n. 28
0
        public void NetHooks_GetData(GetDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.NpcStrike)
            {
                using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                {
                    var reader = new BinaryReader(data);
                    var npcid = reader.ReadInt16();
                    var dmg = reader.ReadInt16();
                    var knockback = reader.ReadSingle();
                    var direction = reader.ReadByte();
                    var crit = reader.ReadBoolean();
                    if (Main.npc[npcid].target < 255)
                    {
                        if (TShock.Players[e.Msg.whoAmI].IsLoggedIn)
                        {
                            int critmultiply=1;
                            if(crit)
                                critmultiply = 2;
                            int actualdmg = (dmg - Main.npc[npcid].defense / 2) * critmultiply;
                            if (actualdmg < 0)
                                actualdmg = 1;
                            int TimeSpan = (int)(DateTime.Now - LastStrike[npcid]).TotalMilliseconds;
                            LastStrike[npcid] = DateTime.Now;
                            //if (TimeSpan>300 && actualdmg >= Main.npc[npcid].life && Main.npc[npcid].damage > 0 && Main.npc[npcid].lifeMax >= 10 && Main.npc[npcid].type != 68 && Main.npc[npcid].life > 0 && Main.npc[npcid].active)
                            if ( Main.npc[npcid].value!=0 && actualdmg >= Main.npc[npcid].life && Main.npc[npcid].damage > 0 && Main.npc[npcid].lifeMax >= 10 && Main.npc[npcid].type != 68 && Main.npc[npcid].life > 0 && Main.npc[npcid].active)
                            {
                                Random r = new Random();
                                int gained = (int)((0.29915 * Math.Pow((double)Main.npc[npcid].value, 0.5983)) < 1 ? 1 : (0.29915 * Math.Pow((double)Main.npc[npcid].value, 0.5983)));
                                int variance = r.Next() % ((gained / 10) + 1);
                                int gainedfinal = gained + variance;
                                EPREvents.MonsterPointAward(npcid, Main.npc[npcid].type, gainedfinal, GetEPRPlayerByIndex(e.Msg.whoAmI));
                                return;
                            }
                            else if (Main.npc[npcid].value != 0 && actualdmg < Main.npc[npcid].life && Main.npc[npcid].damage > 0 && Main.npc[npcid].lifeMax >= 10 && Main.npc[npcid].type != 68 && Main.npc[npcid].life > 0 && Main.npc[npcid].active)
                            {
                                if (EPRConfig.EnablePointShare)
                                {
                                    double dmgpct = (double)actualdmg / (double)Main.npc[npcid].lifeMax;
                                    List<Attacker> PrevAtk = ENPCs[npcid].Attackers.FindAll(item => item.attacker.Index == e.Msg.whoAmI);
                                    if (PrevAtk.Count == 0)
                                    {
                                        ENPCs[npcid].Attackers.Add(new Attacker(GetEPRPlayerByIndex(e.Msg.whoAmI), dmgpct));
                                    }
                                    else if (PrevAtk.Count > 0)
                                    {
                                        PrevAtk[0].DamageDealtPct += dmgpct;
                                    }
                                }
                            }
                            return;
                        }
                    }
                    return;
                }

            }
            if (e.MsgID == PacketTypes.PlayerKillMe)
            {
                if ((!TShock.Players[e.Msg.whoAmI].Group.HasPermission("reapersblessing") && !GetEPRPlayerByIndex(e.Msg.whoAmI).ReaperBless) || !ReapersBlessingEnabled)
                {
                    using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                    {
                        var reader = new BinaryReader(data);
                        var playerid = reader.ReadInt16();
                        var direction = reader.ReadByte();
                        var damage = reader.ReadInt16();
                        var pvp = reader.ReadBoolean();
                        if (TShock.Players[e.Msg.whoAmI].IsLoggedIn)
                        {
                            EPRPlayer player =  GetEPRPlayerByIndex(e.Msg.whoAmI);
                            int prevbal = player.Account;
                            float balanceflt = (prevbal * DeathToll) / 100;
                            int balance = (int)balanceflt - DeathTollStatic;
                            if (balance < 0)
                                balance = 0;
                            TShock.Players[e.Msg.whoAmI].SendMessage("You have lost " + (prevbal - balance).ToString() + " " + currname + "s!", Color.Red);
                            EPREvents.PointOperate(player, balance - prevbal, PointOperateReason.Death);
                        }
                    }
                }

            }
        }
Esempio n. 29
0
        private void NetHooks_GetData(GetDataEventArgs e)
        {
            switch (e.MsgID)
            {
                case PacketTypes.ChestGetContents:
                    if (!e.Handled)
                        using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                        {
                            var reader = new BinaryReader(data);
                            int x = reader.ReadInt32();
                            int y = reader.ReadInt32();
                            reader.Close();
                            int id = Terraria.Chest.FindChest(x, y);
                            CPlayer player = Players[e.Msg.whoAmI];
                            TPPlayer tplayer = tPulse.Players[e.Msg.whoAmI];
                            if (id != -1)
                            {
                                Chest chest = ChestManager.GetChest(id);
                                bool naggedAboutLock = false;

                                switch (player.GetState())
                                {
                                    case SettingState.Setting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                player.SendMessage("You already own this chest!", Color.Red);
                                            else
                                            {
                                                player.SendMessage("This chest is already owned by someone!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();

                                            player.SendMessage("This chest is now yours, and yours only.", Color.Red);
                                        }

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RegionSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                if (chest.IsRegionLocked())
                                                {
                                                    chest.regionLock(false);

                                                    player.SendMessage(
                                                        "Region share disabled. This chest is now only yours. To fully remove protection use \"cunset\".",
                                                        Color.Red);
                                                }
                                                else if (tPulse.Regions.InArea(x, y))
                                                {
                                                    chest.regionLock(true);

                                                    player.SendMessage(
                                                        "This chest is now shared between region users. Use this command again to disable it.",
                                                        Color.Red);
                                                }
                                                else
                                                    player.SendMessage(
                                                        "You can region share chest only if the chest is inside region!",
                                                        Color.Red);
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else if (tPulse.Regions.InArea(x, y))
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();
                                            chest.regionLock(true);

                                            player.SendMessage(
                                                "This chest is now shared between region users with you as owner. Use this command again to disable region sharing (You will still be owner).",
                                                Color.Red);
                                        }
                                        else
                                            player.SendMessage(
                                                "You can region share chest only if the chest is inside region!",
                                                Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PublicSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                if (chest.IsLocked())
                                                {
                                                    chest.UnLock();
                                                    player.SendMessage(
                                                        "This chest is now public! Use \"/cpset\" to set it private.",
                                                        Color.Red);
                                                }
                                                else
                                                {
                                                    chest.Lock();
                                                    player.SendMessage(
                                                        "This chest is now private! Use \"/cpset\" to set it public.",
                                                        Color.Red);
                                                }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);

                                            player.SendMessage(
                                                "This chest is now yours. This chest is public. Use \"/cpset\" to set it private.",
                                                Color.Red);
                                        }
                                        break;

                                    case SettingState.Deleting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player) ||
                                                tplayer.Group.HasPermission("removechestprotection"))
                                            {
                                                chest.Reset();
                                                player.SendMessage("This chest is no longer yours!", Color.Red);
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PasswordSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                                chest.SetPassword(player.PasswordForChest);
                                                player.SendMessage("This chest is now protected with password.",
                                                    Color.Red);
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();
                                            chest.SetPassword(player.PasswordForChest);

                                            player.SendMessage(
                                                "This chest is now protected with password, with you as owner.",
                                                Color.Red);
                                        }

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PasswordUnSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                                chest.SetPassword("");
                                                player.SendMessage("This chest password has been removed.", Color.Red);
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RefillSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                                chest.SetRefill(true);
                                                player.SendMessage("This chest is will now always refill with items.",
                                                    Color.Red);
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.SetRefill(true);

                                            player.SendMessage(
                                                "This chest is will now always refill with items, with you as owner.",
                                                Color.Red);
                                        }

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RefillUnSetting:
                                        if (chest.IsRefill())
                                            if (chest.HasOwner())
                                                if (chest.IsOwnerConvert(player))
                                                {
                                                    chest.SetRefill(false);
                                                    player.SendMessage(
                                                        "This chest is will no longer refill with items.", Color.Red);
                                                }
                                                else
                                                {
                                                    player.SendMessage("This chest isn't yours!", Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                            else
                                            {
                                                chest.SetID(id);
                                                chest.SetPosition(x, y);
                                                chest.SetOwner(player);
                                                chest.SetRefill(false);

                                                player.SendMessage("This chest is will no longer refill with items",
                                                    Color.Red);
                                            }
                                        else
                                            player.SendMessage("This chest is not refilling!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.UnLocking:
                                        if (chest.HasOwner())
                                            if (chest.IsLocked())
                                                if (chest.GetPassword() == "")
                                                {
                                                    player.SendMessage("This chest can't be unlocked with password!",
                                                        Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                                else if (chest.IsOwnerConvert(player))
                                                    player.SendMessage(
                                                        "You are owner of this chest, you dont need to unlock it. If you want to remove password use \"/lockchest remove\".",
                                                        Color.Red);
                                                else if (player.HasAccessToChest(chest.GetID()))
                                                    player.SendMessage("You already have access to this chest!",
                                                        Color.Red);
                                                else if (chest.CheckPassword(player.PasswordForChest))
                                                {
                                                    player.UnlockedChest(chest.GetID());
                                                    player.SendMessage(
                                                        "Chest unlocked! When you leave game you must unlock it again.",
                                                        Color.Red);
                                                }
                                                else
                                                {
                                                    player.SendMessage("Wrong password for chest!", Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                            else
                                                player.SendMessage("This chest is not locked!", Color.Red);
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;
                                }

                                if (tplayer.Group.HasPermission("showchestinfo")) //if player should see chest info
                                    player.SendMessage(
                                        string.Format(
                                            "Chest Owner: {0} || Public: {1} || RegionShare: {2} || Password: {3} || Refill: {4}",
                                            chest.GetOwner() == "" ? "-None-" : chest.GetOwner(),
                                            chest.IsLocked() ? "No" : "Yes", chest.IsRegionLocked() ? "Yes" : "No",
                                            chest.GetPassword() == "" ? "No" : "Yes",
                                            chest.IsRefill() ? "Yes" : "No"), Color.Yellow);

                                if (!tplayer.Group.HasPermission("openallchests") && !chest.IsOpenFor(player))
                                    //if player doesnt has permission to see inside chest, then break and message
                                {
                                    e.Handled = true;
                                    if (!naggedAboutLock)
                                        player.SendMessage(
                                            chest.GetPassword() != ""
                                                ? "This chest is magically locked with password. ( Use \"/cunlock PASSWORD\" to unlock it. )"
                                                : "This chest is magically locked.", Color.IndianRed);
                                    return;
                                }
                            }
                            if (player.GetState() != SettingState.None)
                                //if player is still setting something - end his setting
                                player.SetState(SettingState.None);
                        }
                    break;
                case PacketTypes.TileKill:
                case PacketTypes.Tile:
                    using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                        try
                        {
                            var reader = new BinaryReader(data);
                            if (e.MsgID == PacketTypes.Tile)
                            {
                                byte type = reader.ReadByte();
                                if (!(type == 0 || type == 4))
                                    return;
                            }
                            int x = reader.ReadInt32();
                            int y = reader.ReadInt32();
                            reader.Close();

                            if (Chest.TileIsChest(x, y)) //if is Chest
                            {
                                int id = Terraria.Chest.FindChest(x, y);
                                CPlayer player = Players[e.Msg.whoAmI];
                                TPPlayer tplayer = tPulse.Players[e.Msg.whoAmI];

                                //dirty fix for finding chest, try to find chest point around
                                if (id == -1)
                                    try
                                    {
                                        id = Terraria.Chest.FindChest(x - 1, y); //search one tile left
                                        if (id == -1)
                                        {
                                            id = Terraria.Chest.FindChest(x - 1, y - 1);
                                            //search one tile left and one tile up
                                            if (id == -1)
                                                id = Terraria.Chest.FindChest(x, y - 1); //search one tile up
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Write(ex.ToString(), LogLevel.Error);
                                    }

                                if (id != -1) //if have found chest
                                {
                                    Chest chest = ChestManager.GetChest(id);
                                    if (chest.HasOwner()) //if owned stop removing
                                    {
                                        if (tplayer.Group.HasPermission("removechestprotection") ||
                                            chest.IsOwnerConvert(player))
                                            //display more verbose info to player who has permission to remove protection on this chest
                                            player.SendMessage(
                                                "This chest is protected. To remove it, first remove protection using \"/cunset\" command.",
                                                Color.Red);
                                        else
                                            player.SendMessage("This chest is protected!", Color.Red);

                                        player.SendTileSquare(x, y);
                                        e.Handled = true;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Write(ex.ToString(), LogLevel.Error);
                        }
                    break;
                case PacketTypes.ChestItem:
                    using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                    {
                        var reader = new BinaryReader(data);
                        short id = reader.ReadInt16();
                        byte slot = reader.ReadByte();
                        byte stack = reader.ReadByte();
                        byte prefix = reader.ReadByte();
                        short type = reader.ReadByte();
                        if (id != -1)
                        {
                            Chest chest = ChestManager.GetChest(id);
                            if (chest.IsRefill())
                                e.Handled = true;
                            if (!e.Handled)
                            {
                                var item = Main.chest[id].item[slot];
                                var newitem = new Item();
                                newitem.netDefaults(type);
                                newitem.Prefix(prefix);
                                newitem.AffixName();
                                Log.Write(string.Format("{0}({1}) in slot {2} in chest at {3}x{4} was modified to {5}({6}) by {7}",
                                    item.name, item.stack, slot, Main.chest[id].x, Main.chest[id].y, newitem.name, stack, tPulse.Players[e.Msg.whoAmI].UserAccountName),
                                    LogLevel.Info, false);
                            }
                        }
                    }
                    break;
            }
        }
Esempio n. 30
0
        public static void GetData(GetDataEventArgs e)
        {
            if (e.Handled)
                return;
            try
            {
                switch (e.MsgID)
                {
                    #region player join
                    case PacketTypes.TileGetSection:
                        {
                            if (!TShock.Players[e.Msg.whoAmI].RequestedSection)
                            {
                                lock (PlayerList)
                                {
                                    PlayerList.Add(new ATPlayer(e.Msg.whoAmI));
                                }
                                LoginThread lt = new LoginThread(e.Msg.whoAmI);
                                Thread t = new Thread(new ThreadStart(lt.CheckLogin));
                                t.Start();
                            }
                            break;
                        }
                    #endregion
                    #region Tile Edit
                    case PacketTypes.Tile:
                        {
                            byte type, tileType, style;
                            Int32 x, y;
                            bool fail;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                type = reader.ReadByte();
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                tileType = reader.ReadByte();
                                fail = reader.ReadBoolean();
                                style = reader.ReadByte();
                                reader.Close();
                                reader.Dispose();
                            }
                            int signID = Sign.ReadSign(x, y);
                            //Console.WriteLine("TileEdit: type: {0}, tiletype: {1}, fail: {2}, style: {3}, tile.frameX: {4}", type, tileType, fail, style, Main.tile[x, y].frameX);
                            //  Tile tile = Main.tile[x, y];
                            //    Console.WriteLine("Tileinfo: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.type, tile.frameX, tile.frameY, tile.frameNumber);
                            //   Console.WriteLine("Tiledata: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.Data.type, tile.Data.frameX, tile.Data.frameY, tile.Data.frameNumber);
                            //    Console.WriteLine("type: {0}, Main.tile[].active: {1}, fail: {2}", type, Main.tile[x, y].Data.active, fail);
                            #region Tile Remove
                            if (type == 0 || type == 4)
                            {
                                if (tileType == 0 && signID != -1)
                                {
                                    db.QueryReader("DELETE FROM SignData WHERE X=@0 AND Y=@1 AND WorldID=@2", x, y, Main.worldID);
                                }
                            }
                            #endregion
                            #region Tile place
                            else if (type == 1)
                            {

                            }
                            #endregion
                            break;
                        }
                    #endregion
                    #region Sign Edit
                    case PacketTypes.SignNew:
                        {
                            Int16 signId;
                            Int32 x, y;
                            byte[] textB;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                signId = reader.ReadInt16();
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                textB = reader.ReadBytes(e.Length - 10);
                                reader.Close();
                                reader.Dispose();
                            }
                            string newtxt = Encoding.UTF8.GetString(textB);
                            var tplayer = TShock.Players[e.Msg.whoAmI];
                            int id = Sign.ReadSign(x, y);
                            if (id != -1)
                            {
                                try
                                {
                                    lock (db)
                                    {
                                        var values = new List<SqlValue>();
                                        values.Add(new SqlValue("X", x));
                                        values.Add(new SqlValue("Y", y));
                                        values.Add(new SqlValue("User", "'" + tplayer.Name + "'"));
                                        values.Add(new SqlValue("Time", DateTime.Now.Ticks));
                                        values.Add(new SqlValue("WorldID", Main.worldID));
                                        SQLeditor.InsertValues("SignData", values);
                                        /*System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
                                        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("INSERT INTO user (infoDate) VALUES (@value)", conn);
                                        cmd.Parameters.AddWithValue("@value", DateTime.Now);
                                        cmd.ExecuteNonQuery();*/
                                    }
                                }
                                catch (Exception ex)
                                { Log.ConsoleError(ex.ToString()); }
                            }
                            break;
                        }
                    #endregion
                    #region Sign Read
                    case PacketTypes.SignRead:
                        {
                            int x, y;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();

                                reader.Close();
                            }
                            var id = Sign.ReadSign(x, y);
                            var tplayer = TShock.Players[e.Msg.whoAmI];
                            if (tplayer != null && id != -1)
                            {
                                if (tplayer.Group.HasPermission("AT.signhistory"))
                                {
                                    QueryResult query = db.QueryReader("Select User,Time from SignData where X=@0 AND Y=@1 AND WorldID=@2", x, y, Main.worldID);
                                    tplayer.SendMessage(String.Format("Sign edit history:"), Color.LightSalmon);
                                    while (query.Read())
                                    {
                                        long time = query.Get<long>("Time");
                                        tplayer.SendMessage(String.Format("{0} @ {1}", query.Get<string>("User"), new DateTime(time)), Color.BurlyWood);
                                    }
                                    query.Dispose();
                                }
                            }
                            // Console.WriteLine("x: {0} y: {1}", x, y);
                            break;
                        }
                    #endregion
                    #region Player Update
                    case PacketTypes.PlayerUpdate:
                        {
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                byte plyID = reader.ReadByte();
                                byte flags = reader.ReadByte();
                                byte item = reader.ReadByte();
                                float posX = reader.ReadSingle();
                                float posY = reader.ReadSingle();
                                float velX = reader.ReadSingle();
                                float velY = reader.ReadSingle();
                                reader.Close();
                                reader.Dispose();
                                //Console.WriteLine("PlayerUpdate: playerID: {0}, item: {1}, posX: {2}, posY: {3}, velX: {4}, velY: {5}", plyID, item, posX, posY, velX, velY);
                                //Console.WriteLine("item info: Name: {0}, dmg: {1}, animation: {2}", Main.player[plyID].inventory[item].name, Main.player[plyID].inventory[item].damage, Main.player[plyID].inventory[item].useAnimation);
                                TSPlayer tsplayer = TShock.Players[plyID];
                                if (tsplayer == null)
                                    break;
                                ATPlayer player = GetPlayerByUserID(tsplayer.UserID);
                                if (player == null)
                                    break;
                                // Console.WriteLine("Flags: {0}", flags);
                                if ((flags & 32) == 32)
                                {
                                    try
                                    {
                                        var BT = player.GetBindTool(Main.player[plyID].inventory[item]);
                                        if (BT != null)
                                        {
                                            BT.DoCommand(tsplayer);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.ConsoleError(ex.ToString());
                                    }
                                    //Console.WriteLine("Player {0} used item: {1}", player.TSPlayer.Name, Main.player[plyID].inventory[item].name);
                                }
                            }
                            break;
                        }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 31
0
        private void NetHooks_GetData(GetDataEventArgs e)
        {
            switch (e.MsgID)
            {
                case PacketTypes.ChestGetContents:
                    if (!e.Handled)
                        using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                         try {
                            var reader = new BinaryReader(data);
                            int x = reader.ReadInt32();
                            int y = reader.ReadInt32();
                            reader.Close();
                            int id = Terraria.Chest.FindChest(x, y);
                            CPlayer player = Players[e.Msg.whoAmI];
                            TSPlayer tplayer = TShock.Players[e.Msg.whoAmI];
                            if (id != -1)
                            {
                                Chest chest = chestDbManager.GetChest( id );
                                bool naggedAboutLock = false;

                                switch (player.GetState())
                                {
                                    case SettingState.Setting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                player.SendMessage("You already own this chest!", Color.Red);
                                            else
                                            {
                                                player.SendMessage("This chest is already owned by someone!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();
                                            player.SendMessage("This chest is now yours, and yours only.", Color.Red);
                                            chestDbManager.SaveChest( id );
                                        }

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RegionSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                if (chest.IsRegionLocked())
                                                {
                                                    chest.regionLock(false);
                                                    player.SendMessage( "Region share disabled. This chest is now only yours. To fully remove protection use \"cunset\".", Color.Red);
                                                    chestDbManager.SaveChest( id );
                                                }
                                                else if (TShock.Regions.InArea(x, y))
                                                {
                                                    chest.regionLock(true);
                                                    player.SendMessage( "This chest is now shared between region users. Use this command again to disable it.", Color.Red);
                                                    chestDbManager.SaveChest( id );
                                                }
                                                else
                                                    player.SendMessage( "You can region share chest only if the chest is inside region!", Color.Red);
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else if (TShock.Regions.InArea(x, y))
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();
                                            chest.regionLock(true);
                                            player.SendMessage( "This chest is now shared between region users with you as owner. Use this command again to disable region sharing (You will still be owner).", Color.Red);
                                            chestDbManager.SaveChest( id );
                                        }
                                        else
                                            player.SendMessage( "You can region share chest only if the chest is inside region!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PublicSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                                if (chest.IsLocked())
                                                {
                                                    chest.UnLock();
                                                    player.SendMessage( "This chest is now public! Use \"/cpset\" to set it private.", Color.Red);
                                                    chestDbManager.SaveChest( id );
                                                }
                                                else
                                                {
                                                    chest.Lock();
                                                    player.SendMessage( "This chest is now private! Use \"/cunset\" to set it public.", Color.Red);
                                                    chestDbManager.SaveChest( id );
                                                }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            player.SendMessage( "This chest is now yours. This chest is public. Use \"/cpset\" to set it private.", Color.Red);
                                            chestDbManager.SaveChest( id );
                                        }
                                        break;

                                    case SettingState.Deleting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player) ||
                                                tplayer.Group.HasPermission("removechestprotection"))
                                            {
                                                chest.Reset();
                                                player.SendMessage("This chest is no longer yours!", Color.Red);
                                                chestDbManager.DeleteChest( id );
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PasswordSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                                chest.SetPassword(player.PasswordForChest);
                                                player.SendMessage("This chest is now protected with password.", Color.Red);
                                                chestDbManager.SaveChest( id );
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                            chest.SetID(id);
                                            chest.SetPosition(x, y);
                                            chest.SetOwner(player);
                                            chest.Lock();
                                            chest.SetPassword(player.PasswordForChest);
                                            player.SendMessage( "This chest is now protected with password, with you as owner.", Color.Red);
                                            chestDbManager.SaveChest( id );
                                        }

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.PasswordUnSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                                chest.SetPassword("");
                                                player.SendMessage("This chest password has been removed.", Color.Red);
                                                chestDbManager.DeleteChest( id );
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RefillSetting:
                                        if (chest.HasOwner())
                                            if (chest.IsOwnerConvert(player))
                                            {
                                              chest.SetRefill( true );
                                              if ( player.RefillDelay == 0 )
                                              {
                                                player.SendMessage( "This chest will now refill with items.", Color.Red );
                                                chestDbManager.SaveChest( id );
                                              } // if
                                              else
                                              {
                                                chest.SetRefillDelay( player.RefillDelay );
                                                player.SendMessage( "This chest will now refill with items after a " + player.RefillDelay + " second delay.", Color.Red );
                                                player.RefillDelay = 0;
                                                chestDbManager.SaveChest( id );
                                              } // else
                                            }
                                            else
                                            {
                                                player.SendMessage("This chest isn't yours!", Color.Red);
                                                naggedAboutLock = true;
                                            }
                                        else
                                        {
                                          chest.SetID( id );
                                          chest.SetPosition( x, y );
                                          chest.SetOwner( player );
                                          chest.SetRefill( true );
                                          if ( player.RefillDelay == 0 )
                                          {
                                            player.SendMessage( "This chest will now refill with items, with you as owner.", Color.Green );
                                            chestDbManager.SaveChest( id );
                                          } // if
                                          else
                                          {
                                            chest.SetRefillDelay( player.RefillDelay );
                                            player.SendMessage( "This chest will now refill with items after a " + player.RefillDelay + " second delay, with you as owner.", Color.Green );
                                            player.RefillDelay = 0;
                                            chestDbManager.SaveChest( id );
                                          } // else
                                        } // else

                                        // end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.RefillUnSetting:
                                        if (chest.IsRefill())
                                            if (chest.HasOwner())
                                                if (chest.IsOwnerConvert(player))
                                                {
                                                    chest.SetRefill(false);
                                                    player.SendMessage(
                                                        "This chest will no longer refill with items.", Color.Red);
                                                    chestDbManager.SaveChest( id );
                                                }
                                                else
                                                {
                                                    player.SendMessage("This chest isn't yours!", Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                            else
                                            {
                                                chest.SetID(id);
                                                chest.SetPosition(x, y);
                                                chest.SetOwner(player);
                                                chest.SetRefill(false);
                                                player.SendMessage("This chest will no longer refill with items", Color.Red);
                                                chestDbManager.SaveChest( id );
                                            }
                                        else
                                            player.SendMessage("This chest is not refilling!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;

                                    case SettingState.UnLocking:
                                        if (chest.HasOwner())
                                            if (chest.IsLocked())
                                                if (chest.GetPassword() == "")
                                                {
                                                    player.SendMessage("This chest can't be unlocked with password!", Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                                else if (chest.IsOwnerConvert(player))
                                                    player.SendMessage( "You are owner of this chest, you dont need to unlock it. If you want to remove password use \"/lockchest remove\".", Color.Red);
                                                else if (player.HasAccessToChest(chest.GetID()))
                                                    player.SendMessage("You already have access to this chest!", Color.Red);
                                                else if (chest.CheckPassword(player.PasswordForChest))
                                                {
                                                    player.UnlockedChest(chest.GetID());
                                                    player.SendMessage( "Chest unlocked! When you leave game you must unlock it again.", Color.Red);
                                                }
                                                else
                                                {
                                                    player.SendMessage("Wrong password for chest!", Color.Red);
                                                    naggedAboutLock = true;
                                                }
                                            else
                                                player.SendMessage("This chest is not locked!", Color.Red);
                                        else
                                            player.SendMessage("This chest is not protected!", Color.Red);

                                        //end player setting
                                        player.SetState(SettingState.None);
                                        break;
                                } // switch - (player.GetState())

                                if (tplayer.Group.HasPermission("showchestinfo")) //if player should see chest info
                                    player.SendMessage(
                                        string.Format(
                                            "Chest Owner: {0} || Public: {1} || RegionShare: {2} || Password: {3} || Refill: {4} || Delay: {5}",
                                            chest.GetOwner() == "" ? "-None-" : chest.GetOwner(),
                                            chest.IsLocked() ? "No" : "Yes",
                                            chest.IsRegionLocked() ? "Yes" : "No",
                                            chest.GetPassword() == "" ? "No" : "Yes",
                                            chest.IsRefill() ? "Yes" : "No",
                                            chest.GetRefillDelay() ), Color.Yellow );

                                if (!tplayer.Group.HasPermission("openallchests") && !chest.IsOpenFor(player))
                                { // if player doesnt has permission to see inside chest, then send message and break
                                    e.Handled = true;
                                    if (!naggedAboutLock)
                                        player.SendMessage( chest.GetPassword() != ""
                                                ? "This chest is magically locked with password. ( Use \"/cunlock PASSWORD\" to unlock it. )"
                                                : "This chest is magically locked.", Color.IndianRed);
                                    return;
                                } // if

            // +++++++++++++++++++++++++++++++++++++++++++++++++++
                                if ( chest.IsOpenFor( player ) )
                                  if ( chest.IsRefill() )
                                    if ( chest.GetRefillDelay() > 0 )
                                    {
                                      //player.SendMessage( "This chest has a refill delay of " + chest.GetRefillDelay() + " seconds", Color.Gold );
                                      if ( chest.HasRefillTimerExpired() ) // delay has elapsed, refill chest
                                      {
                                        chest.RefillChest();
                                        //Players[e.Msg.whoAmI].SendMessage( "Refilled", Color.Green );
                                      } // if
                                      else
                                        if ( chest.GetRefillDelayRemaining() == chest.GetRefillDelay() )
                                          Players[e.Msg.whoAmI].SendMessage( "This chest has a refill delay of " + chest.GetRefillDelay() + " seconds", Color.Blue );
                                        else
                                          Players[e.Msg.whoAmI].SendMessage( "Refill will occur in " + chest.GetRefillDelayRemaining() + " seconds", Color.Orange );
                                    } // if
                                    //else // immediate refill
                                      //player.SendMessage( "This chest refills immediately", Color.Green );
                                  //else
                                    //player.SendMessage( "You can open this chest", Color.White );

                            } // if (id != -1)

                            if (player.GetState() != SettingState.None)
                                //if player is still setting something - end his setting
                                player.SetState(SettingState.None);
                      } // try using MemoryStream
                      catch ( Exception ex )
                      {
                        Log.Write( ex.ToString(), LogLevel.Error );
                      }
                    break;
            // -----------------------------------------------------------------------------
                case PacketTypes.ChestItem: // this occurs when a player grabs item from or puts item into chest
                    using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                      try {
                        var reader = new BinaryReader(data);
                        short id = reader.ReadInt16();
                        byte slot = reader.ReadByte();
                        byte stack = reader.ReadByte();
                        byte prefix = reader.ReadByte();
                        short type = reader.ReadInt16(); // formerly ReadByte()
                        reader.Close();

                        if (id != -1)
                        {
                            Chest chest = chestDbManager.GetChest( id );
                            if ( chest.IsRefill() )
                            {
                              if ( chest.GetRefillDelay() > 0 )
                              {
                                //Players[e.Msg.whoAmI].SendMessage( "This chest refills after a delay of " + chest.GetRefillDelay() + " seconds", Color.Violet );
                                chest.StartRefillDelay();
                              } // if
                              else // no refill delay - ignore action
                              {
                                /* Setting e.Handled prevents TShock / Terraria from processing this message
                                 * In this case, it causes Terraria to ignore chest interactions (takes from & adds to)
                                 */
                                //Players[e.Msg.whoAmI].SendMessage( "Chest refilled", Color.Thistle );
                                e.Handled = true;
                              } // else
                            } // if ( chest.GetRefillDelay() > 0 )

                            //if (!e.Handled)
                            //{
                            //    var item = Main.chest[id].item[slot];
                            //    var newitem = new Item();
                            //    newitem.netDefaults(type);
                            //    newitem.Prefix(prefix);
                            //    newitem.AffixName();
                            //    String playerName = (string.IsNullOrEmpty( TShock.Players[e.Msg.whoAmI].UserAccountName )) ? Players[e.Msg.whoAmI].Name : TShock.Players[e.Msg.whoAmI].UserAccountName;
                            //    Log.Write( string.Format( "Item {0}({1}) in slot {2} in chest at {3}x{4} was modified to {5}({6}) by {7}",
                            //        item.name, item.stack, slot, Main.chest[id].x, Main.chest[id].y, newitem.name, stack, playerName ),
                            //        LogLevel.Info, false );
                            //} // if (!e.Handled)

                        } // if (id != -1)
                      } // try using MemoryStream
                      catch ( Exception ex )
                      {
                        Log.Write( ex.ToString(), LogLevel.Error );
                      }
                    break;
            // =============================================================================
                case PacketTypes.TileKill:
                case PacketTypes.Tile:
                    using ( var data = new MemoryStream( e.Msg.readBuffer, e.Index, e.Length ) )
                      try
                      {
                        var reader = new BinaryReader( data );
                        if ( e.MsgID == PacketTypes.Tile )
                        {
                          byte type = reader.ReadByte();
                          if ( !(type == 0 || type == 4) )
                            return;
                        }
                        int x = reader.ReadInt32();
                        int y = reader.ReadInt32();
                        reader.Close();

                        if ( Chest.TileIsChest( x, y ) ) //if is Chest
                        {
                          int id = Terraria.Chest.FindChest( x, y );
                          CPlayer player = Players[e.Msg.whoAmI];
                          TSPlayer tplayer = TShock.Players[e.Msg.whoAmI];

                          //dirty fix for finding chest, try to find chest point around
                          if ( id == -1 )
                            try
                            {
                              id = Terraria.Chest.FindChest( x - 1, y ); //search one tile left
                              if ( id == -1 )
                              {
                                id = Terraria.Chest.FindChest( x - 1, y - 1 );
                                //search one tile left and one tile up
                                if ( id == -1 )
                                  id = Terraria.Chest.FindChest( x, y - 1 ); //search one tile up
                              }
                            }
                            catch ( Exception ex )
                            {
                              Log.Write( ex.ToString(), LogLevel.Error );
                            }

                          if ( id != -1 ) //if have found chest
                          {
                            Chest chest = chestDbManager.GetChest( id );
                            if ( chest.HasOwner() ) //if owned stop removing
                            {
                              if ( tplayer.Group.HasPermission( "removechestprotection" ) ||
                                  chest.IsOwnerConvert( player ) )
                                //display more verbose info to player who has permission to remove protection on this chest
                                player.SendMessage( "This chest is protected. To remove it, first remove protection using \"/cunset\" command.", Color.Red );
                              else
                                player.SendMessage( "This chest is protected!", Color.Red );

                              player.SendTileSquare( x, y );
                              e.Handled = true;
                            }
                          }
                        }
                      }
                      catch ( Exception ex )
                      {
                        Log.Write( ex.ToString(), LogLevel.Error );
                      }
                    break;
            } // switch
        }
Esempio n. 32
0
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled && e.MsgID == PacketTypes.Tile)
     {
         PlayerInfo info = Players[e.Msg.whoAmI];
         if (info.pt != 0)
         {
             int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
             int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
             if (X >= 0 && Y >= 0 && X < Main.maxTilesX && Y < Main.maxTilesY)
             {
                 if (info.pt == 1)
                 {
                     info.x = X;
                     info.y = Y;
                     TShock.Players[e.Msg.whoAmI].SendMessage(String.Format("Set point 1.", X, Y), Color.Yellow);
                 }
                 else if (info.pt == 3)
                 {
                     List<string> Reg = regionManager.InAreaRegionName(X, Y);
                     if (Reg.Count == 0)
                     {TShock.Players[e.Msg.whoAmI].SendMessage("Not Protected", Color.Red);
                     return;}
                     curReg = regionManager.GetRegionByName(Reg[0]);
                         TShock.Players[e.Msg.whoAmI].SendMessage(String.Format("Got Here.", X, Y));
                         info.x = curReg.Area.X;
                         info.y = curReg.Area.Y;
                         info.x2 = curReg.Area.X + curReg.Area.Width;
                         info.y2 = curReg.Area.Y + curReg.Area.Height;
                         TShock.Players[e.Msg.whoAmI].SendMessage(String.Format("Region Set.", X, Y), Color.Yellow);
                 }
                 else
                 {
                     info.x2 = X;
                     info.y2 = Y;
                     TShock.Players[e.Msg.whoAmI].SendMessage("New", Color.Yellow);
                 }
                 info.pt = 0;
                 e.Handled = true;
                 TShock.Players[e.Msg.whoAmI].SendTileSquare(X, Y, 3);
             }
         }
     }
 }
        public void GetData(GetDataEventArgs e)
        {
            try
            {
                switch (e.MsgID)
                {
                    #region Tile Modify
                    case PacketTypes.Tile:
                        using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                        {
                            var reader = new BinaryReader(data);
                            if (e.MsgID == PacketTypes.Tile)
                            {
                                var type = reader.ReadByte();
                                if (!(type == 0 || type == 4))
                                    return;
                            }
                            var x = reader.ReadInt32();
                            var y = reader.ReadInt32();
                            reader.Close();

                            if (Main.tile[x, y].type != 55) return;

                            var id = Terraria.Sign.ReadSign(x, y);
                            var tplayer = TShock.Players[e.Msg.whoAmI];

                            if (id != -1 && Main.sign[id].text.ToLower().StartsWith(getConfig.DefineSignCommands.ToLower()))
                            {
                                scPlayer hitplay = GetscPlayerByName(tplayer.Name);

                                if (!hitplay.destsign)
                                {
                                    if (tplayer.Group.HasPermission("destroysigncommand") && hitplay.tolddest <= 0)
                                    {
                                        tplayer.SendMessage("To destroy this sign, Type /destsign", Color.IndianRed);
                                        hitplay.tolddest = 10;
                                    }
                                    tplayer.SendTileSquare(x, y);
                                    e.Handled = true;

                                    //string[] lines = Main.sign[id].text.Split(Encoding.UTF8.GetString(new byte[] { 10 }).ToCharArray()[0]);
                                    char tosplit = '>';
                                    if (getConfig.CommandsStartWith.Length == 1)
                                        tosplit = getConfig.CommandsStartWith.ToCharArray()[0];
                                    string text = Main.sign[id].text.Replace(Encoding.UTF8.GetString(new byte[] { 10 }), "");
                                    string[] commands = text.Split(tosplit);
                                    foreach (string cmd in commands)
                                    {
                                        DoCommand(id, cmd, tplayer);
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region Edit Sign
                    case PacketTypes.SignNew:
                        if (!e.Handled)
                        {
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                var signId = reader.ReadInt16();
                                var x = reader.ReadInt32();
                                var y = reader.ReadInt32();
                                string newtext = "";
                                try
                                {
                                    var Bytes = reader.ReadBytes(e.Length - 11);
                                    newtext = Encoding.UTF8.GetString(Bytes);
                                }
                                catch { }
                                reader.Close();

                                var id = Terraria.Sign.ReadSign(x, y);
                                var tplayer = TShock.Players[e.Msg.whoAmI];
                                scPlayer edplay = GetscPlayerByID(tplayer.Index);

                                if (Main.sign[id] == null || tplayer == null || edplay == null) return;
                                string oldtext = Main.sign[id].text;
                                string dSignCmd = getConfig.DefineSignCommands;

                                if ((oldtext.StartsWith(dSignCmd) || newtext.StartsWith(dSignCmd)) && !tplayer.Group.HasPermission("createsigncommand"))
                                {
                                    tplayer.SendMessage("You do not have permission to create/edit sign commands!", Color.IndianRed);
                                    e.Handled = true;
                                    tplayer.SendData(PacketTypes.SignNew, "", id);
                                    return;
                                }
                            }
                        }
                        break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Log.Error("[Sign Commands] Exception while recieving data: ");
                Log.Error(ex.ToString());
            }
        }