Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Players' data problem

Discussion in 'Multiplayer' started by PROE_, Apr 18, 2017.

  1. PROE_

    PROE_

    Joined:
    Feb 20, 2016
    Posts:
    32
    Hi guys,
    I'm building the FPS survival game which will be based on multiplayer(using UNET) but actually I'm struggling with saving items and need some help..

    networkingproblem.png
    Didn't want to edit this image but player's name and item name aren't problem as method parameters but still don't know what to do with them
    -----------------------------------------------------------------------------------------------------------------------------------------
    Actually after doing that plan I think that AddItem() and DropItem() only need to be called when this things really happen, of course with Anti-cheat implemented. Isn't that stupid?

    I want player to be able to host P2P network on his own computer.
    On the VPS/dedicated machine people be able to host community servers(like in the Unturned or CS:GO)
    And of course offical game servers.
    And that's why player's inventory can't be hold on client side only(in p2p can be but there are community servers and official servers too) to prevent it from disappearing and cheating.

    And VPS/dedicated servers mean that I have to create another client with less graphics and capability to create players' storage file, right?
    Okay but what with p2p network, so client should also create players' storage file at start, yeah?

    And that made spaghetti in my head... and probably in yours too ..

    It probably doesn't really matter but storage.file should storage:
    - player's name
    - player's last position
    - player's inventory
    - player's variables like health, hungry etc.
    and probably that's it


    And one more question - item database (which ID is which item) should at server side or at client side?

    Thanks for all help!
    And if you don't understand something - write down and I'll explain it to you.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't see where you've decided whether you're going to allow characters and inventory to persist between servers, so a player could leave one server, join another, and have all their "stuff" with them.

    If everything persists between servers, then you're going to want to save the player's character and inventory either on the player's computer (client side generally), or create a centralized character/inventory server that all game servers connect to. The first option is the cheapest for you, and the easiest, but it opens your game up to players just editing their character and inventory. Your game servers are trusting what the client says its character has. Original Diablo did it this way. You can store either with local db, playerperfs, or json, csv, text files, etc.

    If you want to reduce cheating though you'll want a central server probably with some type of database backend. All your game servers would pull player data from the central server, and push changes back. More complicated, and higher cost to you, but harder for players to cheat (though not impossible with players able to host games and those games will push character/inventory updates back).

    If characters and inventory are unique only to a single server, then I'd just have the server save everything as I mentioned above without a central server (local db, playerperfs, json, csv, text files, etc).
     
  3. PROE_

    PROE_

    Joined:
    Feb 20, 2016
    Posts:
    32
    @Joe-Censored So player's inventory will be unique for all servers, the great example of this is Unturned - unique eq for every server and that's probably stored at server side or am I wrong? I'd like to go for something like this.
    But actually the problem is that I don't know where to go.
    Can you point some way?

    Hmm create server client with the lowest usage of CPU/GPU and save data to json/xml file (playerprefs are uncomfortable I think and local db isn't the best thing too I think if people want to host servers on their own computer, text files would be good tho),
    then setup player to send inventory add/remove methods only to server(is this the same thing as master client?) and make it communicate every second

    And do I have to make items IDs store in database? I saw on YT that some people went this way but do i.e. Unturned or Rust have that thing?

    EDIT
    After thought items database for storaging damage, range isn't stupid, prevent cheaters too
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    So if you're concerned about cheaters you've got a big problem storing anything locally on player computers, even if only on the host player's computer. You'll basically have to trust the player hosting the game to not tamper with the data.

    But if you're going that route, if it is not that much data we're talking about, like a few player's inventory, I'd consider just storing it in memory like any other objects you're tracking and periodically dumping to disk in a format like json. It would be a far simpler implementation than SQLite or some other local database. If you're dealing with a lot of data I'd probably then go for an SQLite or similar database approach.