Core/Networking: Fixed crash/wrong opcode one some clients.
This commit is contained in:
@@ -34,6 +34,7 @@ namespace Framework.IO
|
|||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
|
Resize(0);
|
||||||
_wpos = 0;
|
_wpos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,32 +181,25 @@ namespace Game.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncReadWithCallback(InitializeHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReadHandler(SocketAsyncEventArgs args)
|
public override void ReadHandler(SocketAsyncEventArgs args)
|
||||||
{
|
{
|
||||||
if (!IsOpen())
|
if (!IsOpen())
|
||||||
return;
|
return;
|
||||||
Log.outError(LogFilter.Network, $"Raw socket data: {args.Buffer.ToHexString()}");
|
|
||||||
int currentReadIndex = 0;
|
int currentReadIndex = 0;
|
||||||
while (currentReadIndex < args.BytesTransferred)
|
while (currentReadIndex < args.BytesTransferred)
|
||||||
{
|
{
|
||||||
if (_headerBuffer.GetRemainingSpace() > 0)
|
if (_headerBuffer.GetRemainingSpace() > 0)
|
||||||
{
|
{
|
||||||
// need to receive the header
|
// need to receive the header
|
||||||
Log.outError(LogFilter.Network, $"_headerBuffer: {_headerBuffer.GetRemainingSpace()} bytesTransferred: {args.BytesTransferred} ReadIndex: {currentReadIndex}");
|
|
||||||
int readHeaderSize = Math.Min(args.BytesTransferred - currentReadIndex, _headerBuffer.GetRemainingSpace());
|
int readHeaderSize = Math.Min(args.BytesTransferred - currentReadIndex, _headerBuffer.GetRemainingSpace());
|
||||||
_headerBuffer.Write(args.Buffer, currentReadIndex, readHeaderSize);
|
_headerBuffer.Write(args.Buffer, currentReadIndex, readHeaderSize);
|
||||||
Log.outError(LogFilter.Network, $"_headerBuffer Data: {_headerBuffer.GetData().ToHexString()}");
|
|
||||||
currentReadIndex += readHeaderSize;
|
currentReadIndex += readHeaderSize;
|
||||||
|
|
||||||
if (_headerBuffer.GetRemainingSpace() > 0)
|
if (_headerBuffer.GetRemainingSpace() > 0)
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Network, $"Couldn't receive the whole header, _headerBuffer: {_headerBuffer.GetRemainingSpace()} bytesTransferred: {args.BytesTransferred}");
|
|
||||||
break; // Couldn't receive the whole header this time.
|
break; // Couldn't receive the whole header this time.
|
||||||
}
|
|
||||||
|
|
||||||
// We just received nice new header
|
// We just received nice new header
|
||||||
if (!ReadHeader())
|
if (!ReadHeader())
|
||||||
@@ -220,17 +213,12 @@ namespace Game.Networking
|
|||||||
if (_packetBuffer.GetRemainingSpace() > 0)
|
if (_packetBuffer.GetRemainingSpace() > 0)
|
||||||
{
|
{
|
||||||
// need more data in the payload
|
// need more data in the payload
|
||||||
Log.outError(LogFilter.Network, $"_packetBuffer: {_packetBuffer.GetRemainingSpace()} bytesTransferred: {args.BytesTransferred} ReadIndex: {currentReadIndex}");
|
|
||||||
int readDataSize = Math.Min(args.BytesTransferred - currentReadIndex, _packetBuffer.GetRemainingSpace());
|
int readDataSize = Math.Min(args.BytesTransferred - currentReadIndex, _packetBuffer.GetRemainingSpace());
|
||||||
_packetBuffer.Write(args.Buffer, currentReadIndex, readDataSize);
|
_packetBuffer.Write(args.Buffer, currentReadIndex, readDataSize);
|
||||||
Log.outError(LogFilter.Network, $"_packetBuffer Data: {_packetBuffer.GetData().ToHexString()}");
|
|
||||||
currentReadIndex += readDataSize;
|
currentReadIndex += readDataSize;
|
||||||
|
|
||||||
if (_packetBuffer.GetRemainingSpace() > 0)
|
if (_packetBuffer.GetRemainingSpace() > 0)
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Network, $"Couldn't receive the whole data, _packetBuffer: {_headerBuffer.GetRemainingSpace()} bytesTransferred: {args.BytesTransferred}");
|
|
||||||
break; // Couldn't receive the whole data this time.
|
break; // Couldn't receive the whole data this time.
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// just received fresh new payload
|
// just received fresh new payload
|
||||||
|
|||||||
Reference in New Issue
Block a user