07.11.2011, 20:41
(
Последний раз редактировалось Slice; 16.07.2012 в 07:43.
)
Hey,
I've been working on this ban system on and off for a while now, and I think it's reached a stable testing state.
Worth mentioning is IPs are dealt with as integers, not strings. All IPs are tagged with IP:.
Another thing that's probably worth mentioning is it doesn't require any configuration what so ever, and it uses SQLite.
Functions
Macros
Examples
Ban a player
Check if a player is banned
Changes
2011-11-25
http://pastebin.com/R12ZpSjc
I've been working on this ban system on and off for a while now, and I think it's reached a stable testing state.
Worth mentioning is IPs are dealt with as integers, not strings. All IPs are tagged with IP:.
Another thing that's probably worth mentioning is it doesn't require any configuration what so ever, and it uses SQLite.
Functions
GetDotDecimalIP(IP:ip) | Returns a string containing the IP in human-readable format (i.e. 127.0.0.1). | ||||||
IP:GetIntegerIP(ip[]) | Convert a dot-decimal IP string to an integer IP. | ||||||
IP:GetPlayerIP | Returns the integer IP for a player. | ||||||
| Returns true if the IP is within the specified IP range. The 1st argument can be an integer IP or a string. | ||||||
GetDurationFromString(duration[]) | Convert a human-readable duration into seconds. Examples of valid input:
| ||||||
GetStringFromDuration(duration) | Opposite of above (i.e. 9000 => 2 hours 30 minutes). | ||||||
GetUnixTimestamp() | Returns the current UNIX timestamp. | ||||||
|
| ||||||
BanIPRange(IPRange:range, duration = DURATION_PERMANENT) |
| ||||||
BanPlayer(iPlayer, iDuration = DURATION_PERMANENT) |
| ||||||
LiftBan(ban_index) | Remove a ban. | ||||||
| Returns the ban index for the first active ban found on that IP, 0 if no bans. | ||||||
GetPlayerBanIndex(playerid) | Same as above, but for player ID. | ||||||
GetBanType(ban_index) | Returns the ban type for a ban. Possible return values:
| ||||||
|
| ||||||
|
| ||||||
| Set values associated with ban indexes (for example, reason, user id, etc.). | ||||||
| Read values stored by SetBanInfo*. Note that the max string size for GetBanInfoString is 256. For larger strings, use GetBanInfoStringCopy. | ||||||
| Fill the destination array with all active ban indices (indexes) and return the number of indices found. | ||||||
| Same as above, but for player ID. |
IP(x.x.x.x) |
| ||||||
IP_RANGE(x.x.x.x - x.x.x.x) |
| ||||||
IP_OCTET(ip, position) |
| ||||||
IPRange<name> | Used when declating IP range variables (IP ranges are enums). | ||||||
DURATION(x) |
| ||||||
|
| ||||||
|
|
Ban a player
pawn Код:
new ban = BanPlayer(playerid, DURATION(2 hours, 30 minutes));
SetBanInfoString(ban, "reason", "Auto-ban for doing whatever you're not supposed to..");
pawn Код:
public OnPlayerConnect(playerid) {
new ban = GetPlayerBanIndex(playerid);
if (ban) {
new message[128];
if (GetBanType(ban) == BAN_TYPE_RANGE)
format(message, 128, "* Your IP is inside a range-ban, reason: %s", GetBanInfoString(ban, "reason"));
else
format(message, 128, "* You are banned, reason: %s", GetBanInfoString(ban, "reason"));
SendClientMessage(playerid, 0xCC0000FF, message);
// This will output something like: "* You may come back in 1 day and 13 hours"
format(message, 128, "* You may come back in %s.", GetStringFromDuration(GetBanInfoInt(ban, "time_left")));
SendClientMessage(playerid, 0xCC0000FF, message);
Kick(playerid);
return 0;
}
return 1;
}
2011-11-25
- Fixed a bug causing BanIP to fail.
- Minor bug fixes.
- BanIPRange now accepts both strings IP ranges (IPRange<>).
- New functions:
- GetBanIPRange
- GetIPString
- GetIPRangeString
- ClearBanDB
- To facilitate DB upgrades, tables will now be created according to gs_Tables, and missing fields (if any) will be searched for & created from gs_Columns.
- Added automatic table creation.
- The database will have VACUUM done on initialization.
- GetStringFromDuration now puts commas and, if applicable, it puts "and" before the last part.
- Packed a bunch of print and db_query statements to save space.
- Rewrote EscapeSQLiteString to be approx. 160% faster.
- Added Get(IP/Player)BanIndices.
- Added LOOP_IP_BANS and LOOP_PLAYER_BANS.
- Fixed a few bugs related to improper buffer usage.
http://pastebin.com/R12ZpSjc