Fixed incorrect use of ReferenceToIndex, which caused some functions to be unstable during client connection. (#2)
While this function works well with the client indexes we pass in, as its name suggests, we should essentially be passing player references, not client indexes. The problem is that SourceMod looks for this player in the entity list, but they might not be there when connecting, or they might be another client or a bot. This makes the code unstable and confusing, and it works intermittently. Steam doesn't care whether the player is in the entity list—it works with the Steam ID. Using ReferenceToIndex here is fundamentally wrong and causes random -1 errors, especially during OnClientConnect when the entity may not exist yet. This commit replaces it with a direct client index lookup, which is correct and reliable because params[1] is already a client index.
This commit is contained in:
+28
-14
@@ -219,11 +219,16 @@ static cell_t sm_UserHasLicenseForApp(IPluginContext *pContext, const cell_t *pa
|
||||
return k_EUserHasLicenseResultNoAuth;
|
||||
}
|
||||
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
CSteamID checkid = CreateCommonCSteamID(pPlayer, params, 3, 4);
|
||||
@@ -245,12 +250,16 @@ static cell_t sm_UserHasLicenseForAppId(IPluginContext *pContext, const cell_t *
|
||||
|
||||
static cell_t sm_GetClientSteamID(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
CSteamID steamId = CreateCommonCSteamID(pPlayer, params, 4, 5);
|
||||
@@ -270,14 +279,19 @@ static cell_t sm_GetUserGroupStatus(IPluginContext *pContext, const cell_t *para
|
||||
|
||||
if (pServer == NULL)
|
||||
{
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
CSteamID checkid = CreateCommonCSteamID(pPlayer, params, 3, 4);
|
||||
|
||||
+27
-12
@@ -60,11 +60,16 @@ static cell_t sm_RequestUserStats(IPluginContext *pContext, const cell_t *params
|
||||
return 0;
|
||||
}
|
||||
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
CSteamID checkid = CreateCommonCSteamID(pPlayer, params);
|
||||
@@ -80,11 +85,16 @@ static cell_t sm_GetStatCell(IPluginContext *pContext, const cell_t *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
char *pName;
|
||||
@@ -123,11 +133,16 @@ static cell_t sm_GetStatFloat(IPluginContext *pContext, const cell_t *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||
int client = params[1];
|
||||
if (client < 1 || client > playerhelpers->GetMaxClients())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
if (pPlayer == NULL || !pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is not connected", client);
|
||||
}
|
||||
|
||||
char *pName;
|
||||
|
||||
Reference in New Issue
Block a user