Advertisement
Sadom

Untitled

Jun 25th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.59 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_http>
  3. #include <zcmd>
  4.  
  5. // ------------------------------------------------------------------
  6. // Please fill in your API key here, you can obtain an API key from
  7. // http://www.samp-bans.com/page/register
  8. // ------------------------------------------------------------------
  9. #define APIKEY yourkey
  10.  
  11. // ------------------------------------------------------------------
  12. // Do not edit below here unless you know what you're doing!
  13. // ------------------------------------------------------------------
  14. #define APIPATH "www.samp-bans.com/api.php"
  15.  
  16. #define MAX_API_LENGTH 38
  17. #define MAX_PLAYER_IP 15
  18. #define MAX_REASON_LENGTH 50
  19. #define MAX_EXTRA_LENGTH 63
  20. #define MAX_TIME_LENGTH 5
  21.  
  22. #define MAX_POST_LENGTH MAX_API_LENGTH+MAX_PLAYER_IP+MAX_REASON_LENGTH+MAX_EXTRA_LENGTH+MAX_TIME_LENGTH+MAX_PLAYER_NAME+MAX_PLAYER_NAME
  23.  
  24. #define COLOR_RED 0xFF0000FF
  25.  
  26. forward OnBanResponse(index, response_code, data[]);
  27. forward OnRemoveResponse(index, response_code, data[]);
  28. forward OnCheckResponse(index, response_code, data[]);
  29.  
  30. new post_string[MAX_POST_LENGTH];
  31.  
  32. new
  33. ban_reason[MAX_REASON_LENGTH],
  34. ban_target,
  35. ban_time,
  36. names[MAX_PLAYERS][MAX_PLAYER_NAME],
  37. ips[MAX_PLAYERS][MAX_PLAYER_IP],
  38. error[12],
  39. code[128];
  40.  
  41. public OnFilterScriptInit()
  42. {
  43. return 1;
  44. }
  45.  
  46. public OnPlayerConnect(playerid)
  47. {
  48. GetPlayerIp(playerid, ips[playerid], MAX_PLAYER_IP);
  49. GetPlayerName(playerid, names[playerid], MAX_PLAYER_NAME);
  50.  
  51. CheckBan(playerid);
  52. return 1;
  53. }
  54.  
  55. stock CheckBan(playerid)
  56. {
  57. format(post_string, sizeof(post_string), "action=checkip&apikey="#APIKEY"&ban_ip=%s", ips[playerid]);
  58.  
  59. HTTP(playerid, HTTP_POST, APIPATH, post_string, "OnCheckResponse");
  60. return 1;
  61. }
  62.  
  63. COMMAND:ban(playerid, params[])
  64. {
  65. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: You need to be logged in as an RCON administrator to perform this!");
  66. if(sscanf(params, "uis", ban_target, ban_time, ban_reason)) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BAN]: Correct usage -> /ban <player> <time (minutes)> <reason>");
  67. if(!IsPlayerConnected(ban_target)) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: Player was not found!");
  68. if(ban_time < 0) SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: Please input a valid ban time!");
  69.  
  70. format(post_string, sizeof(post_string), "action=addban&apikey="#APIKEY"&ban_user=%s&ban_reason=%s&ban_admin=%s&ban_ip=%s&ban_time=%d",names[ban_target], ban_reason, names[playerid], ips[ban_target], ban_time);
  71.  
  72. HTTP(playerid, HTTP_POST, APIPATH, post_string, "OnBanResponse");
  73.  
  74. Kick(ban_target);
  75. return 1;
  76. }
  77.  
  78. COMMAND:unbanbyip(playerid, params[])
  79. {
  80. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: You need to be logged in as an RCON administrator to perform this!");
  81. if(isnull(params) || strlen(params) > MAX_PLAYER_IP) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: Correct usage -> /unbanbyip <ip address>");
  82.  
  83. format(post_string, sizeof(post_string), "action=remip&apikey="#APIKEY"&ban_ip=%s", params);
  84.  
  85. HTTP(playerid, HTTP_POST, APIPATH, post_string, "OnRemoveResponse");
  86. return 1;
  87. }
  88.  
  89. COMMAND:unbanbyname(playerid, params[])
  90. {
  91. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: You need to be logged in as an RCON administrator to perform this!");
  92. if(isnull(params) || strlen(params) > MAX_PLAYER_NAME) return SendClientMessage(playerid, COLOR_RED, "[SAMP-BANS]: Correct usage -> /unbanbyname <name>");
  93.  
  94. format(post_string, sizeof(post_string), "action=remname&apikey="#APIKEY"&ban_name=%s&expired=true", params);
  95.  
  96. HTTP(playerid, HTTP_POST, APIPATH, post_string, "OnRemoveResponse");
  97. return 1;
  98. }
  99.  
  100. public OnBanResponse(index, response_code, data[])
  101. {
  102. if(response_code == 200)
  103. if(strcmp(data, "Success?Ban added", true)) printf("[SAMP-BANS]: Error, API responded with: %s", data);
  104. else SendClientMessage(index, 0xFFFFFF, "The ban was added");
  105. else printf("[SAMP-BANS]: Encountered an error, the page didn't respond");
  106. }
  107.  
  108. public OnRemoveResponse(index, response_code, data[])
  109. {
  110. if(response_code == 200)
  111. {
  112. if(sscanf(data, "p?ss", error, code)) printf("[SAMP-BANS]: Error, API responded with: %s", data);
  113. else if(strcmp(error, "Success", true) == 0) SendClientMessage(index, COLOR_RED, code);
  114. }
  115. else printf("[SAMP-BANS]: Encountered an error, the page didn't respond");
  116. }
  117.  
  118. public OnCheckResponse(index, response_code, data[])
  119. {
  120. if(response_code == 200)
  121. {
  122. if(sscanf(data, "p?ss", error, code)) printf("[SAMP-BANS]: Error, API responded with: %s", data);
  123. else if(strcmp(error, "Success", true) == 0)
  124. {
  125. SendClientMessage(index, 0xFFFFFF, code);
  126. Kick(index);
  127. printf("[SAMP-BANS]: %s", code);
  128. }
  129. else if(strcmp(code, "Ban not found")) printf("[SAMP-BANS]: Error, API responded with: %s", code);
  130. }
  131. else printf("[SAMP-BANS]: Encountered an error, the page didn't respond");
  132. }
  133.  
  134. stock sscanf(string[], format[], {Float,_}:...)
  135. {
  136. #if defined isnull
  137. if (isnull(string))
  138. #else
  139. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  140. #endif
  141. {
  142. return format[0];
  143. }
  144. #pragma tabsize 4
  145. new
  146. formatPos = 0,
  147. stringPos = 0,
  148. paramPos = 2,
  149. paramCount = numargs(),
  150. delim = ' ';
  151. while (string[stringPos] && string[stringPos] <= ' ')
  152. {
  153. stringPos++;
  154. }
  155. while (paramPos < paramCount && string[stringPos])
  156. {
  157. switch (format[formatPos++])
  158. {
  159. case '\0':
  160. {
  161. return 0;
  162. }
  163. case 'i', 'd':
  164. {
  165. new
  166. neg = 1,
  167. num = 0,
  168. ch = string[stringPos];
  169. if (ch == '-')
  170. {
  171. neg = -1;
  172. ch = string[++stringPos];
  173. }
  174. do
  175. {
  176. stringPos++;
  177. if ('0' <= ch <= '9')
  178. {
  179. num = (num * 10) + (ch - '0');
  180. }
  181. else
  182. {
  183. return -1;
  184. }
  185. }
  186. while ((ch = string[stringPos]) > ' ' && ch != delim);
  187. setarg(paramPos, 0, num * neg);
  188. }
  189. case 'h', 'x':
  190. {
  191. new
  192. num = 0,
  193. ch = string[stringPos];
  194. do
  195. {
  196. stringPos++;
  197. switch (ch)
  198. {
  199. case 'x', 'X':
  200. {
  201. num = 0;
  202. continue;
  203. }
  204. case '0' .. '9':
  205. {
  206. num = (num << 4) | (ch - '0');
  207. }
  208. case 'a' .. 'f':
  209. {
  210. num = (num << 4) | (ch - ('a' - 10));
  211. }
  212. case 'A' .. 'F':
  213. {
  214. num = (num << 4) | (ch - ('A' - 10));
  215. }
  216. default:
  217. {
  218. return -1;
  219. }
  220. }
  221. }
  222. while ((ch = string[stringPos]) > ' ' && ch != delim);
  223. setarg(paramPos, 0, num);
  224. }
  225. case 'c':
  226. {
  227. setarg(paramPos, 0, string[stringPos++]);
  228. }
  229. case 'f':
  230. {
  231.  
  232. new changestr[16], changepos = 0, strpos = stringPos;
  233. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  234. {
  235. changestr[changepos++] = string[strpos++];
  236. }
  237. changestr[changepos] = '\0';
  238. setarg(paramPos,0,_:floatstr(changestr));
  239. }
  240. case 'p':
  241. {
  242. delim = format[formatPos++];
  243. continue;
  244. }
  245. case '\'':
  246. {
  247. new
  248. end = formatPos - 1,
  249. ch;
  250. while ((ch = format[++end]) && ch != '\'') {}
  251. if (!ch)
  252. {
  253. return -1;
  254. }
  255. format[end] = '\0';
  256. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  257. {
  258. if (format[end + 1])
  259. {
  260. return -1;
  261. }
  262. return 0;
  263. }
  264. format[end] = '\'';
  265. stringPos = ch + (end - formatPos);
  266. formatPos = end + 1;
  267. }
  268. case 'u':
  269. {
  270. new
  271. end = stringPos - 1,
  272. id = 0,
  273. bool:num = true,
  274. ch;
  275. while ((ch = string[++end]) && ch != delim)
  276. {
  277. if (num)
  278. {
  279. if ('0' <= ch <= '9')
  280. {
  281. id = (id * 10) + (ch - '0');
  282. }
  283. else
  284. {
  285. num = false;
  286. }
  287. }
  288. }
  289. if (num && IsPlayerConnected(id))
  290. {
  291. setarg(paramPos, 0, id);
  292. }
  293. else
  294. {
  295. #if !defined foreach
  296. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  297. #define __SSCANF_FOREACH__
  298. #endif
  299. string[end] = '\0';
  300. num = false;
  301. new
  302. name[MAX_PLAYER_NAME];
  303. id = end - stringPos;
  304. foreach (Player, playerid)
  305. {
  306. GetPlayerName(playerid, name, sizeof (name));
  307. if (!strcmp(name, string[stringPos], true, id))
  308. {
  309. setarg(paramPos, 0, playerid);
  310. num = true;
  311. break;
  312. }
  313. }
  314. if (!num)
  315. {
  316. setarg(paramPos, 0, INVALID_PLAYER_ID);
  317. }
  318. string[end] = ch;
  319. #if defined __SSCANF_FOREACH__
  320. #undef foreach
  321. #undef __SSCANF_FOREACH__
  322. #endif
  323. }
  324. stringPos = end;
  325. }
  326. case 's', 'z':
  327. {
  328. new
  329. i = 0,
  330. ch;
  331. if (format[formatPos])
  332. {
  333. while ((ch = string[stringPos++]) && ch != delim)
  334. {
  335. setarg(paramPos, i++, ch);
  336. }
  337. if (!i)
  338. {
  339. return -1;
  340. }
  341. }
  342. else
  343. {
  344. while ((ch = string[stringPos++]))
  345. {
  346. setarg(paramPos, i++, ch);
  347. }
  348. }
  349. stringPos--;
  350. setarg(paramPos, i, '\0');
  351. }
  352. default:
  353. {
  354. continue;
  355. }
  356. }
  357. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  358. {
  359. stringPos++;
  360. }
  361. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  362. {
  363. stringPos++;
  364. }
  365. paramPos++;
  366. }
  367. do
  368. {
  369. if ((delim = format[formatPos++]) > ' ')
  370. {
  371. if (delim == '\'')
  372. {
  373. while ((delim = format[formatPos++]) && delim != '\'') {}
  374. }
  375. else if (delim != 'z')
  376. {
  377. return delim;
  378. }
  379. }
  380. }
  381. while (delim > ' ');
  382. return 0;
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement