Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  KryoNet - Suppress multiple connections from same user?  (Read 4763 times)
0 Members and 1 Guest are viewing this topic.
Offline onra

Junior Newbie





« Posted 2011-08-03 17:31:23 »

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.
Offline kalkitus

Senior Newbie


Medals: 1
Exp: 6 years



« Reply #1 - Posted 2011-08-03 18:37:02 »

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.
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2011-08-03 18:41:52 »

Building on kalkitus's post:
You could have an ArrayList<String> 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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2011-08-03 18:44:05 »

Building on kalkitus's post:
You could have an ArrayList<String> 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

Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-08-03 18:46:06 »

AFAIK, each device can only have 1 IP address.

Offline onra

Junior Newbie





« Reply #5 - Posted 2011-08-03 18:56:33 »

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?
Offline kalkitus

Senior Newbie


Medals: 1
Exp: 6 years



« Reply #6 - Posted 2011-08-03 18:57:37 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
         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.
Offline Cero
« Reply #7 - Posted 2011-08-03 19:12:46 »

if they play the game from work, school, open wifi, etc.

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.

Offline divxdede

Junior Member





« Reply #8 - Posted 2011-08-03 19:15:10 »

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).
Offline onra

Junior Newbie





« Reply #9 - Posted 2011-08-03 19:23:31 »

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).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-08-03 19:31:44 »

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

Offline kalkitus

Senior Newbie


Medals: 1
Exp: 6 years



« Reply #11 - Posted 2011-08-03 19:37:07 »

if they play the game from work, school, open wifi, etc.
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 agree. I was just giving some simple examples; open wifi being like a cafe or a downtown hot spot.

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).

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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
Offline divxdede

Junior Member





« Reply #12 - Posted 2011-08-03 19:47:41 »

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).

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.
Offline onra

Junior Newbie





« Reply #13 - Posted 2011-08-03 20:01:50 »

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)?
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #14 - Posted 2011-08-03 20:44:32 »

A quick Google search led me to this neat class: java.net.NetworkInterface
I assume you would do:
1  
byte[] MAC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")).getHardwareAddress();

Offline counterp

Senior Member


Medals: 11



« Reply #15 - Posted 2011-08-03 22:29:33 »

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)?

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)
Offline Cero
« Reply #16 - Posted 2011-08-03 22:32:32 »

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

Offline counterp

Senior Member


Medals: 11



« Reply #17 - Posted 2011-08-03 22:34:42 »

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.
Offline zoto

Senior Member


Medals: 4



« Reply #18 - Posted 2011-08-04 00:05:39 »

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.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #19 - Posted 2011-08-04 01:03:36 »

AFAIK, each device can only have 1 IP address.
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 Smiley
Offline static_flashlight

Senior Newbie




Software Engineer


« Reply #20 - Posted 2011-08-04 01:09:01 »

A quick Google search led me to this neat class: java.net.NetworkInterface
I assume you would do:
1  
byte[] MAC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")).getHardwareAddress();


Never really thought about this kind of application development area before.  Very cool idea, I'm liking it.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!