Kaczmi

Untitled

Apr 8th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.13 KB | None | 0 0
  1. /*
  2.  
  3. --- Timeban System
  4. --- by
  5. --- Mort
  6. */
  7.  
  8. #include <a_samp>
  9.  
  10. #define MAX_SIZE_COMMAND 25
  11. #define MAX_SIZE_PARAMS 103
  12.  
  13. #define mCmd:%0(%1,%2) \
  14. forward cmd_%0(%1,%2); \
  15. public cmd_%0(%1,%2)
  16.  
  17. /*
  18. stock UnParams by Mort
  19. Získá parametry funkce a zapíše je do proměnných
  20. */
  21.  
  22. #include <a_samp>
  23. stock UnParams(params[],&id,duvod[35],&roky,&mesice,&dny,&hodiny,&minuty,&sekundy,&bool:perma)
  24. {
  25. // if(!(params[0]) || (params[0] == 1) && (params[1] == 0)) return false;
  26. // if(!(params[1])) return false;
  27.  
  28. new
  29. paraCount = 0,
  30. len = strlen(params) + 1
  31. ;
  32.  
  33. new
  34. ch2,
  35. value2[50],
  36. pos2 = 0
  37. ;
  38. while((ch2 = params[pos2]) && ch2 != ' ')
  39. {
  40. pos2++;
  41. }
  42. strmid(value2,params,0,pos2);
  43. if(IsInt(value2))
  44. {
  45. id = strval(value2);
  46. for(new i = pos2;i<len;i++)
  47. {
  48. if(params[i] == ' ') // params je mezera , další bude nějakej str
  49. {
  50. new
  51. ch,
  52. delim = ' ',
  53. pos = i + 1,
  54. value[50],
  55. bool:stoped = false
  56. ;
  57.  
  58. while((ch = params[pos]) && ch != delim && ch != EOS)
  59. {
  60. if((pos == (i + 1)) && ch == EOS) { stoped = true; break; }
  61. else
  62. {
  63. pos++;
  64. }
  65. }
  66. if(!stoped)
  67. {
  68. paraCount++;
  69. strmid(value,params,i+1,pos);
  70. if(paraCount == 1)
  71. {
  72. if(strlen(value) >= 5 && strlen(value) < 35)
  73. {
  74. perma = true;
  75. format(duvod,35,value);
  76. }
  77. else
  78. {
  79. return false;
  80. }
  81. }
  82. else if(paraCount == 2)
  83. {
  84. if(IsInt(value))
  85. {
  86. perma = false;
  87. roky = strval(value);
  88. }
  89. else
  90. {
  91. return false;
  92. }
  93. }
  94. else if(paraCount == 3)
  95. {
  96. if(IsInt(value))
  97. {
  98. mesice = strval(value);
  99. }
  100. else
  101. {
  102. return false;
  103. }
  104. }
  105. else if(paraCount == 4)
  106. {
  107. if(IsInt(value))
  108. {
  109. dny = strval(value);
  110. }
  111. else
  112. {
  113. return false;
  114. }
  115. }
  116. else if(paraCount == 5)
  117. {
  118. if(IsInt(value))
  119. {
  120. hodiny = strval(value);
  121. }
  122. else
  123. {
  124. return false;
  125. }
  126. }
  127. else if(paraCount == 6)
  128. {
  129. if(IsInt(value))
  130. {
  131. minuty = strval(value);
  132. }
  133. else
  134. {
  135. return false;
  136. }
  137. }
  138. else if(paraCount == 7)
  139. {
  140. if(IsInt(value))
  141. {
  142. sekundy = strval(value);
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. }
  150.  
  151. }
  152. }
  153. }
  154. else { return false; }
  155. return true;
  156. }
  157.  
  158. stock IsInt(string[])
  159. {
  160. new len = strlen(string);
  161. for(new i=0;i<len;i++)
  162. {
  163. if(string[i] >= '0' && string[i] <= '9') { }
  164. else { return false; }
  165. }
  166. return true;
  167. }
  168.  
  169. stock PN(playerid)
  170. {
  171. new name[MAX_PLAYER_NAME];
  172. GetPlayerName(playerid,name,sizeof(name));
  173. return name;
  174. }
  175.  
  176. stock mktime(hour,minute,second,day,month,year) { // fixed by Mort
  177. new timestamp2;
  178.  
  179. timestamp2 = second + (minute * 60) + (hour * 3600);
  180.  
  181. new days_of_month[12];
  182.  
  183. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
  184. days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31};
  185. } else {
  186. days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31};
  187. }
  188. new days_this_year = 0;
  189. days_this_year = day;
  190. if(month > 0) {
  191. for(new i=0; i<month;i++) {
  192. days_this_year += days_of_month[i];
  193. }
  194. }
  195. timestamp2 += days_this_year * 86400;
  196.  
  197. for(new j=0;j<year;j++) {
  198. timestamp2 += 31536000;
  199. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp2 += 86400;
  200. }
  201.  
  202. return timestamp2;
  203. }
  204.  
  205. stock date( timestamp, _form=0 )
  206. {
  207. /*
  208. ~ convert a Timestamp to a Date.
  209. ~ 10.07.2009
  210.  
  211. date( 1247182451 ) will print >> 09.07.2009-23:34:11
  212. date( 1247182451, 1) will print >> 09/07/2009, 23:34:11
  213. date( 1247182451, 2) will print >> July 09, 2009, 23:34:11
  214. date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
  215. */
  216. new year=1970, day=0, month=0, hour=0, mins=0, sec=0;
  217.  
  218. new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  219. new names_of_month[12][10] = {"Leden","Únor","Březen","Duben","Květen","Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"};
  220. new returnstring[32];
  221.  
  222. while(timestamp>31622400){
  223. timestamp -= 31536000;
  224. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
  225. year++;
  226. }
  227.  
  228. if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
  229. days_of_month[1] = 29;
  230. else
  231. days_of_month[1] = 28;
  232.  
  233.  
  234. while(timestamp>86400){
  235. timestamp -= 86400, day++;
  236. if(day==days_of_month[month]) day=0, month++;
  237. }
  238.  
  239. while(timestamp>60){
  240. timestamp -= 60, mins++;
  241. if( mins == 60) mins=0, hour++;
  242. }
  243.  
  244. sec=timestamp;
  245.  
  246. switch( _form ){
  247. case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  248. case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, mins, sec);
  249. 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);
  250.  
  251. default: format(returnstring, 31, "%02d.%02d.%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  252. }
  253.  
  254. return returnstring;
  255. }
  256.  
  257. stock GetIp(playerid)
  258. {
  259. new ip[16];
  260. GetPlayerIp(playerid,ip,sizeof(ip));
  261. return ip;
  262. }
  263.  
  264. stock UnFormat(str[],variables[][],cha,m=0) // by QWER
  265. {
  266. new len = strlen(str),chcount,i,start,varcount;
  267. while(i < len+1)
  268. {
  269. if(i == len && chcount != 0)
  270. {
  271. strmid(variables[varcount],str,start+1,strlen(str),128);
  272. chcount++;
  273. }
  274. if(str[i] == cha)
  275. {
  276. if((m == 0) || (chcount != m-1))
  277. {
  278. strmid(variables[varcount],str,start + ((start == 0) ? 0 : 1),i,128);
  279. start = i;
  280. chcount++;
  281. varcount++;
  282. }
  283. }
  284. i++;
  285. }
  286. return chcount;
  287. }
  288.  
  289. stock fcreate(filename[])
  290. {
  291. if (fexist(filename)){return false;}
  292. new File:fhandle = fopen(filename,io_write);
  293. fclose(fhandle);
  294. return true;
  295. }
  296.  
  297. stock DeleteLineFromLine(file[],linea)// by QWER
  298. {
  299. new File:a = fopen(file,io_read);
  300. new str[128],str2[128];
  301. format(str2,128,"%s.part",file);
  302. new File:b = fopen(str2,io_write);
  303. new lineb = 1;
  304. while(fread(a,str))
  305. {
  306. if(lineb == linea)
  307. {
  308. lineb++;
  309. continue;
  310. }
  311. else
  312. {
  313. fwrite(b,str);
  314. }
  315. lineb++;
  316. }
  317. fclose(a);
  318. fremove(file);
  319. fclose(b);
  320. b = fopen(str2,io_read);
  321. fcreate(file);
  322. a = fopen(file,io_write);
  323. while(fread(b,str))
  324. {
  325. fwrite(a,str);
  326. }
  327. fclose(a);
  328. fclose(b);
  329. fremove(str2);
  330. }
  331.  
  332.  
  333. /*
  334.  
  335. -- Can be used only for TimebanSystem v2 by Mort!!!!
  336.  
  337. */
  338.  
  339. forward OnPlayerCommandTextMCMD(playerid,cmdtext[]);
  340.  
  341. public OnPlayerCommandTextMCMD(playerid,cmdtext[])
  342. {
  343. new
  344. LastPos = 1,
  345. command[MAX_SIZE_COMMAND],
  346. params[MAX_SIZE_PARAMS],
  347. testCommand[MAX_SIZE_COMMAND+5],
  348. ch
  349. ;
  350.  
  351. while((ch = cmdtext[LastPos]) && ch != EOS && ch != ' ')
  352. {
  353. LastPos++;
  354. }
  355. strmid(command,cmdtext,1,LastPos);
  356. format(testCommand,sizeof(testCommand),"cmd_%s",command);
  357. strmid(params,cmdtext,LastPos+1,128);
  358. printf("params=%s",params);
  359. if(!params[0]) format(params,sizeof(params)," ");
  360. if(CallLocalFunction(testCommand,"is",playerid,params))
  361. {
  362. return true;
  363. }
  364. else
  365. {
  366. return SendClientMessage(playerid,-1,"Chybný příkaz");
  367. }
  368. }
  369.  
  370. public OnPlayerCommandText(playerid,cmdtext[])
  371. {
  372. return OnPlayerCommandTextMCMD(playerid,cmdtext);
  373. }
  374.  
  375. public OnPlayerConnect(playerid)
  376. {
  377. new
  378. File:soubor = fopen("bans.txt",io_read),
  379. str[128],
  380. line
  381. ;
  382.  
  383. while((fread(soubor,str)))
  384. {
  385. line++;
  386. new
  387. var[5][35]
  388. ;
  389. UnFormat(str,var,';');
  390. if(strcmp(var[0],GetIp(playerid),true)==0 || strcmp(var[1],PN(playerid),true)==0)
  391. {
  392. if(strval(var[4]) < gettime())
  393. {
  394. SendClientMessage(playerid,-1,"Ban ti vypršel, doufám, že ses poučil");
  395. DeleteLineFromLine("bans.txt",line);
  396. break;
  397. }
  398. else
  399. {
  400. new s[256];
  401. format(s,sizeof(s),"{FF0000}Ban ti ještě nevypršel!!!\n{FFFFFF}Administrátor: {33FF00}%s\n{FFFFFF}Datum banu: {33FF00}%s\n{FFFFFF}Vypršení banu: {33FF00}%s\n{FFFFFF}Důvod: {33FF00}%s",PN(playerid),date(strval(var[3]),3),date(strval(var[4]),3),var[2]);
  402. ShowPlayerDialog(playerid,10001,DIALOG_STYLE_MSGBOX,"Ban",s,"OK","");
  403. Kick(playerid);
  404. break;
  405. }
  406. }
  407. }
  408. fclose(soubor);
  409. return 1;
  410. }
  411.  
  412.  
  413. ////////////////////////////////////////////////////////////////////////////////
  414.  
  415. mCmd:ban(playerid,params[])
  416. {
  417. if(IsPlayerAdmin(playerid))
  418. {
  419. new
  420. id,
  421. duvod[35],
  422. roky,
  423. mesice,
  424. dny,
  425. hodiny,
  426. minuty,
  427. sekundy,
  428. bool:perma
  429. ;
  430.  
  431. if(UnParams(params,id,duvod,roky,mesice,dny,hodiny,minuty,sekundy,perma)) //return SendClientMessage(playerid,-1,"Usage: /ban [ID] [DUVOD] ([ROKY] [MESICE] [DNY] [HODINY] [MINUTY] [SEKUNDY])");
  432. {
  433. if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Zadané ID není na serveru");
  434. if(playerid == id) return SendClientMessage(playerid,-1,"Nemůžeš zabanovat sám sebe!");
  435. if(perma)
  436. {
  437. new s[128];
  438. format(s,sizeof(s),"Administrátor {FFFF00}%s {FF0000}pernamentně{FFFFFF} zabanoval hráče {FFFF00}%s {FFFFFF}(Důvod: {FFFF00}%s{FFFFFF})",PN(playerid),PN(id),duvod);
  439. SendClientMessageToAll(-1,s);
  440. Ban(id);
  441. }
  442. else
  443. {
  444. printf("roky = %d, mesice = %d, dny = %d, hodiny = %d, minuty = %d, sekundy = %d",roky,mesice,dny,hodiny,minuty,sekundy);
  445. new
  446. time = gettime() + mktime(hodiny,minuty,sekundy,dny,mesice,roky),
  447. str[128],
  448. str2[256],
  449. str3[128],
  450. File:soubor = fopen("bans.txt",io_append)
  451. ;
  452. format(str,sizeof(str),"Administrátor {FF0000}%s{FFFFFF} zabanoval hráče {FF0000}%s{FFFFFF} do {FFFF00}%s",PN(playerid),PN(id),date(time,3));
  453. SendClientMessageToAll(-1,str);
  454.  
  455. format(str2,sizeof(str2),"{FF0000}Byl jsi zabanován!!!\n{FFFFFF}Administrátor: {33FF00}%s\n{FFFFFF}Datum banu: {33FF00}%s\n{FFFFFF}Vypršení banu: {33FF00}%s\n{FFFFFF}Důvod: {33FF00}%s",PN(playerid),date(gettime(),3),date(time,3),duvod);
  456. ShowPlayerDialog(playerid,10000,DIALOG_STYLE_MSGBOX,"Ban",str2,"OK","");
  457.  
  458. format(str3,sizeof(str3),"%s;%s;%s;%d;%d\r\n",GetIp(id),PN(id),duvod,gettime(),time);
  459. fwrite(soubor,str3);
  460. fclose(soubor);
  461. Kick(id);
  462. }
  463. }
  464. else return SendClientMessage(playerid,-1,"Usage: /ban [ID] [DUVOD (min.5 znaků)] ([ROKY] [MESICE] [DNY] [HODINY] [MINUTY] [SEKUNDY])");
  465. }
  466. else SendClientMessage(playerid,-1,"Nejsi admin!");
  467. return true;
  468. }
Advertisement
Add Comment
Please, Sign In to add comment