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


C# NetIncomingMessage.ReadBytes方法代码示例

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


在下文中一共展示了NetIncomingMessage.ReadBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadData

 protected override void ReadData(NetIncomingMessage Message)
 {
     texture.Read(Message);
     int datalen = Message.ReadInt32();
     byte[] data = Message.ReadBytes(datalen);
     img = GetBitmap(data);
 }
开发者ID:CloneDeath,项目名称:FantasyScape,代码行数:7,代码来源:UpdateTexture.cs

示例2: Dispatch

		public void Dispatch(NetIncomingMessage message)
		{
			//The message.LengthBytes - message.PositionInBytes is from GladNet1
			//We need to read the byte[] chunk that is from the current position to the end.
			//For why we do this read this old exerp from GladNet2:
			//"Due to message recycling we cannot trust the internal array of data to be of only the information that should be used for this package.
			//We can trust the indicated size, not the length of .Data, and get a byte[] that represents the sent [Data].
			//However, this will incur a GC penalty which may become an issue; more likely to be an issue on clients."
			byte[] bytes = message.ReadBytes(message.LengthBytes - message.PositionInBytes);

			NetworkMessage gladNetNetworkMessage = null;
					
			try
			{
				gladNetNetworkMessage = deserializer.Deserialize<NetworkMessage>(bytes);
			}
			catch (Exception e)
			{
				//This is only for debug builds because in release end-user exploiters might send garbage and generate many exceptions
#if DEBUG || DEBUGBUILD
				throw new InvalidOperationException($"Could not deserialize message from ID: {message.SenderConnection?.RemoteUniqueIdentifier}");
#else
				//supress exception
				//Do NOT disconnect the peer due to malformed messages
				//Malicious users will spoof the messages of others in that case
#endif
			}

			gladNetNetworkMessage?.Dispatch(this, new LidgrenMessageDetailsAdapter(message, false)); //TODO: Encryption implementation
		}
开发者ID:HelloKitty,项目名称:GladNet2-Lidgren,代码行数:30,代码来源:LidgrenNetworkMessagePublisherService.cs

示例3: ReadPayload

 public override void ReadPayload(NetIncomingMessage message)
 {
     base.ReadPayload(message);
     Image = message.ReadBytes(message.ReadInt32());
     Number = message.ReadUInt32();
     SendIndex = message.ReadInt32();
 }
开发者ID:theslyone,项目名称:RemoteDesktop,代码行数:7,代码来源:ResponseScreenshotMessage.cs

示例4: Route1Tile

        private void Route1Tile(NetIncomingMessage msg)
        {
            //int TileID = Convert.ToInt32(msg.ReadBytes(4));
            //byte EventType = msg.ReadByte();

            TileEngine.TileEngine.EventManager.Enqueue(msg.ReadBytes(msg.LengthBytes - msg.PositionInBytes));
        }
开发者ID:milesgray,项目名称:resatiate,代码行数:7,代码来源:MessageRouter.cs

示例5: DataReceived

			public override void DataReceived ( NetCommand command, NetIncomingMessage msg )
			{
				if (command==NetCommand.Snapshot) {
					
					var frame		=	msg.ReadUInt32();
					var prevFrame	=	msg.ReadUInt32();
					var ackCmdID	=	msg.ReadUInt32();
					var serverTicks	=	msg.ReadInt64();
					var size		=	msg.ReadInt32();

					//Log.Warning("{0}", offsetTicks );

					if (prevFrame!=0) {
						Log.Warning("Bad initial snapshot. Previous frame does not equal zero.");
						return;
					}
					if (ackCmdID!=0) {
						Log.Warning("Bad command ID {0}. Command ID for initial snapshot must be zero.", ackCmdID);
						return;
					}

					//	read snapshot :
					var snapshot	=	NetDeflate.Decompress( msg.ReadBytes(size) );

					//	initial snapshot contains atom table :
					gameClient.Atoms	=	new AtomCollection( msg );


					gameClient.SetState( new Active( gameClient, frame, snapshot, serverTicks ) );
				}

				if (command==NetCommand.Notification) {
					gameClient.FeedNotification( msg.ReadString() );
				}
			}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:35,代码来源:GameClient.Awaiting.cs

示例6: FromNetBuffer

 public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
 {
     var result =
         (GameMap) SerializationHelper.ByteArrayToObject(incomingMessage.ReadBytes(incomingMessage.ReadInt32()));
     var id = incomingMessage.ReadUInt64();
     var packet = new SendMapPacket(result, id);
     return packet;
 }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:8,代码来源:SendMapPacket.cs

示例7: HandleAudioPacket

        private static void HandleAudioPacket(NetIncomingMessage msg)
        {
            Console.WriteLine("Received: {0}", msg.LengthBytes);

            var data = msg.ReadBytes(msg.LengthBytes);
            var decoded = codec.Decode(data);

            waveProvider.AddSamples(decoded, 0, decoded.Length);
        }
开发者ID:JamieH,项目名称:AudioGap,代码行数:9,代码来源:Program.cs

示例8: ReadData

 protected override void ReadData(NetIncomingMessage Message)
 {
     if (!Guid.TryParse(Message.ReadString(), out parent)) {
         throw new Exception("Failed to parse parent guid for addtexture");
     }
     texture.Read(Message);
     int datalen = Message.ReadInt32();
     byte[] data = Message.ReadBytes(datalen);
     texture.Load(GetBitmap(data));
 }
开发者ID:CloneDeath,项目名称:FantasyScape,代码行数:10,代码来源:AddTexture.cs

示例9: FromNetBuffer

        public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
        {
            var type = (ContentType) incomingMessage.ReadByte();
            var length = incomingMessage.ReadInt32();
            var bytes = incomingMessage.ReadBytes(length);

            var o = (List<EditorTemplateEntry>) SerializationHelper.ByteArrayToObject(bytes);
            var packet = new ContentListResultPacket(o, type);

            return packet;
        }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:11,代码来源:ContentListResult.cs

示例10: FromNetBuffer

        public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
        {
            var length = incomingMessage.ReadInt32();
            var bytes = incomingMessage.ReadBytes(length);
            var type = (ContentType) incomingMessage.ReadByte();

            var o = SerializationHelper.ByteArrayToObject(bytes) as IContentTemplate;
            var packet = new ContentSaveRequestPacket(o, type);

            return packet;
        }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:11,代码来源:ContentSaveRequestPacket.cs

示例11: Deserialize

 /// <summary>
 /// Der Inhalt der Nachricht, welcher ein Objekt darstellt
 /// (ganze Nachricht mit Offset der Länge der Bezeichnung z.B. "newDirection"),
 /// wird wieder in ein Objekt deserialisiert. Die Rückgabe muss anschliessend
 /// gecastet werden. Bsp. (Direction)networkManager.Deserialize(msg,msgString)
 /// </summary>
 /// <param name="msg">Eingegangene Nachricht (von IncomingMessageQueue)</param>
 /// <param name="msgString">msg.ReadString()</param>
 /// <returns>Object</returns>
 public object Deserialize(NetIncomingMessage msg, string msgString)
 {
     int offset = msgString.ToArray().Length + 1;
     BinaryFormatter bin = new BinaryFormatter();
     MemoryStream mem = new MemoryStream();
     byte[] dataBuffer = new byte[msg.LengthBytes];
     msg.ReadBytes(dataBuffer, offset, msg.LengthBytes - offset);
     mem.Write(dataBuffer, 0, dataBuffer.Length);
     mem.Seek(offset, 0);
     return bin.Deserialize(mem);
 }
开发者ID:Rosthouse,项目名称:Multi-Pac,代码行数:20,代码来源:INetworkManager.cs

示例12: ReadDelta

        public static GameStateDelta ReadDelta(NetIncomingMessage message)
        {
            uint sequence = message.ReadUInt32();
            uint fromSequence = message.ReadUInt32();
            int length = message.ReadInt32();
            byte[] bytes;
            message.ReadBytes(length, out bytes);

            var delta = new GameStateDelta(bytes);
            delta.Sequence = sequence;
            delta.FromSequence = fromSequence;
            return delta;
        }
开发者ID:Gartley,项目名称:ss13remake,代码行数:13,代码来源:GameStateDelta.cs

示例13: Deserialize

        public static MarshalComponentParameter Deserialize(NetIncomingMessage message)
        {
            if (!_serializerInitialized)
            {
                InitSerializer();
            }
            int length = message.ReadInt32();
            byte[] bytes = message.ReadBytes(length);
            var ms = new MemoryStream(bytes);

            //Thank you NetSerializer
            return (MarshalComponentParameter) Serializer.Deserialize(ms);
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:13,代码来源:MarshalComponentParameter.cs

示例14: LidgrenNetworkMessageMessageContext

		public LidgrenNetworkMessageMessageContext(NetIncomingMessage incomingMessage, IDeserializerStrategy deserializer)
			: base(incomingMessage)
		{
			//The message.LengthBytes - message.PositionInBytes is from GladNet1
			//We need to read the byte[] chunk that is from the current position to the end.
			//For why we do this read this old exerp from GladNet2:
			//"Due to message recycling we cannot trust the internal array of data to be of only the information that should be used for this package.
			//We can trust the indicated size, not the length of .Data, and get a byte[] that represents the sent [Data].
			//However, this will incur a GC penalty which may become an issue; more likely to be an issue on clients."
			byte[] bytes = incomingMessage.ReadBytes(incomingMessage.LengthBytes - incomingMessage.PositionInBytes);

			//Deserializer the network message and the payload.
			GeneratedNetworkMessage = deserializer.Deserialize<NetworkMessage>(bytes);
			GeneratedNetworkMessage?.Payload?.Deserialize(deserializer);
		}
开发者ID:HelloKitty,项目名称:GladNet2-Lidgren,代码行数:15,代码来源:LidgrenNetworkMessageMessageContext.cs

示例15: FromNetBuffer

        public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
        {
            object o = null;
            var locked = incomingMessage.ReadBoolean();
            var type = (ContentType) incomingMessage.ReadByte();

            if (!locked)
            {
                var length = incomingMessage.ReadInt32();
                var bytes = incomingMessage.ReadBytes(length);

                o = SerializationHelper.ByteArrayToObject(bytes);
            }

            var packet = new ContentResultPacket(o, locked, type);

            return packet;
        }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:18,代码来源:ContentResultPacket.cs


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