Add server choose code

Tested in freeshell, almost ok for stable run. Still bugs for some
unexpected operations.