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


C# GameBitBuffer.AppendData方法代码示例

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


在下文中一共展示了GameBitBuffer.AppendData方法的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;
            }
        }
开发者ID:darkschasu,项目名称:d3sharp,代码行数:58,代码来源:GameRouter.cs


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