void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername) { cell_t res; int client = engine->IndexOfEdict(pEntity); CPlayer *pPlayer = &m_Players[client]; /* If they're not connected, they're a bot */ if (!pPlayer->IsConnected()) { /* Run manual connection routines */ char error[255]; const char *authid = engine->GetPlayerNetworkIDString(pEntity); pPlayer->Authorize(authid); pPlayer->m_bFakeClient = true; if (!OnClientConnect(pEntity, playername, "127.0.0.1", error, sizeof(error))) { /* :TODO: kick the bot if it's rejected */ return; } List<IClientListener *>::iterator iter; IClientListener *pListener = NULL; for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientConnected(client); /* See if bot was kicked */ if (!pPlayer->IsConnected()) { return; } } /* Now do authorization */ for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientAuthorized(client, authid); } /* Finally, tell plugins */ if (m_clauth->GetFunctionCount()) { m_clauth->PushCell(client); m_clauth->PushString(authid); m_clauth->Execute(NULL); } pPlayer->Authorize_Post(); } if (playerinfo) { pPlayer->m_Info = playerinfo->GetPlayerInfo(pEntity); } /* Get the client's language */ if (m_QueryLang) { const char *name; if (!pPlayer->IsFakeClient() && (name=engine->GetClientConVarValue(client, "cl_language"))) { unsigned int langid; pPlayer->m_LangId = (g_Translator.GetLanguageByName(name, &langid)) ? langid : g_Translator.GetServerLanguage(); } else { pPlayer->m_LangId = g_Translator.GetServerLanguage(); } } pPlayer->Connect(); m_PlayerCount++; List<IClientListener *>::iterator iter; IClientListener *pListener = NULL; for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientPutInServer(client); } m_clputinserver->PushCell(client); m_clputinserver->Execute(&res, NULL); if (pPlayer->IsAuthorized()) { pPlayer->DoPostConnectAuthorization(); } }
void PlayerManager::RunAuthChecks() { CPlayer *pPlayer; const char *authstr; unsigned int removed = 0; for (unsigned int i=1; i<=m_AuthQueue[0]; i++) { pPlayer = &m_Players[m_AuthQueue[i]]; authstr = engine->GetPlayerNetworkIDString(pPlayer->m_pEdict); if (authstr && authstr[0] != '\0' && (strcmp(authstr, "STEAM_ID_PENDING") != 0)) { /* Set authorization */ pPlayer->Authorize(authstr); /* Mark as removed from queue */ unsigned int client = m_AuthQueue[i]; m_AuthQueue[i] = 0; removed++; /* Send to extensions */ List<IClientListener *>::iterator iter; IClientListener *pListener; for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientAuthorized(client, authstr); if (!pPlayer->IsConnected()) { break; } } /* Send to plugins if player is still connected */ if (pPlayer->IsConnected() && m_clauth->GetFunctionCount()) { /* :TODO: handle the case of a player disconnecting in the middle */ m_clauth->PushCell(client); m_clauth->PushString(authstr); m_clauth->Execute(NULL); } if (pPlayer->IsConnected()) { pPlayer->Authorize_Post(); } } } /* Clean up the queue */ if (removed) { /* We don't have to compact the list if it's empty */ if (removed != m_AuthQueue[0]) { unsigned int diff = 0; for (unsigned int i=1; i<=m_AuthQueue[0]; i++) { /* If this member is removed... */ if (m_AuthQueue[i] == 0) { /* Increase the differential */ diff++; } else { /* diff cannot increase faster than i+1 */ assert(i > diff); assert(i - diff >= 1); /* move this index down */ m_AuthQueue[i - diff] = m_AuthQueue[i]; } } m_AuthQueue[0] -= removed; } else { m_AuthQueue[0] = 0; } } }