public NetEntity(Socket socket, int worldID, SocketAsyncEventArgs sendEventArgs, SocketAsyncEventArgs receiveEventArgs)
{
WorldID = worldID;
m_sendArgs = sendEventArgs;
m_sendArgs.Completed += SendCompleted;
m_receiveArgs = receiveEventArgs;
m_receiveArgs.Completed += ReceiveCompleted;
unsafe
{
//Get the pointer for the send buffer
byte[] buffer = m_sendArgs.Buffer;
fixed (byte* bufPtr = buffer)
{
m_sendBufferPtr = (IntPtr)(bufPtr + m_sendArgs.Offset);
}
}
//Setup socket
m_socket = socket;
socket.NoDelay = true; //No nagling
socket.ReceiveBufferSize = BUFFER_SIZE;
socket.SendBufferSize = BUFFER_SIZE;
AuthState = EntityAuthState.Unauthorised;
//Pin buffers so that we can block copy structs to / from them
m_workingPacketBufferHandle = GCHandle.Alloc(m_workingPacketBuffer, GCHandleType.Pinned);
m_ioStopToken = new CancellationTokenSource();
//Kick off net IO tasks
//QueueSend();
QueueReceive();
}