FoxHound

foXban v2

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