Esempio n. 1
0
 /// <summary>
 /// Handles the packet.
 /// </summary>
 /// <param name="Server">The server.</param>
 /// <param name="Client">The client.</param>
 /// <remarks></remarks>
 public override void HandlePacket(ClassicServer Server, RemoteClient Client)
 {
     Client.Position = Position;
     Position.X      = Position.X / 32;
     Position.Y      = Position.Y / 32;
     Position.Z      = Position.Z / 32;
     Client.Yaw      = Yaw;
     Client.Pitch    = Pitch;
     Server.EnqueueToAllClientsInWorld(new PositionAndOrientationPacket(Client.PlayerID, Position, Yaw, Pitch), Client.World, Client);
 }
Esempio n. 2
0
        /// <summary>
        /// Handles the packet.
        /// </summary>
        /// <param name="Server">The server.</param>
        /// <param name="Client">The client.</param>
        /// <remarks></remarks>
        public override void HandlePacket(ClassicServer Server, RemoteClient Client)
        {
            Client.LoggedIn = true;
            Client.UserName = UserNameOrServerName;
            Client.World    = Server.MainLevel;
            Client.PacketQueue.Enqueue(new IdentificationPacket(Server.Server.Name, Server.Server.MotD, Client.UserType));
            Client.PlayerID = (byte)(Server.Clients.Count() - 1);
            Client.PacketQueue.Enqueue(new WorldInitializePacket());

            MemoryStream ms = new MemoryStream();
            GZipStream   s  = new GZipStream(ms, CompressionMode.Compress, true);

            s.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(World.Find(Client.World).Data.Length)), 0, sizeof(int));
            s.Write(World.Find(Client.World).Data, 0, World.Find(Client.World).Data.Length);
            s.Close();
            byte[] data = ms.GetBuffer();
            ms.Close();

            double numChunks  = data.Length / 1024;
            double chunksSent = 0;

            for (int i = 0; i < data.Length; i += 1024)
            {
                byte[] chunkData = new byte[1024];

                short chunkLength = 1024;
                if (data.Length - i < chunkLength)
                {
                    chunkLength = (short)(data.Length - i);
                }

                Array.Copy(data, i, chunkData, 0, chunkLength);

                Client.PacketQueue.Enqueue(new WorldDataChunkPacket(chunkLength, chunkData, (byte)((chunksSent / numChunks) * 100)));
                chunksSent++;
            }

            Client.PacketQueue.Enqueue(new WorldFinalizePacket(World.Find(Client.World).Width, World.Find(Client.World).Height, World.Find(Client.World).Depth));
            Client.Position = World.Find(Client.World).Spawn.Clone();
            Client.Yaw      = 0; Client.Pitch = 0;
            unchecked { Client.PacketQueue.Enqueue(new PositionAndOrientationPacket((byte)-1, Client.Position, Client.Yaw, Client.Pitch)); }
            Server.LoadAllClientsToClient(Client);
            Server.EnqueueToAllClientsInWorld(new SpawnPlayerPacket(Client.PlayerID, Client.UserName, Client.Position, Client.Yaw, Client.Pitch), Client.World, Client);
        }