Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@ -1117,23 +1117,19 @@
- return 1;
- }
- -static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
- +static bool SetClientInfoInternal(int client, const char* szKey, const char *szValue)
- {
- if (iserver == NULL)
- {
- - return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
- + g_pSM->LogError(myself, "IServer interface not supported, file a bug report.");
- + return false;
- }
- - IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
- - IClient *pClient = iserver->GetClient(params[1] - 1);
- -
- - if (player == NULL || pClient == NULL)
- + IClient *pClient = iserver->GetClient(client - 1);
- + if (pClient == NULL)
- {
- - return pContext->ThrowNativeError("Invalid client index %d", params[1]);
- - }
- - if (!player->IsConnected())
- - {
- - return pContext->ThrowNativeError("Client %d is not connected", params[1]);
- + g_pSM->LogError(myself, "Failed IClient lookup for client %d", client);
- + return false;
- }
- static ValveCall *pCall = NULL;
- @@ -1145,11 +1141,13 @@
- if (!CreateBaseCall("SetUserCvar", ValveCall_Entity, NULL, params, 2, &pCall))
- {
- - return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
- + g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
- + return false;
- }
- else if (!pCall)
- {
- - return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize");
- + g_pSM->LogError(myself, "\"SetUserCvar\" wrapper failed to initialize");
- + return false;
- }
- }
- @@ -1160,11 +1158,13 @@
- {
- if (!CreateBaseCall("UpdateUserSettings", ValveCall_Entity, NULL, NULL, 0, &pUpdateSettings))
- {
- - return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
- + g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
- + return false;
- }
- else if (!pUpdateSettings)
- {
- - return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize");
- + g_pSM->LogError(myself, "\"SetUserCvar\" wrapper failed to initialize");
- + return false;
- }
- }
- #else
- @@ -1174,7 +1174,8 @@
- {
- if (!g_pGameConf->GetOffset("InfoChanged", &changedOffset))
- {
- - return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
- + g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
- + return false;
- }
- }
- #endif
- @@ -1185,8 +1186,10 @@
- /* Not really a CBaseEntity* but this works */
- CBaseEntity **ebuf = (CBaseEntity **)vptr;
- *ebuf = (CBaseEntity *)CGameClient;
- - DECODE_VALVE_PARAM(2, vparams, 0);
- - DECODE_VALVE_PARAM(3, vparams, 1);
- + ebuf += sizeof(CBaseEntity *);
- + *(const char **)ebuf = szKey;
- + ebuf += sizeof(char *);
- + *(const char **)ebuf = szValue;
- FINISH_CALL_SIMPLE(NULL);
- #if SOURCE_ENGINE == SE_DARKMESSIAH
- @@ -1199,6 +1202,93 @@
- *changed = 1;
- #endif
- + return true;
- +}
- +
- +static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
- +{
- + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
- + if (player == NULL)
- + {
- + return pContext->ThrowNativeError("Invalid client index %d", params[1]);
- + }
- + if (!player->IsConnected())
- + {
- + return pContext->ThrowNativeError("Client %d is not connected", params[1]);
- + }
- +
- + char *szKey;
- + if (SP_ERROR_NONE != pContext->LocalToString(params[2], &szKey))
- + {
- + return pContext->ThrowNativeError("Error reading name");
- + }
- + char *szValue;
- + if (SP_ERROR_NONE != pContext->LocalToString(params[3], &szValue))
- + {
- + return pContext->ThrowNativeError("Error reading name");
- + }
- + return SetClientInfoInternal(params[1], szKey, szValue);
- +}
- +
- +// We only need this for cstrike
- +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
- +#define MAX_NAME_LENGTH 32
- +static char newnames[65][MAX_NAME_LENGTH];
- +static char oldnames[65][MAX_NAME_LENGTH];
- +#define CHECKFIXNAME(name) \
- + if (name[client][0] != '\0') \
- + { \
- + CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(client); \
- + datamap_t *datamap = gamehelpers->GetDataMap(pEntity); \
- + typedescription_t *td = gamehelpers->FindInDataMap(datamap, "m_szNetname"); \
- + int offset = GetTypeDescOffs(td); \
- + char *dest = (char *)((intptr_t)pEntity + offset); \
- + strncpy(dest, name[client], td->fieldSize); \
- + name[client][0] = '\0'; \
- + return; \
- + }
- +void SDKTools::OnClientSettingsChanged(int client)
- +{
- + CHECKFIXNAME(oldnames);
- + CHECKFIXNAME(newnames);
- +}
- +#endif
- +
- +static cell_t RenameClient(IPluginContext *pContext, const cell_t *params)
- +{
- + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
- + if (player == NULL)
- + {
- + return pContext->ThrowNativeError("Invalid client index %d", params[1]);
- + }
- + if (!player->IsConnected())
- + {
- + return pContext->ThrowNativeError("Client %d is not connected", params[1]);
- + }
- +
- + char *szNewName;
- + if (SP_ERROR_NONE != pContext->LocalToString(params[2], &szNewName))
- + {
- + return pContext->ThrowNativeError("Error reading name");
- + }
- +
- +#if SOURCE_ENGINE > SE_EPISODE1
- + SetClientInfoInternal(params[1], "name", szNewName);
- +
- +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
- + char gamedir[64];
- + engine->GetGameDir(gamedir, sizeof(gamedir));
- + if (strcmp(gamedir, "cstrike") == 0)
- + {
- + const char *szOldName = player->GetName();
- + strncpy(oldnames[params[1]], szOldName, strlen(szOldName));
- + strncpy(newnames[params[1]], szNewName, strlen(szNewName));
- + }
- +#endif //SOURCE_ENGINE == SE_ORANGEBOXVALVE
- +#else
- + engine->ClientCommand(player->GetEdict(), "name %s", szNewName);
- +#endif //SOURCE_ENGINE > SE_EPISODE1
- +
- return 1;
- }
- @@ -1229,5 +1319,6 @@
- {"EquipPlayerWeapon", WeaponEquip},
- {"ActivateEntity", ActivateEntity},
- {"SetClientInfo", SetClientInfo},
- + {"RenameClient", RenameClient},
- {NULL, NULL},
- };
Add Comment
Please, Sign In to add comment