RP Name Kick
#1

I tried to make a system that when someone joins with a name like: Stefand or sasaasd or fuckme etc.
They will get kicked with a message.
But as soon as I join with a name that does not have a _ included it will just kick me without a message.

pawn Код:
public OnPlayerConnect(playerid)
{
    TogglePlayerSpectating(playerid, true);

    GetPlayerIp(playerid, PlayerIP[playerid], 16);
   
    new query[126];
    format(query, sizeof(query), "SELECT * FROM `Bans` WHERE `Username` = '%s' OR `Ipaddress` = '%s'", GetName(playerid), PlayerIP[playerid]);
    mysql_function_query(connectionHandle, query, true, "BansCallback", "d", playerid);

    return 1;
}
pawn Код:
//CALLBACKS FROM QUERY
forward BansCallback(playerid);
public BansCallback(playerid)
{
    new
        AdminName[MAX_PLAYER_NAME],
        BanReason[60],
        temp[30];

    cache_get_row(0, 0, temp);
    new iBanID = strval(temp);
    cache_get_row(0, 2, AdminName);
    cache_get_row(0, 3, BanReason);
    cache_get_row(0, 5, temp);
    new iBannedTimestamp = strval(temp);
    cache_get_row(0, 6, temp);
    new iUnbannedTimestamp = strval(temp);

    if(iUnbannedTimestamp == -1)
    {
        clearPlayerChat(playerid);

        SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
        SendClientMessage(playerid, -1, " ");
        fSendClientMessage(playerid, COLOR_WHITE, "You were banned by {E70000}%s {FFFFFF}on %s.", AdminName, date(iBannedTimestamp, 2));
        fSendClientMessage(playerid, COLOR_WHITE, "Reason: %s", BanReason);
        SendClientMessage(playerid, -1, " ");
        SendClientMessage(playerid, COLOR_WHITE, "This is a permanent ban and it will not expire.");
        Kick(playerid);
    }
    else if(gettime() >= iUnbannedTimestamp)
    {
        new query[128];
        format(query, sizeof(query), "DELETE FROM `Bans` WHERE `BanID` = %d", iBanID);
        mysql_function_query(connectionHandle, query, false, "DefaultCallback", "");

        format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Username` = '%s'", GetName(playerid));
        mysql_function_query(connectionHandle, query, true, "LoadCallback", "d", playerid);
    }
    else
    {
        clearPlayerChat(playerid);
        SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
        SendClientMessage(playerid, -1, " ");
        fSendClientMessage(playerid, COLOR_WHITE, "You were banned by {E70000}%s {FFFFFF}on %s.", AdminName, date(iBannedTimestamp, 2));
        fSendClientMessage(playerid, COLOR_WHITE, "Reason: %s", BanReason);
        SendClientMessage(playerid, -1, " ");
        fSendClientMessage(playerid, COLOR_WHITE, "You will be automatically unbanned on %s.", date(iUnbannedTimestamp, 2));
        Kick(playerid);
    }
    return 1;
}

forward LoadCallback(playerid);
public LoadCallback(playerid)
{
    new
        rows,
        fields;

    cache_get_data(rows, fields);
    if(rows == 1)
    {
        new temp[50];
        cache_get_row(0, 0, temp); // #0 = #1 in the DB
        Player[playerid][UserID] = strval(temp);
        cache_get_row(0, 2, Player[playerid][Password]);
        cache_get_row(0, 3, Player[playerid][LastIP]);
        cache_get_row(0, 4, temp);
        Player[playerid][Adminlevel] = strval(temp);
        cache_get_row(0, 5, temp);
        Player[playerid][Money] = strval(temp);
        cache_get_row(0, 6, temp);
        Player[playerid][RegTime] = strval(temp);
        cache_get_row(0, 7, temp);
        Player[playerid][LastOn] = strval(temp);
        cache_get_row(0, 8, temp);
        Player[playerid][Level] = strval(temp);
        cache_get_row(0, 9, Player[playerid][Gender]);
        cache_get_row(0, 10, temp);
        Player[playerid][Age] = strval(temp);
        cache_get_row(0, 11, temp);
        Player[playerid][Health] = floatstr(temp);
        cache_get_row(0, 12, temp);
        Player[playerid][Armour] = floatstr(temp);
        cache_get_row(0, 13, temp);
        Player[playerid][Skin] = strval(temp);

        clearPlayerChat(playerid);
        //SendClientMessage(playerid, COLOR_WHITE, "SERVER: This account "#COL_EMB_GREEN"has been registered."#COL_EMB_WHITE" Please authenticate in order to proceed.");
        SPD(playerid, DIALOG_AUTHENTICATION);
    }
    else if(rows == 0)
    {
        clearPlayerChat(playerid);
        new playernamesplit[3][MAX_PLAYER_NAME], Name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Name, sizeof(Name));
        split(Name, playernamesplit, '_');

        if (!strlen(playernamesplit[0]) || !strlen(playernamesplit[1]))
        {
            SendClientMessage(playerid, COLOR_WHITE, "Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
            Kick(playerid);
        }
        else
        {
           
            SPD(playerid, DIALOG_REGISTER);
        }
    }
    else
    {
        clearPlayerChat(playerid);
        SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
        Kick(playerid);
    }
    return 1;
}

forward DefaultCallback(playerid);
public DefaultCallback(playerid)
{
    //lets leave this blank :)
    return 1;
}
Reply
#2

pawn Код:
stock IsPlayerCorrectlyNamed( playerid )
{
     new pNAME[MAX_PLAYER_NAME]; GetPlayerName( playerid, pNAME, MAX_PLAYER_NAME );
     for( new i = 0 ; i < 10 ; i++ )
     {
          if(strfind(name, i, true) != -1 ) return Kick( playerid );
      }
      if( strfind(name, "_", true) == -1) return Kick( playerid );
      else return 1;
}
This COULD work. I have never tried this function before, it should probably work. You can add whatever other symbols you need like "@, ]" to be checked.
Reply
#3

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
pawn Код:
stock IsPlayerCorrectlyNamed( playerid )
{
     new pNAME[MAX_PLAYER_NAME]; GetPlayerName( playerid, pNAME, MAX_PLAYER_NAME );
     for( new i = 0 ; i < 10 ; i++ )
     {
          if(strfind(name, i, true) != -1 ) return Kick( playerid );
      }
      if( strfind(name, "_", true) == -1) return Kick( playerid );
      else return 1;
}
This COULD work. I have never tried this function before, it should probably work. You can add whatever other symbols you need like "@, ]" to be checked.
It already kicks people but I want it to also send the message I've made but it kicks them right away.
Reply
#4

Quote:
Originally Posted by SA-MP Wiki
Important Note: As of SA-MP 0.3x, any message sent to the player with SendClientMessage before Kick() will not be displayed for them.
It can be "fixed" by adding a timer. For more information take a look at this post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)