本文整理汇总了C#中Packet.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.Read方法的具体用法?C# Packet.Read怎么用?C# Packet.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.Read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAddonInfo
//! TODO Implement server side addon & banned addon handling
public static async void HandleAddonInfo(CharacterSession session, byte[] addonData)
{
var addonInfo = new AddonInfo();
var addonDataReader = new Packet(addonData, 0);
var addons = addonDataReader.Read<uint>();
for (var i = 0; i < addons; i++)
{
var addonName = addonDataReader.ReadString();
var addonInfoProvided = addonDataReader.Read<bool>();
var addonCRC = addonDataReader.Read<uint>();
var urlCRC = addonDataReader.Read<uint>();
Log.Debug($"AddonData: Name '{addonName}', Info Provided '{addonInfoProvided}', CRC '0x{addonCRC:X}', URL CRC '0x{urlCRC:X}'.");
addonInfo.Addons.Add(new AddonInfoData
{
InfoProvided = addonInfoProvided,
KeyProvided = true,
KeyData = addonPublicKey
});
}
await session.Send(addonInfo);
}
示例2: HandleAuthRequest
public static void HandleAuthRequest(Packet packet, AuthSession session)
{
packet.Read<uint>(32);
packet.Read<ulong>(64);
var loginName = packet.ReadString();
Console.WriteLine($"Account '{loginName}' tries to connect.");
//var account = DB.Auth.Single<Account>(a => a.Email == loginName);
//if (account != null && account.Online)
{
var authComplete = new Packet(ServerMessage.AuthComplete);
authComplete.Write(0, 32);
session.Send(authComplete);
var connectToRealm = new Packet(ServerMessage.ConnectToRealm);
connectToRealm.Write(BitConverter.ToUInt32(new byte[] { 1, 0, 0, 127 }, 0), 32);
connectToRealm.Write(24000, 16);
connectToRealm.Write(0, 64);
connectToRealm.Write(0, 64);
connectToRealm.Write(0, 32);
connectToRealm.WriteWString("Multi-Emu");
connectToRealm.Write(0, 2);
connectToRealm.Write(0, 21);
session.Send(connectToRealm);
}
}
示例3: Invoke
public static async Task Invoke(Packet reader, Session session)
{
var message = reader.Header.Message;
Tuple<MethodInfo, Type> data;
if (MessageHandlers.TryGetValue(message, out data))
{
var handlerObj = Activator.CreateInstance(data.Item2) as ClientPacket;
handlerObj.Packet = reader;
await Task.Run(() => handlerObj.Read());
// Fix the position after the last read.
reader.Read(1);
if (handlerObj.IsReadComplete)
data.Item1.Invoke(null, new object[] { handlerObj, session });
else
Log.Error($"Packet read for '{data.Item2.Name}' failed.");
}
else
{
var msgName = Enum.GetName(typeof(ClientMessage), message) ?? Enum.GetName(typeof(GlobalClientMessage), message);
if (msgName == null)
Log.Network($"Received unknown opcode '0x{message:X}, Length: {reader.Data.Length}'.");
else
Log.Network($"Packet handler for '{msgName} (0x{message:X}), Length: {reader.Data.Length}' not implemented.");
}
}
示例4: OnConnection
public override void OnConnection(object sender, SocketAsyncEventArgs e)
{
if (!isTransferInitiated[1])
{
var clientToServer = "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER";
var data = new byte[0x32];
Buffer.BlockCopy(dataBuffer, 0, data, 0, data.Length);
var transferInitiate = new Packet(data, false);
var length = transferInitiate.Read<ushort>();
var msg = transferInitiate.Read<string>(0, true);
if (msg == clientToServer)
{
isTransferInitiated[1] = true;
e.Completed -= OnConnection;
e.Completed += Process;
Log.Message(LogType.Debug, "Initial packet transfer for Client '{0}' successfully initialized.", GetClientIP());
client.ReceiveAsync(e);
// Assign server challenge for auth digest calculations
Challenge = BitConverter.ToUInt32(new byte[0].GenerateRandomKey(4), 0);
AuthHandler.HandleAuthChallenge(this);
}
else
{
Log.Message(LogType.Debug, "Wrong initial packet transfer data for Client '{0}'.", GetClientIP());
Dispose();
}
}
else
Dispose();
}
示例5: OnPacket
protected void OnPacket(Session session, Packet packet, int channel)
{
var peer = new SessionRemotingPeer(session);
RemotingManager.Process(packet.Read().ToArray(), peer);
}
示例6: OnCharDelete
public static void OnCharDelete(Packet packet, CharacterSession session)
{
var guid = packet.Read<SmartGuid>();
if (guid.CreationBits > 0 && guid.Type == GuidType.Player)
HandleDeleteChar(session, guid);
}
示例7: OnCreateCharacter
public static void OnCreateCharacter(Packet packet, CharacterSession session)
{
var nameLength = packet.GetBits<int>(6);
var useTemplateSet = packet.GetBit();
var raceId = packet.Read<Race>();
var classId = packet.Read<Class>();
var sexId = packet.Read<byte>();
var skinId = packet.Read<byte>();
var faceId = packet.Read<byte>();
var hairStyleId = packet.Read<byte>();
var hairColorId = packet.Read<byte>();
var facialHairStyleId = packet.Read<byte>();
packet.Skip(1);
var name = packet.Read<string>(nameLength).ToLowerEnd();
var createChar = new Packet(ServerMessage.CreateChar);
if (!ClientDB.ChrRaces.Any(c => c.Id == raceId) || !ClientDB.ChrClasses.Any(c => c.Id == classId))
{
createChar.Write(CharCreateCode.Failed);
session.Send(createChar);
return;
}
if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == raceId && c.ClassId == classId))
{
createChar.Write(CharCreateCode.Failed);
session.Send(createChar);
return;
}
if (DB.Character.Any<Character>(c => c.Name == name))
{
createChar.Write(CharCreateCode.NameInUse);
session.Send(createChar);
return;
}
if (useTemplateSet)
{
var templateSetId = packet.Read<int>();
var accTemplate = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == templateSetId);
var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == templateSetId);
if (accTemplate || realmTemplate)
{
var template = DB.Character.Single<CharacterTemplateSet>(s => s.Id == templateSetId);
// Implement...
}
else
createChar.Write(CharCreateCode.Failed);
}
else
{
var creationData = DB.Character.Single<CharacterCreationData>(d => d.Race == raceId && d.Class == classId);
var creationData2 = DB.Character.Select<CharacterCreationData>();
if (creationData != null)
{
var newChar = new Character
{
Name = name,
GameAccountId = session.GameAccount.Id,
RealmId = session.Realm.Id,
Race = raceId,
Class = classId,
Sex = sexId,
Skin = skinId,
Face = faceId,
HairStyle = hairStyleId,
HairColor = hairColorId,
FacialHairStyle = facialHairStyleId,
Level = 1,
Map = creationData.Map,
X = creationData.X,
Y = creationData.Y,
Z = creationData.Z,
O = creationData.O,
CharacterFlags = CharacterFlags.Decline,
FirstLogin = true
};
if (DB.Character.Add(newChar))
{
createChar.Write(CharCreateCode.Success);
Manager.Character.LearnStartAbilities(newChar);
}
else
createChar.Write(CharCreateCode.Failed);
}
else
createChar.Write(CharCreateCode.Failed);
//.........这里部分代码省略.........
示例8: OnAuthSession
public static void OnAuthSession(Packet packet, RealmSession session)
{
// Part of the header
packet.Read<ushort>();
var loginServerId = packet.Read<uint>();
var build = packet.Read<short>();
var localChallenge = packet.Read<uint>();
var siteId = packet.Read<uint>();
var realmId = packet.Read<uint>();
var loginServerType = packet.Read<LoginServerTypes>();
var buildType = packet.Read<sbyte>();
var regionId = packet.Read<uint>();
var dosResponse = packet.Read<ulong>();
var digest = packet.ReadBytes(20);
var accountName = packet.ReadString(11);
var useIPv6 = packet.GetBit();
// AddonInfo stuff
var compressedAddonInfoSize = packet.Read<int>();
var uncompressedAddonInfoSize = packet.Read<int>();
var compressedAddonData = packet.ReadBytes(compressedAddonInfoSize - 4);
var accountParts = accountName.Split(new[] { '#' });
var authResult = AuthResults.Ok;
if (loginServerType != LoginServerTypes.Battlenet)
authResult = AuthResults.Reject;
if (authResult == AuthResults.Ok)
{
if (accountParts.Length == 2)
{
var accountId = int.Parse(accountParts[0]);
var gameIndex = byte.Parse(accountParts[1]);
var gameAccount = DB.Auth.GameAccounts.SingleOrDefault(ga => ga.AccountId == accountId && ga.Index == gameIndex);
if (gameAccount != null)
{
var sha1 = new Sha1();
sha1.Process(accountName);
sha1.Process(0u);
sha1.Process(localChallenge);
sha1.Process(session.Challenge);
sha1.Finish(gameAccount.SessionKey.ToByteArray(), 40);
// Check the password digest.
if (sha1.Digest.Compare(digest))
{
session.GameAccount = gameAccount;
AddonHandler.LoadAddonInfoData(session, compressedAddonData, compressedAddonInfoSize, uncompressedAddonInfoSize);
}
else
authResult = AuthResults.IncorrectPassword;
}
else
authResult = AuthResults.UnknownAccount;
}
else
authResult = AuthResults.UnknownAccount;
}
HandleAuthResponse(authResult, session);
//TODO [partially done] Implement security checks & field handling.
//TODO Implement AuthResponse.
}
示例9: OnConnection
public virtual void OnConnection(object sender, SocketAsyncEventArgs e)
{
if (!isTransferInitiated[1])
{
var clientToServer = "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER";
var data = new byte[0x32];
Buffer.BlockCopy(dataBuffer, 0, data, 0, data.Length);
var transferInitiate = new Packet(data, false);
var length = transferInitiate.Read<ushort>();
var msg = transferInitiate.Read<string>(0, true);
if (msg == clientToServer)
{
isTransferInitiated[1] = true;
e.Completed -= OnConnection;
e.Completed += Process;
Log.Message(LogType.Debug, "Initial packet transfer for Client '{0}' successfully initialized.", GetClientIP());
client.ReceiveAsync(e);
}
else
{
Log.Message(LogType.Debug, "Wrong initial packet transfer data for Client '{0}'.", GetClientIP());
Dispose();
}
}
else
Dispose();
}