当前位置: 首页>>代码示例>>C#>>正文


C# BitUnpack.GetNameLength方法代码示例

本文整理汇总了C#中BitUnpack.GetNameLength方法的典型用法代码示例。如果您正苦于以下问题:C# BitUnpack.GetNameLength方法的具体用法?C# BitUnpack.GetNameLength怎么用?C# BitUnpack.GetNameLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitUnpack的用法示例。


在下文中一共展示了BitUnpack.GetNameLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleChatMessageWhisper

        public static void HandleChatMessageWhisper(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);
            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            uint nameLength = BitUnpack.GetNameLength<uint>(9);

            string chatMessage = packet.ReadString(messageLength);
            string receiverName = packet.ReadString(nameLength);

            WorldClass rSession = WorldMgr.GetSession(receiverName);

            SendMessageByType(ref rSession, MessageType.ChatMessageWhisper, language, chatMessage);
            SendMessageByType(ref session, MessageType.ChatMessageWhisperInform, language, chatMessage);
        }
开发者ID:Mogale,项目名称:Arctium,代码行数:16,代码来源:ChatHandler.cs

示例2: HandleResponseCharacterCreate

        public static void HandleResponseCharacterCreate(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte pClass = packet.ReadByte();
            byte hairStyle = packet.ReadByte();
            byte facialHair = packet.ReadByte();
            byte race = packet.ReadByte();
            byte face = packet.ReadByte();
            byte skin = packet.ReadByte();
            byte gender = packet.ReadByte();
            byte hairColor = packet.ReadByte();
            packet.ReadByte();                      // Always 0

            uint nameLength = BitUnpack.GetNameLength<uint>(7);
            string name = packet.ReadString(nameLength);

            SQLResult result = DB.Characters.Select("SELECT * from characters WHERE name = '{0}'", name);
            PacketWriter writer = new PacketWriter(LegacyMessage.ResponseCharacterCreate);

            if (result.Count != 0)
            {
                // Name already in use
                writer.WriteUInt8(0x32);
                session.Send(writer);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = {0} AND class = {1}", race, pClass);
            if (result.Count == 0)
            {
                writer.WriteUInt8(0x31);
                session.Send(writer);
                return;
            }

            uint map = result.Read<uint>(0, "map");
            uint zone = result.Read<uint>(0, "zone");
            float posX = result.Read<float>(0, "posX");
            float posY = result.Read<float>(0, "posY");
            float posZ = result.Read<float>(0, "posZ");
            float posO = result.Read<float>(0, "posO");

            DB.Characters.Execute("INSERT INTO characters (name, accountid, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair) VALUES (" +
                                  "'{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, '{8}', '{9}', '{10}', '{11}', {12}, {13}, {14}, {15})",
                                  name, session.Account.Id, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair);

            // Success
            writer.WriteUInt8(0x2F);
            session.Send(writer);
        }
开发者ID:thundergod221,项目名称:Arctium,代码行数:51,代码来源:CharacterHandler.cs

示例3: HandleAuthResponse

        public static void HandleAuthResponse(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            packet.Skip(54);

            int addonSize = packet.ReadInt32();
            packet.Skip(addonSize);

            uint nameLength = BitUnpack.GetNameLength<uint>(12);
            string accountName = packet.ReadString(nameLength);

            SQLResult result = DB.Realms.Select("SELECT * FROM accounts WHERE name = ?", accountName);
            if (result.Count == 0)
                session.clientSocket.Close();
            else
                session.Account = new Account()
                {
                    Id         = result.Read<int>(0, "id"),
                    Name       = result.Read<String>(0, "name"),
                    Password   = result.Read<String>(0, "password"),
                    SessionKey = result.Read<String>(0, "sessionkey"),
                    Expansion  = result.Read<byte>(0, "expansion"),
                    GMLevel    = result.Read<byte>(0, "gmlevel"),
                    IP         = result.Read<String>(0, "ip"),
                    Language   = result.Read<String>(0, "language")
                };

            string K = session.Account.SessionKey;
            byte[] kBytes = new byte[K.Length / 2];

            for (int i = 0; i < K.Length; i += 2)
                kBytes[i / 2] = Convert.ToByte(K.Substring(i, 2), 16);

            session.Crypt.Initialize(kBytes);

            uint realmId = WorldConfig.RealmId;
            SQLResult realmClassResult = DB.Realms.Select("SELECT class, expansion FROM realm_classes WHERE realmId = ?", realmId);
            SQLResult realmRaceResult = DB.Realms.Select("SELECT race, expansion FROM realm_races WHERE realmId = ?", realmId);

            bool HasAccountData = true;
            bool IsInQueue = false;

            PacketWriter authResponse = new PacketWriter(JAMCMessage.AuthResponse);
            BitPack BitPack = new BitPack(authResponse);

            BitPack.Write(1);                                      // HasAccountData

            if (HasAccountData)
            {
                BitPack.Write(realmClassResult.Count, 25);         // Activation count for classes
                BitPack.Write(0);                                  // Unknown, 5.0.4
                BitPack.Write(0);                                  // Unknown, 5.1.0
                BitPack.Write(0, 22);                              // Activate character template windows/button

                //if (HasCharacterTemplate)
                //Write bits for char templates...

                BitPack.Write(realmRaceResult.Count, 25);          // Activation count for races
                BitPack.Write(IsInQueue);                          // IsInQueue
            }

            if (IsInQueue)
            {
                BitPack.Write(0);                                  // Unknown
                BitPack.Flush();

                authResponse.WriteUInt32(0);                       // QueuePosition
            }
            else
                BitPack.Flush();

            if (HasAccountData)
            {
                //if (HasCharacterTemplate)
                //Write data for char templates...

                for (int r = 0; r < realmRaceResult.Count; r++)
                {
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "expansion"));
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "race"));
                }

                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);
                authResponse.WriteUInt8(0);
                authResponse.WriteUInt8(session.Account.Expansion);
                authResponse.WriteUInt8(session.Account.Expansion);

                for (int c = 0; c < realmClassResult.Count; c++)
                {
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "class"));
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "expansion"));
                }

                authResponse.WriteUInt32(0);
            }

            authResponse.WriteUInt8((byte)AuthCodes.AUTH_OK);

