• Advertisement
Sign in to follow this  

Question about manage game room for multiplayer game

This topic is 1924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My Java exercise is creating a card game like Microsoft Hearts plus multiplayer via internet.
I decided to let player create game room.
When player clicks button create game, a signal is send to server, and server creates a game object. This game object is managed by using an arraylist.
The problem is if this game is destroyed, others player don’t know it was removed. They choose game from their lists and send it back to server.
If I send an object, I can use arraylist.contains(…) to determine if this game still exist or not. However, I think this way is not good because we must loop all array for each client request. This is not efficient (I assume we have a lot of players at the same time)
I move to other way. I send index of the game I choose. At server, I get the game with this index. If the comparison returns true, this game is still there and vice versa. It sounds good but new problem appears. Let see this example:
We have
Game : a b c d e f
Index : 1 2 3 4 5 6
We remove c
Game : a b d e f
Index : 1 2 3 4 5
In this case, player chooses game “c”, we can definitely say “c” is out. If player chooses game “d”, he sends to server index 4. Now, 4 is game “e” and the comparison return false. We say game not existing, but its index is 3. It is still there.
Hic. I don’t know how to do. I hope receiving advice from you. Thx a lot. Edited by KhoaVN

Share this post

Link to post
Share on other sites
You should identify rooms with unique IDs. That can be some number allocated by the server, that doesn't change, or some name that's enforced to be unique.
You should keep the mapping from id to actual room instance as a hash table / dictionary, rather than an ArrayList.
Thus, when you race, so that the player says "join room X" while the message "room X is going away" is on the wire, you will see that X is no longer in the dictionary / hash table, and you can return the error "that room no longer exists."

Share this post

Link to post
Share on other sites
I checked some games and I found something. I do not know if what i thought is right or wrong.
The games I play are Teeworlds, Begone, and league of legends. I guess:
- In Teeworlds (2D scrolling shooting) and Begone (FPS), each game host on different server. We connect to server of game developer (let us call it: main server) to get IP and port of game host. After receiving IP and port, we connect to game host and play. This way, main server's job is very easy. It just manages players' state to decide which player should receive update info (game host list ...). It also does not worry about game state. It just maintains game list and receive game status (like full or not full, max player). If game host is turned off, it removes game out of list. We cannot create our games following this way. If we want to own a game, we must run another game host.
- In the other hand, LOL give us an ability to create game. Therefore, I guess there is just one server for all function. I create game, join game on the given server. It also means that server must be super strong to handle all things.
The first way seems to be easy to implement. Each game manages its resources on its host. Main server is dedicated to process updating game host info and player info to clients. However, for card game, we do not want player waiting for someone hosts the game to join. If there is no game host, no one can play. We want player create account, login and join game. If there is no game, player can create game by himself.
Therefore, we move to second way. All things are in the given server. It is only one. This way seems to be suitable. However, I wonder if it is theory or practice. For each connection, we need a pair of sockets and one thread to hold communication. For each game, we need at least one thread to run. For instance, we have 400 players and 100 games (4 players per game); we will need 400 threads of communication + 100 game threads + 1 listening thread (and more for server system). The server must be strong to handle things. Is there any server out there strong enough for this (of course not super mainframe computer)?
Above is what i draw from playing and watching game. I know I miss many technical details and knowledge. With the famous and massive game like LOL that has thousands of people and thousands of games at the same time, the story will be different.
Now, I am very confused how to create a good client-server game. I need tutorials and advices. I search through internet, but there is not much information. I tried with “game lobby”, “game room management” key word, but they doesn’t give me useful info.
I need help! Edited by KhoaVN

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement