Search Unity

Need Help Choosing a Server Solution

Discussion in 'Multiplayer' started by orionburcham, Sep 16, 2014.

  1. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    488
    Hello! I'm interested in adding online support to my game. Specifically, I want a system that lets me store & access user account information, asset bundles, and user save data. I'm new to the server game, and I could use some expert help picking out the right solution.

    When I first started thinking about this, here's what I had in mind:

    I would rent some cloud storage through a SaaS somewhere, add a MongoDB database, and have Unity access it by talking to a sever-side PHP script (to prevent direct access to the database over the internet).

    That's all fine an dandy, but then I started looking into some MongoDB SaaS solutions, like MongoLab. This looks like a great service, but I don't see any way to host my PHP file on their severs, so I started imagining I would need to do this:

    Here, I'm hosting the PHP script on my own server somewhere, and talking to MongoLab through their REST API. This just doesn't seem secure, since the PHP script isn't on the same server as the database. It's online requests can be intercepted, possibly allowing outside access to the database.

    However, there seemed to be yet another issue: I'm not sure if it makes sense to store all my binary data (Unity Asset Bundles, user Save Games, etc.) directly inside my Mongo database. Maybe I should be storing those completely separately on a dedicated data server, and only storing links to them in my Mongo database? Something like this?:

    Here, the PHP script is only asking the MongoLab database for the links it need to actually grab the needed AssetBundle file from my file server. All this before passing the AssetBundle back to Unity. This seems super shaky, since those links could change and my entire Mongo database would be out of sync.

    Anyone who has ventured into these waters, please help me make sense of this. How are these problems normally solved?

    Many sincere thanks for any help-
    Orion
     
    Last edited: Sep 16, 2014
  2. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Hi
    MongoDB is not a perfect choice but is a good one and has a good integration with many languages.
    You can host your content on your database if you can scale it. Riak, MongoDB and some other no sql databases are good enough. You can also store your content on CDN networks or services like amazon S3 and access them via script/server code/game servers.
    If you only need some data online and don't need any game server functionality then the approach you took is a nice one. Also you can take a look at player.io which is a competitor of us but seems nice for what you want to do.

    Storing your data in a CDN has the advantage of being fast in most places for download but you should pay for it. I don't know how much budget you have and your game's other requirements, the size of bundles and how you use them. If you give me more information then I might be able to help more.
     
  3. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    488
    Thanks for your reply. I'm becoming a bit more knowledgeable. :) For more detail, let me lay out my basic needs:
    • Online storage for asset bundles (anything from streaming levels to small dlc - will be accessed frequently)
    • Storage for user saved games (the unity app will autosave the player's progress and upload it periodically)
    • MP functionality (Planning on using Photon for all of my MP and matchmaking needs).
    • Online user account data (as an identity for MP games, and to help store each player's saved games).
    The ideal experience:
    1. The user starts my app, and logs on using their user account data
    2. (If this is an MP game, the game then connects to Photon, which handles all my in-game MP features.)
    3. Once logged in, the game looks up and downloads the player's most recent saved game.
    4. Based on the asset needs of that save, the game then pulls down any asset bundles it needs, and loads them.
    5. When prompted by the user (or when the app is closed), the game creates a save of their progress, and uploads it for next time.
    I pictured using an online database to organize the user data, asset bundles, and game saves. If need be, I would store all actual content (asset bundles, game saves, etc.) separately- either on the same server, or a dedicated CDN.

    - - -
    A few questions:
    What different database would you recommend (if any)?

    My plan was to handle all actual game networking through Photon PUN+. I imagine it could operate basically completely independently of my storage solutions. Does this raise any red flags?

    I've seen a lot of debate out there about VPS vs. Cloud CDN. Do you have any thought on this?

    What about security issues here? Everything I've read so far says only ever access your database or server-based content through a server side PHP script (or Node.js, or the like). If my database is on its own database-only server (like MongoLab), and my content is on a content-only CDN, then where would that PHP script live? And if it's on a different server than either of them, isn't that inherently insecure?

    Many thanks, again.
    Orion
     
    Last edited: Sep 17, 2014
  4. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Your database should not be accessible to the users. CDNs can host things which are publicly available for download. Some storage systems like amazon's dynamo DB, Riak, MongoDB etc can be used for file storage as well. I'm no expert here.
    If you want to use photon's pun+ with their cloud without hosting your servers then you should have a host which you put your php scripts in which do all database related operations, they should validate that the data is coming from the game and is valid in some way as well. If you host your photon server or write logic for their cloud servers (remember reading some news about custom code on their cloud) then you can do saves only from that code and try to verify some client actions on the server. Otherwise what you would do if someone sends a wrong score to your php script and ...
    Honestly speaking neither php nor javascript/node.js are not awesome platforms because of the language features and something based on a better language like asp.net web pages or web services or python might serve you better in the long run however it depends on your skills as well.

    You can host your public content on the CDN and your save data on a database but it will complicate your setup, if you don't have users from all around the world or speed of downloads is not too critical you can store all of them in your database.

    The thing which I said about mongoDB was because of the master locks that it has for updating data. Also it has limits on the amount of binary data per key value pair which might be less than what you need or not. Not a database expert either so don't talk much about that.
    Search for No SQL databases and you'll find a set of options. Key value pairs with limited query capabilities should be good enough for your case but you know it better.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @orionburcham: If you want to be able to store game state, you could also look into Photon Turnbased. It must be setup with a web service (called via http) to save a room's state. Players can stay in the room as inactive and rejoin the room .
    PUN is not yet compatible with Photon Turnbased though.
    Alternatively we now partner with PlayFab, which offers user-accounts with inventory, state, in-game currency and payment and some more. It's a service, too and they will integrate Photon as multiplayer solution. Actually, this will work nicely in tandem already but there are no combined SDKs and demos yet.

    In any case: Making a DB for the state available via PHP is also just fine. Aside from exposing the DB connection directly in the client, anything should be ok.