BattleNet.RealmServer.CharacterList C# (CSharp) Method

CharacterList() protected method

protected CharacterList ( byte type, List data ) : void
type byte
data List
return void
        protected void CharacterList(byte type, List<byte> data)
        {
            UInt16 count = BitConverter.ToUInt16(data.ToArray(), 9);
            if (count == 0)
            {
                Console.WriteLine("{0}: [MCP] There are no characters on this account", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_ON_MCP;
            }
            else
            {
                bool foundCharacter = false;
                bool selectFirstCharacter = false;
                if (ClientlessBot.debugging)
                    Console.WriteLine("{0}: [MCP] List of characters on this account", m_owner.Account);
                int offset = 11;

                for (int i = 1; i <= count; i++)
                {
                    offset += 4;
                    String dataString = System.Text.Encoding.ASCII.GetString(data.ToArray());
                    String characterName = Utils.readNullTerminatedString(dataString, ref offset);
                    int length = data.IndexOf(0, offset)-offset;
                    List<byte> stats = data.GetRange(offset,length);
                    offset += length;
                    m_owner.ClassByte =(byte)((stats[13] - 0x01) & 0xFF);
                    byte level = stats[25];
                    byte flags = stats[26];
                    bool hardcore = (flags & 0x04) != 0;
                    bool dead = (flags & 0x08) != 0;
                    bool expansion = (flags & 0x20) != 0;
                    String coreString = hardcore ? "Hardcore" : "Softcore";
                    String versionString = expansion ? "Expansion" : "Classic";
                    String classType;

                    switch (m_owner.ClassByte)
                    {
                        case 0: classType = "Amazon";
                            break;
                        case 1: classType = "Sorceress";
                            break;
                        case 2: classType = "Necromancer";
                            break;
                        case 3: classType = "Paladin";
                            break;
                        case 4: classType = "Barbarian";
                            break;
                        case 5: classType = "Druid";
                            break;
                        case 6: classType = "Assassin";
                            break;
                        default: classType = "Unknown";
                            break;
                    }

                    if (ClientlessBot.debugging)
                        Console.WriteLine("{0}: [MCP] {1}. {2}, Level: {3}, {6} ({4}|{5})", m_owner.Account, i, characterName, level, coreString, versionString, classType);

                    if (m_owner.Character == null && i == 1)
                    {
                        selectFirstCharacter = true;
                        m_owner.Character = characterName;
                    }

                    if (m_owner.Character.Equals(characterName))
                    {
                        foundCharacter = true;
                        m_owner.CharacterLevel = level;
                    }
                }
                if (selectFirstCharacter)
                    if (ClientlessBot.debugging)
                        Console.WriteLine("{0}: [MCP] No character specified, chose first character", m_owner.Account);
                if (!foundCharacter)
                {
                    Console.WriteLine("{0}: [MCP] Unable to locate character specified", m_owner.Account);
                    return;
                }

                Console.WriteLine("{0}: [MCP] Logging on to character {1}", m_owner.Account, m_owner.Character);

                byte[] packet = BuildPacket(0x07, System.Text.Encoding.ASCII.GetBytes(m_owner.Character), zero);
                m_stream.Write(packet, 0, packet.Length);
            }
        }