#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <gamecms5>
#include <reapi>
new Trie:g_trhNamesData;
new HookChain:g_hcSUIN;
new g_szNames[][] =
{
"бубубу",
"мемеме",
"хрюхрю"
}
public OnAPIPluginLoaded(Handle:sqlTuple)
{
SQL_ThreadQuery(sqlTuple, "SQL_ThreadQuery_post", "SELECT `users`.`id`, cast(convert(`users`.`nick` using utf8) as binary) as `nick` \
FROM `users` WHERE (`users`.`nick` != '' AND `users`.`nick` != '---');");
}
public SQL_ThreadQuery_post(failstate, Handle:query, const error[], errornum)
{
if(SQL_Error(error, errornum, failstate) || !SQL_NumResults(query))
{
pause("a");
return;
}
g_trhNamesData = TrieCreate();
while(SQL_MoreResults(query))
{
static id, szNick[MAX_NAME_LENGTH];
id = SQL_ReadResult(query, SQL_FieldNameToNum(query, "id"));
SQL_ReadResult(query, SQL_FieldNameToNum(query, "nick"), szNick, charsmax(szNick));
mysql_escape_string(szNick, charsmax(szNick) * 2);
TrieSetCell(g_trhNamesData, szNick, id);
SQL_NextRow(query);
}
g_hcSUIN = RegisterHookChain(RG_CBasePlayer_SetClientUserInfoName, "CBasePlayer_SetUserInfoName", .post = false);
if(get_playersnum_ex(GetPlayers_ExcludeHLTV | GetPlayers_ExcludeBots))
{
for(new i = 1; i <= MaxClients; i++)
if(is_user_connected(i))
client_putinserver(i);
}
}
public client_putinserver(id)
{
if(!g_hcSUIN)
return;
new szName[MAX_NAME_LENGTH];
get_entvar(id, var_netname, szName, charsmax(szName));
CBasePlayer_SetUserInfoName(id, "", szName);
}
public CBasePlayer_SetUserInfoName(const iClient, infobuffer[], szNewName[])
{
if(FnBlockUseName(iClient, szNewName))
{
if(infobuffer[0] != EOS)
{
SetHookChainReturn(ATYPE_INTEGER, false);
return HC_SUPERCEDE;
}
DisableHookChain(g_hcSUIN);
set_entvar(iClient, var_netname, g_szNames[random(sizeof(g_szNames))]);
EnableHookChain(g_hcSUIN);
}
return HC_CONTINUE;
}
bool:FnBlockUseName(id, szName[])
{
static iMemberId;
if(!TrieGetCell(g_trhNamesData, szName, iMemberId))
return false;
if(iMemberId == 0)
return false;
return (cmsapi_is_user_member(id) != iMemberId || !cmsapi_get_admin_ident(id));
}