public TCPClient(TCPClient oldClient) { this.GotKeys = oldClient.GotKeys; this.SalsaKey01 = oldClient.SalsaKey01; this.SalsaKey02 = oldClient.SalsaKey02; this.SalsaIV01 = oldClient.SalsaIV01; this.SalsaIV02 = oldClient.SalsaIV02; this.ClientID = oldClient.ClientID; this.Stream = oldClient.Stream; this.Buffer = new byte[8192]; this.Username = oldClient.Username; this.Password = oldClient.Password; this.Decryptor = oldClient.Decryptor; this.Encryptor = oldClient.Encryptor; this.Client = oldClient.Client; this.Deflate = oldClient.Inflate; this.Inflate = oldClient.Inflate; }
private void ReadCallback(IAsyncResult ar) { TCPClient rHelper = (TCPClient)ar.AsyncState; rHelper.RecvBytes = -1; try { rHelper.RecvBytes = rHelper.Stream.EndRead(ar); if (rHelper.RecvBytes == 0) { HandleDisconnect(rHelper); return; } // TODO: Possibly multi-part packets (?) if (rHelper.GotKeys) { TCPClient helper = new TCPClient(rHelper); rHelper.Stream.BeginRead(helper.Buffer, 0, 8192, new AsyncCallback(ReadCallback), helper); this.eventPacketReceived(rHelper); } else { this.eventPacketReceived(rHelper); TCPClient helper = new TCPClient(rHelper); rHelper.Stream.BeginRead(helper.Buffer, 0, 8192, new AsyncCallback(ReadCallback), helper); } } catch (Exception ex) { // Handle Client Disconnection //Log.Write(LogLevel.Error, "{0}", ex); HandleDisconnect(rHelper); } }
public void ForceDisconnect(TCPClient pClient) { pClient.Stream.Close(); }
private void HandleDisconnect(TCPClient helper) { this.eventClientDisconnected(helper); this.Clients.Remove(helper); helper.Stream.Close(); }