Starting to get it, but not - Multiplayer Card Game

Actually I realize I already have a list of players on clientside to keep track of Players that are logged in, I think I have an idea of how to do this, I will prob come back soon with problems though :-X

hmm right so I guess you can send any object, I was just missing a default no parameter constructor.

I have a design question, how would you handle telling the user what cards he has, and then telling the server which card he wants to play.

I was thinking of re creating the Player object with a list (Hand) which would hold the cards the player has, so server side it will add 13 cards to the Players hand and then tell the client which cards were added and then the client will add them and display them. Then the client side will display the cards on the board and if one of them is clicked then it will tell the server, the server will check and see if the player actually has that card and then notify the game that the user played the card. Also this method would require me to have a “Player object” created for each client also, but I believe I should keep the client as thin as possible, basically just being a Visual of what is happening on the server

Is this how you would do it?

Yes, to prevent cheating and hacking, it is best if the server has all the logic and the only thing clients do is send back what the user clicked on and typed.

That is a decent way of doing it.

You can think of the game as a simulation that is running on both the server and the clients. The server simulation has all the information and is authoritative about what is valid, etc. When the server simulation changes, updates are sent to the clients to update their simulation. The client simulations may not have all the information, eg they may know how many cards other players have, but not what the cards are. So, some of the data may need to be “cleaned” or even omitted (eg, in another game the server would know about an invisible character but this info shouldn’t be sent to the clients). It may be worth it to use some of the same objects on both the server and clients. Often the same logic is needed in both places. Eg, the client needs to know what are the valid plays for a card so the GUI can make that clear to the user, and the server needs to know that same information to make sure the client isn’t trying to make an invalid play. You might be able to come up with some clever coding where the clients’ simulations are automatically kept up to date when the server simulation is modified. Your GUI could take a simulation to render. This would also allow you to rendering a GUI for debugging the server simulation.

Ahh thank you that makes great sense, I realize that some data may need to be “cleaned” but am wondering if I am doing it properly. When the game is started a user is given a hand (this is just a test it of course wont work like this in the actual game) and that hand is placed in the Player object, however when a user connects it is sent each player object to let it know who are logged in, however I realized that the Player object holds a hand and I dont want the client having access to other players hands so I decided to send it a copy of the Player but with a null hand. Is this what you were referring to?

I was even thinking to just send the Client a String with the player name because it has no reason for having an actual Player object for each player…

**Hmm do you think its better to just create a new Player object on the client side and then fill in its hand through the use of Packets, or would it be even smarter to just have a “Player” object hold the players information and then the GameTable could have a HashMap of <Player, Hand> that way the GameTable will map which player has which Hand, and then if they leave the table they will no longer be tied to the hand because it would make no sense for a player in the Lobby to have a hand correct?

Thanks again for the help guys, I really appreciate it! I know it seems like I am just throwing out so many ideas but I am just trying to get straight what I want to do and see different ways things can be done.

Btw Nate, KryoNet is BALLER! Thanks for it!

I think it depends on how your game is structured. If you are going for a lobby-style approach with game tables and such, then when a player connects, all the players in the lobby will be sent a message (‘Hsaka has entered the lobby’ or maybe just an integer representing the number of players currently online). Then a player could make a request to the server to get a list of the names of players online if he wishes to see that. When a player clicks on a table, he would get a message with a list of the names of the players in that table. No need to send objects across the wire when only a subset of the information in them is actually being used by the client.

[quote=“Swattkidd7,post:24,topic:36765”]
On the server, I would just have an array field in the Player object for the hand. The game table would maintain a list of player objects in it. When a player leaves, they are removed from the game table’s list and added to the lobby’s list. On the client, when the player is dealt a hand, the server sends the hand to the respective player and the client stores it in his own array.

Hey guys I just want to say thank you for all the advice you have given, it has helped me make tons of progress on this project.

However, of course, I have another issue. When trying to connect to both TCP and UDP ports I get the error “Connected, but timed out during UDP registration.”

This works for local ip 127.0.0.1, but when I use my actual static IP it gets this error. Also I am able to connect to TCP only but its UDP that has trouble. I have also forwarded the proper UDP port and TCP port so I am not sure what could be wrong.

Thanks in advance!

I googled the error and I found this:


      synchronized (tcpRegistrationLock) {
                                while (!tcpRegistered && System.currentTimeMillis() < endTime) {
                                        try {
                                                tcpRegistrationLock.wait(100);
                                        } catch (InterruptedException ignored) {
                                        }
                                }
                                if (!tcpRegistered) {
                                        throw new SocketTimeoutException("Connected, but timed out during TCP registration.\n"
                                                + "Note: Client#update must be called in a separate thread during connect.");
                                }
                        }

            This is code from the Kryonet TCP and UDP client/server library for Java. The error thrown here seems to have some more information. I'm not sure if this helps you but I found it, and you can has it. Note the note: Note: Client#update must be called in a separate thread during connect.

This is the web site it was on: http://code.google.com/p/kryonet/source/browse/trunk/kryonet/src/com/esotericsoftware/kryonet/Client.java?r=69

Silly question: Why do you need UDP for a turn based card game?

Hey Thanks for that! I will definitely look at that and try it out, seems like I will need to connect in a separate thread.

And the UDP isnt needed for the card game, I was just trying it out :slight_smile: