KryoNet - Suppress multiple connections from same user?

Hello,

I am using KryoNet to implement multiplayer functionality in my game. Now I don’t want the same person to play more than once on the same server. Or to describe it a bit different: I don’t want the same person have more than one connection established to the server.

Now I know you can’t always suppress this. When someone is on different hosts/machines, he can do that. But at least I want to suppress more than one connection per machine.

How can I do that using KryoNet? Does KryoNet have such a functionality or do I have to code it myself?

I would be glad if you could share your wisdom with me.

I don’t have access to my code on this computer but…

You should be able to grab the host information from the connection and do a match to the other connections to make sure there are no equals.

Building on kalkitus’s post:
You could have an ArrayList that with each connection, you check if it contains the IP. If it is, just close the connection. If it isn’t, add the IP to the list.

Thought the same, but with Mac addresses obviously these should be unique to each PC/device

AFAIK, each device can only have 1 IP address.

Ok, but I would want to remove disconnected connections from the list. As far as I know you can’t grab their IP/host anymore when they’re disconnected, can you?

In that case I would need to iterate over the whole list and check for the disconnected connection id?

If they come from the same LAN, they will have the same IP address. Unfortunately, this can not be helped and will cause problems, if they play the game from work, school, open wifi, etc.

Here’s what you can have in your server listener:


			public void connected(Connection c){
				Connection[] connections = server.getConnections();

				for(int i = 0; i < connections.length; i++)
					if(c.getRemoteAddressTCP().equals(connections[i].getRemoteAddressTCP()))
						c.close();
				
			}

I haven’t tested it, but you can see the general idea here. Also, now that I think of it, it should be in the received method so that you may send back a error message to why the player was disconnected from the server.

every house / apartment with more than one human living in it, have a lan and use a router, wifi or not makes no difference.

I work in a hospital also, EVERYONE, every patient, every worker, just everyone has the same IP to the outside.
Schools, Hotels, Internet cafe’s whatever - the list goes on.

IP has little meaning. Rarely points to only one person.

Such controls must not be done at the IP layer because a lot of machines can share the same public IP address on Internet (when theses machines are on a LAN)
You should envisage an authentification protocol (based on a registered account) and refuse to have the same account with 2 connections in the same time (whatever their IPs are).

That is a given. Not allowing to log into the same account more than once.

But I also want to prevent the same person playing with more than one account on the same server (at least on the same machine).

Well then you need to compare InetSocketAddresses because that stores the outbound port used by the client.

I agree. I was just giving some simple examples; open wifi being like a cafe or a downtown hot spot.

It’s possible to grab the MAC (unique to the machine) of the network card being used by the client and have that client send that MAC to the server to store and compare to other clients.


import java.net.InetAddress;
import java.net.NetworkInterface;

public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress addr = InetAddress.getLocalHost();

    NetworkInterface ni = NetworkInterface.getByInetAddress(addr);
    byte[] maca = ni.getHardwareAddress();

    for (int k = 0; k < maca.length; k++) {
      System.out.format("%02X%s", maca[k], (k < maca.length - 1) ? "-" : "");
    }
  }
}

Source: http://forums.techarena.in/software-development/1295054.htm

An option is to let 2 accounts with the same ip to connect in the same time and on the other side create a tools that track theses situations in order to control theses semi-manually.
When you detect such situation, you can imagine request an “identity check” (manually or not)
You can also create a white liste of IP that being known as public site…

So, you can go on the “IP” blocking system, but you can loose a non-negligeable target (school, work station, family, …)

In all case, it’s not a simple problem.
The best way is to discourage to run into multiple accounts by providing a well fitted game’s contents (like social /guild, palmares / high score, etc…) that “force” the player to concentrate it’s effort inside a single account for “be” the best.

I guess I’ll use the mac address solution. Any objections to this?

Also, how could I make a KryoNet client send his mac address during connect (not after the connection is established, during establishment)?

A quick Google search led me to this neat class: java.net.NetworkInterface
I assume you would do:


byte[] MAC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")).getHardwareAddress();

You can’t. You’re going to have to connect, send the MAC address, then close the connection if it is a duplicate :\

What you should do is log connection attempts so if someone is spamming with multiple invalid connection attempts, you can choose to temporarily block the address from connecting. (Well, only if this becomes a problem, otherwise, I think the MAC address fix should work well)

Just to note: When talking about security issues, you couldn’t do it this way.
Since mac addresses can be faked/changed.

Obviously in game development i don’t think its important

I would just use the whole account approach; 1 account cant connect to two games at the same time, not even login and stuff

He already has that implemented he says, and this is still good to have. If you think about it, you can make it so you can run any game you’re not suppose to run multiple instances of locally on the same machine. However, most people won’t go through the hassle.

IP and Mac filtering wont work as already pointed out it will result in way too many false positives.

To combat this you will need to have the users install some kind of spyware like Punk Buster. Even spyware wont protect you if the user simply uses 2 different computers so it’s probably better to just accept it.

sorry to dredge up a post so far behind, but this is not neccesarily true. LANs aside, a single computer can have more than 1 IP address. This because each NIC (network interface card) has an IP, so if you have more than 1 NIC, you have more than 1 IP.

just in case you ever needed to know that :slight_smile: