public ILoginResult DoHandshake(TcpClient client) { TcpPrimitiveConnection?connection = null; try { connection = new TcpPrimitiveConnection(client); /* Receive the greeting string, this is the only communication * that does not follow the 'command' 'command-length' 'argument1'... * structure */ _ = connection.ReceiveString(); SetBinaryMode(connection); var(wasSeed, _, seed) = connection.ReceiveSystemStringCommand(SystemOp.Seed); if (!wasSeed) { return(new InvalidProtocolLoginResult("seed")); } _result = new SeededPrimitiveConnection(seed, connection); connection = null; return(_success); } finally { connection?.Dispose(); } }
public bool TryLogin(TcpClient client, out ClientHandle handle) { IPrimitiveConnection?primConn = null; IMessageConnection? msgConn = null; try { primConn = new TcpPrimitiveConnection(client); // TODO(@MattWindsor91): handshake etc. msgConn = new MessageConnection(primConn, _decoderFunc); handle = new ClientHandle(msgConn); // Prevent disposals in finally block below. primConn = null; msgConn = null; return(true); } finally { msgConn?.Dispose(); primConn?.Dispose(); client?.Close(); } }