I'd like to build an iPhone game for the Game Center and am currently researching the server part of it all. I learn best by example and I'm having a hard time finding any examples of simple game servers that demonstrate...
- How data is formatted and sent to the server and how it is received
- How to authenticate the data that is being sent/received to avoid players cheating, etc.
- How the game server code is structured along with the DB
I'd like to build the game server using Ruby on Rails, though I'll settle for any examples using any framework just to understand how these concepts work. Does anyone know of any books or online resources that has covered this or shows some example code on how to bu开发者_运维百科ild a game server?
I would have to think that most multiplayer games on the iPhone require a gamer server, yet I can't seem to find any resources that discuss how to build one. Ever resource I find that discusses building multiplayer games (including Apple's docs) says the same thing, "Developing a game server is outside the scope of this book, but we’ll focus on the client side code necessary to connect to such a server."
Thanks so much in advance for your help!
EDIT: A few more details about what I'm trying to accomplish...
I'm trying to develop a two player (possibly more) game that where the users compete to solve a puzzle faster than the other player. Match making will be handled by the Game Center, but I'll need a game server that will start/manage the games and store the results in a DB. The overall process will be something like...
- Game Center pairs up two players
- The player data is sent to the server to initialize a new game
- The start of the game is synchronized by the server
- The game starts and each player attempts to solve the puzzle
- When either player finishes, the server is notified
- As soon as both players finish, the server responds with the results and the results are stored on the server.
OK, after reading your edit, Node.js should do the job quite well I think.
Regarding your points:
I don't know how exactly the pairing works(guess you get a pair of keys or so to validate the requests) but it should be hard to implement, regardless of the programming language.
Easy: Setup a server, handle connections, keep a list of running games, for each game keep track of the state(players, time etc.), that should be at maximum(well depending on the message procotol you use..) 150-200 lines
Just send some kind of ready event to each of the players in a given game when you deem that game to be ready(like everyone touched the 'I'm ready' button or so)
OK, some tips here:
Track the remaining/passed time on the server and send it to the players, timers get off pretty quickly(I had 4-5 secs off in just about 3 minutes)
To prevent cheating, validate the moves on the server, that should be fairly easy in case of a puzzle game. You could also check the times between each move everything below 50ms should be suspicious, but that mainly depends on the difficulty of the puzzles.
By checking the moves on the server this is pretty easy too, you don't have to rely on a client sending you a "Look I'm done" message.
Again easy, just send out the events with the accompanying data and log the points into the db.
The most important point is obviously the prevention of cheating, in case of a puzzle game where the solution can be easily solved by a computer, it's impossible to prevent it completely. Although, with the tips above you can make it harder.
But keep in mind, you can't stop people from cheating on the high-scores when the game is simple, building more and more protection into the game just doesn't make sense. Focus on the game-play, make it interesting and simple for humans but complex and unpredictable for computers.
In case of the DB, uh... I suppose you could go with MongoDB for that, but I haven't played around with that under Node yet.
Oh, and if you want a impression what you can do with Node.js here's the game that I've built:
http://github.com/BonsaiDen/NodeGame-Shooter
All the logic runs on the server, the clients just draw the stuff they know about, I had a playable prototype up and running in two evenings.
I recently built a client server application, the server side was based on Netty. There are a number of great examples of how things might be able to work on their website. It turned out to perform well also. For a game you might also consider utilising Google ProtoBuffers - an example of this is also on the Netty site.
Just so you know, the GameKit API includes functionality to allow you to send data to the other players in your game. You might want to consider using this instead since it will save you a lot of work building a game server from scratch and you get to make use of Apple's well-tested networking infrastructure.
精彩评论