-1
\$\begingroup\$

So I'm currently developing my own protocol on top of the already existing protocol, TCP.

This is what I'm thinking..

When the client connects, it's going to send a packet to the server with the username and password in order for the server to check whether that player exits or not, if it does exist it's going to send back a packet to the client that tried connecting saying "Successful connection". When the client receives this packet it's going to spawn the player into the game world. Once the player has spawned in, it's going to send another packet to the server saying "I'm in" which the server then will interpret as "Okay, a new client has landed in the game world, time to notify all the other already connected clients" so the server sends a packet to all of them in which they can add a new player object to their "internal" list of players.

Here is the issue.. The client that connected has no idea about the already connected clients.. How on earth do I add them to it's internal list of players?

Is this a good structure? What's a good way of notifying the connecting client that there are players already on the server?

\$\endgroup\$
4
  • 5
    \$\begingroup\$ What is so different about a player from other game objects? How do you tell your clients that "a monster" has spawned? \$\endgroup\$
    – Vaillancourt
    Aug 28 '20 at 22:33
  • 1
    \$\begingroup\$ When the client tells the server "I'm in", have the server send back a list of current clients. If this makes the packet too large, you can break it into multiple packets. \$\endgroup\$
    – Kevin
    Aug 28 '20 at 23:44
  • \$\begingroup\$ @Kevin I was thinking about that but I'm not sure how to serialize a list, I guess I need to look into that \$\endgroup\$
    – RileyDan
    Aug 29 '20 at 0:31
  • 1
    \$\begingroup\$ You can serialize anything, using any combination of manual serialization code or existing APIs/plugins. \$\endgroup\$
    – Kevin
    Aug 29 '20 at 0:52
0
\$\begingroup\$

As Kevin rightfully noted:

When the client tells the server "I'm in", have the server send back a list of current clients ("here're clients"). If this makes the packet too large, you can break it into multiple packets.


You can also think of this packet to be of the same kind as the one you named "Okay, a new client has landed in the game world, time to notify all the other already connected clients". Make it a "new clients packet". This packet will contain a list of clients. One client when notifying already connected clients about the new client connected. Many clients when server inform newly connected client about already connected clients. This also makes it easy to split large lists into chunks by sending slices of the clients (e.g. 30 per packet).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.