简单游戏服务器的代码示例 [英] Code examples for simple game servers

查看:208
本文介绍了简单游戏服务器的代码示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为游戏中心构建一个iPhone游戏,目前正在研究服务器部分。我通过示例学习最好,我很难找到任何简单的游戏服务器示例,证明...

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...


  1. 格式化并发送到服务器及其接收方式

  2. 如何验证正在发送/接收的数据,以避免玩家作弊等。

  3. 如何将游戏服务器代码与DB结构化

我想使用Ruby on Rails构建游戏服务器,我将使用任何框架来解决任何示例,以了解这些概念如何工作。有人知道任何书籍或在线资源,涵盖了这一点,或显示一些示例代码如何构建一个游戏服务器?

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 build a game server?

我不得不认为iPhone上的大多数多人游戏都需要一个游戏服务器,但我似乎找不到任何讨论如何构建游戏服务器的资源。资源我发现讨论建立多人游戏(包括苹果的文档)说同样的事情,开发一个游戏服务器是在本书的范围之外,但我们将关注客户端代码连接到这样一个服务器。

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."

非常感谢您的帮助!

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...


  1. 游戏中心配对两个玩家


  2. 游戏开始时由服务器同步

  3. 游戏开始,每个玩家尝试解决难题

  4. 当任何一个播放器完成播放时,都会通知服务器

  5. 一旦两个播放器完成,服务器就会响应结果,结果存储在服务器上。

  1. Game Center pairs up two players
  2. The player data is sent to the server to initialize a new game
  3. The start of the game is synchronized by the server
  4. The game starts and each player attempts to solve the puzzle
  5. When either player finishes, the server is notified
  6. As soon as both players finish, the server responds with the results and the results are stored on the server.


推荐答案

关于你的观点:


  1. 我不知道配对是如何工作的(猜测你得到一对密钥等来验证请求),但它应该很难实现,而不考虑编程语言。

  1. 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.

简单:设置服务器,处理连接,保存运行游戏列表,每个游戏跟踪状态(玩家,时间等)取决于你使用的消息procotol。)150-200行

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:


  1. 在服务器上跟踪剩余/通过的时间,并将其发送给玩家,计时器很快下车(我有4-5秒只需约3分钟)

  1. 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.

$ b $ 您可以检查每次移动之间的时间一切低于50ms应该是可疑的,但这主要取决于难题的难度。 b

  • 通过检查服务器上的移动,这也很容易,你不必依赖客户端发送看完我已完成的消息。

  • 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.

    再次轻松,只需发送带有附带数据的事件,并将点数记录到db。

    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.

    在DB的情况下,呃...我想你可以去与MongoDB的,但我没有玩过的节点下。

    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.

    如果你想要一个印象你可以做的Node.js这里是我已经构建的游戏:

    http://github.com/BonsaiDen/NodeGame-Shooter

    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.

    这篇关于简单游戏服务器的代码示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