コード例 #1
0
        void OnAlter(ref HookContext ctx, ref HookArgs.PlayerWorldAlteration args)
        {
            var player = ctx.Player;

            if (player == null && ctx.Sender is Projectile)
            {
                player = (ctx.Sender as Projectile).Creator as Player;
            }

            if (player == null || player.Name == null)
            {
                ProgramLog.Error.Log("<Restrict> Invalid player in OnAlter.");
                ctx.SetResult(HookResult.IGNORE);
                return;
            }

            if (!restrictGuests)
            {
                return;
            }

            if (player.AuthenticatedAs == null)
            {
                ctx.SetResult(HookResult.RECTIFY);
                player.sendMessage("<Restrict> You are not allowed to alter the world as a guest.");
                player.sendMessage("<Restrict> Type \"/reg password\" to request registration.");
            }
            else if (IsRestrictedForUser(ctx.Player, WorldAlter))
            {
                ctx.SetResult(HookResult.RECTIFY);
                player.sendMessage("<Restrict> You are not allowed to alter the world without permissions.");
            }
        }
コード例 #2
0
 void OnPlayerWorldAlteration(ref HookContext ctx, ref HookArgs.PlayerWorldAlteration args)
 {
     if (!tileBreakageAllowed)
     {
         return;
     }
     Log("Cancelled Tile change of Player: " + ctx.Player.Name);
     ctx.SetResult(HookResult.RECTIFY);
 }
コード例 #3
0
        void OnPlayerWorldAlteration(ref HookContext ctx, ref HookArgs.PlayerWorldAlteration args)
        {
            Vector2 Position = new Vector2(args.X, args.Y);

            if (args.TileWasPlaced && args.Type == SelectorItem && selection.isInSelectionlist(ctx.Player) && ctx.Player.Op)
            {
                ctx.SetResult(HookResult.RECTIFY);
                SelectorPos = !SelectorPos;

                Vector2[] mousePoints = selection.GetSelection(ctx.Player);

                if (!SelectorPos)
                {
                    mousePoints[0] = Position;
                }
                else
                {
                    mousePoints[1] = Position;
                }

                selection.SetSelection(ctx.Player, mousePoints);

                ctx.Player.sendMessage(String.Format("You have selected block at {0},{1}, {2} position",
                                                     Position.X, Position.Y, (!SelectorPos) ? "First" : "Second"), ChatColor.Green);
                return;
            }

            foreach (Region rgn in regionManager.Regions)
            {
                if (rgn.HasPoint(Position))
                {
                    if (IsRestrictedForUser(ctx.Player, rgn, ((args.TileWasRemoved || args.WallWasRemoved) ? TileBreak : TilePlace)))
                    {
                        ctx.SetResult(WorldAlter);
                        ctx.Player.sendMessage("You cannot edit this area!", ChatColor.Red);
                        return;
                    }
                }
            }
        }
