First part of port from simulator to server

First commit for the ported simulator code from c# to c++