我应该如何设计我的数据库 &用于回合制多人 iPhone 棋盘游戏的 API 服务器?(考虑 nodejs、mongo、couch 等) [英] How should I architect my DB & API server for a turn based multiplayer iPhone board game? (thinking about nodejs, mongo, couch, etc)

查看:22
本文介绍了我应该如何设计我的数据库 &用于回合制多人 iPhone 棋盘游戏的 API 服务器?(考虑 nodejs、mongo、couch 等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款适用于 iPhone 和最终适用于 Android 的回合制棋盘游戏.我正在使用 Appcelerator Titanium 来开发它.我的多人游戏设计类似于 Words With Friends.用户准备好后轮流进行,然后相应地更新对手的游戏板.

I'm working on a turn based board game for iPhone and eventually Android. I'm using Appcelerator Titanium to develop it. My multiplayer design is similar to Words With Friends. Users take turns when ready, and then the opponent's game board is updated accordingly.

我的需求之一是拥有一个消息 API,使 2 个玩家的设备能够在移动后彼此更新游戏板的状态.考虑使用 JSON 执行此操作并在设备上保留一个 JSON 对象,该对象包含任何给定时间所有游戏棋盘的位置.这是需要在本地设备上更新的对象,然后在移动完成后将更改发送到对手的设备.

One of my needs is to have a messaging API which enables the 2 players' devices to update one another on the status of the game board after a move. Thinking of doing this with JSON and keeping a JSON object on the device which contains the location of all game board pieces at any given time. This is the object that will need to update on the local device and then send a change to the opponent's device after a move is made.

我过去曾为移动平台开发过 API,为此我将 PHP 与 MySQL 结合使用,并在 API 服务器和移动设备之间来回发送 JSON.仅适用于低并发用户和一般非大型应用程序.这是希望这个会变得庞大;)

I've done APIs in the past for mobile platforms and to do so I've used PHP with MySQL and sent JSON back and forth between the API server and the mobile device. Works just dandy for low concurrent users, and generally non-massive apps. Here's to hoping this one will get massive ;)

所以现在,我开始考虑持久性套接字,而不是一般的 httpd 服务器等,以及我的新游戏是否需要它们.我还认为放弃大 LAMP 堆栈可能是明智的,为了可扩展性和开发的便利性,更多地倾向于像 Mongo/Couch -> node.js -> iPhone 这样的数据流.老实说,这也是我第一次涉足非 sql db 和 node.js.

So now, instead of a general httpd server and the like, I'm starting to think about persistent sockets and if they're needed or not for my new game. I'm also thinking that it might be smart to forgo the big LAMP stack, and for scalability and maybe ease of development, to lean more towards a data flow of something like Mongo/Couch -> node.js -> iPhone. I'll be honest, it would be my first foray into a non-sql db and node.js as well.

有兴趣听听其他人对此的看法和经验、更多选择/想法,以及我是否以正确的方式思考它,或者只是让自己头疼.

Interested to hear others' takes and experiences on this, more options/thoughts, and whether I am thinking about it the right way, or just creating headaches for myself.

推荐答案

首先,Nodejs 非常适合向 NoSQL 数据库编写反向 TCP 代理.您可以让所有标准命令通过,但使用您自己的魔法改变/扩展它们的 API,例如让 MongoDB 使用 HTTP 或 CouchDB 通过套接字使用二进制协议.

First of all, Nodejs is awesome for writing reverse TCP proxies to NoSQL databases. You could let all the standard commands pass through but alter/extend their APIs with your own magic, e.g. making MongoDB speak HTTP or CouchDB speak a binary protocol over sockets.

在选择 NoSQL 解决方案来存储棋盘游戏棋子和监控玩家动作时,我认为 Redis 和 CouchDB 都是最佳选择.

When it comes to choosing a NoSQL solution for storing board game pieces and monitoring for player moves I think either Redis and CouchDB are the best candidates.

  1. CouchDB.它快速、可靠,并且可以处理大量并发 HTTP 连接.这可能是最好的选择,因为与 Redis 不同,它可以在文档更改时广播消息.持续更改 API 让您可以非常简单地监控每个玩家的应用程序他们董事会的变化.请求可能如下所示:

  1. CouchDB. It's fast, reliable, and can handle a lot of concurrent HTTP connections. It's probably the best option because unlike Redis it can broadcast a message when a document changes. The continous changes API makes it super simple for you to have each player's app monitor for changes to their board. The request might look like:

curl "$HOST/dbname/_changes?filter=app/gameboard&feed=continuous&gameid=38934&heartbeat=1000


每个客户端都会收到一个JSON每当相关文档发生更改时,响应中每行的对象.(并且每 1000 毫秒一个空白换行符作为一种保持活动.)

  • Redis.它使用简单的基于行的协议(如 MemcacheD++)通过套接字进行通信,并允许您存储具有任意——甚至二进制——值的列表、集合、哈希.它非常快,因为一切都发生在内存中,但异步持久化到磁盘.但最重要的是,您应该对其进行评估,因为它已经内置了 PubSub 通知.请注意,您必须通过玩家共享的频道明确发布移动通知,因为 Redis 不会在键/值更改时自动发布.
  • 由于 MongoDB 没有观察变化发生时的机制或执行发布订阅,我认为它不是一个好的选择,尽管您可以付出额外的努力使其工作.

    Since MongoDB does not have a mechanism for observing changes as-they-happen or doing pubsub I don't consider it a good option, though with extra effort you could make it work.

    总而言之,您可以单独使用 CouchDB、单独的 Redis 或将大 LAMP 堆栈"替换为单独的 CouchDB,或者将其放置在节点应用程序后面以过滤/扩展它们已经提供的 API,以使其适合您的游戏.

    So to conclude, you may be able to replace "the big LAMP stack" with CouchDB alone, Redis alone, or either one placed behind a node app for filtering/extending the APIs they already provide into something that fits your game.

    祝你好运!

    这篇关于我应该如何设计我的数据库 &用于回合制多人 iPhone 棋盘游戏的 API 服务器?(考虑 nodejs、mongo、couch 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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