One of the maps I've played, nicknamed SotiS (DoTA in SC2) has the ability to maintain stats, which are sent back to their own server.
Does anybody know how this is done?
SC2 maps do not have the ability to connect to databases or web services - this could easily be abused. SoTiS can do it using a separate application, but most maps do not use this.
The only persistent storage SC2 maps have are the bank files, XML files saved with the extension .SC2Bank
in your SC2 data folder. All player stats, settings, etc. from that map are stored in that map's bank file.
The maps usually do not actually keep track of global records - rather, they keep track locally of the best records seen so far. Every time a game is started, everyone's individual leaderboards are combined and overwritten with the combined leaderboard. This causes the leaderboard records to spread very quickly, much like a computer virus.
For example, if my top-3-players list consists of having seen player A with score 300, player B with 200, and C with 100; and you've seen player D with 400, A with 350 (he improved his score!) and E with 50; then when we play with each other, both of our high-score lists will be overwritten with player D with 400, A with 350, and B with 200. There are a few more kinks to work through (ex. usernames are not unique, so you also need to propagate some sort of unique ID), but otherwise this solution works well.
Of course, since the high-scores are stored locally, it will always be possible for someone to hack the scores. The only reason stats-hacking is not more widespread than it currently is is that the bank signature algorithm has not been reverse-engineered
The bank signing algorithm has now been released to the public by hackers, and, as expected, high score lists on all maps are now completely meaningless.
I believe you can write to files with the scripting available in SC2. The server interaction is done by a separate application.