Guest User

Untitled

a guest
Oct 8th, 2010
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.73 KB | None | 0 0
  1. #pragma unused ret_memcpy
  2.  
  3. #include <a_samp>
  4. #include <dini>
  5. #include <dutils>
  6.  
  7. #define FILTERSCRIPT
  8. #if defined FILTERSCRIPT
  9. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  10. #define COLOUR_GREEN 0x33AA33AA
  11. #define COLOUR_RED 0xAA3333AA
  12. #define COLOUR_YELLOW 0xFFFF00AA
  13. #define COLOUR_LIGHTBLUE 0x33CCFFAA
  14. #define COLOUR_ORANGE 0xFF9900AA
  15.  
  16. #define PlayerFile "rAdmin/Users/%s.ini"
  17. #define SettingFile "rAdmin/Settings/MainSettings.ini"
  18. #define CommandFile "rAdmin/Settings/Commands.ini"
  19.  
  20. enum PLAYER_MAIN {
  21. PLAYER_NAME[MAX_PLAYER_NAME],
  22. PLAYER_IP[16],
  23. PLAYER_REGGED,
  24. PLAYER_PASS,
  25. PLAYER_LOGGED,
  26. PLAYER_LEVEL,
  27. PLAYER_WIRED,
  28. PLAYER_JAILED
  29. }
  30.  
  31. new gPlayerInfo[MAX_PLAYERS][PLAYER_MAIN];
  32.  
  33. enum SETTINGS_MAIN {
  34. POCKET_MONEY,
  35. JAIL_COMMANDS,
  36. ANNOUNCE_SECONDS,
  37. PASS_MIN,
  38. PASS_MAX
  39. }
  40.  
  41. new gSettings[SETTINGS_MAIN];
  42.  
  43. enum COMMANDS_MAIN {
  44. AKILL,
  45. ANNOUNCE,
  46. ARMOURALL,
  47. BAN,
  48. CARHP,
  49. EXPLODE,
  50. FLIP,
  51. GOTO,
  52. GETHERE,
  53. GIVEARMOUR,
  54. GIVEHEALTH,
  55. GIVEWEAPON,
  56. GOD,
  57. HEALALL,
  58. IMITATE,
  59. IP,
  60. KICK,
  61. MAXAMMO,
  62. PING,
  63. SETLEVEL,
  64. SETWANTED,
  65. TBAN,
  66. TIME,
  67. WEATHER
  68. }
  69.  
  70. new gCommands[COMMANDS_MAIN];
  71.  
  72. public OnFilterScriptInit()
  73. {
  74. print("\n****************************************");
  75. print("* rAdmin: Admin filterscript by TheHoodRat *");
  76. print("****************************************\n");
  77.  
  78. if(!fexist(SettingFile))
  79. {
  80. dini_Create(SettingFile);
  81. dini_IntSet(SettingFile, "PocketMoney", 3000);
  82. dini_IntSet(SettingFile, "JailCommands", 0);
  83. dini_IntSet(SettingFile, "AnnounceSeconds", 3);
  84. dini_IntSet(SettingFile, "PassMin", 3);
  85. dini_IntSet(SettingFile, "PassMax", 15);
  86. }
  87.  
  88. gSettings[POCKET_MONEY] = dini_Int(SettingFile, "PocketMoney");
  89. gSettings[JAIL_COMMANDS] = dini_Int(SettingFile, "JailCommands");
  90. gSettings[ANNOUNCE_SECONDS] = dini_Int(SettingFile, "AnnounceSeconds");
  91. gSettings[PASS_MIN] = dini_Int(SettingFile, "PassMin");
  92. gSettings[PASS_MAX] = dini_Int(SettingFile, "PassMax");
  93.  
  94. if(!fexist(CommandFile))
  95. {
  96. dini_Create(CommandFile);
  97. dini_IntSet(CommandFile, "Akill", 6);
  98. dini_IntSet(CommandFile, "Announce", 5);
  99. dini_IntSet(CommandFile, "Armourall", 3);
  100. dini_IntSet(CommandFile, "Ban", 9);
  101. dini_IntSet(CommandFile, "Carhp", 4);
  102. dini_IntSet(CommandFile, "Explode", 5);
  103. dini_IntSet(CommandFile, "Goto", 4);
  104. dini_IntSet(CommandFile, "Gethere", 5);
  105. dini_IntSet(CommandFile, "Givearmour", 6);
  106. dini_IntSet(CommandFile, "Givehealth", 6);
  107. dini_IntSet(CommandFile, "Giveweapon", 7);
  108. dini_IntSet(CommandFile, "God", 10);
  109. dini_IntSet(CommandFile, "Healall", 7);
  110. dini_IntSet(CommandFile, "Imitate", 8);
  111. dini_IntSet(CommandFile, "Ip", 2);
  112. dini_IntSet(CommandFile, "Kick", 7);
  113. dini_IntSet(CommandFile, "Maxammo", 8);
  114. dini_IntSet(CommandFile, "Ping", 1);
  115. dini_IntSet(CommandFile, "Setlevel", 10);
  116. dini_IntSet(CommandFile, "Setwanted", 6);
  117. dini_IntSet(CommandFile, "Tban", 9);
  118. dini_IntSet(CommandFile, "Time", 3);
  119. dini_IntSet(CommandFile, "Weather", 3);
  120. }
  121.  
  122. gCommands[AKILL] = dini_Int(CommandFile, "Akill");
  123. gCommands[ANNOUNCE] = dini_Int(CommandFile, "Announce");
  124. gCommands[ARMOURALL] = dini_Int(CommandFile, "Armourall");
  125. gCommands[BAN] = dini_Int(CommandFile, "Ban");
  126. gCommands[CARHP] = dini_Int(CommandFile, "Carhp");
  127. gCommands[EXPLODE] = dini_Int(CommandFile, "Explode");
  128. gCommands[GOTO] = dini_Int(CommandFile, "Goto");
  129. gCommands[GETHERE] = dini_Int(CommandFile, "Gethere");
  130. gCommands[GIVEARMOUR] = dini_Int(CommandFile, "Givearmour");
  131. gCommands[GIVEHEALTH] = dini_Int(CommandFile, "Givehealth");
  132. gCommands[GIVEWEAPON] = dini_Int(CommandFile, "Giveweapon");
  133. gCommands[GOD] = dini_Int(CommandFile, "God");
  134. gCommands[HEALALL] = dini_Int(CommandFile, "Healall");
  135. gCommands[IMITATE] = dini_Int(CommandFile, "Imitate");
  136. gCommands[IP] = dini_Int(CommandFile, "Ip");
  137. gCommands[KICK] = dini_Int(CommandFile, "Kick");
  138. gCommands[MAXAMMO] = dini_Int(CommandFile, "Maxammo");
  139. gCommands[SETLEVEL] = dini_Int(CommandFile, "Setlevel");
  140. gCommands[SETWANTED] = dini_Int(CommandFile, "Setwanted");
  141. gCommands[TBAN] = dini_Int(CommandFile, "Tban");
  142. gCommands[TIME] = dini_Int(CommandFile, "Time");
  143. gCommands[WEATHER] = dini_Int(CommandFile, "Weather");
  144.  
  145. return 1;
  146. }
  147. #endif
  148.  
  149. public OnPlayerConnect(playerid)
  150. {
  151. new file[100],Name[MAX_PLAYER_NAME],Ip[16];
  152. GetPlayerName(playerid,Name,sizeof(Name));
  153. GetPlayerIp(playerid,Ip,sizeof(Ip));
  154. format(file,sizeof(file),PlayerFile,Name);
  155.  
  156. if(!dini_Exists(file))
  157. {
  158. dini_Create(file);
  159. dini_Set(file,"Name",Name);
  160. dini_Set(file,"Ip",Ip);
  161. dini_IntSet(file,"Registered",-1);
  162. dini_IntSet(file,"Password",0);
  163. dini_IntSet(file,"Level",0);
  164. dini_IntSet(file,"Wired",0);
  165. dini_IntSet(file,"Jailed",0);
  166. SendClientMessage(playerid,COLOUR_ORANGE,"Your username is not recognized on this server. Please /register to continue.");
  167. }
  168. strcat(gPlayerInfo[playerid][PLAYER_NAME], dini_Get(file,"Name"));
  169. strcat(gPlayerInfo[playerid][PLAYER_IP], dini_Get(file,"Ip"));
  170. gPlayerInfo[playerid][PLAYER_REGGED] = dini_Int(file,"Registered");
  171. gPlayerInfo[playerid][PLAYER_PASS] = dini_Int(file,"Password");
  172. gPlayerInfo[playerid][PLAYER_LEVEL] = dini_Int(file,"Level");
  173. gPlayerInfo[playerid][PLAYER_WIRED] = dini_Int(file,"Wired");
  174. gPlayerInfo[playerid][PLAYER_JAILED] = dini_Int(file,"Jailed");
  175. if(gPlayerInfo[playerid][PLAYER_REGGED] == 0) SendClientMessage(playerid,COLOUR_ORANGE,"You're username is recognised on this server, but you have not registered. Please /register to continue.");
  176. else if(gPlayerInfo[playerid][PLAYER_REGGED] == 1) SendClientMessage(playerid,COLOUR_ORANGE,"You're username is recognised on this server. Please /login to continue.");
  177. gPlayerInfo[playerid][PLAYER_REGGED] = 0;
  178. return 1;
  179. }
  180.  
  181. public OnPlayerDisconnect(playerid, reason)
  182. {
  183. new file[100];
  184. format(file,sizeof(file),PlayerFile,gPlayerInfo[playerid][PLAYER_NAME]);
  185. dini_Set(file,"Name",gPlayerInfo[playerid][PLAYER_NAME]);
  186. dini_Set(file,"Ip",gPlayerInfo[playerid][PLAYER_IP]);
  187. dini_IntSet(file,"Registered",gPlayerInfo[playerid][PLAYER_REGGED]);
  188. dini_IntSet(file,"Password",gPlayerInfo[playerid][PLAYER_PASS]);
  189. dini_IntSet(file,"Level",gPlayerInfo[playerid][PLAYER_LEVEL]);
  190. dini_IntSet(file,"Wired",gPlayerInfo[playerid][PLAYER_WIRED]);
  191. dini_IntSet(file,"Jailed",gPlayerInfo[playerid][PLAYER_JAILED]);
  192. gPlayerInfo[playerid][PLAYER_NAME] = 0;
  193. gPlayerInfo[playerid][PLAYER_IP] = 0;
  194. gPlayerInfo[playerid][PLAYER_REGGED] = 0;
  195. gPlayerInfo[playerid][PLAYER_LOGGED] = 0;
  196. gPlayerInfo[playerid][PLAYER_PASS] = 0;
  197. gPlayerInfo[playerid][PLAYER_LEVEL] = 0;
  198. gPlayerInfo[playerid][PLAYER_WIRED] = 0;
  199. gPlayerInfo[playerid][PLAYER_JAILED] = 0;
  200. return 1;
  201. }
  202.  
  203. public OnPlayerCommandText(playerid, cmdtext[])
  204. {
  205. dcmd(register, 8, cmdtext);
  206. dcmd(login, 5, cmdtext);
  207. dcmd(logout, 6, cmdtext);
  208. dcmd(password, 8, cmdtext);
  209. dcmd(akill, 5, cmdtext);
  210. dcmd(announce, 8, cmdtext);
  211. return 0;
  212. }
  213.  
  214. dcmd_register(playerid, params[])
  215. {
  216. if(gPlayerInfo[playerid][PLAYER_REGGED] == 1)
  217. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You have already registered!");
  218. else if(!params[0])
  219. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /register [password]");
  220. else if(strlen(params) < gSettings[PASS_MIN] || strlen(params) > gSettings[PASS_MAX])
  221. {
  222. new string[128];
  223. format(string, sizeof(string), "ERROR: Password must be between %d and $d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
  224. return SendClientMessage(playerid, COLOUR_ORANGE, string);
  225. }
  226. else
  227. {
  228. new password = num_hash(params);
  229. gPlayerInfo[playerid][PLAYER_PASS] = password;
  230. gPlayerInfo[playerid][PLAYER_REGGED] = 1;
  231. gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
  232. GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
  233. new string[128]; format(string, sizeof(string), "You have successfully registered your account with the password \'%s\'. You have been automatically logged in.", params);
  234. return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  235. }
  236. }
  237.  
  238. dcmd_login(playerid, params[])
  239. {
  240. if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  241. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
  242. else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 1)
  243. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You are already logged-in.");
  244. else if(!params[0])
  245. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /login [password]");
  246. else
  247. {
  248. new password = num_hash(params);
  249. if(gPlayerInfo[playerid][PLAYER_PASS] == password)
  250. {
  251. gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
  252. GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
  253. return SendClientMessage(playerid, COLOUR_LIGHTBLUE, "You have successfully logged in to your account.");
  254. }
  255. else
  256. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
  257. }
  258. }
  259.  
  260. dcmd_logout(playerid, params[])
  261. {
  262. #pragma unused params
  263. if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  264. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register.");
  265. else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 0)
  266. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You are already logged-out.");
  267. else
  268. {
  269. gPlayerInfo[playerid][PLAYER_LOGGED] = 0;
  270. return SendClientMessage(playerid, COLOUR_LIGHTBLUE, "You have successfully logged out of your account.");
  271. }
  272. }
  273.  
  274. dcmd_password(playerid, params[])
  275. {
  276. if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  277. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
  278. else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 0)
  279. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must be logged-in to do that! Use /login [password] to login.");
  280. else
  281. {
  282. new tmp[256],
  283. tmp2[256],
  284. index;
  285. tmp = strtok(params, index);
  286. if(!strlen(tmp))
  287. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
  288. tmp2 = strtok(params, index);
  289. if(!strlen(tmp2))
  290. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
  291. new oldpassword = num_hash(tmp), newpassword = num_hash(tmp2);
  292. if(gPlayerInfo[playerid][PLAYER_PASS] == oldpassword)
  293. {
  294. if(oldpassword == newpassword)
  295. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Your old password can not be the same as your new password.");
  296. else if(strlen(tmp2) < gSettings[PASS_MIN] || strlen(tmp2) > gSettings[PASS_MAX])
  297. {
  298. new string[100]; format(string, sizeof(string), "ERROR: Your new password must be between %d and %d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
  299. return SendClientMessage(playerid, COLOUR_ORANGE, string);
  300. }
  301. gPlayerInfo[playerid][PLAYER_PASS] = newpassword;
  302. new string[128]; format(string, sizeof(string), "You have successfully changed your password from \'%s\' to \'%s\'.", tmp, tmp2);
  303. return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  304. }
  305. else
  306. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
  307. }
  308. }
  309.  
  310. dcmd_akill(playerid, params[])
  311. {
  312. if(gPlayerInfo[playerid][PLAYER_LEVEL] < gCommands[AKILL])
  313. {
  314. new string[100];
  315. format(string, sizeof(string), "You must be administrator level %d to use that command!", gCommands[AKILL]);
  316. return SendClientMessage(playerid, COLOUR_ORANGE, string);
  317. }
  318. else if(!strlen(params))
  319. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /akill [id | name]");
  320. else
  321. {
  322. new id = (isNumeric(params)) ? strval(params) : GetPlayerId(params);
  323. if(IsPlayerConnected(id) && id != playerid)
  324. {
  325. SetPlayerHealth(id, 0.0);
  326. new string[128];
  327. format(string, sizeof(string), "You have been admin-killed by administrator \'%s\'.", gPlayerInfo[playerid][PLAYER_NAME]);
  328. SendClientMessage(id, COLOUR_ORANGE, string);
  329. format(string, sizeof(string), "You have successfully admin-killed player \'%s\'.", gPlayerInfo[id][PLAYER_NAME]);
  330. return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  331. }
  332. else
  333. return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You can not admin-kill yourself or a disconnected player.");
  334. }
  335. }
  336.  
  337. dcmd_announce(playerid, params[])
  338. {
  339. if(gPlayerInfo[playerid][PLAYER_LEVEL] < gCommands[ANNOUNCE])
  340. {
  341. new string[100];
  342. format(string, sizeof(string), "You must be administrator level %d to use that command!", gCommands[ANNOUNCE]);
  343. return SendClientMessage(playerid, COLOUR_ORANGE, string);
  344. }
  345. else if(!strlen(params))
  346. return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /announce [message]");
  347. else
  348. return GameTextForAll(params, gSettings[ANNOUNCE_SECONDS] * 1000, 3);
  349. }
  350.  
  351. stock GetPlayerId(const Name[])
  352. {
  353. for(new i; i<MAX_PLAYERS; i++)
  354. {
  355. if(IsPlayerConnected(i))
  356. {
  357. new pName[MAX_PLAYER_NAME];
  358. GetPlayerName(i, pName, sizeof(pName));
  359. if(strcmp(Name, pName, true)==0)
  360. {
  361. return i;
  362. }
  363. }
  364. }
  365. return -1;
  366. }
Advertisement
Add Comment
Please, Sign In to add comment