[Include] newkb.inc -> Kick and ban functions extension
#1

NEW KICK & BAN

v1.1 - Update on 10.04.2013
INTRODUCTION:
Hello!

Since I was inactive for a bit too long here on SAMP, decided to do some release(s) for this comunity! Anyways, this isn't actually something really "new", but eh, you'll see and judge it by yourself! This is also fix for a problem with kicking and baning while sending message to client which wouldn't be displayed to them!

Ever wanted to have a kick and ban function with exteneded parameters? Ever wanted to do something in just one line? Well, this include does that same thing - multiple stuff in one function! Proceed to further explanation down below...

Also, since the v1.1, there are 3 new disconnect reasons - DC_REASON_BAN ( 97 ), DC_REASON_KICK ( 98 ) and DC_REASON_BAN_IP ( 99 )! You can use them under "OnPlayerDisconnect" if you have leave messages system! I have fixed all warnings and errors in v1.1 that were accidentaly caused by my mistake!
__________________________________________________ __________________________________________________

EXPLANATION:

One and only function:

pawn Код:
native Client(...);
No parameters "pre-defined" (are these good words to use?), though you cant leave the function without a single parameter (min. are 2)! Let's go step by step!

1. Step - Determing what you want to actually do with player

Do you want to kick them or ban them? Well, decide!

pawn Код:
Client(CLIENT_ACTION_BAN); //ban all players
OR

pawn Код:
Client(CLIENT_ACTION_BAN_IP); //IP-ban all players
OR

pawn Код:
Client(CLIENT_ACTION_KICK); //kick all players
Now, you don't want to use this (or do you?) since it's designed to kick/ban all players IF the second parameter isn't used! Now those function become this now:

pawn Код:
Client(CLIENT_ACTION_BAN, playerid); //bans player
OR

pawn Код:
Client(CLIENT_ACTION_BAN_IP, playerid); //bans player IP and then kicks them
OR

pawn Код:
Client(CLIENT_ACTION_KICK, playerid); //kicks player
First step is explained, lets proceed!

2. Step - What kind of notification do you want?

There are 2 different choises to pick - notify wit message box or notify with message! Use following (I'll be using CLIENT_ACTION_KICK in all further explanations):

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG);
OR

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_DIALOG);
This won't work since this function should have either 2 or 5 and higher parameters! Furthermore, second step is done!

3. Step - Do you want to notify someone about taken action? If yes, who?

Three possible choices - notify all players, notify single player or notify RCON admins (+ console print)! (proceeding with usage of NOTIFICATION_TYPE_MSG)

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_ALL);
OR

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER);
OR

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_RCON);
Yet again this won't work since there are still less than 5 parameters used! Go on to fourth step!

4. Step - Actual notifying

Again, two different choices - depending which NOTIFICATION_TYPE you are using! I'll provide you with 2 possible looks of this function!

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER, "You are kicked from this server!", 0xFF0000); //note the message and color code
OR

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_DIALOG, NOTIFY_PLAYER, "KICKED!", "You are kicked from this server!", "Close"); //note the 3 strings now - 1st one is dialog caption, 2nd one is info, and 3rd one is a button for a player to click!
Though function with dialog notification must be somehow similiar as it is given in example, the message one can be changed, meaning this:

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER, "You are kicked from this server!"); //note the message, but color code is missing - therefore, will send a white message
Also, dialog can only be shown to a player that will be banned/kicked since I decided to do it like that!

__________________________________________________ _______________________________________________

CREDITS:

fiki574 - Creating this include
LarzI - Helping me understand how getarg() with arrays/strings

__________________________________________________ _______________________________________________

DOWNLOAD:

Code isn't too advanced/big, so I'll just post it here!

pawn Код:
#if defined _newkb_included
    #endinput
#endif
#define _newkb_included

#define NOTIFICATION_TYPE_MSG       (0)
#define NOTIFICATION_TYPE_DIALOG    (1)
#define NOTIFY_ALL                  (2)
#define NOTIFY_PLAYER               (3)
#define NOTIFY_RCON                 (4)
#define CLIENT_ACTION_KICK          (5)
#define CLIENT_ACTION_BAN           (6)
#define CLIENT_ACTION_BAN_IP        (7)
#define DC_REASON_BAN               (97)
#define DC_REASON_KICK              (98)
#define DC_REASON_BAN_IP            (99)

new KickTimer[MAX_PLAYERS], BanTimer[MAX_PLAYERS];

/*Natives:
native Client(...);
*/


stock Client(...)
{
    new action = -1, playerid = INVALID_PLAYER_ID, notification = -1, notify_who = -1;
    action = getarg(0);
    playerid = getarg(1);
    if(numargs() >= 2)
    {
        notification = getarg(2);
        switch(notification)
        {
            case NOTIFICATION_TYPE_MSG:
            {
                notify_who = getarg(3);
                new msg[100];
                for(new k = 0; getarg(4, k) != 0; k++)
                {
                    msg[k] = getarg(4,k);
                }
                new msgcolor = getarg(5);

                switch(notify_who)
                {
                    case NOTIFY_ALL:
                    {
                        SendClientMessageToAll(msgcolor, msg);
                    }

                    case NOTIFY_PLAYER:
                    {
                        SendClientMessage(playerid, msgcolor, msg);
                    }

                    case NOTIFY_RCON:
                    {
                        if(IsPlayerAdmin(playerid) == 1) SendClientMessage(playerid, msgcolor, msg);
                        printf("%s", msg);
                    }
                }
            }

            case NOTIFICATION_TYPE_DIALOG:
            {
                notify_who = getarg(3);
                new caption[20];
                for(new k = 0; getarg(4, k) != 0; k++)
                {
                    caption[k] = getarg(4,k);
                }
                new info[256];
                for(new k = 0; getarg(5, k) != 0; k++)
                {
                    info[k] = getarg(5,k);
                }
                new button[10];
                for(new k = 0; getarg(6, k) != 0; k++)
                {
                    button[k] = getarg(6,k);
                }

                switch(notify_who)
                {
                    case NOTIFY_PLAYER:
                    {
                        ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,caption,info,button,"");
                    }

                    case NOTIFY_ALL, NOTIFY_RCON:
                    {
                        return 0;
                    }
                }
            }  
        }  
       
        switch(action)
        {
            case CLIENT_ACTION_BAN:
            {
                OnPlayerDisconnectEx(playerid, DC_REASON_BAN);
                BanTimer[playerid] = SetTimerEx("BanPlayer", 100, false, "d", playerid);
                if(numargs() == 1) for(new i = 0; i < MAX_PLAYERS; i++) OnPlayerDisconnectEx(playerid, DC_REASON_BAN), Ban(i);
               
            }

            case CLIENT_ACTION_KICK:
            {
                OnPlayerDisconnectEx(playerid, DC_REASON_KICK);
                KickTimer[playerid] = SetTimerEx("KickPlayer", 100, false, "d", playerid);
                if(numargs() == 1) for(new i = 0; i < MAX_PLAYERS; i++) OnPlayerDisconnectEx(i, DC_REASON_KICK), Kick(i);
            }

            case CLIENT_ACTION_BAN_IP:
            {
                OnPlayerDisconnectEx(playerid, DC_REASON_BAN_IP);
                new ip[32];
                GetPlayerIp(playerid,ip,sizeof(ip));
                new banit[40];
                format(banit,sizeof(banit),"banip %s", ip);
                SendRconCommand(banit);
                if(numargs() == 1)
                {
                    new pip[32];
                    for(new i = 0; i < MAX_PLAYERS; i++)
                    {  
                        GetPlayerIp(i,pip,sizeof(pip));
                        new banit2[40];
                        format(banit2,sizeof(banit2),"banip %s", ip);
                        SendRconCommand(banit2);
                        OnPlayerDisconnectEx(i, DC_REASON_BAN_IP);
                    }
                }
                KickTimer[playerid] = SetTimerEx("KickPlayer", 100, false, "d", playerid);
            }
        }  
    }
    return 1;
}

