GetPlayerIp weird thing -
NeXoR - 16.06.2016
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(mysql, query, sizeof(query), "INSERT INTO `Admins` (`Username`, `ALogin`, `APassword`, `AdminLevel`, `IP`) VALUES ('%e', '0', '', '%d', '%s')", RPN(playerb), level, RPIP(playerb));
mysql_tquery(mysql, query);
format(string, sizeof(string), "Congratulations, You have been promoted to level %d Admin by %s %s.", level, RPARN(playerid), RPN(playerid));
SendClientMessage(playerb, COLOR_RED, string);
SendClientMessage(playerb, COLOR_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(mysql, query, sizeof(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(mysql, query);
format(string, sizeof(string), " Administrator %s has disconnected from the server.", RPN(playerid));
SendAMessage(1, string);
}
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(playerid, ip, sizeof(ip));
return ip;
}
How can I fix it ?
It prevents my autologin function from working
Re: GetPlayerIp weird thing -
oMa37 - 16.06.2016
Change %s to %e IP
Re: GetPlayerIp weird thing -
Konstantinos - 16.06.2016
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.
Re: GetPlayerIp weird thing -
Gammix - 16.06.2016
Quote:
Originally Posted by Konstantinos
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 ?
Re: GetPlayerIp weird thing -
Konstantinos - 16.06.2016
Quote:
Originally Posted by Gammix
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.
Re: GetPlayerIp weird thing -
NeXoR - 17.06.2016
Quote:
Originally Posted by Konstantinos
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