You don't have to write your own masterserver, because Unity provides one that you can build yourself and run on your own server (either rent one or set up one at your home)!
http://unity3d.com/master-server/index.html
This should help to get you going:
http://www.youtube.com/watch?v=1KIoGOYOUvk
http://answers.unity3d.com/questions/43440/setting-your-own-masterserver-up.html
↧