Working on a multi-player turn-based game. So far I am using Unity Networking and it works fine with a server running an few players connected to the server and everyone playing together at the same time. Well, by everyone I mean several LAN machines with me running around the room pressing the buttons.
I am interested in a Play-by-Database feature, similar to PBEM (Play-by-Email), so that all players don’t have to be online at the same time. Number of players per game could be from 2 to 12, but the database could handle many such games running at the same time.
I understand the code where unity gets and sets data from a db. What I know nothing about is how would I get the db to trigger processing in my unity server? Example:
I have 6 players and a per-turn timelimit of 24 hours for a particular game. I was thinking:
- At some time during the 24hrs, each player runs their Unity client and sends their ‘orders’ for the turn to my database (this seems straight forward)
- Once all 6 player have submitted their orders, or the timelimit has expired, the database somehow triggers a headless unity process to run. (here’s the part I don’t know enough about)
3)this unity process then sends the results of the turn back into the database.
4)Next time players connect to the database, they download the results from the database. (again, straight forward)
Presumably the unity server is running windows, as I believe that is the only platform that can run a headless/displayless unity.
Can MySQL be setup to run an external process when certain conditions are met (i.e. all players submitted turns or 24 hours has passed) ?
Or do I have to have a cron job (possible in windows?) or similar persistent script that polls the db and if the conditions are met, then launches unity with some commandline args or a config file that tell it to load the orders from the db?
Or even just have 1 or more persistent Unity processes that polls the db at intervals and just grabs whatever game is ready to be calculated?
I guess the last 2 options have the advantage that the db can run on a different machine than the unity processes. Only the db needs to be on a ‘real’ server accessible from the internet.