How Does Spaceteam Work?
Asked Answered
B

2

6

For those not in the know, Spaceteam is a very popular and very fun multiplayer game for iOS.

It allows for real time gameplay among multiple devices on an ad-hoc Wifi network - how does it do this?

Are there published libraries describing how to build protocols on top of ad-hoc networking libraries? Is it iOS specific, or would it be possible to build a variety of applications across different platforms?

Quickly, answer before we hit the asteroid!

Bertina answered 20/2, 2013 at 1:13 Comment(3)
It certainly would not be OS specific. The network is layered in such a way that all devices use the same fundamental protocols. Example, all devices have an IP address that they can use to speak with each other.Courser
Is there a chance this game works using the alljoyn api? alljoyn.orgTherron
The Spaceteam developer has written a blog post detailing the game's networking.Sickly
R
3

Specifically which aspect are you interested in? There's nothing particularly special about mobile devices or ad hoc Wi-Fi networks (except in an ad hoc network, not all devices may be able to communicate with each other, so some mesh networking can help but unnecessarily complicates matters for the normal case).

I'll answer the broader question first, because it's more interesting. In my experience, there are a handful of major considerations:

  • Server/client or peer-to-peer? By this I mean whether there's a "master" deciding the true state of the world and communicating this to all clients. Avara is the only game I know of that is "peer-to-peer" in this sense (peers sent commands to all other peers; this proved bandwidth-heavy for modem users on 6-player games). I am not aware of games using more sophisticated network topologies to communicate game state (e.g. only sending data to one client on each LAN).
  • What do you do about latency? Avara is the only game I know of which lags everyone locally by the "latency tolerance" in order to get a consistent state of the world, which was terrible if someone was on a modem (turning off compression helped a lot). There are various ways to do "latency compensation" (e.g. in Half-Life/CS), some of which could also work on peer-to-peer games.
  • Time sync? For client-server games, you at least need to worry about a changing RTT. For peer-to-peer games, I think you also want to agree on timing that minimizes the effective maximum latency.
  • What if clients disagree about the state of the world? Avara just lets peers decide on their own state of the world (and displays "reality fragmentation detected" if it senses a mismatch, which might happen due to dropped packets or a too-low "latency tolerance").
  • What if a player leaves? For a P2P game, you might have to agree on a consistent game state (e.g. if the player was disconnected after sending commands to a subset of other peers). For a client-server game, you might have to elect a new master.

And now, after watching the Spaceteam trailer:

I have no idea how it works, since I haven't reverse-engineered the protocol. However, it's pretty simple to make something that works well enough:

  • Use some sort of P2P discovery to find players (e.g. Bonjour; there should be plenty of docs and samples out there).
  • Communicate with peers. I've done this with GameKit circa iOS 3/4 (I'm not sure if it still works over Wi-Fi).
  • Elect a master. This can be as simple as whoever presses "ready" last attempts to be the master. In some edge cases you might have to handle failure.
  • Let the master decide everything. Spaceteam is not latency-sensitive; Wi-Fi latency tends to be at most a handful of milliseconds, and nobody's really going to notice if one device is slower by 100 ms (as long as the UI responds fast enough).
Resistance answered 20/2, 2013 at 2:15 Comment(1)
This comment might be quite late, but do you have any information on how the seamless Bluetooth integration works? Spaceteam doesn't require any kind of pairing, which is a great way to do things.Periostitis
M
0

There is a library made by Spaceteam that does this for Unity games. https://github.com/hengineer/CaptainsMess

The creator of Spaceteam also wrote an old blog post about Networking in Spaceteam http://spaceteamadmirals.club/blog/the-spaceteam-networking-post/


There is an iOS only library that will connect nearby devices easily called MultipeerConnectivity https://developer.apple.com/documentation/multipeerconnectivity


If you want something that will work cross-platform I have an example app here: https://github.com/brendaninnis/LocalNetworkingApp, which I explain in great detail here: http://brendaninnis.ca/connect-nearby-devices-part-1.html

Mahon answered 17/11, 2019 at 1:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.