Exemplo 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(MultiplayerServer Server, RemoteClient Client)
 {
     Server.KickPlayer(Client.PlayerEntity.Name, "Sent invalid packet!");
 }
Exemplo 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(MultiplayerServer Server, RemoteClient client)
        {
            if (client.LoggedIn)
            {
                Server.KickPlayer(client.PlayerEntity.Name, "Invalid packet recieved!");
                return;
            }
            if (ProtocolVersionOrEID < MultiplayerServer.ProtocolVersion)
            {
                client.PacketQueue.Clear();
                client.PacketQueue.Enqueue(new DisconnectPacket("Outdated client!"));
                return;
            }
            if (ProtocolVersionOrEID > MultiplayerServer.ProtocolVersion)
            {
                client.PacketQueue.Clear();
                client.PacketQueue.Enqueue(new DisconnectPacket("Outdated server!"));
                return;
            }

            client.PlayerEntity = Server.Levels[0].LoadPlayer(Username);

            if (Server.CurrentServer.OnlineMode)
            {
                WebClient webClient = new WebClient();
                try
                {
                    StreamReader r = new StreamReader(webClient.OpenRead("http://session.minecraft.net/game/checkserver.jsp?user="******"&serverId=" + client.OnlineModeHash));
                    if (!r.ReadToEnd().ToUpper().Contains("YES"))
                    {
                        Server.KickPlayer(client.PlayerEntity.Name, "Failed to verify username!");
                        r.Close();
                        return;
                    }
                    r.Close();
                }
                catch
                {
                    Server.KickPlayer(client.PlayerEntity.Name, "Failed to verify username!");
                    return;
                }
            }

            this.ProtocolVersionOrEID = client.PlayerEntity.ID;
            this.WorldMode = Server.Levels[0].GameMode;
            this.LevelType = Server.Levels[0].WorldGenerator.Name;
            this.IsServerContext = false;
            this.MaxPlayers = (byte)Server.CurrentServer.MaxPlayers;
            client.PacketQueue.Enqueue(this);
            this.IsServerContext = true;
            this.Username = client.PlayerEntity.Name;

            ChunkManager.RecalculateClientColumns(client, Server, true);

            // TODO: Send inventory
            client.PacketQueue.Enqueue(new SpawnPositionPacket(Server.Levels[client.PlayerEntity.LevelIndex].Spawn));
            client.PlayerEntity.Location = Server.Levels[client.PlayerEntity.LevelIndex].Spawn;

            // Send Position
            client.PacketQueue.Enqueue(new PlayerPositionAndLookPacket(client.PlayerEntity));
            client.LoggedIn = true;
            client.PlayerEntity.GameMode = Server.Levels[client.PlayerEntity.LevelIndex].GameMode;

            // Send the new client to all logged in clients
            Server.EnqueueToAllClients(new PlayerListItemPacket(client.PlayerEntity.Name, true, 0));

            // Send all logged in clients to the new client
            foreach (RemoteClient c in Server.GetLoggedInClients())
                if (c.PlayerEntity.Name != client.PlayerEntity.Name)
                    client.PacketQueue.Enqueue(new PlayerListItemPacket(c.PlayerEntity.Name, true, 0));

            // Add entity
            Server.GetWorld(client).AddEntity(client.PlayerEntity);
            foreach (RemoteClient c in Server.GetClientsInWorldExcept(Server.GetWorld(client), client))
            {
                c.PacketQueue.Enqueue(new SpawnNamedEntityPacket(client.PlayerEntity.ID, client.PlayerEntity.Name,
                    client.PlayerEntity.Location, client.PlayerEntity.Rotation, client.PlayerEntity.InHand.ID));
                c.PacketQueue.Enqueue(new EntityPacket());

                client.PacketQueue.Enqueue(new SpawnNamedEntityPacket(c.PlayerEntity.ID, c.PlayerEntity.Name,
                    c.PlayerEntity.Location, c.PlayerEntity.Rotation, c.PlayerEntity.InHand.ID));
            }
            client.PacketQueue.Enqueue(new TimeUpdatePacket(Server.Levels[client.PlayerEntity.LevelIndex].Time));

            if (Server.GetLevel(client).WeatherManager.WeatherOccuring)
                client.PacketQueue.Enqueue(new ChangeGameStatePacket(NewOrInvalidState.BeginRain));

            SetWindowItemsPacket swip = new SetWindowItemsPacket(0, client.PlayerEntity.Inventory);
            client.PacketQueue.Enqueue(swip);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Handles the packet.
 /// </summary>
 /// <param name="Server">The server.</param>
 /// <param name="Client">The client.</param>
 /// <remarks></remarks>
 public override void HandlePacket(MultiplayerServer Server, RemoteClient Client)
 {
     if (Client.PlayerEntity.ID != EntityID)
     {
         Server.KickPlayer(Client.PlayerEntity.Name, "Hacking!");
         return;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Handles the packet.
 /// </summary>
 /// <param name="Server">The server.</param>
 /// <param name="Client">The client.</param>
 /// <remarks></remarks>
 public override void HandlePacket(MultiplayerServer Server, RemoteClient Client)
 {
     Block b = Server.GetWorld(Client).GetBlock(this.SignLocation);
     if (!(b is SignPostBlock) && !(b is WallSignBlock))
     {
         Server.KickPlayer(Client.PlayerEntity.Name, "Sign hacking!");
         return;
     }
     if (b is SignPostBlock)
         (b as SignPostBlock).Data.Text = this.Text;
     else
         (b as WallSignBlock).Data.Text = this.Text;
     Server.Levels[Client.PlayerEntity.LevelIndex].SetBlock(this.SignLocation, b);
     Server.EnqueueToAllClientsExcept(this, Client.PlayerEntity);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the packet.
        /// </summary>
        /// <param name="Server">The server.</param>
        /// <param name="Client">The client.</param>
        /// <remarks></remarks>
        public override void HandlePacket(MultiplayerServer Server, RemoteClient Client)
        {
            if (EntityID != Client.PlayerEntity.ID)
            {
                Server.KickPlayer(Client.PlayerEntity.Name, "Hacking!");
                return;
            }

            if (Action == EntityAction.Crouch || Action == EntityAction.UnCrouch)
            {
                Animation animation = Action == EntityAction.Crouch ? Animation.Crouch : Animation.UnCrouch;
                foreach (RemoteClient c in Server.GetClientsInWorldExcept(Server.GetWorld(Client), Client))
                {
                    c.PacketQueue.Enqueue(new AnimationPacket(Client.PlayerEntity.ID, animation));
                }
            }
            if (Action == EntityAction.LeaveBed)
            {
                //Unoccupy the metadata of the block
                Block bed = Server.GetWorld(Client.PlayerEntity).GetBlock(Client.PlayerEntity.OccupiedBed); //Get the block
                bed.Metadata = (byte)(bed.Metadata & ~0x4); // Remove flag
                Server.GetWorld(Client.PlayerEntity).SetBlock(Client.PlayerEntity.OccupiedBed, bed); //Set block

                Client.PlayerEntity.OccupiedBed = null; //Nullify the clients bed position

                Server.EnqueueToAllClients(new AnimationPacket(Client.PlayerEntity.ID, Animation.LeaveBed));
            }
        }