Search Unity

Storing Data on Server/Host

Discussion in 'Multiplayer' started by imgodot, Mar 15, 2016.

  1. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    How do I store data that should reside only on the server/host?

    Let's say I am tracking player points that will determine when the game is won.
    How do I do that?
    Where do I do that?

    Help Mr. Wizard!

    -- Paul
     
  2. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    you'd need a dedicated host to keep persistent data on, either in file format or a mysql/mssql/etc database.
     
    Joe-Censored likes this.
  3. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    Ah, come on! Are you serious?
    I know you are serious, of course, but that is just crazy-town!
    I cannot believe that most multiplayer games don't need to store information server-side and, if they do, that they all have to use persistent disk data.

    Perhaps a different, though related, question: Where would I write code to determine the win condition for a game?
    On an authoritative server, I would think that would be done on the server/host but, with UNET, I have no clue where that would go.

    Thanks for putting up with me and my UNET confusions.
    -- Paul
     
  4. g_a_p

    g_a_p

    Joined:
    Mar 16, 2015
    Posts:
    281
  5. Freakyuno

    Freakyuno

    Joined:
    Jul 22, 2013
    Posts:
    138
    @imgodot - There are lots of options out there for third party tools, which integrate directly into Unity and will add a persistence layer to your server code, allowing you to store whatever you'd like.

    When you start getting into the area of data persistence, I guarantee NO two games are going to want to do it the same way, so it becomes a big topic. There are some generic providers out there that'll get you a ways down the road, but I actually would recommend you roll your own to start with, so you understand some of the basic concepts, before you offload it to someone else.

    Remember, Unity is not, and has never tried to be a "Game Kit" - It's an engine - the "kit" part can be created through the Unity Asset store if you'd like to build your game that way, otherwise roll your sleeves up and dig in, and we'll be here to help you along the way!
     
  6. Scorr

    Scorr

    Joined:
    Jul 2, 2013
    Posts:
    73
    I think you're confused; for persistent data you could store it in a database like Whippets said. If you simply want to track player points that determine when the game is won, you can just keep a variable server-side. Look into SyncVars if you want to share this variable across all clients.

    UNET uses the client/server model so you'd also write the win condition on your server. You could use a Command for this.

    It seems like you're missing the basics of UNET, so I suggest you check out the other pages in the documentation.
     
  7. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    Thanks to all for the responses.

    Maybe, you can still ease my mind.
    For now, let's ignore data persistence since I have already have a list for player data that is created by a custom network manager class.

    So, I have a list that holds player health and it gets updated by each player via server-side code.
    Now, I want to determine if someone won the game.
    Where should I put such code?

    I could perform that test whenever any player takes damage and updates his health in the player list.
    That would all happen server-side (which is good) but it just seems ugly to me to have all the players testing for the win condition. But, perhaps, there is no better way than that in UNET. But, a boy can dream, can't he?

    -- Paul
     
  8. Kiaurutis

    Kiaurutis

    Joined:
    Jul 5, 2015
    Posts:
    1
    First of all your question title is not accurate. "Storing" server data would mean writing data from server RAM to a file. In your case you are asking how to manage game state data in server.
    You should make a list of active players in server. When player takes damage, you will check if he is still alive. If he died, you need to disable him (delete from list or set some variable in the list that it is dead), so that dead players don't continue playing. I don't know what is the win condition in your game, but I assume it is only one player is alive or only players of one team are alive. In any case, when a player dies, you will check the number of active players (or number of active players in each team). If there is only one player (or team of players) alive, then they are winners.