Help With MySQL Ban List Script
#1

I'm trying to make it to where when someone is banned, the information about their ban is added to a MySQL database, but when I try and compile this, Pawno crashes. What is wrong? Also, I KNOW there is going to be something wrong with the MySQL stuff, so could you go ahead and fix that now? The table name is bans and the column/field or whatever names are Name, Reason, Admin, and IP. Here's the ban script:

Код:
#include <a_samp>
#include <a_mysql>

if(strcmp(cmd, "/adban", true) == 0 && PlayerAdminLevel[playerid] == 0) // Admin Ban
{
if(!PLAYERLIST_authed[playerid])
{
SendClientMessage(playerid,0xFF0000AA,"Bad Command. Type /commands for available commands depending on your chosen job/skill");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /adban (id)");
return 1;
}
giveplayerid = strval(tmp);
if(!IsNumeric(tmp)) {
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /adban (id) ID Must be a number");
return 1;
}
new output[255];
new File:ftw=fopen("banlist.txt", io_append);
new str[255];
new str1[255];
new bannername[24];
GetPlayerName(playerid,bannername, 24);
strmid(output,cmdtext,9,strlen(cmdtext));
if (IsPlayerConnected(giveplayerid)) {
SetPlayerInterior(giveplayerid,0);
SetPlayerPos(giveplayerid,-127.0526,2258.4316,29.4287);
SetPlayerFacingAngle(giveplayerid,217.0701);
SetCameraBehindPlayer(giveplayerid);
SetTimer("BanExplosionone",500,0);
AdminKilled[giveplayerid] =1;
GetPlayerName(giveplayerid, string, 24);
format(str, 255, "**(ADMIN BAN)** %s(%d) %s \r\n", string,giveplayerid,output);
format(str1, 255, "**(Banned By)**: %s \r\n",bannername);
SendClientMessageToAll(COLOR_RED, str);
fwrite(ftw, str);
fwrite(ftw, str1);
fclose(ftw);
printf("%s", string);
if(udb_Exists(PlayerName(giveplayerid)) && PLAYERLIST_authed[giveplayerid]) {
dUserSetINT(PlayerName(giveplayerid)).("nameban",1);
}

#define SQL_HOST "secret_host?"
#define SQL_DB "roleplay_bans"
#define SQL_USER "roleplay_bans"
#define SQL_PASS "secret?"

GetPlayerName(playerid,Name,sizeof(Name));
GetPlayerIp(playerid, plrIP, sizeof(plrIP));
mysql_real_escape_string(Name,Name);
mysql_real_escape_string(output,output);
mysql_real_escape_string(bannername,bannername);
mysql_real_escape_string(plrIP,plrIP);
format(query,sizeof(query),"INSERT INTO `"bans"` (Name, Reason, Admin, IP) VALUES ('%s',md5('%s'))",name,output,bannername,plrIP);
mysql_query(query);
mysql_query("INSERT INTO bans (Name, Reason, Admin, IP)

SendClientMessage(giveplayerid,COLOR_RED,"||| YOU HAVE BEEN BANNED FROM THIS SERVER");
SendClientMessage(giveplayerid,COLOR_RED,"||| You can appeal this action at our website");
SendClientMessage(giveplayerid,COLOR_RED,"||| Visit lolcats.com for details");
SendClientMessage(giveplayerid,COLOR_RED,"||| Please note that we do not unban hackers/cheaters");
SendClientMessage(giveplayerid,COLOR_RED,"||| You can also take a screenshot of this message for your unban appeal");
Banning[giveplayerid] = 1;
}
else {
format(string, sizeof(string), "ID (%d) Is not an active player", giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
}
return 1;
}
Reply
#2

Код:
INSERT INTO `"bans"` (Name, Reason, Admin, IP) VALUES ('%s',md5('%s'))
If you need only name and reason to be added add like this:
Код:
INSERT INTO `"bans"` (Name, Reason) VALUES ('%s',md5('%s'))
You don't need to fill up all the rows with custom values, just make sure that you define default values in mysql table ,so it knows what to add if you don't specific otherwise.

And btw, that encryption (md5) is pretty useless there since you don't have any passwords. If you encrypt something you won't be able to unencrypt that ever again.
Reply
#3

So how may I take out the encryption, just delete it? I did realize the problem, how it wouldn't need an md5 encryption... I just didn't know how to take it out... Also, is there a way to log a time to one of the column things too?

***EDIT*** I have changed it to this, but Pawno still crashes:

Код:
#define SQL_HOST "secret_host?"
#define SQL_DB "roleplay_bans"
#define SQL_USER "roleplay_bans"
#define SQL_PASS "secret?"

GetPlayerName(playerid,Name,sizeof(Name));
GetPlayerIp(playerid, plrIP, sizeof(plrIP));
mysql_real_escape_string(Name,Name);
mysql_real_escape_string(output,output);
mysql_real_escape_string(bannername,bannername);
mysql_real_escape_string(plrIP,plrIP);
format(query,sizeof(query),"INSERT INTO `"bans"` (Name, Reason, Admin, IP) VALUES ('%s',md5('%s'))";
mysql_query(query);
mysql_query("INSERT INTO bans (Name, Reason, Admin, IP)
Reply
#4

What a mess you got there -.-

pawn Код:
GetPlayerName(playerid,Name,sizeof(Name));
GetPlayerIp(playerid, plrIP, sizeof(plrIP));
mysql_real_escape_string(Name,Name);
mysql_real_escape_string(output,output);
mysql_real_escape_string(bannername,bannername);
mysql_real_escape_string(plrIP,plrIP);
format(query,sizeof(query),"INSERT INTO `"bans"` (Name, Reason, Admin, IP) VALUES ('%s','%s','%s','%s')",Name,output,bannername,plrIP);
mysql_query(query);
Reply
#5

I know, I'm a bit new... but pawno is still crashing. Am I missing any curly brackets ({ and }) anywhere? Thanks!
Reply
#6

Pawno crashing? Buy a new computer maybe

Never got pawno crashed, so I don't know what could cause it. Maybe it's just your computer or you have done something really wrong in script.
Reply
#7

I have been told that it crashes if you have too many/too less curly brackets...
Reply
#8

Is the bit under the includes under OnPlayerCommandText and is cmd defined?
Reply
#9

Try replacing the string with this one:
pawn Код:
"INSERT INTO bans (Name, Reason, Admin, IP) VALUES('%s','%s','%s','%s')"
Table names should not have quotes, and you had made 2 strings:
pawn Код:
"This is a string, inside quotes "no string here" another string here"
"INSERT INTO `"bans"` (Name, Reason, Admin, IP) VALUES ('%s','%s','%s','%s')"
/* "bans" is like "no string here" in the first example, it is outside the quotes */
Reply
#10

I believe I am missing curly brackets somewhere, so could someone put them in? thanks!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)