コード例 #1
0
        //Death message
        //Player killed
        //Teleport
        /// <summary>
        /// Callde via vanilla code when a player has been hurt
        /// </summary>
        /// <param name="player">Player.</param>
        /// <param name="damage">Damage.</param>
        /// <param name="hitDirection">Hit direction.</param>
        /// <param name="pvp">If set to <c>true</c> pvp.</param>
        /// <param name="quiet">If set to <c>true</c> quiet.</param>
        /// <param name="deathText">Death text.</param>
        /// <param name="crit">If set to <c>true</c> crit.</param>
        /// <param name="cooldownCounter">Cooldown counter.</param>
        public static bool OnPlayerHurt(Terraria.Player player, int damage, int hitDirection, bool pvp = false, bool quiet = false, string deathText = " was slain...", bool crit = false, int cooldownCounter = -1)
        {
            var ctx = new HookContext()
            {
            //                Sender = player, This
            //                Player = player
            };
            var args = new HookArgs.PlayerHurt()
            {
                Victim = player,
                Damage = damage,
                HitDirection = hitDirection,
                Pvp = pvp,
                Quiet = quiet,
                Obituary = deathText,
                Critical = crit,
                CooldownCounter = cooldownCounter
            };

            HookPoints.PlayerHurt.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick()) return false;

            return ctx.Result == HookResult.DEFAULT;
        }
コード例 #2
0
        /// <summary>
        /// Raised by vanilla code when a player has been killed
        /// </summary>
        /// <param name="player">Player.</param>
        /// <param name="dmg">Dmg.</param>
        /// <param name="hitDirection">Hit direction.</param>
        /// <param name="pvp">Pvp.</param>
        /// <param name="deathText">Death text.</param>
        public static bool OnPlayerKilled(Terraria.Player player, ref double dmg, ref int hitDirection, ref bool pvp, ref string deathText)
        {
            var ctx = new HookContext()
            {
                Sender = player,
                Player = player
            };
            var args = new HookArgs.PlayerKilled()
            {
                Damage = dmg,
                HitDirection = hitDirection,
                PvP = pvp,
                DeathText = deathText
            };

            HookPoints.PlayerKilled.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick()) return false;

            if (ctx.Result == HookResult.DEFAULT)
            {
                deathText = player.name + deathText;
                return true;
            }

            dmg = args.Damage;
            hitDirection = args.HitDirection;
            pvp = args.PvP;
            deathText = args.DeathText;
            return ctx.Result != HookResult.IGNORE;
        }
コード例 #3
0
        public ClientConnection(Socket sock)
            : base(sock)
        {
            if (SlotId == 0)
                SlotId = -1;

            var remoteEndPoint = (IPEndPoint)sock.RemoteEndPoint;
            _remoteAddress = new TcpAddress(remoteEndPoint.Address, remoteEndPoint.Port);

            sock.LingerState = new LingerOption(true, 10);
            sock.NoDelay = true;

            var ctx = new HookContext
            {
                Connection = this
            };

            var args = new HookArgs.NewConnection();

            HookPoints.NewConnection.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return;

            _isReceiving = true; //The connection was established, so we can begin reading
        }
コード例 #4
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            if (Main.netMode != 2)
                return true;

            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();

            if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7)
                return true;

            int chestIndex = Chest.FindChest(x, y);
            if (chestIndex <= -1 || Chest.UsingChest(chestIndex) != -1)
                return true;

            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player
            };

            var args = new TDSMHookArgs.ChestOpenReceived
            {
                X = x,
                Y = y,
                ChestIndex = chestIndex
            };

            TDSMHookPoints.ChestOpenReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return true;

            if (ctx.Result == HookResult.IGNORE)
                return true;

            if (ctx.Result == HookResult.DEFAULT && chestIndex > -1)
            {
                for (int i = 0; i < 40; i++)
                {
                    NetMessage.SendData(32, bufferId, -1, "", chestIndex, (float)i, 0, 0, 0, 0, 0);
                }
                NetMessage.SendData(33, bufferId, -1, "", chestIndex, 0, 0, 0, 0, 0, 0);
                Main.player[bufferId].chest = chestIndex;
                if (Main.myPlayer == bufferId)
                {
                    Main.recBigList = false;
                }

                NetMessage.SendData(80, -1, bufferId, "", bufferId, (float)chestIndex, 0, 0, 0, 0, 0);
            }

            return true;
        }
コード例 #5
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];

            var x = (int)buffer.reader.ReadInt16();
            var y = (int)buffer.reader.ReadInt16();
            var colour = buffer.reader.ReadByte();

            if (!WorldGen.InWorld(x, y, 3))
            {
                return true;
            }

            var player = Main.player[bufferId];

            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Sender = player,
                Player = player,
            };

            var args = new TDSMHookArgs.PaintWall
            {
                X = x,
                Y = y,
                Colour = colour
            };

            TDSMHookPoints.PaintWall.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return true;

            if (ctx.Result == HookResult.IGNORE)
                return true;

            if (ctx.Result == HookResult.RECTIFY)
            {
                NetMessage.SendTileSquare(bufferId, x, y, 1);
                return true;
            }

            WorldGen.paintWall(x, y, colour, false);
            if (Main.netMode == 2)
            {
                NetMessage.SendData(64, -1, bufferId, "", x, (float)y, (float)colour, 0f, 0, 0, 0);
            }
            return true;
        }
コード例 #6
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            if (Main.netMode != 2)
            {
                return true;
            }
            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();
            int id = Sign.ReadSign(x, y, true);

            if (id >= 0)
            {
                var ctx = new HookContext
                {
                    Connection = player.Connection.Socket,
                    Sender = player,
                    Player = player
                };

                var args = new TDSMHookArgs.SignTextGet
                {
                    X = x,
                    Y = y,
                    SignIndex = (short)id,
                    Text = (id >= 0 && Main.sign[id] != null) ? Main.sign[id].text : null,
                };

                TDSMHookPoints.SignTextGet.Invoke(ref ctx, ref args);

                if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                    return true;

                if (args.Text != null)
                {
                    NetMessage.SendData(47, bufferId, -1, "", id, (float)bufferId, 0, 0, 0, 0, 0);
                }
            }
            return true;
        }
