Examples (iOS)
Examples (Android)

 

» Zones and Rooms architecture

SmartFoxServer 2X introduces significant improvements in the way Zones and Rooms can be configured with respect to SmartFoxServer 1.x. In particular we have established a new simple concept called Room Groups that allows to organize Rooms into logical groups, separated from each others. Users will be able to subscribe for events happening in the Groups they are interested in, ignoring all the others. 

A major advantage of this approach is that the initial room list sent by the server will be smaller, and the number of events fired to each client is highly reduced, especially in case of high traffic applications.

An example will clarify the concept:

zone diagram

An user could initially subscribe to the Lobby group and receive Room updates (such as newly created or removed rooms, user count changes and Room Variables updates) only for the Rooms under that Group.
If the user is interested in playing games he can subscribe to one of the other game Groups, see which games are available and join them. Users can also unsubscribe any Group at any time. The User could even avoid to subscribe to any Group at all and still be able to join any Room in the Zone, although he won't receive any updates from Rooms that are not joined.

The new approach, in conjunction with the finer-grained level of Zone and Room configuration (more on this later), allows the application designer to create highly sophisticated systems whith multiple lobbies, games, personal rooms, private areas, etc. The new features also provide a more rational and organized way to manage thousands of Rooms in the Zone while keeping the amount of client updates to the bare minimum.

The following list describes a few different possible scenarios.

Finally Groups can be created at runtime and subscribed/unsubscribed dynamically.

» Fine-grained Zone and Room events

With SmartFoxServer 2X you have more control over the events fired by each Zone and Room.
This is an example from the Room configuration in the Administration Tool:

AdminTool

The above interface shows how you can fine tune each Room-level event and permission when creating a new Room. According to the above configuration users will be able to change the name and password of the Room, while the resizing (capacity change) will be denied. Public messages are also allowed in the Room and all available events will be notified.
In another Room you may want to configure these settings differently, suppressing some of the events and providing a different set of permissions.

Rooms define two categories of settings: Permissions and Events.

Permissions indicate which Room-related operations can be executed at runtime.

Events indicate which events the Room will notify to the joined clients. Finally, Rooms have a new way of defining their Removal Mode, which indicates if and when the Room should be auto-removed. The following settings are available.

» User count updates

One of the most bandwidth eating update in SmartFoxServer is the User Count Update event, which is fired to all users each time the number of users inside any Room changes. Under an heavy traffic this event can be fired dozens of times per second, leading to significant bandwidth consumption and dropped-messages problem.

SmartFoxServer 2X introduces a couple of engine-level optimizations that reduce the impact of user count updates by a large degree.

To give you a better idea of how the throttling system works, let's suppose we have set the interval to 2000 milliseconds. This is what happens between two intervals:

This is what is really sent as the update on the next interval:

Only the latest up-to-date user counts are transmitted and all the rest is filtered out.

» Room Variables and User Variables

SmartFoxServer 2Xintroduces significant improvements in the area of Room/User Variables adding more flexibility on both client and server side.
One of the most requested enhancement was to support nested objects and we have added that. Both arrays and dictionaries are now fully supported. Also we have added the following two new settings.

This is a quick example of how you can set Room Variables in an Extension:

 
private void setSomeVariables(Room room, User owner)
{
	List<RoomVariable> listOfVars = new ArrayList<RoomVariable>();
	listOfVars.add( new SFSRoomVariable("bgImage", "coolBackground.jpg") );
	listOfVars.add( new SFSRoomVariable("stars", 4) );
	
	RoomVariable hiddenVar = new SFSRoomVariable("isPremiumUsersOnly", true);
	hiddenVar.setHidden(true);
	listOfVars.add(hiddenVar);
	
	// Set variables
	sfsApi.setRoomVariables(owner, room, listOfVars)
}	

As you can see the Room Variable called hiddenVar is marked as hidden and it will not be transmitted to the client. The server-side code will be able to check it and see if the Room is for premium users only.

On the client side (ActionScript 3), setting variables is equally straightforward:

 
private function setSomeVariables(room:Room):void
{
	var listOfVars:Array = new Array()
 
	listOfVars.push( new SFSRoomVariable("bgImage", "coolBackground.jpg") )
	listOfVars.push( new SFSRoomVariable("stars", 4) )
 
	// nested object
	var chatSettings:SFSObject = new SFSObject()
	chatSettings.putUtfStringArray("allowedFonts", ["Verdana", "Arial", "Times New Roman"])
	chatSettings.putIntArray("allowedFontSizes", [10,11,12,13])
	chatSettings.putBool("isBoldAllowed", true)
	chatSettings.putBool("isItalicAllowed", true)
	chatSettings.putBool("isUnderlineAllowed", false)
	
	listOfVars.push( new SFSRoomVariable("settings", chatSettings))
	
	// Set variables
	sfs.send( new SetRoomVariablesRequest(listOfVars, room) )
}