Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

turn-based multiplayer advice?

Discussion in 'Multiplayer' started by mindlube, Apr 3, 2012.

  1. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Hi all, I'm adding multiplayer to my dominos game (current version is just vs. cpu) I am initially targeting iOS, Android and MacOS. I might want to port it to Windows and webplayer later. so requirements:

    - Cross-platform
    - Unity plugin, or c# assembly, or unity friendly
    - allow multiple matches! This is a turn-based game and I want to enable players to have multiple matches, much like in Draw Something or other social games.

    I already ported it to use PhotonCloud with RPCs, and it works great. Only to realize I can't persist room data with Photon cloud. So for multiple persistent matches I would need to mod the server SDK and run my own Photon server(s). Certainly within my skill set but not what I prefer to spend time. I do really like Photon but it seems like overkill for turn-based multiplayer.

    What turn-based multiplayer framework/middleware or cloud solutions are out there?

    OpenFeint: I thought I heard they had a P2P turn based solution but I don't see it on their developer pages. Also it's iOS and Android only. Dont really like the forced login to openfeint too.

    Apple GameCenter P2P turn-based multiplayer: iOS 5+ only. not cross platform

    Photon: doesn't explicitly support turn-based with persistent matches, but has hooks in the server SDK for loading/saving room state.

    SmartFoxServer2: are there any extensions or mods for SmartFox for turn-based?

    Electrotank: same issues as photon?

    Maybe I'll just roll my own using Amazon AWS + Memcached [edit: or NoSQL db]...

    Any suggestions appreciated!
     
    Last edited: Apr 3, 2012
  2. tcarr9

    tcarr9

    Joined:
    Oct 11, 2010
    Posts:
    63
    If these are going to be two player games (not 3 or 4 player games) the way that most of the "with friends" social games are, I would suggest you don't bother trying to make a persistent Room for each game. On ElectroServer, I would just have a server level plugin that holds the info on each active game in memory, and persists the current game state to a database after each move is approved. If a player makes a move in a given game, and the opponent is not currently online, then that game would be removed from the active games in memory, until the opponent does come online.

    Use case:
    Player A logs on.
    Server checks database to see which games are waiting for Player A to move, and sends that info.
    Player A chooses one of the waiting games and asks for the game state of it.
    Server plugin sends the game state for the chosen game.
    Player A makes a move, and sends info to the server plugin (gameId, move).
    Server plugin performs any logic (is this a legal move, does this end the game, etc) and persists the info the to database so that when Player B logs on he can have his turn. Perhaps it even pushes a notification to Player B about this game.

    edit: for the newly created games and matching, you could either use GameManager or just have that same server plugin have a concurrent data structure of players waiting for an opponent, and have it do the matching.
     
    Last edited: Apr 3, 2012
  3. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Thanks Teresa for your reply! The more I learn, I see that Unity Networking / Electrotank / Smartfox / Photon etc. are not well suited for turn-based multiplayer where many matches are active and long-running. I am currently looking at rolling my own server using TCP sockets and memcachd. SignalR looks pretty nice and can serve web clients as well as straight C# socket clients.
     
    Last edited: Apr 4, 2012
  4. tigeba

    tigeba

    Joined:
    Sep 11, 2008
    Posts:
    70
    mindlube,

    If you are really are talking about games that have very limited, or no realtime interaction, it is possible that you might be better off using what would effectively be web based tech to back your game. If you are considering using sockets, then you might be better off with middleware that is made for socket gaming -vs- rolling your own. It all depends on your experience level of course :)
     
  5. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Thanks Jonathan, I appreciate how active electrotank is here on the forums! Just for background I am a software engineer with ~15 years of experience. But my experience with network programming for games, is just about nil.

    By comparison, I looked at Photon Cloud and although very impressive and solid, it's inheritently "room-based" with a lobby. I was told for this use case I'd have to run my own server, mod their server SDK and save the state of the rooms when users disconnected.

    By the time I've gone to all that cost and trouble I'd still be stuck working around the 1-room-(game)-per-connection-concept. I might as well write my own server exactly to spec. Does electrotank have the same limitation?

    I am not a TCP socket programmer! I have dabbled yeah, but wouldn't claim to have those skills! I know what I don't know!

    SignalR (apparently sponsored by Microsoft! https://github.com/SignalR/SignalR ) looks like a perfect match. As a C# stack it builds nicely in Mono. It is an asych, highly scalable server (i.e. doesnt fork thread for every socket). It should support thousands of connections on a very modest hardware. It is designed for realtime TCP socket applications, while also being fluent in web standards like WebSockets and long-polling which I see as a bonus, not as a drawback necessarily. So adding stats and rankings to my web page would be incredibly simple. You can call it "web based tech", implying my inexperience no offense taken ;)
    Now to fire this thing up and see if I can connect from Unity :)

    edit:

    just to clarify the use-case: this is turn based, and not real time. fast or near-realtime is good though. Estimate thousands of players with an average of like 3-5 matches they are playing. Don't want 3-5+ connections to the server for every player. Want to stream match data to the users for all matches they are participating in, plus rankings/leaderboard and chat messages.
     
    Last edited: Apr 4, 2012
  6. tigeba

    tigeba

    Joined:
    Sep 11, 2008
    Posts:
    70
    I think Teresa was suggesting that for your game using our room stuff might be of little benefit, and you might look into using what we call a "Server Level Plugin" which would basically allow you to work at more of a 'per user' level and store your gamestate however it would be most useful.

    I didn't meant to imply any level of experience or sophistication by calling something 'web based', I was just using that as shorthand for 'HTTP based' essentially.

    One thing to watch out for is that due to quirks in compatibility with Mono/.Net/Unity you might find that client libraries not written specifically with Unity in mind may have some issues. For example, most libraries that would make use of HTTP would probably try to use System.Net.WebRequest. You will find this won't be available on iOS, Web Player, Android, etc. Whatever you do, make sure to carefully test features on your target platform, and not just in the editor, especially when it comes to networking.
     
    Last edited: Apr 4, 2012
  7. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Thanks for clarifying Jonathan. I'll definitely look again at electroserver and the Server Level Plugin idea mentioned above. It might come down to license cost hardware requirements too.

    re: HTTP Based; I'm just kicking the tires of SignalR today. It looks like it has about 2-3 different transport types one of which is http. So not sure; but you are probably right in calling it http based in general. But even in standard html5 WebSockets/Socket.IO, the http is only for connection setup and then it switches to a tcp socket stream.
    Anyways, cheers
     
  8. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    121
    How did this turned out? I am trying to make SignalR work with Unity, but I was not able to make it run yet.
     
  9. dhruvc

    dhruvc

    Joined:
    Apr 19, 2013
    Posts:
    51
    You can explore using App42 cloud for making such turn based games that require persistent storage (and not realtime sockets). App42 cloud SDK can be used to store JSON data on its cloud and also allows you to send push notifications. There is unfortunately no Unity3D turn based sample yet - but we do have an Android Tic Tac Toe sample application which you can check out and see if it fits your game. You can then do something similar with the App42 Unity SDK. Here is a link to the git repo with the sample -
    https://github.com/shephertz/App42-Tic-Tac-Toe/
    http://blogs.shephertz.com/2013/05/...-notification-in-android-with-app42-platform/
     
  10. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Hi Joel, it's still a work in progress, but I am currently using Photon socket server and C# client API (not using the photon cloud as it's not really suitable for asynchronous turn based games)