コード例 #7
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];

            int npcId = (int)buffer.reader.ReadInt16();
            int playerId = (int)buffer.reader.ReadByte();

            if (Main.netMode == 2)
                playerId = bufferId;

            var ply = Main.player[playerId];
            var ctx = new HookContext()
            {
                Sender = ply,
                Player = ply
            };
            var args = new TDSMHookArgs.NpcHurtReceived()
            {
                Victim = Terraria.Main.npc[npcId],
                Damage = ply.inventory[ply.selectedItem].damage,
                HitDirection = ply.direction,
                Knockback = ply.inventory[ply.selectedItem].knockBack,
                Critical = false,
                FromNet = false,
                NoEffect = false
            };

            TDSMHookPoints.NpcHurtReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE) return true;

            Terraria.Main.npc[npcId].StrikeNPC(args.Damage, args.Knockback, args.HitDirection, false, false, false);

            if (Main.netMode == 2)
            {
                NetMessage.SendData(24, -1, bufferId, "", npcId, (float)playerId, 0, 0, 0, 0, 0);
                NetMessage.SendData(23, -1, -1, "", npcId, 0, 0, 0, 0, 0, 0);
            }
            return true;
        }
コード例 #8
0
        private static void ProcessTileSquare(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            short size = buffer.reader.ReadInt16();
            int startX = (int)buffer.reader.ReadInt16();
            int startY = (int)buffer.reader.ReadInt16();
            if (!WorldGen.InWorld(startX, startY, 3))
            {
                return;
            }

            var ctx = new HookContext
            {
                Sender = player,
                Player = player,
                Connection = player.Connection.Socket
            };

            var args = new HookArgs.TileSquareReceived
            {
                X = startX,
                Y = startY,
                Size = size,
                ReadBuffer = buffer.readBuffer
                //                start = num
            };

            HookPoints.TileSquareReceived.Invoke(ref ctx, ref args);

            //            if (args.applied > 0)
            //            {
            //                WorldGen.RangeFrame(startX, startY, startX + (int)size, startY + (int)size);
            //                NetMessage.SendData((int)Packet.TILE_SQUARE, -1, bufferId, String.Empty, (int)size, (float)startX, (float)startY, 0f, 0);
            //            }

            if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                return;

            BitsByte bitsByte10 = 0;
            BitsByte bitsByte11 = 0;
            for (int x = startX; x < startX + (int)size; x++)
            {
                for (int y = startY; y < startY + (int)size; y++)
                {
                    if (Main.tile[x, y] == null)
                    {

            #if Full_API && !MemTile && !VANILLACOMPAT
                        Main.tile[x, y] = new Tile();
            #elif Full_API && MemTile
                        Main.tile[x, y] = new OTA.Memory.MemTile(x, y);
            #elif Full_API && VANILLACOMPAT && TileReady
                        Main.tile[x, y] = new OTA.Memory.MemTile();
            #endif
                    }
                    var tile = Main.tile[x, y];
                    bool flag7 = tile.active();
                    bitsByte10 = buffer.reader.ReadByte();
                    bitsByte11 = buffer.reader.ReadByte();
                    tile.active(bitsByte10[0]);
                    tile.wall = (bitsByte10[2] ? (byte)1 : (byte)0);
                    bool flag8 = bitsByte10[3];
                    if (Main.netMode != 2)
                    {
                        tile.liquid = (flag8 ? (byte)1 : (byte)0);
                    }
                    tile.wire(bitsByte10[4]);
                    tile.halfBrick(bitsByte10[5]);
                    tile.actuator(bitsByte10[6]);
                    tile.inActive(bitsByte10[7]);
                    tile.wire2(bitsByte11[0]);
                    tile.wire3(bitsByte11[1]);
                    if (bitsByte11[2])
                    {
                        tile.color(buffer.reader.ReadByte());
                    }
                    if (bitsByte11[3])
                    {
                        tile.wallColor(buffer.reader.ReadByte());
                    }
                    if (tile.active())
                    {
                        int type3 = (int)tile.type;
                        tile.type = buffer.reader.ReadUInt16();
                        if (Main.tileFrameImportant[(int)tile.type])
                        {
                            tile.frameX = buffer.reader.ReadInt16();
                            tile.frameY = buffer.reader.ReadInt16();
                        }
                        else
                        {
                            if (!flag7 || (int)tile.type != type3)
                            {
                                tile.frameX = -1;
                                tile.frameY = -1;
                            }
                        }
                        byte b4 = 0;
                        if (bitsByte11[4])
                        {
                            b4 += 1;
                        }
                        if (bitsByte11[5])
                        {
                            b4 += 2;
                        }
                        if (bitsByte11[6])
                        {
                            b4 += 4;
                        }
                        tile.slope(b4);
                    }
                    if (tile.wall > 0)
                    {
                        tile.wall = buffer.reader.ReadByte();
                    }
                    if (flag8)
                    {
                        tile.liquid = buffer.reader.ReadByte();
                        tile.liquidType((int)buffer.reader.ReadByte());
                    }
                }
            }
            WorldGen.RangeFrame(startX, startY, startX + (int)size, startY + (int)size);
            if (Main.netMode == 2)
            {
                NetMessage.SendData((int)Packet.TILE_SQUARE, -1, bufferId, "", (int)size, (float)startX, (float)startY, 0, 0, 0, 0);
                return;
            }
        }
コード例 #9
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();
            byte liquid = buffer.reader.ReadByte();
            byte liquidType = buffer.reader.ReadByte();

            if (Main.netMode == 2 && Netplay.spamCheck)
            {
                int centerX = (int)(Main.player[bufferId].position.X + (float)(Main.player[bufferId].width / 2));
                int centerY = (int)(Main.player[bufferId].position.Y + (float)(Main.player[bufferId].height / 2));
                int range = 10;
                int minX = centerX - range;
                int maxX = centerX + range;
                int minY = centerY - range;
                int maxY = centerY + range;
                if (x < minX || x > maxX || y < minY || y > maxY)
                {
                    NetMessage.BootPlayer(bufferId, "Cheating attempt detected: Liquid spam");
                    return true;
                }
            }

            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player
            };

            var args = new TDSMHookArgs.LiquidFlowReceived
            {
                X = x,
                Y = y,
                Amount = liquid,
                Lava = liquidType == 1
            };

            TDSMHookPoints.LiquidFlowReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return true;

            if (ctx.Result == HookResult.IGNORE)
                return true;

            if (ctx.Result == HookResult.RECTIFY)
            {
                //                var msg = NewNetMessage.PrepareThreadInstance();
                //                msg.FlowLiquid(x, y);
                //                msg.Send(whoAmI);
                Terraria.NetMessage.SendData((int)Packet.FLOW_LIQUID, bufferId, -1, String.Empty, x, y);
                return true;
            }

            if (Main.tile[x, y] == null)
            {
                Main.tile[x, y] = new OTA.Memory.MemTile();
            }
            lock (Main.tile[x, y])
            {
                Main.tile[x, y].liquid = liquid;
                Main.tile[x, y].liquidType((int)liquidType);
                if (Main.netMode == 2)
                {
                    WorldGen.SquareTileFrame(x, y, true);
                }
            }

            return true;
        }
コード例 #10
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            byte b7 = buffer.reader.ReadByte();
            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();
            int type = (int)buffer.reader.ReadInt16();

            if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7)
            {
                return true;
            }

            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player
            };

            var args = new TDSMHookArgs.ChestBreakReceived
            {
                X = x,
                Y = y
            };

            TDSMHookPoints.ChestBreakReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return true;

            if (ctx.Result == HookResult.IGNORE)
                return true;

            if (ctx.Result == HookResult.RECTIFY)
            {
                NetMessage.SendTileSquare(bufferId, x, y, 3);
                return true;
            }

            if (Main.netMode == 2)
            {
                if (b7 == 0)
                {
                    int num107 = WorldGen.PlaceChest(x, y, 21, false, type);
                    if (num107 == -1)
                    {
                        NetMessage.SendData(34, bufferId, -1, "", (int)b7, (float)x, (float)y, (float)type, num107, 0, 0);
                        Item.NewItem(x * 16, y * 16, 32, 32, Chest.chestItemSpawn[type], 1, true, 0, false, false);
                        return true;
                    }
                    NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, (float)type, num107, 0, 0);
                    return true;
                }
                else if (b7 == 2)
                {
                    int num108 = WorldGen.PlaceChest(x, y, 88, false, type);
                    if (num108 == -1)
                    {
                        NetMessage.SendData(34, bufferId, -1, "", (int)b7, (float)x, (float)y, (float)type, num108, 0, 0);
                        Item.NewItem(x * 16, y * 16, 32, 32, Chest.dresserItemSpawn[type], 1, true, 0, false, false);
                        return true;
                    }
                    NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, (float)type, num108, 0, 0);
                    return true;
                }
                else
                {
                    var tile2 = Main.tile[x, y];
                    if (tile2.type == 21 && b7 == 1)
                    {
                        if (tile2.frameX % 36 != 0)
                        {
                            x--;
                        }
                        if (tile2.frameY % 36 != 0)
                        {
                            y--;
                        }
                        int number = Chest.FindChest(x, y);
                        WorldGen.KillTile(x, y, false, false, false);
                        if (!tile2.active())
                        {
                            NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, 0f, number, 0, 0);
                            return true;
                        }
                        return true;
                    }
                    else
                    {
                        if (tile2.type != 88 || b7 != 3)
                        {
                            return true;
                        }
                        x -= (int)(tile2.frameX % 54 / 18);
                        if (tile2.frameY % 36 != 0)
                        {
                            y--;
                        }
                        int number2 = Chest.FindChest(x, y);
                        WorldGen.KillTile(x, y, false, false, false);
                        if (!tile2.active())
                        {
                            NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, 0f, number2, 0, 0);
                            return true;
                        }
                        return true;
                    }
                }
            }
            else
            {
                int id = (int)buffer.reader.ReadInt16();
                if (b7 == 0)
                {
                    if (id == -1)
                    {
                        WorldGen.KillTile(x, y, false, false, false);
                        return true;
                    }
                    WorldGen.PlaceChestDirect(x, y, 21, type, id);
                    return true;
                }
                else
                {
                    if (b7 != 2)
                    {
                        Chest.DestroyChestDirect(x, y, id);
                        WorldGen.KillTile(x, y, false, false, false);
                        return true;
                    }
                    if (id == -1)
                    {
                        WorldGen.KillTile(x, y, false, false, false);
                        return true;
                    }
                    WorldGen.PlaceDresserDirect(x, y, 88, type, id);
                    return true;
                }
            }
            return true;
        }
