Store sessions in db

Still work in progress branch, at the moment clients are told they have reconnected but after a few changesets the server stops accepting their changes (or the client stops sending them).