//.........这里部分代码省略.........
开发者ID:gamerdistrict,项目名称:Arctium,代码行数:101,代码来源:AuthenticationHandler.cs

示例4: HandleResponseCharacterCreate

        public static void HandleResponseCharacterCreate(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte pClass = packet.ReadByte();
            byte hairStyle = packet.ReadByte();
            byte facialHair = packet.ReadByte();
            byte race = packet.ReadByte();
            byte face = packet.ReadByte();
            byte skin = packet.ReadByte();
            byte gender = packet.ReadByte();
            byte hairColor = packet.ReadByte();
            packet.ReadByte();                      // Always 0

            uint nameLength = BitUnpack.GetNameLength<uint>(7);
            string name = Character.NormalizeName(packet.ReadString(nameLength));

            SQLResult result = DB.Characters.Select("SELECT * from characters WHERE name = ?", name);
            PacketWriter writer = new PacketWriter(LegacyMessage.ResponseCharacterCreate);

            if (result.Count != 0)
            {
                // Name already in use
                writer.WriteUInt8(0x32);
                session.Send(ref writer);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = ? AND class = ?", race, pClass);
            if (result.Count == 0)
            {
                writer.WriteUInt8(0x31);
                session.Send(ref writer);
                return;
            }

            uint map = result.Read<uint>(0, "map");
            uint zone = result.Read<uint>(0, "zone");
            float posX = result.Read<float>(0, "posX");
            float posY = result.Read<float>(0, "posY");
            float posZ = result.Read<float>(0, "posZ");
            float posO = result.Read<float>(0, "posO");

            // Allow declined names for now
            var characterFlags = CharacterFlag.Decline;

            DB.Characters.Execute("INSERT INTO characters (name, accountid, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair, characterFlags) VALUES (" +
                                  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                                  name, session.Account.Id, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair, characterFlags);

            // Success
            writer.WriteUInt8(0x2F);
            session.Send(ref writer);
        }
开发者ID:Krogonos,项目名称:Mop-5.1.0-Core,代码行数:54,代码来源:CharacterHandler.cs


注:本文中的BitUnpack.GetNameLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。