Well, setting up your own web service with a mysql database isn’t that difficult. The wiki even has a simple example. The general concept is almost always:
User <--> Webservice (PHP script) <--> Database (mysql)
-----------------------------------------------
Client | Server
Side | Side
So the user always communicates with you PHP script. When a user has finished a game, it sends it’s race-data to the PHP script. The PHP script simply checks if that name-nationality-level combination has already a value and if the result is better, replace it.
The user is also able to query the PHP script to get, either the last24 or the all-time top10/top20/top100 values.
I would go with two seperated identical tables. One for each type of leaderboard (24, alltime). If data is incoming you simply do the above mentioned procedure for both tables. The 24 table should also be “cleaned up” frequently. My table would probably look like this:
CREATE TABLE `alltime` (
`name` VARCHAR(15) NOT NULL DEFAULT 'anonymous',
`nationality` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`level` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`time` FLOAT NOT NULL DEFAULT '99999',
`timestamp` DATETIME,
PRIMARY KEY(`name`, `nationality`, `level`)
)
ENGINE=MyISAM;
The first 3 fields are considered as the primary key, so no duplicates are allowed for every combination of those 3 fields. The name is limited to 15 characters and the nationality is just an index into your nationality list / table. You might want to use unity’s SystemLanguage for that. level is also just an index to idenitfy the level. If you want you can change the type also to some sort of string, but it increases the record size in the DB.
time is just the best time for that combination of name, nat. and level. timestamp is only required in the 24 table, but it wouldn’t hurt to include it in the all time as well. That way you can also display when that time was achieved. The timestamp value is used to determine if 24h have passed in which case you would kick a record out of the table during the “cleaning process”.
One major problem you’re going to face is cheating. Since it’s a webservice anyone can simply send in fake data to get on the top of the highscore list. Since you have to trust the data a client sends in there’s not much you can do to prevent cheating. What you can do is calculate some checksum of all data you send in and verify that on the server in the PHP script (MD5 hash with fix salt + random salt).
There are free webhosters out there where you can get wenspace for free. It’s just important to have PHP and a mysql database included. If it’s a serious project, i would suggest to get a paid webhoster as free hosters can terminate your membership at any time, though that doesn’t happen very often ^^. Some of the free hosters have quite nasty rules. So they often forbid to use their service just as database without an actual website on it. So it might be a good idea to simply put a website on to show the highscores as well on the website.
As for the communication between your app and your webservice it’s up to you encode your data and how to pass it forth and back. The most easiest way to pass data from your app to the web is using URL parameters which can easily read in from your PHP script. However most will use form-data in a POST request (a bit more script-kiddy resistant).
If you want to request the highscores from the server, personally i would use JSON. The example on the wiki simply uses tabs to seperate fields and newline characters to seperate records. This can be parsed quite easily with string.Split, but you have to take precaution to not allow those characters in the userdata or it messes up the output or could even lead to a security problem.
ps: It doesn’t matter for which platform you build your game. All have possible internet access and should be able to contact a webservice.