Server state machine. NOT FINISHED.