The 'DisplayInfo' function is a PHP script designed for fetching and displaying user information from a MySQL database. Key aspects of the function include:
Database Connection: Utilizes the 'connect.php' file for establishing a connection to the MySQL database.
Prepared Statement: Prepares a SQL statement to select all fields from the 'users' table where the token matches the provided request token.
Execution and Validation: Executes the prepared statement and checks if a matching row is found. If not, it returns a message indicating that the token was not found.
Data Retrieval: Data Retrieval: Retrieves various user-related data from the fetched row, including ID, gold, lumber, mana, and counts of different units (peasant, knight, archer, mage, catapult).
Response Object: Response Object: Constructs a response object containing the retrieved data and a server message indicating that the information has been displayed.
JSON Output: JSON Output: Encodes the response object into JSON format and echoes it back to the client.
This PHP script showcases my proficiency in database interactions and handling user data within a server-side environment, demonstrating a key aspect of web development.
The Login function is a PHP script responsible for authenticating users based on their email and password against a MySQL database.
Key features of this function include:
Database Connection:
Utilizes the 'connect.php' file to establish a connection to the MySQL database.
Prepared Statement:
Prepares a SQL statement to select 'user data from the users table where the provided email matches.
Execution and Validation:
Executes the prepared statement and checks if a matching row is found. If not, it returns a message indicating that the email was not found.
Password Verification:
Uses the 'password_verify' function to compare the hashed password stored in the database with the provided password. If the verification fails, it returns a login failure message.
Token Generation and Update:
If login is successful, generates a random token using the 'GetRandomStringUniqid' function and updates the user's token in the database.
Response Object:
Constructs a response object containing the generated token and a success message.
JSON Output:
Encodes the response object into JSON format and echoes it back to the client.
This code snippet utilizes Unity's 'UnityWebRequest' to perform a POST request to a specified URL with form data. Key
aspects of this code include:
Web Request Setup: Creates a 'UnityWebRequest ' object configured for a POST request with the specified URL ('url') and form data ('formData') .
Asynchronous Request: Utilizes the 'yield return webRequest.SendWebRequest()' construct for asynchronous execution, allowing the game to continue processing while waiting for the web request to complete.
Response Handling: Logs the downloaded text from the web request and deserializes it into a 'FindNewOpponentResponse' object using 'JsonUtility.FromJson' . The server response message is also logged for debugging purposes.
UI Update on Successful Response: If the server message indicates finding a new opponent, updates various UI elements with information received from the server, such as the opponent's name, resources (gold, lumber, mana), and troop amounts (peasant, knight, archer, mage, catapult)
Data Storage: Stores the latest opponent ID for future reference.
The ResourceUpdateRequest class is a C# representation of a JSON request payload for updating resource information in a multiplayer game. Key attributes and features include:
Serialization Attribute: The [System.Serializable] attribute indicates that instances of this class can be converted to and from JSON format, facilitating communication between the client and server.
Action Identifier: Contains a string attribute action initialized to "Resource_Display," signifying the purpose of the request is to display resource information.
Token Attribute: Represents the user's authentication token required for server validation.
The ResourceUpdateResponse class is a C# representation of a JSON response payload for resource updates in a multiplayer game. Key attributes and features include:
Server Message Attribute: Contains a string attribute serverMessage that conveys information about the success or failure of the resource update operation.
Resource Attributes: Includes integer attributes (gold, lumber, mana, peasant, knight, archer, mage, catapult) representing the updated quantities of various in-game resources.
The Assignment
This project was a special solo project because we as students were introduced to php and databases.
We used Unitys build in JSON functionality and we used an Application called "DevServer 17".
The requirements of this were quite hard: we had to create a login / create account screen at the start of the game with the php functionality in the background.
We had to have a goal in the game to interact with other "players". And we had to do this all in 6 weeks.
The first couple of weeks was a lot of struggling and learing to use php together with Unity.
And the last 3-4 weeks were weeks of pure development and working late nights.