コード例 #11
0
        /// <summary>
        /// Parses and process a command from a sender
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="line">Line.</param>
        public void ParseAndProcess(ISender sender, string line)
        {
            var ctx = new HookContext
            {
                Sender = sender,
            #if Full_API
                Player = sender as Player
            #endif
            };

            #if Full_API
            ctx.Connection = ctx.Player != null ? ctx.Player.Connection.Socket : null;
            #endif

            var hargs = new HookArgs.ServerCommand();

            try
            {
                CommandInfo info;

                var firstSpace = line.IndexOf(' ');

                if (firstSpace < 0)
                    firstSpace = line.Length;

                var prefix = line.Substring(0, firstSpace).ToLower();

                hargs.Prefix = prefix;

                if (FindStringCommand(prefix, out info))
                {
                    hargs.ArgumentString = (firstSpace < line.Length - 1 ? line.Substring(firstSpace + 1, line.Length - firstSpace - 1) : "").Trim();

                    HookPoints.ServerCommand.Invoke(ref ctx, ref hargs);

                    if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                        return;

                    if (ctx.Result != HookResult.CONTINUE && !CheckAccessLevel(info, sender))
                    {
                        sender.SendMessage("Permissions error", 255, 238, 130, 238);
                        return;
                    }

                    try
                    {
                        info.Run(sender, hargs.ArgumentString);
                    }
                    catch (NLua.Exceptions.LuaScriptException e)
                    {
                        if (e.IsNetException)
                        {
                            var ex = e.GetBaseException();
                            if (ex != null)
                            {
                                if (ex is CommandError)
                                {
                                    sender.SendMessage(prefix + ": " + ex.Message);
                                    info.ShowHelp(sender);
                                }
                            }
                        }
                    }
                    catch (ExitException e)
                    {
                        throw e;
                    }
                    catch (CommandError e)
                    {
                        sender.SendMessage(prefix + ": " + e.Message);
                        info.ShowHelp(sender);
                    }
                    return;
                }

                var args = new ArgumentList();
                var command = Tokenize(line, args);

                if (command != null)
                {
                    if (FindTokenCommand(command, out info))
                    {
                        hargs.Arguments = args;
                        hargs.ArgumentString = args.ToString();

                        foreach (BasePlugin plg in PluginManager._plugins.Values)
                        {
                            if (plg.commands.ContainsKey(command))
                            {
                                args.Plugin = plg;
                            }
                        }

                        HookPoints.ServerCommand.Invoke(ref ctx, ref hargs);

                        if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                            return;

                        if (ctx.Result != HookResult.CONTINUE && !CheckAccessLevel(info, sender))
                        {
                            sender.SendMessage("Permissions error", 255, 238, 130, 238);
                            return;
                        }

                        try
                        {
                            info.Run(sender, hargs.Arguments);
                        }
                        catch (NLua.Exceptions.LuaScriptException e)
                        {
                            if (e.IsNetException)
                            {
                                var ex = e.GetBaseException();
                                if (ex != null)
                                {
                                    if (ex is CommandError)
                                    {
                                        sender.SendMessage(command + ": " + ex.Message);
                                        info.ShowHelp(sender);
                                    }
                                }
                            }
                        }
                        catch (ExitException e)
                        {
                            throw e;
                        }
                        catch (CommandError e)
                        {
                            sender.SendMessage(command + ": " + e.Message);
                            info.ShowHelp(sender);
                        }
                        return;
                    }
                    else
                    {
                        sender.SendMessage(String.Format("No such command '{0}'.", command));
                    }
                }
            }
            catch (ExitException e)
            {
                throw e;
            }
            catch (TokenizerException e)
            {
                sender.SendMessage(e.Message);
            }
        }
コード例 #12
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];
            var conn = Netplay.Clients[bufferId];

            if (Main.netMode != 2)
            {
                return true;
            }
            var clientPassword = buffer.reader.ReadString();
            if (conn.State == -1)
            {
                var ctx = new HookContext
                {
                    Connection = conn.Socket,
                    Player = player,
                    Sender = player
                };

                var args = new TDSMHookArgs.ServerPassReceived
                {
                    Password = clientPassword,
                };

                TDSMHookPoints.ServerPassReceived.Invoke(ref ctx, ref args);

                if (ctx.CheckForKick())
                    return true;

                if (ctx.Result == HookResult.ASK_PASS)
                {
                    NetMessage.SendData((int)Packet.PASSWORD_REQUEST, bufferId);
                    return true;
                }
                else if (ctx.Result == HookResult.CONTINUE || clientPassword == Netplay.ServerPassword)
                {
                    Netplay.Clients[bufferId].State = 1;
                    NetMessage.SendData((int)Packet.CONNECTION_RESPONSE, bufferId, -1, "", 0, 0f, 0f, 0f, 0, 0, 0);
                    return true;
                }

                conn.Kick("Incorrect server password.");
            }
            else if (conn.State == (int)ConnectionState.AwaitingUserPassword)
            {
                //var name = player.name ?? "";

                var ctx = new HookContext
                {
                    Connection = conn.Socket,
                    Player = player,
                    Sender = player
                };

                var args = new TDSMHookArgs.PlayerPassReceived
                {
                    Password = clientPassword
                };

                TDSMHookPoints.PlayerPassReceived.Invoke(ref ctx, ref args);

                if (ctx.CheckForKick())
                    return true;

                if (ctx.Result == HookResult.ASK_PASS)
                {
                    NetMessage.SendData((int)Packet.PASSWORD_REQUEST, bufferId);
                    return true;
                }
                else // HookResult.DEFAULT
                {
                    //ProgramLog.Error.Log("Accepted player: " + player.name + "/" + (player.AuthenticatedAs ?? "null"));

                    //Continue with world request
                    Netplay.Clients[bufferId].State = 2;
                    Netplay.Clients[bufferId].ResetSections();
                    NetMessage.SendData(7, bufferId, -1, "", 0, 0f, 0f, 0f, 0, 0, 0);
                    Main.SyncAnInvasion(bufferId);

                    return true;
                }
            }

            return true;
        }
