Код:
#include <amxmodx>
#include <amxmisc>
#include <orpheu>
new Trie:ReplacementsTrie
new ConfigFile[] = "steamID_replacements.ini"
new BackOut[32] = "false"
public plugin_precache()
{
loadConfigFile(ReplacementsTrie=TrieCreate(),ConfigFile)
OrpheuRegisterHook(OrpheuGetFunction("SV_GetIDString"),"OnSV_GetIDString",OrpheuHookPost)
}
loadConfigFile(Trie:replacementsTrie,configFile[])
{
new path[100]
get_configsdir(path,charsmax(path))
format(path,charsmax(path),"%s/%s",path,configFile)
new file = fopen(path,"r")
if(file)
{
new line[100]
new steamIDLeft[32]
new steamIDRight[32]
new lineNumber = 1
while(fgets(file,line,charsmax(line)))
{
trim(line)
if(line[0] != '#')
{
strbreak(line,steamIDLeft,charsmax(steamIDLeft),steamIDRight,charsmax(steamIDRig
ht))
if(steamIDLeft[0] && steamIDRight[0])
{
TrieSetString(replacementsTrie,steamIDLeft,steamIDRight)
}
else
{
server_print("[steamID_replacements] Line number %d is invalid",lineNumber)
}
}
lineNumber++
}
fclose(file)
}
else
{
file = fopen(path,"w+")
if(file)
{
fprintf(file,"# Add lines with format ORIGINAL REPLACEMENT^n")
fclose(file)
set_fail_state("[steamID_replacements] Created base file")
}
else
{
set_fail_state("[steamID_replacements] Failed to create base file")
}
}
}
public OnSV_GetIDString(x)
{
static steamID[32]
OrpheuGetReturn(steamID,charsmax(steamID))
if (equal(BackOut,"false")&&!TrieKeyExists(ReplacementsTrie,steamID))
{
new players[32]
static inum,i,id,authid[32]
BackOut="true"
get_players(players,inum,"ch")
if(!TrieKeyExists(ReplacementsTrie,steamID)&&inum>0)
for(i = 0; i < inum; i++)
{
id = players[i]
//if(!is_user_connected(id)) continue;
get_user_authid(id, authid, 31)
if (equal(authid,steamID))
{
TrieSetString(Trie,steamID)
}
}
BackOut="false";
}
if(TrieKeyExists(ReplacementsTrie,steamID))
{
static newSteamID[32]
TrieGetString(ReplacementsTrie,steamID,newSteamID,charsmax(newSteamID))
OrpheuSetReturn(newSteamID)
}
}