Online Free Poker
Made with: Unity, C#, PHP, mysql
Solo project
Module ‘NetworkProgramming’ - 8 weeks
June 2025
Functionality
For this project, I chose to simply recreate poker, since it’s a game with turn-based mechanics, a score at the end of the game (your total chips and the difference between the number of chips you started with and what you have left), and it can be played with 2–4 players. When you create an account, you start with 1,000 chips. You can use these chips to play online against others to win as many chips as possible and reach the top of the leaderboard. For each game, the score (how many chips you won or lost in that game) is saved to the database.
Development process
The first part of the project was to create an API in PHP that would allow you to use queries to login, register, save scores, format info in json, etc. We then had to create an online turn-based multiplayer game that would save your high scores to that database. We got a database setup with mysql provided by our uni, so that part we didn’t have to do ourselves.
Technical Overview
When the Unity server starts, it attempts to log into a session via PHP. If successful, the Unity server establishes a session with the PHP server. Currently, you can only connect to the server if it is running on your own LAN network, as I have not yet been able to set up a dedicated server.
Unity clients can then connect to the Unity server via the Unity Transport API. I use this API for communication between the clients and the server. For example, when you want to log in or register, as a client you ask the server to send a web request. In this request, you include your entered username and hashed password. Using the API, it is checked whether this user info is correct. If it is, the Unity server first receives the response and then passes it on to the client that requested it.
On the PHP side, communication with Unity is done by encoding data as JSON, which Unity then converts into the necessary variables. I also use the database for matchmaking. If you try to find a match and there are no existing matches you can join, then as a client you ask the Unity server to send a request to the database to create an entry in the poker_match table, and then add your userID to it. If someone else later searches for a match, they will find this one, join it, wait for possible additional players to join, and then the match will start.
The match itself runs entirely through the Unity Transport API. By sending strings and integers to the Unity server, it knows what to do with the received information. For example, if you want to raise your bet, you send an array to the Unity server containing your userID, your matchID, the action you’re taking (raising, in this case), and the function in which the server should process this (PlayTurn). The Unity server can then handle this and send the necessary information to the correct clients, as all clients always include their connectionID when sending data.
Sometimes, during a match, a query to the database is required, for example, to check how many chips a player still has.