matfer, about your last question only, what seems to be the trick these days is to do an A2S_INFO server query and time that, that will give u latency
Example (for phyton but you should be able to recreate it easy in cpp) here (look for the ping function)