コード例 #13
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            var isConnection = player == null || player.Connection == null || !player.active;
            if (isConnection)
            {
                //player = new Player();
            }
            player.whoAmI = bufferId;
            player.IPAddress = Netplay.Clients[bufferId].Socket.GetRemoteAddress().GetIdentifier();

            if (bufferId == Main.myPlayer && !Main.ServerSideCharacter)
            {
                return true;
            }

            var data = new TDSMHookArgs.PlayerDataReceived()
            {
                IsConnecting = isConnection
            };

            data.Parse(buffer.reader, start, length);
            //            Skip(read);
            //
            //            if (data.Hair >= MAX_HAIR_ID)
            //            {
            //                data.Hair = 0;
            //            }
            //
            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player,
            };
            //
            TDSMHookPoints.PlayerDataReceived.Invoke(ref ctx, ref data);
            //
            if (ctx.CheckForKick())
                return true;

            if (!data.NameChecked)
            {
                string error;
                if (!data.CheckName(out error))
                {
                    player.Connection.Kick(error);
                    return true;
                }
            }

            //            string address = player.IPAddress.Split(':')[0];
            //            if (!data.BansChecked)
            //            {
            //                if (Server.Bans.Contains(address) || Server.Bans.Contains(data.Name))
            //                {
            //                    ProgramLog.Admin.Log("Prevented banned user {0} from accessing the server.", data.Name);
            //                    conn.Kick("You are banned from this server.");
            //                    return;
            //                }
            //            }
            //
            //            if (!data.WhitelistChecked && Server.WhitelistEnabled)
            //            {
            //                if (!Server.Whitelist.Contains(address) && !Server.Whitelist.Contains(data.Name))
            //                {
            //                    ProgramLog.Admin.Log("Prevented non whitelisted user {0} from accessing the server.", data.Name);
            //                    conn.Kick("You do not have access to this server.");
            //                    return;
            //                }
            //            }

            data.Apply(player);

            {
                var lname = player.name.ToLower();

                foreach (var otherPlayer in Main.player)
                {
                    //                            var otherSlot = Terraria.Netplay.Clients[otherPlayer.whoAmI];
                    if (otherPlayer.name != null && lname == otherPlayer.name.ToLower() && otherPlayer.whoAmI != bufferId) // && otherSlot.State >= SlotState.CONNECTED)
                    {
                        player.Kick("A \"" + otherPlayer.name + "\" is already on this server.");
                        return true;
                    }
                }
            }

            if (isConnection)
            {
                if (ctx.Result == HookResult.ASK_PASS)
                {
                    Netplay.Clients[bufferId].State = (int)ConnectionState.AwaitingUserPassword;
                    //                    conn.State = SlotState.PLAYER_AUTH;

                    //                    var msg = NewNetMessage.PrepareThreadInstance();
                    //                    msg.PasswordRequest();
                    //                    conn.Send(msg.Output);
                    NetMessage.SendData((int)Packet.PASSWORD_REQUEST, bufferId);

                    return true;
                }
                else // HookResult.DEFAULT
                {
                    // don't allow replacing connections for guests, but do for registered users
                    //                    if (conn.State < SlotState.PLAYING)

                    //conn.Queue = (int)loginEvent.Priority; // actual queueing done on world request message

                    // and now decide whether to queue the connection
                    //SlotManager.Schedule (conn, (int)loginEvent.Priority);

                    //if (Netplay.Clients[bufferId].State == -2)
                    //{
                    //    //Netplay.Clients[bufferId].State = 1;
                    //    ProgramLog.Error.Log("User password accepted, send world");
                    //}
                    //else
                    //{
                    //Netplay.Clients[bufferId].State = 1;
                    //NetMessage.SendData((int)Packet.CONNECTION_RESPONSE, bufferId, -1, "", 0, 0f, 0f, 0f, 0, 0, 0);
                    //}
                }
            }

            if (player.name.Length > Player.nameLen)
            {
                NetMessage.SendData(2, bufferId, -1, "Name is too long.");
                return true;
            }
            if (player.name == "")
            {
                NetMessage.SendData(2, bufferId, -1, "Empty name.");
                return true;
            }

            Netplay.Clients[bufferId].Name = player.name;

            OTA.Callbacks.VanillaHooks.OnPlayerEntering(player);

            return true;
        }
