Exemplo n.º 1
0
        public void SendPacketToClient(PacketBytes packet, String playerName, Byte[] data)
        {
            ClientSocket player = this.FindPlayer(playerName) as ClientSocket;

            if (player != null)
            {
                player.SendPacket(packet, data);
            }
        }
Exemplo n.º 2
0
        private void Receive()
        {
            if (!handShakeSendToServer)
            {
                PacketGenerator gen = new PacketGenerator();
                gen.Add((byte)PacketBytes._0x02_Handshake_0x02);
                gen.Add(Name);
                client.Client.Send(gen.ToByteArray());
                handShakeSendToServer = true;
            }

            extBuffer = ReceiveBytes(client.Client, 1);

            PacketBytes firstByte = (PacketBytes)extBuffer[0];
            PacketSizes size      = MinecraftEnums.GetPacketSize(firstByte);

            if (size != PacketSizes.Minus_1)
            {
                if (firstByte == PacketBytes._0x0D_PlayerMoveAndLook_0x0D)
                {
                    size = PacketSizes.Minus_1;
                }
                if (firstByte == PacketBytes._0x03_Chat_0x03)
                {
                    size = PacketSizes.Minus_1;
                }

                if (size != PacketSizes.Minus_1)
                {
                    ReceiveBytes((int)size);
                }
            }

            if (size == PacketSizes.Minus_1)
            {
                switch (firstByte)
                {
                case PacketBytes.Minues_1:
                    break;

                case PacketBytes._0x00_KeepAlive_0x00:
                    break;

                case PacketBytes._0x01_Login_0x01:
                    if (!loginRequestReceived)
                    {
                        LoginRequest();
                    }
                    break;

                case PacketBytes._0x02_Handshake_0x02:
                    if (!handShakeReceived)
                    {
                        Handshake();
                    }
                    break;

                case PacketBytes._0x03_Chat_0x03:
                    String chat = ReceiveString(client.Client);
                    AddOutput("Chat: " + chat);
                    break;

                case PacketBytes._0x04_UpdateTime_0x04:
                    ReceiveInt64();
                    break;

                case PacketBytes._0x05_EntityEquipment_01_0x05:
                    ReceiveInt32();
                    ReceiveInt16();
                    ReceiveInt16();
                    ReceiveInt16();
                    break;

                case PacketBytes._0x06_SpawnPosition_02_0x06:
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    break;

                case PacketBytes._0x07_Use_Entity_0x07:
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveBoolean();
                    break;

                case PacketBytes._0x08_Health_0x08:
                    short health = ReceiveInt16();
                    if (health <= 0)
                    {
                        PacketGenerator gen = new PacketGenerator();
                        gen.Add(PacketBytes._0x08_Health_0x08);
                        client.Client.Send(gen.ToByteArray());
                    }
                    break;

                case PacketBytes._0x09_Respawn_0x09:
                    break;

                case PacketBytes._0x0A_Player_0x0A:
                    break;

                case PacketBytes._0x0B_PlayerPosition_0x0B:
                    break;

                case PacketBytes._0x0C_PlayerLook_0x0C:

                    break;

                case PacketBytes._0x0D_PlayerMoveAndLook_0x0D:
                    position.X          = Util.AtoD(ReceiveBytes(8), 0);
                    position.Y          = Util.AtoD(ReceiveBytes(8), 0);
                    position.Stance     = Util.AtoD(ReceiveBytes(8), 0);
                    position.Z          = Util.AtoD(ReceiveBytes(8), 0);
                    position.Rotation   = Util.AtoF(ReceiveBytes(4), 0);
                    position.Pitch      = Util.AtoF(ReceiveBytes(4), 0);
                    position.Unkown     = ByteArythmetic.GetBoolean(ReceiveBytes(1), 0);
                    moveAndLookReceived = true;
                    Move(0);
                    break;

                case PacketBytes._0x0E_BlockDig_0x0E:
                    break;

                case PacketBytes._0x0F_PlaceBlock_0x0F:
                    break;

                case PacketBytes._0x10_BlockItemSwitch_0x10:
                    ReceiveBytes(2);
                    break;

                case PacketBytes._0x11_UseBed_0x11:
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveInt32();
                    break;

                case PacketBytes._0x12_ArmAnimation_0x12:
                    ReceiveInt32();
                    ReceiveByte();
                    break;

                case PacketBytes._0x13_NewPacket_0x13:
                    ReceiveBytes(5);
                    break;

                case PacketBytes._0x14_EntitySpawnName_0x14:
                    ReceiveInt32();
                    ReceiveString(client.Client);
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveInt16();
                    break;

                case PacketBytes._0x15_EntitySpawn_0x15:
                    ReceiveInt32();
                    ReceiveInt16();
                    ReceiveByte();
                    ReceiveInt16();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    break;

                case PacketBytes._0x16_CollectItem_0x16:
                    ReceiveInt32();
                    ReceiveInt32();
                    break;

                case PacketBytes._0x17_AddObject_0x17:
                    ReceiveBytes(client.Client, 17);
                    if (Util.AtoI(ReceiveBytes(client.Client, 4), 0) > 0)
                    {
                        ReceiveBytes(client.Client, 6);
                    }
                    break;

                case PacketBytes._0x18_MobSpawn_0x18:
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    HandleInsanity(client.Client);
                    break;

                case PacketBytes._0x1B_NewPacket:
                    ReceiveFloat();
                    ReceiveFloat();
                    ReceiveFloat();
                    ReceiveFloat();
                    ReceiveBoolean();
                    ReceiveBoolean();
                    break;

                case PacketBytes._0x1C_EntityVelocity_0x1C:
                    ReceiveInt32();
                    ReceiveInt16();
                    ReceiveInt16();
                    ReceiveInt16();
                    break;

                case PacketBytes._0x1D_DestroyEntity_0x1D:
                    ReceiveInt32();
                    break;

                case PacketBytes._0x1E_Entity_0x1E:
                    ReceiveInt32();
                    break;

                case PacketBytes._0x1F_RelativeEntityMove_0x1F:
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    break;

                case PacketBytes._0x19_NewPacket_0x19:
                    ReceiveInt32();
                    ReceiveString(client.Client);
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    break;

                case PacketBytes._0x20_EntityLook_0x20:
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    break;

                case PacketBytes._0x21_RelativeEntityLookAndMove_0x21:
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    break;

                case PacketBytes._0x22_EntityTeleport_0x22:
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    break;

                case PacketBytes._0x26_HitEntity_0x26:
                    ReceiveInt32();
                    ReceiveByte();
                    break;

                case PacketBytes._0x27_AttachEntity_0x27:
                    ReceiveInt32();
                    ReceiveInt32();
                    break;

                case PacketBytes._0x28_NewPacket_0x28:
                    ReceiveInt32();
                    HandleInsanity(client.Client);
                    break;

                case PacketBytes._0x32_ChunkPre_0x32:
                    ReceiveInt32();
                    ReceiveInt32();
                    ReceiveBoolean();
                    break;

                case PacketBytes._0x33_ChunkMap_0x33:
                    ReceiveInt32();
                    ReceiveInt16();
                    ReceiveInt32();
                    ReceiveByte();
                    ReceiveByte();
                    ReceiveByte();
                    int chunkSize = ReceiveInt32();
                    ReceiveBytes(chunkSize);
                    break;

                case PacketBytes._0x34_MultiBlockChange_0x34:
                    this.ReceiveBytes(8);
                    this.ReceiveBytes(ByteArythmetic.GetInt16(this.ReceiveBytes(2), 0) * 4);
                    break;

                case PacketBytes._0x35_BlockChange_0x35:
                    ReceiveBytes(11);
                    break;

                case PacketBytes._0x36_BlockAction_0x36:
                    ReceiveBytes(12);
                    break;

                case PacketBytes._0x3C_Explosion_0x3C:
                    ReceiveBytes(28);     //8 + 8 + 8 + 4
                    ReceiveBytes(ByteArythmetic.GetInt32(ReceiveBytes(4), 0) * 3);
                    break;

                case PacketBytes._0x46_InvalidBed_0x46:
                    ReceiveByte();
                    break;

                case PacketBytes._0x47_Weather_0x47:
                    ReceiveBytes(17);
                    break;

                case PacketBytes._0x64_OpenWindow_0x64:
                    ReceiveBytes(2);
                    ReceiveStringUtf8(client.Client);     // UTF8
                    ReceiveBytes(1);
                    break;

                case PacketBytes._0x65_CloseWindow_0x65:
                    ReceiveBytes(1);
                    break;

                case PacketBytes._0x66_WindowClick_0x66:
                    ReceiveBytes(7);     // Update 1.5 + 1 bool
                    if (Util.AtoN(ReceiveBytes(2), 0) >= 0)
                    {
                        ReceiveBytes(3);
                    }
                    break;

                case PacketBytes._0x67_SetSlot_0x67:
                    ReceiveBytes(3);
                    if (Util.AtoN(ReceiveBytes(2), 0) >= 0)
                    {
                        ReceiveBytes(3);
                    }
                    break;

                case PacketBytes._0x68_WindowItems_0x68:
                    short xmax = Util.AtoN(ReceiveBytes(3), 1);
                    for (short cx = 0; cx < xmax; cx++)
                    {
                        if (Util.AtoN(ReceiveBytes(2), 0) >= 0)
                        {
                            ReceiveBytes(3);
                        }
                    }
                    break;

                case PacketBytes._0x69_UpdateProgressBar_0x69:
                    ReceiveBytes(5);
                    break;

                case PacketBytes._0x6A_Transaction_0x6A:
                    ReceiveBytes(4);
                    break;

                case PacketBytes._0x82_UpdateSign_0x82:
                    ReceiveBytes(10);
                    ReceiveString(client.Client);
                    ReceiveString(client.Client);
                    ReceiveString(client.Client);
                    ReceiveString(client.Client);
                    break;

                case PacketBytes._0x83_MapData_0x83:
                {
                    ReceiveBytes(client.Client, 4);
                    ReceiveBytes(client.Client, Util.AtoI(ReceiveBytes(client.Client, 1), 0));
                }
                break;

                case PacketBytes._0xC8_IncrementStatistics_0xC8:
                    ReceiveBytes(5);
                    break;

                case PacketBytes._0xFF_Disconnect_0xFF:
                    String str = ReceiveString(client.Client);
                    AddOutput("NPC Disconnected: " + str);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
 public void Add(PacketBytes value)
 {
     Add((byte)value);
 }
Exemplo n.º 4
0
 public static PacketSizes GetPacketSize(PacketBytes firstByte)
 {
     switch (firstByte)
     {
         case PacketBytes.Minues_1:
             return PacketSizes.Minus_1;
         case PacketBytes._0x00_KeepAlive_0x00:
             return PacketSizes._0x00_KeepAlive_0x00;
         case PacketBytes._0x01_Login_0x01:
             return PacketSizes._0x01_Login_0x01;
         case PacketBytes._0x02_Handshake_0x02:
             return PacketSizes._0x02_Handshake_0x02;
         case PacketBytes._0x03_Chat_0x03:
             return PacketSizes._0x03_Chat_0x03;
         case PacketBytes._0x04_UpdateTime_0x04:
             return PacketSizes._0x04_UpdateTime_0x04;
         case PacketBytes._0x05_EntityEquipment_01_0x05:
             return PacketSizes._0x05_EntityEquipment_01_0x05;
         case PacketBytes._0x06_SpawnPosition_02_0x06:
             return PacketSizes._0x06_SpawnPosition_02_0x06;
         case PacketBytes._0x07_Use_Entity_0x07:
             return PacketSizes._0x07_Use_Entity_0x07;
         case PacketBytes._0x08_Health_0x08:
             return PacketSizes._0x08_Health_0x08;
         case PacketBytes._0x09_Respawn_0x09:
             return PacketSizes._0x09_Respawn_0x09;
         case PacketBytes._0x0A_Player_0x0A:
             return PacketSizes._0x0A_Unkown01_0x0A;
         case PacketBytes._0x0B_PlayerPosition_0x0B:
             return PacketSizes._0x0B_PlayerPosition_0x0B;
         case PacketBytes._0x0C_PlayerLook_0x0C:
             return PacketSizes._0x0C_PlayerLook_0x0C;
         case PacketBytes._0x0D_PlayerMoveAndLook_0x0D:
             return PacketSizes._0x0D_PlayerMoveAndLook_0x0D;
         case PacketBytes._0x0E_BlockDig_0x0E:
             return PacketSizes._0x0E_BlockDig_0x0E;
         case PacketBytes._0x0F_PlaceBlock_0x0F:
             return PacketSizes._0x0F_PlaceBlock_0x0F;
         case PacketBytes._0x10_BlockItemSwitch_0x10:
             return PacketSizes._0x10_BlockItemSwitch_0x10;
         case PacketBytes._0x11_UseBed_0x11:
             return PacketSizes._0x11_UseBed_0x11;
         case PacketBytes._0x12_ArmAnimation_0x12:
             return PacketSizes._0x12_ArmAnimation_0x12;
         case PacketBytes._0x13_NewPacket_0x13:
             return PacketSizes._0x13_NewPacket_0x13;
         case PacketBytes._0x14_EntitySpawnName_0x14:
             return PacketSizes._0x14_EntitySpawnName_0x14;
         case PacketBytes._0x15_EntitySpawn_0x15:
             return PacketSizes._0x15_EntitySpawn_0x15;
         case PacketBytes._0x16_CollectItem_0x16:
             return PacketSizes._0x16_CollectItem_0x16;
         case PacketBytes._0x17_AddObject_0x17:
             return PacketSizes._0x17_Unkown02_0x17;
         case PacketBytes._0x18_MobSpawn_0x18:
             return PacketSizes._0x18_MobSpawn_0x18;
         case PacketBytes._0x19_NewPacket_0x19:
             return PacketSizes._0x19_EntityPainting_0x19;
         case PacketBytes._0x1B_NewPacket:
             return PacketSizes._0x1B_NewPacket;
         case PacketBytes._0x1C_EntityVelocity_0x1C:
             return PacketSizes._0x1C_EntityVelocity_0x1C;
         case PacketBytes._0x1D_DestroyEntity_0x1D:
             return PacketSizes._0x1D_DestroyEntity_0x1D;
         case PacketBytes._0x1E_Entity_0x1E:
             return PacketSizes._0x1E_Entity_0x1E;
         case PacketBytes._0x1F_RelativeEntityMove_0x1F:
             return PacketSizes._0x1F_RelativeEntityMove_0x1F;
         case PacketBytes._0x20_EntityLook_0x20:
             return PacketSizes._0x20_EntityLook_0x20;
         case PacketBytes._0x21_RelativeEntityLookAndMove_0x21:
             return PacketSizes._0x21_RelativeEntityLookAndMove_0x21;
         case PacketBytes._0x22_EntityTeleport_0x22:
             return PacketSizes._0x22_EntityTeleport_0x22;
         case PacketBytes._0x26_HitEntity_0x26:
             return PacketSizes._0x26_HitEntity_0x26;
         case PacketBytes._0x27_AttachEntity_0x27:
             return PacketSizes._0x27_AttachEntity_0x27;
         case PacketBytes._0x28_NewPacket_0x28:
             return PacketSizes._0x28_EntityMetadata_0x28;
         case PacketBytes._0x32_ChunkPre_0x32:
             return PacketSizes._0x32_ChunkPre_0x32;
         case PacketBytes._0x33_ChunkMap_0x33:
             return PacketSizes._0x33_ChunkMap_0x33;
         case PacketBytes._0x34_MultiBlockChange_0x34:
             return PacketSizes._0x34_MultiBlockChange_0x34;
         case PacketBytes._0x35_BlockChange_0x35:
             return PacketSizes._0x35_BlockChange_0x35;
         case PacketBytes._0x36_BlockAction_0x36:
             return PacketSizes._0x36_BlockAction_0x36;
         case PacketBytes._0x3C_Explosion_0x3C:
             return PacketSizes._0x3C_Explosion_0x3C;
         case PacketBytes._0x3D_SoundEffect_0x3D:
             return PacketSizes._0x3D_SoundEffect_0x3D;
         case PacketBytes._0x46_InvalidBed_0x46:
             return PacketSizes._0x46_InvalidBed_0x46;
         case PacketBytes._0x47_Weather_0x47:
             return PacketSizes._0x47_Weather_0x47; // Update 1.5 Weather
         case PacketBytes._0x64_OpenWindow_0x64:
             return PacketSizes._0x64_OpenWindow_0x64;
         case PacketBytes._0x65_CloseWindow_0x65:
             return PacketSizes._0x65_CloseWindow_0x65;
         case PacketBytes._0x66_WindowClick_0x66:
             return PacketSizes._0x66_WindowClick_0x66;
         case PacketBytes._0x67_SetSlot_0x67:
             return PacketSizes._0x67_SetSlot_0x67;
         case PacketBytes._0x68_WindowItems_0x68:
             return PacketSizes._0x68_WindowItems_0x68;
         case PacketBytes._0x69_UpdateProgressBar_0x69:
             return PacketSizes._0x69_UpdateProgressBar_0x69;
         case PacketBytes._0x6A_Transaction_0x6A:
             return PacketSizes._0x6A_Transaction_0x6A;
         case PacketBytes._0x82_UpdateSign_0x82:
             return PacketSizes._0x82_UpdateSign_0x82;
         case PacketBytes._0x83_MapData_0x83:
             return PacketSizes._0x83_MapData_0x83;
         case PacketBytes._0xC8_IncrementStatistics_0xC8: // Update 1.5 Statistics
             return PacketSizes._0xC8_IncrementStatistics_0xC8;
         case PacketBytes._0xFF_Disconnect_0xFF:
             return PacketSizes._0xFF_Disconnect_0xFF;
         default:
             return PacketSizes.Minus_2;
     }
 }
Exemplo n.º 5
0
 public void SendPacketToClient(PacketBytes packet, String playerName, Byte[] data)
 {
     ClientSocket player = this.FindPlayer(playerName) as ClientSocket;
     if (player != null)
     {
         player.SendPacket(packet, data);
     }
 }
Exemplo n.º 6
0
 public void SendInternalPacket(PacketBytes byteId, byte[] data, ClientSocket player)
 {
     player.SendPacket((byte)byteId, data, player.InternalSock, false);
 }
Exemplo n.º 7
0
 public void SendInternalPacket(PacketBytes byteId, byte[] data, ClientSocket player)
 {
     player.SendPacket((byte)byteId, data, player.InternalSock, false);
 }
Exemplo n.º 8
0
 public void SendPacket(PacketBytes packet_id, byte[] data)
 {
     byte id = (byte)packet_id;
     this.SendPacket(id, data, this.externalSock);
 }
Exemplo n.º 9
0
        public static PacketSizes GetPacketSize(PacketBytes firstByte)
        {
            switch (firstByte)
            {
            case PacketBytes.Minues_1:
                return(PacketSizes.Minus_1);

            case PacketBytes._0x00_KeepAlive_0x00:
                return(PacketSizes._0x00_KeepAlive_0x00);

            case PacketBytes._0x01_Login_0x01:
                return(PacketSizes._0x01_Login_0x01);

            case PacketBytes._0x02_Handshake_0x02:
                return(PacketSizes._0x02_Handshake_0x02);

            case PacketBytes._0x03_Chat_0x03:
                return(PacketSizes._0x03_Chat_0x03);

            case PacketBytes._0x04_UpdateTime_0x04:
                return(PacketSizes._0x04_UpdateTime_0x04);

            case PacketBytes._0x05_EntityEquipment_01_0x05:
                return(PacketSizes._0x05_EntityEquipment_01_0x05);

            case PacketBytes._0x06_SpawnPosition_02_0x06:
                return(PacketSizes._0x06_SpawnPosition_02_0x06);

            case PacketBytes._0x07_Use_Entity_0x07:
                return(PacketSizes._0x07_Use_Entity_0x07);

            case PacketBytes._0x08_Health_0x08:
                return(PacketSizes._0x08_Health_0x08);

            case PacketBytes._0x09_Respawn_0x09:
                return(PacketSizes._0x09_Respawn_0x09);

            case PacketBytes._0x0A_Player_0x0A:
                return(PacketSizes._0x0A_Unkown01_0x0A);

            case PacketBytes._0x0B_PlayerPosition_0x0B:
                return(PacketSizes._0x0B_PlayerPosition_0x0B);

            case PacketBytes._0x0C_PlayerLook_0x0C:
                return(PacketSizes._0x0C_PlayerLook_0x0C);

            case PacketBytes._0x0D_PlayerMoveAndLook_0x0D:
                return(PacketSizes._0x0D_PlayerMoveAndLook_0x0D);

            case PacketBytes._0x0E_BlockDig_0x0E:
                return(PacketSizes._0x0E_BlockDig_0x0E);

            case PacketBytes._0x0F_PlaceBlock_0x0F:
                return(PacketSizes._0x0F_PlaceBlock_0x0F);

            case PacketBytes._0x10_BlockItemSwitch_0x10:
                return(PacketSizes._0x10_BlockItemSwitch_0x10);

            case PacketBytes._0x11_UseBed_0x11:
                return(PacketSizes._0x11_UseBed_0x11);

            case PacketBytes._0x12_ArmAnimation_0x12:
                return(PacketSizes._0x12_ArmAnimation_0x12);

            case PacketBytes._0x13_NewPacket_0x13:
                return(PacketSizes._0x13_NewPacket_0x13);

            case PacketBytes._0x14_EntitySpawnName_0x14:
                return(PacketSizes._0x14_EntitySpawnName_0x14);

            case PacketBytes._0x15_EntitySpawn_0x15:
                return(PacketSizes._0x15_EntitySpawn_0x15);

            case PacketBytes._0x16_CollectItem_0x16:
                return(PacketSizes._0x16_CollectItem_0x16);

            case PacketBytes._0x17_AddObject_0x17:
                return(PacketSizes._0x17_Unkown02_0x17);

            case PacketBytes._0x18_MobSpawn_0x18:
                return(PacketSizes._0x18_MobSpawn_0x18);

            case PacketBytes._0x19_NewPacket_0x19:
                return(PacketSizes._0x19_EntityPainting_0x19);

            case PacketBytes._0x1B_NewPacket:
                return(PacketSizes._0x1B_NewPacket);

            case PacketBytes._0x1C_EntityVelocity_0x1C:
                return(PacketSizes._0x1C_EntityVelocity_0x1C);

            case PacketBytes._0x1D_DestroyEntity_0x1D:
                return(PacketSizes._0x1D_DestroyEntity_0x1D);

            case PacketBytes._0x1E_Entity_0x1E:
                return(PacketSizes._0x1E_Entity_0x1E);

            case PacketBytes._0x1F_RelativeEntityMove_0x1F:
                return(PacketSizes._0x1F_RelativeEntityMove_0x1F);

            case PacketBytes._0x20_EntityLook_0x20:
                return(PacketSizes._0x20_EntityLook_0x20);

            case PacketBytes._0x21_RelativeEntityLookAndMove_0x21:
                return(PacketSizes._0x21_RelativeEntityLookAndMove_0x21);

            case PacketBytes._0x22_EntityTeleport_0x22:
                return(PacketSizes._0x22_EntityTeleport_0x22);

            case PacketBytes._0x26_HitEntity_0x26:
                return(PacketSizes._0x26_HitEntity_0x26);

            case PacketBytes._0x27_AttachEntity_0x27:
                return(PacketSizes._0x27_AttachEntity_0x27);

            case PacketBytes._0x28_NewPacket_0x28:
                return(PacketSizes._0x28_EntityMetadata_0x28);

            case PacketBytes._0x32_ChunkPre_0x32:
                return(PacketSizes._0x32_ChunkPre_0x32);

            case PacketBytes._0x33_ChunkMap_0x33:
                return(PacketSizes._0x33_ChunkMap_0x33);

            case PacketBytes._0x34_MultiBlockChange_0x34:
                return(PacketSizes._0x34_MultiBlockChange_0x34);

            case PacketBytes._0x35_BlockChange_0x35:
                return(PacketSizes._0x35_BlockChange_0x35);

            case PacketBytes._0x36_BlockAction_0x36:
                return(PacketSizes._0x36_BlockAction_0x36);

            case PacketBytes._0x3C_Explosion_0x3C:
                return(PacketSizes._0x3C_Explosion_0x3C);

            case PacketBytes._0x3D_SoundEffect_0x3D:
                return(PacketSizes._0x3D_SoundEffect_0x3D);

            case PacketBytes._0x46_InvalidBed_0x46:
                return(PacketSizes._0x46_InvalidBed_0x46);

            case PacketBytes._0x47_Weather_0x47:
                return(PacketSizes._0x47_Weather_0x47);    // Update 1.5 Weather

            case PacketBytes._0x64_OpenWindow_0x64:
                return(PacketSizes._0x64_OpenWindow_0x64);

            case PacketBytes._0x65_CloseWindow_0x65:
                return(PacketSizes._0x65_CloseWindow_0x65);

            case PacketBytes._0x66_WindowClick_0x66:
                return(PacketSizes._0x66_WindowClick_0x66);

            case PacketBytes._0x67_SetSlot_0x67:
                return(PacketSizes._0x67_SetSlot_0x67);

            case PacketBytes._0x68_WindowItems_0x68:
                return(PacketSizes._0x68_WindowItems_0x68);

            case PacketBytes._0x69_UpdateProgressBar_0x69:
                return(PacketSizes._0x69_UpdateProgressBar_0x69);

            case PacketBytes._0x6A_Transaction_0x6A:
                return(PacketSizes._0x6A_Transaction_0x6A);

            case PacketBytes._0x82_UpdateSign_0x82:
                return(PacketSizes._0x82_UpdateSign_0x82);

            case PacketBytes._0x83_MapData_0x83:
                return(PacketSizes._0x83_MapData_0x83);

            case PacketBytes._0xC8_IncrementStatistics_0xC8:     // Update 1.5 Statistics
                return(PacketSizes._0xC8_IncrementStatistics_0xC8);

            case PacketBytes._0xFF_Disconnect_0xFF:
                return(PacketSizes._0xFF_Disconnect_0xFF);

            default:
                return(PacketSizes.Minus_2);
            }
        }
Exemplo n.º 10
0
 public void Add(PacketBytes value)
 {
     Add((byte)value);
 }
Exemplo n.º 11
0
        public void ReadCallback(IAsyncResult ar)
        {
            String      content = String.Empty;
            ServerState state   = (ServerState)ar.AsyncState;
            Socket      handler = state.workSocket;

            int bytesRead = 0;

            try
            {
                bytesRead = handler.EndReceive(ar);
            }
            catch (SocketException)
            {
                // Connection closed by peer
                if (OnDisconnect != null)
                {
                    OnDisconnect(this, state.endPoint);
                }
                return;
            }
            catch (ObjectDisposedException)
            {
                // Connection closed by client
                if (OnDisconnect != null)
                {
                    OnDisconnect(this, state.endPoint);
                }
                return;
            }
            catch (Exception e)
            {
                if (OnError != null)
                {
                    OnError(this, e.ToString());
                }
                return;
            }

            if (bytesRead > 0)
            {
                byte[]      data      = state.dynamicBuffer;
                PacketBytes firstByte = (PacketBytes)data[0];
                PacketSizes size      = PacketSizes.Null;

                if (state.result == null)
                {
                    switch (firstByte)
                    {
                    case PacketBytes.KeepAlive_0x00:
                        size = PacketSizes.KeepAlive_0x00;
                        break;

                    case PacketBytes.Login_0x01:
                        size = PacketSizes.Login_0x01;
                        break;

                    case PacketBytes.Handshake_0x02:
                        size = PacketSizes.Handshake_0x02;
                        break;

                    case PacketBytes.Chat_0x03:
                        size = PacketSizes.Chat_0x03;
                        break;

                    case PacketBytes.UpdateTime_0x04:
                        size = PacketSizes.UpdateTime_0x04;
                        break;

                    case PacketBytes.Unkown01_0x0A:
                        size = PacketSizes.Unkown01_0x0A;
                        break;

                    case PacketBytes.PlayerPosition_0x0B:
                        size = PacketSizes.PlayerPosition_0x0B;
                        break;

                    case PacketBytes.PlayerLook_0x0C:
                        size = PacketSizes.PlayerLook_0x0C;
                        break;

                    case PacketBytes.PlayerMoveAndLook_0x0D:
                        size = PacketSizes.PlayerMoveAndLook_0x0D;
                        break;

                    case PacketBytes.PlaceBlock_0x0F:
                        size = PacketSizes.PlaceBlock_0x0F;
                        break;

                    case PacketBytes.BlockItemSwitch_0x10:
                        size = PacketSizes.BlockItemSwitch_0x10;
                        break;

                    case PacketBytes.AddToInventory_0x11:
                        size = PacketSizes.AddToInventory_0x11;
                        break;

                    case PacketBytes.ArmAnimation_0x12:
                        size = PacketSizes.ArmAnimation_0x12;
                        break;

                    case PacketBytes.EntitySpawnName_0x14:
                        size = PacketSizes.EntitySpawnName_0x14;
                        break;

                    case PacketBytes.EntitySpawn_0x15:
                        size = PacketSizes.EntitySpawn_0x15;
                        break;

                    case PacketBytes.CollectItem_0x16:
                        size = PacketSizes.CollectItem_0x16;
                        break;

                    case PacketBytes.Unkown02_0x17:
                        size = PacketSizes.Unkown02_0x17;
                        break;

                    case PacketBytes.MobSpawn_0x18:
                        size = PacketSizes.MobSpawn_0x18;
                        break;

                    case PacketBytes.DestroyEntity_0x1D:
                        size = PacketSizes.DestroyEntity_0x1D;
                        break;

                    case PacketBytes.Entity_0x1E:
                        size = PacketSizes.Entity_0x1E;
                        break;

                    case PacketBytes.RelativeEntityMove_0x1F:
                        size = PacketSizes.RelativeEntityMove_0x1F;
                        break;

                    case PacketBytes.EntityLook_0x20:
                        size = PacketSizes.EntityLook_0x20;
                        break;

                    case PacketBytes.RelativeEntityLookAndMove_0x21:
                        size = PacketSizes.RelativeEntityLookAndMove_0x21;
                        break;

                    case PacketBytes.EntityTeleport_0x22:
                        size = PacketSizes.EntityTeleport_0x22;
                        break;

                    case PacketBytes.ChunkPre_0x32:
                        size = PacketSizes.ChunkPre_0x32;
                        break;

                    case PacketBytes.ChunkMap_0x33:
                        size = PacketSizes.ChunkMap_0x33;
                        break;

                    case PacketBytes.MultiBlockChange_0x34:
                        size = PacketSizes.MultiBlockChange_0x34;
                        break;

                    case PacketBytes.BlockChange_0x35:
                        size = PacketSizes.BlockChange_0x35;
                        break;

                    case PacketBytes.Disconnect_0xFF:
                        size = PacketSizes.Disconnect_0xFF;
                        break;
                    }

                    if (size == PacketSizes.String)
                    {
                        if (state.result == null)
                        {
                            state.result = new StringResult(this, handler, state, firstByte, data, 2);
                            state.result.Receive(); // erster einsprung
                        }
                        else
                        {
                            if (state.result.HasResult)
                            {
                                String result = (state.result as StringResult).ResultString;
                                state.result = null;
                            }
                            else
                            {
                                state.result.Receive(); // nächster einsprung
                            }
                        }
                    }

                    if (size == PacketSizes.String)
                    {
                        if (state.result == null)
                        {
                            state.result = new StringResult(this, handler, state, firstByte, data, bytesRead);
                            state.result.Receive(); // erster einsprung
                        }
                        else
                        {
                            if (state.result.HasResult)
                            {
                                String result = (state.result as StringResult).ResultString;
                                state.result = null;
                            }
                            else
                            {
                                state.result.Receive(); // nächster einsprung
                            }
                        }
                    }
                }

                if (OnByteDataAvailable != null)
                {
                    OnByteDataAvailable(this, handler, firstByte, data, bytesRead);
                }
            }
            else
            {
                // Connection closed by peer
                if (OnDisconnect != null)
                {
                    OnDisconnect(this, state.endPoint);
                }
            }
        }