#if defined _e_admin_included
#endinput
#endif
#define _e_admin_included
#include <a_samp>
#include <dutils>
#include <dini>
//------------------------------------------------
#define ADMIN_FOLDER "SAMP Admin" //The main admin system directory/folder
#define CONFIG_FOLDER "Configurations" //The admin system configuration directory/folder
#define LOGS_FOLDER ""ADMIN_FOLDER"/Logs" //path saving logs
#define ACCOUNTS_FOLDER "Accounts" //path saving user data
#define PATH_ACCOUNTS ""ADMIN_FOLDER"/"ACCOUNTS_FOLDER"/%s.ini" //path for saving users data
#define PATH_TEMPBAN ""ADMIN_FOLDER"/Tempbans.ini" //path for saving temp bans
#define PATH_AKA ""ADMIN_FOLDER"/aka.ini" //path for saving player akas
#define PATH_SETTINGS ""ADMIN_FOLDER"/"CONFIG_FOLDER"/Settings.ini" //path for the main config file
#define PATH_FORBIDENNAMES ""ADMIN_FOLDER"/"CONFIG_FOLDER"/ForbiddenNames.ini" //path for forbidden names
#define PATH_FORBIDENWORDS ""ADMIN_FOLDER"/"CONFIG_FOLDER"/ForbiddenWords.ini" //path for forbidden words
#define PATH_FORBIDENWEAPONS ""ADMIN_FOLDER"/"CONFIG_FOLDER"/ForbiddenWeapons.ini" //path for forbidden words
#define PATH_FORBIDENPARTOFNAMES ""ADMIN_FOLDER"/"CONFIG_FOLDER"/ForbiddenPartNames.ini" //path for forbidden part of names
#define PATH_BADRCONLOGINS ""ADMIN_FOLDER"/"CONFIG_FOLDER"/BadRconLogins.ini" //path saving bad rcon logins
//------------------------------------------------
#define dUser(%1).( udb_User(%1,
#define dUserINT(%1).( udb_UserInt(%1,
#define dUserSet(%1).( udb_UserSet(%1,
#define dUserSetINT(%1).( udb_UserSetInt(%1,
#define dUserSetFLOAT(%1).( udb_UserSetFloat(%1,
#define dUserFLOAT(%1).( udb_UserFloat(%1,
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
stock udb_encode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace("_","_00",tmp);
tmp=strreplace(";","_01",tmp);
tmp=strreplace("!","_02",tmp);
tmp=strreplace("/","_03",tmp);
tmp=strreplace("\\","_04",tmp);
tmp=strreplace("[","_05",tmp);
tmp=strreplace("]","_06",tmp);
tmp=strreplace("?","_07",tmp);
tmp=strreplace(".","_08",tmp);
tmp=strreplace("*","_09",tmp);
tmp=strreplace("<","_10",tmp);
tmp=strreplace(">","_11",tmp);
tmp=strreplace("{","_12",tmp);
tmp=strreplace("}","_13",tmp);
tmp=strreplace(" ","_14",tmp);
tmp=strreplace("\"","_15",tmp);
tmp=strreplace(":","_16",tmp);
tmp=strreplace("|","_17",tmp);
tmp=strreplace("=","_18",tmp);
return tmp;
}
stock udb_decode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace("_01",";",tmp);
tmp=strreplace("_02","!",tmp);
tmp=strreplace("_03","/",tmp);
tmp=strreplace("_04","\\",tmp);
tmp=strreplace("_05","[",tmp);
tmp=strreplace("_06","]",tmp);
tmp=strreplace("_07","?",tmp);
tmp=strreplace("_08",".",tmp);
tmp=strreplace("_09","*",tmp);
tmp=strreplace("_10","<",tmp);
tmp=strreplace("_11",">",tmp);
tmp=strreplace("_12","{",tmp);
tmp=strreplace("_13","}",tmp);
tmp=strreplace("_14"," ",tmp);
tmp=strreplace("_15","\"",tmp);
tmp=strreplace("_16",":",tmp);
tmp=strreplace("_17","|",tmp);
tmp=strreplace("_18","=",tmp);
tmp=strreplace("_00","_",tmp);
return tmp;
}
stock udb_Exists(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),PATH_ACCOUNTS,udb_encode(ni ckname));
return fexist(tmp);
}
stock udb_Remove(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),PATH_ACCOUNTS,udb_encode(ni ckname));
return dini_Remove(tmp);
}
stock udb_UserSetInt(nickname[],key[],value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
return dini_IntSet(fname,key,value);
}
stock udb_UserSetFloat(nickname[],key[],Float:value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
return dini_FloatSet(fname,key,value);
}
stock udb_UserSet(nickname[],key[],value[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
return dini_Set(fname,key,value);
}
stock udb_User(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
format(fname,sizeof(fname),dini_Get(fname,key));
return fname;
}
stock Float:udb_UserFloat(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
return dini_Float(fname,key);
}
stock udb_UserInt(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
return dini_Int(fname,key);
}
stock udb_Create(nickname[])
{
if (udb_Exists(nickname)) return false;
new fname[MAX_STRING];
format(fname,sizeof(fname),PATH_ACCOUNTS,udb_encod e(nickname));
dini_Create(fname);
return true;
}
stock udb_RenameUser(nickname[],newnick[])
{
new oldfname[MAX_STRING];
new newfname[MAX_STRING];
format(oldfname,sizeof(oldfname),PATH_ACCOUNTS,udb _encode(nickname));
format(newfname,sizeof(newfname),PATH_ACCOUNTS,udb _encode(newnick));
return frenametextfile(oldfname,newfname);
}
stock IsPlayerLAdmin(playerid)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp, tmp2;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"level");
tmp2 = dini_Int(file,"loggedin");
if( (IsPlayerConnected(playerid)) && (tmp > 0) && (tmp2 == 1)) return true;
else return false;
}
stock IsPlayerAdminLevel(playerid, level)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp, tmp2;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"level");
tmp2 = dini_Int(file,"loggedin");
if( (IsPlayerConnected(playerid)) && (tmp >= level) && (tmp2 != 0)) return true;
else return false;
}
stock IsPlayerLVIP(playerid)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp, tmp2;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"AccountType");
tmp2 = dini_Int(file,"loggedin");
if( (IsPlayerConnected(playerid)) && (tmp > 0) && (tmp2 == 1)) return true;
else return false;
}
stock IsPlayerVIPLevel(playerid, level)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp, tmp2;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"AccountType");
tmp2 = dini_Int(file,"loggedin");
if( (IsPlayerConnected(playerid)) && (tmp >= level) && (tmp2 != 0)) return true;
else return false;
}
stock IsPlayerLogged(playerid)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"loggedin");
if( (IsPlayerConnected(playerid)) && (tmp == 1)) return true;
else return false;
}
stock IsPlayerBanned(playerid)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"Banned");
if( (IsPlayerConnected(playerid)) && (tmp == 1)) return true;
else return false;
}
stock IsPlayerRegistered(playerid)
{
new name[MAX_PLAYER_NAME];
new file[256], tmp;
GetPlayerName(playerid, name, sizeof(name));
format(file,256,PATH_ACCOUNTS,udb_encode(name));
tmp = dini_Int(file,"Registered");
if( (IsPlayerConnected(playerid)) && (tmp == 1)) return true;
else return false;
}
|