6.2 Introduction: Extensions architecture

Before we start seeing how extensions plug into the SmartFoxServer PRO architecture let's take a look at this diagram:

Even if it may look complicated at a first glance, the way extensions are connected to the server is very simple.

SmartFoxServer can run many applications at once using the concept of "Zones" which are represented by the green rectangles. Each Zone can run its custom code in complete isolation, it can contain any number of different Rooms (the gray boxes), where users can interact with each others, chat, play games, exchange data etc...
Each Zone also provides the abiltiy to access a database source in very convenient way through its "Database Manager", which can be configured in the main server config file and it becomes available at runtime, providing direct access to the database.

» Extension Level
Extensions can be plugged at two different levels: Zone Level or Room Level. The only big difference between the two types is the amount of control they can have over the server objects. In other words an extension plugged at Zone Level will be able to see all the rooms inside that Zone and all the clients connected in each room, while extensions plugged at Room Level will only be able to control the users and the other objects available in that specific Room.

A typical use-case for a Room Level extension is a multi-player game system running many different types of games. Supposing we have 20+ different games like card games, table games, real time game etc... we could write the server side logic of each title in a different Extension and plug the right game extension to each new game room created.

A Zone Level use case would be the creation of a Lobby with a registration system, an avatar customization section, user profile etc...
The extension could also be responsible for handling game challenges, chat rooms, one-on-one private chats etc...


» Performance considerations

When planning the development of a server side Extension it is also important to consider the amount of performance needed by Zone Level Extensions and Room Level Extensions. The latter are instantiated each time a game room is created and attached to it.
If you're planning to develop complex server side logic or if you are going to handle many thousands games simultaneously you should always consider the pros and cons of using one approach or the other.

If your server is running 2000 games simultaneously and you're using extensions at Room Level, you're going to have 2000 instances of your extension running concurrently in the server, requiring more CPU time and memory than a Zone Level approach, where only one extensions is responsible of handling all the game rooms.

More in general when your server side logic becomes complex and you can foresee a high number of concurrent clients, it is reccomendable to choose Zone Level Extensions in order to save server resources.

On the other hand simpler extensions (for example a turn-based game) can be conveniently developed at Room Level.


doc index