Mysql GetPlayerIP something wrong
#1

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 )
Reply
#2

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?
Reply
#3

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

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
Reply
#5

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

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

// Disconnect
Use "PlayerIP[playerid]"
Reply
#6

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); 
Reply
#7

anyone have idea ? sorry for dump
Reply
#8

Yes, the variable Query has already been defined ...
Reply
#9

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
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)