SA-MP Forums Archive
Mysql GetPlayerIP something wrong - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql GetPlayerIP something wrong (/showthread.php?tid=318531)



Mysql GetPlayerIP something wrong - doreto - 15.02.2012

i wonna to store ip on player when he disconnect and here my code
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
Query[100];
    
format(Query,sizeof(Query),"UPDATE playerdata SET money=%d, score=%d, ip=%s  WHERE username='%s'",GetPlayerMoney(playerid),GetPlayerScore(playerid),GetPlayerIP(playerid),PlayerName(playerid));
    
mysql_query(Query);
    return 
true;

and my stock for GetPlayerIP
PHP код:
stock GetPlayerIP(playerid)
{
    new 
Ip[25];
    
GetPlayerIp(playeridIpsizeof(Ip));
    return 
Ip;

on mysql i use IP int(16) and sometimes store ip like 55 sometimes dont store (im 100% connect to datebase )


Re: Mysql GetPlayerIP something wrong - Vince - 15.02.2012

GetPlayerIp doesn't work properly in OnPlayerDisconnect, as the player is already disconnected at that point. It will return 255.255.255.255 (an invalid IP address) most of the time. You should update the IP when a player connects or logs in. The IP doesn't change while the player is connected, or does it?


Re: Mysql GetPlayerIP something wrong - KingHual - 15.02.2012

Solution: Do the same when a player logs in instead of doing it on player disconnect. Vince already explained why.


Re: Mysql GetPlayerIP something wrong - doreto - 15.02.2012

really ? hmm then how to record player ip when he connect

PHP код:
        this is my login dialog
        format
(Query,sizeof(Query),"SELECT username FROM playerdata WHERE username='%s' AND password='%s'",PlayerName(playerid),inputtext);
        
mysql_query(Query);
        
mysql_store_result(); 
now i try to INSERT IP into db but nothing show
PHP код:
format(Querysizeof(Query), "INSERT INTO playerdata IP VALUES '%s'",GetPlayerIP(playerid)); 
//GetPlayerIP i user my stock above


Re: Mysql GetPlayerIP something wrong - iTorran - 15.02.2012

pawn Код:
// Top of script
new PlayerIP[MAX_PLAYERS][16];

// Login
format(PlayerIP[playerid], 16, "%s", GetPlayerIP(playerid));

// Disconnect
Use "PlayerIP[playerid]"



Re: Mysql GetPlayerIP something wrong - doreto - 15.02.2012

Quote:
Originally Posted by iTorran
Посмотреть сообщение
pawn Код:
// Top of script
new PlayerIP[MAX_PLAYERS][16];

// Login
format(PlayerIP[playerid], 16, "%s", GetPlayerIP(playerid));

// Disconnect
Use "PlayerIP[playerid]"
its strange becose when i post your code
PHP код:
    if( dialogid == DIALOG_LOGIN )
    {
        new 
Query[100];
        if(!
response) return
        
Kick(playerid),
        
SendClientMessage(playerid,-1,"Login exit");
        
format(Query,sizeof(Query),"SELECT username FROM playerdata WHERE username='%s' AND password='%s'",PlayerName(playerid),inputtext);
        new 
PlayerIP[MAX_PLAYERS][16];
        
format(PlayerIP[playerid], 16"%s"GetPlayerIP(playerid));
        
mysql_query(Query);
        
mysql_store_result(); 
its show me gamemode.pwn(353) : error 021: symbol already defined: "Query" << my register dialog
PHP код:
    if( dialogid == DIALOG_REGISTER )
    {
        new 
Query[100];// line 353
        
if(!response) return
        
Kick(playerid),
        
SendClientMessage(playerid,COLOR_RED,"You have cansel to register!");
        
format(Query,sizeof(Query),"INSERT INTO playerdata (username,password,score,money,ip) VALUES ('%s','%s',0,0,'%s')",PlayerName(playerid),inputtext);
        
mysql_query(Query); 



Re: Mysql GetPlayerIP something wrong - doreto - 15.02.2012

anyone have idea ? sorry for dump


Re: Mysql GetPlayerIP something wrong - KingHual - 15.02.2012

Yes, the variable Query has already been defined ...


Re: Mysql GetPlayerIP something wrong - doreto - 15.02.2012

if i remove new Query[100]; from register dialog its show
PHP код:
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
Header size
:           2696 bytes
Code size
:            33520 bytes
Data size
:            21912 bytes
Stack
/heap size:      16384 bytesestimated maxusage=14156 cells (56624 bytes)
Total requirements:   74512 bytes 
and give error and cant connect to db


Respuesta: Mysql GetPlayerIP something wrong - kirk - 15.02.2012

Name it rQuery, for example, the one you removed as it seems you alredy defined a global variable called Query.