I thought I’d share my experiences of using Microsoft Azure as a back end for the game.
I wanted to be able to store players game data, that is primarily their settings, progress and inventory etc. I think in the past a lot of people have used a MySql DB on a hosting package from an ISP which is totally fine, but I decided to explore Azure, so here is how I did it.
I subscribed to Azure, this is easy and free just search Microsoft Azure and start your free trial, there are other ways to do this via the developer essential program etc. Anyway once I had my subscription I created a WebApp and a database using the Easy tables widget (lots of information on the internet) if you are using Unity this is a really great place to get you going right here https://www.youtube.com/watch?v=R8adpelztJA There was enough information in this tutorial for me to adapt things to handle the following:-
- Check the player name is available.
- Register the player and setup the database entries.
- Handle player login.
- Update the database as the game is played.
By doing this you can now play on multiple devices or share one, as when you login your unique settings and progress follow you. Now then this tutorial will only get you so far as one piece that was missing was how to secure your data, as in the tutorial all the table entries are accessible by anyone. To overcome this, I opted to use Microsoft Azure Active Directory (AAD) now it starts to get a little more complex as obviously I needed my requests to be authenticated. You will need an understanding and some experience in RestSharp and secure access to do this.
I didn’t want any of the access tokens to exist in my code, I guess at this stage I do benefit from my day job as a developer/DBA the access tokens for AAD are only valid for a specific time so typically this is how it works: –
You start the game it works out whether a token has ever been issued (for a new install obviously it won’t exist) if it has ever existed is it still valid, if it’s not there or out of date go to Azure and get new tokens. I’ve achieved this using my own code, the credentials needed are created on the fly in memory and never exist in code or on disk. Once I have a valid token for the session one of two things happen depending on whether the player has ticked the ‘keep me logged in’ check box on the login screen, if they have then the previously played player name and password are used to access the player data and initialise the game, if not you are prompted to login. Every time any interaction with Azure is required a token check is made to see if the access tokens are still valid or need to be renewed. To store the local data, health current weapon and current level etc I use the Anti Cheat Toolkit for Unity by Code Stage that encrypts the playerprefs on disk. Never use this for your Azure credentials they should never exist on a player’s machine.
The UI I use is from the Asset Store too it’s the ULogin System from Lovatto Studios, out of the box this comes with PHP code, as I’ve said before my strengths are in coding not artwork so I liked their UI and used that with only a few tweaks, but then plugged in my own code to use Microsoft Azure.
From start to finish it took about 16 hours of coding but I really like it, Azure is great, robust, so fast and has all the tools you need under one roof! I highly recommend you consider Azure, if you take your time and learn it all its very powerful and if you set it up correctly it’s still free after your free trial until you really start loading it up which at the end of the day means you have lots of players by then so fair enough.
I say Azure has all the tools under one roof it does but I did use the fantastic Postman https://www.getpostman.com/ to create my API code snippets, and to test my calls, rather than using Unity until I was confident they were working. You can do this inside Azure but personally I just had more experience with postman.
And that’s it, Microsoft Azure works perfectly for this and is super scalable from free when you need it to be, too fast and powerful when you need that too.