484 | Chapter 13: Symmetric Proxy Pattern
Example 13-4. proxygame.asc
application.onAppStart=function( )
{
trace(this.name + " is reloaded");
this.ss_so = SharedObject.get("proxmove",false);
this.dup1=false;
this.dup2=false;
};
//------------------------
application.onConnect=function(currentClient,username)
{
currentClient.name=username;
if(currentClient.moveNow==null)
{
currentClient.moveNow="ready";
}
var cl=application.clients.length;
//Check username and see if there are no
duplications or more than two players
if(((username == "player1" && !this.dup1) || (
username == "player2" && !this.dup2)) && cl<=1)
{
this.acceptConnection(currentClient);
this.ss_so.setProperty(currentClient.name,username);
if(username=="player1")
{
this.dup1=true;
}
else
{
this.dup2=true;
}
}
else
{
this.rejectConnection(currentClient);
trace("Connection rejected");
}
currentClient.makeMove=function(moveit)
{
application.ss_so.setProperty(currentClient.moveNow,moveit)
someMove=application.ss_so.getProperty(currentClient.moveNow);
playerNow=application.ss_so.getProperty(currentClient.name);
someMove+="~"+playerNow;
application.ss_so.send("onProxyMove",someMove);
};
currentClient.checkPlayNum=function( )