将 Pusher/Pubnub 与权威游戏服务器结合使用

发布于 2024-12-20 18:52:57 字数 299 浏览 1 评论 0原文

我想构建一个 2 人回合制游戏,并使用权威服务器来管理游戏状态/逻辑。我想到的流程是这样的:

  • 玩家订阅一个独特的游戏频道(通过 pubnub/pusher/类似的东西)
  • 玩家通过 HTTP 直接将他们的回合提交到游戏服务器
  • 服务器运行游戏逻辑并将结果发布到游戏的频道(两个玩家都订阅了)
  • 客户端处理响应并呈现结果
  • 匹配有点让我困惑。有什么建议吗?

这是在这种情况下使用发布/订阅服务的“正确”方式吗?有没有更好的方法(除了不断轮询服务器之外的其他方法)?

I'd like to build a 2-player turn based game with an authoritative server to manage the game state/logic. The flow I have in mind is something like:

  • Players are subscribed to a unique game channel (via pubnub/pusher/something similar)
  • Players submit their turns over HTTP directly to the game server
  • The server runs the game logic and publishes the result to the game's channel (which both players are subscribed to)
  • The client handles the response and renders the outcome
  • matchmaking kind of confuses me though. Any suggestions?

Is that the "right" way of using a pub/sub service in this scenraio? Is there a better approach (something other than polling the server constantly)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沧笙踏歌 2024-12-27 18:52:57

这是我们办公室的热门话题!我一直使用 PubNub 作为权威的游戏服务器,并创造性地选择频道名称。它的工作原理如下:

  1. 运行一个 Node.js 服务器(不一定是 Node;可以是任何东西)来为您的内容提供服务,并且还充当权威实体。
  2. 当客户端连接时,生成一个 UUID(可以在服务器端或客户端完成)并让客户端和服务器都侦听该通道(类似于“my_game_[UUID]”)。
  3. 由于没有其他客户端知道该通道名称,因此客户端和服务器可以在该通道上自由通信。
  4. 服务器可以与每个人通信,客户端可以通过服务器执行安全操作,并使用“不安全”的普通 pubnub 通道相互通信。

This is a heated topic at our office! I've been using PubNub as an authoritative game server using creative choice of channel names. It works like this:

  1. Run a node.js server (doesn't have to be node; can be anything) that serves your content, and also acts as an authoritative entity.
  2. When a client connects, generate a UUID (can be done either server-side or client-side) and have both the client and server listen on that channel (something like "my_game_[UUID]").
  3. Because no other clients know this channel name, the client and server can communicate freely on this channel.
  4. The server can talk to everyone, and clients can perform secure actions through the server and communicate with each other using an "unsecure" vanilla pubnub channel.
或十年 2024-12-27 18:52:57

你的建议听起来不错,而且是“正确”的方式。您面临的挑战从计算机时代开始就一直存在,其中同步数据是移动智能手机等多个设备之间的要求。轮询速度慢且成本高(对于大量玩家来说没有意义)。多人游戏就是一个很好的例子,需要配对玩家并提供游戏室。您的解决方案是:

  1. 创建一个游戏大厅,玩家可以在其中创建游戏室并加入游戏室。
  2. 创建玩家自动配对(快速加入)[推荐]

您可以使用 Socket.IO 等产品和其他一些开源选项来解决此技术挑战。然而,您只想构建游戏,而不是专注于部署 Node.JS 服务器并将其连接到 Express。

请改用 PubNub、PusherApp 或 Beacon Push 等云服务。利用 Pub/Sub API 轻松同步多人游戏环境中的用户。

Your proposal sounds great and is the "right" way. The challenge you face is shared from the beginning of the computer epoch, where synchronizing data is a requirement between multiple devices such as a mobile smartphone. Polling is SLOW and expensive (and does not make sense for a large number of players). Multiplayer games is a great example need to pair players and provide game rooms. Your solution is to:

  1. Create a Game Lobby, where players can create game rooms and join game rooms.
  2. Create an Auto-Pair of players (Quick Join) [Recommended]

You may solve this technical challenge with products such as Socket.IO and some other open source options. However you want to just build your game rather than focus on deploying a Node.JS server and hooking it up to Express.

Instead use a Cloud Service like PubNub, PusherApp or Beacon Push. Utilize the Pub/Sub API to synchronize users in a multiplayer environment easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文