Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <hamsandwich>
- #define VIP_STEAM (1<<0)
- #define VIP_IP (1<<1)
- #define VIP_NAME (1<<2)
- #define is_user(%1) (1 <= %1 <= 32)
- new Array:vipAuthArray;
- new Array:vipPasswordArray;
- new Array:vipFlagsArray;
- new Array:vipAccessArray;
- new cvarPasswordField
- new bool:vip[33], vipFlags[33];
- new letter[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
- public plugin_init()
- {
- register_plugin("VIPSystem", "1.2", "ZETA [M|E|N]");
- cvarPasswordField = register_cvar("cod_password_field", "_pw");
- LoadVipList("klase.ini");
- }
- public plugin_precache()
- {
- vipAuthArray = ArrayCreate(44, 1);
- vipPasswordArray = ArrayCreate(32, 1);
- vipFlagsArray = ArrayCreate(1, 1);
- vipAccessArray = ArrayCreate(1, 1);
- }
- LoadVipList(const fileName[])
- {
- new path[64];
- get_localinfo("amxx_configsdir", path, charsmax(path));
- format(path, charsmax(path), "%s/%s", path, fileName);
- new file = fopen(path, "r");
- if (file)
- {
- new text[121], auth[44], pass[32], flags[26], acc[3];
- while (!feof(file))
- {
- fgets(file, text, charsmax(text));
- trim(text);
- if (text[0] == ';')
- {
- continue;
- }
- if (parse(text, auth, charsmax(auth), pass, charsmax(pass), flags, charsmax(flags), acc, charsmax(acc)) != 4)
- {
- continue;
- }
- LoadVip(auth, pass, flags, acc);
- }
- fclose(file);
- }
- }
- FindFlag(const arr[], const ch)
- {
- new size = strlen(arr);
- for (new i = 0; i < size; i++)
- {
- if (arr[i] == ch)
- {
- return true;
- }
- }
- return false;
- }
- ReadFlags(const str[])
- {
- new flagsBin = 0;
- for (new i = 0; i < 26; i++)
- {
- if (FindFlag(str, letter[i]))
- {
- flagsBin |= (1<<i);
- }
- }
- return flagsBin;
- }
- ReadAccess(const str[])
- {
- new accBin = 0;
- for (new i = 0; i < 3; i++)
- {
- if (FindFlag(str, letter[i]))
- {
- accBin |= (1<<i);
- }
- }
- return accBin;
- }
- LoadVip(const auth[], const pass[], const flags[], const acc[])
- {
- ArrayPushString(vipAuthArray, auth);
- ArrayPushString(vipPasswordArray, pass);
- ArrayPushCell(vipFlagsArray, ReadFlags(flags));
- ArrayPushCell(vipAccessArray, ReadAccess(acc));
- }
- GetAccess(const id)
- {
- new userName[32], passField[32], userPass[32], userAuth[32], userIp[44];
- get_user_info(id, "name", userName, charsmax(userName));
- get_pcvar_string(cvarPasswordField, passField, charsmax(passField));
- get_user_info(id, passField, userPass, charsmax(userPass));
- get_user_authid(id, userAuth, charsmax(userAuth));
- get_user_ip(id, userIp, charsmax(userIp), 1);
- RemoveAccess(id);
- new auth[44], pass[32], acc, flags;
- new size = ArraySize(vipAuthArray);
- for (new i = 0; i < size; i++)
- {
- ArrayGetString(vipAuthArray, i, auth, charsmax(auth));
- ArrayGetString(vipPasswordArray, i, pass, charsmax(pass));
- flags = ArrayGetCell(vipFlagsArray, i);
- acc = ArrayGetCell(vipAccessArray, i);
- if (((acc & VIP_STEAM) && equal(auth, userAuth)) || ((acc & VIP_IP) && equal(auth, userIp)) || ((acc & VIP_NAME) && equal(auth, userName) && equal(pass, userPass)))
- {
- vip[id] = true;
- vipFlags[id] = flags;
- break;
- }
- }
- }
- RemoveAccess(const id)
- {
- vip[id] = false;
- vipFlags[id] = 0;
- }
- // Events
- public client_putinserver(id)
- {
- GetAccess(id);
- }
- public client_disconnect(id)
- {
- RemoveAccess(id);
- }
- public client_infochanged(id)
- {
- new newname[32], oldname[32];
- get_user_name(id, oldname, charsmax(oldname));
- get_user_info(id, "name", newname, charsmax(newname));
- if (!equal(newname, oldname))
- {
- GetAccess(id);
- }
- }
- // Natives
- public plugin_natives()
- {
- register_native("cod_get_user_premium", "NativeGetUserVip",1);
- register_native("cod_user_has_flag", "NativeGetVipFlag",1);
- register_native("cod_get_user_flags", "NativeGetVipFlags",1);
- }
- public NativeGetUserVip(id)
- {
- if (!is_user(id))
- {
- return false;
- }
- return vip[id];
- }
- public NativeGetVipFlag(id, flag)
- {
- if (!is_user(id) || !vip[id])
- {
- return false;
- }
- if (flag && !(vipFlags[id] & flag))
- {
- return false;
- }
- return true;
- }
- public NativeGetVipFlags(id)
- {
- if (!is_user(id))
- {
- return 0;
- }
- return vipFlags[id];
- }
- public plugin_end()
- {
- ArrayDestroy(vipAuthArray);
- ArrayDestroy(vipPasswordArray);
- ArrayDestroy(vipFlagsArray);
- ArrayDestroy(vipAccessArray);
- }
Advertisement
Add Comment
Please, Sign In to add comment