• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [Solved] Listing servers for client

X

XirmiX

Guest
So, I've been following this tutorial (and the previous videos) about how to set up a multiplayer connection, registration and login and so forth. I have made certain things different for myself, however... first of all, the client holds onto all of the registrations and login details, the server doesn't hold onto it. Secondly, I'm aiming to have the server listed for all the clients, before joining. There not being a master server of any sorts, the servers being something that players can host and then when while they are up, players can select them and join them. Here's part 4 of the set of tutorials I followed:


Question is, how do I do that? I would guess I need to have, inside the obj_controller's networking event (I have most of what is featured in the previous videos as is in the tutorials, except for parts on where the player account information is stored and how it's handled. Some of the information from the 4th tutorial, the one I posted above, is also in my code, but it's indented for now, so I don't get any glitches or errors while I'm trying to get this through) for both client and server something so that the client would receive information from created servers and for the server to send to the client "yeap, I exist! You can join" and then for the client to have a bar pop up in a room, which then can be clicked to join the server. If I understood buffers and how they work and such, I could probably write this myself, but for the moment, I'm not at that skill as of yet (but might be soon).

Here's the networking data in my Client
Code:
///Check for server and data
{
var eventType = ds_map_find_value(async_load, "type");
switch(eventType)
{
    //Transfer data between the client and the server
    case network_type_data:
        var buffer = ds_map_find_value(async_load, "buffer");
        buffer_seek(buffer, buffer_seek_start, 0);
        scr_handleIncomingPackets(buffer);
    break;
}
}

And my Server:
Code:
{
var eventType = ds_map_find_value(async_load, "type");
switch(eventType)
{
    case network_type_connect:
    //Add the client to the socket list
        var socket = ds_map_find_value(async_load, "socket");
     
        ds_list_add(global.players, socket)
     
        //send player id
        buffer_seek(global.buffer, buffer_seek_start, 0);
        buffer_write(global.buffer, buffer_u8, 2);
        network_send_packet(socket, global.buffer, buffer_tell(global.buffer));
     
        scr_showNotification("a new player has joined");
    break;
    //Remove the client from the socket list
    case network_type_disconnect:
        var socket = ds_map_find_value(async_load, "socket");
        var index = ds_list_find_index(global.players, socket);
        if (index >= 0)
        {
            ds_list_delete(global.players, index);
        }
     
        //Player leaving
        var playerLeavingId = 0;
        with(obj_player)
        {
            if (playerSocket == socket)
            {
                playerLeavingId = playerIdentifier;
            }
        }
        scr_showNotification("a new player has left");
    break;
    //Transfer data between the client and the server
    case network_type_data:
        var buffer = ds_map_find_value(async_load, "buffer");
        var socket = ds_map_find_value(async_load, "id");
        buffer_seek(buffer, buffer_seek_start, 0);
        scr_handleIncomingPackets(buffer, socket);
    break;
}
I know I need something to add to these two, but what? And of course, the room and the pop-up button that should show up in a server list... which, too needs creation, man, there's a lot of stuff that needs making for setting up multiplayer!

EDIT: While waiting for answers, I looked up on the manual about ds_lists and buffers... yeah, I cannot comprehend how to use them, buffers especially.
 
Last edited by a moderator:
X

XirmiX

Guest
Anybody? Sorry if I'm bothering, but I really need some input from others on this, because I'll be stuck if I don't, since I don't have much of an understanding of buffers, ds_lists and packet handling. If I at least get some help and get some better explanation on these things (because right now, what the manual provides me in terms of the information about them is partially incomprehensive to me), I could probably create a functioning server list myself.

On another note, I thought a bit about ports... do different servers need different ports? If so, how would I be able to allow players to host their own servers, while insuring that servers hosted don't get the same ports, crashing each other or having information collide and malfunction if that were to happen or whatever? Like, if two servers have set the same port in network_create_server (e.g. 40000) would it be fine, or would problems occur?
 
F

Fishman1175

Guest
Sounds like you want a web server to handle connections/matchmaking players. It also sounds like you are pretty far away from achieving this.

Players only know how to connect to another computer if they get told where. Since the IP address of players changes, and people don't readily know their IP address, this is a hassle.

A web server (written in PHP, or other similar language) is always in the same spot, like www.mymatchmaking.info (the URL gets resolved to an IP automatically). There a many free web hosting sites that give you enough resources for development purposes. I use 000webhost and it works great for me (but they have had hack issues in the past, free hosting is totally fine for dev purposes, but never buy hosting from them..)

Games connect to the server. They tell the server they are hosting a game. The server can tell what the players IP address is, and it can tell other people that connect to the server what their IP address is. Game maker has http_post and similar functions for interacting with web servers.
 
Last edited by a moderator:

Xer0botXer0

Senpai
If the client holds onto the registration info, does this include the password ? if so, then there's no need for a password and anyone can login as anyone.

In regards to you wanting to list multiple servers for the clients, this is not possible without a third party application or web page that collects the ip address of servers coming online.
 
X

XirmiX

Guest
You need a web site for client to get info about servers? Is there really no other way?

What about if I tried to make it so that the player connects to all of the servers when they log in, but in a different way, so the information of the match (i.e. the world itself wouldn't be displayed to them) and the clients who are connected to the server's room itself. Question is whether this would cause huge lag for everyone? Of course, the info about a server's map and players in it I plan to load up only when you click on it, which is when you would also have the join button for that particular server pop up. But right now, I simply want to have a list where instances of an object with a server bar sprite pop up for each hosted server. So, perhaps the clients can all send their IP addresses to the servers or whatever is needed, and then servers will know to pop themselves up for the players. So, it would be like first you're connected to all of the servers, but in a different way, and then you connect to just one server and have the map of the server and their character and other player characters shown?

So, based on what you said, two servers can't have the same port? Cause I'm still confused about that as, again, I don't have much experience with networking.

@Xer0botXer0 yes, yes, I've been told that logging in is pointless if client holds onto all of their data, but considering that it's a game where your account information would need to be saved so you can keep your progress and so other people can play on your machine, but with their own track of progress, logging in is needed. Since I don't want a central master server (because that would be pointlessly expensive) and people troll-stealing usernames, this is probably the better bet. If you check out a topic I made two topics ago from this one, you would know that each player gets a unique, 16-digit player ID generated. Provided, you can still get the same ID as another user, since there is no central server getting the info about player IDs, but the chances of that happening are small and if that does happen, players can change their ID anyway, if they can locate where their account data is stored and even then, what problems would this really cause? It's two different machines and two different clients, so if two players with the same ID did meet each other on a server, I don't see how the game would crash. The ID's purpose is for something else entirely anyway and it has to do with the fact that players get to have the same username.
 
Last edited by a moderator:
X

XirmiX

Guest
Is there really no way of doing what I want to without a web site? Would the method I proposed work or wouldn't it? Or it would, but would cause a lot of lag?
 
X

XirmiX

Guest
I just thought of a great way to do this, but the question is, is whether this would actually be feasible...

So, you have each player who logs in have a button they can press in order to get connection with other players. This button would send out a code to the network. The client would essentially be telling the network "connect me to everyone else who has this code". The network checks through whomever has also sent out the code and matches all the clients together through itself. But how exactly would I do this through code? Or would the network simply not let me do this?
 
F

Fishman1175

Guest
"The network" is around 340000000000000000000000000000000000000 device addresses. Not feasible.
Unless you only want LAN, then use network_send_broadcast(). There are YoYo tutorials that demo it.
 
X

XirmiX

Guest
"The network" is around 340000000000000000000000000000000000000 device addresses. Not feasible.
Unless you only want LAN, then use network_send_broadcast(). There are YoYo tutorials that demo it.
So, I'm guessing there's no way for "the network" to simply listen for special code from every user around the world, and the moment somebody sends the code to it, at that moment it will connect that user to anyone else who has sent it to it.

If I do set up a website, it will probably need to be one which is a child of another site, such as Weebly, so I don't have to pay. I really don't want to muffle up in monetary interactions when it comes to this game, because the game itself needs to be completely free so that I would not get any issues coming from a certain company, who's game this one is based off of. It's not a straight copy, but there will be a lot of things that in concept, games have in common. The main difference being that theirs is 3D and mine is 2D.
 

The-any-Key

Member
GMnet use a small java server (cost $5/month).
The clients contact this java server and get a list of all game servers from it.
 
X

XirmiX

Guest
@Fishman1175 cheers for that, I'll possibly get back to server listing once I actually have an MMO going.

GMnet use a small java server (cost $5/month).
The clients contact this java server and get a list of all game servers from it.
Thanks for the offer, but I'd rather use free ones, at least for this one game that I'm making, because it will be free of charge as well. Having to pay for a site that will hold a server list for a free game while I'm broke isn't going to do the game any favour.
 
Top