Smartfoxserver Plugin for Cheat Proof Games.

Here’s my first attempt at creating a smartfox server plugin for mmo’s that was server side to reduce cheating by
only allowing updates to occur on the server.
If you are interested in the full code feel free to email me at admin @ bluetopazgames.com.
You can setup a basic server for less than 1 euro for 10 concurrent people.
http://www.smartfoxserver.com/buy/sfs2x#p=elastic

int frequency = 35;
int delay = 0;

// create a game loop
sfs = SmartFoxServer.getInstance();
taskScheduler = sfs.getTaskScheduler().scheduleAtFixedRate(new TaskGameLoop(), delay, frequency, TimeUnit.MILLISECONDS);

private class TaskGameLoop implements Runnable
{
public void run()
{
// loop through users
List users = SmartFoxServer.getInstance().getUserManager().getAllUsers();
Iterator user_iterator = users.iterator();
List userVarList = null;

while(user_iterator.hasNext())
{
User user = user_iterator.next();
int x = user.getVariable(“x”).getIntValue().intValue();
int y = user.getVariable(“y”).getIntValue().intValue();
int direction = user.getVariable(“d”).getIntValue().intValue();
int state = user.getVariable(“s”).getIntValue().intValue();
int dx = 0;
int dy = 0;
boolean blocked = false;
userVarList = new ArrayList();

// room boundaries.
if( x < 0 ) { x = 0; } if( y < 0 ) { y = 0; } if( x > 8160 )
{
x = 8160;
}
if( y > 8160 )
{
y = 8160;
}

if( state == Player.STATE_WALK )
{
List nearby_users = user.getCurrentMMORoom().getProximityList(user);
List nearby_items = user.getCurrentMMORoom().getProximityItems(user);
Iterator users_iterator = nearby_users.iterator();
Iterator items_iterator = nearby_items.iterator();

if( direction == Player.NORTH )
{
dy = -5;
}
else if( direction == Player.EAST )
{
dx = 5;
}
else if( direction == Player.SOUTH )
{
dy = 5;
}
else if( direction == Player.WEST )
{
dx = -5;
}

// stop all movement if they are within 32 pixels of each other.
while( users_iterator.hasNext() )
{
User tmpUser = users_iterator.next();
int userx = tmpUser.getVariable(“x”).getIntValue().intValue();
int usery = tmpUser.getVariable(“y”).getIntValue().intValue();
int absx = Math.abs((x+dx)-userx);
int absy = Math.abs((y+dy)-usery);

//System.out.println( “absx” + absx + ” absy” +absy );
if( absx <= 35 && absy <= 35 ) { blocked = true; } } /* commented out for performance reasons. No items for now.*/ /* while( items_iterator.hasNext() ) { BaseMMOItem tmpItem = items_iterator.next(); int itemx = tmpItem.getVariable("x").getIntValue().intValue(); int itemy = tmpItem.getVariable("y").getIntValue().intValue(); int absx = Math.abs(itemx-x+dx); int absy = Math.abs(itemy-y+dy); if( absx < 32 && absy < 32 ) { blocked = true; } }*/ } if( dx != 0 ) { userVarList.add(new SFSUserVariable("x", x+dx)); } if( dy != 0 ) { userVarList.add(new SFSUserVariable("y", y+dy)); } // send out the data! if( userVarList.size() > 0 && !blocked)
{
SmartFoxServer.getInstance().getAPIManager().getSFSApi().setUserVariables(user, userVarList);
}
}

}

// move creatures+items (MMOItems)

// check collisions

// spawning creatures+items

}

As you can see from the code it’s incomplete.
I think I was trying to use MMOItem for tiles and transmitting those tiles which is crazy.
The idea was that perhaps the players could interact with the world like minecraft, modifying it and then having the state updates shared with the
various clients. I gave up quickly when I saw the performance.

Leave a Reply

Your email address will not be published. Required fields are marked *