MakeTeleport() static private method

static private MakeTeleport ( int id, Position pos ) : Packet
id int
pos Position
return Packet
Ejemplo n.º 1
0
        public void MoveBot()
        {
            Position oldPos = Pos; //curent pos
            Position delta  = new Position(
                (short)(nextPos.X - oldPos.X),
                (short)(nextPos.Y - oldPos.Y),
                (short)(nextPos.Z - oldPos.Z));

            //set the packet
            Packet packet = PacketWriter.MakeMoveRotate(ID, new Position
            {
                X = delta.X,
                Y = delta.Y,
                Z = delta.Z,
                R = Pos.R,
                L = 0
            });

            //send packet to everyone in the world
            if (nextPos == oldPos && oldPos != null)
            {
                world.Players.Send(PacketWriter.MakeTeleport(ID, new Position(world.Map.Spawn.X, world.Map.Spawn.Y, world.Map.Spawn.Z)));
                Pos = new Position(world.Map.Spawn.X, world.Map.Spawn.Y, world.Map.Spawn.Z, Pos.R, Pos.L);
            }
            else
            {
                world.Players.Send(packet);
                Pos = nextPos;
            }
            world.Players.Message(Pos.ToBlockCoords().ToString());
        }
Ejemplo n.º 2
0
        public void MakeRandomDecision()
        {
            int rand = new Random().Next(1, 5);

            switch (rand)
            {
            case 1:
                Pos.R += 15;
                world.Players.Send(PacketWriter.MakeRotate(ID, Pos));
                break;

            case 2:
                Pos.R += 90;
                world.Players.Send(PacketWriter.MakeRotate(ID, Pos));
                break;

            case 3:
                int player = new Random().Next(0, world.Players.Count() - 1);
                world.Players.Send(PacketWriter.MakeTeleport(ID, world.Players[player].Position));
                Pos = world.Players[player].Position;
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
 void TP(Player player, Command cmd)
 {
     if (player.Can(Permissions.Teleport))
     {
         string name = cmd.Next();
         if (name == null)
         {
             player.Send(PacketWriter.MakeTeleport(255, world.map.spawn));
         }
         else
         {
             Player target = world.FindPlayer(name);
             if (target != null)
             {
                 Position pos = target.pos;
                 pos.x += 1;
                 pos.y += 1;
                 pos.h += 1;
                 player.Send(PacketWriter.MakeTeleport(255, pos));
             }
             else if (cmd.Next() == null)
             {
                 world.NoPlayerMessage(player, name);
             }
             else
             {
                 cmd.Rewind();
                 int x, y, h;
                 if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out h))
                 {
                     if (x < 0 || x > world.map.widthX ||
                         y < 0 || y > world.map.widthY ||
                         y < 0 || y > world.map.height)
                     {
                         player.Message("Specified coordinates are outside the map!");
                     }
                     else
                     {
                         player.pos.Set(x * 32 + 16, y * 32 + 16, h * 32 + 16, player.pos.r, player.pos.l);
                         player.Send(PacketWriter.MakeTeleport(255, player.pos));
                     }
                 }
                 else
                 {
                     player.Message("See " + Color.Help + "/help tp" + Color.Sys + " for information on using /tp");
                 }
             }
         }
     }
     else
     {
         world.NoAccessMessage(player);
     }
 }
Ejemplo n.º 4
0
 void SetSpawn(Player player, Command cmd)
 {
     if (player.Can(Permissions.SetSpawn))
     {
         world.map.spawn = player.pos;
         world.map.Save();
         world.map.changesSinceBackup++;
         player.Send(PacketWriter.MakeTeleport(255, world.map.spawn), true);
         player.Message("New spawn point saved.");
         world.log.Log("{0} changed the spawned point.", LogType.UserActivity, player.name);
     }
     else
     {
         world.NoAccessMessage(player);
     }
 }