コード例 #4
0
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            byte  action = ReadByte(readBuffer);
            int   x      = (int)ReadInt16(readBuffer);
            int   y      = (int)ReadInt16(readBuffer);
            short type   = ReadInt16(readBuffer);
            int   style  = (int)ReadByte(readBuffer);
            bool  fail   = type == 1;

            var player = Main.player[whoAmI];

            if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
            {
                player.Kick("Out of range tile received from client.");
                return;
            }

            if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
            {
                Tools.WriteLine("{0} @ {1}: {2} attempted to alter world in unloaded tile.");
                return;
            }

            //TODO implement the old methods
            var ctx = new HookContext
            {
                Connection = (Terraria.Netplay.Clients[whoAmI] as ServerSlot).conn,
                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);

                NewNetMessage.SendTileSquare(whoAmI, x, y, 1);
                return;
            }

            if (Main.tile[x, y] == null)
            {
                Main.tile[x, y] = new Tile();
            }
            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == 0 || action == 2 || action == 4)
                    {
                        Terraria.Netplay.Clients[whoAmI].SpamDeleteBlock += 1f;
                    }
                    if (action == 1 || action == 3)
                    {
                        Terraria.Netplay.Clients[whoAmI].SpamAddBlock += 1f;
                    }
                }
                if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }

            if (action == 0)
            {
                WorldGen.KillTile(x, y, fail, false, false);
            }
            if (action == 1)
            {
                WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
            }
            if (action == 2)
            {
                WorldGen.KillWall(x, y, fail);
            }
            if (action == 3)
            {
                WorldGen.PlaceWall(x, y, (int)type, false);
            }
            if (action == 4)
            {
                WorldGen.KillTile(x, y, fail, false, true);
            }
            if (action == 5)
            {
                WorldGen.PlaceWire(x, y);
            }
            if (action == 6)
            {
                WorldGen.KillWire(x, y);
            }
            if (action == 7)
            {
                WorldGen.PoundTile(x, y);
            }
            if (action == 8)
            {
                WorldGen.PlaceActuator(x, y);
            }
            if (action == 9)
            {
                WorldGen.KillActuator(x, y);
            }
            if (action == 10)
            {
                WorldGen.PlaceWire2(x, y);
            }
            if (action == 11)
            {
                WorldGen.KillWire2(x, y);
            }
            if (action == 12)
            {
                WorldGen.PlaceWire3(x, y);
            }
            if (action == 13)
            {
                WorldGen.KillWire3(x, y);
            }
            if (action == 14)
            {
                WorldGen.SlopeTile(x, y, (int)type);
            }
            if (action == 15)
            {
                Minecart.FrameTrack(x, y, true, false);
            }
            if (Main.netMode != 2)
            {
                return;
            }
            NewNetMessage.SendData(17, -1, whoAmI, String.Empty, (int)action, (float)x, (float)y, (float)type, style);
            if (action == 1 && type == 53)
            {
                NewNetMessage.SendTileSquare(-1, x, y, 1);
                return;
            }
        }
        private static void ProcessTileBreak(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];

            byte  action = 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,
                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)
            {
                Main.tile[x, y] = new Tile();
            }

            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == 0 || action == 2 || action == 4)
                    {
                        Netplay.Clients[bufferId].SpamDeleteBlock += 1;
                    }
                    if (action == 1 || action == 3)
                    {
                        Netplay.Clients[bufferId].SpamAddBlock += 1;
                    }
                }
                if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }
            if (action == 0)
            {
                WorldGen.KillTile(x, y, fail, false, false);
            }
            if (action == 1)
            {
                WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
            }
            if (action == 2)
            {
                WorldGen.KillWall(x, y, fail);
            }
            if (action == 3)
            {
                WorldGen.PlaceWall(x, y, (int)type, false);
            }
            if (action == 4)
            {
                WorldGen.KillTile(x, y, fail, false, true);
            }
            if (action == 5)
            {
                WorldGen.PlaceWire(x, y);
            }
            if (action == 6)
            {
                WorldGen.KillWire(x, y);
            }
            if (action == 7)
            {
                WorldGen.PoundTile(x, y);
            }
            if (action == 8)
            {
                WorldGen.PlaceActuator(x, y);
            }
            if (action == 9)
            {
                WorldGen.KillActuator(x, y);
            }
            if (action == 10)
            {
                WorldGen.PlaceWire2(x, y);
            }
            if (action == 11)
            {
                WorldGen.KillWire2(x, y);
            }
            if (action == 12)
            {
                WorldGen.PlaceWire3(x, y);
            }
            if (action == 13)
            {
                WorldGen.KillWire3(x, y);
            }
            if (action == 14)
            {
                WorldGen.SlopeTile(x, y, (int)type);
            }
            if (action == 15)
            {
                Minecart.FrameTrack(x, y, true, false);
            }
            if (Main.netMode != 2)
            {
                return;
            }
            NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0);
            if (action == 1 && type == 53)
            {
                NetMessage.SendTileSquare(-1, x, y, 1);
            }
        }
