private void ProcessMessageFrame <T>() where T : IMessageFrame, new() { if (!running) { throw new OpenDiablo2Exception("You have made a terrible mistake. Cannot get a message frame if you are not connected."); } using (var ms = new MemoryStream(requestSocket.ReceiveFrameBytes())) using (var br = new BinaryReader(ms)) { var messageFrame = getMessageFrame((eMessageFrameType)br.ReadByte()); if (messageFrame.GetType() != typeof(T)) { throw new OpenDiablo2Exception("Recieved unexpected message frame!"); } messageFrame.LoadFrom(br); lock (getGameState().ThreadLocker) messageFrame.Process(requestSocket.GetHashCode(), this); } }
private void ProcessMessageFrame <T>() where T : IMessageFrame, new() { if (!running) { throw new OpenDiablo2Exception("You have made a terrible mistake. Cannot get a message frame if you are not connected."); } var bytes = requestSocket.ReceiveFrameBytes(); var frameType = (eMessageFrameType)bytes[0]; var frameData = bytes.Skip(1).ToArray(); // TODO: Can we maybe use pointers? This seems wasteful var messageFrame = getMessageFrame(frameType); if (messageFrame.GetType() != typeof(T)) { throw new OpenDiablo2Exception("Recieved unexpected message frame!"); } messageFrame.Data = frameData; lock (getGameState().ThreadLocker) { messageFrame.Process(requestSocket.GetHashCode(), this); } }