Add state machine in mainloop of Server's main thread (by X1n)