#include <amxmodx>
#include <amxmisc>
new const PLUGIN[] = \"Registered SteamID\"
new const VERSION[] = \"1.0\"
new const AUTHOR[] = \"Mlk27/danielkza\"
new Array:g_hNameArray
new Array:g_hAuthArray
new g_szSteamFile[64]
new cvNameChangeKick
new cvConnectKick
new cvRenameTries
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar(\"regsteamidname\", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
get_configsdir(g_szSteamFile, charsmax(g_szSteamFile))
add(g_szSteamFile, charsmax(g_szSteamFile), \"/steamidname.txt\")
LoadNames(true)
register_concmd(\"nr_reload\", \"Reload_Command\", ADMIN_RCON) // Reload names and steamid from steamidname.txt
register_clcmd(\"nr_check\", \"cmd_CheckRegister\") // Find all names registerted under steamid
cvNameChangeKick = register_cvar(\"nr_change_kick\", \"1\")
cvConnectKick = register_cvar(\"nr_connect_kick\", \"1\")
cvRenameTries = register_cvar(\"nr_rename_tries\", \"5\")
}
public Reload_Command(id, level, cid)
{
if(cmd_access(id, level, cid, 1))
{
console_print(id, \"[AMXX] %d name reservations loaded\", LoadNames())
// Recheck all players\' names
static iPlayers[32], iNum //
get_players(iPlayers, iNum)
for(new i=0; i < iNum;i++)
client_authorized(iPlayers[i])
}
return PLUGIN_HANDLED
}
public cmd_CheckRegister(id)
{
new szAuth[35]
get_user_authid(id, szAuth, charsmax(szAuth))
client_print(id, print_console, \"Registered name(s) under this SteamID\")
client_print(id, print_console, \"SteamID: %s\", szAuth)
client_print(id, print_console, \"------------------------------------------------\")
new iSize = min(ArraySize(g_hNameArray), ArraySize(g_hAuthArray))
new szTempAuth[35], szTempName[32]
new iCount
for(new i=0; i < iSize; i++)
{
ArrayGetString(g_hAuthArray, i, szTempAuth, charsmax(szTempAuth))
ArrayGetString(g_hNameArray, i, szTempName, charsmax(szTempName))
if(equali(szTempAuth, szAuth))
{
iCount++
console_print(id, \"%i. %s\", iCount, szTempName)
}
}
client_print(id, print_console, \"------------------------------------------------\")
client_print(id, print_console, \"Total registered name(s): %i\", iCount)
client_print(id, print_console, \"------------------------------------------------\")
return PLUGIN_HANDLED
}
public client_authorized(id)
{
static szName[32], szAuth[35] //
get_user_name(id, szName, charsmax(szName))
get_user_authid(id, szAuth, charsmax(szAuth))
if(!CheckName(szName, szAuth))
{
switch(get_pcvar_num(cvConnectKick))
{
case 0:
{
static szUsedName[32], szTempName[32]
copy(szUsedName, 28, szName)
new iMaxTries = min(get_pcvar_num(cvRenameTries), 9)
for(new i=1; i <= iMaxTries; i++)
{
formatex(szTempName, charsmax(szTempName), \"%s(%d)\", szUsedName, i)
if(!find_player(\"a\", szTempName) && CheckName(szTempName, szAuth))
{
set_user_info(id, \"name\", szTempName)
client_print(id, print_chat, \"[AMXX] Your name was changed, because it was already registered to another SteamID.\")
return
}
}
}
case 1:
{
server_cmd(\"kick #%d This name is registered to someone else\'s SteamID!\", get_user_userid(id))
}
}
log_to_file(\"steamidfail.txt\", \"On Join: [SteamID] %s [Name] %s\", szAuth, szName)
}
}
public client_infochanged(id)
{
new szNewName[32], szOldName[32], szAuth[35]
get_user_info(id, \"name\", szNewName, charsmax(szNewName))
get_user_name(id, szOldName, charsmax(szOldName))
get_user_authid(id, szAuth, charsmax(szAuth))
if(!equali(szNewName, szOldName) && !CheckName(szNewName, szAuth))
{
switch(get_pcvar_num(cvNameChangeKick))
{
case 0:
{
set_user_info(id, \"name\", szOldName)
client_print(id, print_chat, \"Your new name is reserved to another SteamID. Name change cancelled\")
}
case 1:
{
server_cmd(\"kick #%d This name is registered to someone else\'s SteamID!\", get_user_userid(id))
}
}
log_to_file(\"steamidfail.txt\", \"Name Change: [SteamID] %s [OldName] %s [NewName] %s\", szAuth, szOldName, szNewName)
}
}
LoadNames(iFatal = false)
{
if(!g_hNameArray)
{
g_hNameArray = ArrayCreate(32)
g_hAuthArray = ArrayCreate(35)
}
else
{
ArrayClear(g_hNameArray)
ArrayClear(g_hAuthArray)
}
new hFile = fopen(g_szSteamFile, \"r\")
if(!hFile)
hFile = fopen(g_szSteamFile, \"w+\")
if(!hFile)
{
if(iFatal)
{
new szFailMsg[64]
formatex(szFailMsg, charsmax(szFailMsg), \"Can\'t open/create file %s\", g_szSteamFile)
set_fail_state(szFailMsg)
}
return 0
}
else
{
static szName[32], szAuth[35], szBuffer[128] //
while(!feof(hFile))
{
fgets(hFile, szBuffer, charsmax(szBuffer))
trim(szBuffer)
if(!szBuffer[0] || szBuffer[0] == \';\' || (szBuffer[0] == \'/\' && szBuffer[1] == \'/\' ))
continue
parse(szBuffer, szAuth, charsmax(szAuth), szName, charsmax(szName))
if(szName[0] && szAuth[0])
{
ArrayPushString(g_hNameArray, szName)
ArrayPushString(g_hAuthArray, szAuth)
}
}
fclose(hFile)
}
return ArraySize(g_hNameArray)
}
CheckName(szName[], szAuth[])
{
new iSize = min(ArraySize(g_hNameArray), ArraySize(g_hAuthArray))
static szTempName[32], szTempAuth[35] //
for(new i=0; i < iSize; i++)
{
ArrayGetString(g_hNameArray, i, szTempName, charsmax(szTempName))
ArrayGetString(g_hAuthArray, i, szTempAuth, charsmax(szTempAuth))
if(equali(szTempName, szName))
return equali(szTempAuth, szAuth)
}
return true
}