fiki574_CRO

fban.inc (v1.1) (NEW!)

Aug 7th, 2013
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.26 KB | None | 0 0
  1. #if defined _fban_included
  2.     #endinput
  3. #endif
  4. #define _fban_included
  5.  
  6. //include SAMP file include (Credits: SAMP team)
  7. #include <a_samp>
  8. //include Blazing User Database (Credits: Slice)
  9. #include <bud>
  10. //include string file include (Credits: Pawno creators)
  11. #include <string>
  12.  
  13. /*fban.inc functions:
  14. native InitBanDatabase(dbname[]);
  15. native TimeBan(playerid, reason[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
  16. native TimeBanEx(name[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
  17. native IsPlayerBanned(playerid);
  18. native IsPlayerBannedEx(name[]);
  19. native GetPlayerBanTime(playerid, &year, &month, &day, &hour, &min, &sec);
  20. native GetPlayerBanTimeEx(name[], &year, &month, &day, &hour, &min, &sec);
  21. native UnbanPlayer(playerid);
  22. native UnbanPlayerEx(name[]);
  23. */
  24.  
  25. //permanent ban, just like from "samp.ban" file
  26. #define BAN_TYPE_PERMANENT      (1)
  27. //normal, temporar ban
  28. #define BAN_TYPE_TEMP_NORMAL    (2)
  29.  
  30. stock InitBanDatabase(dbname[])
  31. {
  32.     //initialize our database
  33.     BUD::Setting(opt.Database, dbname);
  34.     BUD::Setting(opt.Asynchronous, true);
  35.     BUD::Setting(opt.KeepAliveTime, 3000);
  36.     BUD::Setting(opt.CheckForUpdates, true);
  37.     BUD::Initialize();
  38.     BUD::VerifyColumn("name", BUD::TYPE_STRING);
  39.     BUD::VerifyColumn("bantype", BUD::TYPE_NUMBER);
  40.     BUD::VerifyColumn("expiryyear", BUD::TYPE_NUMBER);
  41.     BUD::VerifyColumn("expirymonth", BUD::TYPE_NUMBER);
  42.     BUD::VerifyColumn("expiryday", BUD::TYPE_NUMBER);
  43.     BUD::VerifyColumn("expiryhour", BUD::TYPE_NUMBER);
  44.     BUD::VerifyColumn("expirymin", BUD::TYPE_NUMBER);
  45.     BUD::VerifyColumn("expirysec", BUD::TYPE_NUMBER);
  46.     BUD::VerifyColumn("ip", BUD::TYPE_STRING);
  47.     BUD::VerifyColumn("isipbanned", BUD::TYPE_NUMBER);
  48. }
  49.  
  50. stock TimeBan(playerid, reason[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0)
  51. {
  52.     //declare our time variables
  53.     new hour,
  54.         min,
  55.         sec;
  56.  
  57.     //declare our date variables
  58.     new year,
  59.             month,
  60.         day;
  61.  
  62.     //declare new time variables used for calculating
  63.     new newhour,
  64.         newmin,
  65.         newsec;
  66.  
  67.     //declare new date variable used for calculating
  68.     new newyear,
  69.         newmonth,
  70.             newday;
  71.  
  72.     //get current time and date
  73.     gettime(hour, min, sec);
  74.     getdate(year, month, day);
  75.    
  76.     //assign values to our new variables
  77.     newday = day;
  78.     newmonth = month;
  79.     newyear = year;
  80.    
  81.     //calculate seconds
  82.     newsec = sec + seconds;
  83.  
  84.     //calculate minutes
  85.     newmin = min + minutes;
  86.  
  87.     //calculate hours
  88.     newhour = hour + hours;
  89.    
  90.     //is there maybe a new minute calculated? if yes, increase minutes ammount
  91.     if(newsec >= 60)
  92.     {
  93.         //calculate seconds and minutes
  94.         do
  95.         {
  96.             newmin++;
  97.             newsec = newsec - 60;
  98.         }
  99.         //check if seconds exceed the value of 60
  100.         while(newsec >= 60);
  101.     }
  102.    
  103.     //check for hour switch if there's more than 60 minutes
  104.     if(newmin >= 60)
  105.     {
  106.         //calculate minutes and hours
  107.         do
  108.         {
  109.             newhour++;
  110.             newmin = newmin - 60;
  111.         }
  112.         //check if minutes exceed the value of 60
  113.         while(newmin >= 60);
  114.     }
  115.    
  116.     //new day calculation if hours larger than 24
  117.     if(newhour >= 24)
  118.     {
  119.         //calculate hours and days
  120.         do
  121.         {
  122.             newday++;
  123.             newhour = newhour - 24;
  124.         }
  125.         //check if hours exceed the value of 24
  126.         while(newhour >= 24);
  127.     }
  128.    
  129.     //calculate new month (months with 31 days)
  130.     if(month == 1 && newday > 31 || month == 3 && newday > 31 || month == 5 && newday > 31 || month == 7 && newday > 31 || month == 9 && newday > 31 || month == 11 && newday > 31)
  131.     {
  132.         newmonth++;
  133.         newday = newday - 31;
  134.     }
  135.  
  136.     //calculate new month (months with 30 days)
  137.     if(month == 2 && newday > 30 || month == 4 && newday > 30 || month == 6 && newday > 30 || month == 8 && newday > 30 || month == 10 && newday > 30 || month == 12 && newday > 30)
  138.     {
  139.         newmonth++;
  140.         newday = newday - 30;
  141.     }
  142.    
  143.     //calculate if there's any changes to year
  144.     if(newmonth > 12)
  145.     {
  146.         newyear++;
  147.         newmonth = newmonth - 12;
  148.     }
  149.    
  150.     //get player's name
  151.     new name[MAX_PLAYER_NAME];
  152.     GetPlayerName(playerid, name, sizeof(name));
  153.    
  154.     //declare player IP variable
  155.     new pip[32];
  156.  
  157.     //get player's IP address
  158.     GetPlayerIp(playerid, pip, sizeof(pip));
  159.    
  160.     //register player in bans database
  161.     if(BUD::RegisterName(name, name))
  162.     {
  163.         //different ban types use different DB saving
  164.         switch(bantype)
  165.         {
  166.             //permanent IP ban (just like in "samp.ban" file)
  167.             case BAN_TYPE_PERMANENT:
  168.             {
  169.                 //insert data in table
  170.                 BUD::MultiSet(BUD::GetNameUID(name), "siiiiiiisi", "name", name, "bantype", BAN_TYPE_PERMANENT, "expiryyear", 0, "expirymonth", 0, "expiryday", 0, "expiryhour", 0, "expirymin", 0, "expirysec", 0, "ip", pip, "isipbanned", 1);
  171.                 SendClientMessageToAll(0xFFFFFF, reason);
  172.             }
  173.            
  174.                     //normal, temporar ban that will expire in choosen ammount of time
  175.             case BAN_TYPE_TEMP_NORMAL:
  176.             {
  177.                 //insert data in table
  178.                 BUD::MultiSet(BUD::GetNameUID(name), "siiiiiiisi", "name", name, "bantype", BAN_TYPE_TEMP_NORMAL, "expiryyear", newyear, "expirymonth", newmonth, "expiryday", newday, "expiryhour", newhour, "expirymin", newmin, "expirysec", newsec, "ip", 0, "isipbanned", 1);
  179.                 SendClientMessageToAll(0xFFFFFF, reason);
  180.             }
  181.         }
  182.         Kick(playerid);
  183.     }
  184.     else return 0;
  185.     return 1;
  186. }
  187.  
  188. stock TimeBanEx(name[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0)
  189. {
  190.     //declare our time variables
  191.     new hour,
  192.         min,
  193.         sec;
  194.  
  195.     //declare our date variables
  196.     new year,
  197.             month,
  198.         day;
  199.  
  200.     //declare new time variables used for calculating
  201.     new newhour,
  202.         newmin,
  203.         newsec;
  204.  
  205.     //declare new date variable used for calculating
  206.     new newyear,
  207.         newmonth,
  208.             newday;
  209.  
  210.     //get current time and date
  211.     gettime(hour, min, sec);
  212.     getdate(year, month, day);
  213.    
  214.     //assign values to our new variables
  215.     newday = day;
  216.     newmonth = month;
  217.     newyear = year;
  218.    
  219.     //calculate seconds
  220.     newsec = sec + seconds;
  221.  
  222.     //calculate minutes
  223.     newmin = min + minutes;
  224.  
  225.     //calculate hours
  226.     newhour = hour + hours;
  227.    
  228.     //is there maybe a new minute calculated? if yes, increase minutes ammount
  229.     if(newsec >= 60)
  230.     {
  231.         //calculate seconds and minutes
  232.         do
  233.         {
  234.             newmin++;
  235.             newsec = newsec - 60;
  236.         }
  237.         //check if seconds exceed the value of 60
  238.         while(newsec >= 60);
  239.     }
  240.    
  241.     //check for hour switch if there's more than 60 minutes
  242.     if(newmin >= 60)
  243.     {
  244.         //calculate minutes and hours
  245.         do
  246.         {
  247.             newhour++;
  248.             newmin = newmin - 60;
  249.         }
  250.         //check if minutes exceed the value of 60
  251.         while(newmin >= 60);
  252.     }
  253.    
  254.     //new day calculation if hours larger than 24
  255.     if(newhour >= 24)
  256.     {
  257.         //calculate hours and days
  258.         do
  259.         {
  260.             newday++;
  261.             newhour = newhour - 24;
  262.         }
  263.         //check if hours exceed the value of 24
  264.         while(newhour >= 24);
  265.     }
  266.    
  267.     //calculate new month (months with 31 days)
  268.     if(month == 1 && newday > 31 || month == 3 && newday > 31 || month == 5 && newday > 31 || month == 7 && newday > 31 || month == 9 && newday > 31 || month == 11 && newday > 31)
  269.     {
  270.         newmonth++;
  271.         newday = newday - 31;
  272.     }
  273.  
  274.     //calculate new month (months with 30 days)
  275.     if(month == 2 && newday > 30 || month == 4 && newday > 30 || month == 6 && newday > 30 || month == 8 && newday > 30 || month == 10 && newday > 30 || month == 12 && newday > 30)
  276.     {
  277.         newmonth++;
  278.         newday = newday - 30;
  279.     }
  280.    
  281.     //calculate if there's any changes to year
  282.     if(newmonth > 12)
  283.     {
  284.         newyear++;
  285.         newmonth = newmonth - 12;
  286.     }
  287.    
  288.     //register player in bans database
  289.     if(BUD::RegisterName(name, name))
  290.     {
  291.         //different ban types use different DB saving
  292.         switch(bantype)
  293.         {
  294.             //permanent IP ban (just like in "samp.ban" file)
  295.             case BAN_TYPE_PERMANENT:
  296.             {
  297.                 //insert data in table
  298.                 BUD::MultiSet(BUD::GetNameUID(name), "siiiiiiisi", "name", name, "bantype", BAN_TYPE_PERMANENT, "expiryyear", 0, "expirymonth", 0, "expiryday", 0, "expiryhour", 0, "expirymin", 0, "expirysec", 0, "ip", pip, "isipbanned", 1);
  299.                 SendClientMessageToAll(0xFFFFFF, reason);
  300.             }
  301.            
  302.                     //normal, temporar ban that will expire in choosen ammount of time
  303.             case BAN_TYPE_TEMP_NORMAL:
  304.             {
  305.                 //insert data in table
  306.                 BUD::MultiSet(BUD::GetNameUID(name), "siiiiiiisi", "name", name, "bantype", BAN_TYPE_TEMP_NORMAL, "expiryyear", newyear, "expirymonth", newmonth, "expiryday", newday, "expiryhour", newhour, "expirymin", newmin, "expirysec", newsec, "ip", 0, "isipbanned", 1);
  307.                 SendClientMessageToAll(0xFFFFFF, reason);
  308.             }
  309.         }
  310.     }
  311.     else return 0;
  312.     return 1;
  313. }
  314.  
  315. stock IsPlayerBanned(playerid)
  316. {
  317.     //declare our name variable
  318.     new name[MAX_PLAYER_NAME];
  319.    
  320.     //get player's name
  321.     GetPlayerName(playerid, name, sizeof(name));
  322.    
  323.     //declare a variable for ban type of a player
  324.     new bantype;
  325.    
  326.     //check if player is actually in ban database
  327.     if(BUD::IsNameRegistered(name))
  328.     {
  329.         //get player ban type
  330.         bantype = BUD::GetIntEntry(BUD::GetNameUID(name), "bantype");
  331.        
  332.         //return ban type
  333.         return bantype;
  334.     }
  335.     //player doesnt exist in ban database
  336.     else return 0;
  337. }
  338.  
  339. stock IsPlayerBannedEx(name[])
  340. {
  341.     //declare a variable for ban type of a player
  342.     new bantype;
  343.  
  344.     //check if player is actually in ban database
  345.     if(BUD::IsNameRegistered(name))
  346.     {
  347.         //get player ban type
  348.         bantype = BUD::GetIntEntry(BUD::GetNameUID(name), "bantype");
  349.  
  350.         //return ban type
  351.         return bantype;
  352.     }
  353.     //player doesnt exist in ban database
  354.     else return 0;
  355. }
  356.  
  357. stock GetPlayerBanTime(playerid, &year, &month, &day, &hour, &min, &sec)
  358. {
  359.         //declare our name variable
  360.     new name[MAX_PLAYER_NAME];
  361.  
  362.     //get player's name
  363.     GetPlayerName(playerid, name, sizeof(name));
  364.    
  365.     //declare our date variables
  366.     new getyear,
  367.         getmonth,
  368.         getday;
  369.        
  370.     //declare our time variables
  371.     new gethour,
  372.         getmin,
  373.         getsec;
  374.    
  375.     //check if player is actually in ban database
  376.     if(BUD::IsNameRegistered(name))
  377.     {
  378.         //get remaining ban time
  379.         BUD::MultiGet(BUD::GetNameUID(name), "iiiiii",
  380.                                              "expiryyear", getyear,
  381.                                              "expirymonth", getmonth,
  382.                                              "expiryday", getday,
  383.                                              "expiryhour", gethour,
  384.                                              "expirymin", getmin,
  385.                                              "expirysec", getsec);
  386.  
  387.         //assign to date variables
  388.         year = getyear;
  389.         month = getmonth;
  390.         day = getday;
  391.        
  392.         //assign to time variables
  393.         hour = gethour;
  394.         min = getmin;
  395.         sec = getsec;
  396.        
  397.         //success
  398.         return 1;
  399.     }
  400.     //player doesnt exist in ban database
  401.     else return 0;
  402. }
  403.  
  404. stock GetPlayerBanTimeEx(name[], &year, &month, &day, &hour, &min, &sec)
  405. {
  406.     //declare our date variables
  407.     new getyear,
  408.         getmonth,
  409.         getday;
  410.  
  411.     //declare our time variables
  412.     new gethour,
  413.         getmin,
  414.         getsec;
  415.  
  416.     //check if player is actually in ban database
  417.     if(BUD::IsNameRegistered(name))
  418.     {
  419.         //get remaining ban time
  420.         BUD::MultiGet(BUD::GetNameUID(name), "iiiiii",
  421.                                              "expiryyear", getyear,
  422.                                              "expirymonth", getmonth,
  423.                                              "expiryday", getday,
  424.                                              "expiryhour", gethour,
  425.                                              "expirymin", getmin,
  426.                                              "expirysec", getsec);
  427.  
  428.         //assign to date variables
  429.         year = getyear;
  430.         month = getmonth;
  431.         day = getday;
  432.  
  433.         //assign to time variables
  434.         hour = gethour;
  435.         min = getmin;
  436.         sec = getsec;
  437.  
  438.         //success
  439.         return 1;
  440.     }
  441.     //player doesnt exist in ban database
  442.     else return 0;
  443. }
  444.  
  445. stock UnbanPlayer(playerid)
  446. {
  447.     //declare our name variable
  448.     new name[MAX_PLAYER_NAME];
  449.  
  450.     //get player's name
  451.     GetPlayerName(playerid, name, sizeof(name));
  452.    
  453.     //check if player is actually in ban database
  454.     if(BUD::IsNameRegistered(name))
  455.     {
  456.         //delete player from ban database
  457.         BUD::UnregisterName(name);
  458.  
  459.         //successfully unbanned player
  460.         return 1;
  461.     }
  462.     //fail, player not banned
  463.     else return 0;
  464. }
  465.  
  466. stock UnbanPlayerEx(name[])
  467. {
  468.     //check if player is actually in ban database
  469.     if(BUD::IsNameRegistered(name))
  470.     {
  471.         //delete player from ban database
  472.         BUD::UnregisterName(name);
  473.        
  474.         //successfully unbanned player
  475.         return 1;
  476.     }
  477.     //fail, player not banned
  478.     else return 0;
  479. }
Advertisement
Add Comment
Please, Sign In to add comment