Name Goes Null
#1

ok my problem is when I connect to my server on my host, it loses my name after it does my temp ban check my name becomes null. after name is set to null whenever it tries to use it, formated in a string, in sendclientmessage the server crashes. other players can connect fine doesn't do this for them, does this on both of my pcs with any name I use. However when I run the server from localhost(my pc) it does NOT do it and I connect just fine. I can connect to other servers on the same host aswell with no error.

very confusing error hope I explained it well enough. I usually don't need any help, but with this I'm at a loss. Thanks in advance to any suggestions, ideas and/or fixes.

things I've already tried:
reinstalled sa-mp 3z and GTA:SA, still null name after the tempbancheck returns false.
commented the tempbancheck out and it worked fine for me on the host.


here comes the code:

Onplayerconnect
Код:
    printf("my name is %s", fName(playerid));
    if(TempBanCheck(playerid)){
        Kick(playerid);
        return 1;
    }
    else{
        printf("then my name is %s", fName(playerid));
    }
Tempban code
Код:
stock TempBanCheck(playerid)
{
	if(!test){
	    MySQLCheck();
	    return false;
	}
	new ip[15];
	new str[128];
	new tmp[256];
	new query[512];
	new ban_second, ban_minute, ban_hour, ban_day, ban_month, ban_year;
	GetPlayerIp(playerid, ip, sizeof(ip));
              format(query,sizeof(query),"SELECT * FROM `"TEMPBANTABLENAME"` WHERE tempban_ip = '%s'",ip);
	mysql_query(query,-1,playerid,connection);
	mysql_store_result(connection);

	new nrows = mysql_num_rows(connection);
	if(nrows == 1)
	{
		mysql_fetch_field("tempban_second",tmp,connection);
		ban_second = strval(tmp);
		mysql_fetch_field("tempban_minute",tmp,connection);
		ban_minute = strval(tmp);
		mysql_fetch_field("tempban_hour",tmp,connection);
		ban_hour = strval(tmp);
		mysql_fetch_field("tempban_day",tmp,connection);
		ban_day = strval(tmp);
		mysql_fetch_field("tempban_month",tmp,connection);
		ban_month = strval(tmp);
		mysql_fetch_field("tempban_year",tmp,connection);
		ban_year = strval(tmp);
		mysql_free_result(connection);
	}else{
                   mysql_free_result(connection);
                   printf("beore return false my name is %s", fName(playerid));
                   return false;
	}
	new year, month, day, hour, minute, second;
	getdate(year, month, day);
              gettime(hour, minute, second);
              new bool:kban=false;
	if(year >= ban_year && month > ban_month){
 		kban = false;
 	}else{
 	    if(ban_year > year){
			kban = true;
		}
 	    if(ban_month > month && ban_year >= year){
			kban = true;
		}
		if(ban_day > day && ban_month >= month && ban_year >= year){
			kban = true;
		}
		if(ban_day == day && ban_month == month && ban_year == year) {
			if(ban_hour > hour) {
				kban = true;
			}else{
			    if(ban_minute >= minute && ban_second >= second) {
					kban = true;
				}
			}
		}
		
	}
	if(kban == true) {
	    if(ban_minute<=9 && ban_minute>=0){
	        if(ban_second<=9 && ban_second>=0){
		    	format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:0%d:0%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
		    }else{
				format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:0%d:%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
			}
		}else{
	        if(ban_second<=9 && ban_second>=0){
	    		format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:%d:0%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
			}else{
				format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:%d:%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
			}
		}
	   	SendClientMessage(playerid, RED, str);
    	return true;
	}else{
		format(query,sizeof(query),"DELETE FROM `"TEMPBANTABLENAME"` WHERE `tempban_ip` = '%s'", ip);
		mysql_query(query,-1,playerid,connection);
	}
	return false;
}
the code failed to paste with proper indentation but I did indent to where the code gets to.

Server Log
Quote:

[05:03:49] Incoming connection: *.*.*.*:51603
[05:03:50] [join] [ABK]Necro has joined the server (0:*.*.*.*)
[05:03:50] my name is [ABK]Necro
[05:03:50] beore return false my name is [ABK]Necro
[05:03:50] then my name is

Reply
#2

Interesting. How does your fName function looks like? Is it simply wrapper around GetPlayerName?
Reply
#3

yea

Код:
stock fName(playerid)
{
  new name[MAX_PLAYER_NAME];
  GetPlayerName(playerid, name, sizeof(name));
  return name;
}
on another note... I can revert back to 0.3x and it works fine on both my host and localhost.
Reply
#4

Well, I'm baffled. How does standard GetPlayerName in place of last fName behave? Few theories: memory corruption on mysql plugin part. Add crashdetect, maybe something bad happens, but only screws up a few things (like GPN function). Check mysql_log for errors.

Quote:

`"TEMPBANTABLENAME"`

What's your TEMPBANTABLENAME definition? Is it
Quote:

#define TEMPBANTABLENAME "something"

or
Quote:

#define TEMPBANTABLENAME something

I'm not well versed with that mysql plugin version, I'd suggest moving onto newest one (unthreaded queries are supported).
Reply
#5

MySQL logs no errors.

the define has quotes cuz it is a string of course.

idk what crashdetect is, i'll search in a sec :P

altho why ONLY happens for me? and doesn't do it on my pc, and server is windows 2008 so using exact same plugin files. AND even bigger works 100% in 3x but not 3z.
Reply
#6

I don't know what it caused it but I know a way of fixing it. Getting the name of the player only once on connect and store it to an array:
pawn Код:
// definition:
#define fName(%0) Player_Name[%0]

// global:
new
    Player_Name[MAX_PLAYERS][21];

