This week, I've been focusing on building out the backend infrastructure for my Connected games. The goal is to enable features like online multiplayer and user accounts/profiles.
I decided to use the popular XAMPP stack, which combines Apache, MySQL, and PHP into an easy-to-use local development environment. After installing XAMPP, I created a new MySQL database to store game data like user accounts, high scores, multiplayer match logs, and more.
With the database in place, I turned to PHP to build the APIs that my Unity game clients will communicate with. PHP connects to the MySQL database and handles tasks like authenticating users, retrieving/updating relaying multiplayer data between clients, and so on.
A major milestone this week was implementing user authentication by adding login and registration functionality connected to the SQL database on the backend. Players can now create new accounts, which stores their username, email, and encrypted password in the database. During login, the provided credentials are validated against the database records for secure authentication. This paves the way for persistent user accounts, enabling features like saved game progress and online multiplayer matchmaking tied to each user.
Here's a code snippet that I have done in Unity, PHP attached below.
It took some time to get the PHP code working correctly and properly integrated with the database schema I had designed. But after testing and debugging, I now have a functional set of backend APIs that my Unity games can call into.
The next step is to integrate this backend directly into my Unity projects. I'll be using Unity's UnityWebRequest class to send HTTP requests to my PHP APIs and handle the responses. This will allow my games to authenticate users, report scores to leaderboards, initiate/join multiplayer matches, and more.
I'm excited to have the core backend plumbing in place. Building out online functionality for my Connected games will really help take them to the next level. Stay tuned for more updates as I make progress integrating the backend with Unity!