SA-MP Forums Archive
Max Registrations From IP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Max Registrations From IP (/showthread.php?tid=599163)



Max Registrations From IP - yvoms - 21.01.2016

Hey guys, i know i've been here alot this night, but i wonder..
I've tried something which used to work but somehow no longer does.
I made a check, to see how much accounts a player has registered under ip X
If it contained more than 3 rows with the same IP the player was kicked.
However it no longer works, it doesn't function anymore

Код:
forward OnRegistrationCheck(playerid);
Код:
public OnRegistrationCheck(playerid)
{
      if(cache_get_row_count() >= 3) 
      {
      SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Server]:{ffffff} You have reached the max registered accounts on this IP, please use your previous account.");
      Kick(playerid);
  }
      return 1;
}
Код:
public OnAccountCheck(playerid)
{
        new rows, fields;
        cache_get_data(rows, fields, mysql);
        if(rows)
        {
                cache_get_field_content(0, "IP", IP[playerid], mysql, 16);
                new newIP[16];
                GetPlayerIp(playerid, newIP, 16);
                IsPlayerRegisterd[playerid] = 1;
                {
                        (!strlen(IP[playerid]) || strcmp(IP[playerid], newIP, true));
                        cache_get_field_content(0, "Password", pData[playerid][Password], mysql, 129);
                        pData[playerid][ID] = cache_get_field_content_int(0, "ID");
                        ShowPlayerDialog(playerid, dLOGIN, DIALOG_STYLE_PASSWORD, "Login", "In order to play, you need to login", "Login", "Quit");
                }
        }
        else
        {
        			 new pIP[16], query[72];
					 GetPlayerIp(playerid, pIP, sizeof(pIP));
					 mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `IP` = '%s'", pIP);
					 mysql_tquery(mysql, query, "OnRegistrationCheck", "s", playerid);
                	 ShowPlayerDialog(playerid, dREGISTER, DIALOG_STYLE_PASSWORD, "Register", "In order to play, you need to register.", "Register", "Quit");
        }

        return 1;
}
Is it because the IP is fetched as a string?


Re: Max Registrations From IP - Jefff - 21.01.2016

playerid is a integer not string, should be "i"
pawn Код:
"OnRegistrationCheck", "s", playerid);



Re: Max Registrations From IP - Vince - 21.01.2016

^ What he said.

Also if you only want to count something you should use the COUNT() aggregate function. Sending over the entire resultset (possibly containing hundreds of rows) is more resource intensive and therefore slower. The COUNT() function will always give 1 row with 1 column with 1 value that contains the number of rows. Even if the count is 0.


Re: Max Registrations From IP - yvoms - 21.01.2016

Seems that it has helped however, its kicking me before i get the message lol.


Re: Max Registrations From IP - Jefff - 21.01.2016

pawn Код:
forward OnRegistrationCheck(playerid, delay);
public OnRegistrationCheck(playerid, delay)
{
    if(delay == 0)
    {
        if(cache_get_row_count() >= 3)
        {
            SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Server]:{ffffff} You have reached the max registered accounts on this IP, please use your previous account.");
            SetTimerEx("OnRegistrationCheck",400,false,"ii",playerid,1); // kick must be delayed few ms
        }
    }
    else
    {
        Kick(playerid);
    }
    return 1;
}
+
in tquery

pawn Код:
"OnRegistrationCheck", "ii", playerid,0);
you should search delayed Kick/Ban include


Re: Max Registrations From IP - yvoms - 21.01.2016

Thanks Jeff, ill do that