Added interface for adding commands to server.
Refactors server loop.

This is largely in preparation for the json parsing.

The server is now smarter about catching exceptions in its main loop and then continuing.