[HELP] IP compare

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
xrs
Posts: 25
Joined: Thu Sep 24, 2009 11:05 am
Contact:

[HELP] IP compare

Post 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?
User avatar
Gnacik
L2j Veteran
L2j Veteran
Posts: 925
Joined: Tue Dec 16, 2008 3:49 pm
Location: Wąchock ٩(̾●̮̮̃̾•̃̾)۶ Polska
Contact:

Re: [HELP] IP compare

Post by Gnacik »

Try:
String playerip = getClient().getConnection().getInetAddress().getHostAddress();
String targetip = targetPlayer.getClient().getConnection().getInetAddress().getHostAddress();
if(playerip.equals(targetip))
{
}
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: [HELP] IP compare

Post by janiii »

DON'T compare strings using == operator! use equals method instead!
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
Post Reply