Page 1 of 1

[HELP] IP compare

Posted: Fri Oct 02, 2009 12:49 pm
by xrs
If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision Number:3587M
L2JDP Revision Number:6680

I want to check if player and his target IP addresses are the same:

Code: Select all

if (getClient().getConnection().getInetAddress().getHostAddress() == targetPlayer.getClient().getConnection().getInetAddress().getHostAddress()) {     sendMessage("Killed player with same IP. No reward.");      return; }
This statement returns false, allthough both IP's are the same.
If I add line:

Code: Select all

sendMessage("Checking IP:" + getClient().getConnection().getInetAddress().getHostAddress() + ":" + targetPlayer.getClient().getConnection().getInetAddress().getHostAddress()); 
In game client I get output: Checking IP:127.0.0.1:127.0.0.1
This means that i get IP of player and his target correctly(both clients are on same PC on localhost), but then how come the if sentence states false? Maybe I need to convert the value getHostAddress() before comparing?

Re: [HELP] IP compare

Posted: Fri Oct 02, 2009 1:06 pm
by Gnacik
Try:
String playerip = getClient().getConnection().getInetAddress().getHostAddress();
String targetip = targetPlayer.getClient().getConnection().getInetAddress().getHostAddress();
if(playerip.equals(targetip))
{
}

Re: [HELP] IP compare

Posted: Fri Oct 02, 2009 1:37 pm
by janiii
DON'T compare strings using == operator! use equals method instead!