MegastoRM

cod_vip_flagovi.sma

May 13th, 2012
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <hamsandwich>
  3.  
  4. #define VIP_STEAM (1<<0)
  5. #define VIP_IP (1<<1)
  6. #define VIP_NAME (1<<2)
  7. #define is_user(%1) (1 <= %1 <= 32)
  8.  
  9. new Array:vipAuthArray;
  10. new Array:vipPasswordArray;
  11. new Array:vipFlagsArray;
  12. new Array:vipAccessArray;
  13.  
  14. new cvarPasswordField
  15.  
  16. new bool:vip[33], vipFlags[33];
  17.  
  18. 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'};
  19.  
  20. public plugin_init()
  21. {
  22. register_plugin("VIPSystem", "1.2", "ZETA [M|E|N]");
  23.  
  24. cvarPasswordField = register_cvar("cod_password_field", "_pw");
  25.  
  26. LoadVipList("klase.ini");
  27. }
  28.  
  29. public plugin_precache()
  30. {
  31. vipAuthArray = ArrayCreate(44, 1);
  32. vipPasswordArray = ArrayCreate(32, 1);
  33. vipFlagsArray = ArrayCreate(1, 1);
  34. vipAccessArray = ArrayCreate(1, 1);
  35. }
  36.  
  37. LoadVipList(const fileName[])
  38. {
  39. new path[64];
  40. get_localinfo("amxx_configsdir", path, charsmax(path));
  41. format(path, charsmax(path), "%s/%s", path, fileName);
  42.  
  43. new file = fopen(path, "r");
  44.  
  45. if (file)
  46. {
  47. new text[121], auth[44], pass[32], flags[26], acc[3];
  48.  
  49. while (!feof(file))
  50. {
  51. fgets(file, text, charsmax(text));
  52. trim(text);
  53.  
  54. if (text[0] == ';')
  55. {
  56. continue;
  57. }
  58.  
  59. if (parse(text, auth, charsmax(auth), pass, charsmax(pass), flags, charsmax(flags), acc, charsmax(acc)) != 4)
  60. {
  61. continue;
  62. }
  63.  
  64. LoadVip(auth, pass, flags, acc);
  65. }
  66.  
  67. fclose(file);
  68. }
  69. }
  70.  
  71. FindFlag(const arr[], const ch)
  72. {
  73. new size = strlen(arr);
  74. for (new i = 0; i < size; i++)
  75. {
  76. if (arr[i] == ch)
  77. {
  78. return true;
  79. }
  80. }
  81.  
  82. return false;
  83. }
  84.  
  85. ReadFlags(const str[])
  86. {
  87. new flagsBin = 0;
  88. for (new i = 0; i < 26; i++)
  89. {
  90. if (FindFlag(str, letter[i]))
  91. {
  92. flagsBin |= (1<<i);
  93. }
  94. }
  95.  
  96. return flagsBin;
  97. }
  98.  
  99. ReadAccess(const str[])
  100. {
  101. new accBin = 0;
  102. for (new i = 0; i < 3; i++)
  103. {
  104. if (FindFlag(str, letter[i]))
  105. {
  106. accBin |= (1<<i);
  107. }
  108. }
  109.  
  110. return accBin;
  111. }
  112.  
  113. LoadVip(const auth[], const pass[], const flags[], const acc[])
  114. {
  115. ArrayPushString(vipAuthArray, auth);
  116. ArrayPushString(vipPasswordArray, pass);
  117. ArrayPushCell(vipFlagsArray, ReadFlags(flags));
  118. ArrayPushCell(vipAccessArray, ReadAccess(acc));
  119. }
  120.  
  121. GetAccess(const id)
  122. {
  123. new userName[32], passField[32], userPass[32], userAuth[32], userIp[44];
  124. get_user_info(id, "name", userName, charsmax(userName));
  125. get_pcvar_string(cvarPasswordField, passField, charsmax(passField));
  126. get_user_info(id, passField, userPass, charsmax(userPass));
  127. get_user_authid(id, userAuth, charsmax(userAuth));
  128. get_user_ip(id, userIp, charsmax(userIp), 1);
  129.  
  130. RemoveAccess(id);
  131.  
  132. new auth[44], pass[32], acc, flags;
  133. new size = ArraySize(vipAuthArray);
  134.  
  135. for (new i = 0; i < size; i++)
  136. {
  137. ArrayGetString(vipAuthArray, i, auth, charsmax(auth));
  138. ArrayGetString(vipPasswordArray, i, pass, charsmax(pass));
  139. flags = ArrayGetCell(vipFlagsArray, i);
  140. acc = ArrayGetCell(vipAccessArray, i);
  141.  
  142. if (((acc & VIP_STEAM) && equal(auth, userAuth)) || ((acc & VIP_IP) && equal(auth, userIp)) || ((acc & VIP_NAME) && equal(auth, userName) && equal(pass, userPass)))
  143. {
  144. vip[id] = true;
  145. vipFlags[id] = flags;
  146. break;
  147. }
  148. }
  149. }
  150.  
  151. RemoveAccess(const id)
  152. {
  153. vip[id] = false;
  154. vipFlags[id] = 0;
  155. }
  156.  
  157. // Events
  158.  
  159. public client_putinserver(id)
  160. {
  161. GetAccess(id);
  162. }
  163.  
  164. public client_disconnect(id)
  165. {
  166. RemoveAccess(id);
  167. }
  168.  
  169. public client_infochanged(id)
  170. {
  171. new newname[32], oldname[32];
  172. get_user_name(id, oldname, charsmax(oldname));
  173. get_user_info(id, "name", newname, charsmax(newname));
  174.  
  175. if (!equal(newname, oldname))
  176. {
  177. GetAccess(id);
  178. }
  179. }
  180.  
  181. // Natives
  182.  
  183. public plugin_natives()
  184. {
  185. register_native("cod_get_user_premium", "NativeGetUserVip",1);
  186. register_native("cod_user_has_flag", "NativeGetVipFlag",1);
  187. register_native("cod_get_user_flags", "NativeGetVipFlags",1);
  188. }
  189.  
  190. public NativeGetUserVip(id)
  191. {
  192. if (!is_user(id))
  193. {
  194. return false;
  195. }
  196.  
  197. return vip[id];
  198. }
  199.  
  200. public NativeGetVipFlag(id, flag)
  201. {
  202. if (!is_user(id) || !vip[id])
  203. {
  204. return false;
  205. }
  206.  
  207. if (flag && !(vipFlags[id] & flag))
  208. {
  209. return false;
  210. }
  211.  
  212. return true;
  213. }
  214.  
  215. public NativeGetVipFlags(id)
  216. {
  217. if (!is_user(id))
  218. {
  219. return 0;
  220. }
  221.  
  222. return vipFlags[id];
  223. }
  224.  
  225. public plugin_end()
  226. {
  227. ArrayDestroy(vipAuthArray);
  228. ArrayDestroy(vipPasswordArray);
  229. ArrayDestroy(vipFlagsArray);
  230. ArrayDestroy(vipAccessArray);
  231. }
Advertisement
Add Comment
Please, Sign In to add comment