1

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?

Lope
  • 5,388
  • 4
  • 30
  • 40
  • Have you tried using a local path in getLocal()? What context are your SWF files in (local file, hosted)? – Michael Brewer-Davis Sep 28 '11 at 22:33
  • I was testing it as local file as well as hosted on my site, it didn't work either way. I didn't try setting path in getLocal(), I am going to look into it – Lope Sep 28 '11 at 22:45

1 Answers1

0

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 )
}
The_asMan
  • 6,364
  • 4
  • 23
  • 34
  • as I mentioned in original question, I tried that, but it isn't very reliable. I was able to start 2 instances of the game from time to time. But it still looks like best solution so I will probably use it – Lope Sep 29 '11 at 21:22
  • I use this all the time and never have reliability issues. the only place I can think of it failing is if one connection is activeX and the other a plugin, but I haven't tested it so don't know. At the least it should keep them from opening up new tabs and running it. – The_asMan Sep 29 '11 at 22:38
  • yeah, I noticed that lot of people are using this without any problems but not me :/ I am not sure if it is something specific about my game (I have no idea what it might be) or maybe how some game portals handle their swf files – Lope Sep 29 '11 at 23:25
  • Or another aspect you can look at is to allow multi-boxing. Just make it pointless in the game to do it. – The_asMan Sep 29 '11 at 23:40
  • I have strategy game, I can't allow it, it ruins experience for other players – Lope Sep 30 '11 at 00:17
  • Not sure how a strat game would matter with multibox. Normally the only games that hurt from multiboxing are games the at you have to grind xp/money on. And that you can just ban accounts – The_asMan Sep 30 '11 at 15:12
  • if there are 3 players in game, and 2 of them is actually one person than he has huge advantage, because he won't attack himself and has in fact twice as many resources as the other guy. This can ruin game pretty fast (and it is currently happening to my game) – Lope Oct 01 '11 at 12:11
  • Log IPs for accounts that are in session. If you have more then 1 you know its a cheater – The_asMan Oct 03 '11 at 15:18
  • they might be behind NAT, in same school/household/whatever... they might be different people and use same IP – Lope Oct 03 '11 at 18:01