コード例 #14
0
        private static void ProcessPlayerData(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            var isConnection = player == null || player.Connection == null || !player.active;
            if (isConnection)
            {
                //player = new Player();
            }
            player.whoAmI = bufferId;
            player.IPAddress = Netplay.Clients[bufferId].Socket.GetRemoteAddress().GetIdentifier();

            if (bufferId == Main.myPlayer && !Main.ServerSideCharacter)
            {
                return;
            }

            var data = new HookArgs.PlayerDataReceived()
            {
                IsConnecting = isConnection
            };

            data.Parse(buffer.reader, start, length);
            //            Skip(read);
            //
            //            if (data.Hair >= MAX_HAIR_ID)
            //            {
            //                data.Hair = 0;
            //            }
            //
            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player,
            };
            //
            HookPoints.PlayerDataReceived.Invoke(ref ctx, ref data);
            //
            if (ctx.CheckForKick())
                return;

            if (!data.NameChecked)
            {
                string error;
                if (!data.CheckName(out error))
                {
                    player.Connection.Kick(error);
                    return;
                }
            }

            //            string address = player.IPAddress.Split(':')[0];
            //            if (!data.BansChecked)
            //            {
            //                if (Server.Bans.Contains(address) || Server.Bans.Contains(data.Name))
            //                {
            //                    ProgramLog.Admin.Log("Prevented banned user {0} from accessing the server.", data.Name);
            //                    conn.Kick("You are banned from this server.");
            //                    return;
            //                }
            //            }
            //
            //            if (!data.WhitelistChecked && Server.WhitelistEnabled)
            //            {
            //                if (!Server.Whitelist.Contains(address) && !Server.Whitelist.Contains(data.Name))
            //                {
            //                    ProgramLog.Admin.Log("Prevented non whitelisted user {0} from accessing the server.", data.Name);
            //                    conn.Kick("You do not have access to this server.");
            //                    return;
            //                }
            //            }

            data.Apply(player);

            {
                var lname = player.Name.ToLower();

                foreach (var otherPlayer in Main.player)
                {
                    //                            var otherSlot = Terraria.Netplay.Clients[otherPlayer.whoAmI];
                    if (otherPlayer.Name != null && lname == otherPlayer.Name.ToLower() && otherPlayer.whoAmI != bufferId) // && otherSlot.State >= SlotState.CONNECTED)
                    {
                        player.Kick("A \"" + otherPlayer.Name + "\" is already on this server.");
                        return;
                    }
                }
            }

            if (isConnection)
            {
                if (ctx.Result == HookResult.ASK_PASS)
                {
                    Netplay.Clients[bufferId].State = -2;
                    //                    conn.State = SlotState.PLAYER_AUTH;

                    //                    var msg = NewNetMessage.PrepareThreadInstance();
                    //                    msg.PasswordRequest();
                    //                    conn.Send(msg.Output);
                    NetMessage.SendData((int)Packet.PASSWORD_REQUEST, bufferId);

                    return;
                }
                else // HookResult.DEFAULT
                {
                    // don't allow replacing connections for guests, but do for registered users
                    //                    if (conn.State < SlotState.PLAYING)

                    //conn.Queue = (int)loginEvent.Priority; // actual queueing done on world request message

                    // and now decide whether to queue the connection
                    //SlotManager.Schedule (conn, (int)loginEvent.Priority);

                    //if (Netplay.Clients[bufferId].State == -2)
                    //{
                    //    //Netplay.Clients[bufferId].State = 1;
                    //    ProgramLog.Error.Log("User password accepted, send world");
                    //}
                    //else
                    //{
                    //Netplay.Clients[bufferId].State = 1;
                    //NetMessage.SendData((int)Packet.CONNECTION_RESPONSE, bufferId, -1, "", 0, 0f, 0f, 0f, 0, 0, 0);
                    //}
                }
            }

            if (player.name.Length > Player.nameLen)
            {
                NetMessage.SendData(2, bufferId, -1, "Name is too long.");
                return;
            }
            if (player.name == "")
            {
                NetMessage.SendData(2, bufferId, -1, "Empty name.");
                return;
            }

            Netplay.Clients[bufferId].Name = player.name;
            OTA.Callbacks.VanillaHooks.OnPlayerEntering(player);

            return;

            //            int num6 = (int)buffer.reader.ReadByte();
            //            if (Main.netMode == 2)
            //            {
            //                num6 = bufferId;
            //            }
            //            if (num6 == Main.myPlayer && !Main.ServerSideCharacter)
            //            {
            //                return;
            //            }
            //            Player player = Main.player[num6];
            //            player.whoAmI = num6;
            //            player.skinVariant = (int)buffer.reader.ReadByte();
            //            player.skinVariant = (int)MathHelper.Clamp((float)player.skinVariant, 0, 7);
            //            player.hair = (int)buffer.reader.ReadByte();
            //            if (player.hair >= 134)
            //            {
            //                player.hair = 0;
            //            }
            //            player.name = buffer.reader.ReadString().Trim().Trim();
            //            player.hairDye = buffer.reader.ReadByte();
            //            BitsByte bitsByte = buffer.reader.ReadByte();
            //            for (int num7 = 0; num7 < 8; num7++)
            //            {
            //                player.hideVisual[num7] = bitsByte[num7];
            //            }
            //            bitsByte = buffer.reader.ReadByte();
            //            for (int num8 = 0; num8 < 2; num8++)
            //            {
            //                player.hideVisual[num8 + 8] = bitsByte[num8];
            //            }
            //            player.hideMisc = buffer.reader.ReadByte();
            //            player.hairColor = buffer.reader.ReadRGB();
            //            player.skinColor = buffer.reader.ReadRGB();
            //            player.eyeColor = buffer.reader.ReadRGB();
            //            player.shirtColor = buffer.reader.ReadRGB();
            //            player.underShirtColor = buffer.reader.ReadRGB();
            //            player.pantsColor = buffer.reader.ReadRGB();
            //            player.shoeColor = buffer.reader.ReadRGB();
            //            BitsByte bitsByte2 = buffer.reader.ReadByte();
            //            player.difficulty = 0;
            //            if (bitsByte2[0])
            //            {
            //                Player expr_B25 = player;
            //                expr_B25.difficulty += 1;
            //            }
            //            if (bitsByte2[1])
            //            {
            //                Player expr_B3F = player;
            //                expr_B3F.difficulty += 2;
            //            }
            //            if (player.difficulty > 2)
            //            {
            //                player.difficulty = 2;
            //            }
            //            player.extraAccessory = bitsByte2[2];
            //            if (Main.netMode != 2)
            //            {
            //                return;
            //            }
            //            bool flag = false;
            //            if (Netplay.Clients[bufferId].State < 10)
            //            {
            //                for (int num9 = 0; num9 < 255; num9++)
            //                {
            //                    if (num9 != num6 && player.name == Main.player[num9].name && Netplay.Clients[num9].IsActive)
            //                    {
            //                        flag = true;
            //                    }
            //                }
            //            }
            //            if (flag)
            //            {
            //                NetMessage.SendData(2, bufferId, -1, player.name + " " + Lang.mp[5], 0, 0, 0, 0, 0, 0, 0);
            //                return;
            //            }
            //            if (player.name.Length > Player.nameLen)
            //            {
            //                NetMessage.SendData(2, bufferId, -1, "Name is too long.", 0, 0, 0, 0, 0, 0, 0);
            //                return;
            //            }
            //            if (player.name == "")
            //            {
            //                NetMessage.SendData(2, bufferId, -1, "Empty name.", 0, 0, 0, 0, 0, 0, 0);
            //                return;
            //            }
            //
            //            var ctx = new HookContext
            //                {
            //                    Connection = player.conn,
            //                    Player = player,
            //                    Sender = player,
            //                };
            //
            //            HookPoints.PlayerDataReceived.Invoke (ref ctx, ref data);
            //
            //            if (ctx.CheckForKick ())
            //                return;
            //
            //            if (! data.NameChecked)
            //            {
            //                string error;
            //                if (! data.CheckName (out error))
            //                {
            //                    conn.Kick (error);
            //                    return;
            //                }
            //            }
            //
            //            if (! data.BansChecked)
            //            {
            //                string address = conn.RemoteAddress.Split(':')[0];
            //
            //                if (Server.BanList.containsException (address) || Server.BanList.containsException (data.Name))
            //                {
            //                    ProgramLog.Admin.Log ("Prevented user {0} from accessing the server.", data.Name);
            //                    conn.Kick ("You are banned from this server.");
            //                    return;
            //                }
            //            }
            //
            //            data.Apply (player);
            //
            //            if (ctx.Result == HookResult.ASK_PASS)
            //            {
            //                conn.State = SlotState.PLAYER_AUTH;
            //
            //                var msg = NetMessage.PrepareThreadInstance ();
            //                msg.PasswordRequest ();
            //                conn.Send (msg.Output);
            //
            //                return;
            //            }
            //            else // HookResult.DEFAULT
            //            {
            //                // don't allow replacing connections for guests, but do for registered users
            //                if (conn.State < SlotState.PLAYING)
            //                {
            //                    var lname = player.Name.ToLower();
            //
            //                    foreach (var otherPlayer in Main.players)
            //                    {
            //                        var otherSlot = NetPlay.slots[otherPlayer.whoAmi];
            //                        if (otherPlayer.Name != null && lname == otherPlayer.Name.ToLower() && otherSlot.state >= SlotState.CONNECTED)
            //                        {
            //                            conn.Kick ("A \"" + otherPlayer.Name + "\" is already on this server.");
            //                            return;
            //                        }
            //                    }
            //                }
            //
            //                //conn.Queue = (int)loginEvent.Priority; // actual queueing done on world request message
            //
            //                // and now decide whether to queue the connection
            //                //SlotManager.Schedule (conn, (int)loginEvent.Priority);
            //
            //                //NetMessage.SendData (4, -1, -1, player.Name, whoAmI);
            //            }
            //
            //            Netplay.Clients[bufferId].Name = player.name;
            //            NetMessage.SendData(4, -1, bufferId, player.name, num6, 0, 0, 0, 0, 0, 0);
        }