// OnPlayerConnect:
GetPlayerName(playerid, Player_Name[playerid], 21);
so remove the fName stock and it will be fine.

PS: If you have server crashes, then load crashdetect plugin: https://github.com/Zeex/samp-plugin-...ases/tag/v4.13
For more information about crashes/run time errors such as line that caused it etc, use debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Re-compile your scripts and start the server. After a server crash, post the server log.
Reply
#7

hmmm that may work. thanks i'll try that. +rep to u sir.
Reply
#8

nope didn't work, my name is still null after the tempbancheck. besides that's more of a workaround even if it did work. thanks tho. still unsolved. the REAL QUESTION is why does the name go null after my tempbancheck function returns false.

and now even more weird cuz with this work around it had already gotten and stored the playername.
its almost like it loses all stored variables.

here is what crashdetect added:

Quote:

[05:41:39] [debug] Server crashed while executing FR_Admin.amx
[05:41:39] [debug] AMX backtrace:
[05:41:39] [debug] #0 native format () [00471450] from Fatal_Rivalry.exe
[05:41:39] [debug] #1 000216dc in public OnPlayerConnect () from FR_Admin.amx
[05:41:40] [debug] Native backtrace:
[05:41:40] [debug] #0 00403334 in ?? () from Fatal_Rivalry.exe
[05:41:40] [debug] #1 716358ca in AmxCallback () from plugins\crashdetect.DLL
[05:41:40] [debug] #2 7163774f in amx_Exec () from plugins\crashdetect.DLL
[05:41:40] [debug] #3 71630834 in CrashDetect:: DoAmxExec () from plugins\crashdetect.DLL
[05:41:40] [debug] #4 7163591a in AmxExec () from plugins\crashdetect.DLL
[05:41:40] [debug] #5 0046a41f in ?? () from Fatal_Rivalry.exe
[05:41:40] [debug] #6 00465f2d in ?? () from Fatal_Rivalry.exe

Reply
#9

Give 16 size for IP.
Quote:

format(query,sizeof(query),"SELECT * FROM `"TEMPBANTABLENAME"` WHERE tempban_ip = '%s'",ip);

This line is problematic.
Please do before
pawn Код:
print("SELECT * FROM `"TEMPBANTABLENAME"` WHERE tempban_ip = '%s'");
print(ip);
Reply
#10

You get the name before tusing TempBanCheck, right? It's the first time I've heard of that happens so I guess you'll have to do some debugging manually:

pawn Код:
stock TempBanCheck(playerid)
{
    if(!test)
    {
        MySQLCheck();
        return false;
    }
    new ip[15];
    new str[128];
    new tmp[256];
    new query[512];
    new ban_second, ban_minute, ban_hour, ban_day, ban_month, ban_year;
    GetPlayerIp(playerid, ip, sizeof(ip));
    print("DEBUG: TempBanCheck -> 1");
    format(query,sizeof(query),"SELECT * FROM `"TEMPBANTABLENAME"` WHERE tempban_ip = '%s'",ip);
    mysql_query(query,-1,playerid,connection);
    mysql_store_result(connection);
   
    new nrows = mysql_num_rows(connection);
    if(nrows == 1)
    {
        mysql_fetch_field("tempban_second",tmp,connection);
        ban_second = strval(tmp);
        mysql_fetch_field("tempban_minute",tmp,connection);
        ban_minute = strval(tmp);
        mysql_fetch_field("tempban_hour",tmp,connection);
        ban_hour = strval(tmp);
        mysql_fetch_field("tempban_day",tmp,connection);
        ban_day = strval(tmp);
        mysql_fetch_field("tempban_month",tmp,connection);
        ban_month = strval(tmp);
        mysql_fetch_field("tempban_year",tmp,connection);
        ban_year = strval(tmp);
        mysql_free_result(connection);
    }
    else
    {
        mysql_free_result(connection);
        printf("beore return false my name is %s", fName(playerid));
        return false;
    }
    new year, month, day, hour, minute, second;
    getdate(year, month, day);
    gettime(hour, minute, second);
    new bool:kban=false;
    if(year >= ban_year && month > ban_month) kban = false;
    else
    {
        if(ban_year > year) kban = true;
        else if(ban_month > month && ban_year >= year) kban = true;
        else if(ban_day > day && ban_month >= month && ban_year >= year) kban = true;
        else if(ban_day == day && ban_month == month && ban_year == year)
        {
            if(ban_hour > hour) kban = true;
            else
            {
                if(ban_minute >= minute && ban_second >= second) kban = true;
            }
        }
       
    }
    if(kban == true)
    {
        if(ban_minute<=9 && ban_minute>=0)
        {
            if(ban_second<=9 && ban_second>=0)
            {
                print("DEBUG: TempBanCheck -> 2");
                format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:0%d:0%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
            }
            else
            {
                print("DEBUG: TempBanCheck -> 3");
                format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:0%d:%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
            }
        }
        else
        {
            if(ban_second<=9 && ban_second>=0)
            {
                print("DEBUG: TempBanCheck -> 4");
                format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:%d:0%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
            }
            else
            {
                print("DEBUG: TempBanCheck -> 5");
                format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d - %d:%d:%d -|", ban_day, ban_month, ban_year, ban_hour, ban_minute, ban_second);
            }
        }
        SendClientMessage(playerid, RED, str);
        return true;
    }
    else
    {
        print("DEBUG: TempBanCheck -> 6");
        format(query,sizeof(query),"DELETE FROM `"TEMPBANTABLENAME"` WHERE `tempban_ip` = '%s'", ip);
        mysql_query(query,-1,playerid,connection);
    }
    return false;
}
I remember only 1 way that format crashed and that was with send formatted message function (using emit).

And print the server log.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)