6.2 Introduction: Extensions architecture

Before we start seeing how extensions plug into the SmartFoxServer PRO architecture have 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.
Let's start by examining the diagram from the very top of it:

The red rectangle represents the server itself. As you may remember SmartFoxServer can run many applications at once using "Zones" (the green rectangles). Essentially each Zone is a container of Rooms, where users can interact with each others, chat, play games, exchange data etc...
The Zone contains also other two other important objects: the extension and the database manager: the former is custom code that can be plugged in the Zone to handle your custom logic and the latter allows the developer to connect to an external db.

» Extension Level

As shown in the above diagram, Extensions can be plugged at Zone Level or at 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.

Let's suppose we're creating a chess game, where each game-room will hold a game for 2 clients.
In this case we could write our chess game logic and plug it at Room Level, then each game room will load a copy of that extension and run it. This way you only have to write the code necessary to handle one game, and then the server will dynamically attach your game logic to each game room.

An example for a Zone Level extension would be creating a mailer extension that can be called from any room within the Zone. The mailer would allow to exchange emails between chat users without leaving the Fash multi player application, and it would allow users to compose the messages inside the client application. In this case the Zone Level would be the better choice as we need one instance only of our extension, available for all rooms.

» 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 the 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