Ark1409
Ark1409

Reputation: 25

Online Multipler Games in Java

In Java, is there a way to make a client/server system for a game without having to enter ips (like in Minecraft). But instead, have it automatically connect the user to a game when he requests to join one (like in Fortnite, or surviv.io).

The only method I current know for client/server is having to give each user a server ip to connect to (like in Minecraft), so I was wondering if I could do it this way.

Thanks in advance.

Upvotes: 0

Views: 143

Answers (1)

Kong
Kong

Reputation: 23

IMHO, I think in all ".io" games, they are only hiding the registration processing. In my case, the previous game I made had a feature calls "Quick Play". When a player uses that playing method and first time joins the game, I get his device's ID (for example in Android) then use it as a unique ID for that player in-game (I'm not sure about iOS but you can get that unique value in Android). You can see the example below:

_on(TEvent.CONNECTION_SUCCESS, args -> {
            var connection = Connection.convert(args[0]);
            var message = TObject.convert(args[1]);

            info("CONNECTION", connection.getAddress());

            // Allow the connection login into server (become a player)
            String username = message.getString("u");
            // Should confirm that credentials by data from database or other services, here
            // is only for testing
            _playerApi.login(new PlayerLogin(username), connection);

            return null;
});

Now when a new user login, he will send his device's ID and I can treat him a new player and make that ID as his name (or making a randomized name for him)

You can see more detail in the link below: Login Example

Upvotes: 1

Related Questions