RTS, PHP/SQL networking.

I’m coding an RTS and for multiplayer I am going to use PHP and a SQL database. :sunglasses:

I have one question though I don’t know how bad this will be for my server

Psuedo code:
PHP request
wait for data
repeat

I could always just make it whenever the players LOS changes it does a PHP request but I want to know if this one is good before I make the LOS way.

I needed this information two days ago and I still need it! :rage:

By Server do you mean the Server hosting the php script ? Or do you mean the Game Server ?

I’ll assume you mean the Game Server.

If you use the WWW class to call your php script it will do the request in the background and not hold up the main thread running the game.

details at Unity - Scripting API: WWW

Whether this is a good method for your game or not depends on what information you are fetching or posting to your PHP script. Is it high score data or other information ? If it is player positions and world state information to share between players you would be better looking at Unitys inbuilt Networking classes.

I got a cheap internet host with SQL/PHP thats it. So yeh a server hosting the PHP

I cannot afford an actual game server so I cannot use the networking class. I have to get the positions/whatever from an SQL database.

If you use the built in Networking classes one of the players in the game can act as the server then you don’t have to pay for hosting etc.

The introduction materials for Networking are here

http://unity3d.com/support/documentation/Manual/Networked%20Multiplayer.html

and there are networking examples at the following link
http://unity3d.com/support/resources/example-projects/networking-example

If you’re using WWW requests and a database your position updates will not be quick enough and you’ll end up with player positions being updated in a very jerky manner.

My plan with this game is to be a 24/7 RTS like tribal wars only real time.

You can set where people go at what time even if no-one is online at all. I was going to have the destinations set on the database and have the game calculate where the unit is according to the time the unit was given that order. I could do that AND have a player act as a host when they are online though and speed stuff up. :sunglasses:

Good luck with the project, sounds pretty cool, just a note fome someone who chomped thru a lot of bandwidth and crashed his webserver - Don’t run a WWW request inside an Update() unless you check how often you have sent the request before hand :slight_smile: oooooops!

realtime RTS means you won’t be using HTTP, no hoster will accept you on his farm without a fully dedicated machine and metered traffic costs.
realtime RTS in a pseudo mmo environment normally is a job for photon, neutron or Smart Fox Server pro

Yes, dreamora if I wanted an MMO RTS I would but this is not really and MMO in a sense here is the setup of the game:

The player has a mothership spacecraft that they can use to travel the galaxy, each planet can be colonized and is a battlefield. A maximum of 5 people can be on a planet at a time and thats when the multiplayer comes to play. I plan to setup the battlefield (after the recomendations from this thread) like this, When a player logs onto their battlefield and no other player is on it they will host that server until they log off. A PHP script will download all of the data of that battlefield as of that time onto their computer (May have CE probs :() and the game will carry out from there. Every 5 minutes the server will be backed up to the SQL database and when the host logs off it will back up the data and find another host. Well thats the theory at least. :sunglasses:

sounds rather clumsy and unworkable.

  1. the host would have to backup all the data through php … will put some serious pressure on that (direct sql is unlikely an option, you don’t want wildcard accesses to your db)
    also where do you intend to store the intermediate data? basically the sql always should have the servers current state as it can’t replicate the state for other users without having it :wink:

  2. http is nice for a few things but not sending hundreds of k from each user to each user … so if the R in your RTS is meant for real you will pay some massive fee for traffic and a machine strong enough to not die on the web and db end.

For such a game I would heavily favor Smart Fox actually, as you can hook into the db directly from the serverside among other things and it really works “in realtime” (TCP) and runs rather lightweight especially on the cpu compared to what you have.
Same goes for Photon if you favor that.

As most of my projects are. :smile: I manage everything in a strange way. I think it wouldn’t be too much stress on the server though. I am doing approx. 10 php scripts every 5 minutes (And thats only if it gets popular) for updating the data incase the host’s internet dies, and players finding the IP of their host. I beleive with Unity’s networking that if you connect to a server it downloads everything instanitiated in it. I’ve never work with it before though.

and how do you intend to sync the data between the 5 players otherwise? regular networking through an own master server setup or alike? :slight_smile:

and yes up to a given degree just having it instantiate things would work