本文整理汇总了C#中Game.Base.Packets.GSPacketIn.ReadHeader方法的典型用法代码示例。如果您正苦于以下问题:C# GSPacketIn.ReadHeader方法的具体用法?C# GSPacketIn.ReadHeader怎么用?C# GSPacketIn.ReadHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game.Base.Packets.GSPacketIn
的用法示例。
在下文中一共展示了GSPacketIn.ReadHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPacket_
public GSPacketIn ReadPacket_()
{
byte[] buffer = ReadBytes();
GSPacketIn pkg = new GSPacketIn(buffer, buffer.Length);
pkg.ReadHeader();
return pkg;
}
示例2: Clone
public GSPacketIn Clone()
{
GSPacketIn pkg = new GSPacketIn(m_buffer, m_length);
pkg.ReadHeader();
pkg.Offset = m_length;
return pkg;
}
示例3: ReadPacket
public GSPacketIn ReadPacket()
{
int maxLen = this.ReadShort();
byte[] buf = this.ReadBytes(maxLen);
buf[0] = 113;
buf[1] = 172;
GSPacketIn pkg = new GSPacketIn(buf, maxLen);
pkg.ReadHeader();
if (pkg.Length != maxLen)
{
throw new Exception(string.Format("Error packet in ReadPacket,data length didn't equal packet length, data:{0}, packet:{1}", maxLen, pkg.Length));
}
return pkg;
}
示例4: ReceiveBytes
//.........这里部分代码省略.........
//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
{
pkg.CopyFrom(buffer, curOffset, 0, packetLength);
}
pkg.ReadHeader();
log.Debug((Marshal.ToHexDump("Recieve Packet:", pkg.Buffer, 0, packetLength)));
try
{
m_client.OnRecvPacket(pkg);
}
catch (Exception e)
{
if (log.IsErrorEnabled)
log.Error("HandlePacket(pak)", e);
}
curOffset += packetLength;
} while (bufferSize - 1 > curOffset);
if (bufferSize - 1 == curOffset)
{
buffer[0] = buffer[curOffset];
m_client.PacketBufSize = 1;
}
}
}