public NetIO(Socket sock, Dictionary<ushort, Packet> commandTable, Client client ,ClientManager manager)
{
this.sock = sock;
this.stream = new NetworkStream(sock);
this.commandTable = commandTable;
this.client = client;
this.currentClientManager = manager;
this.callbackSize = new AsyncCallback(this.ReceiveSize);
this.callbackData = new AsyncCallback(this.ReceiveData);
this.nlock = new ReaderWriterLock();
// Use the static key untill the keys have been exchanged
this.clientKey = new byte[16];
Encryption.StaticKey.CopyTo(this.clientKey, 0);
this.serverKey = new byte[16];
Encryption.StaticKey.CopyTo(this.serverKey, 0);
this.isDisconnected = false;
// Receive the size of the next packet and call ReceiveSize when finished
if (sock.Connected)
{
try { stream.BeginRead(buffer, 0, 2, this.callbackSize, null); }
catch (Exception ex) {
Logger.ShowError(ex, null);
try//this could crash the gateway somehow,so better ignore the Exception
{
this.Disconnect();
}
catch (Exception)
{
}
Logger.ShowWarning("Invalid packet head from:" + sock.RemoteEndPoint.ToString(), null);
return;
}
}
else { this.Disconnect(); return; }
}