本文整理汇总了C#中Packet.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.GetData方法的具体用法?C# Packet.GetData怎么用?C# Packet.GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.GetData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Broadcast
public void Broadcast(Packet packet, ulong excludeID = 0)
{
Broadcast(packet.GetData(), excludeID);
}
示例2: SendTo
public void SendTo(Guid guid, Packet packet)
{
SendTo(guid, packet.GetData());
}
示例3: Broadcast
public void Broadcast(Packet packet, params Guid[] ignore)
{
Broadcast(packet.GetData(), ignore);
}
示例4: SendPacket
public void SendPacket(Packet p, NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered)
{
//if (!isConnected()) return;
byte[] data = p.GetData();
NetOutgoingMessage om = NetClient.CreateMessage();
om.Write(data);
NetClient.SendMessage(om, method);
//netClient.Recycle(om);
}
示例5: SendGameModeEvent
protected void SendGameModeEvent(string eventName, Packet bytes, NetworkPlayer playerReceiving = null)
{
Packet14SCGameModeEvent packet = new Packet14SCGameModeEvent(eventName);
packet.WriteBytes(bytes.GetData());
GameServer.ServerNetworkManager.SendPacket(packet, playerReceiving != null ? playerReceiving.NetConnection : null);
}
示例6: UpdateCache
public void UpdateCache()
{
var blockPos = new Vector2((int)(EntityPosition.X / GameServer.BlockSize), (int)(EntityPosition.Y / GameServer.BlockSize));
short startX = (short)MathHelper.Clamp((int)blockPos.X - (750 / GameServer.BlockSize), 0, GameServer.WorldSizeX);
short startY = (short)MathHelper.Clamp((int)blockPos.Y - (750 / GameServer.BlockSize), 0, GameServer.WorldSizeY);
short endX = (short)MathHelper.Clamp(startX + 64, 0, GameServer.WorldSizeX);
short endY = (short)MathHelper.Clamp(startY + 64, 0, GameServer.WorldSizeY);
for (short x = startX; x < endX; x++)
{
Packet packet = new Packet();
//Generate two bitmasks where each bit determines if the block's ID/MD are updated.
long[] masks = GenerateRowBitMask(x);
long maskID = masks[0];
long maskMD = masks[1];
//No updates
if (maskID == 0 && maskMD == 0) continue;
int numBitsID = GetNumBitsSet(maskID);
int numBitsMD = GetNumBitsSet(maskMD);
//If we're only setting one block, just ignore the bitmask and send the block itself.
if (numBitsID == 1 && numBitsMD == 1)
{
int oneX = 0;
int oneY = 0;
for (int i = 0; i < 64; i++)
{
if ((maskID & ((long)1 << i)) == 0)
{
if ((maskMD & ((long)1 << i)) == 0) continue;
}
oneX = x;
oneY = startY + i;
}
PlayerBlockCache[oneX, oneY].ID = GameServer.WorldBlocks[oneX, oneY].ID;
PlayerBlockCache[oneX, oneY].MetaData = GameServer.WorldBlocks[oneX, oneY].MetaData;
Packet packet2 = new Packet1SCGameEvent(GameServer.GameEvents.Block_Set, (short)oneX, (short)oneY, GameServer.WorldBlocks[oneX, oneY].ID, GameServer.WorldBlocks[oneX, oneY].MetaData);
GameServer.ServerNetworkManager.SendPacket(packet2, NetConnection);
continue;
}
for (int i = 0; i < endY - startY; i++)
{
BlockData curData = GameServer.WorldBlocks[x, startY + i];
bool IDUpdate = (maskID & ((long) 1 << i)) != 0;
bool MDUpdate = (maskMD & ((long) 1 << i)) != 0;
if (!IDUpdate && !MDUpdate) continue;
if (IDUpdate)
{
packet.WriteShort(curData.ID);
PlayerBlockCache[x, startY + i].ID = curData.ID;
}
if(MDUpdate)
{
packet.WriteByte(curData.MetaData);
PlayerBlockCache[x, startY + i].MetaData = curData.MetaData;
}
}
Packet p = new Packet1SCGameEvent(GameServer.GameEvents.Block_Set_Line);
p.WriteShort(x);
p.WriteShort(startY);
p.WriteLong(maskID);
p.WriteLong(maskMD);
p.WriteBytes(packet.GetData());
GameServer.ServerNetworkManager.SendPacket(p, NetConnection);
}
}
示例7: processByte
private bool processByte(Packet p, byte b)
{
if (b != kDelimiter && p.State == PacketState.WaitForInitialDelimiter)
{
return false;
}
if (b == kDelimiter)
{
if(p.State == PacketState.WaitForInitialDelimiter)
{
p.State = PacketState.WaitForFinalDelimiter;
}
else if(p.State == PacketState.WaitForFinalDelimiter && p.GetData().Length != 0)
{
return true;
}
return false;
}
if (b == kEscape)
{
p.State = PacketState.EscapeNextByte;
return false;
}
if (p.State == PacketState.EscapeNextByte)
{
p.AddByte((byte)(b ^ (1 << 5)));
p.State = PacketState.WaitForFinalDelimiter;
}
else
{
p.AddByte(b);
}
return false;
}
示例8: deviceReaderAsync
private async Task deviceReaderAsync()
{
Packet currentPacket = new Packet();
using (DataReader dataReader = new DataReader(serialDevice.InputStream))
{
dataReader.InputStreamOptions = InputStreamOptions.Partial;
try
{
while (true)
{
await dataReader.LoadAsync(kReadBufferSize).AsTask(readCancellation.Token);
while (dataReader.UnconsumedBufferLength > 0)
{
if (currentPacket.ByteCount == 0)
{
currentPacket.receivedFromPortStart = DateTime.Now;
}
if (processByte(currentPacket, dataReader.ReadByte()))
{
currentPacket.receivedFromPortEnd = DateTime.Now;
//if it's an empty receive, drop it.
if(currentPacket.ByteCount == 2)
{
if (currentPacket.GetData()[0] == kCodeReceive)
{
currentPacket = new Packet();
continue;
}
}
incomingPacketQueue.Post(currentPacket);
currentPacket = new Packet();
}
}
}
}
catch (TaskCanceledException tce)
{
System.Diagnostics.Debug.WriteLine("Read cancelled " + tce.ToString());
}
finally
{
dataReader.DetachStream();
}
}
}
示例9: SendPacket
public void SendPacket(Packet p, NetConnection stream = null, NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered)
{
byte[] data = p.GetData();
try
{
if (stream == null)
{
foreach (NetworkPlayer pl in GameServer.NetworkPlayers)
{
NetOutgoingMessage msg = NetServer.CreateMessage();
msg.Write(data);
NetConnection clientStream = pl.NetConnection;
NetServer.SendMessage(msg, clientStream, method);
}
}
else if (stream != null)
{
NetOutgoingMessage msg = NetServer.CreateMessage();
msg.Write(data);
NetServer.SendMessage(msg, stream, method);
}
}
catch
{
}
}
示例10: Send
public void Send(Packet packet)
{
if (!IsConnected)
return;
Send(packet.GetData());
}