Search Unity

Question Users and Registration - Server Help.

Discussion in 'Multiplayer' started by wittywesley09, Oct 13, 2020.

  1. wittywesley09

    wittywesley09

    Joined:
    May 20, 2018
    Posts:
    6
    I've been playing around making a couple of games where admittedly I'm way over my head in what I'm trying to accomplish. But, the one thing that both my projects have in common is the need for user accounts and registration. I know a lot of people have asked this same question too many times, and I've seen plenty of forums on this subject. What I wanna do, However, Is sightly different than what I've seen and I have no Idea if it'll work or if it's a good Idea or not.
    The three things I know I need for user and registration are:

    1. A database to store the users information, username, password, etc.(MySQL and PHP are the names that keep coming up.)
    2. The in game GUI that the player will interact with.(Already made it.)
    3. A method to tie them together.(Seen a lot of examples)

    The different thing I wanna do, if possible, is not use MySQL or PHP. I want to store the database on a network accessible storage device, something like a private server, or on the client side. The Users have in game Inventories and customizable characters(still working out the kinks on both), all of which are stored on the client, so the user needs to have access to information. I admit I don't want hacking, but I want to have the data stored on one of my own machines. I don't like storing any of my information on someone else's server if possible, so If I can keep it local that'd be great. Is this crazy plan possible? This system should work for both of my projects.

    also if anybody's got and ideas on how to do the customizable characters system thing, that be awesome. There are two models (1 male, 1 female) both with a variety of hair styles and clothing articles. I know how to change things in game. How would I save those changes per user, hair and color, outfit, etc?
     
  2. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    If you want to prevent hacking then there is no way around of removing direct access to the data from the client.

    When you said you want to keep the data on your own machine, did you mean you want it to be stored with the game, or you just don't trust any other web server to host your data?
    If its the later then try installing XAMPP and just host your own PHP script and MySQL database.

    Maybe you can explain in more detail why clients need to access the database directly, I am pretty sure we can help you to find a solution for that so that this is not required.
     
  3. wittywesley09

    wittywesley09

    Joined:
    May 20, 2018
    Posts:
    6
    I don't want the client to have direct access to the database, but having the ability to change account details, including username and password would be good. I'm assuming that can and should be done in game. As far as hosting my own PHP script and MySQL database is concerned, I like that Idea a lot better than having someone else host my data. Thanks for the tip on the software. I like having data on my own machine as opposed to storing it somewhere else where someone else can if they try get to it. I'm a like play tower defense with my own computer system.
     
  4. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    Usually you do a web request which will go to your web server to a PHP script and the PHP script access the database.

    Now lets say you want infos about player X, instead of the client asking the database for player X it will call the GetPlayerInfo.php script with the argument player X, then the PHP script will get the info and sends it to the client as response to his web request. This has the advantage that the client doesn't know your database password, clients can be decompiled and hackers could gain easy access to your system that way. Also you can check the user input in the php file, if you have a php file that deletes a user account you can check a user can only delete his own account, not some other account.

    You can host php scripts and then just do web requests to:
    localhost/changePassword.php
    localhost/register.php
    localhost/login.php
    and so on
     
  5. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    If there is more than just highscore mangemant like e.g. account management, then I would recommend a PHP framework.
     
    FakeByte likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm confused by what you're asking here. Are you literally talking about having the database on your personal home network (effectively an internet dedicated server, but at your house), or creating a system where the clients have to configure a home server for their own database?

    If you're just talking about having it at your personal location that is easy. You likely have a network connection with a dynamic IP address, so you buy a domain name and use a dynamic DNS service to point it to your IP address. Then you configure your router or another dynamic DNS client you keep running on your network to keep the IP address for your domain name up to date. Then you set up whatever server you want on your home network, enable the appropriate port forwarding for whatever services you need accessible to the greater interwebs, and it is basically like you've got a dedicated server on the internet.

    Now you don't want PHP/MySQL? Well you have to pick something, and it needs to be something which can manage multiple simultaneous writes without corrupting. So it can't be just some text file or csv you have clients all writing to at the same time. You need some server process which manages that, which your typical NAS isn't really set up for on its own. What I did for my game is create a Unity build which acts as a database. It receives requests and data updates using pick your favorite real time networking API in the same way as you would send any other messages in a networked game. Then this "database" server can have as a back end whatever you want. It could still be PHP/MySQL, it could be SQLite, or it could be just text files. You can even change your mind and switch between different back end solutions while only modifying the code for this database server without affecting the rest of your game.

    To expand more on my game's implementation, as it may give you some ideas.... When my Unity based database server starts, it reads through a series of csv files which contain all the "database" data. You can do it this way if you expect the amount of data you're ever going to handle is within what your server can keep in RAM at the same time. It then responds to requests from various servers which need the data or need to update the data. Every 20 minutes or when the server is ordered to shut down it writes all the data it has back to those csv files.

    I designed it this way because I found when making the initial prototype of my game I spent an inordinate amount of time dealing with database queries instead of actually making the game, and this way it don't deal with that but can any time later switch my database server over to using a real database if the amount of data it is storing ends up requiring it.
     
    Last edited: Oct 13, 2020
  7. wittywesley09

    wittywesley09

    Joined:
    May 20, 2018
    Posts:
    6
    So, the former is the closest to what I'm after. What I'm after in the long run is hosting a database server on one of my machines. That being said I have no idea how to go about that. For the time being I like your idea of having a testing database as a text file stored in the unity build or somewhere on my machine that can be modified later and upgraded. Also, having it capable of saving data on shut down is awesome.
    I'd like to know how you went about doing that, because it's a great starting point to me. That way I can work on developing the system and upgrade it to my own server database or just a SQLite database. I get the feeling the easiest method still involves a MySQL database, but I'd prefer to be hosting it.

    Now, can I assume player inventories, character appearance, skills and levels Information can be stored on the client side, or should that also be compiled on the account side? Bearing in mind that player can change what their character looks like in game, and I have a player to player trading system involved. Like I said, I'm in over my head. I know how make models, in game scripts, and make things move. Networking is a little foreign to me.
     
  8. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    I would store it on the server side, you don't want the client to change his level information and if character appearance is saved on the server it is easier to send that info to other players.
     
  9. rickcollette

    rickcollette

    Joined:
    Mar 17, 2013
    Posts:
    304
    @wittywesley09 - I'd love to find out more about this. I have been developing a solution that closely parallels what you are describing. My background is cloud security, and my focus is on providing secure and private metrics and authorization( login). It sounds exactly like what you are looking for.