HRESULT CreateStandaloneGame (void) { HRESULT hr; // Create the AdminSession class object IAdminSessionClassPtr spClass; if (!Error (hr = CoGetClassObject (__uuidof(AdminSession), CLSCTX_LOCAL_SERVER, NULL, __uuidof(spClass), (void**)&spClass))) { // Create an instance of the host object for an IAdminSessionHost interface AdminSessionSecureHost xHost; // Create an AdminSession object IAdminSessionPtr spSession; hr = spClass->CreateSession (&xHost, &spSession); ::CoDisconnectObject(&xHost, 0); if (!Error (hr)) { // Get the Server property from the session object IAdminServerPtr spServer; if (!Error (hr = spSession->get_Server (&spServer))) { // Get the Games property from the server object if (!Error (hr = spServer->get_Games (&m_spAdminGamesPtr))) { // check to see if there are existing games // and proceed only if there aren't CheckForExistingGames (); } } } } return hr; }
/*------------------------------------------------------------------------- * ~CAdminSession() *------------------------------------------------------------------------- */ CAdminSession::~CAdminSession() { XLockStatic lock(&s_cs); if (this == s_pWhoStartedServer) s_pWhoStartedServer = NULL; // Remove ourself from the static collection XSessionsIt it = std::find(s_vecSessions.begin(), s_vecSessions.end(), this); if (it != s_vecSessions.end()) s_vecSessions.erase(it); lock.Unlock(); #if defined(ALLSRV_STANDALONE) // Possibly shutdown the standalone server if no more sessions if (0 == GetSessionCount()) { // Get the Server property IAdminServerPtr spServer; if (SUCCEEDED(get_Server(&spServer))) { IAdminGamesPtr spGames; if (SUCCEEDED(spServer->get_Games(&spGames))) { // Shutdown the server if no games exist long cGames = 0; spGames->get_Count(&cGames); // KGJV #114 - if lobbied then dont shutdown if create game allowed on this server bool bSupposedToConnectToLobby = !(FEDSRV_GUID != g.fm.GetHostApplicationGuid()); if ((0 == cGames) && (bSupposedToConnectToLobby ? (g.cStaticCoreInfo == 0) : true)) PostThreadMessage(g.idReceiveThread, WM_QUIT, 0, 0); } } } #endif // defined(ALLSRV_STANDALONE) }