[Include] fban.inc -> Easily ban players for certain amount of time
#1

fban.inc v1.1

Updated on 12.8.2013 | 15:30
INTRODUCTION:
Hello. After long time of inactivity and un-wilingness + lack of interest, I eventually decided to release this neat include. With this include, you can either ban player temporarily or permanently, depending on you. I'm gonna explain each function from include, and what it does. As a side note - I haven't made ban checking, that's what you have to do on your own (under OnPlayerConnect, for example).

__________________________________________________ __________________________________________________

FUNCTIONS:
pawn Код:
native InitBanDatabase(dbname[]);
native TimeBan(playerid, reason[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
native TimeBanEx(name[], bantype = BAN_TYPE_PERMANENT, hours = 0, minutes = 0, seconds = 0);
native IsPlayerBanned(playerid);
native IsPlayerBannedEx(name[]);
native GetPlayerBanTime(playerid, &year, &month, &day, &hour, &min, &sec);
native GetPlayerBanTimeEx(name[], &year, &month, &day, &hour, &min, &sec);
native UnbanPlayer(playerid);
native UnbanPlayerEx(name[]);
__________________________________________________ _______________________________________________

CHANGELOG:

Version 1.1:
  • Added "reason[]" parameter in "TimeBan" function
  • Added "TimeBanEx" function
Version 1.0:
  • Initial release
__________________________________________________ _______________________________________________

EXPLANATION:

First, also pretty much most important function, is "InitBanDatabase". Since this include uses another include named "BUD" made by Slice (look down for link to original thread), you have to specify your database name. Example:
pawn Код:
public OnFilterScriptInit()
{
    InitBanDatabase("bans.db");
    return 1;
}
This function will create "bans.db" database in "scriptfiles" folder which is later used in pretty much whole ban system.


"TimeBan" function is the actual ban function. There are few ways you can use it as there are also optional parameters in there. Example:
pawn Код:
COMMAND:timeban(playerid,params[])
{
     new pid, reason[50];
     if(!sscanf(params, "rs[50]",  pid, reason))
     {
          TimeBan(pid, reason, BAN_TYPE_TEMP_NORMAL, 48);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /timeban <playerid> <reason>");
     return 1;
}
This will ban a player for 48 hours / 2 days. However, if you just use first parameter, which is "playerid", it will ban player permanently. Next...


"TimeBanEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter.


"IsPlayerBanned" checks if player exists in ban database. If yes, function returns 1, if not function returns 0. Simple as that.


"IsPlayerBannedEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:isbanned(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          if(IsPlayerBannedEx(name) == 1) SendClientMessage(playerid, -1, "Player is permanently banned.");
          else if(IsPlayerBannedEx(name) == 2) SendClientMessage(playerid, -1, "Player is temporarily banned.");
          else if(IsPlayerBannedEx(name) == 0) SendClientMessage(playerid, -1, "Player is not banned.");
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /isbanned <name>");
     return 1;
}

"GetPlayerBanTime" returns time and date when player will have their ban removed. Though, there's no auto-ban removal, another thing you have to do on your own (again, you can do that under OnPlayerConnect and simply unban player).


"GetPlayerBanTimeEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:checkban(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          new y, mo, d, h, mi, s;
          GetPlayerBanTime(playerid, y, mo, d, h, mi, s);
          new str[100];
          format(str, sizeof(str), "%s's ban expires on: %d.%d.%d | %d:%d:%d", name, d, mo, y, h, mi, s);
          SendClientMessage(playerid, -1, str);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /checkban <name>");
     return 1;
}
Simple, eh?


"UnbanPlayer" function removes player from ban database and allows him to play.


"UnbanPlayerEx" does exactly same thing as non-"ex" function, it just has "name[]" parameter, instead of "playerid" parameter. Example:
pawn Код:
COMMAND:unban(playerid,params[])
{
     new name[32];
     if(!sscanf(params, "s[32]",  name))
     {
          UnbanPlayerEx(name);
          SendClientMessage(playerid, -1, "Player is unbanned.");
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /unban<name>");
     return 1;
}
Also, again a note - all function already have some checks inside themselves, so there's no need to check e.g. if player is in database. Include does it all.

__________________________________________________ _______________________________________________

CREDITS:

fiki574 - creating this include
Slice - BUD (Blazing User Database) (click here)
Zeex - ZCDM command processor used in my examples (click here)

__________________________________________________ _______________________________________________

BUGS:

Haven't found any, though there's I think an exploit. If you type large amount of hours, months and days won't be properly calculated and it may happen that months will have >= 32 days. :O

Also, report if you find any bugs!

__________________________________________________ _______________________________________________

DOWNLOAD:

Pastebin (v1.1) (current, recommended)

No mirrors, please!
__________________________________________________ _______________________________________________

Regards,
Fiki!
Reply


Messages In This Thread
fban.inc -> Easily ban players for certain amount of time - by fiki574 - 07.08.2013, 14:34
Re: fban.inc -> Easily ban players for certain amount of time - by Anak - 07.08.2013, 14:37
Re: fban.inc -> Easily ban players for certain amount of time - by PT - 07.08.2013, 14:45
Re: fban.inc -> Easily ban players for certain amount of time - by SsHady - 07.08.2013, 14:45
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 07.08.2013, 17:18
Re: fban.inc -> Easily ban players for certain amount of time - by Jochemd - 07.08.2013, 17:27
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 07.08.2013, 17:33
Re: fban.inc -> Easily ban players for certain amount of time - by Tamer - 07.08.2013, 17:55
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 07.08.2013, 18:25
Re: fban.inc -> Easily ban players for certain amount of time - by Jochemd - 07.08.2013, 22:13
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 12.08.2013, 13:12
Re: fban.inc -> Easily ban players for certain amount of time - by dEcooR - 12.08.2013, 14:42
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 12.08.2013, 15:24
Re: fban.inc -> Easily ban players for certain amount of time - by Tamer - 12.08.2013, 15:36
Re: fban.inc -> Easily ban players for certain amount of time - by fiki574 - 13.08.2013, 09:03
Re: fban.inc -> Easily ban players for certain amount of time - by xiaoyang - 26.07.2015, 14:01

Forum Jump:


Users browsing this thread: 1 Guest(s)