本文整理汇总了C#中Lidgren.Network.NetBuffer.Write方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.Write方法的具体用法?C# NetBuffer.Write怎么用?C# NetBuffer.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSendDiscoveryRequest
internal void DoSendDiscoveryRequest(
IPEndPoint endPoint,
bool useBroadcast,
NetDiscoveryRequest request,
float interval,
float timeout)
{
if (!m_netBase.m_isBound)
m_netBase.Start();
if (request == null)
{
m_netBase.LogVerbose("Creating discovery request " + m_nextRequestNumber);
request = new NetDiscoveryRequest(endPoint, m_nextRequestNumber++, useBroadcast, interval, timeout);
if (m_requests == null)
m_requests = new List<NetDiscoveryRequest>();
m_requests.Add(request);
}
string appIdent = m_netBase.m_config.ApplicationIdentifier;
NetBuffer data = new NetBuffer(appIdent.Length + 8);
// write app identifier
data.Write(appIdent);
// write netbase identifier to avoid self-discovery
data.Write(m_netBase.m_randomIdentifier);
// write request number
data.Write((ushort)request.Number);
m_netBase.LogWrite("Discovering " + endPoint.ToString() + "...");
m_netBase.QueueSingleUnreliableSystemMessage(NetSystemType.Discovery, data, endPoint, useBroadcast);
}
示例2: Write
public void Write(NetBuffer om)
{
if (MetaData == null) MetaData = "Null";
om.Write(MetaData);
om.Write(Data.Length);
om.Write(Data);
}
示例3: Write
public override void Write(NetBuffer om)
{
base.Write(om);
om.Write(FollowerId.Count);
foreach(var obj in FollowerId)
{
om.Write(obj);
}
}
示例4: Write
public void Write(NetBuffer om)
{
if (Address == null) Address = string.Empty;
if (ConnectName == null) ConnectName = string.Empty;
if (Information == null) ConnectName = string.Empty;
om.Write(Address);
om.Write(ConnectName);
om.Write(Information);
}
示例5: Write
public override void Write(NetBuffer om)
{
base.Write(om);
om.Write(Followers.Count);
foreach(var obj in Followers)
{
om.Write(obj.Key);
om.Write(obj.Value);
}
}
示例6: Write
public void Write(NetBuffer om)
{
om.Write(MessagePacketId);
om.Write(Number);
if (Bytes != null)
{
om.Write(Bytes.Length);
om.Write(Bytes);
}
else
{
om.Write(0);
}
}
示例7: Write
public void Write(NetBuffer om)
{
if(Plugins != null)
{
om.Write(Plugins.Count);
foreach (var obj in Plugins)
{
om.Write(obj);
}
}
else
{
om.Write(0);
}
}
示例8: Encode
internal void Encode(NetBuffer intoBuffer)
{
Debug.Assert(m_sequenceNumber != -1);
// message type, netchannel and sequence number
intoBuffer.Write((byte)((int)m_type | ((int)m_sequenceChannel << 3)));
intoBuffer.Write((ushort)m_sequenceNumber);
// payload length
int len = m_data.LengthBytes;
intoBuffer.WriteVariableUInt32((uint)len);
// copy payload
intoBuffer.Write(m_data.Data, 0, len);
return;
}
示例9: WriteStringTable
internal void WriteStringTable(NetBuffer buffer, string str)
{
// Bits:
// 0: Does the actual string follows? (if so, send confirmation)
// 1: Is the value contained in the following 6 bits ONLY? (false = use one more byte for 14 bits total)
// 2-7: value
// 8-15: (possibly) value
int val;
if (!m_stringTable.TryGetValue(str, out val))
{
// new value
val = m_stringTable.Count;
if (val >= c_maxTabledStrings)
{
val = 0;
}
else
{
m_stringTableLookUp[val] = str;
val |= (1 << 16); // 1 means not acknowledged yet
m_stringTable[str] = val;
}
}
// is it known at destination?
bool known = (val < (1 << 16));
ushort actualVal = (ushort)val;
buffer.Write(known);
if (actualVal < 64)
{
buffer.Write(false);
buffer.Write(actualVal, 6);
} else {
buffer.Write(true);
buffer.Write(actualVal, 6 + 8);
}
if (!known)
buffer.Write(str);
}
示例10: HandlesAllItemsOnTheMessage
public void HandlesAllItemsOnTheMessage()
{
var msg = new Message() { Items = { new Item() { Type = ItemType.SuccessfulJoin, Data = 143 }, new Item() { Type = ItemType.NewClient, Data = 3 }, new Item() { Type = ItemType.Player, Data = new Frenetic.Player.PlayerState() } } };
NetBuffer buffer = new NetBuffer();
buffer.Write(msg);
stubNetClient.Stub(me => me.CreateBuffer()).Return(buffer);
stubNetClient.Stub(me => me.ReadMessage(Arg<NetBuffer>.Is.Equal(buffer), out Arg<NetMessageType>.Out(NetMessageType.Data).Dummy)).Return(true);
clientNetworkSession.ClientJoined += delegate { };
var unprocessedMsg = clientNetworkSession.ReadNextMessage();
Assert.AreEqual(1, unprocessedMsg.Items.Count);
Assert.AreEqual(ItemType.Player, unprocessedMsg.Items[0].Type);
}
示例11: ToBuffer
public NetBuffer ToBuffer()
{
if(IsComplete)
{
var Buffer = new NetBuffer();
var t = from p in PacketList orderby p.Number select p;
foreach(var obj in t)
{
Buffer.Write(obj.Bytes);
}
return Buffer;
}
return null;
}
示例12: ServerReceivesDataFromClientAndCreatesMessage
public void ServerReceivesDataFromClientAndCreatesMessage()
{
NetBuffer tmpBuffer = new NetBuffer();
tmpBuffer.Write(new Message() { Items = { new Item() { Type = ItemType.NewClient, Data = 10 } } });
stubNetServer.Stub(x => x.CreateBuffer()).Return(tmpBuffer);
stubNetServer.Stub(x => x.ReadMessage(Arg<NetBuffer>.Is.Anything,
out Arg<NetMessageType>.Out(NetMessageType.Data).Dummy,
out Arg<INetConnection>.Out(stubNetConnection).Dummy))
.Return(true);
Message msg = serverNetworkSession.ReadNextMessage();
stubNetServer.AssertWasCalled(x => x.ReadMessage(Arg<NetBuffer>.Is.Equal(tmpBuffer),
out Arg<NetMessageType>.Out(NetMessageType.Data).Dummy,
out Arg<INetConnection>.Out(stubNetConnection).Dummy));
Assert.AreEqual(ItemType.NewClient, msg.Items[0].Type);
Assert.AreEqual(10, msg.Items[0].Data);
}
示例13: ReadStringTable
internal string ReadStringTable(NetBuffer buffer)
{
byte b = buffer.ReadByte();
bool stringFollows = ((b & 1) == 0);
bool shortVal = ((b & 2) == 0);
int val = 0;
if (shortVal)
val = b >> 2;
else
val = ((b & (255 << 2)) << 6) | buffer.ReadByte();
string retval = string.Empty;
if (stringFollows)
{
retval = buffer.ReadString();
m_stringTable[retval] = val;
m_stringTableLookUp[val] = retval;
//
// Send confirmation
//
NetBuffer buf = new NetBuffer(2);
buf.Write((ushort)val);
m_owner.QueueSingleUnreliableSystemMessage(
NetSystemType.StringTableAck,
buf,
m_remoteEndPoint,
false
);
return retval;
}
if (!m_stringTableLookUp.TryGetValue(val, out retval))
{
// Ack! Failed to find string table value!
throw new Exception("ACK!");
}
return retval;
}
示例14: Write
public void Write(NetBuffer om)
{
om.Write(PluginName);
om.Write(MethodName);
om.Write(RspType);
if (RspType == StringDataType)
{
om.Write(StringCommandRsp);
}
else if (RspType == BinaryDataType)
{
om.Write(BinaryCommandRsp.Length);
om.Write(BinaryCommandRsp);
}
}
示例15: MSG_WriteDeltaEntity
/*
==================
MSG_WriteDeltaEntity
Writes part of a packetentities message, including the entity number.
Can delta from either a baseline or a previous packet_entity
If to is NULL, a remove entity update will be sent
If force is not set, then nothing at all will be generated if the entity is
identical, under the assumption that the in-order delta code will catch it.
==================
*/
public void MSG_WriteDeltaEntity(NetBuffer msg, ref Common.entityState_t from, ref Common.entityState_t to, bool force)
{
int msgStart = msg.LengthBits;
// a NULL to is a delta remove message
if (to == null)
{
if (from == null)
return;
msg.Write(from.number);
msg.Write(true);
return;
}
if (to.number < 0 || to.number >= 1024)
{
Common.Instance.Error("MSG_WriteDeltaEntity: Bad entity number: " + to.number);
}
NetBuffer buf = new NetBuffer();
//NetBuffer buf = msg;
int lc = 0;
//if (from.number != to.number) { lc = 1; buf.Write(true); buf.Write(to.number); } else { buf.Write(false); }
if (from.eType != to.eType) { lc = 2; buf.Write(true); buf.Write(to.eType); } else { buf.Write(false); }
if (from.eFlags != to.eFlags) { lc = 3; buf.Write(true); buf.Write((int)to.eFlags); } else { buf.Write(false); }
int middle = buf.LengthBits;
if (from.pos.trBase.X != to.pos.trBase.X) { lc = 4; buf.Write(true); buf.Write(to.pos.trBase.X); } else { buf.Write(false); }
if (from.pos.trBase.Y != to.pos.trBase.Y) { lc = 5; buf.Write(true); buf.Write(to.pos.trBase.Y); } else { buf.Write(false); }
if (from.pos.trBase.Z != to.pos.trBase.Z) { lc = 6; buf.Write(true); buf.Write(to.pos.trBase.Z); } else { buf.Write(false); }
if (from.pos.trDelta.X != to.pos.trDelta.X) {
lc = 7; buf.Write(true); buf.Write(to.pos.trDelta.X); } else { buf.Write(false); }
if (from.pos.trDelta.Y != to.pos.trDelta.Y) { lc = 8; buf.Write(true); buf.Write(to.pos.trDelta.Y); } else { buf.Write(false); }
if (from.pos.trDelta.Z != to.pos.trDelta.Z) { lc = 9; buf.Write(true); buf.Write(to.pos.trDelta.Z); } else { buf.Write(false); }
if (from.pos.trDuration != to.pos.trDuration) { lc = 10; buf.Write(true); buf.Write(to.pos.trDuration); } else { buf.Write(false); }
if (from.pos.trTime != to.pos.trTime) { lc = 11; buf.Write(true); buf.Write(to.pos.trTime); } else { buf.Write(false); }
if (from.pos.trType != to.pos.trType) { lc = 12; buf.Write(true); buf.Write((int)to.pos.trType); } else { buf.Write(false); }
if (from.apos.trBase.X != to.apos.trBase.X) { lc = 13; buf.Write(true); buf.Write(to.apos.trBase.X); } else { buf.Write(false); }
if (from.apos.trBase.Y != to.apos.trBase.Y) { lc = 14; buf.Write(true); buf.Write(to.apos.trBase.Y); } else { buf.Write(false); }
if (from.apos.trBase.Z != to.apos.trBase.Z) { lc = 15; buf.Write(true); buf.Write(to.apos.trBase.Z); } else { buf.Write(false); }
if (from.apos.trDelta.X != to.apos.trDelta.X) { lc = 16; buf.Write(true); buf.Write(to.apos.trDelta.X); } else { buf.Write(false); }
if (from.apos.trDelta.Y != to.apos.trDelta.Y) { lc = 17; buf.Write(true); buf.Write(to.apos.trDelta.Y); } else { buf.Write(false); }
if (from.apos.trDelta.Z != to.apos.trDelta.Z) { lc = 18; buf.Write(true); buf.Write(to.apos.trDelta.Z); } else { buf.Write(false); }
if (from.apos.trDuration != to.apos.trDuration) { lc = 19; buf.Write(true); buf.Write(to.apos.trDuration); } else { buf.Write(false); }
if (from.apos.trTime != to.apos.trTime) { lc = 20; buf.Write(true); buf.Write(to.apos.trTime); } else { buf.Write(false); }
if (from.apos.trType != to.apos.trType) { lc = 21; buf.Write(true); buf.Write((int)to.apos.trType); } else { buf.Write(false); }
if (from.time != to.time) { lc = 22; buf.Write(true); buf.Write(to.time); } else { buf.Write(false); }
if (from.time2 != to.time2) { lc = 23; buf.Write(true); buf.Write(to.time2); } else { buf.Write(false); }
if (from.origin.X != to.origin.X) { lc = 24; buf.Write(true); buf.Write(to.origin.X); } else { buf.Write(false); }
if (from.origin.Y != to.origin.Y) { lc = 25; buf.Write(true); buf.Write(to.origin.Y); } else { buf.Write(false); }
if (from.origin.Z != to.origin.Z) { lc = 26; buf.Write(true); buf.Write(to.origin.Z); } else { buf.Write(false); }
if (from.origin2.X != to.origin2.X) { lc = 27; buf.Write(true); buf.Write(to.origin2.X); } else { buf.Write(false); }
if (from.origin2.Y != to.origin2.Y) { lc = 28; buf.Write(true); buf.Write(to.origin2.Y); } else { buf.Write(false); }
if (from.origin2.Z != to.origin2.Z) { lc = 29; buf.Write(true); buf.Write(to.origin2.Z); } else { buf.Write(false); }
if (from.angles.X != to.angles.X) { lc = 30; buf.Write(true); buf.Write(to.angles.X); } else { buf.Write(false); }
if (from.angles.Y != to.angles.Y) { lc = 31; buf.Write(true); buf.Write(to.angles.Y); } else { buf.Write(false); }
if (from.angles.Z != to.angles.Z) { lc = 32; buf.Write(true); buf.Write(to.angles.Z); } else { buf.Write(false); }
if (from.angles2.X != to.angles2.X) { lc = 33; buf.Write(true); buf.Write(to.angles2.X); } else { buf.Write(false); }
if (from.angles2.Y != to.angles2.Y) { lc = 34; buf.Write(true); buf.Write(to.angles2.Y); } else { buf.Write(false); }
if (from.angles2.Z != to.angles2.Z) { lc = 35; buf.Write(true); buf.Write(to.angles2.Z); } else { buf.Write(false); }
if (from.otherEntityNum != to.otherEntityNum) { lc = 36; buf.Write(true); buf.Write(to.otherEntityNum); } else { buf.Write(false); }
if (from.otherEntityNum2 != to.otherEntityNum2) { lc = 37; buf.Write(true); buf.Write(to.otherEntityNum2); } else { buf.Write(false); }
if (from.groundEntityNum != to.groundEntityNum) { lc = 38; buf.Write(true); buf.Write(to.groundEntityNum); } else { buf.Write(false); }
if (from.modelindex != to.modelindex) { lc = 39; buf.Write(true); buf.Write(to.modelindex); } else { buf.Write(false); }
if (from.clientNum != to.clientNum) { lc = 40; buf.Write(true); buf.Write(to.clientNum); } else { buf.Write(false); }
if (from.frame != to.frame) { lc = 41; buf.Write(true); buf.Write(to.frame); } else { buf.Write(false); }
if (from.solid != to.solid) { lc = 42; buf.Write(true); buf.Write(to.solid); } else { buf.Write(false); }
if (from.generic1 != to.generic1) { lc = 43; buf.Write(true); buf.Write(to.generic1); } else { buf.Write(false); }
if (lc == 0)
{
// nothing at all changed
if (!force)
{
return; // nothing at all
}
// write two bits for no change
msg.Write(to.number);
msg.Write(false); // not removed
msg.Write(false); // no delta
return;
}
//.........这里部分代码省略.........