CAP negotiation refactor

This fixes SASL problem on freenode.net (on 1.18 and HEAD it was impossible to login from TOR, where SASL is a must). Hopefully it wouldn't break other servers, at least rizon.net is still working for me.