MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
Hello,
I just recently added a new MySQL ban system to my server. It works, but theres a problem. When I banned a person, they can still join and play on the server when they reconnect. I tried to fix it, but I can't seem to find the problem@
pawn Код:
stock CheckBan(playerid)
{
new query[126], IP[16];
GetPlayerIp(playerid, IP, sizeof(IP));
format(query,sizeof(query),"SELECT * FROM 'bans' WHERE ('Name' = '%s' OR 'IP' = '%s') AND 'Status' = 1", GetName(playerid), IP );
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(rows == 1)
{
new bReason[128], bannedBy[MAX_PLAYER_NAME], Dialog[128];
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(bReason, "Reason");
mysql_fetch_field_row(bannedBy, "BannedBy");
format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! \n{FF0000}Name:{FFFFFF} %s \n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s", GetName(playerid), bReason, bannedBy);
ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned", Dialog, "Close", "");
}
return 1;
}
mysql_free_result();
return 0;
}
Under onplayerconnect I have this:
So here is my problem. I tried banning myself, and the data goes to the database. But If I connect again, it just continues to play! So the ban is not loading! Please help
Please help me! Thanks
Re: MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
Please help!
Re: MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
Can someone please help?
Re: MySQL ban not loading if player is banned! -
Scenario - 25.03.2013
Can someone please READ THE FORUM RULES?
Re: MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
I understand, but I need help!
Re: MySQL ban not loading if player is banned! -
Scenario - 25.03.2013
And you're not the only person on this forum that needs help! Your problem is no more important than anyone else's problem.
You should re-check the MySQL plugin's release topic for the proper usage of mysql_fetch_row_format(), by the way.
Re: MySQL ban not loading if player is banned! -
ReVo_ - 25.03.2013
Enable MySQL debug and give us what the file say.
Try the query in phpmyadmin (or where u want) and check if it's correct
new query[126]
to
new query[131];
Query length: 90
Max nick: 24
Max IP: 16
90+24+16 = 130
Re: MySQL ban not loading if player is banned! -
park4bmx - 25.03.2013
no callbacks are called once the player is banned !
Do the BAN manually will be a way to go here.
Re: MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
Ok I'll show you what I got!
pawn Код:
public OnPlayerConnect(playerid)
{
new query[250];
if(CheckBan(playerid) == 0)
{
new
pname[24];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_PASSWORD, "{F81414}Register","{FFFFFF}Your account is not registered! \nPlease register your account by typing in a password below!","Register","Cancel");
}
if(rows == 1)
{
new IP[2][16];
mysql_fetch_field_row(IP[0],"IP");
GetPlayerIp(playerid, IP[1], 16);
if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
{
MySQL_Login(playerid);
}
else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
{
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_PASSWORD, "{00FF22}Login","{FFFFFF}Your account is registered! \nPlease login to your account by typing in your password below","Login","Cancel");
IsRegistered[playerid] = 1;
}
}
mysql_free_result();
}
return 1;
}
My CheckBan stock:
pawn Код:
stock CheckBan(playerid)
{
new query[126], IP[16];
GetPlayerIp(playerid, IP, sizeof(IP));
format(query,sizeof(query),"SELECT * FROM 'bans' WHERE (`Name` = '%s' OR `IP` = '%s') AND `Status` = 1", GetName(playerid), IP );
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() >= 1)
{
new bReason[128], bannedBy[MAX_PLAYER_NAME], Dialog[128];
while(mysql_fetch_row_format(query,"|")) // what's this? checks if there is a row
{
mysql_fetch_field_row(bReason, "Reason");
mysql_fetch_field_row(bannedBy, "BannedBy");
format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! \n{FF0000}Name:{FFFFFF} %s \n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s", GetName(playerid), bReason, bannedBy);
ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned", Dialog, "Close", "");
}
return 1;
}
mysql_free_result();
return 0;
}
And my BAN command:
pawn Код:
CMD:ban(playerid, params[])
{
if(pInfo[playerid][pAdmin] < 4 )
return PlayerIsNotAdmin( playerid );
new id,
reason[128];
if( sscanf(params, "us", id, reason))
return SendUsageError( playerid, "/ban [Name/ID] [Reason]" );
if( id == INVALID_PLAYER_ID)
return InvalidPlayerError( playerid );
new
name1[MAX_PLAYER_NAME],
name[MAX_PLAYER_NAME],
str[128];
GetPlayerName(playerid,name1,MAX_PLAYER_NAME);
GetPlayerName(id,name,MAX_PLAYER_NAME);
format(str, sizeof (str), "[BAN] Administrator %s has banned %s. Reason: %s", name1, name, reason);
SendClientMessageToAll(RED, str);
new
query[200], IP[16];
GetPlayerIp(id, IP, sizeof(IP));
format(query,sizeof(query), "INSERT INTO bans (Name, IP, Reason, BannedBy, Date, Status) VALUES('%s', '%s', '%s', '%s', NOW(), '1')", GetName(id), IP, reason, GetName(playerid), gettime());
mysql_query(query);
SetTimerEx( "KickPlayer",100, false, "i", id);
return 1;
}
Re: MySQL ban not loading if player is banned! -
FunnyBear - 25.03.2013
EDIT: Somehow, I managed to fix it, and it works. But, when I connect it shows the dialog, but the whole of the BannedBy name doesn't appear, it just sometimes show no name or just 2 letters.
Here it is
pawn Код:
format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! \n{FF0000}Name:{FFFFFF} %s \n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s", Name, bReason, bannedBy);