public void Handle(User u, InPacket p)
        {
            ushort usernameLength = p.ReadUShort();
            string username = p.ReadString(usernameLength);
            ushort passwordLength = p.ReadUShort();
            string password = p.ReadString(passwordLength);

            Console.WriteLine("Login Request: {0}:{1}", username, password);
        }
Exemple #2
0
        public static void HandleMigrate(MapleConnection connection, InPacket packet)
        {
            ushort status = packet.ReadUShort();

            if (status == 0)
            {
                string ip   = string.Join(".", packet.ReadBytes(4));
                ushort port = packet.ReadUShort();

                packet.ReadBytes(6); // NOTE: Unknown.

                MapleConnection.User.ID = packet.ReadInt();
                MapleConnection.Instance.Reconnect(UserState.Game, ip, port);
            }
        }
		private void OnGamePortResponse(InPacket inPacket)
		{
			byte id = inPacket.ReadByte();
			ushort port = inPacket.ReadUShort();

			this.GamePortPool.Enqueue(id, port);
		}
Exemple #4
0
        protected override void Dispatch(InPacket inPacket)
        {
            try
            {
                if (inPacket.OperationCode == (ushort)ClientOpcode.LOGIN_SERVER)
                {
                    inPacket.ReadUShort();            // 原始長度
                    var Header = inPacket.ReadByte(); // 讀取包頭

                    Log.Hex("Received (0x{0:X2}) packet from {1}: ", inPacket.Content, Header, this.Title);

                    switch ((LoginClientOpcode)Header)
                    {
                    case LoginClientOpcode.LOGIN_REQ:
                        LoginHandler.Login_Req(inPacket, this);
                        break;

                    case LoginClientOpcode.SERVERLIST_REQ:
                        LoginHandler.ServerList_Req(inPacket, this);
                        break;

                    case LoginClientOpcode.GAME_REQ:
                        LoginHandler.Game_Req(inPacket, this);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Unhandled Packet Exception from {0}: \n{1}", this.Title, e.ToString());
            }
        }
Exemple #5
0
        public static void HandleSetField(MapleConnection connection, InPacket packet)
        {
            connection.Character = new Character();

            ushort loopCount = packet.ReadUShort();

            for (int i = 0; i < loopCount; i++)
            {
                packet.ReadLong();
            }

            int gameServerId = packet.ReadInt();

            packet.ReadByte();
            packet.ReadInt();
            connection.Character.PortalCount = packet.ReadByte();
            packet.ReadInt();

            bool characterData = packet.ReadBool();

            if (characterData)
            {
                HelpPacket.DecodeCharacterData(connection.Character, packet);
            }
            else
            {
            }

            Main.Instance.SetField(new Bitmap(1500, 2000));
        }
        public override void Dispatch(InPacket inPacket)
        {
            if (inPacket.OperationCode == Program.ServerIP)
            {
                ushort status = inPacket.ReadUShort();
                ushort status2 = inPacket.ReadUShort();
                byte[] ip = inPacket.ReadBytes(4);
                ushort port = inPacket.ReadUShort();
                byte[] leftover = inPacket.ReadLeftoverBytes();

                Program.IP = string.Format("{0}.{1}.{2}.{3}", ip[0], ip[1], ip[2], ip[3]);
                Program.Port = port;

                using (OutPacket outPacket = new OutPacket(Program.ServerIP))
                {
                    outPacket.WriteUShort(status);
                    outPacket.WriteUShort(status2);
                    outPacket.WriteBytes(127, 0, 0, 1);
                    outPacket.WriteUShort(8484);
                    outPacket.WriteBytes(leftover);

                    if (ClientSession.Instance != null)
                    {
                        ClientSession.Instance.Send(outPacket.ToArray());
                    }
                }
            }
            else
            {
                using (OutPacket outPacket = new OutPacket(inPacket))
                {
                    if (ClientSession.Instance != null)
                    {
                        ClientSession.Instance.Send(outPacket.ToArray());
                    }
                }
            }
        }
        public override void Dispatch(InPacket inPacket)
        {
            if (inPacket.OperationCode == Program.ServerIP)
            {
                ushort status   = inPacket.ReadUShort();
                ushort status2  = inPacket.ReadUShort();
                byte[] ip       = inPacket.ReadBytes(4);
                ushort port     = inPacket.ReadUShort();
                byte[] leftover = inPacket.ReadLeftoverBytes();

                Program.IP   = string.Format("{0}.{1}.{2}.{3}", ip[0], ip[1], ip[2], ip[3]);
                Program.Port = port;

                using (OutPacket outPacket = new OutPacket(Program.ServerIP))
                {
                    outPacket.WriteUShort(status);
                    outPacket.WriteUShort(status2);
                    outPacket.WriteBytes(127, 0, 0, 1);
                    outPacket.WriteUShort(8484);
                    outPacket.WriteBytes(leftover);

                    if (ClientSession.Instance != null)
                    {
                        ClientSession.Instance.Send(outPacket.ToArray());
                    }
                }
            }
            else
            {
                using (OutPacket outPacket = new OutPacket(inPacket))
                {
                    if (ClientSession.Instance != null)
                    {
                        ClientSession.Instance.Send(outPacket.ToArray());
                    }
                }
            }
        }
Exemple #8
0
        public void Depot_Char_tab(ClientSession cs, InPacket ip)
        {
            ushort test = ip.ReadUShort();

            CharIndex = ip.ReadInt();
            using (OutPacket oPacket = new OutPacket(GameOpcodes.EVENT_DEPOT_CHAR_TAB_INFO_ACK))
            {
                LogFactory.GetLog("Gacha").LogInfo("CHARACTER: " + CharIndex);
                oPacket.WriteInt(5);
                oPacket.WriteByte(0);
                oPacket.WriteByte((byte)CharIndex);
                oPacket.WriteHexString("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
                oPacket.Assemble(cs.CRYPT_KEY, cs.CRYPT_HMAC, cs.CRYPT_PREFIX, ++cs.CRYPT_COUNT);
                cs.Send(oPacket);
                LogFactory.GetLog("DEPOT_CHAR").LogHex("", ip.ToArray());
            }
        }
		private void OnShopPortResponse(InPacket inPacket)
		{
			ushort port = inPacket.ReadUShort();

			this.ShopPortPool.Enqueue(port);
		}
Exemple #10
0
        public void OnJoinRoom(ClientSession cs, InPacket ip)
        {
            ip.ReadByte(); // 0
            ip.ReadByte(); // 0
            ip.ReadByte(); // 0
            ip.ReadByte(); // 0
            ushort RoomID  = ip.ReadUShort();
            int    PassLen = ip.ReadInt();
            string Pass    = "";

            if (PassLen > 0)
            {
                Pass = ip.ReadUnicodeString(PassLen);
            }
            //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM ID: "+RoomID);
            //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM Length Password: "******"ROOM INFO:").LogInfo("ROOM Password: "******"Main").LogInfo(" Sergio Dean {0} metade Kana {1} {2} uma determinada ranhura ({3}, {4})", Team1, Team2, pos, EmptyPos1, EmptyPos2);

            // 방 슬롯에 정보 입력
            room.Slot[pos].Active = true;
            room.Slot[pos].cs     = cs;
            room.Slot[pos].Open   = false;
            room.Slot[pos].Spree  = 0;
            room.Slot[pos].Leader = false;
            room.Slot[pos].AFK    = false;

            // 유저한테 방 입력
            cs.CurrentRoom = room;

            // 방에 있는 사람들한테 입장했다고 알려준다. (입장하는놈은 제외)
            using (OutPacket oPacket = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_BROAD))
            {
                oPacket.WriteInt(cs.Login.Length * 2);
                oPacket.WriteUnicodeString(cs.Login);
                oPacket.WriteInt(cs.LoginUID);
                oPacket.WriteInt(cs.Nick.Length * 2);
                oPacket.WriteUnicodeString(cs.Nick);
                oPacket.WriteInt(pos);
                oPacket.WriteByte((byte)cs.CurrentChar);
                oPacket.WriteHexString("00 FF 00 FF 00 FF 00 00 00 00");
                oPacket.WriteByte((byte)(pos / 3)); // 팀을 구하면 됨. 빠르게 처리하기 위해서
                oPacket.WriteHexString("01 00 00 00 0D 00 00 00 00 10 F4 00 00 00 00 00 4E 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 51 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5F 00 00 00 00 00 00 00 00 00 00 00");
                if (room.GetRoomLeaderCS() == cs)
                {
                    oPacket.WriteByte(1);
                }
                else
                {
                    oPacket.WriteByte(0);
                }
                oPacket.WriteHexString("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

                oPacket.WriteByte((byte)cs.MyCharacter.MyChar.Length);
                for (int i = 0; i < cs.MyCharacter.MyChar.Length; i++)
                {
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].CharType);
                    //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM Chartype: " + cs.MyCharacter.MyChar[i].CharType);
                    oPacket.WriteInt(0);
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].Promotion);
                    //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM Chartype: " + cs.MyCharacter.MyChar[i].Promotion);
                    oPacket.WriteInt(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteInt(cs.MyCharacter.MyChar[i].Exp);
                    //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM Chartype: " + cs.MyCharacter.MyChar[i].Exp);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].Level);
                    //LogFactory.GetLog("ROOM INFO:").LogInfo("ROOM Chartype: " + cs.MyCharacter.MyChar[i].Level);
                    oPacket.WriteInt(0);
                    oPacket.WriteInt(0);

                    oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip.Length);
                    for (int j = 0; j < cs.MyCharacter.MyChar[i].Equip.Length; j++)
                    {
                        oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip[j].ItemID);
                        oPacket.WriteInt(1);
                        oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip[j].ItemUID);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteByte(0);
                        oPacket.WriteByte(0);
                        oPacket.WriteByte(0);
                    }

                    //oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 01 00 00 00 00 00 00 00 00 02 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 01 FF 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 2C 00 00 01 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07");
                    // 이 패킷이 아래 끝까지 분리됐음. ▼▼
                    oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 01 00");

                    // 장착한 스킬

                    /*
                     * oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill.Length);
                     * for (int j = 0; j < cs.MyCharacter.MyChar[i].EquipSkill.Length; j++)
                     * {
                     *  oPacket.WriteInt(0);
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill[j].SkillGroup);
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill[j].SkillID);
                     * }*/
                    oPacket.WriteInt(0);

                    // FF가 스킬포인트일지도
                    oPacket.WriteHexString("00 00 00 FF 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 FF 00 00 00 00 00 00");

                    // 배운 스킬

                    /*oPacket.WriteInt(cs.MyCharacter.MyChar[i].MySkill.Length);
                     * for (int j = 0; j < cs.MyCharacter.MyChar[i].MySkill.Length; j++)
                     * {
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].MySkill[j].SkillID);
                     * }*/
                    oPacket.WriteInt(0);

                    oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 2C 00 00 01 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07");
                    // ▲▲
                }
                oPacket.WriteHexString("00 00 00 04 13 00 A8 C0 01 EC A8 C0 9B BA FE A9");
                oPacket.WriteIPFromString(cs.GetIP(), false);
                oPacket.WriteHexString("00 00 00 01 7E F6 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 E5 6A 00 00 00 01 2C BD 52 5A 00 00 00 00 01 00 00 E5 88 00 00 00 01 2C BD 52 5B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 56 86 32 00 56 87 6E D4 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

                // 방에 있는 모든 유저에게 전송해야함.
                for (int i = 0; i < 6; i++)
                {
                    // 나 자신은 제외한 나머지한테 전송
                    if (room.Slot[i].Active == true && room.Slot[i].cs != cs)
                    {
                        oPacket.Assemble(room.Slot[i].cs.CRYPT_KEY, room.Slot[i].cs.CRYPT_HMAC, room.Slot[i].cs.CRYPT_PREFIX, room.Slot[i].cs.CRYPT_COUNT);
                        room.Slot[i].cs.Send(oPacket); // 패킷 보내고
                        oPacket.CancelAssemble();      // 다시 패킷 복구
                    }
                }
            }

            // 방에 접속했다고 알려준다.
            using (OutPacket op = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_INFO_ACK))
            {
                op.WriteUShort(RoomID);
                op.WriteInt(room.RoomName.Length * 2);
                op.WriteUnicodeString(room.RoomName);
                op.WriteByte(0);
                if (room.RoomPass.Length > 0)
                {
                    op.WriteByte(1); // 비밀방
                }
                else
                {
                    op.WriteByte(0); // 공개방
                }
                op.WriteInt(room.RoomPass.Length * 2);
                op.WriteUnicodeString(room.RoomPass);
                op.WriteShort((short)room.GetPlayerCount());
                op.WriteShort((short)room.GetFreeSlot());
                op.WriteHexString("00 0B");
                op.WriteByte((byte)room.GameCategory);
                op.WriteInt(room.GameMode);
                op.WriteInt(room.ItemMode);
                op.WriteBool(room.RandomMap);
                op.WriteInt(room.GameMap);
                op.WriteHexString("00 00 00 0C");
                for (int i = 0; i < 6; i++)
                {
                    op.WriteBool(room.Slot[i].Open);
                }
                op.WriteHexString("FF FF FF FF 00 00 00 00 00 00 00 00 01");
                op.WriteIPFromString(Server.UDPRelayIP, true);
                op.WriteShort(Server.UDPRelayPort);
                op.WriteIPFromString(Server.TCPRelayIP, true);
                op.WriteShort(Server.TCPRelayPort);

                op.WriteHexString("01 00 01 00 00 01 2C 00 00 00 14 00 02 4B 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 01 00 00 00 00");

                op.Assemble(cs.CRYPT_KEY, cs.CRYPT_HMAC, cs.CRYPT_PREFIX, cs.CRYPT_COUNT);
                cs.Send(op);
            }

            room.SendJoinRoomInfoDivide(cs);
            //return;

            // 방에 입장할 수 없다.