コード例 #6
0
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            var slot = NetPlay.slots[whoAmI];

            byte tileAction = readBuffer[num++];
            int  x          = BitConverter.ToInt32(readBuffer, num);

            num += 4;
            int y = BitConverter.ToInt32(readBuffer, num);

            num += 4;

            byte tileType = readBuffer[num++];
            byte style    = readBuffer[num];
            bool failFlag = (tileType == 1);

            if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
            {
                slot.Kick("Out of range tile received from client.");
                return;
            }

            if (!NetPlay.slots[whoAmI].tileSection[NetPlay.GetSectionX(x), NetPlay.GetSectionY(y)])
            {
                ProgramLog.Debug.Log("{0} @ {1}: {2} attempted to alter world in unloaded tile.");
                return;
            }

            var editor  = staticEditor;            //new SandboxEditor<PlayerSandbox> ();
            var sandbox = editor.Sandbox;

            lock (WorldModify.playerEditLock)
            {
                sandbox.Initialize();
                var player = Main.players[whoAmI];

                switch (tileAction)
                {
                case 0:
                    editor.KillTile(x, y, failFlag);
                    //[TODO] Get block modifications outside the x,y axis to update on Client end
                    //WorldModify.KillTile(null, x, y, failFlag);
                    break;

                case 1:
                    if (editor.PlaceTile(x, y, (int)tileType, false, true, whoAmI, style))
                    {
                        if (tileType == 15 && player.direction == 1)
                        {
                            sandbox.SetFrameXAt(x, y, (short)(sandbox.FrameXAt(x, y) + 18));
                            sandbox.SetFrameXAt(x, y - 1, (short)(sandbox.FrameXAt(x, y - 1) + 18));
                        }
                        else if (tileType == 106)
                        {
                            editor.SquareTileFrame(x, y, true);
                        }
                    }
                    break;

                case 2:
                    editor.KillWall(x, y, failFlag);
                    break;

                case 3:
                    editor.PlaceWall(x, y, (int)tileType, false);
                    break;

                case 4:
                    editor.KillTile(x, y, failFlag, false, true);
                    break;

                case 5:
                    editor.PlaceWire(x, y);
                    break;

                case 6:
                    editor.KillWire(x, y);
                    break;
                }

//				if (sandbox.ChangedTileCount == 0)
//					return;

                var ctx = new HookContext
                {
                    Connection = NetPlay.slots[whoAmI].conn,
                    Sender     = player,
                    Player     = player,
                };

                var args = new HookArgs.PlayerWorldAlteration
                {
                    X       = x, Y = y,
                    Action  = tileAction,
                    Type    = tileType,
                    Style   = style,
                    Sandbox = sandbox,
                };

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

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

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

                if (ctx.Result != HookResult.RECTIFY)
                {
                    if (!args.TypeChecked)
                    {
                        switch (tileAction)
                        {
                        case 1:
                        case 4:
                            if (tileType >= Main.MAX_TILE_SETS)
                            {
                                slot.Kick("Invalid tile type received from client.");
                                return;
                            }
                            break;

                        case 3:
                            if (tileType >= Main.MAX_WALL_SETS)
                            {
                                slot.Kick("Invalid wall type received from client.");
                                return;
                            }
                            break;
                        }
                    }

                    if (!failFlag)
                    {
                        if (tileAction == 0 || tileAction == 2 || tileAction == 4)
                        {
                            NetPlay.slots[whoAmI].spamDelBlock += 1f;
                        }
                        else if (tileAction == 1 || tileAction == 3)
                        {
                            NetPlay.slots[whoAmI].spamAddBlock += 1f;
                        }
                    }

                    NetMessage.SendData(17, -1, whoAmI, "", (int)tileAction, (float)x, (float)y, (float)tileType, style);

                    sandbox.Apply(Main.players[whoAmI]);

                    return;
                }

                if (player.rowsToRectify.Count > 0 || sandbox.changedRows.Count > 0)
                {
                    lock (player.rowsToRectify)
                    {
                        foreach (var kv in sandbox.changedRows)
                        {
                            int  y0 = kv.Key;
                            var  x1 = kv.Value.Min;
                            var  x2 = kv.Value.Max;
                            uint row;
                            if (player.rowsToRectify.TryGetValue((ushort)y0, out row))
                            {
                                player.rowsToRectify[(ushort)y0] = (uint)(Math.Min(x1, row >> 16) << 16) | (uint)(Math.Max(x2, row & 0xffff));
                            }
                            else
                            {
                                player.rowsToRectify[(ushort)y0] = (uint)(x1 << 16) | (uint)x2;
                            }
                        }
                    }
                }
            }

            //if (tileAction == 1 && tileType == 53)
            //{
            //    NetMessage.SendTileSquare(-1, x, y, 1);
            //}
        }