本文整理汇总了C#中Game.Base.Packets.GSPacketIn.CopyFrom3方法的典型用法代码示例。如果您正苦于以下问题:C# GSPacketIn.CopyFrom3方法的具体用法?C# GSPacketIn.CopyFrom3怎么用?C# GSPacketIn.CopyFrom3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game.Base.Packets.GSPacketIn
的用法示例。
在下文中一共展示了GSPacketIn.CopyFrom3方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveBytes
/// <summary>
/// Called when the client receives bytes
/// </summary>
/// <param name="numBytes">The number of bytes received</param>
public void ReceiveBytes(int numBytes)
{
lock (this)
{
byte[] buffer = m_client.PacketBuf;
//End Offset of buffer
int bufferSize = m_client.PacketBufSize + numBytes;
//log.Debug(Marshal.ToHexDump("Recieve:", buffer, 0, bufferSize));
//Size < minimum
if (bufferSize < GSPacketIn.HDR_SIZE)
{
m_client.PacketBufSize = bufferSize; // undo buffer read
return;
}
//Reset the offset
m_client.PacketBufSize = 0;
int curOffset = 0;
do
{
//read buffer length
int packetLength = 0;
int header = 0;
if (m_client.Encryted)
{
//int key = receive_fsm.getState();
int i = receive_fsm.count;
//key = (key & (0xff << 16)) >> 16;
byte[] tempKey = cloneArrary(m_client.RECEIVE_KEY);
while (curOffset + 4 < bufferSize)
{
byte[] tempBuffer = decryptBytes(buffer,curOffset, 8, tempKey);
header = ((byte)(tempBuffer[0] ) << 8) + (byte)(tempBuffer[1]);
if (header == GSPacketIn.HEADER)
{
packetLength = ((byte)(tempBuffer[2]) << 8) + (byte)(tempBuffer[3]);
break;
}
else
{
curOffset++;
}
}
//decryptBytes(buffer,
}
else
{
while(curOffset + 4 < bufferSize)
{
header = (buffer[curOffset] << 8) + buffer[curOffset + 1];
if (header == GSPacketIn.HEADER)
{
packetLength = (buffer[curOffset + 2] << 8) + buffer[curOffset + 3];
break;
}
else
{
curOffset++;
}
}
}
if ((packetLength != 0 && packetLength < GSPacketIn.HDR_SIZE) || packetLength > 2048)
{
log.Error("packetLength:" + packetLength + ",GSPacketIn.HDR_SIZE:" + GSPacketIn.HDR_SIZE + ",offset:" + curOffset + ",bufferSize:" + bufferSize + ",numBytes:" + numBytes);
log.ErrorFormat("Err pkg from {0}:", m_client.TcpEndpoint);
log.Error(Marshal.ToHexDump("===> error buffer", buffer));
m_client.PacketBufSize = 0;
if (m_client.Strict)
{
m_client.Disconnect();
}
return;
}
int dataLeft = bufferSize - curOffset;
if (dataLeft < packetLength || packetLength == 0)
{
Array.Copy(buffer, curOffset, buffer, 0, dataLeft);
m_client.PacketBufSize = dataLeft;
break;
}
GSPacketIn pkg = new GSPacketIn(new byte[2048],2048);
if (m_client.Encryted)
{
// pkg.CopyFrom(buffer, curOffset, 0, packetLength, receive_fsm.getState());
pkg.CopyFrom3(buffer, curOffset, 0, packetLength, m_client.RECEIVE_KEY);
//receive_fsm.UpdateState();
}
else
{
//.........这里部分代码省略.........