Ejemplo n.º 5
0
 void Bring(Player player, Command cmd)
 {
     if (player.Can(Permissions.Bring))
     {
         string name   = cmd.Next();
         Player target = world.FindPlayer(name);
         if (target != null)
         {
             Position pos = player.pos;
             pos.x += 1;
             pos.y += 1;
             pos.h += 1;
             target.Send(PacketWriter.MakeTeleport(255, pos));
         }
         else
         {
             world.NoPlayerMessage(player, name);
         }
     }
     else
     {
         world.NoAccessMessage(player);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Teleports the bot to a specific location
 /// </summary>
 public void teleportBot(Position p)
 {
     World.Players.Send(PacketWriter.MakeTeleport(ID, p));
 }
Ejemplo n.º 7
0
        void IoLoop()
        {
            short  x, y, h;
            byte   mode, type, opcode;
            Packet packet;

            int pollInterval = 200;
            int pollCounter  = 0;
            int packetsSent  = 0;

            try {
                LoginSequence();
                canSend = true;

                while (!canDispose)
                {
                    Thread.Sleep(1);
                    packetsSent = 0;

                    // detect player disconnect
                    if (pollCounter > pollInterval)
                    {
                        if (!client.Connected ||
                            (client.Client.Poll(1000, SelectMode.SelectRead) && client.Client.Available == 0))
                        {
                            world.log.Log("Session.IoLoop: Lost connection to {0}.", LogType.Debug, player.name);
                            return;
                        }
                        pollCounter = 0;
                    }
                    pollCounter++;

                    // send priority output to player
                    while (canSend && priorityOutputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick)
                    {
                        lock ( priorityQueueLock ) {
                            packet = priorityOutputQueue.Dequeue();
                        }
                        writer.Write(packet.data);
                        packetsSent++;
                        if (packet.data[0] == (byte)OutputCodes.Disconnect)
                        {
                            world.log.Log("Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name);
                            return;
                        }
                    }

                    // send output to player
                    while (canSend && outputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick)
                    {
                        lock ( queueLock ) {
                            packet = outputQueue.Dequeue();
                        }
                        writer.Write(packet.data);
                        packetsSent++;
                        if (packet.data[0] == (byte)OutputCodes.Disconnect)
                        {
                            writer.Flush();
                            world.log.Log("Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name);
                            return;
                        }
                    }

                    // get input from player
                    while (canReceive && client.GetStream().DataAvailable)
                    {
                        opcode = reader.ReadByte();
                        switch ((InputCodes)opcode)
                        {
                        // Message
                        case InputCodes.Message:
                            reader.ReadByte();
                            string message = ReadString();
                            if (Player.CheckForIllegalChars(message))
                            {
                                world.log.Log("Player.ParseMessage: {0} attempted to write illegal characters in chat and was kicked.",
                                              LogType.SuspiciousActivity,
                                              player.name);
                                KickNow("Illegal characters in chat.");
                                return;
                            }
                            else
                            {
                                player.ParseMessage(message, false);
                            }
                            break;

                        // Player movement
                        case InputCodes.MoveRotate:
                            reader.ReadByte();
                            Position newPos = new Position();
                            newPos.x = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.h = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.y = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.r = reader.ReadByte();
                            newPos.l = reader.ReadByte();

                            if (newPos.h < 0 || newPos.x < -32 || newPos.x >= world.map.widthX * 32 + 32 || newPos.y < -32 || newPos.y > world.map.widthY * 32 + 32)
                            {
                                world.log.Log(player.name + " was kicked for moving out of map boundaries.", LogType.SuspiciousActivity);
                                world.SendToAll(player.name + " was kicked for moving out of map boundaries.", null);
                                KickNow("Hacking detected: out of map boundaries.");
                                return;
                            }

                            Position delta = new Position(), oldPos = player.pos;
                            bool     posChanged, rotChanged;

                            if (!player.isHidden)
                            {
                                delta.Set(newPos.x - oldPos.x, newPos.y - oldPos.y, newPos.h - oldPos.h, newPos.r, newPos.l);
                                posChanged = delta.x != 0 || delta.y != 0 || delta.h != 0;
                                rotChanged = newPos.r != oldPos.r || newPos.l != oldPos.l;

                                if (player.isFrozen)
                                {
                                    if (rotChanged)
                                    {
                                        world.SendToAll(PacketWriter.MakeRotate(player.id, newPos), player);
                                        player.pos.r = newPos.r;
                                        player.pos.l = newPos.l;
                                    }
                                    if (posChanged)
                                    {
                                        SendNow(PacketWriter.MakeTeleport(255, player.pos));
                                    }
                                }
                                else
                                {
                                    if (delta.FitsIntoByte() && fullPositionUpdateCounter < fullPositionUpdateInterval)
                                    {
                                        if (posChanged && rotChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeMoveRotate(player.id, delta), player);
                                        }
                                        else if (posChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeMove(player.id, delta), player);
                                        }
                                        else if (rotChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeRotate(player.id, newPos), player);
                                        }
                                    }
                                    else if (!delta.IsZero() && !player.isFrozen)
                                    {
                                        world.SendToAll(PacketWriter.MakeTeleport(player.id, newPos), player);
                                    }
                                    player.pos = newPos;
                                    if (player.isDummySpamming)
                                    {
                                        world.cmd.standardCommands.Dummy(player, new Command("/dummy " + player.name));
                                    }
                                }

                                fullPositionUpdateCounter++;
                                if (fullPositionUpdateCounter >= fullPositionUpdateInterval)
                                {
                                    fullPositionUpdateCounter = 0;
                                }
                            }
                            break;

                        // Set tile
                        case InputCodes.SetTile:
                            x    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            h    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            y    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            mode = reader.ReadByte();
                            type = reader.ReadByte();
                            if (type > 49 || x < 0 || x > world.map.widthX || y < 0 || y > world.map.widthY || h < 0 || h > world.map.height)
                            {
                                world.log.Log(player.name + " was kicked for sending bad SetTile packets.", LogType.SuspiciousActivity);
                                world.SendToAll(player.name + " was kicked for sending bad SetTile packets.", null);
                                KickNow("Hacking detected: illegal SetTile packet.");
                                return;
                            }
                            else
                            {
                                player.SetTile(x, y, h, mode == 1, (Block)type);
                            }
                            break;
                        }
                    }
                }
            } catch (ThreadAbortException) {
                world.log.Log("Session.IoLoop: Thread aborted!", LogType.Error);
            } catch (IOException ex) {
                world.log.Log("Session.IoLoop: {0}.", LogType.Warning, ex.Message);
            } catch (SocketException ex) {
                world.log.Log("Session.IoLoop: {0}.", LogType.Warning, ex.Message);
            } catch (Exception ex) {
                world.log.Log("Session.IoLoop: {0}: {1}.", LogType.Error, ex.ToString(), ex.Message);
            } finally {
                canQueue   = false;
                canSend    = false;
                canDispose = true;
            }
        }