Empty Dialog (MySQL)
#1

Hey,

I've created a function to check whether a player is banned. If they are, a dialog will show up giving them their ban details then kicking them. However, the information from the database isn't there in the dialog.

For example, it should say:

Ban Reason: Hacks
Banned By: Anti - Cheat

But it will come out as

Ban Reason:
Banned By:

Here is the code,

pawn Code:
forward OnBanLoad(playerid);
public OnBanLoad(playerid)
{
    new rows, fields, temp[120];
    new
        bReason,
        bannedBy,
        bName,
        Dialog[403],
        bIP,
        bExpiration,
        bID;

    cache_get_data(rows, fields, mysql);

    if(rows != 0)
    {
        cache_get_field_content(1, "Name", temp), bName = strval(temp);
        cache_get_field_content(3, "Reason", temp), bReason = strval(temp);
        cache_get_field_content(4, "BannedBy", temp), bannedBy = strval(temp);
        cache_get_field_content(2, "IP", temp), bIP = strval(temp);
        cache_get_field_content(0, "BanID", temp), bID = strval(temp);
        cache_get_field_content(7, "Expiration", temp), bExpiration = strval(temp);

        /*bName = cache_get_field_content_int(1, "Name");
        bReason = cache_get_field_content_int(3, "Reason");
        bannedBy = cache_get_field_content_int(4, "BannedBy");
        bIP = cache_get_field_content_int(2, "IP");
        bID = cache_get_field_content_int(0, "BanID");
        bExpiration = cache_get_field_content_int(7, "Expiration");
        #pragma unused temp*/



        if(bExpiration > 0)
        {
            if(gettime() >= bExpiration)
            {
                new query[74];
                mysql_format(mysql, query, sizeof(query), "UPDATE `bans` SET `Status`=0 WHERE `BanID` = '%d'", bID);
                mysql_tquery(mysql, query, "", "");
            }
            else
            {
                format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! Ban details:\n\n{FF0000}Name:{FFFFFF} %s \n{FF0000}IP:{FFFFFF} %s\n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s\n\n{FF0000}You will be unbanned in %d day(s)!\n\n{FF0000}If you think this ban is unfair, you can apply for an unban appeal at our forums\n{FF0000}Note - We do not unban hackers, or people who lie in their appeal", bName, bIP, bReason, bannedBy, (bExpiration-gettime()+86400)/86400);
                ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned!", Dialog, "Close", "");
                SetTimerEx( "KickPlayer",100, false, "i", playerid);
            }
        }
        else
        {
            format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! Ban details:\n\n{FF0000}Name:{FFFFFF} %s \n{FF0000}IP:{FFFFFF} %s\n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s\n\n{FF0000}You are banned forever!\n\n{FF0000}If you think this ban is unfair, you can apply for an unban appeal at our forums\n{FF0000}Note - We do not unban hackers, or people who lie in their appeal", bName, bIP, bReason, bannedBy);
            ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned!", Dialog, "Close", "");
            SetTimerEx( "KickPlayer",100, false, "i", playerid);
        }
    }
    return 1;
}
How am I able to fix this problem?

Thanks
Reply
#2

Do you get any error on mysql log?
Reply
#3

Quote:
Originally Posted by Maximus0
View Post
Do you get any error on mysql log?
Nope,