forward KickPlayer(playerid);
public KickPlayer(playerid)
{
    Kick(playerid);
    KillTimer(KickTimer[playerid]);
    return 0;
}

forward BanPlayer(playerid);
public BanPlayer(playerid)
{
    Ban(playerid);
    KillTimer(BanTimer[playerid]);
    return 0;
}

forward OnPlayerDisconnectEx(playerid, reason);
public OnPlayerDisconnectEx(playerid, reason)
{
    return CallLocalFunction("OnPlayerDisconnect", "dd", playerid, reason);
}
__________________________________________________ _______________________________________________

Regards,
Fiki!


P.S. I know I've maybe made this include (the include itself + presentation) a bit too complicated! :P
Reply
#2

No replies??

Anyways, I made a new update (v1.1) in which I fixed some errors and warnings from v1.0 + I've added some new stuff which is explained in "INTRODUCTION" part of the first post! Please redownload!
Reply
#3

This is cool but I hate the way you decided to use only 1 function. Trying to figure out what parameters should be used is hard as fuck.

You should really consider keeping the one function with the long string of parameters and also creating more which do the same thing and are easier to understand.

Also, the Client function is not a native. You had me fooled for a moment into thinking this also contained a plugin.
Reply
#4

Quote:
Originally Posted by SchurmanCQC
Посмотреть сообщение
This is cool but I hate the way you decided to use only 1 function. Trying to figure out what parameters should be used is hard as fuck.

You should really consider keeping the one function with the long string of parameters and also creating more which do the same thing and are easier to understand.

Also, the Client function is not a native. You had me fooled for a moment into thinking this also contained a plugin.
Well, I know it may be too hard to learn and understand, but the point of this function was to enable scripter using multiple and different parameters! Also, making this function with optional parameters instead of arguments would require to create one more extra function because when you use message type notification, it needs 2 parameters (actual message and color) and when you use dialog type notification, it requires 3 parameters (caption, info and button)! Though, this indeed can be made with option parameters, e.g.:

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, "You are kicked from the server!", 0xFF0000, 0, 0, 0);
where 0's are those parts for the dialog style notification (well, they are actually strings so I can't use integrers, but this is just example)! On the other hand, using dialog style nofitication would look something like this:

pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_DIALOG, 0, 0, "KICKED!", "You are kicked from the server!", "Close");
where 0's are parameters for message style notification!

Then, if you want to for example kick all players, you would have to do this:

pawn Код:
Client(CLIENT_ACTION_KICK, 0, 0, 0, 0, 0, 0, 0);
where 0's represent all other optional parameters! I didn't like this look of function, thats why I did it with arguments!


So, if you do understand and learn how this function works, it should be easy to use it! (those upper-posted examples are somewhere near what you meant, right?)

About the name - I simply couldn't think of better one so I used "Client"! :P

Any constructive and positive criticism/comments are welcome!

Regards!
Reply
#5

wonder- FULL include!
Reply
#6

Amazing! I love this :
Quote:

Also, since the v1.1, there are 3 new disconnect reasons - DC_REASON_BAN ( 97 ), DC_REASON_KICK ( 98 ) and DC_REASON_BAN_IP ( 99 )!

I agree with this :
Quote:

Trying to figure out what parameters should be used is hard as fuck.

This include is great!
Reply
#7

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
wonder- FULL include!
Thanks!

Quote:
Originally Posted by greentarch
Посмотреть сообщение
Amazing! I love this :


I agree with this :


This include is great!
Thank you!

Look at the post above Niko's one, everything is explained and discussed there!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)