Multiplayer Questions

I am working on creating a 2D game for fun to learn some of the many and multiplayer games. The game itself will smash the armies of two players against each other in a strategic turnover battle. I am developing it as a standalone desktop client (then maybe a phone app eventually).

I am writing a game in Java and I do not trust the client, so I take security into account. Players will have a personal account with their army rosters etc. that will live on the server. Also, I am planning on using mySQL to store such data on the server.

I'm not sure how to implement this. Am I using something like a web server? It seems to be wrong, but I don't know what technologies to use for Java frontend and backend where client is not trusted. Please note that I am not looking for a discussion on the best way to do this, I just need to know the concepts, maybe some technology examples and maybe a link to a tutorial.

Thanks for any help!

+3


source to share


2 answers


Unless you plan for this to be a browser game, I don't think using a web server would be a better idea.

Sockets might be the answer you are looking for, with them you can create your own communication protocol that does not trust the client.

The server will need to use the server socket and accept multiple clients.

You can also use Swing for the client UI.

Here is the default java Sockets tutorial.



For example, your protocol might include the following commands: (Client to Server) Move (UnitGroup, Point) - Tells the server where you want to move the group to a point, then the server performs calculations to determine how long it takes for the units to profit and began to move them.

(Server to Client) PositionUpdated (UnitGroup, Point) - Tells the client that the group has moved somewhere and may need to be updated on the display

If you publish your protocol, players can even make their own clients to watch the game as they please. Your server will keep it fair by giving clients what they need to "see".

I don't know how this might affect latency.

+5


source


Just add a little to Psetmaj's helpful answer:

Your game client and game server will be dealing with structures (lists, etc.) that you use in a very Java-centric way. The part you are not running into yet is figuring out how to package these commands and structures for transport in TCP or UDP and then unpack them on the other end. This is called "sorting" (when you pack the payload) and "de-marshalling" (when you unpack it and turn it back into something Java can understand). In fact, the "hard" part about this is that it is very tedious and has to happen for every other message that goes back and forth.



My advice is to work on a library of helper functions as you go along, which is responsible for converting the structs you are using and from the view they will have when they are sent and received over the network. This view can be textual like AJAX or binary like Java RMI, depending on what you decide to try.

+3


source







All Articles