In a file, I have the line:
Code:
hitman *p STEAM_ID_SOMETHING a b c d
This restricts the model "hitman" to "steam_id_something" and access flags "a b c d". I have this function to check it.
Code:
bool:CheckAccess(id,const Model[])
{
if(!is_user_connected(id))
return false
new pFile = fopen(g_ConfigDir,"r"),bool:FileFound = false,bool:HasAccess = false
if(!pFile)
return false
static Data[128],fModel[36],Access[36]
while(!feof(pFile))
{
fgets(pFile,Data,127);
strbreak(Data,fModel,35,Access,35);
if(containi(Model,fModel) == -1)
continue
if(containi(Access,"*P") != -1)
strbreak(Access,Data,1,Access,35);
FileFound = true
if(!Access[0])
break
strbreak(Access,Access,35,Data,127);
if(containi(Access,"STEAM_") != -1)
{
new AuthID[36]
get_user_authid(id,AuthID,35);
if(equali(Access,Data))
{
HasAccess = true
break
}
}
if(Data[0])
{
new Len = strlen(Data) / 2,iAccess
server_print("LEN: %d",Len);
for(new Count;Count < Len;Count++)
{
strbreak(Data,Access,35,Data,127);
iAccess = GetStringAccess(Access);
if(iAccess & GetUserAccess(id))
{
HasAccess = true
break
}
}
if(HasAccess)
break
}
}
fclose(pFile);
if(FileFound)
return HasAccess
return true
}
But I'm super annoyed when I think I'm doing something wrong. The above function works. But I think it can be better, is there anything / other alternatives i can do, to accomplish this?
Also, since i'm using a file. Should I use ether a vault system, or dynamic arrays?
__________________