Advertisement
Guest User

Untitled

a guest
Nov 9th, 2011
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #define DIALOG1 1
  4. #define DIALOG2 2
  5.  
  6. #define QCMD:%1(%2) \
  7. forward cmd_%1(%2); \
  8. public cmd_%1(%2)
  9.  
  10. #define SCM(%0,%1) SendClientMessage(%0,-1,%1)
  11. #pragma unused ret_memcpy
  12.  
  13.  
  14. #pragma unused strtok
  15.  
  16.  
  17. stock BanPlayer(playerid,admin[],months,days,hours,reason[])
  18. {
  19. new
  20. dat = gettime()+mktime(hours,0,0,days,months,0),
  21. str[128],
  22. cesta[16+15];
  23. format(str,sizeof(str),"Administrátor {FFFF00}%s{FFFFFF} zabanoval hráče {FFFF00}%s{FFFFFF} do %s ( Duvod:{FF0000} %s )",admin,PlayerName(playerid),date(dat,2),reason);
  24. format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
  25. SendClientMessageToAll(-1,str);
  26. print(str);
  27. dini_Create(cesta);
  28. dini_Set(cesta,"JmenoHrace",PlayerName(playerid));
  29. dini_IntSet(cesta,"Kdy",gettime());
  30. dini_IntSet(cesta,"Dokdy",dat);
  31. dini_Set(cesta,"Admin",admin);
  32. dini_Set(cesta,"Duvod",reason);
  33. Kick(playerid);
  34. }
  35.  
  36. stock PlayerIP(playerid)
  37. {
  38. new ip[16];
  39. GetPlayerIp(playerid,ip,sizeof(ip));
  40. return ip;
  41. }
  42.  
  43. stock PlayerName(playerid)
  44. {
  45. new name[MAX_PLAYER_NAME];
  46. GetPlayerName(playerid,name,sizeof(name));
  47. return name;
  48. }
  49.  
  50. stock IsBanned(playerid)
  51. {
  52. new
  53. cesta[16+15];
  54. format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
  55. if(dini_Exists(cesta))
  56. {
  57. if(dini_Int(cesta,"Dokdy")-gettime() > 0)
  58. {
  59. return 3;
  60. }
  61. else
  62. {
  63. return 2;
  64. }
  65. }
  66. return 1;
  67. }
  68.  
  69. public OnPlayerConnect(playerid)
  70. {
  71. new cesta[16+15];
  72. format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
  73. new strr[270];
  74. if(IsBanned(playerid) == 3)
  75. {
  76. format(strr,sizeof(strr),"{FFFFFF}Jméno hráče: {FF0000}%s\n{FFFFFF}Od kdy: {FF0000}%s\n{FFFFFF}Do kdy: {FF0000}%s\n{FFFFFF}Admin: {FF0000}%s\n{FFFFFF}Duvod: {FF0000}%s",dini_Get(cesta,"JmenoHrace"),date(dini_Int(cesta,"Kdy"),2),date(dini_Int(cesta,"Dokdy"),2),dini_Get(cesta,"Admin"),dini_Get(cesta,"Duvod"));
  77. ShowPlayerDialog(playerid,DIALOG1,DIALOG_STYLE_MSGBOX,"BANNED",strr,"OK","");
  78. Kick(playerid);
  79. }
  80. else if(IsBanned(playerid) == 2)
  81. {
  82. ShowPlayerDialog(playerid,DIALOG2,DIALOG_STYLE_MSGBOX,"UNBANNED","Nyní jsi unbanovaný, doufám, že jsi se poučil","OK","");
  83. dini_Remove(cesta);
  84. }
  85. return true;
  86. }
  87.  
  88. forward OnPlayerCommand(playerid,command[]);
  89.  
  90. public OnPlayerCommand(playerid,command[])
  91. {
  92. new
  93. cmd[50],
  94. params[128],
  95. size = strfind(command, " ", true);
  96. if(size != -1)
  97. {
  98. strmid(params,command,size+1,strlen(command));
  99. strmid(cmd,command,1,size);
  100. }else
  101. {
  102. strmid(cmd,command,1,strlen(command));
  103. params = " ";
  104. }
  105. format(cmd,50,"cmd_%s",cmd);
  106. if(CallLocalFunction(cmd,"is",playerid,params))
  107. {
  108. return true;
  109. }else
  110. {
  111. return SCM(playerid,"Příkaz {FF0000}neexistuje");
  112. }
  113. }
  114.  
  115. public OnPlayerCommandText(playerid,cmdtext[]){
  116.  
  117. return OnPlayerCommand(playerid,cmdtext);
  118. }
  119.  
  120. /*
  121. *
  122. * CMDS
  123. *
  124. * */
  125.  
  126. QCMD:ban(playerid,params[])
  127. {
  128. if(IsPlayerAdmin(playerid))
  129. {
  130. new
  131. id,
  132. mesice,
  133. dny,
  134. hodiny,
  135. duvod[15];
  136.  
  137. if(sscanf(params,"idddz",id,mesice,dny,hodiny,duvod)) return SendClientMessage(playerid,-1,"Použití: /ban [ID] [MESICE] [DNY] [HODINY] [DUVOD]");
  138. else if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Hráe není na serveru");
  139. else if(strlen(duvod) > 15 || strlen(duvod) < 1) return SendClientMessage(playerid,-1,"Moc krátký nebo moc dlouhý duvod");
  140. else
  141. {
  142. BanPlayer(id,PlayerName(playerid),mesice,dny,hodiny,duvod);
  143. }
  144. }
  145. else SendClientMessage(playerid,-1,"Nejsi RCON Admin!");
  146. return 1;
  147. }
  148.  
  149. ///////////////////////////////////////////////
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /*stock mktime(hour,minute,second,day,month,year) {
  167. new timestamp2;
  168.  
  169. timestamp2 = second + (minute * 60) + (hour * 3600);
  170.  
  171. new days_of_month[12];
  172.  
  173. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
  174. days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
  175. } else {
  176. days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
  177. }
  178. new days_this_year = 0;
  179. days_this_year = day;
  180. if(month > 1) { // No January Calculation, because its always the 0 past months
  181. for(new i=0; i<month-1;i++) {
  182. days_this_year += days_of_month[i];
  183. }
  184. }
  185. timestamp2 += days_this_year * 86400;
  186.  
  187. for(new j=1970;j<year;j++) {
  188. timestamp2 += 31536000;
  189. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp2 += 86400; // Schaltjahr + 1 Tag
  190. }
  191.  
  192. return timestamp2;
  193. }*/
  194.  
  195. stock date( timestamp, _form=0 )
  196. {
  197. /*
  198. ~ convert a Timestamp to a Date.
  199. ~ 10.07.2009
  200.  
  201. date( 1247182451 ) will print >> 09.07.2009-23:34:11
  202. date( 1247182451, 1) will print >> 09/07/2009, 23:34:11
  203. date( 1247182451, 2) will print >> July 09, 2009, 23:34:11
  204. date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
  205. */
  206. new year=1970, day=0, month=0, hour=0, mins=0, sec=0;
  207.  
  208. new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  209. new names_of_month[12][10] = {"Leden","Únor","Březen","Duben","Květen","Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"};
  210. new returnstring[32];
  211.  
  212. while(timestamp>31622400){
  213. timestamp -= 31536000;
  214. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
  215. year++;
  216. }
  217.  
  218. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
  219. days_of_month[1] = 29;
  220. else
  221. days_of_month[1] = 28;
  222.  
  223.  
  224. while(timestamp>86400){
  225. timestamp -= 86400, day++;
  226. if(day==days_of_month[month]) day=0, month++;
  227. }
  228.  
  229. while(timestamp>60){
  230. timestamp -= 60, mins++;
  231. if( mins == 60) mins=0, hour++;
  232. }
  233.  
  234. sec=timestamp;
  235.  
  236. switch( _form ){
  237. case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  238. case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, mins, sec);
  239. case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1,names_of_month[month][0],names_of_month[month][1],names_of_month[month][2], year,hour+2,mins);
  240.  
  241. default: format(returnstring, 31, "%02d.%02d.%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  242. }
  243.  
  244. return returnstring;
  245. }
  246.  
  247.  
  248. stock sscanf(string[], format[], {Float,_}:...)
  249. {
  250. #if defined isnull
  251. if (isnull(string))
  252. #else
  253. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  254. #endif
  255. {
  256. return format[0];
  257. }
  258. #pragma tabsize 4
  259. new
  260. formatPos = 0,
  261. stringPos = 0,
  262. paramPos = 2,
  263. paramCount = numargs(),
  264. delim = ' ';
  265. while (string[stringPos] && string[stringPos] <= ' ')
  266. {
  267. stringPos++;
  268. }
  269. while (paramPos < paramCount && string[stringPos])
  270. {
  271. switch (format[formatPos++])
  272. {
  273. case '\0':
  274. {
  275. return 0;
  276. }
  277. case 'i', 'd':
  278. {
  279. new
  280. neg = 1,
  281. num = 0,
  282. ch = string[stringPos];
  283. if (ch == '-')
  284. {
  285. neg = -1;
  286. ch = string[++stringPos];
  287. }
  288. do
  289. {
  290. stringPos++;
  291. if ('0' <= ch <= '9')
  292. {
  293. num = (num * 10) + (ch - '0');
  294. }
  295. else
  296. {
  297. return -1;
  298. }
  299. }
  300. while ((ch = string[stringPos]) > ' ' && ch != delim);
  301. setarg(paramPos, 0, num * neg);
  302. }
  303. case 'h', 'x':
  304. {
  305. new
  306. num = 0,
  307. ch = string[stringPos];
  308. do
  309. {
  310. stringPos++;
  311. switch (ch)
  312. {
  313. case 'x', 'X':
  314. {
  315. num = 0;
  316. continue;
  317. }
  318. case '0' .. '9':
  319. {
  320. num = (num << 4) | (ch - '0');
  321. }
  322. case 'a' .. 'f':
  323. {
  324. num = (num << 4) | (ch - ('a' - 10));
  325. }
  326. case 'A' .. 'F':
  327. {
  328. num = (num << 4) | (ch - ('A' - 10));
  329. }
  330. default:
  331. {
  332. return -1;
  333. }
  334. }
  335. }
  336. while ((ch = string[stringPos]) > ' ' && ch != delim);
  337. setarg(paramPos, 0, num);
  338. }
  339. case 'c':
  340. {
  341. setarg(paramPos, 0, string[stringPos++]);
  342. }
  343. case 'f':
  344. {
  345.  
  346. new changestr[16], changepos = 0, strpos = stringPos;
  347. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  348. {
  349. changestr[changepos++] = string[strpos++];
  350. }
  351. changestr[changepos] = '\0';
  352. setarg(paramPos,0,_:floatstr(changestr));
  353. }
  354. case 'p':
  355. {
  356. delim = format[formatPos++];
  357. continue;
  358. }
  359. case '\'':
  360. {
  361. new
  362. end = formatPos - 1,
  363. ch;
  364. while ((ch = format[++end]) && ch != '\'') {}
  365. if (!ch)
  366. {
  367. return -1;
  368. }
  369. format[end] = '\0';
  370. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  371. {
  372. if (format[end + 1])
  373. {
  374. return -1;
  375. }
  376. return 0;
  377. }
  378. format[end] = '\'';
  379. stringPos = ch + (end - formatPos);
  380. formatPos = end + 1;
  381. }
  382. case 'u':
  383. {
  384. new
  385. end = stringPos - 1,
  386. id = 0,
  387. bool:num = true,
  388. ch;
  389. while ((ch = string[++end]) && ch != delim)
  390. {
  391. if (num)
  392. {
  393. if ('0' <= ch <= '9')
  394. {
  395. id = (id * 10) + (ch - '0');
  396. }
  397. else
  398. {
  399. num = false;
  400. }
  401. }
  402. }
  403. if (num && IsPlayerConnected(id))
  404. {
  405. setarg(paramPos, 0, id);
  406. }
  407. else
  408. {
  409. #if !defined foreach
  410. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  411. #define __SSCANF_FOREACH__
  412. #endif
  413. string[end] = '\0';
  414. num = false;
  415. new
  416. name[MAX_PLAYER_NAME];
  417. id = end - stringPos;
  418. foreach (Player, playerid)
  419. {
  420. GetPlayerName(playerid, name, sizeof (name));
  421. if (!strcmp(name, string[stringPos], true, id))
  422. {
  423. setarg(paramPos, 0, playerid);
  424. num = true;
  425. break;
  426. }
  427. }
  428. if (!num)
  429. {
  430. setarg(paramPos, 0, INVALID_PLAYER_ID);
  431. }
  432. string[end] = ch;
  433. #if defined __SSCANF_FOREACH__
  434. #undef foreach
  435. #undef __SSCANF_FOREACH__
  436. #endif
  437. }
  438. stringPos = end;
  439. }
  440. case 's', 'z':
  441. {
  442. new
  443. i = 0,
  444. ch;
  445. if (format[formatPos])
  446. {
  447. while ((ch = string[stringPos++]) && ch != delim)
  448. {
  449. setarg(paramPos, i++, ch);
  450. }
  451. if (!i)
  452. {
  453. return -1;
  454. }
  455. }
  456. else
  457. {
  458. while ((ch = string[stringPos++]))
  459. {
  460. setarg(paramPos, i++, ch);
  461. }
  462. }
  463. stringPos--;
  464. setarg(paramPos, i, '\0');
  465. }
  466. default:
  467. {
  468. continue;
  469. }
  470. }
  471. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  472. {
  473. stringPos++;
  474. }
  475. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  476. {
  477. stringPos++;
  478. }
  479. paramPos++;
  480. }
  481. do
  482. {
  483. if ((delim = format[formatPos++]) > ' ')
  484. {
  485. if (delim == '\'')
  486. {
  487. while ((delim = format[formatPos++]) && delim != '\'') {}
  488. }
  489. else if (delim != 'z')
  490. {
  491. return delim;
  492. }
  493. }
  494. }
  495. while (delim > ' ');
  496. return 0;
  497. }
  498.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement