Пример #1
0
 private void StartGame()
 {
     PacketID packetID;
     while (isConnected) {
         packetID = (PacketID)readByte ();
         this.commandCountReceived++;
         packetHistory.Add (packetID);
         double stance;
         int entityID = 0;
         //Console.WriteLine (
         //	"[{0}:{1}:{2}] [{3}]: {4}",this.commandCountReceived,this.packetCountReceived,this.packetSizeReceived,DateTime.Now.ToLongTimeString(),Enum.GetName(typeof(PacketID),packetID));
         switch (packetID) {
         case PacketID.LoginRequest:
             this.player = new Player (this.connectName, this);
             this.player.entityID = readInt ();
             entities [this.player.entityID] = this.player;
             readString ();
             this.levelType = readString ();
             this.serverMode = (ServerMode)readInt ();
             this.dimension = (Dimension)readInt ();
             this.difficulty = (Difficulty)readByte ();
             readByte ();
             this.maxPlayers = readByte ();
             Console.WriteLine ("Entity ID: {0}", this.player.entityID);
             Console.WriteLine ("Level Type: {0}", this.levelType);
             Console.WriteLine ("Server mode: {0}", Enum.GetName (typeof(ServerMode), this.serverMode));
             Console.WriteLine ("Dimension: {0}", Enum.GetName (typeof(Dimension), this.dimension));
             Console.WriteLine ("Difficulty: {0}", Enum.GetName (typeof(Difficulty), this.difficulty));
             Console.WriteLine ("Max players: {0}", this.maxPlayers);
             break;
         case PacketID.DisconnectKick:
             string serverAnswer = readString ();
             Console.WriteLine ("Dissconnected: {0}", serverAnswer);
             isConnected = false;
             isLogged = false;
             break;
         case PacketID.KeepAlive:
             this.SendPacket (new object[]{(byte)PacketID.KeepAlive,readInt ()});
             break;
         case PacketID.PluginMessage:
             string channel = readString ();
             byte[] data = readBytes (readShort ());
             Console.WriteLine ("Plugins data for {0} size: {1}", channel, data.Length);
             break;
         case PacketID.SpawnPosition:
             this.spawnPosition = new XYZ<int> (readInt (), readInt (), readInt ());
             //Console.WriteLine ("Spawn position: X: {0} Y: {1} Z: {2}", X, Y, Z);
             break;
         case PacketID.PlayerAbilities:
             this.player.invulnerability = readBool ();
             this.player.isFlying = readBool ();
             this.player.canFly = readBool ();
             this.player.instantDestroy = readBool ();
             Console.WriteLine (this.player.invulnerability ? "Player cannot take damage" : "Player can take damage");
             Console.WriteLine (this.player.isFlying ? "Player is currently flying" : "Player is't currently flying");
             Console.WriteLine (this.player.canFly ? "Player is able to fly" : "Player is't able to fly");
             Console.WriteLine (this.player.instantDestroy ? "Player can destroy blocks instantly" : "Player can't destroy blocks instantly");
             break;
         case PacketID.TimeUpdate:
             this.time = readLong ();
         //Console.WriteLine ("Time: {0}", time);
             break;
         case PacketID.ChatMessage:
             string msg = readString ();
             if (clearString (msg).Length > 0) {
                 this.chat.Add (clearString (msg));
                 Console.WriteLine ("--|{0}", clearString (msg));
             }
             break;
         case PacketID.PlayerPositionLook:
             lock (this.player) {
                 this.player.position.x = readDouble ();
                 stance = readDouble ();
                 this.player.position.y = readDouble ();
                 this.player.position.z = readDouble ();
                 this.map.updateMap ();
                 this.player.endPosition = this.player.position;
                 this.player.look.yaw = readFloat ();
                 this.player.look.pitch = readFloat ();
                 this.player.onGround = readBool ();
                 this.player.height = stance - this.player.position.y;
             }
             Console.WriteLine (
                 "Absolute position: X:{0:0.####} Y:{1:0.####} Z:{2:0.####} Height:{3:0.###!#}",
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.z, this.player.height);
             Console.WriteLine ("Absolute rotation: X:{0} Y:{1}", this.player.look.yaw, this.player.look.pitch);
             Console.WriteLine ("On ground: {0}", this.player.onGround ? "yes" : "no");
             this.SendPacket (new object[] {
                 (byte)PacketID.PlayerPositionLook,
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.y + this.player.height,
                 this.player.position.z,this.player.look.yaw,this.player.look.pitch,this.player.onGround}
             );
             isLogged = true;
             break;
         case PacketID.Player:
             this.player.onGround = readBool ();
             Console.WriteLine ("On ground: {0}", this.player.onGround ? "yes" : "no");
             break;
         case PacketID.PlayerPosition:
             lock (this.player) {
                 this.player.position.x = readDouble ();
                 this.player.position.y = readDouble ();
                 stance = readDouble ();
                 this.player.position.z = readDouble ();
                 this.map.updateMap ();
                 this.player.height = stance - this.player.position.y;
                 this.player.endPosition = this.player.position;
             }
             Console.WriteLine (
                 "Absolute position: X:{0} Y:{1} Z:{2} Height:{3}",
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.z,
                 this.player.height
             );
             break;
         case PacketID.SpawnPainting:
             Painting picture = new Painting ();
             picture.entityID = readInt ();
             picture.title = readString ();
             picture.centerPosition.x = readInt ();
             picture.centerPosition.y = readInt ();
             picture.centerPosition.z = readInt ();
             picture.direction = readInt ();
             this.entities [picture.entityID] = picture;
         //Console.WriteLine ("Spawn Painting: {4} X:{0} Y:{1} Z:{2} Direction:{3}", x2, y2, z2, direction, title);
             break;
         case PacketID.EntityHeadLook:
             entityID = readInt ();
             if (entities.ContainsKey (entityID))
                 entities [entityID].headYaw = readByte ();
             else
                 readByte ();
         //Console.WriteLine ("Head yaw: {0} steps", headYew);
             break;
         case PacketID.SpawnMob:
             Mob mob = new Mob ();
             mob.entityID = readInt ();
             mob.type = readByte ();
             mob.position.x = readInt ();
             mob.position.y = readInt ();
             mob.position.z = readInt ();
             mob.look.yaw = readByte ();
             mob.look.pitch = readByte ();
             mob.headYaw = readByte ();
             mob.metadata = readMetadata ();
             entities [mob.entityID] = mob;
         /*Console.WriteLine (
             "Spawn Mob: Type:{0} X:{1} Y:{2} Z:{3} Yaw:{4} Pitch:{5} Head Yaw:{6} Metadate size:{7}",
             type,
             x3,
             y3,
             z3,
             yaw2,
             pitch2,
             headYaw2,
             metadata
         );*/
             break;
         case PacketID.EntityVelocity:
             entityID = readInt ();
             if (entities.ContainsKey (entityID)) {
                 entities [entityID].velocity.x = readShort ();
                 entities [entityID].velocity.y = readShort ();
                 entities [entityID].velocity.z = readShort ();
             } else {
                 readShort ();
                 readShort ();
                 readShort ();
             }
         //Console.WriteLine ("Velocity: X:{0} Y:{1} Z:{1}", vX / 28800.0, vY / 28800.0, vZ / 28800.0);
             break;
         case PacketID.SpawnNamedEntity:
             {
                 OtherPlayer p = new OtherPlayer ();
                 p.entityID = readInt ();
                 p.name = readString ();
                 p.position.x = readInt ();
                 p.position.y = readInt ();
                 p.position.z = readInt ();
                 p.look.yaw = readByte ();
                 p.look.pitch = readByte ();
                 p.currentItem = readShort ();
                 entities [p.entityID] = p;
                 Console.WriteLine (
                 "Player spawned: {3} X:{0} Y:{1} Z:{2} yaw:{4} pitch:{5} withItem:{6}",
                 p.position.x,
                 p.position.y,
                 p.position.z,
                 p.name,
                 p.look.yaw,
                 p.look.pitch,
                 p.currentItem
                 );
             }
             break;
         case PacketID.EntityEquipment:
             entityID = readInt ();
             if (entities.ContainsKey (entityID) && entities [entityID].GetType () == typeof(OtherPlayer)) {
                 OtherPlayer p = (OtherPlayer)entities [entityID];
                 Armor armor = new Armor ();
                 armor.slot = readShort ();
                 armor.itemID = readShort ();
                 armor.damage = readShort ();
                 p.armor [armor.slot] = armor;
                 Console.WriteLine ("Equipment: slot:{0} itemID:{1} damage:{2}", armor.slot, armor.itemID, armor.damage);
             } else {
                 readShort ();
                 readShort ();
                 readShort ();
             }
             break;
         case PacketID.SpawnDroppedItem:
             DroppedItem item = new DroppedItem ();
             item.entityID = readInt ();
             //readInt ();
             item.item = readShort ();
             item.count = readByte ();
             item.data = readShort ();
             item.position.x = readInt ();
             item.position.z = readInt ();
             item.position.y = readInt ();
             item.rotation = readByte ();
             item.pitch = readByte ();
             item.roll = readByte ();
             entities [item.entityID] = item;
             Console.WriteLine (
                 "Dropped item: item:{0}:{2} count:{1} x:{3} y:{4} z:{5} rotation:{6} pitch:{7} roll:{8}",
             item.item,
             item.count,
             item.data,
             item.position.x,
             item.position.y,
             item.position.z,
             item.rotation,
             item.pitch,
             item.roll
             );
             break;
         case PacketID.MapColumnAllocation:
             {
                 int x = readInt ();
                 int z = readInt ();
                 bool mode = readBool ();
                 if (mode) {
                     this.map.initChunk (x, z);
                 } else {
                     this.map.unloadChunk (x, z);
                 }
                 /*Console.WriteLine (
                 "Need to {0} the chunk [{1};{2}]",
                 mode ? "initialize" : "unload",
                 x,
                 z);*/
                 //this.map.WriteMap ();
             }
             break;
         case PacketID.PlayerListItem:
             string name = clearString (readString ());
             bool online = readBool ();
             short ping = readShort ();
             if (online) {
                 playerList [name] = ping;
             } else {
                 playerList.Remove (name);
             }
             Console.WriteLine ("Player:{0} ping:{1} {2} game", name, ping, online ? "enter" : "exit");
             break;
         case PacketID.SetWindowItems:
             byte windowId = readByte ();
             short count2 = readShort ();
         //Console.Write ("Window items: count:{0}", count2);
             for (int i = 0; i<count2; i++) {
                 short id = readShort ();
                 if (id != -1) {
                     byte itemCount = readByte ();
                     short _data = readShort ();
                     if (_data != -1)
                         readBytes (_data);
                     //Console.Write (" [{0}: id: {1} count:{2} dataSize:{3}]", i, id, itemCount, _data);
                 }// else
                 //Console.Write (" [{0};{1}]", i, "Empty");
             }
         //Console.WriteLine ();
             break;
         case PacketID.SetSlot:
             byte winID = readByte ();
             short _slot = readShort ();
             short _id = readShort ();
             if (_id != -1) {
                 byte itemCount = readByte ();
                 short _data = readShort ();
                 if (_data != -1)
                     readBytes (_data);
                 /*Console.WriteLine (
                 "Set slot: [window:{4} {0}: id: {1} count:{2} dataSize:{3}]",
                 _slot,
                 _id,
                 itemCount,
                 _data,
                 winID
             );*/
             } //else
             //Console.WriteLine ("Set slot: [window:{2} {0};{1}]", _slot, "Empty", winID);
             break;
         case PacketID.SpawnExperienceOrb:
             readInt ();
             int x7 = readInt ();
             int y7 = readInt ();
             int z7 = readInt ();
             int count3 = readShort ();
             Console.WriteLine ("Spawn expirience orb: x:{0} y:{1} z:{2} count:{3}", x7, y7, z7, count3);
             break;
         case PacketID.EntityRelativeMove:
             entityID = readInt ();
             sbyte dx = (sbyte)readByte ();
             sbyte dy = (sbyte)readByte ();
             sbyte dz = (sbyte)readByte ();
             if (entities.ContainsKey (entityID) && entities [entityID].GetType () == typeof(OtherPlayer)) {
                 //Console.WriteLine ("Entity move: dx:{0:0.##} dy:{1:0.##} dz:{2:0.##}", dx/32.0, dy/32.0, dz/32.0);
             }
             break;
         case PacketID.EntityLook:
             readInt ();
             byte yaw4 = readByte ();
             byte pitch5 = readByte ();
         //Console.WriteLine ("Entity rotate: yaw:{0} pitch:{1}", yaw4, pitch5);
             break;
         case PacketID.DestroyEntity:
             entities.Remove (readInt ());
         //Console.WriteLine ("Destroy entity");
             break;
         case PacketID.EntityTeleport:
             readInt ();
             int x8 = readInt ();
             int y8 = readInt ();
             int z8 = readInt ();
             byte yaw8 = readByte ();
             byte pitch8 = readByte ();
         //Console.WriteLine ("Entity teleport: X:{0} Y:{1} Z:{2} yaw:{3} pitch:{4}", x8, y8, z8, yaw8, pitch8);
             break;
         case PacketID.BlockAction:
             int x9 = readInt ();
             short y9 = readShort ();
             int z9 = readInt ();
             byte byte1 = readByte ();
             byte byte2 = readByte ();
         //Console.WriteLine ("Block action: X:{0} Y:{1} Z:{2} bytes:[{3},{4}]",x9,y9,z9,byte1,byte2);
             break;
         case PacketID.EntityLookandRelativeMove:
             readInt ();
             int x10 = readByte ();
             int y10 = readByte ();
             int z10 = readByte ();
             byte yaw9 = readByte ();
             byte pitch9 = readByte ();
         //Console.WriteLine ("Entity relative look/move: dX:{0} dY:{1} dZ:{2} Yaw:{3} Pitch:{4}", x10, y10, z10, yaw9, pitch9);
             break;
         case PacketID.EntityMetadata:
             readInt ();
             int msize = readMetadata ();
             break;
         case PacketID.Animation:
             readInt ();
             readByte ();
             break;
         case PacketID.SpawnObjectVehicle:
             /*for (int i =0; i<50 && i<stream.Count; i++) {
                 Console.Write ("{0} ",Convert.ToString (stream[i],16));
             }*/
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             readInt ();
             int fireball = readInt ();
             if (fireball > 0) {
                 readShort ();
                 readShort ();
                 readShort ();
             }
             break;
         case PacketID.EntityStatus:
             readInt ();
             readByte ();
             break;
         case PacketID.IncrementStatistic:
             int statisticID = readInt ();
             byte value = readByte ();
             Console.WriteLine ("Statistic {0} change to {1}", statisticID, value);
             break;
         case PacketID.UpdateHealth:
             this.player.health = readShort ();
             this.player.food = readShort ();
             this.player.saturation = readFloat ();
             Console.WriteLine (
                 "Update health:{0} food:{1} saturation:{2}",
                 this.player.health, this.player.food, this.player.saturation);
             if (this.player.health < 1) {
                 this.SendPacket (new object[] {
                     (byte)PacketID.Respawn,
                     (int)this.dimension,
                     (byte)this.difficulty,
                     (byte)this.serverMode,
                     this.worldHeight,
                     this.levelType
                 }
                 );
             }
             break;
         case PacketID.UseBed:
             readInt ();
             readByte ();
             readInt ();
             readByte ();
             readInt ();
             Console.WriteLine ("use bad");
             break;
         case PacketID.CollectItem:
             readInt ();
             readInt ();
             Console.WriteLine ("Someone pick up items");
             break;
         case PacketID.Entity:
             entities [readInt ()] = new Entity ();
             break;
         case PacketID.AttachEntity:
             readInt ();
             readInt ();
             Console.WriteLine ("Attach player to vehicle");
             break;
         case PacketID.EntityEffect:
             readInt ();
             readByte ();
             readByte ();
             readShort ();
             break;
         case PacketID.RemoveEntityEffect:
             readInt ();
             readByte ();
             break;
         case PacketID.SetExperience:
             readFloat ();
             readShort ();
             readShort ();
             break;
         case PacketID.MapChunks:
             {
                 int x = readInt ();
                 int z = readInt ();
                 bool ground = readBool ();
                 short primarymask = readShort ();
                 short addmask = readShort ();
                 int size = readInt ();
                 readInt ();
                 byte[] chunk = readBytes (size);
                 this.map.loadChunk (x, z, chunk);
                 Console.WriteLine (
                 "Chunk uploaded[{4};{5}] size:{0} ground:{1} mask:{2} mask:{3}", size,ground,Convert.ToString(primarymask,2),Convert.ToString(addmask,2),x,z);
         }
             break;
         case PacketID.MultiBlockChange:
             readInt ();
             readInt ();
             readShort ();
             int _size = readInt ();
             readBytes (_size);
             Console.WriteLine ("Multi block changes size:{0}", _size);
             break;
         case PacketID.BlockChange:
             readInt ();
             readByte ();
             readInt ();
             readByte ();
             readByte ();
             break;
         case PacketID.Explosion:
             readDouble ();
             readDouble ();
             readDouble ();
             readFloat ();
             int size2 = readInt ();
             readBytes (size2 * 3);
             Console.WriteLine ("Explosion records:{0}", size2);
             break;
         case PacketID.SoundParticleEffect:
             readInt ();
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             break;
         case PacketID.ChangeGameState:
             byte byte3 = readByte ();
             byte byte4 = readByte ();
             Console.WriteLine (@"Change game mod: reason: {0} game mod:{1}", byte3, byte4);
             break;
         case PacketID.Thunderbolt:
             readInt ();
             readBool ();
             readInt ();
             readInt ();
             readInt ();
             Console.WriteLine ("Thunderbolt!");
             break;
         case PacketID.OpenWindow:
             readByte ();
             readByte ();
             string winTitle = readString ();
             int slotnum = readByte ();
             Console.WriteLine ("Open window {0} slots:{1}", winTitle, slotnum);
             break;
         case PacketID.CloseWindow:
             readByte ();
             Console.WriteLine ("Close window");
             break;
         case PacketID.UpdateWindowProperty:
             readByte ();
             readShort ();
             readShort ();
             break;
         case PacketID.ItemData:
             readShort ();
             readShort ();
             int textLength = readByte ();
             byte[] text = readBytes (textLength);
             Console.WriteLine ("Item data: {0}", Encoding.ASCII.GetString (text));
             break;
         case PacketID.UpdateTileEntity:
             readInt ();
             readShort ();
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             readInt ();
             break;
         case PacketID.Respawn:
             this.dimension = (Dimension)readInt ();
             this.difficulty = (Difficulty)readByte ();
             this.serverMode = (ServerMode)readByte ();
             this.worldHeight = readShort ();
             this.levelType = readString ();
             Console.WriteLine ("Level Type: {0}", this.levelType);
             Console.WriteLine ("Server mode: {0}", Enum.GetName (typeof(ServerMode), this.serverMode));
             Console.WriteLine ("Dimension: {0}", Enum.GetName (typeof(Dimension), this.dimension));
             Console.WriteLine ("Difficulty: {0}", Enum.GetName (typeof(Difficulty), this.difficulty));
             Console.WriteLine ("World height: {0}", this.worldHeight);
             break;
         case PacketID.ConfirmTransaction:
             readByte ();
             readShort ();
             readBool ();
             Console.WriteLine ("Confirm transaction");
             break;
         case PacketID.CreativeInventoryAction:
             readShort ();
             short _id2 = readShort ();
             if (_id2 != -1) {
                 byte itemCount = readByte ();
                 short _data = readShort ();
                 if (_data != -1)
                     readBytes (_data);
             }
             break;
         case PacketID.UpdateSign:
             readInt ();
             readShort ();
             readInt ();
             string line1 = readString ();
             string line2 = readString ();
             string line3 = readString ();
             string line4 = readString ();
             //Console.WriteLine ("Update sign:{0} {1} {2} {3}", line1, line2, line3, line4);
             break;
         default:
             Console.WriteLine ("Unknown response: {0} ", Convert.ToString ((byte)packetID, 16));
             isConnected = false;
             isLogged = false;
             client.Close ();
             throw new Exception ("Unknown response");
             break;
         }
     }
 }
Пример #2
0
        private void StartGame()
        {
            PacketID packetID;

            while (isConnected)
            {
                packetID = (PacketID)readByte();
                this.commandCountReceived++;
                packetHistory.Add(packetID);
                double stance;
                int    entityID = 0;
                //Console.WriteLine (
                //	"[{0}:{1}:{2}] [{3}]: {4}",this.commandCountReceived,this.packetCountReceived,this.packetSizeReceived,DateTime.Now.ToLongTimeString(),Enum.GetName(typeof(PacketID),packetID));
                switch (packetID)
                {
                case PacketID.LoginRequest:
                    this.player                     = new Player(this.connectName, this);
                    this.player.entityID            = readInt();
                    entities [this.player.entityID] = this.player;
                    readString();
                    this.levelType  = readString();
                    this.serverMode = (ServerMode)readInt();
                    this.dimension  = (Dimension)readInt();
                    this.difficulty = (Difficulty)readByte();
                    readByte();
                    this.maxPlayers = readByte();
                    Console.WriteLine("Entity ID: {0}", this.player.entityID);
                    Console.WriteLine("Level Type: {0}", this.levelType);
                    Console.WriteLine("Server mode: {0}", Enum.GetName(typeof(ServerMode), this.serverMode));
                    Console.WriteLine("Dimension: {0}", Enum.GetName(typeof(Dimension), this.dimension));
                    Console.WriteLine("Difficulty: {0}", Enum.GetName(typeof(Difficulty), this.difficulty));
                    Console.WriteLine("Max players: {0}", this.maxPlayers);
                    break;

                case PacketID.DisconnectKick:
                    string serverAnswer = readString();
                    Console.WriteLine("Dissconnected: {0}", serverAnswer);
                    isConnected = false;
                    isLogged    = false;
                    break;

                case PacketID.KeepAlive:
                    this.SendPacket(new object[] { (byte)PacketID.KeepAlive, readInt() });
                    break;

                case PacketID.PluginMessage:
                    string channel = readString();
                    byte[] data    = readBytes(readShort());
                    Console.WriteLine("Plugins data for {0} size: {1}", channel, data.Length);
                    break;

                case PacketID.SpawnPosition:
                    this.spawnPosition = new XYZ <int> (readInt(), readInt(), readInt());
                    //Console.WriteLine ("Spawn position: X: {0} Y: {1} Z: {2}", X, Y, Z);
                    break;

                case PacketID.PlayerAbilities:
                    this.player.invulnerability = readBool();
                    this.player.isFlying        = readBool();
                    this.player.canFly          = readBool();
                    this.player.instantDestroy  = readBool();
                    Console.WriteLine(this.player.invulnerability ? "Player cannot take damage" : "Player can take damage");
                    Console.WriteLine(this.player.isFlying ? "Player is currently flying" : "Player is't currently flying");
                    Console.WriteLine(this.player.canFly ? "Player is able to fly" : "Player is't able to fly");
                    Console.WriteLine(this.player.instantDestroy ? "Player can destroy blocks instantly" : "Player can't destroy blocks instantly");
                    break;

                case PacketID.TimeUpdate:
                    this.time = readLong();
                    //Console.WriteLine ("Time: {0}", time);
                    break;

                case PacketID.ChatMessage:
                    string msg = readString();
                    if (clearString(msg).Length > 0)
                    {
                        this.chat.Add(clearString(msg));
                        Console.WriteLine("--|{0}", clearString(msg));
                    }
                    break;

                case PacketID.PlayerPositionLook:
                    lock (this.player) {
                        this.player.position.x = readDouble();
                        stance = readDouble();
                        this.player.position.y = readDouble();
                        this.player.position.z = readDouble();
                        this.map.updateMap();
                        this.player.endPosition = this.player.position;
                        this.player.look.yaw    = readFloat();
                        this.player.look.pitch  = readFloat();
                        this.player.onGround    = readBool();
                        this.player.height      = stance - this.player.position.y;
                    }
                    Console.WriteLine(
                        "Absolute position: X:{0:0.####} Y:{1:0.####} Z:{2:0.####} Height:{3:0.###!#}",
                        this.player.position.x,
                        this.player.position.y,
                        this.player.position.z, this.player.height);
                    Console.WriteLine("Absolute rotation: X:{0} Y:{1}", this.player.look.yaw, this.player.look.pitch);
                    Console.WriteLine("On ground: {0}", this.player.onGround ? "yes" : "no");
                    this.SendPacket(new object[] {
                        (byte)PacketID.PlayerPositionLook,
                        this.player.position.x,
                        this.player.position.y,
                        this.player.position.y + this.player.height,
                        this.player.position.z, this.player.look.yaw, this.player.look.pitch, this.player.onGround
                    }
                                    );
                    isLogged = true;
                    break;

                case PacketID.Player:
                    this.player.onGround = readBool();
                    Console.WriteLine("On ground: {0}", this.player.onGround ? "yes" : "no");
                    break;

                case PacketID.PlayerPosition:
                    lock (this.player) {
                        this.player.position.x = readDouble();
                        this.player.position.y = readDouble();
                        stance = readDouble();
                        this.player.position.z = readDouble();
                        this.map.updateMap();
                        this.player.height      = stance - this.player.position.y;
                        this.player.endPosition = this.player.position;
                    }
                    Console.WriteLine(
                        "Absolute position: X:{0} Y:{1} Z:{2} Height:{3}",
                        this.player.position.x,
                        this.player.position.y,
                        this.player.position.z,
                        this.player.height
                        );
                    break;

                case PacketID.SpawnPainting:
                    Painting picture = new Painting();
                    picture.entityID                 = readInt();
                    picture.title                    = readString();
                    picture.centerPosition.x         = readInt();
                    picture.centerPosition.y         = readInt();
                    picture.centerPosition.z         = readInt();
                    picture.direction                = readInt();
                    this.entities [picture.entityID] = picture;
                    //Console.WriteLine ("Spawn Painting: {4} X:{0} Y:{1} Z:{2} Direction:{3}", x2, y2, z2, direction, title);
                    break;

                case PacketID.EntityHeadLook:
                    entityID = readInt();
                    if (entities.ContainsKey(entityID))
                    {
                        entities [entityID].headYaw = readByte();
                    }
                    else
                    {
                        readByte();
                    }
                    //Console.WriteLine ("Head yaw: {0} steps", headYew);
                    break;

                case PacketID.SpawnMob:
                    Mob mob = new Mob();
                    mob.entityID            = readInt();
                    mob.type                = readByte();
                    mob.position.x          = readInt();
                    mob.position.y          = readInt();
                    mob.position.z          = readInt();
                    mob.look.yaw            = readByte();
                    mob.look.pitch          = readByte();
                    mob.headYaw             = readByte();
                    mob.metadata            = readMetadata();
                    entities [mob.entityID] = mob;

                    /*Console.WriteLine (
                     *      "Spawn Mob: Type:{0} X:{1} Y:{2} Z:{3} Yaw:{4} Pitch:{5} Head Yaw:{6} Metadate size:{7}",
                     *      type,
                     *      x3,
                     *      y3,
                     *      z3,
                     *      yaw2,
                     *      pitch2,
                     *      headYaw2,
                     *      metadata
                     * );*/
                    break;

                case PacketID.EntityVelocity:
                    entityID = readInt();
                    if (entities.ContainsKey(entityID))
                    {
                        entities [entityID].velocity.x = readShort();
                        entities [entityID].velocity.y = readShort();
                        entities [entityID].velocity.z = readShort();
                    }
                    else
                    {
                        readShort();
                        readShort();
                        readShort();
                    }
                    //Console.WriteLine ("Velocity: X:{0} Y:{1} Z:{1}", vX / 28800.0, vY / 28800.0, vZ / 28800.0);
                    break;

                case PacketID.SpawnNamedEntity:
                {
                    OtherPlayer p = new OtherPlayer();
                    p.entityID            = readInt();
                    p.name                = readString();
                    p.position.x          = readInt();
                    p.position.y          = readInt();
                    p.position.z          = readInt();
                    p.look.yaw            = readByte();
                    p.look.pitch          = readByte();
                    p.currentItem         = readShort();
                    entities [p.entityID] = p;
                    Console.WriteLine(
                        "Player spawned: {3} X:{0} Y:{1} Z:{2} yaw:{4} pitch:{5} withItem:{6}",
                        p.position.x,
                        p.position.y,
                        p.position.z,
                        p.name,
                        p.look.yaw,
                        p.look.pitch,
                        p.currentItem
                        );
                }
                break;

                case PacketID.EntityEquipment:
                    entityID = readInt();
                    if (entities.ContainsKey(entityID) && entities [entityID].GetType() == typeof(OtherPlayer))
                    {
                        OtherPlayer p     = (OtherPlayer)entities [entityID];
                        Armor       armor = new Armor();
                        armor.slot           = readShort();
                        armor.itemID         = readShort();
                        armor.damage         = readShort();
                        p.armor [armor.slot] = armor;
                        Console.WriteLine("Equipment: slot:{0} itemID:{1} damage:{2}", armor.slot, armor.itemID, armor.damage);
                    }
                    else
                    {
                        readShort();
                        readShort();
                        readShort();
                    }
                    break;

                case PacketID.SpawnDroppedItem:
                    DroppedItem item = new DroppedItem();
                    item.entityID = readInt();
                    //readInt ();
                    item.item                = readShort();
                    item.count               = readByte();
                    item.data                = readShort();
                    item.position.x          = readInt();
                    item.position.z          = readInt();
                    item.position.y          = readInt();
                    item.rotation            = readByte();
                    item.pitch               = readByte();
                    item.roll                = readByte();
                    entities [item.entityID] = item;
                    Console.WriteLine(
                        "Dropped item: item:{0}:{2} count:{1} x:{3} y:{4} z:{5} rotation:{6} pitch:{7} roll:{8}",
                        item.item,
                        item.count,
                        item.data,
                        item.position.x,
                        item.position.y,
                        item.position.z,
                        item.rotation,
                        item.pitch,
                        item.roll
                        );
                    break;

                case PacketID.MapColumnAllocation:
                {
                    int  x    = readInt();
                    int  z    = readInt();
                    bool mode = readBool();
                    if (mode)
                    {
                        this.map.initChunk(x, z);
                    }
                    else
                    {
                        this.map.unloadChunk(x, z);
                    }

                    /*Console.WriteLine (
                     * "Need to {0} the chunk [{1};{2}]",
                     * mode ? "initialize" : "unload",
                     * x,
                     * z);*/
                    //this.map.WriteMap ();
                }
                break;

                case PacketID.PlayerListItem:
                    string name   = clearString(readString());
                    bool   online = readBool();
                    short  ping   = readShort();
                    if (online)
                    {
                        playerList [name] = ping;
                    }
                    else
                    {
                        playerList.Remove(name);
                    }
                    Console.WriteLine("Player:{0} ping:{1} {2} game", name, ping, online ? "enter" : "exit");
                    break;

                case PacketID.SetWindowItems:
                    byte  windowId = readByte();
                    short count2   = readShort();
                    //Console.Write ("Window items: count:{0}", count2);
                    for (int i = 0; i < count2; i++)
                    {
                        short id = readShort();
                        if (id != -1)
                        {
                            byte  itemCount = readByte();
                            short _data     = readShort();
                            if (_data != -1)
                            {
                                readBytes(_data);
                            }
                            //Console.Write (" [{0}: id: {1} count:{2} dataSize:{3}]", i, id, itemCount, _data);
                        }                        // else
                                                 //Console.Write (" [{0};{1}]", i, "Empty");
                    }
                    //Console.WriteLine ();
                    break;

                case PacketID.SetSlot:
                    byte  winID = readByte();
                    short _slot = readShort();
                    short _id   = readShort();
                    if (_id != -1)
                    {
                        byte  itemCount = readByte();
                        short _data     = readShort();
                        if (_data != -1)
                        {
                            readBytes(_data);
                        }

                        /*Console.WriteLine (
                         * "Set slot: [window:{4} {0}: id: {1} count:{2} dataSize:{3}]",
                         * _slot,
                         * _id,
                         * itemCount,
                         * _data,
                         * winID
                         * );*/
                    }                     //else
                    //Console.WriteLine ("Set slot: [window:{2} {0};{1}]", _slot, "Empty", winID);
                    break;

                case PacketID.SpawnExperienceOrb:
                    readInt();
                    int x7     = readInt();
                    int y7     = readInt();
                    int z7     = readInt();
                    int count3 = readShort();
                    Console.WriteLine("Spawn expirience orb: x:{0} y:{1} z:{2} count:{3}", x7, y7, z7, count3);
                    break;

                case PacketID.EntityRelativeMove:
                    entityID = readInt();
                    sbyte dx = (sbyte)readByte();
                    sbyte dy = (sbyte)readByte();
                    sbyte dz = (sbyte)readByte();
                    if (entities.ContainsKey(entityID) && entities [entityID].GetType() == typeof(OtherPlayer))
                    {
                        //Console.WriteLine ("Entity move: dx:{0:0.##} dy:{1:0.##} dz:{2:0.##}", dx/32.0, dy/32.0, dz/32.0);
                    }
                    break;

                case PacketID.EntityLook:
                    readInt();
                    byte yaw4   = readByte();
                    byte pitch5 = readByte();
                    //Console.WriteLine ("Entity rotate: yaw:{0} pitch:{1}", yaw4, pitch5);
                    break;

                case PacketID.DestroyEntity:
                    entities.Remove(readInt());
                    //Console.WriteLine ("Destroy entity");
                    break;

                case PacketID.EntityTeleport:
                    readInt();
                    int  x8     = readInt();
                    int  y8     = readInt();
                    int  z8     = readInt();
                    byte yaw8   = readByte();
                    byte pitch8 = readByte();
                    //Console.WriteLine ("Entity teleport: X:{0} Y:{1} Z:{2} yaw:{3} pitch:{4}", x8, y8, z8, yaw8, pitch8);
                    break;

                case PacketID.BlockAction:
                    int   x9    = readInt();
                    short y9    = readShort();
                    int   z9    = readInt();
                    byte  byte1 = readByte();
                    byte  byte2 = readByte();
                    //Console.WriteLine ("Block action: X:{0} Y:{1} Z:{2} bytes:[{3},{4}]",x9,y9,z9,byte1,byte2);
                    break;

                case PacketID.EntityLookandRelativeMove:
                    readInt();
                    int  x10    = readByte();
                    int  y10    = readByte();
                    int  z10    = readByte();
                    byte yaw9   = readByte();
                    byte pitch9 = readByte();
                    //Console.WriteLine ("Entity relative look/move: dX:{0} dY:{1} dZ:{2} Yaw:{3} Pitch:{4}", x10, y10, z10, yaw9, pitch9);
                    break;

                case PacketID.EntityMetadata:
                    readInt();
                    int msize = readMetadata();
                    break;

                case PacketID.Animation:
                    readInt();
                    readByte();
                    break;

                case PacketID.SpawnObjectVehicle:
                    /*for (int i =0; i<50 && i<stream.Count; i++) {
                     *      Console.Write ("{0} ",Convert.ToString (stream[i],16));
                     * }*/
                    readInt();
                    readByte();
                    readInt();
                    readInt();
                    readInt();
                    int fireball = readInt();
                    if (fireball > 0)
                    {
                        readShort();
                        readShort();
                        readShort();
                    }
                    break;

                case PacketID.EntityStatus:
                    readInt();
                    readByte();
                    break;

                case PacketID.IncrementStatistic:
                    int  statisticID = readInt();
                    byte value       = readByte();
                    Console.WriteLine("Statistic {0} change to {1}", statisticID, value);
                    break;

                case PacketID.UpdateHealth:
                    this.player.health     = readShort();
                    this.player.food       = readShort();
                    this.player.saturation = readFloat();
                    Console.WriteLine(
                        "Update health:{0} food:{1} saturation:{2}",
                        this.player.health, this.player.food, this.player.saturation);
                    if (this.player.health < 1)
                    {
                        this.SendPacket(new object[] {
                            (byte)PacketID.Respawn,
                            (int)this.dimension,
                            (byte)this.difficulty,
                            (byte)this.serverMode,
                            this.worldHeight,
                            this.levelType
                        }
                                        );
                    }
                    break;

                case PacketID.UseBed:
                    readInt();
                    readByte();
                    readInt();
                    readByte();
                    readInt();
                    Console.WriteLine("use bad");
                    break;

                case PacketID.CollectItem:
                    readInt();
                    readInt();
                    Console.WriteLine("Someone pick up items");
                    break;

                case PacketID.Entity:
                    entities [readInt()] = new Entity();
                    break;

                case PacketID.AttachEntity:
                    readInt();
                    readInt();
                    Console.WriteLine("Attach player to vehicle");
                    break;

                case PacketID.EntityEffect:
                    readInt();
                    readByte();
                    readByte();
                    readShort();
                    break;

                case PacketID.RemoveEntityEffect:
                    readInt();
                    readByte();
                    break;

                case PacketID.SetExperience:
                    readFloat();
                    readShort();
                    readShort();
                    break;

                case PacketID.MapChunks:
                {
                    int   x           = readInt();
                    int   z           = readInt();
                    bool  ground      = readBool();
                    short primarymask = readShort();
                    short addmask     = readShort();
                    int   size        = readInt();
                    readInt();
                    byte[] chunk = readBytes(size);
                    this.map.loadChunk(x, z, chunk);
                    Console.WriteLine(
                        "Chunk uploaded[{4};{5}] size:{0} ground:{1} mask:{2} mask:{3}", size, ground, Convert.ToString(primarymask, 2), Convert.ToString(addmask, 2), x, z);
                }
                break;

                case PacketID.MultiBlockChange:
                    readInt();
                    readInt();
                    readShort();
                    int _size = readInt();
                    readBytes(_size);
                    Console.WriteLine("Multi block changes size:{0}", _size);
                    break;

                case PacketID.BlockChange:
                    readInt();
                    readByte();
                    readInt();
                    readByte();
                    readByte();
                    break;

                case PacketID.Explosion:
                    readDouble();
                    readDouble();
                    readDouble();
                    readFloat();
                    int size2 = readInt();
                    readBytes(size2 * 3);
                    Console.WriteLine("Explosion records:{0}", size2);
                    break;

                case PacketID.SoundParticleEffect:
                    readInt();
                    readInt();
                    readByte();
                    readInt();
                    readInt();
                    break;

                case PacketID.ChangeGameState:
                    byte byte3 = readByte();
                    byte byte4 = readByte();
                    Console.WriteLine(@"Change game mod: reason: {0} game mod:{1}", byte3, byte4);
                    break;

                case PacketID.Thunderbolt:
                    readInt();
                    readBool();
                    readInt();
                    readInt();
                    readInt();
                    Console.WriteLine("Thunderbolt!");
                    break;

                case PacketID.OpenWindow:
                    readByte();
                    readByte();
                    string winTitle = readString();
                    int    slotnum  = readByte();
                    Console.WriteLine("Open window {0} slots:{1}", winTitle, slotnum);
                    break;

                case PacketID.CloseWindow:
                    readByte();
                    Console.WriteLine("Close window");
                    break;

                case PacketID.UpdateWindowProperty:
                    readByte();
                    readShort();
                    readShort();
                    break;

                case PacketID.ItemData:
                    readShort();
                    readShort();
                    int    textLength = readByte();
                    byte[] text       = readBytes(textLength);
                    Console.WriteLine("Item data: {0}", Encoding.ASCII.GetString(text));
                    break;

                case PacketID.UpdateTileEntity:
                    readInt();
                    readShort();
                    readInt();
                    readByte();
                    readInt();
                    readInt();
                    readInt();
                    break;

                case PacketID.Respawn:
                    this.dimension   = (Dimension)readInt();
                    this.difficulty  = (Difficulty)readByte();
                    this.serverMode  = (ServerMode)readByte();
                    this.worldHeight = readShort();
                    this.levelType   = readString();
                    Console.WriteLine("Level Type: {0}", this.levelType);
                    Console.WriteLine("Server mode: {0}", Enum.GetName(typeof(ServerMode), this.serverMode));
                    Console.WriteLine("Dimension: {0}", Enum.GetName(typeof(Dimension), this.dimension));
                    Console.WriteLine("Difficulty: {0}", Enum.GetName(typeof(Difficulty), this.difficulty));
                    Console.WriteLine("World height: {0}", this.worldHeight);
                    break;

                case PacketID.ConfirmTransaction:
                    readByte();
                    readShort();
                    readBool();
                    Console.WriteLine("Confirm transaction");
                    break;

                case PacketID.CreativeInventoryAction:
                    readShort();
                    short _id2 = readShort();
                    if (_id2 != -1)
                    {
                        byte  itemCount = readByte();
                        short _data     = readShort();
                        if (_data != -1)
                        {
                            readBytes(_data);
                        }
                    }
                    break;

                case PacketID.UpdateSign:
                    readInt();
                    readShort();
                    readInt();
                    string line1 = readString();
                    string line2 = readString();
                    string line3 = readString();
                    string line4 = readString();
                    //Console.WriteLine ("Update sign:{0} {1} {2} {3}", line1, line2, line3, line4);
                    break;

                default:
                    Console.WriteLine("Unknown response: {0} ", Convert.ToString((byte)packetID, 16));
                    isConnected = false;
                    isLogged    = false;
                    client.Close();
                    throw new Exception("Unknown response");
                    break;
                }
            }
        }