C++ server code

Latest master merged in. We should discuss the layout of the code.
I think just edge cases. From what I can recall, weird matches were causing problems, but normal cases were fine.