示例#1
0
        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            switch (ClientStatus)
            {
                case ClientStatus.InitialSpawn:
                    // Create a hash for session verification
                    SHA1 sha1 = SHA1.Create();
                    AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey);
                    byte[] shaData = Encoding.UTF8.GetBytes(client.AuthenticationHash)
                        .Concat(client.SharedKey)
                        .Concat(encodedKey.GetBytes()).ToArray();
                    string hash = Cryptography.JavaHexDigest(shaData);

                    // Talk to session.minecraft.net
                    if (server.OnlineMode)
                    {
                        var webClient = new WebClient();
                        var webReader = new StreamReader(webClient.OpenRead(
                            new Uri(string.Format(sessionCheckUri, client.Username, hash))));
                        string response = webReader.ReadToEnd();
                        webReader.Close();
                        if (response != "YES")
                        {
                            client.SendPacket(new DisconnectPacket("Failed to verify username!"));
                            return;
                        }
                    }

                    server.LogInPlayer(client);
                    break;
                case ClientStatus.Respawn:
                    var world = server.GetClientWorld(client);
                    client.Entity.Position = new Vector3(
                        client.Entity.SpawnPoint.X,
                        client.Entity.SpawnPoint.Y + PlayerEntity.Height,
                        client.Entity.SpawnPoint.Z);
                    client.Entity.Health = client.Entity.MaxHealth;
                    client.Entity.Food = 20;
                    client.Entity.FoodSaturation = 20;
                    server.EntityManager.SpawnEntity(server.GetClientWorld(client), client.Entity);
                    //client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation));
                    client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Difficulty,
                        client.Entity.GameMode, world.LevelType));
                    client.SendPacket(new PlayerPositionAndLookPacket(
                                  client.Entity.Position, client.Entity.Yaw, client.Entity.Pitch, true));
                    server.ProcessSendQueue();
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
示例#2
0
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (client.Entity.Position.DistanceTo(Position) <= MaxDigDistance)
     {
         switch (Action)
         {
             case PlayerAction.StartedDigging:
                 if (client.Entity.GameMode == GameMode.Creative)
                     server.GetClientWorld(client).SetBlock(Position, new AirBlock());
                 break;
             case PlayerAction.FinishedDigging:
                 server.GetClientWorld(client).SetBlock(Position, new AirBlock());
                 break;
         }
     }
 }
示例#3
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (Client.Entity.Position.DistanceTo(Position) <= MaxDigDistance)
     {
         switch (Action)
         {
             case PlayerAction.StartedDigging:
                 // if (creative)
                 Server.GetClientWorld(Client).SetBlock(Position, new AirBlock());
                 break;
             case PlayerAction.FinishedDigging:
                 Server.GetClientWorld(Client).SetBlock(Position, new AirBlock());
                 break;
         }
     }
 }
示例#4
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     switch (Action)
     {
         case EntityAction.Crouch:
             Client.IsCrouching = true;
             break;
         case EntityAction.Uncrouch:
             Client.IsCrouching = false;
             break;
         case EntityAction.StartSprinting:
             Client.IsSprinting = true;
             break;
         case EntityAction.StopSprinting:
             Client.IsSprinting = false;
             break;
     }
     if (Action != EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         this.EntityId = Client.Entity.Id;
         for (int i = 0; i < 
              Server.GetClientsInWorld(Server.GetClientWorld(Client)).Count(); i++)
         {
             if (Server.Clients [i] != Client)
                 Server.Clients [i].SendPacket(this);
         }
         Server.ProcessSendQueue();
     }
 }
示例#5
0
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     EntityId = client.Entity.Id;
     var clients = server.GetClientsInWorld(server.GetClientWorld(client)).Where(c => c.Entity.Id != EntityId);
     foreach (var _client in clients)
         _client.SendPacket(this);
     server.ProcessSendQueue();
 }
示例#6
0
 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] payload = new byte[] { PacketId }
         .Concat(DataUtility.CreateInt32((int)Dimension))
         .Concat(new byte[] { (byte)Difficulty, (byte)GameMode })
         .Concat(DataUtility.CreateInt16(WorldHeight))
         .Concat(DataUtility.CreateString(server.GetClientWorld(client).LevelType))
         .ToArray();
     client.SendData(payload);
 }
示例#7
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (!Client.ReadyToSpawn)
         return;
     Client.Entity.Position = new Vector3(X, Y, Z);
     if (Client.Entity.Position.DistanceTo(Client.Entity.OldPosition) > 
         Client.MaxMoveDistance)
     {
         Client.SendPacket(new DisconnectPacket("Hacking: You moved too fast!"));
         Server.ProcessSendQueue();
         return;
     }
     Client.UpdateChunksAsync();
     Server.GetClientWorld(Client).EntityManager.UpdateEntity(Client.Entity);
     Server.ProcessSendQueue();
 }
示例#8
0
 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (Client.Entity.Position.DistanceTo(Position) > 6)
         return;
     if (HeldItem.Id < 0x80 && HeldItem.Id >= 0)
     {
         Block block = (Block)HeldItem.Id;
         Vector3 clickedBlock = Position;
         Vector3 placedBlock = Position;
         placedBlock += AdjustByDirection(Direction);
         if (block != null)
         {
             // TODO: More stuff here
             Server.GetClientWorld(Client).SetBlock(placedBlock, block);
         }
     }
 }
示例#9
0
 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (client.Entity.Position.DistanceTo(Position) > 6) // TODO: Use client.Reach
         return;
     var item = client.Entity.Inventory[client.Entity.SelectedSlot];
     if (item != null && item.Id == 0xFFFF)
         item.Id = 0;
     if (item != null)
     {
         item.Item.OnItemUsed(server.GetClientWorld(client), Position, AdjustByDirection(Direction), CursorPosition, client.Entity);
         if (client.Entity.GameMode != GameMode.Creative)
             client.Entity.Inventory[client.Entity.SelectedSlot].Count--;
     }
     else
     {
         client.SendPacket(new DisconnectPacket("Unrecognized item!"));
         server.ProcessSendQueue();
     }
 }