コード例 #15
0
        public static bool OnNameCollision(Terraria.Player connectee, int bufferId)
        {
            var ctx = new HookContext();
            var args = new HookArgs.NameConflict()
            {
                Connectee = connectee,
                BufferId = bufferId
            };

            HookPoints.NameConflict.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick()) return false;

            return ctx.Result == HookResult.DEFAULT; //Continue on to kicking
        }
コード例 #16
0
        internal static void ProcessQueuedPlayerCommand(Tuple<Int32, String> message)
        {
            var bufferId = message.Item1;
            var chat = message.Item2;

            var player = Main.player[bufferId];
            var color = Color.White;

            if (Main.netMode != 2)
                return;

            var lowered = message.Item2.ToLower();
            if (lowered == Lang.mp[6] || lowered == Lang.mp[21])
            {
                var players = "";
                for (int i = 0; i < 255; i++)
                {
                    if (Main.player[i].active)
                    {
                        if (players.Length > 0)
                            players += ", ";
                        players += Main.player[i].name;
                    }
                }
                NetMessage.SendData((int)Packet.PLAYER_CHAT, bufferId, -1, Lang.mp[7] + " " + players + ".", 255, 255, 240, 20, 0, 0, 0);
                return;
            }
            else if (lowered.StartsWith("/me "))
            {
                NetMessage.SendData((int)Packet.PLAYER_CHAT, -1, -1, "*" + Main.player[bufferId].name + " " + chat.Substring(4), 255, 200, 100, 0, 0, 0, 0);
                return;
            }
            else if (lowered == Lang.mp[8])
            {
                NetMessage.SendData((int)Packet.PLAYER_CHAT, -1, -1, string.Concat(new object[]
                        {
                            "*",
                            Main.player[bufferId].name,
                            " ",
                            Lang.mp[9],
                            " ",
                            Main.rand.Next(1, 101)
                        }), 255, 255, 240, 20, 0, 0, 0);
                return;
            }
            else if (lowered.StartsWith("/p "))
            {
                int team = Main.player[bufferId].team;
                color = Main.teamColor[team];
                if (team != 0)
                {
                    for (int num74 = 0; num74 < 255; num74++)
                    {
                        if (Main.player[num74].team == team)
                        {
                            NetMessage.SendData((int)Packet.PLAYER_CHAT, num74, -1, chat.Substring(3), bufferId, (float)color.R, (float)color.G, (float)color.B, 0, 0, 0);
                        }
                    }
                    return;
                }
                NetMessage.SendData((int)Packet.PLAYER_CHAT, bufferId, -1, Lang.mp[10], 255, 255, 240, 20, 0, 0, 0);
                return;
            }
            else
            {
                if (Main.player[bufferId].difficulty == 2)
                    color = Main.hcColor;
                else if (Main.player[bufferId].difficulty == 1)
                    color = Main.mcColor;

                var ctx = new HookContext
                {
                    Connection = player.Connection.Socket,
                    Sender = player,
                    Player = player
                };

                var args = new TDSMHookArgs.PlayerChat
                {
                    Message = chat,
                    Color = color
                };

                TDSMHookPoints.PlayerChat.Invoke(ref ctx, ref args);

                if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                    return;

                if (ctx.Result == HookResult.RECTIFY)
                {
                    //The a plugin is enforcing the format
                    NetMessage.SendData((int)Packet.PLAYER_CHAT, -1, -1, args.Message, 255, (float)args.Color.R, (float)args.Color.G, (float)args.Color.B, 0, 0, 0);
                }
                else
                {
                    //Default <Player> ...
                    NetMessage.SendData((int)Packet.PLAYER_CHAT, -1, -1, args.Message, bufferId, (float)args.Color.R, (float)args.Color.G, (float)args.Color.B, 0, 0, 0);
                }

                if (Main.dedServ)
                {
                    ProgramLog.Chat.Log("<" + Main.player[bufferId].name + "> " + args.Message);
                }
            }
        }
コード例 #17
0
        private static void ProcessTileBreak(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];

            ActionType action = (ActionType)buffer.reader.ReadByte();
            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();
            short type = buffer.reader.ReadInt16();
            int style = (int)buffer.reader.ReadByte();
            bool fail = type == 1;

            if (!WorldGen.InWorld(x, y, 3))
            {
                return;
            }

            var player = Main.player[bufferId];

            //TODO implement the old methods
            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.PlayerWorldAlteration
            {
                X = x,
                Y = y,
                Action = action,
                Type = type,
                Style = style
            };

            HookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return;

            if (ctx.Result == HookResult.IGNORE)
                return;

            if (ctx.Result == HookResult.RECTIFY)
            {
                //Terraria.WorldGen.SquareTileFrame (x, y, true);
                NetMessage.SendTileSquare(bufferId, x, y, 1);
                return;
            }

            if (Main.tile[x, y] == null)
            {

            #if Full_API && !MemTile && !VANILLACOMPAT
                Main.tile[x, y] = new Tile();
            #elif Full_API && MemTile
                Main.tile[x, y] = new OTA.Memory.MemTile(x, y);
            #elif Full_API && VANILLACOMPAT && TileReady
                Main.tile[x, y] = new OTA.Memory.MemTile();
            #endif
            }

            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == ActionType.KillTile || action == ActionType.KillWall || action == ActionType.KillTile1)
                    {
                        Netplay.Clients[bufferId].SpamDeleteBlock += 1;
                    }
                    if (action == ActionType.PlaceTile || action == ActionType.PlaceWall)
                    {
                        Netplay.Clients[bufferId].SpamAddBlock += 1;
                    }
                }
                if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }
            switch (action)
            {
                case ActionType.KillTile:
                    WorldGen.KillTile(x, y, fail, false, false);
                    break;
                case ActionType.PlaceTile:
                    WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
                    break;
                case ActionType.KillWall:
                    WorldGen.KillWall(x, y, fail);
                    break;
                case ActionType.PlaceWall:
                    WorldGen.PlaceWall(x, y, (int)type, false);
                    break;
                case ActionType.KillTile1:
                    WorldGen.KillTile(x, y, fail, false, true);
                    break;
                case ActionType.PlaceWire:
                    WorldGen.PlaceWall(x, y, (int)type, false);
                    break;
                case ActionType.KillWire:
                    WorldGen.KillWire(x, y);
                    break;
                case ActionType.PoundTile:
                    WorldGen.PoundTile(x, y);
                    break;
                case ActionType.PlaceActuator:
                    WorldGen.PlaceActuator(x, y);
                    break;
                case ActionType.KillActuator:
                    WorldGen.KillActuator(x, y);
                    break;
                case ActionType.PlaceWire2:
                    WorldGen.PlaceWire2(x, y);
                    break;
                case ActionType.KillWire2:
                    WorldGen.KillWire2(x, y);
                    break;
                case ActionType.PlaceWire3:
                    WorldGen.PlaceWire3(x, y);
                    break;
                case ActionType.KillWire3:
                    WorldGen.KillWire3(x, y);
                    break;
                case ActionType.SlopeTile:
                    WorldGen.SlopeTile(x, y, (int)type);
                    break;
                case ActionType.FrameTrack:
                    Minecart.FrameTrack(x, y, true, false);
                    break;
            }
            if (Main.netMode != 2)
            {
                return;
            }
            NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0);
            if (action == ActionType.PlaceTile && type == 53)
            {
                NetMessage.SendTileSquare(-1, x, y, 1);
            }
        }
