[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
#2

nice, i will test it on my server.
Reply
#3

Good i like!
Reply
#4

Great Job D
Seem's a bit complicated but Nice
+1
Reply
#5

Quote:
Originally Posted by Anak
Посмотреть сообщение
nice, i will test it on my server.
Thanks. Let me know the results

Quote:
Originally Posted by PT
Посмотреть сообщение
Good i like!
Thank you.

Quote:
Originally Posted by SsHady
Посмотреть сообщение
Great Job D
Seem's a bit complicated but Nice
+1
Thanks. It may seem, but math does it's job.


NOTE: Small fix has been made, check out pastebin.
Reply
#6

I have a suggestion: use timestamps. It's way easier and it might even be WAY less work if you use the TimestampToDate include
Reply
#7

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
I have a suggestion: use timestamps. It's way easier and it might even be WAY less work if you use the TimestampToDate include
Well, yes, but I wanted to do it like this, hard way (or is it hard way?).
Reply
#8

Just on time, what can I say? I was planning to do a very complicated ban system with MYSQL databses but with this I don't need it at all.

Thanks a lot, I will integrate my script to this soon.

If possible, make functions to allow us ban players which are not online, so: TimeBanEx([name]...)

Add reason parameter to the ban function. Also please add IP bans.
Reply
#9

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
Just on time, what can I say? I was planning to do a very complicated ban system with MYSQL databses but with this I don't need it at all.

Thanks a lot, I will integrate my script to this soon.

If possible, make functions to allow us ban players which are not online, so: TimeBanEx([name]...)

Add reason parameter to the ban function. Also please add IP bans.
I plan on adding such features in future versions, of course.

And thank you
Reply
#10

Quote:
Originally Posted by fiki574
Посмотреть сообщение
Well, yes, but I wanted to do it like this, hard way (or is it hard way?).
Yeah this is the hard way. Well not hard but it could be easier
Reply
#11

Update!

Please redownload new version 1.1
Reply
#12

nice one
Reply
#13

Quote:
Originally Posted by dEcooR
Посмотреть сообщение
nice one
Thanks
Reply
#14

Thanks for the update.
Reply
#15

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
Thanks for the update.
No problem
Reply
#16

How to write a custom time Ban cmd.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)