Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #define PLUGIN "Access Admin Srvcmd"
- #define VERSION "1.0"
- #define AUTHOR "CheezPuff"
- #pragma semicolon 1
- const PATH_STRLEN = 64;
- const PLAYER_NAME_STRLEN = 32;
- const TEXT_STRLEN = 128;
- const AUTHID_STRLEN = 24;
- const PASSWORD_STRLEN = 32;
- const ACCESS_STRLEN = 24;
- const FLAGS_STRLEN = 8;
- const DATE_END_STRLEN = 32;
- const MESSAGE_STRLEN = 256;
- const TIME_STRLEN = 32;
- const NULLENT = -1;
- new const USER_INFO_KEY[] = "_gmf";
- new g_sConfigsDir[PATH_STRLEN];
- new g_sLogsDir[PATH_STRLEN];
- new g_sUsersFile[PATH_STRLEN + 32];
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- register_srvcmd("reloadadmins", "SrvCmdReloadAdmins"); // יעשה את עבודה וידפיס את השם של השחקן עם אדמין בלוג
- }
- public plugin_cfg() {
- get_localinfo("amxx_logs", g_sLogsDir, charsmax(g_sLogsDir)); // טעינת והרצת פקודה
- add(g_sLogsDir, charsmax(g_sLogsDir), "/admins_statistic"); // הגדרה ויצירה של הקובץ
- if(!dir_exists(g_sLogsDir)) mkdir(g_sLogsDir); // בדיקה במידה והקובץ אינו קיים
- get_localinfo("amxx_configsdir", g_sConfigsDir, charsmax(g_sConfigsDir));
- formatex(g_sUsersFile, charsmax(g_sUsersFile), "%s/users.ini", g_sConfigsDir);
- ReadUsersFile();
- }
- public client_authorized(id) {
- SetAdminAccess(id);
- }
- ReadUsersFile() {
- new iFileID;
- if((iFileID = fopen(g_sUsersFile, "rt"))) {
- new sText[TEXT_STRLEN],\
- sAuthID[AUTHID_STRLEN],\
- sPassword[PASSWORD_STRLEN],\
- sAccess[ACCESS_STRLEN],\
- sFlags[FLAGS_STRLEN],\
- sDateEnd[DATE_END_STRLEN];
- while(!feof(iFileID)) {
- fgets(iFileID, sText, charsmax(sText)); trim(sText);
- if(!sText[0] || sText[0] == ';') continue;
- parse(sText,\
- sAuthID, charsmax(sAuthID),\
- sPassword, charsmax(sPassword),\
- sAccess, charsmax(sAccess),\
- sFlags, charsmax(sFlags),\
- sDateEnd, charsmax(sDateEnd)\
- );
- if(sDateEnd[0])
- if(parse_time(sDateEnd, "%d.%m.%Y") < get_systime())
- continue;
- admins_push(sAuthID, sPassword, read_flags(sAccess), read_flags(sFlags));
- }
- fclose(iFileID);
- }
- }
- SetAdminAccess(const id) {
- remove_user_flags(id);
- new sAuthID[AUTHID_STRLEN], sAuthIDTemp[AUTHID_STRLEN], iAdminIndex = NULLENT;
- get_user_authid(id, sAuthID, charsmax(sAuthID));
- for(new i, iAdminsCount = admins_num(); i < iAdminsCount; i++) {
- admins_lookup(i, AdminProp_Auth, sAuthIDTemp, charsmax(sAuthIDTemp));
- if(equal(sAuthID, sAuthIDTemp)) {
- iAdminIndex = i;
- break;
- }
- }
- if(iAdminIndex != NULLENT) {
- new sPassword[PASSWORD_STRLEN], sPasswordTemp[PASSWORD_STRLEN];
- get_user_info(id, USER_INFO_KEY, sPassword, charsmax(sPassword));
- admins_lookup(iAdminIndex, AdminProp_Password, sPasswordTemp, charsmax(sPasswordTemp));
- if(equal(sPassword, sPasswordTemp)) {
- new sAccess[ACCESS_STRLEN], bsAccess, sPlayerName[PLAYER_NAME_STRLEN];
- bsAccess = admins_lookup(iAdminIndex, AdminProp_Access);
- get_flags(bsAccess, sAccess, charsmax(sAccess));
- get_user_name(id, sPlayerName, charsmax(sPlayerName));
- set_user_flags(id, bsAccess);
- logging(g_sLogsDir, "admins_connection_", "^"%s^" ^"%s^" ^"%s^"", sAuthID, sPlayerName, sAccess); // לוג לתיקיה בתוך לוגס
- } else
- server_cmd("kick #%d ^"%s^"", get_user_userid(id), "Invalid password specified"); // יתן קיק למי שלא יעשה ישים את הפרטים הנכונים
- } else
- set_user_flags(id, ADMIN_USER);
- }
- public SrvCmdReloadAdmins() {
- admins_flush(); ReadUsersFile();
- new aPlayersID[MAX_PLAYERS], iPlayersNum;
- get_players(aPlayersID, iPlayersNum, "ch");
- for(new i; i < iPlayersNum; i++)
- SetAdminAccess(aPlayersID[i]);
- server_print("administrators reloaded"); // ידפיס בקונסול שאדמין הראשי עשה ריפרש
- }
- stock logging(const sLogsDir[], const sFileName[], const sMessage[], any:...) {
- new iFileID, sFormatMsg[MESSAGE_STRLEN], sTime[TIME_STRLEN], sLogFile[PATH_STRLEN + 32];
- vformat(sFormatMsg, charsmax(sFormatMsg), sMessage, 4);
- get_time("%m.%Y.log", sTime, charsmax(sTime));
- formatex(sLogFile, charsmax(sLogFile), "%s/%s%s", sLogsDir, sFileName, sTime);
- iFileID = fopen(sLogFile, "at");
- get_time("%d.%m.%Y - %H:%M:%S", sTime, charsmax(sTime));
- fprintf(iFileID, "^"%s^" %s^n", sTime, sFormatMsg);
- fclose(iFileID);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement