本文整理汇总了C#中D3Sharp.Net.Game.Packets.GameBitBuffer.IsPacketAvailable方法的典型用法代码示例。如果您正苦于以下问题:C# GameBitBuffer.IsPacketAvailable方法的具体用法?C# GameBitBuffer.IsPacketAvailable怎么用?C# GameBitBuffer.IsPacketAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类D3Sharp.Net.Game.Packets.GameBitBuffer
的用法示例。
在下文中一共展示了GameBitBuffer.IsPacketAvailable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Identify
public static void Identify(IConnection connection, MemoryStream stream)
{
//We Should move this part to a more central position
if (gameMessages == null)
{
gameMessages = new Dictionary<Type, Action<GameMessage, GameBitBuffer, IConnection>>();
var actionInfos = typeof(GameRouter).GetMethods().Where(o => o.GetParameters().Where(a => a.ParameterType == typeof(GameMessage)).Count() == 1 &&
o.GetParameters().Where(a => a.ParameterType == typeof(IConnection)).Count() == 1 &&
o.GetParameters().Where(a => a.ParameterType == typeof(GameBitBuffer)).Count() == 1
).ToList();
foreach (var actionInfo in actionInfos)
{
Action<GameMessage, GameBitBuffer, IConnection> action = (Action<GameMessage, GameBitBuffer, IConnection>)Delegate.CreateDelegate(typeof(Action<GameMessage, GameBitBuffer, IConnection>), actionInfo);
Type typ = Type.GetType("D3Sharp.Net.Game.Packets." + actionInfo.Name);
gameMessages.Add(typ, action);
}
}
//
GameBitBuffer _incomingBuffer = new GameBitBuffer(512);
GameBitBuffer _outgoingBuffer = new GameBitBuffer(ushort.MaxValue);
_outgoingBuffer.WriteInt(32, 0);
var header = new GameHeader(stream);
var payload = new byte[header.Length - 6];
stream.Read(payload, 0, (int)header.Length - 6);
_incomingBuffer.AppendData(header.Data);
_incomingBuffer.AppendData(payload);
while (_incomingBuffer.IsPacketAvailable())
{
int end = _incomingBuffer.Position;
end += _incomingBuffer.ReadInt(32) * 8;
while ((end - _incomingBuffer.Position) >= 9)
{
GameMessage msg = _incomingBuffer.ParseMessage();
Logger.LogIncoming(msg);
try
{
if (gameMessages.ContainsKey(GetMessageType(msg.Id)))
gameMessages[GetMessageType(msg.Id)](msg, _outgoingBuffer, connection);
else
Logger.Debug("Unhandled game message: 0x{0:X4} {1}", msg.Id, msg.GetType().Name);
}
catch (NotImplementedException)
{
Logger.Debug("Unhandled game message: 0x{0:X4} {1}", msg.Id, msg.GetType().Name);
}
}
_incomingBuffer.Position = end;
}
}