本文整理汇总了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);
}
示例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);
}
示例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);
//.........这里部分代码省略.........
示例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);
}