Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on learning network programming. I'm working on a simple card game. The basic idea is:

Players enter the lobby
Players see tables
Players sit at an empty seat

Once they sit, they do not need any information from the lobby, they see the card table and the data about the other players and so forth.

I've programmed the server portion for the game itself. The clients connect to my server object and the server then receives and sends messages; quite simple.

The tricky concepts for me are:

What's a good way to run many tables at the same time?
What's a good way to keep the lobby consistently updated for each person in the lobby (eg: MSG_TABLE_FILLED, 22)

Ideally I'd like to have 1 server exe for all of this and to have to deal with multithreading as little as possible.

I'm going to use the enet library.

I was thinking that each time a game session starts, I push a new Game and I map the client IPs to that table, then I just route messages from those clients to that Game.

Since enet supports channels I was thinking of using 2 channels per table, one for the game messages and one for in game chat.

Would something like this work?

Does anyone have any advice / design ideas for a game with a lobby and many tables? Is there a usual way this is done that I'm overlooking?

Any conceptual ideas or even c/c++ code examples would be very helpful.

Thanks

share|improve this question

migrated from stackoverflow.com Nov 23 '11 at 23:28

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer 1

up vote 5 down vote accepted

First, don't use the IP address. IP addresses can change and UDP is stateless. Instead, assign each client a session and have them pass the session ID back to you in each message. The enet library already does this. The event structure will tell you the ID of the client.

You'll need to keep a structure for each peer. That should include whether the peer is in a game or not, and if so which game they are in. Also store in the game structure a table of which peers are in that game.

When a message is sent to the lobby, iterate over the table of peers (or a table just of peers in the lobby) and send the message to each peer. When a game message is received, look up which game that peer is in, and send the message to the handler function for that game object.

I'm not sure what else to tell you at such a high level.

share|improve this answer
4  
Also, with NAT in the picture, there could be more than one user represented by a single IP address. –  Randolf Richardson Nov 24 '11 at 1:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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