Move the logout functionality to the worker

This moves the existing logout functionality to the worker, and also fixes a minor issue where the error code for the closing of the websocket wasn't being propagated correctly.

There are a few issues with the logout functionality - namely whether or not we should expect successful log out, and that we shouldn't really be using the nick. However, these are issues that we expect to resolve with full presence functionality later and/or a proper authentication system. Hence I've left the existing functionality largely in the same manner as it was, to simplify this change.