A Unity3D script to prevent your precious web game from being pinched from authorised websites and just hosted somewhere else.
This sort of very simple protection is especially important if you are trying to monetize your web game and do not want it spread around on websites where you don’t see any financial compensation.
If you host on Wooglie.com or Shockwave.com, I highly recommend you at least drop this script in to your project. It’s one more line of defence against random people just swiping your game and hosting it on their own advertising supported website.
How to use: Copy and paste this code in to a new C# script named AntiPiracy.cs and then attach the script to one of your game objects, such as the player, or the main menu. You only need to use it once, and it only needs to execute once.
You specify the list of permitted remote hosts in the Unity3D Inspector. There can be multiple remote hosts, though you should generally create a new build for each website you release your game on as there can only be a single bounce URL. For Wooglie.com your remote hosts would be http://wooglie.com, http://www.wooglie.com and http://contentmirror.wooglie.com. You must put http:// or https:// in front of each of your remote hosts for the script to work. The script is reasonably smart but it cannot work if you give it bad input.
You can change the list of permitted local hosts too, though you shouldn’t need to unless you are doing something unusual. Local hosts are used when you run your game in a web browser from file:// or http://localhost/.
You can specify whether to permit running on local host with a simple check box. This lets you test your game in a web browser by using Build and Run (CTRL+B on Windows) without having to do anything special.
If the piracy test fails, you specify a URL for the web browser to redirect the player to. This can be anything you want, but should probably be the homepage of the game or the correct page for the game on Wooglie.com or Shockwave.com.
You can manually invoke the piracy test by calling the function TestPiracy(). You could test at the beginning of every level if you so desire. Though one test is usually sufficient.
The script runs automatically at start-up. You can disable this behaviour by commenting out the function Start() and then manually invoking the piracy test.
If you want to be really sneaky, you can wait a few levels, or a few minutes before bouncing the player out of the game.
When you create a release build I suggest you disable Permit Local Host in the Inspector unless you want your players to be able to download and play your game from their desktop.
How it works: The script maintains a list of websites that are permitted to host your game. When the script starts up it looks at website it is being hosted on, and if it doesn’t match up with one of the permitted websites you’ve specified, it bounces the player to a webpage that you’ve specified.
Assumptions: This isn’t going to stop anybody really determined. It’s a simple matter for anyone willing to take the time to decompile your entire game and edit the strings containing the list of permitted websites. What it will do is prevent 90% or more of the websites that just harvest random
The License: It’s the GNU Lesser GPL. That means you can take it, modify it, put it in your own game, and so on. You have to leave the copyright notice in place, if you create a modified version and distribute it, you have to supply the source code. You cannot sell the AntiPiracy script, but you can include it in a product that is for sale.
If you represent Wooglie.com, Shockwave.com or any of the other websites out there that host Unity3D games, feel free to link directly to this webpage, and also host the file directly on your own webpage so long as the entire file, including copyright information, remains intact.