GetPlayerIp weird thing
#1

Hey guys, I have added the most simple autologin system to my Admin mode, but I noticed something weird
When I register a new admin (in this case, myself), it marks the IP as 127.0.0.1 (which is localhost)

It also registers it on the database
Code:
PHP Code:
if(!aInfo[playerb][aLevel])
    {
        
mysql_format(mysqlquerysizeof(query), "INSERT INTO `Admins` (`Username`, `ALogin`, `APassword`, `AdminLevel`, `IP`) VALUES ('%e', '0', '', '%d', '%s')"RPN(playerb), levelRPIP(playerb));
        
mysql_tquery(mysqlquery);
        
format(stringsizeof(string), "Congratulations, You have been promoted to level %d Admin by %s %s."levelRPARN(playerid), RPN(playerid));
        
SendClientMessage(playerbCOLOR_REDstring);
        
SendClientMessage(playerbCOLOR_RED"Please set your private admin password using /AdmPass, You cannot receieve your powers until then.");
        
AdminChat[playerid] = 1;
    } 
This is where I update the data when an Admin disconnects
PHP Code:
    if(aInfo[playerid][aLevel])
    {
        new 
query[1000], string[128];
        
mysql_format(mysqlquerysizeof(query), "UPDATE `Admins` SET `AdminLevel`='%d', `APassword`='%s', `IP`='%s', `ALogin`='%d' WHERE `Username`='%e' LIMIT 1",
         
aInfo[playerid][aLevel], aInfo[playerid][aPass], RPIP(playerid), aInfo[playerid][aALogin], RPN(playerid));
         
mysql_tquery(mysqlquery);
         
format(stringsizeof(string), "    Administrator %s has disconnected from the server."RPN(playerid));
         
SendAMessage(1string);
    } 
Now, I checked up my database and I noticed that the IP is 255.255.255.255

The RPIP is a simple code
PHP Code:
stock RPIP(playerid)
{
    new 
ip[16];
    
GetPlayerIp(playeridipsizeof(ip));
    return 
ip;

How can I fix it ?
It prevents my autologin function from working
Reply
#2

Change %s to %e IP
Reply
#3

Using GetPlayerIp in OnPlayerDisconnect callback from localhost always return 255.255.255.255
When a player logins, send a query to update the IP rather when disconnecting.

Another thing is:
- Have a unique ID for each player in the table (auto increment enabled). Whenever you want to update or select (I'm not referring to check whether the player is registered or not) data for a player, use that "ID" in WHERE clause instead of "Username". Use FOREIGN KEY Constraints for the "Admins" table.

- Update data to the table ONLY when needed.
Reply
#4

Quote:
Originally Posted by Konstantinos
View Post
Have a unique ID for each player in the table (auto increment enabled). Whenever you want to update or select (I'm not referring to check whether the player is registered or not) data for a player, use that "ID" in WHERE clause instead of "Username".
Does that really makes a significant difference in speed ?
Reply
#5

Quote:
Originally Posted by Gammix
View Post
Does that really makes a significant difference in speed ?
Sure it does. If the "Username" is not indexed and is also a text will obviously be slower searching than an indexed (primary keys are) integer.

Worth noting that any column is used in WHERE or ORDER BY must be indexed.
Reply
#6

Quote:
Originally Posted by Konstantinos
View Post
Sure it does. If the "Username" is not indexed and is also a text will obviously be slower searching than an indexed (primary keys are) integer.

Worth noting that any column is used in WHERE or ORDER BY must be indexed.
Well I use the mysql database for saving the Admin information, what I build is an Admin FS, I don't have any other tables and I don't need any
I use Username as Primary, so basically, I don't think it would make such difference
I would like to see your opinions about what Konstantinos offered me, since i'm pretty new to Pawn MYSQL at all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)