Gateway: 2 Fixes

* Logon fix when a Logon message is present, 2012 Server
* Logoff fix for a race condition that could cause the client to crash when using Gateway