Advertisement
TYUI

TImeban

Nov 16th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.35 KB | None | 0 0
  1. #include <YSI\y_ini>
  2. #include <YSI\y_commands>
  3. #define HODINA(%0) 3600*%0
  4. #define DIALOG_ID 874
  5. #define BANPATH "Timeban/%s.txt"
  6.  
  7. enum bInfo
  8. {
  9.     bIP,
  10.     bDATE,
  11.     bHODINY,
  12.     bNAME,
  13. }
  14.  
  15. enum pInfo
  16. {
  17.     Admin
  18. }
  19.  
  20. new PlayerBan[MAX_PLAYERS][bInfo];
  21. new PlayerInfo[MAX_PLAYERS][pInfo];
  22.  
  23. forward LoadBan_data(playerid,name[],value[]);
  24. public LoadBan_data(playerid,name[],value[])
  25. {
  26.     INI_Int("Ip",PlayerBan[playerid][bIP]);
  27.     INI_Int("Date",PlayerBan[playerid][bDATE]);
  28.     INI_Int("Hodiny",PlayerBan[playerid][bHODINY]);
  29.     INI_Int("Name",PlayerBan[playerid][bNAME]);
  30.     return 1;
  31. }
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35. if(fexist(BanPath(playerid)))
  36. {
  37.     INI_ParseFile(BanPath(playerid), "LoadBan_%s", .bExtra = true, .extra = playerid);
  38.     new dovod[75],string[128],ip[20];
  39.     GetPlayerIp(playerid,ip,20);
  40.     if(gettime() > strval(string))
  41.     {
  42.         SendClientMessage(playerid,0x0000FFFF,"[TimeBan] {FF0000}Ban ti vypršal, dúfam že si sa poučil");
  43.         fremove(BanPath(playerid));
  44.         }else{
  45.         new strong[100];
  46.         new ban[128];
  47.         strcat(ban,"Tvoj ešte stále nevypršal !\n");
  48.         format(strong, sizeof(strong),"Nick: %s \n", Jmeno(playerid));
  49.         strcat(ban,strong);
  50.         format(strong, sizeof(strong),"IP: %s \n", PlayerBan[playerid][bIP]);
  51.         strcat(ban,strong);
  52.         format(strong, sizeof(strong), "Dôvod: %s \n", dovod);
  53.         strcat(ban,strong);
  54.         format(strong, sizeof(strong), "Admin: %s \n", PlayerInfo[playerid][Admin]);
  55.         strcat(ban,strong);
  56.         format(strong, sizeof(strong), "Kedy: %s \n", date(strval(string)));
  57.         strcat(ban,strong);
  58.         format(strong, sizeof(strong), "Platnosť %s \n", date(strval(string)));
  59.         strcat(ban,strong);
  60.         ShowPlayerDialog(playerid,DIALOG_ID,DIALOG_STYLE_MSGBOX,"{0000FF}TimeBan",ban,"OK","");
  61.         SetTimerEx("KickPublic", 1500, 0, "d", playerid);
  62.     }
  63. }
  64. return 1;
  65. }
  66.  
  67. CMD:ban(playerid, params[], help[])
  68. {
  69.     if(GetPlayerState(playerid) == PLAYER_STATE_WASTED) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Nemôžeš byť vo výbere postáv !");
  70.     new a[3][60],id,hodiny;
  71.     if(UnFormat(params,a,' ',3) != 3) return SendClientMessage(playerid,0x0000FFFF,"[Server]: /ban [id] [hodinky] [dovod]");
  72.     id = strval(a[0]);
  73.     if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Hráč není na servery !");
  74.     if(IsPlayerAdmin(id)) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Nemôžeš zabanovať hlavného admina !");
  75.     new plrIP[64],name[32];
  76.  
  77.     hodiny = strval(a[1]);
  78.     new INI:Fi = INI_Open(BanPath(playerid));
  79.     INI_SetTag(Fi,"BAN Data");
  80.     INI_WriteInt(Fi,"Ip", GetPlayerIp(playerid, plrIP, 64));
  81.     INI_WriteInt(Fi,"Date", gettime());
  82.     INI_WriteInt(Fi,"Hodiny", HODINA(hodiny)+gettime());
  83.     INI_WriteInt(Fi,"Name", GetPlayerName(playerid,name,sizeof(name)));
  84.     INI_WriteString(Fi,"Hrac",a[2]);
  85.     INI_Close(Fi);
  86.  
  87.     new strong[128];
  88.     format(strong, sizeof(strong),"[TimeBan] {FF0000}Admin {FFFFFF}%s{FF0000} dal hráčovy {FFFFFF}%s {FF0000}ban na %d hodín Dôvod: %s",Jmeno(playerid),Jmeno(id),hodiny,a[2]);
  89.     SendClientMessageToAll(-1,strong);
  90.     SetTimerEx("KickPublic", 1500, 0, "d", id);
  91.     return true;
  92. }
  93.  
  94. forward KickPublic(playerid);
  95. public KickPublic(playerid)
  96. {
  97.     Kick(playerid);
  98.     return 1;
  99. }
  100.  
  101. stock BanPath(playerid)
  102. {
  103.     new string[128],playername[MAX_PLAYER_NAME];
  104.     GetPlayerName(playerid,playername,sizeof(playername));
  105.     format(string,sizeof(string),BANPATH,playername);
  106.     return string;
  107. }
  108.  
  109.  
  110. stock Jmeno(playerid)
  111. {
  112.     new n[MAX_PLAYER_NAME];
  113.     GetPlayerName(playerid,n,MAX_PLAYER_NAME);
  114.     return n;
  115. }
  116.  
  117. stock UnFormat(str[],variables[][],cha,m=0)
  118. {
  119.     new len = strlen(str),chcount,i,start,varcount;
  120.     while(i < len+1)
  121.     {
  122.         if(i == len && chcount != 0)
  123.         {
  124.             strmid(variables[varcount],str,start+1,strlen(str),128);
  125.             chcount++;
  126.         }
  127.         if(str[i] == cha)
  128.         {
  129.             if((m == 0) || (chcount != m-1))
  130.             {
  131.                 strmid(variables[varcount],str,start + ((start == 0) ? 0 : 1),i,128);
  132.                 start = i;
  133.                 chcount++;
  134.                 varcount++;
  135.             }
  136.         }
  137.         i++;
  138.     }
  139.     return chcount;
  140. }
  141.  
  142. stock date( timestamp, _form=1 )
  143. {
  144.     new year=1970, day=0, month=0, hour=0, mins=0, sec=0;
  145.     new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  146.     new names_of_month[12][10] = {"Januar","Februar","Marec","April","Maj","Jun","Jul","August","September","Oktober","November","December"};
  147.     new returnstring[32];
  148.     while(timestamp>31622400)
  149.     {
  150.         timestamp -= 31536000;
  151.         if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
  152.         year++;
  153.     }
  154.     if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
  155.     days_of_month[1] = 29;
  156.     else
  157.     days_of_month[1] = 28;
  158.     while(timestamp>86400)
  159.     {
  160.         timestamp -= 86400, day++;
  161.         if(day==days_of_month[month]) day=0, month++;
  162.     }
  163.     while(timestamp>60)
  164.     {
  165.         timestamp -= 60, mins++;
  166.         if( mins == 60) mins=0, hour++;
  167.     }
  168.     sec=timestamp;
  169.     switch( _form )
  170.     {
  171.         case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  172.         case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, mins, sec);
  173.         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,mins);
  174.         default: format(returnstring, 31, "%02d.%02d.%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
  175.     }
  176.     return returnstring;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement