本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadBytes方法的具体用法?C# NetBuffer.ReadBytes怎么用?C# NetBuffer.ReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadBytes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public void Read(NetBuffer im)
{
MessagePacketId = im.ReadInt64();
Number = im.ReadInt32();
int length = im.ReadInt32();
if (length != 0)
{
Bytes = im.ReadBytes(length);
}
}
示例2: Read
public void Read(NetBuffer im)
{
PluginName = im.ReadString();
MethodName = im.ReadString();
RspType = im.ReadByte();
if (RspType == StringDataType)
{
StringCommandRsp = im.ReadString();
}
else if (RspType == BinaryDataType)
{
int l = im.ReadInt32();
BinaryCommandRsp = im.ReadBytes(l);
}
}
示例3: ReadFrom
/// <summary>
/// Read this message from the packet buffer
/// </summary>
/// <returns>new read pointer position</returns>
internal void ReadFrom(NetBuffer buffer, IPEndPoint endpoint)
{
m_senderEndPoint = endpoint;
// read header
byte header = buffer.ReadByte();
m_type = (NetMessageLibraryType)(header & 7);
m_sequenceChannel = (NetChannel)(header >> 3);
m_sequenceNumber = buffer.ReadUInt16();
int payLen = (int)buffer.ReadVariableUInt32();
// copy payload into message buffer
m_data.EnsureBufferSize(payLen * 8);
buffer.ReadBytes(m_data.Data, 0, payLen);
m_data.Reset(0, payLen * 8);
return;
}
示例4: Main
//.........这里部分代码省略.........
short a = msg.ReadInt16();
short b = msg.ReadInt16();
short c = msg.ReadInt16();
if (a != short.MaxValue || b != short.MinValue || c != -42)
throw new Exception("Ack thpth short failed");
if (msg.ReadInt32() != 421)
throw new Exception("Ack thphth 1");
if (msg.ReadByte() != (byte)7)
throw new Exception("Ack thphth 2");
if (msg.ReadSingle() != -42.8f)
throw new Exception("Ack thphth 3");
if (msg.ReadString() != "duke of earl")
throw new Exception("Ack thphth 4");
if (msg.ReadVariableInt32() != -1) throw new Exception("ReadVariableInt32 failed 1");
if (msg.ReadVariableInt32() != 5) throw new Exception("ReadVariableInt32 failed 2");
if (msg.ReadVariableInt32() != -18) throw new Exception("ReadVariableInt32 failed 3");
if (msg.ReadVariableInt32() != 42) throw new Exception("ReadVariableInt32 failed 4");
if (msg.ReadVariableInt32() != -420) throw new Exception("ReadVariableInt32 failed 5");
if (msg.ReadUInt32() != 9991)
throw new Exception("Ack thphth 4.5");
if (msg.ReadBoolean() != true)
throw new Exception("Ack thphth 5");
if (msg.ReadUInt32(5) != (uint)3)
throw new Exception("Ack thphth 6");
if (msg.ReadSingle() != 8.111f)
throw new Exception("Ack thphth 7");
if (msg.ReadString() != "again")
throw new Exception("Ack thphth 8");
byte[] rrr = msg.ReadBytes(4);
if (rrr[0] != arr[0] || rrr[1] != arr[1] || rrr[2] != arr[2] || rrr[3] != arr[3])
throw new Exception("Ack thphth 9");
if (msg.ReadByte(7) != 7)
throw new Exception("Ack thphth 10");
if (msg.ReadInt32() != Int32.MinValue)
throw new Exception("Ack thphth 11");
if (msg.ReadUInt32() != UInt32.MaxValue)
throw new Exception("Ack thphth 12");
float v = msg.ReadRangedSingle(-10, 50, 12);
// v should be close to, but not necessarily exactly, 21.0f
if ((float)Math.Abs(21.0f - v) > 0.1f)
throw new Exception("Ack thphth *RangedSingle() failed");
if (msg.ReadInt32(5) != 15)
throw new Exception("Ack thphth ReadInt32 1");
if (msg.ReadInt32(5) != 2)
throw new Exception("Ack thphth ReadInt32 2");
if (msg.ReadInt32(5) != 0)
throw new Exception("Ack thphth ReadInt32 3");
if (msg.ReadInt32(5) != -1)
throw new Exception("Ack thphth ReadInt32 4");
if (msg.ReadInt32(5) != -2)
throw new Exception("Ack thphth ReadInt32 5");
if (msg.ReadInt32(5) != -15)
throw new Exception("Ack thphth ReadInt32 6");
UInt64 longVal = msg.ReadUInt64();
if (longVal != UInt64.MaxValue)
throw new Exception("Ack thphth UInt64");
if (msg.ReadInt64() != Int64.MaxValue)
throw new Exception("Ack thphth Int64");
示例5: Read
public void Read(NetBuffer im)
{
MetaData = im.ReadString();
int l = im.ReadInt32();
Data = im.ReadBytes(l);
}
示例6: ParseSnapshot
/*
================
CL_ParseSnapshot
If the snapshot is parsed properly, it will be copied to
cl.snap and saved in cl.snapshots[]. If the snapshot is invalid
for any reason, no changes to the state will be made at all.
================
*/
void ParseSnapshot(NetBuffer msg)
{
// read in the new snapshot to a temporary buffer
// we will only copy to cl.snap if it is valid
clSnapshot_t newsnap = new clSnapshot_t();
clSnapshot_t old;
// we will have read any new server commands in this
// message before we got to svc_snapshot
newsnap.ServerCommandNum = clc.serverCommandSequence;
newsnap.serverTime = msg.ReadInt32();
newsnap.messageNum = clc.serverMessageSequence;
int deltaNum = msg.ReadByte();
if (deltaNum <= 0)
{
newsnap.deltaNum = -1;
}
else
newsnap.deltaNum = newsnap.messageNum - deltaNum;
newsnap.snapFlags = msg.ReadByte();
// If the frame is delta compressed from data that we
// no longer have available, we must suck up the rest of
// the frame, but not use it, then ask for a non-compressed
// message
if (newsnap.deltaNum <= 0)
{
newsnap.valid = true; // uncompressed frame
old = null;
}
else
{
old = cl.snapshots[newsnap.deltaNum & 31];
if (!old.valid)
{
// should never happen
Common.Instance.WriteLine("ParseSnapshot: Delta from invalid frame (not supposed to happen!).");
}
else if (old.messageNum != newsnap.deltaNum)
{
// The frame that the server did the delta from
// is too old, so we can't reconstruct it properly.
Common.Instance.WriteLine("ParseSnapshot: Delta frame too old.");
}
else if (cl.parseEntitiesNum - old.parseEntitiesNum > 2048 - 128)
{
Common.Instance.WriteLine("ParseSnapshot: Delta parseEntitiesNum too old");
}
else
newsnap.valid = true; // valid delta parse
}
// read areamask
int len = msg.ReadByte();
newsnap.areamask = msg.ReadBytes(32);
// read playerinfo
if (old != null)
{
Net.ReadDeltaPlayerstate(msg, old.ps, newsnap.ps);
}
else
Net.ReadDeltaPlayerstate(msg, null, newsnap.ps);
// read packet entities
ParsePacketEntities(msg, old, newsnap);
// if not valid, dump the entire thing now that it has
// been properly read
if (!newsnap.valid)
return;
// clear the valid flags of any snapshots between the last
// received and this one, so if there was a dropped packet
// it won't look like something valid to delta from next
// time we wrap around in the buffer
int oldMessageNum = cl.snap.messageNum + 1;
if (newsnap.messageNum - oldMessageNum >= 32)
{
oldMessageNum = newsnap.messageNum - 31;
}
for (; oldMessageNum < newsnap.messageNum; oldMessageNum++ )
{
cl.snapshots[oldMessageNum & 31].valid = false;
}
// copy to the current good spot
cl.snap = newsnap;
cl.snap.ping = 999;
// calculate ping time
//.........这里部分代码省略.........
示例7: ProcessInboundMessage
protected override NetBuffer ProcessInboundMessage(NetBuffer message)
{
switch(cryptoState)
{
case CryptoHostState.Connected:
{
int code = message.ReadInt32();
if (code == RSA_KEY_MESSAGE)
{
XmlSerializer s = new XmlSerializer(typeof(RSAParameters));
string b = message.ReadString();
StringReader reader = new StringReader(b);
RSAKey = (RSAParameters)s.Deserialize(reader);
RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(RSAKey);
NetBuffer msg = new NetBuffer();
msg.Write((Int32)CRYPTO_SECRET_MESSAGE);
byte[] secret = RSA.Encrypt(MakeSecret(),false);
msg.Write((Int32)secret.Length);
msg.Write(secret);
client.SendMessage(msg,NetChannel.ReliableInOrder1);
cryptoState = CryptoHostState.SentSecret;
}
else
{
cryptoState = CryptoHostState.Invalid;
client.Disconnect("Bad Crypto");
}
}
return null;
case CryptoHostState.SentSecret:
{
int code = message.ReadInt32();
if (code == CRYPTO_SECRET_VERIFY)
{
// set em as real and let the base class call any events it needs to
string verify = new UTF8Encoding().GetString(DecryptBuffer(message.ReadBytes(message.ReadInt32())));
NetBuffer b = new NetBuffer();
b.Write(CRYPTO_SECRET_VERIFY);
byte[] cryptoBuffer = EncryptBuffer(new UTF8Encoding().GetBytes(verify));
b.Write(cryptoBuffer.Length);
b.Write(cryptoBuffer);
client.SendMessage(b, NetChannel.ReliableInOrder1);
cryptoState = CryptoHostState.SentVerify;
}
else
{
cryptoState = CryptoHostState.Invalid;
client.Disconnect("Bad Crypto");
}
}
return null;
case CryptoHostState.SentVerify:
{
int code = message.ReadInt32();
if (code == CRYPTO_ACCEPT)
{
cryptoState = CryptoHostState.Authenticated;
base.Connected(message);
}
else
{
cryptoState = CryptoHostState.Invalid;
client.Disconnect("Bad Crypto");
}
}
return null;
case CryptoHostState.Authenticated:
return new NetBuffer(DecryptBuffer(message.ReadBytes(message.LengthBytes)));
}
return message;
}
示例8: ProcessOutboundMessage
protected override NetBuffer ProcessOutboundMessage(NetBuffer message)
{
if (cryptoState == CryptoHostState.Authenticated)
return new NetBuffer(EncryptBuffer(message.ReadBytes(message.LengthBytes)));
return message;
}
示例9: DecryptMessage
protected virtual NetBuffer DecryptMessage( CryptoHostConnection connection, NetBuffer buffer )
{
return new NetBuffer(connection.DecryptBuffer(buffer.ReadBytes(buffer.LengthBytes)));
}
示例10: ProcessOutboundMessage
protected override NetBuffer ProcessOutboundMessage(NetConnection to, NetBuffer message)
{
if (CryptoClients.ContainsKey(to))
{
CryptoHostConnection connection = CryptoClients[to];
if (connection.state == CryptoHostState.Authenticated)
return new NetBuffer(connection.EncryptBuffer(message.ReadBytes(message.LengthBytes)));
}
return message;
}
示例11: ProcessInboundMessage
protected override NetBuffer ProcessInboundMessage(NetConnection from, NetBuffer message)
{
CryptoHostConnection connection;
if (CryptoClients.ContainsKey(from))
connection = CryptoClients[from];
else
return message;
int code = -1;
switch (connection.state)
{
case CryptoHostState.Authenticated:
return DecryptMessage(connection, message);
case CryptoHostState.Invalid:
return null;
case CryptoHostState.InitalConnect:
{
// should be the response with a random key encoded with the shit
code = message.ReadInt32();
if (code == CRYPTO_SECRET_MESSAGE)
{
connection.state = CryptoHostState.GotSecret;
connection.SetSecret(RSA.Decrypt(message.ReadBytes(message.ReadInt32()),false));
connection.secretVerifyString = new Random().Next().ToString();
// crypto the random string with the secret and send it back
NetBuffer b = new NetBuffer();
b.Write(CRYPTO_SECRET_VERIFY);
byte[] cryptoBuffer = connection.EncryptBuffer(new UTF8Encoding().GetBytes(connection.secretVerifyString));
b.Write(cryptoBuffer.Length);
b.Write(cryptoBuffer);
server.SendMessage(b, from, NetChannel.ReliableInOrder1);
}
else
{
NetBuffer errorBuffer = new NetBuffer();
errorBuffer.Write(CRYPTO_DENY);
errorBuffer.Write("Invalid Secret");
server.SendMessage(errorBuffer, from, NetChannel.ReliableInOrder1);
from.Disconnect("CryptoError", 1);
connection.state = CryptoHostState.Invalid;
}
return null;
}
case CryptoHostState.GotSecret:
{
// should be the response with the properly encrypted sample
code = message.ReadInt32();
if (code == CRYPTO_SECRET_VERIFY)
{
// set em as real and let the base class call any events it needs to
string verify = new UTF8Encoding().GetString(connection.DecryptBuffer(message.ReadBytes(message.ReadInt32())));
if (verify == connection.secretVerifyString)
{
connection.state = CryptoHostState.Authenticated;
NetBuffer b = new NetBuffer();
b.Write(CRYPTO_ACCEPT);
server.SendMessage(b, from, NetChannel.ReliableInOrder1);
base.UserConnected(from);
return null;
}
}
NetBuffer errorBuffer = new NetBuffer();
errorBuffer.Write(CRYPTO_DENY);
errorBuffer.Write("Invalid Verify");
server.SendMessage(errorBuffer, from, NetChannel.ReliableInOrder1);
from.Disconnect("CryptoError", 1);
connection.state = CryptoHostState.Invalid;
return null;
}
}
return message;
}