How Online Game Sync™ Works
Game players can battle other players just like popular mobile strategy games such as Castle Clash
Scripts included with the Complete Game Kit
Purchasing the Complete Kit includes demo Online Game Sync™ PHP server software. Get it now from the customer download center.
If you ordered our product in the Unity Asset Store, please contact help at citybuildingkit.com to request your copy of the server scripts.
The City Building Strategy Kit comes with the first-of-its-kind feature called Online Game Sync™ that operates on any standard Linux web server with PHP. No subscription or cloud required.
Plus, hosting hundreds of thousands of users is possible. Data for 10,000 players uses approximately 15-50MBs of space.
For advanced developers launching a game worldwide, we recommend deploying the Online Game Sync™ demo software to the cloud. For example AWS EC2 configured with CloudFront CDN for delivery and S3 for low-cost map storage. More details at the bottom of this page.
About Online Game Sync™
Technically, your player's village configuration and map data is saved locally on each device. This allows for offline gameplay but with the Online Game Sync™ a copy of each map is sent online to your central server when the player opts to battle other players and enter the online gameplay component.
Battles use the industry standard: asynchronous gameplay, meaning when Player #1 searches for a village to attack, only the village of a player who has not entered a battle for a minimum of 60 minutes will be returned.
There are two components involved in getting a match:
- Sending the Player's Map Online
- Retrieval of Player #2 map data for battle
And two components involved in finishing a match:
- Storing results of Player #2 back online
- Updating resources for Player #1
Complete Kit - Testing the CityBuildingKit.com PvP
Add your License code to both the Game and Map01 scenes for both Save Load WWW and Save Load Battle. The following two screenshots show that you open the scene, then select SaveLoadWWW or SaveLoadBattle in the Hierarchy GameManager.
Pro Kit - Testing With CityBuildingKit.com PvP
For the Pro Kit, you'll find the URLs hardcoded in the SaveLoadWWW.cs and SaveLoadBattle.cs files. To test PvP with our server software demo, edit both SaveLoadWWW.cs and SaveLoadBattle.cs and insert your license code into every URL request, such as:
?license=INSERT-YOUR-LICENSE-CODE
Setup
Server Requirements
PHP Version 5+
Standard Web Host (any shared hosting or VPS is fine for development testing)
For Security, Change The Default Variable Names
Use the demo scripts at your own risk. We recommend randomizing the default variable names in each of the demo scripts and restricting uploads to secure your server.
Open each of the PHP scripts included with the server software demo and customize the variables such as [email protected] for notifications. Upload all files including the maps directory with the sample maps to your server. Then update the URLs to your hosting in both SaveLoadWWW.cs and SaveLoadBattle.cs in Unity.
Part 1 - Sending the Player's Map Online
The first component involves both Unity and the server side scripting. When a player initiates a battle search, their map data is first saved locally on the device with their ID #, then a copy is sent to the server online.
Post Variables:
Variables | Description |
---|---|
savefile | (File) This is a copy of map data (textfile) saved locally |
mapid | (Alphanumeric Text) This is the player's ID number. If one is not yet created, the scripting in Unity creates one for the player and saves it. |
Part 2 - Retrieval of Player #2 Map Data for Battle
After connecting online and posting the player's map data and ID, the game will download the results. The output expected is another player's map data, and nothing else. No formatting or response codes. The map will be loaded in the battle script and displayed to the user as a battle they play.
However, if a failure occurs, the game expects the response code "0" from the server. You can customize the expected behavior in the battle script in Unity.
Response | Description |
---|---|
Player #2 map data | The complete source of Player #2's map data (no formatting, nothing else) |
0 | An error occurred |
Part 3 - Storing results of Player #2 back online
After the battle is finished, the Player #2 map data is sent online and if successfully store the script expects a response code of "1", nothing else. (No formatting, no quotes)
However, if a failure occurs, the game expects the response code "0" from the server. Like before, you can customize the expected behavior in the battle script in Unity.
Variable | Description |
---|---|
savefile | The complete source of Player #2's map data with resources changed |
mapid | (Alphanumeric Text) This is Player #2's ID number. |
Response Code | Description |
---|---|
1 | Successful storage of Player #2 map data (attacked city) |
0 | An error occurred on the server |
Part 4 - Updating resources for Player #1
After the battle is finished, Player #1 has their resources updated with what they gained from the battle in the local copy of their map data.
Test Your Setup
A demo administration file is included. Access this file to see uploaded maps, upload sample player maps, and delete maps. Each of the maps listed use a random non-identifiable user map ID.
We highly recommend you use this file to test your configuration before playing the game. Make sure upload, viewing, and deleting works before using your Unity game.
How to Generate Maps
You can create your own maps by playing the game in Unity with the Pro or Complete Kits, designing a layout and then opening the settings and pressing Local Save. The Internal Operations console will report the exact filename that was saved based on your user's identification mapid created when the game started for the first time. Save this file. More details in the Game Settings > Save and About Map files pages of the documentation.
Sample Map Data
Please open the About Map Files page of this documentation for more details about map files and online samples.
Deploying to the Cloud
For professional developers who want reliable, fast, worldwide player map hosting, we recommend deploying a simple Apache with PHP AWS EC2 instance combined with S3 for map storage and CloudFront for worldwide instantaneous delivery. The setup won't be as easy as a standard Apache VPS, but the gameplay loading will be near zero and minimal costs since each player's data averages 1KB in size.
You can host data for 10,000 players with approximately 10MBs-50MBs of space.
Updated less than a minute ago