Code:
[22:48:02] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `bans` WHERE (`Name` = 'LoLiTsTols' OR `IP` = '') AND `Status` = '1'"..
[22:48:02] [DEBUG] CMySQLQuery::Execute[OnBanLoad(i)] - starting query execution
[22:48:02] [DEBUG] CMySQLQuery::Execute[OnBanLoad(i)] - query was successful
[22:48:02] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[22:48:02] [DEBUG] CMySQLQuery::Execute[OnBanLoad(i)] - data being passed to ProcessCallbacks()
[22:48:02] [DEBUG] Calling callback "OnBanLoad"..
[22:48:02] [DEBUG] cache_get_data - connection: 1
[22:48:02] [DEBUG] cache_get_field_content - row: 1, field_name: "Name", connection: 1, max_len: 120
[22:48:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "Name", data: "LoLiTsTols"
[22:48:02] [DEBUG] cache_get_field_content - row: 3, field_name: "Reason", connection: 1, max_len: 120
[22:48:02] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('3')
[22:48:02] [DEBUG] cache_get_field_content - row: 4, field_name: "BannedBy", connection: 1, max_len: 120
[22:48:02] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('4')
[22:48:02] [DEBUG] cache_get_field_content - row: 2, field_name: "IP", connection: 1, max_len: 120
[22:48:02] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('2')
[22:48:02] [DEBUG] cache_get_field_content - row: 0, field_name: "BanID", connection: 1, max_len: 120
[22:48:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "BanID", data: "151"
[22:48:02] [DEBUG] cache_get_field_content - row: 7, field_name: "Expiration", connection: 1, max_len: 120
[22:48:02] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('7')
[22:48:02] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[22:48:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
Reply
#4

First of all, show us what have you tried to fix this issue. Then on fail you should post a thread.

I have tried with R33, but as I am using R6 it get's kinda new for me to response.
I will suggest you to check this link and start script from scratch.
Reply
#5

Quote:
Originally Posted by Maximus0
View Post
First of all, show us what have you tried to fix this issue. Then on fail you should post a thread.

I have tried with R33, but as I am using R6 it get's kinda new for me to response.
I will suggest you to check this link and start script from scratch.
I am actually upgrading my scripts from R6 to R33. There is some stuff commented in the script, and that's what I thought would fix the problem but it didn't.

Any help?
Reply
#6

Use this -
pawn Code:
cache_get_field_content(0, "Name", temp), bName = strval(temp);
        cache_get_field_content(0, "Reason", temp), bReason = strval(temp);
        cache_get_field_content(0, "BannedBy", temp), bannedBy = strval(temp);
        cache_get_field_content(0, "IP", temp), bIP = strval(temp);
        cache_get_field_content(0, "BanID", temp), bID = strval(temp);
        cache_get_field_content(0, "Expiration", temp), bExpiration = strval(temp);

        /*bName = cache_get_field_content_int(0, "Name");
        bReason = cache_get_field_content_int(0, "Reason");
        bannedBy = cache_get_field_content_int(0, "BannedBy");
        bIP = cache_get_field_content_int(0, "IP");
        bID = cache_get_field_content_int(0, "BanID");
        bExpiration = cache_get_field_content_int(0, "Expiration");
        #pragma unused temp*/
You will use cache_get_field_content(0,.....)
The first parameter of cache_get_field_content is for row number since row number starts from 0 so it will be 0, if you have more than one rows then you change the value of first parameter to row number.
Reply
#7

I've done it, it's not working. I'll show you the ban check code.

Under OnPlayerConnect:


If the player isn't banned then it will continue to register/login
Code:
if(CheckBan(playerid) == 0)
    {
   		mysql_format(mysql, query, sizeof(query),"SELECT `password` FROM `"PlayerTable"` WHERE `user` = '%e' LIMIT 1", Name[playerid]);
   		mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
	}

Code:
stock CheckBan(playerid)
{

    new
		query[100];

    mysql_format(mysql, query, sizeof(query), "SELECT * FROM `"BanTable"` WHERE (`Name` = '%e' OR `IP` = '%s') AND `Status` = '1'", Name[playerid]);
    mysql_tquery(mysql, query, "OnBanLoad", "i", playerid);
    return 1;
}
Code:
public OnBanLoad(playerid)
{
    new rows, fields, temp[120];
    new
		bReason,
		bannedBy,
		bName,
		Dialog[403],
		bIP,
		bExpiration,
		bID;

	cache_get_data(rows, fields, mysql);

	if(rows != 0)
	{
	    cache_get_field_content(0, "BanID", temp), bID = strval(temp);
		cache_get_field_content(1, "Name", temp), bName = strval(temp);
		cache_get_field_content(2, "IP", temp), bIP = strval(temp);
		cache_get_field_content(3, "Reason", temp), bReason = strval(temp);
		cache_get_field_content(4, "BannedBy", temp), bannedBy = strval(temp);
		cache_get_field_content(7, "Expiration", temp), bExpiration = strval(temp);


		if(bExpiration > 0)
  		{
    		if(gettime() >= bExpiration)
    		{
				new query[74];
 		        mysql_format(mysql, query, sizeof(query), "UPDATE `bans` SET `Status`=0 WHERE `BanID` = '%d'", bID);
				mysql_tquery(mysql, query, "", "");
			}
 			else
     		{
       			format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! Ban details:\n\n{FF0000}Name:{FFFFFF} %s \n{FF0000}IP:{FFFFFF} %s\n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s\n\n{FF0000}You will be unbanned in %d day(s)!\n\n{FF0000}If you think this ban is unfair, you can apply for an unban appeal at our forums\n{FF0000}Note - We do not unban hackers, or people who lie in their appeal", bName, bIP, bReason, bannedBy, (bExpiration-gettime()+86400)/86400);
       			ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned!", Dialog, "Close", "");
                SetTimerEx( "KickPlayer",100, false, "i", playerid);
		  	}
        }
        else
        {
      		format(Dialog, sizeof(Dialog), "{FF0000}You are banned from this server! Ban details:\n\n{FF0000}Name:{FFFFFF} %s \n{FF0000}IP:{FFFFFF} %s\n{FF0000}Reason:{FFFFFF} %s \n{FF0000}Banned By:{FFFFFF} %s\n\n{FF0000}You are banned forever!\n\n{FF0000}If you think this ban is unfair, you can apply for an unban appeal at our forums\n{FF0000}Note - We do not unban hackers, or people who lie in their appeal", bName, bIP, bReason, bannedBy);
         	ShowPlayerDialog(playerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "{FF0000}Banned!", Dialog, "Close", "");
            SetTimerEx( "KickPlayer",100, false, "i", playerid);
		}
	}
	return 1;
}
Reply
#8

cache_get_field_content("1",.... Change these numbers to "0". in all cache get codes.
Reply
#9

Quote:
Originally Posted by Inn0cent
View Post
cache_get_field_content("1",.... Change these numbers to "0". in all cache get codes.
I've tried that

pawn Code:
cache_get_field_content(0, "BanID", temp), bID = strval(temp);
        cache_get_field_content(0, "Name", temp), bName = strval(temp);
        cache_get_field_content(0, "IP", temp), bIP = strval(temp);
        cache_get_field_content(0, "Reason", temp), bReason = strval(temp);
        cache_get_field_content(0, "BannedBy", temp), bannedBy = strval(temp);
        cache_get_field_content(0, "Expiration", temp), bExpiration = strval(temp);
Still doesn't work
Reply
#10

Quote:
Originally Posted by Inn0cent
View Post
cache_get_field_content("1",.... Change these numbers to "0". in all cache get codes.
That won't work because it's an index.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)