This is what I use in one of my plugins to write a new admin. It will verify the admin does not already exist before adding. Whatever you pass as comment will show up after the semi-colon.
PHP Code:
public cmd_AddAdmin(auth[], accessflags[], password[], flags[], comment[])
{
/*This has been modified from the original amxmodx version to allow
for input of the comment line. This allows a comment to be specified
instead of only being supplied if the added admin is online at
the time of being added*/
// Make sure that the users.ini file exists.
new configsDir[64];
get_configsdir(configsDir, 63);
format(configsDir, 63, "%s/users.ini", configsDir);
if (!file_exists(configsDir))
{
console_print(0, "[%s] File ^"%s^" doesn't exist.", PLUGIN, configsDir);
return;
}
// Make sure steamid isn't already in file.
new line = 0, textline[256], len;
const SIZE = 63;
new line_steamid[SIZE + 1], line_password[SIZE + 1], line_accessflags[SIZE + 1], line_flags[SIZE + 1], parsedParams;
// <name|ip|steamid> <password> <access flags> <account flags>
while ((line = read_file(configsDir, line, textline, 255, len)))
{
if (len == 0 || equal(textline, ";", 1))
continue; // comment line
parsedParams = parse(textline, line_steamid, SIZE, line_password, SIZE, line_accessflags, SIZE, line_flags, SIZE);
if (parsedParams != 4)
continue; // Send warning/error?
if ( (containi(line_flags, flags) != -1) && (equal(line_steamid, auth)) )
{
console_print(0, "[%s] %s already exists!", PLUGIN, auth);
return;
}
}
// If we came here, steamid doesn't exist in users.ini. Add it.
new linetoadd[512];
formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^" ; %s", auth, password, accessflags, flags, comment);
if (!write_file(configsDir, linetoadd))
log_amx("Failed writing admin [%s:%s]", auth, comment);
}
__________________