server: Implement (parts of) the server connection stuff

Untested, unfinished.