本文整理汇总了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);
}
示例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
}
示例3: ReadPayload
public override void ReadPayload(NetIncomingMessage message)
{
base.ReadPayload(message);
Image = message.ReadBytes(message.ReadInt32());
Number = message.ReadUInt32();
SendIndex = message.ReadInt32();
}
示例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));
}
示例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() );
}
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}