Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.15 KB | None | 0 0
  1. /* FoxBan: Time Ban System
  2. By FoxHound */
  3.  
  4. //------< INCLUDEs >------//
  5.     #include <a_samp>
  6. //------------------------//
  7.  
  8. //-------------< DEFINEs >--------------//
  9.     #define FB_foxBanFile "FoxBan/%s.fxban"
  10.     #define MAX_STRING 255
  11. //--------------------------------------//
  12.  
  13. //---------------< FORWARDs >---------------//
  14.     forward FB_OnPlayerConnect(playerid);
  15. //------------------------------------------//
  16.  
  17. //-------< NEWs >-------//
  18.     new FB_tbDir[64];
  19. //----------------------//
  20.  
  21. //----------------------------------------------------------< OnPlayerConnect >-----------------------------------------------------------//
  22.     public FB_OnPlayerConnect(playerid)
  23.     {
  24.         new pName[MAX_PLAYER_NAME];
  25.         GetPlayerName(playerid,pName,sizeof(pName));
  26.         format(FB_tbDir,sizeof(FB_tbDir),FB_foxBanFile,pName);
  27.         if(FB_dini_Exists(FB_tbDir))
  28.         {
  29.             if(FB_dini_Int(FB_tbDir,"fbFB_Time")+FB_dini_Int(FB_tbDir,"fbDuration") > FB_Time())
  30.             {
  31.                 new string[96];
  32.                 new sekki=(FB_dini_Int(FB_tbDir,"fbFB_Time")+FB_dini_Int(FB_tbDir,"fbDuration"))-FB_Time(),minni=sekki/60;
  33.                 sekki=sekki-minni*60;
  34.                 format(string,sizeof(string),"You are timebanned from this server. Remaining time: %d minutes %d seconds",minni,sekki);
  35.                 SendClientMessage(playerid,0xADC7E7FF,string);
  36.                 Kick(playerid);
  37.             } else { FB_dini_Remove(FB_tbDir); }
  38.         }
  39.         return 1;
  40.     }
  41. //----------------------------------------------------------------------------------------------------------------------------------------//
  42.  
  43. //------------------------< TBAN >------------------------//
  44.     forward TBan(pID,bFB_Time);
  45.     public TBan(pID,bFB_Time)
  46.     {
  47.         new pName[MAX_PLAYER_NAME],string[64];
  48.         GetPlayerName(pID,pName,sizeof(pName));
  49.         format(string,sizeof(string),FB_foxBanFile,pName);
  50.         FB_dini_Create(string);
  51.         FB_dini_IntSet(string,"fbFB_Time",FB_Time());
  52.         FB_dini_IntSet(string,"fbDuration",bFB_Time*60);
  53.         Kick(pID);
  54.     }
  55. //--------------------------------------------------------//
  56.  
  57. //---------------------------< TUNBAN >---------------------------//
  58.     forward TUnban(playername[]);
  59.     public TUnban(playername[])
  60.     {
  61.         format(FB_tbDir,sizeof(FB_tbDir),FB_foxBanFile,playername);
  62.         if(FB_dini_Exists(FB_tbDir)) {
  63.             FB_dini_Remove(FB_tbDir); return true; }
  64.         return false;
  65.     }
  66. //----------------------------------------------------------------//
  67.  
  68. //---------------------------------------------< TUNBAN >---------------------------------------------//
  69.     stock GetPlayerBanFB_Time(playername[],&minu=0,&seco=0)
  70.     {
  71.         format(FB_tbDir,sizeof(FB_tbDir),FB_foxBanFile,playername);
  72.         if(FB_dini_Exists(FB_tbDir))
  73.         {
  74.             seco=(FB_dini_Int(FB_tbDir,"fbFB_Time")+FB_dini_Int(FB_tbDir,"fbDuration"))-FB_Time();
  75.             seco=seco-minu*60;
  76.             minu=seco/60;
  77.         }
  78.     }
  79. //----------------------------------------------------------------------------------------------------//
  80.  
  81. //------------------------< BanFileExist >------------------------//
  82.     forward BanFileExist(playername[]);
  83.     public BanFileExist(playername[])
  84.     {
  85.         format(FB_tbDir,sizeof(FB_tbDir),FB_foxBanFile,playername);
  86.         if(FB_dini_Exists(FB_tbDir)) { return 1; } else { return 0; }
  87.     }
  88. //----------------------------------------------------------------//
  89.  
  90. //////////////////////////////////////////// INTEGRATED DINI.inc & DUTILS.inc (THX DRACOBLUE) ////////////////////////////////////////////////
  91. stock FB_mktime(hour,minute,second,day,month,year) {
  92.     new timestamp2; timestamp2 = second + (minute * 60) + (hour * 3600); new days_of_month[12]; if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) { days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; } else { days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; }
  93.     new days_this_year = 0; days_this_year = day; if(month > 1) {  for(new i=0; i<month-1;i++) { days_this_year += days_of_month[i]; }
  94.     } timestamp2 += days_this_year * 86400; for(new j=1970;j<year;j++) { timestamp2 += 31536000; if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; }
  95.     return timestamp2; }
  96. stock FB_Time() { new fxban_int_hour,fxban_int_minute,fxban_int_second,fxban_int_year,fxban_int_month,fxban_int_day; gettime(fxban_int_hour, fxban_int_minute, fxban_int_second); getdate(fxban_int_year, fxban_int_month, fxban_int_day); return FB_mktime(fxban_int_hour,fxban_int_minute,fxban_int_second,fxban_int_day,fxban_int_month,fxban_int_year); }
  97. stock FB_fcopytextfile(oldname[],newname[]) {
  98.     new File:ohnd,File:nhnd; if (!fexist(oldname)) return false; ohnd=fopen(oldname,io_read); nhnd=fopen(newname,io_write); new tmpres[MAX_STRING]; while (fread(ohnd,tmpres)) {
  99.         FB_StripNewLine(tmpres); format(tmpres,sizeof(tmpres),"%s\r\n",tmpres); fwrite(nhnd,tmpres); }
  100.     fclose(ohnd); fclose(nhnd); return true; }
  101. stock FB_equal(str1[],str2[],bool:ignorecase) { if (strlen(str1)!=strlen(str2)) return false; if (strcmp(str1,str2,ignorecase)==0) return true; return false; }
  102. stock FB_ret_memcpy(source[],index=0,numbytes) {
  103.     new tmp[MAX_STRING],i=0; tmp[0]=0; if (index>=strlen(source)) return tmp; if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index; if (numbytes<=0) return tmp; for (i=index;i<numbytes+index;i++) {
  104.         tmp[i-index]=source[i]; if (source[i]==0) return tmp; }
  105.     tmp[numbytes]=0; return tmp; }
  106. stock FB_strlower(txt[]) {
  107.     new tmp[MAX_STRING]; tmp[0]=0; if (txt[0]==0) return tmp; new i=0; for (i=0;i<strlen(txt);i++) {
  108.         tmp[i]=tolower(txt[i]); }
  109.     tmp[strlen(txt)]=0; return tmp; }
  110. stock FB_StripNewLine(string[]) { new len = strlen(string); if (string[0]==0) return ; if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) { string[len - 1] = 0; if (string[0]==0) return ; if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0; } }
  111. stock FB_set(dest[],source[]) {
  112.     new count = strlen(source),i=0; for (i=0;i<count;i++) {
  113.         dest[i]=source[i]; }
  114.     dest[count]=0; }
  115. stock FB_dini_Exists(filename[]) { if (fexist(filename)) return true; return false; }
  116. stock FB_dini_Remove(filename[]) { if (!fexist(filename)) return false; fremove(filename); return true; }
  117. stock FB_dini_Create(filename[]) { new File:fhnd; if (fexist(filename)) return false; fhnd=fopen(filename,io_write); fclose(fhnd); return true; }
  118. stock FB_dini_IntSet(filename[],key[],value) { new valuestring[MAX_STRING]; format(valuestring,sizeof(valuestring),"%d",value); return FB_dini_Set(filename,key,valuestring); }
  119. stock FB_dini_Int(filename[],key[]) { return strval(FB_dini_Get(filename,key)); }
  120. stock FB_dini_Set(filename[],key[],value[]) {
  121.     new File:fohnd, File:fwhnd; new bool:wasset=false; new tmpres[MAX_STRING]; if (key[0]==0) return false; format(tmpres,sizeof(tmpres),"%s.part",filename); fohnd=fopen(filename,io_read); if (!fohnd) return false; fremove(tmpres); fwhnd=fopen(tmpres,io_write); while (fread(fohnd,tmpres)) {
  122.         FB_StripNewLine(tmpres); if ((!wasset)&&(FB_equal(FB_dini_PRIVATE_ExtractKey(tmpres),key,true))) { format(tmpres,sizeof(tmpres),"%s=%s",key,value); wasset=true; }
  123.         fwrite(fwhnd,tmpres); fwrite(fwhnd,"\r\n"); }
  124.     if (!wasset) { format(tmpres,sizeof(tmpres),"%s=%s",key,value); fwrite(fwhnd,tmpres); fwrite(fwhnd,"\r\n"); }
  125.     fclose(fohnd); fclose(fwhnd); format(tmpres,sizeof(tmpres),"%s.part",filename); if (FB_fcopytextfile(tmpres,filename)) { return fremove(tmpres); }
  126.     return false; }
  127. stock FB_dini_Get(filename[],key[]) {
  128.     new File:fohnd,tmpres[MAX_STRING],tmpres2[MAX_STRING]; tmpres[0]=0; fohnd=fopen(filename,io_read); if (!fohnd) return tmpres; while (fread(fohnd,tmpres)) {
  129.         FB_StripNewLine(tmpres); if(FB_equal(FB_dini_PRIVATE_ExtractKey(tmpres),key,true)) { tmpres2[0]=0; strcat(tmpres2,FB_dini_PRIVATE_ExtractValue(tmpres)); fclose(fohnd); return tmpres2; } }
  130.     fclose(fohnd); return tmpres; }
  131. stock FB_dini_PRIVATE_ExtractKey(line[]) { new tmp[MAX_STRING]; tmp[0]=0; if (strfind(line,"=",true)==-1) return tmp; FB_set(tmp,FB_strlower(FB_ret_memcpy(line,0,strfind(line,"=",true)))); return tmp; }
  132. stock FB_dini_PRIVATE_ExtractValue(line[]) {
  133.     new tmp[MAX_STRING]; tmp[0]=0; if (strfind(line,"=",true)==-1) { return tmp; }
  134.     FB_set(tmp,FB_ret_memcpy(line,strfind(line,"=",true)+1,strlen(line))); return tmp; }
  135. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  136.    
  137. #define OnPlayerConnect FB_OnPlayerConnect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement