Implements most of socket and user auth