1.1 --- a/core/PlayerManager.cpp Mon Jul 07 23:12:21 2008 +0000
1.2 +++ b/core/PlayerManager.cpp Tue Jul 08 09:20:47 2008 +0000
1.3 @@ -121,7 +121,7 @@
1.4 ParamType p1[] = {Param_Cell, Param_String, Param_Cell};
1.5 ParamType p2[] = {Param_Cell};
1.6
1.7 - m_clconnect = g_Forwards.CreateForward("OnClientConnect", ET_Event, 3, p1);
1.8 + m_clconnect = g_Forwards.CreateForward("OnClientConnect", ET_LowEvent, 3, p1);
1.9 m_clputinserver = g_Forwards.CreateForward("OnClientPutInServer", ET_Ignore, 1, p2);
1.10 m_cldisconnect = g_Forwards.CreateForward("OnClientDisconnect", ET_Ignore, 1, p2);
1.11 m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
1.12 @@ -288,7 +288,7 @@
1.13 unsigned int removed = 0;
1.14 for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
1.15 {
1.16 - pPlayer = GetPlayerByIndex(m_AuthQueue[i]);
1.17 + pPlayer = &m_Players[m_AuthQueue[i]];
1.18 authstr = engine->GetPlayerNetworkIDString(pPlayer->m_pEdict);
1.19 if (authstr && authstr[0] != '\0'
1.20 && (strcmp(authstr, "STEAM_ID_PENDING") != 0))
1.21 @@ -362,6 +362,7 @@
1.22 bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
1.23 {
1.24 int client = engine->IndexOfEdict(pEntity);
1.25 + CPlayer *pPlayer = &m_Players[client];
1.26
1.27 List<IClientListener *>::iterator iter;
1.28 IClientListener *pListener = NULL;
1.29 @@ -376,26 +377,29 @@
1.30
1.31 cell_t res = 1;
1.32
1.33 - m_Players[client].Initialize(pszName, pszAddress, pEntity);
1.34 + pPlayer->Initialize(pszName, pszAddress, pEntity);
1.35 m_clconnect->PushCell(client);
1.36 m_clconnect->PushStringEx(reject, maxrejectlen, SM_PARAM_STRING_UTF8, SM_PARAM_COPYBACK);
1.37 m_clconnect->PushCell(maxrejectlen);
1.38 - m_clconnect->Execute(&res, NULL);
1.39 + m_clconnect->Execute(&res);
1.40
1.41 if (res)
1.42 {
1.43 - if (!m_Players[client].IsAuthorized())
1.44 + if (!pPlayer->IsAuthorized())
1.45 {
1.46 m_AuthQueue[++m_AuthQueue[0]] = client;
1.47 }
1.48 +
1.49 + m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = client;
1.50 }
1.51 else
1.52 {
1.53 - RETURN_META_VALUE(MRES_SUPERCEDE, false);
1.54 + if (!pPlayer->IsFakeClient())
1.55 + {
1.56 + RETURN_META_VALUE(MRES_SUPERCEDE, false);
1.57 + }
1.58 }
1.59
1.60 - m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = client;
1.61 -
1.62 return true;
1.63 }
1.64
1.65 @@ -403,7 +407,7 @@
1.66 {
1.67 int client = engine->IndexOfEdict(pEntity);
1.68 bool orig_value = META_RESULT_ORIG_RET(bool);
1.69 - CPlayer *pPlayer = GetPlayerByIndex(client);
1.70 + CPlayer *pPlayer = &m_Players[client];
1.71
1.72 if (orig_value)
1.73 {
1.74 @@ -418,13 +422,17 @@
1.75 break;
1.76 }
1.77 }
1.78 +
1.79 + if (!pPlayer->IsFakeClient()
1.80 + && m_bIsListenServer
1.81 + && strncmp(pszAddress, "127.0.0.1", 9) == 0)
1.82 + {
1.83 + m_ListenClient = client;
1.84 + }
1.85 }
1.86 -
1.87 - if (!pPlayer->IsFakeClient()
1.88 - && m_bIsListenServer
1.89 - && strncmp(pszAddress, "127.0.0.1", 9) == 0)
1.90 + else
1.91 {
1.92 - m_ListenClient = client;
1.93 + InvalidatePlayer(pPlayer);
1.94 }
1.95
1.96 return true;
1.97 @@ -434,8 +442,8 @@
1.98 {
1.99 cell_t res;
1.100 int client = engine->IndexOfEdict(pEntity);
1.101 + CPlayer *pPlayer = &m_Players[client];
1.102
1.103 - CPlayer *pPlayer = GetPlayerByIndex(client);
1.104 /* If they're not connected, they're a bot */
1.105 if (!pPlayer->IsConnected())
1.106 {
1.107 @@ -494,7 +502,7 @@
1.108 }
1.109 }
1.110
1.111 - m_Players[client].Connect();
1.112 + pPlayer->Connect();
1.113 m_PlayerCount++;
1.114
1.115 List<IClientListener *>::iterator iter;
1.116 @@ -508,9 +516,9 @@
1.117 m_clputinserver->PushCell(client);
1.118 m_clputinserver->Execute(&res, NULL);
1.119
1.120 - if (m_Players[client].IsAuthorized())
1.121 + if (pPlayer->IsAuthorized())
1.122 {
1.123 - m_Players[client].DoPostConnectAuthorization();
1.124 + pPlayer->DoPostConnectAuthorization();
1.125 }
1.126 }
1.127
1.128 @@ -531,8 +539,9 @@
1.129 {
1.130 cell_t res;
1.131 int client = engine->IndexOfEdict(pEntity);
1.132 + CPlayer *pPlayer = &m_Players[client];
1.133
1.134 - if (m_Players[client].IsConnected())
1.135 + if (pPlayer->IsConnected())
1.136 {
1.137 m_cldisconnect->PushCell(client);
1.138 m_cldisconnect->Execute(&res, NULL);
1.139 @@ -543,7 +552,7 @@
1.140 return;
1.141 }
1.142
1.143 - if (m_Players[client].WasCountedAsInGame())
1.144 + if (pPlayer->WasCountedAsInGame())
1.145 {
1.146 m_PlayerCount--;
1.147 }
1.148 @@ -556,29 +565,7 @@
1.149 pListener->OnClientDisconnecting(client);
1.150 }
1.151
1.152 - /**
1.153 - * Remove client from auth queue if necessary
1.154 - */
1.155 - if (!m_Players[client].IsAuthorized())
1.156 - {
1.157 - for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
1.158 - {
1.159 - if (m_AuthQueue[i] == (unsigned)client)
1.160 - {
1.161 - /* Move everything ahead of us back by one */
1.162 - for (unsigned int j=i+1; j<=m_AuthQueue[0]; j++)
1.163 - {
1.164 - m_AuthQueue[j-1] = m_AuthQueue[j];
1.165 - }
1.166 - /* Remove us and break */
1.167 - m_AuthQueue[0]--;
1.168 - break;
1.169 - }
1.170 - }
1.171 - }
1.172 -
1.173 - m_Players[client].Disconnect();
1.174 - m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = 0;
1.175 + InvalidatePlayer(pPlayer);
1.176
1.177 if (m_ListenClient == client)
1.178 {
1.179 @@ -613,9 +600,9 @@
1.180 #endif
1.181 int client = engine->IndexOfEdict(pEntity);
1.182 cell_t res = Pl_Continue;
1.183 + CPlayer *pPlayer = &m_Players[client];
1.184
1.185 - CPlayer *pPlayer = GetPlayerByIndex(client);
1.186 - if (!pPlayer || !pPlayer->IsConnected())
1.187 + if (!pPlayer->IsConnected())
1.188 {
1.189 return;
1.190 }
1.191 @@ -667,8 +654,9 @@
1.192 {
1.193 cell_t res;
1.194 int client = engine->IndexOfEdict(pEntity);
1.195 + CPlayer *pPlayer = &m_Players[client];
1.196
1.197 - if (!m_Players[client].IsConnected())
1.198 + if (!pPlayer->IsConnected())
1.199 {
1.200 return;
1.201 }
1.202 @@ -676,42 +664,42 @@
1.203 m_clinfochanged->PushCell(engine->IndexOfEdict(pEntity));
1.204 m_clinfochanged->Execute(&res, NULL);
1.205
1.206 - IPlayerInfo *info = m_Players[client].GetPlayerInfo();
1.207 + IPlayerInfo *info = pPlayer->GetPlayerInfo();
1.208 const char *new_name = info ? info->GetName() : engine->GetClientConVarValue(client, "name");
1.209 - const char *old_name = m_Players[client].m_Name.c_str();
1.210 + const char *old_name = pPlayer->m_Name.c_str();
1.211
1.212 if (strcmp(old_name, new_name) != 0)
1.213 {
1.214 AdminId id = g_Admins.FindAdminByIdentity("name", new_name);
1.215 - if (id != INVALID_ADMIN_ID && m_Players[client].GetAdminId() != id)
1.216 + if (id != INVALID_ADMIN_ID && pPlayer->GetAdminId() != id)
1.217 {
1.218 - if (!CheckSetAdminName(client, &m_Players[client], id))
1.219 + if (!CheckSetAdminName(client, pPlayer, id))
1.220 {
1.221 - m_Players[client].Kick("Your name is reserved by SourceMod; set your password to use it.");
1.222 + pPlayer->Kick("Your name is reserved by SourceMod; set your password to use it.");
1.223 RETURN_META(MRES_IGNORED);
1.224 }
1.225 } else if ((id = g_Admins.FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) {
1.226 - if (id == m_Players[client].GetAdminId())
1.227 + if (id == pPlayer->GetAdminId())
1.228 {
1.229 /* This player is changing their name; force them to drop admin privileges! */
1.230 - m_Players[client].SetAdminId(INVALID_ADMIN_ID, false);
1.231 + pPlayer->SetAdminId(INVALID_ADMIN_ID, false);
1.232 }
1.233 }
1.234 - m_Players[client].SetName(new_name);
1.235 + pPlayer->SetName(new_name);
1.236 }
1.237
1.238 if (m_PassInfoVar.size() > 0)
1.239 {
1.240 /* Try for a password change */
1.241 - const char *old_pass = m_Players[client].m_LastPassword.c_str();
1.242 + const char *old_pass = pPlayer->m_LastPassword.c_str();
1.243 const char *new_pass = engine->GetClientConVarValue(client, m_PassInfoVar.c_str());
1.244 if (strcmp(old_pass, new_pass) != 0)
1.245 {
1.246 - m_Players[client].m_LastPassword.assign(new_pass);
1.247 - if (m_Players[client].IsInGame() && m_Players[client].IsAuthorized())
1.248 + pPlayer->m_LastPassword.assign(new_pass);
1.249 + if (pPlayer->IsInGame() && pPlayer->IsAuthorized())
1.250 {
1.251 /* If there is already an admin id assigned, this will just bail out. */
1.252 - m_Players[client].DoBasicAdminChecks();
1.253 + pPlayer->DoBasicAdminChecks();
1.254 }
1.255 }
1.256 }
1.257 @@ -862,6 +850,33 @@
1.258 target_processors.remove(pHandler);
1.259 }
1.260
1.261 +void PlayerManager::InvalidatePlayer(CPlayer *pPlayer)
1.262 +{
1.263 + /**
1.264 + * Remove client from auth queue if necessary
1.265 + */
1.266 + if (!pPlayer->IsAuthorized())
1.267 + {
1.268 + for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
1.269 + {
1.270 + if (m_AuthQueue[i] == (unsigned)pPlayer->m_iIndex)
1.271 + {
1.272 + /* Move everything ahead of us back by one */
1.273 + for (unsigned int j=i+1; j<=m_AuthQueue[0]; j++)
1.274 + {
1.275 + m_AuthQueue[j-1] = m_AuthQueue[j];
1.276 + }
1.277 + /* Remove us and break */
1.278 + m_AuthQueue[0]--;
1.279 + break;
1.280 + }
1.281 + }
1.282 + }
1.283 +
1.284 + m_UserIdLookUp[engine->GetPlayerUserId(pPlayer->m_pEdict)] = 0;
1.285 + pPlayer->Disconnect();
1.286 +}
1.287 +
1.288 int PlayerManager::InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags)
1.289 {
1.290 if ((flags & COMMAND_FILTER_CONNECTED) == COMMAND_FILTER_CONNECTED