コード例 #18
0
        private static void ProcessChestOpen(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            if (Main.netMode != 2)
            {
                return;
            }
            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();

            if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7)
            {
                return;
            }

            int chestIndex = Chest.FindChest(x, y);
            if (chestIndex <= -1 || Chest.UsingChest(chestIndex) != -1)
            {
                return;
            }
            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Player = player,
                Sender = player
            };

            var args = new HookArgs.ChestOpenReceived
            {
                X = x,
                Y = y,
                ChestIndex = chestIndex
            };

            HookPoints.ChestOpenReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.DEFAULT && chestIndex > -1)
            {
                for (int i = 0; i < 40; i++)
                {
                    NetMessage.SendData(32, bufferId, -1, "", chestIndex, (float)i, 0, 0, 0, 0, 0);
                }
                NetMessage.SendData(33, bufferId, -1, "", chestIndex, 0, 0, 0, 0, 0, 0);
                Main.player[bufferId].chest = chestIndex;
                if (Main.myPlayer == bufferId)
                {
                    Main.recBigList = false;
                }
                //Recipe.FindRecipes();
                NetMessage.SendData(80, -1, bufferId, "", bufferId, (float)chestIndex, 0, 0, 0, 0, 0);
                //if (Main.tile[x, y].frameX >= 36 && Main.tile[x, y].frameX < 72)
                //{
                //    AchievementsHelper.HandleSpecialEvent(Main.player[bufferId], 16);
                //}
            }
        }
コード例 #19
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];

            var npcId = (int)buffer.reader.ReadInt16();
            var damage = (int)buffer.reader.ReadInt16();
            var knockBack = buffer.reader.ReadSingle();
            var hitDirection = (int)(buffer.reader.ReadByte() - 1);
            var critical = buffer.reader.ReadByte();

            if (Main.netMode == 2)
            {
                if (damage < 0) damage = 0;
                Main.npc[npcId].PlayerInteraction(buffer.whoAmI);
            }

            var ply = Main.player[bufferId];
            var ctx = new HookContext()
            {
                Sender = ply,
                Player = ply
            };
            var args = new TDSMHookArgs.NpcHurtReceived()
            {
                Victim = Terraria.Main.npc[npcId],
                Damage = ply.inventory[ply.selectedItem].damage,
                HitDirection = ply.direction,
                Knockback = ply.inventory[ply.selectedItem].knockBack,
                Critical = false
            };

            TDSMHookPoints.NpcHurtReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE) return true;

            if (damage >= 0)
                Main.npc[npcId].StrikeNPC(damage, knockBack, hitDirection, critical == 1, false, true);
            else
            {
                Main.npc[npcId].life = 0;
                Main.npc[npcId].HitEffect(0, 10.0);
                Main.npc[npcId].active = false;
            }

            if (Main.netMode != 2)
                return true;

            NetMessage.SendData(28, -1, buffer.whoAmI, String.Empty, npcId, (float)damage, knockBack, (float)hitDirection, (int)critical);
            if (Main.npc[npcId].life <= 0)
                NetMessage.SendData(23, -1, -1, String.Empty, npcId);
            else Main.npc[npcId].netUpdate = true;

            if (Main.npc[npcId].realLife < 0)
                return true;

            if (Main.npc[Main.npc[npcId].realLife].life <= 0)
            {
                NetMessage.SendData(23, -1, -1, String.Empty, Main.npc[npcId].realLife);
                return true;
            }

            Main.npc[Main.npc[npcId].realLife].netUpdate = true;
            return true;
        }
コード例 #20
0
        private static void ProcessWriteSign(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];
            var player = Main.player[bufferId];

            int signId = (int)buffer.reader.ReadInt16();
            int x = (int)buffer.reader.ReadInt16();
            int y = (int)buffer.reader.ReadInt16();
            string text = buffer.reader.ReadString();

            string existing = null;
            if (Main.sign[signId] != null)
            {
                existing = Main.sign[signId].text;
            }

            Main.sign[signId] = new Sign();
            Main.sign[signId].x = x;
            Main.sign[signId].y = y;

            Sign.TextSign(signId, text);
            int ply = (int)buffer.reader.ReadByte();

            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.SignTextSet
            {
                X = x,
                Y = y,
                SignIndex = signId,
                Text = text,
                OldSign = Main.sign[signId],
            };

            HookPoints.SignTextSet.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick() || ctx.Result == HookResult.IGNORE)
                return;

            if (Main.netMode == 2 && existing != text)
            {
                ply = bufferId;
                NetMessage.SendData(47, -1, bufferId, "", signId, (float)ply, 0, 0, 0, 0, 0);
            }

            if (Main.netMode == 1 && ply == Main.myPlayer && Main.sign[signId] != null)
            {
                Main.playerInventory = false;
                Main.player[Main.myPlayer].talkNPC = -1;
                Main.npcChatCornerItem = 0;
                Main.editSign = false;
                Main.PlaySound(10, -1, -1, 1);
                Main.player[Main.myPlayer].sign = signId;
                Main.npcChatText = Main.sign[signId].text;
            }
        }