cantjoin:
            using (OutPacket op = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_INFO_DIVIDE_ACK))
            {
                op.WriteInt(6);
                op.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 30 00 00 00 F9 00 00 09 0D 00 00 00 00 00 00 00 00 F2 04 00 00 00 00 00 00 13 49 F4 FC 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 09 13 F2 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

                op.CompressAndAssemble(cs.CRYPT_KEY, cs.CRYPT_HMAC, cs.CRYPT_PREFIX, cs.CRYPT_COUNT);
                cs.Send(op);
            }
            //return;
        }
Exemple #11
0
        public override void OnPacket(InPacket iPacket)
        {
            try
            {
                iPacket.Decrypt(CRYPT_KEY);

                GameOpcodes uOpcode    = (GameOpcodes)iPacket.ReadUShort();
                int         uSize      = iPacket.ReadInt();
                bool        isCompress = iPacket.ReadBool();
                int         cSize      = 0;
                if (isCompress == true)
                {
                    cSize = iPacket.ReadInt();
                    LogFactory.GetLog("Main").LogWarning("[{0}] pacote comprimido chegada {1} ({2})", Login, (int)uOpcode, uOpcode.ToString());
                }
                else
                {
                    LogFactory.GetLog("Main").LogInfo("[{0}] de chegada de pacotes {1} ({2})", Login, (int)uOpcode, uOpcode.ToString());
                }

                LogFactory.GetLog("Main").LogHex("Pacote", iPacket.ToArray());

                switch (uOpcode)
                {
                case GameOpcodes.EVENT_HEART_BIT_NOT:     // 0
                    OnHeartBeatNot();
                    break;

                case GameOpcodes.EVENT_CHANGE_CHARACTER_INFO_REQ:     //1618
                    InfoChars.ChangeCharInfo(this);
                    break;

                case GameOpcodes.EVENT_VERIFY_ACCOUNT_REQ:     // 2
                    MyUser.OnLogin(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_CURRENT_CHARACTER_REQ:
                    MyCommon.SetCurretChar(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GET_FULL_SP_INFO_REQ:     // 423 0x1A7
                    MyCommon.OnGetFullSPInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_PET_COSTUM_LIST_REQ:     // 517 0x205
                    MyCommon.OnPetCostumList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_INVEN_BUFF_ITEM_LIST_REQ:     // 1226 0x04CA
                    MyCommon.OnInvenBuffItemList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_DEPOT_INFO_REQ:     // 1340 0x053C
                    MyCommon.OnDepotInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_STAT_CLIENT_INFO:     // 226 0x00E2
                    MyCommon.OnStatClientInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_COST_RATE_FOR_GAMBLE_BUY_REQ:     // 871 0x0367
                    MyCommon.OnCostRateForGambleBuy(this);
                    break;

                case GameOpcodes.EVENT_REGISTER_NICKNAME_REQ:     // 134 0x0086
                    MyUser.OnRegisterNick(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_IDLE_STATE_REQ:     // 835 0x0343
                    MyCommon.OnSetIDLE(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHAR_SELECT_JOIN_REQ:     // 1557 0x0613
                    MyUser.OnCharSelectJoin(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHOICE_BOX_LIST_REQ:     // 1012 0x03F4
                    MyCommon.OnChoiceBoxList(this);
                    break;

                case GameOpcodes.EVENT_EXP_POTION_LIST_REQ:     // 1338 0x053A
                    MyCommon.OnExpPotionList(this);
                    break;

                case GameOpcodes.EVENT_AGIT_STORE_CATALOG_REQ:     // 1114 0x054A
                    MyCommon.OnAgitStoreCatalog(this);
                    break;

                case GameOpcodes.EVENT_AGIT_STORE_MATERIAL_REQ:     // 1116 0x045C
                    MyCommon.OnAgitStoreMaterial(this);
                    break;

                case GameOpcodes.EVENT_AGIT_MAP_CATALOGUE_REQ:     // 1106 0x0452
                    MyCommon.OnAgitMapCatalogue(this);
                    break;

                case GameOpcodes.EVENT_FAIRY_TREE_LV_TABLE_REQ:     // 1184 0x04A0
                    MyCommon.OnFaityTreeLvTable(this);
                    break;

                case GameOpcodes.EVENT_INVITE_DENY_NOT:     // 348 0x015C
                    InviteDeny = iPacket.ReadBool();
                    break;

                case GameOpcodes.EVENT_GET_USER_DONATION_INFO_REQ:     // 523 0x020B
                    MyCommon.OnGetUserDonationInfo(this);
                    break;

                case GameOpcodes.EVENT_RECOMMEND_FULL_INFO_REQ:     // 567 0x0237
                    MyCommon.OnRecommentUser(this);
                    break;

                case GameOpcodes.EVENT_USER_BINGO_DATA_REQ:     // 654 0x28E
                    MyCommon.OnUserBingoData(this);
                    break;

                case GameOpcodes.EVENT_CHANNEL_LIST_REQ:     // 14 0x0E
                    MyCommon.OnChannelList(this);
                    break;

                case GameOpcodes.EVENT_DONATION_INFO_REQ:     // 525 0x020D
                    MyCommon.OnDonationInfo(this);
                    break;

                case GameOpcodes.EVENT_ENTER_CHANNEL_REQ:     // 12 0x0C
                    MyUser.OnEnterChannel(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_CHANNEL_NOT:     // 26
                    MyUser.OnLeaveChannel(this);
                    break;

                case GameOpcodes.EVENT_CREATE_ROOM_REQ:
                    MyUser.OnCreateRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_ROOM_INFO_REQ:
                    CurrentRoom.OnChangeRoomInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_ROOMUSER_INFO_REQ:
                    CurrentRoom.OnChangeUserInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_ROOM_REQ:
                    CurrentRoom.OnLeaveRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_ROOM_LIST_REQ:
                    CurrentChannel.OnRoomList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_JOIN_ROOM_REQ:
                    CurrentChannel.OnJoinRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_START_GAME_REQ:
                    CurrentRoom.StartGame(this, iPacket);
                    break;

                case GameOpcodes.EVENT_RELAY_LOADING_STATE:
                    CurrentRoom.OnLoadState(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LOAD_COMPLETE_NOT:
                    //MyUser.LoadComplete(this, iPacket);
                    CurrentRoom.OnLoadComplete(this, iPacket);
                    break;

                case GameOpcodes.EVENT_STAGE_LOAD_COMPLETE_NOT:
                    //MyUser.StageLoadComplete(this, iPacket);
                    CurrentRoom.OnStageLoadComplete(this, iPacket);
                    break;

                case GameOpcodes.EVENT_ROOM_MEMBER_PING_INFO_REQ:
                    CurrentRoom.OnPingInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GET_ROOMUSER_IDLE_STATE_REQ:
                    CurrentRoom.OnIdleInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_END_GAME_REQ:
                    CurrentRoom.OnGameEnd(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHAT_REQ:
                    CurrentChannel.OnChat(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_GAME_REQ:
                    CurrentRoom.OnLeaveGame(this, iPacket);
                    break;

                case GameOpcodes.EVENT_EQUIP_ITEM_REQ:
                    MyCharacter.OnEquipItem(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_LOOK_EQUIP_REQ:
                    MyCharacter.OnChangeEquipInRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_PRESS_STATE_REQ:
                    CurrentRoom.OnSetPressState(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SKILL_TRAINING_REQ:
                    MyCharacter.OnTrainSkill(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_SKILL_REQ:
                    MyCharacter.OnSetSkill(this, iPacket);
                    break;

                case GameOpcodes.DB_EVENT_SYSTEM_GUIDE_COMPLETE_INFO_REQ:
                    MyCommon.SendGuideCompleteInfo(this);
                    break;

                case GameOpcodes.EVENT_CASHBACK_EXTRA_RATIO_INFO_REQ:
                    MyShop.CashRatio(this);
                    break;

                case GameOpcodes.EVENT_PACKAGE_INFO_REQ:
                    MyShop.packageInfo(this);
                    break;

                case GameOpcodes.EVENT_PACKAGE_INFO_DETAIL_REQ:
                    MyShop.packageInfoDetail(this, iPacket);
                    break;

                default:
                {
                    LogFactory.GetLog("Main").LogWarning("pacote indefinido foi recebido. Opcode: {0}({1})", (int)uOpcode, uOpcode.ToString());
                    LogFactory.GetLog("Main").LogHex("Pacote", iPacket.ToArray());
                    break;
                }
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLog("Main").LogFatal(e);
                Close();
            }
        }
        private void OnRegistrationRequest(InPacket inPacket)
        {
            ServerUtilities.ServerType type = (ServerUtilities.ServerType)inPacket.ReadByte();
            string     securityCode         = inPacket.ReadString();
            IPEndPoint endPoint             = new IPEndPoint(inPacket.ReadIPAddress(), inPacket.ReadUShort());
            World      world = LoginServer.Worlds.Next(type);

            bool worked = false;

            using (OutPacket outPacket = new OutPacket(InteroperabilityMessage.RegistrationResponse))
            {
                if (securityCode != LoginServer.SecurityCode)
                {
                    outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidCode);

                    Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                   .ServerRegistrationResponse.InvalidCode));
                }
                else if (world == null)
                {
                    outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.WorldsFull);

                    Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                   .ServerRegistrationResponse.WorldsFull));
                }
                else
                {
                    if (world.HostIP.ToString() != endPoint.Address.ToString())
                    {
                        outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidIP);

                        Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                       .ServerRegistrationResponse.InvalidIP));
                    }
                    else
                    {
                        this._type          = type;
                        this.RemoteEndPoint = endPoint;
                        this.WorldID        = world.ID;

                        switch (this._type)
                        {
                        case ServerUtilities.ServerType.Char:
                        {
                            this.World.CharServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Game:
                        {
                            this.World.Add(this);
                            this._id = (byte)this.World.Count;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);
                            outPacket.WriteByte(this.ExternalID);
                            outPacket.WriteString(this.World.ScrollingHeader);
                            outPacket.WriteInt(this.World.Rates.Experience);
                            outPacket.WriteInt(this.World.Rates.QuestExperience);
                            outPacket.WriteInt(this.World.Rates.PartyQuestExperience);
                            outPacket.WriteInt(this.World.Rates.Meso);
                            outPacket.WriteInt(this.World.Rates.Loot);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Message:
                        {
                            this.World.MessageServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Shop:
                        {
                            this.World.ShopServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;
                        }
                    }
                }

                this.Send(outPacket);
            }

            if (worked)
            {
                switch (this._type)
                {
                case ServerUtilities.ServerType.Char:
                {
                    Log.Success("Registered Char {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Game:
                {
                    Log.Success("Registered Game {0}-{1} at {2}.", this.World.Name, this.ExternalID,
                                this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Message:
                {
                    Log.Success("Registered Message {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Shop:
                {
                    Log.Success("Registered Shop {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;
                }
            }
            else
            {
                Log.Warn("Server registration failed.");

                this.Stop();
            }
        }
Exemple #13
0
        public void OnJoinRoom(ClientSession cs, InPacket ip)
        {
            ip.ReadByte(); // 0
            ip.ReadByte(); // 0
            ip.ReadByte(); // 0
            ushort RoomID  = ip.ReadUShort();
            int    PassLen = ip.ReadInt();
            string Pass    = "";

            if (PassLen > 0)
            {
                Pass = ip.ReadUnicodeString(PassLen);
            }


            Room room = GetRoom(RoomID);


            if (room == null)
            {
                goto cantjoin;
            }


            if (room.GetFreeSlot() == 0 || room.Playing == true || cs.CurrentRoom != null)
            {
                goto cantjoin;
            }


            if (room.RoomPass != Pass)
            {
                goto cantjoin;
            }


            byte Team1 = 0, Team2 = 0;
            int  EmptyPos1 = -1, EmptyPos2 = -1;

            for (int i = 0; i < 3; i++)
            {
                if (room.Slot[i].Active == true)
                {
                    Team1++;
                }
                if (EmptyPos1 == -1 && room.Slot[i].Open == true)
                {
                    EmptyPos1 = i;
                }
            }
            for (int i = 3; i < 6; i++)
            {
                if (room.Slot[i].Active == true)
                {
                    Team2++;
                }
                if (EmptyPos2 == -1 && room.Slot[i].Open == true)
                {
                    EmptyPos2 = i;
                }
            }


            int pos = EmptyPos1;

            if (Team1 >= Team2)
            {
                pos = EmptyPos2;
            }

            room.Slot[pos].Active = true;
            room.Slot[pos].cs     = cs;
            room.Slot[pos].Open   = false;
            room.Slot[pos].Spree  = 0;
            room.Slot[pos].Leader = false;
            room.Slot[pos].AFK    = false;


            cs.CurrentRoom = room;


            using (OutPacket oPacket = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_BROAD))
            {
                oPacket.WriteInt(cs.Login.Length * 2);
                oPacket.WriteUnicodeString(cs.Login);
                oPacket.WriteInt(cs.LoginUID);
                oPacket.WriteInt(cs.Nick.Length * 2);
                oPacket.WriteUnicodeString(cs.Nick);
                oPacket.WriteInt(pos);
                oPacket.WriteByte((byte)cs.CurrentChar);
                oPacket.WriteHexString("00 FF 00 FF 00 FF 00 00 00 00");
                oPacket.WriteByte((byte)(pos / 3));
                oPacket.WriteHexString("01 00 00 00 0D 00 00 00 00 10 F4 00 00 00 00 00 4E 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 51 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5F 00 00 00 00 00 00 00 00 00 00 00");
                if (room.GetRoomLeaderCS() == cs)
                {
                    oPacket.WriteByte(1);
                }
                else
                {
                    oPacket.WriteByte(0);
                }
                oPacket.WriteHexString("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

                oPacket.WriteByte((byte)cs.MyCharacter.MyChar.Length);
                for (int i = 0; i < cs.MyCharacter.MyChar.Length; i++)
                {
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].CharType);
                    oPacket.WriteInt(0);
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].Promotion);
                    oPacket.WriteInt(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteInt(cs.MyCharacter.MyChar[i].Exp);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte(0);
                    oPacket.WriteByte((byte)cs.MyCharacter.MyChar[i].Level);
                    oPacket.WriteInt(0);
                    oPacket.WriteInt(0);

                    oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip.Length);
                    for (int j = 0; j < cs.MyCharacter.MyChar[i].Equip.Length; j++)
                    {
                        oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip[j].ItemID);
                        oPacket.WriteInt(1);
                        oPacket.WriteInt(cs.MyCharacter.MyChar[i].Equip[j].ItemUID);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteInt(0);
                        oPacket.WriteByte(0);
                        oPacket.WriteByte(0);
                        oPacket.WriteByte(0);
                    }

                    //oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 01 00 00 00 00 00 00 00 00 02 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 01 FF 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 2C 00 00 01 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07");

                    oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 01 00");


                    /*
                     * oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill.Length);
                     * for (int j = 0; j < cs.MyCharacter.MyChar[i].EquipSkill.Length; j++)
                     * {
                     *  oPacket.WriteInt(0);
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill[j].SkillGroup);
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].EquipSkill[j].SkillID);
                     * }*/
                    oPacket.WriteInt(0);


                    oPacket.WriteHexString("00 00 00 FF 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 FF 00 00 00 00 00 00");


                    /*oPacket.WriteInt(cs.MyCharacter.MyChar[i].MySkill.Length);
                     * for (int j = 0; j < cs.MyCharacter.MyChar[i].MySkill.Length; j++)
                     * {
                     *  oPacket.WriteInt(cs.MyCharacter.MyChar[i].MySkill[j].SkillID);
                     * }*/
                    oPacket.WriteInt(0);

                    oPacket.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 2C 00 00 01 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07");
                }
                oPacket.WriteHexString("00 00 00 04 13 00 A8 C0 01 EC A8 C0 9B BA FE A9");
                oPacket.WriteIPFromString(cs.GetIP(), false);
                oPacket.WriteHexString("00 00 00 01 7E F6 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 E5 6A 00 00 00 01 2C BD 52 5A 00 00 00 00 01 00 00 E5 88 00 00 00 01 2C BD 52 5B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 56 86 32 00 56 87 6E D4 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");


                for (int i = 0; i < 6; i++)
                {
                    if (room.Slot[i].Active == true && room.Slot[i].cs != cs)
                    {
                        oPacket.Assemble(room.Slot[i].cs.CRYPT_KEY, room.Slot[i].cs.CRYPT_HMAC, room.Slot[i].cs.CRYPT_PREFIX, room.Slot[i].cs.CRYPT_COUNT);
                        room.Slot[i].cs.Send(oPacket);
                        oPacket.CancelAssemble();
                    }
                }
            }


            using (OutPacket op = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_INFO_ACK))
            {
                op.WriteUShort(RoomID);
                op.WriteInt(room.RoomName.Length * 2);
                op.WriteUnicodeString(room.RoomName);
                op.WriteByte(0);
                if (room.RoomPass.Length > 0)
                {
                    op.WriteByte(1);
                }
                else
                {
                    op.WriteByte(0);
                }
                op.WriteInt(room.RoomPass.Length * 2);
                op.WriteUnicodeString(room.RoomPass);
                op.WriteShort((short)room.GetPlayerCount());
                op.WriteShort((short)room.GetFreeSlot());
                op.WriteHexString("00 0B");
                op.WriteByte((byte)room.GameCategory);
                op.WriteInt(room.GameMode);
                op.WriteInt(room.ItemMode);
                op.WriteBool(room.RandomMap);
                op.WriteInt(room.GameMap);
                op.WriteHexString("00 00 00 0C");
                for (int i = 0; i < 6; i++)
                {
                    op.WriteBool(room.Slot[i].Open);
                }
                op.WriteHexString("FF FF FF FF 00 00 00 00 00 00 00 00 01");
                op.WriteIPFromString(Server.UDPRelayIP, true);
                op.WriteShort(Server.UDPRelayPort);
                op.WriteIPFromString(Server.TCPRelayIP, true);
                op.WriteShort(Server.TCPRelayPort);

                op.WriteHexString("01 00 01 00 00 01 2C 00 00 00 14 00 02 4B 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 01 00 00 00 00");

                op.Assemble(cs.CRYPT_KEY, cs.CRYPT_HMAC, cs.CRYPT_PREFIX, cs.CRYPT_COUNT);
                cs.Send(op);
            }

            room.SendJoinRoomInfoDivide(cs);
            return;


cantjoin:
            using (OutPacket op = new OutPacket(GameOpcodes.EVENT_JOIN_ROOM_INFO_DIVIDE_ACK))
            {
                op.WriteInt(6);
                op.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 01 30 00 00 00 F9 00 00 09 0D 00 00 00 00 00 00 00 00 F2 04 00 00 00 00 00 00 13 49 F4 FC 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 09 13 F2 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

                op.CompressAndAssemble(cs.CRYPT_KEY, cs.CRYPT_HMAC, cs.CRYPT_PREFIX, cs.CRYPT_COUNT);
                cs.Send(op);
            }
            return;
        }
        public override void OnPacket(InPacket iPacket)
        {
            try
            {
                iPacket.Decrypt(CRYPT_KEY);

                GameOpcodes uOpcode    = (GameOpcodes)iPacket.ReadUShort();
                int         uSize      = iPacket.ReadInt();
                bool        isCompress = iPacket.ReadBool();
                int         cSize      = 0;
                if (isCompress == true)
                {
                    cSize = iPacket.ReadInt();
                    LogFactory.GetLog("Main").LogWarning("[{0}] Pacote comprimido {1}({2})", Login, (int)uOpcode, uOpcode.ToString());
                }
                else
                {
                    LogFactory.GetLog("Main").LogInfo("[{0}] Packet {1}({2})", Login, (int)uOpcode, uOpcode.ToString());
                }

                LogFactory.GetLog("Main").LogHex("Pacote: ", iPacket.ToArray());

                switch (uOpcode)
                {
                case GameOpcodes.HEART_BIT_NOT:     // 0
                    OnHeartBeatNot();
                    break;

                case GameOpcodes.EVENT_VERIFY_ACCOUNT_REQ:     // 2
                    MyUser.OnLogin(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GET_FULL_SP_INFO_REQ:     // 423 0x1A7
                    MyCommon.OnGetFullSPInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_PET_COSTUM_LIST_REQ:     // 517 0x205
                    MyCommon.OnPetCostumList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_INVEN_BUFF_ITEM_LIST_REQ:     // 1226 0x04CA
                    MyCommon.OnInvenBuffItemList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_DEPOT_INFO_REQ:     // 1340 0x053C
                    MyCommon.OnDepotInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_STAT_CLIENT_INFO:     // 226 0x00E2
                    MyCommon.OnStatClientInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_COST_RATE_FOR_GAMBLE_BUY_REQ:     // 871 0x0367
                    MyCommon.OnCostRateForGambleBuy(this);
                    break;

                case GameOpcodes.EVENT_ENTER_AGIT_REQ:    //AGITT
                    MyAgit.EnterAgit(this);
                    break;

                case GameOpcodes.EVENT_AGIT_LOADING_COMPLETE_REQ:    //AGITT
                    MyAgit.AgitLoadComplete(this);
                    break;

                case GameOpcodes.EVENT_REGISTER_NICKNAME_REQ:     // 134 0x0086
                    MyUser.OnRegisterNick(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_IDLE_STATE_REQ:     // 835 0x0343
                    MyCommon.OnSetIDLE(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHAR_SELECT_JOIN_REQ:     // 1555 0x0613
                    MyUser.OnCharSelectJoin(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHOICE_BOX_LIST_REQ:     // 1012 0x03F4
                    MyCommon.OnChoiceBoxList(this);
                    break;

                case GameOpcodes.EVENT_EXP_POTION_LIST_REQ:     // 1338 0x053A
                    MyCommon.OnExpPotionList(this);
                    break;

                case GameOpcodes.EVENT_AGIT_STORE_CATALOG_REQ:     // 1114 0x054A
                    MyCommon.OnAgitStoreCatalog(this);
                    break;

                case GameOpcodes.EVENT_AGIT_STORE_MATERIAL_REQ:     // 1116 0x045C
                    MyCommon.OnAgitStoreMaterial(this);
                    break;

                case GameOpcodes.EVENT_AGIT_MAP_CATALOGUE_REQ:     // 1106 0x0452
                    MyCommon.OnAgitMapCatalogue(this);
                    break;

                case GameOpcodes.EVENT_FAIRY_TREE_LV_TABLE_REQ:     // 1184 0x04A0
                    MyCommon.OnFaityTreeLvTable(this);
                    break;

                case GameOpcodes.EVENT_INVITE_DENY_NOT:     // 348 0x015C
                    InviteDeny = iPacket.ReadBool();
                    break;

                case GameOpcodes.EVENT_GET_USER_DONATION_INFO_REQ:     // 523 0x020B
                    MyCommon.OnGetUserDonationInfo(this);
                    break;

                case GameOpcodes.EVENT_RECOMMEND_FULL_INFO_REQ:     // 567 0x0237
                    MyCommon.OnRecommentUser(this);
                    break;

                case GameOpcodes.EVENT_USER_BINGO_DATA_REQ:     // 654 0x28E
                    MyCommon.OnUserBingoData(this);
                    break;

                case GameOpcodes.EVENT_CHANNEL_LIST_REQ:     // 14 0x0E
                    MyCommon.OnChannelList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_DONATION_INFO_REQ:     // 525 0x020D
                    MyCommon.OnDonationInfo(this);
                    break;

                case GameOpcodes.EVENT_ENTER_CHANNEL_REQ:     // 12 0x0C
                    MyUser.OnEnterChannel(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_CHANNEL_NOT:     // 26
                    MyUser.OnLeaveChannel(this);
                    break;

                case GameOpcodes.EVENT_CREATE_ROOM_REQ:     // 24 방 만들기
                    MyUser.OnCreateRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_ROOM_INFO_REQ:     // 28 0x1C 방의 게임모드 정보 바뀜
                    CurrentRoom.OnChangeRoomInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_ROOMUSER_INFO_REQ:     // 40 0x28 방의 유저 정보 바뀜
                    CurrentRoom.OnChangeUserInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_ROOM_REQ:     // 33 0x21 방에서 나가기 요청
                    CurrentRoom.OnLeaveRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_ROOM_LIST_REQ:     // 16 0x10 방 목록 요청
                    CurrentChannel.OnRoomList(this, iPacket);
                    break;

                case GameOpcodes.EVENT_JOIN_ROOM_REQ:     // 20 방 입장 요청
                    CurrentChannel.OnJoinRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_START_GAME_REQ:     // 36 게임 시작 요청
                    CurrentRoom.OnGameStart(this, iPacket);
                    break;

                case GameOpcodes.EVENT_RELAY_LOADING_STATE:     // 842 게임로딩중 로딩진행도
                    CurrentRoom.OnLoadState(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LOAD_COMPLETE_NOT:     // 39 로딩 끝났다는거 전송 (게임으로 들여보내짐)
                    CurrentRoom.OnLoadComplete(this, iPacket);
                    break;

                case GameOpcodes.EVENT_STAGE_LOAD_COMPLETE_NOT:     // 927 스테이지 로딩이 끝났다
                    CurrentRoom.OnStageLoadComplete(this, iPacket);
                    break;

                case GameOpcodes.EVENT_ROOM_MEMBER_PING_INFO_REQ:     // 837 게임 멤버 핑 정보 요청 (게임시작 할때 쓰나봄)
                    CurrentRoom.OnPingInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GET_ROOMUSER_IDLE_STATE_REQ:     // 833 자리비움 상태 요청
                    CurrentRoom.OnIdleInfo(this, iPacket);
                    break;

                case GameOpcodes.EVENT_END_GAME_REQ:     // 게임 종료
                    CurrentRoom.OnGameEnd(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHAT_REQ:     // 6 채팅!
                    CurrentChannel.OnChat(this, iPacket);
                    break;

                case GameOpcodes.EVENT_LEAVE_GAME_REQ:     // 44 게임중 나가기
                    CurrentRoom.OnLeaveGame(this, iPacket);
                    break;

                case GameOpcodes.EVENT_EQUIP_ITEM_REQ:     // 62 장비 변경 요청
                    MyCharacter.OnEquipItem(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHANGE_LOOK_EQUIP_REQ:     // 860 방에서 장비변경 요청 (이게 선처리 된 후 EVENT_EQUIP_ITEM_REQ)
                    MyCharacter.OnChangeEquipInRoom(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_PRESS_STATE_REQ:     // 방에서 다른 용무중
                    CurrentRoom.OnSetPressState(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SKILL_TRAINING_REQ:     // 스킬 배우기
                    MyCharacter.OnTrainSkill(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SET_SKILL_REQ:     // 스킬 장착 요청
                    MyCharacter.OnSetSkill(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SERVER_LIST_REQ:
                    MyUser.SendServerList(this);
                    break;

                case GameOpcodes.EVENT_SQUARE_LIST_REQ:
                    square.SquareList(this);
                    break;

                case GameOpcodes.EVENT_ENTER_SQUARE_REQ:
                    square.enterSquare(this);
                    break;

                case GameOpcodes.EVENT_LEAVE_SQUARE_REQ:
                    square.LeaveSquare(this);
                    break;

                case GameOpcodes.EVENT_CASHBACK_EXTRA_RATIO_INFO_REQ:
                    MyShop.CashRatio(this);
                    break;

                case GameOpcodes.EVENT_PACKAGE_INFO_REQ:
                    MyShop.packageInfo(this);
                    break;

                case GameOpcodes.EVENT_PACKAGE_INFO_DETAIL_REQ:
                    MyShop.packageInfoDetail(this, iPacket);
                    break;

                case GameOpcodes.EVENT_ITEM_BUY_CHECK_REQ:
                    MyShop.CheckItem(this, iPacket);
                    break;

                case GameOpcodes.EVENT_BUY_VIRTUAL_CASH_REQ:
                    MyShop.BuyVP(this, iPacket);
                    break;

                case GameOpcodes.EVENT_BUY_FOR_GP_REQ:
                    MyShop.BuyGP(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CHARISMAS_EVENT_INFO_REQ:
                    MyCommon.Event_Gifts(this);
                    break;

                case GameOpcodes.EVENT_CHECK_ROOM_USERLIST_NOT:
                    CurrentRoom.checkRoomUser(this);
                    break;

                case GameOpcodes.EVENT_STAT_LOADING_TIME_NOT:
                    CurrentRoom.statLoadingTime(this, iPacket);
                    break;

                case GameOpcodes.EVENT_SPECIAL_REWARD_REQ:
                    CurrentRoom.RewardItem(this, iPacket);
                    break;

                case GameOpcodes.EVENT_DEPOT_CHAR_TAB_INFO_REQ:
                    GachaList.Depot_Char_tab(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GACHA_REWARD_LIST_REQ:
                    GachaList.Gacha_Reward_List(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GACHA_SET_REWARD_LIST_REQ:
                    GachaList.Gacha_SET_Reward_List(this, iPacket);
                    break;

                case GameOpcodes.EVENT_GACHA_LEVEL_ACTION_REQ:
                    GachaList.Gacha_Action(this, iPacket);
                    break;

                case GameOpcodes.EVENT_REMOVE_MISSION_REQ:
                    MyQuests.RemoveMission(this, iPacket);
                    break;

                case GameOpcodes.EVENT_REGIST_MISSION_REQ:
                    MyQuests.RegisterMission(this, iPacket);
                    break;

                case GameOpcodes.EVENT_COMPLETE_MISSION_REQ:
                    MyQuests.CompleteMission(this, iPacket);
                    break;

                case GameOpcodes.EVENT_CREATE_PET_REQ:
                    MyPet.create_pet(this, iPacket);
                    break;

                case GameOpcodes.EVENT_HERO_ITEM_CATALOG_REQ:
                    heroico.Hero_Item_Catalog(this);
                    break;

                case GameOpcodes.EVENT_HERO_ITEM_MATERIAL_REQ:
                    heroico.Hero_Item_Material(this);
                    break;

                case GameOpcodes.EVENT_MANUFACTURES3_CATALOG_REQ:
                    manufacture.Manufacture_Catalog(this);
                    break;

                case GameOpcodes.EVENT_SPECIFIC_ITEM_BREAKUP_INFO_REQ:
                    manufacture.SpecificItemBreakup(this);
                    break;

                case GameOpcodes.EVENT_MANUFACTURES3_MATERIAL_REQ:
                    manufacture.ManuFactureMaterial(this);
                    break;

                case GameOpcodes.EVENT_DUNGEON_REWARD_EXP_REQ:
                    CurrentRoom.RewardEXP(this, iPacket);
                    break;

                case GameOpcodes.EVENT_USER_LIST_REQ:
                    MyUser.ListUsers(this);
                    break;

                default:
                {
                    LogFactory.GetLog("Main").LogWarning("pacote indefinido foi recebida. Opcode: {0}({1})", (int)uOpcode, uOpcode.ToString());
                    LogFactory.GetLog("Main").LogHex("Pacote: ", iPacket.ToArray());
                    break;
                }
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLog("Main").LogError(e.ToString());
                Close();
            }
        }