29.11.2010, 03:48
(
Последний раз редактировалось Hiitch; 30.11.2010 в 10:32.
)
Ok, well I have a rather weird bug that i'm not 100% sure about.
Since I'm new to mysql, i'll try to explain what I did.
What I wanted was a command where when a player is banned, it updates mysql with infos about the ban: player that was banned, admin that banned the player, the reason of ban, the activeness of the ban(either 1 or 0), and the user's IP. I finished this, and it updates to mysql nicely, while also banning the IP in samp.ban, which is what I wanted.
Now, here is my problem.
I have made an unban command. This command is supposed to navigate the database and find the IP of the player, unban them, and set the item 'active' to 0, meaning that they can connect. If it doesn't find the name, it will send a message letting them know that there is no player to unban (either doesn't exist, or the user is not banned.)
This is the code:
But what happens, is it always says that the player is not banned or does not exist, does not exist. Any reason why?
P.s. I tried using the sql syntax in wampserver, and it finds the player IP, however, when I use the unban command in game, nothing happens.
I hope I have given you enough information on the problem. Also, the ban command is below.
Since I'm new to mysql, i'll try to explain what I did.
What I wanted was a command where when a player is banned, it updates mysql with infos about the ban: player that was banned, admin that banned the player, the reason of ban, the activeness of the ban(either 1 or 0), and the user's IP. I finished this, and it updates to mysql nicely, while also banning the IP in samp.ban, which is what I wanted.
Now, here is my problem.
I have made an unban command. This command is supposed to navigate the database and find the IP of the player, unban them, and set the item 'active' to 0, meaning that they can connect. If it doesn't find the name, it will send a message letting them know that there is no player to unban (either doesn't exist, or the user is not banned.)
This is the code:
pawn Код:
dcmd_unban(playerid, params[])
{
if(GetPlayerAdminLevel(playerid) < 1) return 0;
new
aName[24],
str[256],
string[256],
name[100];
GetPlayerName(playerid, aName, 24);
if(sscanf(params, "z", name)) SendClientMessage(playerid, 0xFFFFFFFF, "[ @ ] Error! Use: /unban (name)");
{
format(str,sizeof(str),"SELECT ip FROM `bans` WHERE Banned='%s' AND active='1'",name);
mysql_query(str);
mysql_store_result();
if(mysql_num_rows() == 0)
{
SendClientMessage(playerid,0xFFFFFFAF,"[ @ ] This player is not banned or doesn't exist!");
mysql_free_result();
return 1;
}
new check[1][50];
mysql_fetch_row(string,"|");
split(string,check,'|');
mysql_free_result();
format(string,sizeof(string),"unbanip %s",check[0]);
SendRconCommand(string);
format(str, 256, "[ @ ] %s has been unbanned by %s!", name,GetName(playerid));
SendClientMessageToAll(0xFFFFFFAF, str);
SendRconCommand("reloadbans");
format(string,sizeof(string),"UPDATE `bans` SET active='0' WHERE Banned='%s' AND active='1'",name);
mysql_query(string);
printf("[UNBAN] %s has been unbanned by %s!", name, aName);
}
return true;
}
P.s. I tried using the sql syntax in wampserver, and it finds the player IP, however, when I use the unban command in game, nothing happens.
I hope I have given you enough information on the problem. Also, the ban command is below.
pawn Код:
dcmd_ban(playerid, params[])
{
if(GetPlayerAdminLevel(playerid) < 1) return 0;
new
id,
string[200],
aName[24],
msg[64];
if(sscanf(params, "ds", id, msg)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /ban <id> <reason>");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"[ ! ] Invalid playerid.");
if(GetPlayerAdminLevel(id) >= GetPlayerAdminLevel(playerid)) return SendClientMessage(playerid,COLOR_RED,"[ ! ] You can't ban this player !");
// if(id == playerid) return SendClientMessage(playerid,COLOR_RED,"[ ! ] You cannot ban yourself");
else
{
GetPlayerName(playerid, aName, 24);
format(msg, sizeof (msg), "%s%s !", msg[0] ? ("for ") : (""), msg);
format(string, sizeof(string), "[ ! ] %s has been banned by %s : %s",GetName(id),aName,msg);
SendClientMessageToAll(COLOR_AC,string);
printf("[PLAYER-BANNED] NAME: %s / ADMIN: %s / REASON: %s",GetName(id),aName,msg);
TogglePlayerControllable(id, 0);
format(string, sizeof(string), "[ ! ] You have been banned from the server.");
SendClientMessage(id,COLOR_RED,string);
BanEx(id,msg);
}
return 1;
}