How to prevent multiboxing in flash game?
I have multiplayer flash game (AS3) and I would like to prevent multiboxing, e.g. prevent user running two (or more) instances of my game at one computer. Is there simple and reliable way how to do that? I don't want to filter them based on IP address.
I tried to use LocalConnection, but it was unreliable. It worked most of the time but for some reason it failed sometimes.
Then I tried to use SharedObject to write random value to it and than check for change in periodic interval. Idea is that when second instance starts, it will overwrite previous value and check in first instance will fail.
public function MultiboxPreventer(callback:Function)
{
uniqueKey = Math.random() * uint.MAX_VALUE;
so = SharedObject.getLocal("prefs");
so.data.multiboxKey = uniqueKey;
so.flush();
trace("MB init: " + so.data.multiboxKey);
so = null;
this.callback = callback;
var t:Timer = new Timer(10000, 0);
开发者_运维知识库 t.addEventListener(TimerEvent.TIMER, checkKey);
t.start();
}
private function checkKey(event:TimerEvent):void {
so = SharedObject.getLocal("prefs");
if(so.data.multiboxKey != uniqueKey) {
callback();
}
trace("MB check: " + so.data.multiboxKey);
}
but when I test this it behaves as if each instance had its own SharedObject so they never rewrite each other's value.
What is best way to accomplish this?
Use local connection
If the connection already exists you know that there is another game open because the connection will fail if already in use.
Of course this only applies to 1 computer.
import flash.net.LocalConnection
var lcReceiver:LocalConnection = new LocalConnection();
try {
lcReceiver.allowDomain('*')
lcReceiver.connect( '_tectcon');
} catch (error:ArgumentError) {
trace('CONNECTION FAILURE ' + error.message )
}
精彩评论