How to get zone extension from a room extension.

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
truongnt
Posts: 3
Joined: 03 May 2018, 15:24

How to get zone extension from a room extension.

Postby truongnt » 03 May 2018, 15:37

Hi all,
I need get zone extension from a room extension to communicate data.
In administration Tool, i have setup extension for zone "BasicExamples".
And this is my code:

Code: Select all

public World(RoomExtension ext){      
      this.roomExt =ext;      
      this.zoneExt = (ZoneExtension) roomExt .getParentZone().getExtension();      
      roomExt.trace("Zone: "+roomExt .getParentZone());
      roomExt.trace("Zone Extension :"+zoneExt + " RoomExtension:"+roomExt );
}

When i run server i saw that log:

Code: Select all

INFO  [main] Extensions     - {__lib__}: Zone: { Zone: BasicExamples }
INFO  [main] Extensions     - {__lib__}: Zone Extension :null RoomExtension:{ Ext: __lib__, Type: JAVA, Lev: ROOM, { Zone: BasicExamples }, [ Room: TAI XIU, Id: 2, Group: default, isGame: true ] }


You can see Zone Extension :null.
Please help me fix above code.
Thank you!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get zone extension from a room extension.

Postby Lapo » 03 May 2018, 15:52

Hi,
it looks like the Zone doesn't have an active Extension.
Are you entirely sure that an Extension is attached to that Zone? Another reason why it could return null is if the Zone fails the initialization phase. Typically this is due to exceptions in the Zone's init() method.

Check your logs at server startup, to see if there's any init error.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
truongnt
Posts: 3
Joined: 03 May 2018, 15:24

Re: How to get zone extension from a room extension.

Postby truongnt » 04 May 2018, 13:41

Lapo wrote:Hi,
it looks like the Zone doesn't have an active Extension.
Are you entirely sure that an Extension is attached to that Zone? Another reason why it could return null is if the Zone fails the initialization phase. Typically this is due to exceptions in the Zone's init() method.

Check your logs at server startup, to see if there's any init error.

Cheers


Hi Lapo,
thank for quick reply.
I think i already attached extension to zone.
I'm not sure have exception in Zone's init() method.
This is log init my server, please help me to check it.

Code: Select all

20:47:06,115 INFO  [main] v2.SmartFoxServer     - Boot sequence starts...
20:47:06,778 INFO  [main] core.SFSEventManager     - AnonymousService-1 initialized
20:47:06,808 INFO  [main] impl.DefaultFileReplicator     - Using "C:\Users\Truon\AppData\Local\Temp\vfs_cache" as temporary files store.
20:47:06,887 INFO  [main] v2.SmartFoxServer     - License loaded:

==========================================
LICENSE DETAILS
------------------------------------------
Type            : Community Edition
Max users       : 100
==========================================

20:47:06,888 INFO  [main] managers.SFSBannedUserStorage     - BanUserStorage initialized
20:47:06,902 INFO  [main] managers.SFSBannedUserManager     - BanUser data loaded: 0 records.
20:47:06,911 INFO  [main] v2.SmartFoxServer     - Protocol Type is: BINARY
20:47:06,914 INFO  [main] config.DefaultConfigLoader     - Loading: zones\BasicExamples.zone.xml
20:47:06,954 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: BasicExamples
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

20:47:07,395 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: BasicExamples }, [ Room: The Lobby, Id: 0, Group: default, isGame: false ], type = SFSRoom
20:47:07,409 INFO  [main] Extensions     - {fps}: FPS extension initialized
20:47:07,410 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: BasicExamples }, [ Room: Casino, Id: 1, Group: default, isGame: false ], type = SFSRoom
20:47:07,415 INFO  [main] Extensions     - {__lib__}: Init casino extension
20:47:07,415 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: BasicExamples }, [ Room: TAI XIU, Id: 2, Group: default, isGame: true ], type = SFSRoom
20:47:07,418 INFO  [main] Extensions     - {__lib__}: Zone: { Zone: BasicExamples }
20:47:07,419 INFO  [main] Extensions     - {__lib__}: Zone Extension :null RoomExtension:{ Ext: __lib__, Type: JAVA, Lev: ROOM, { Zone: BasicExamples }, [ Room: TAI XIU, Id: 2, Group: default, isGame: true ] }
20:47:07,419 INFO  [main] Extensions     - {__lib__}: Init game tai xiu
20:47:07,422 INFO  [main] Extensions     - {__lib__}: Init extension tai xiu
20:47:07,429 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: --=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 3, Group: default, isGame: false ], type = SFSRoom
20:47:07,484 INFO  [main] core.AdminToolService     - AdminTool Service started
20:47:07,789 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - Listening Sockets: { 0.0.0.0:9933, (Tcp) } { 127.0.0.1:9933, (Udp) } { 127.0.0.1:8787, (Tcp) }
20:47:07,791 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - 
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|                                         
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_| 
[ 2.13.0 ]

20:47:07,791 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.13.0) READY!
20:47:07,794 INFO  [SFSWorker:Ext:2] Extensions     - {__lib__}: Init zone extension
20:47:10,509 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.1.0) READY.


My setting on Zone Configuraton Image
Thank you!
User avatar
truongnt
Posts: 3
Joined: 03 May 2018, 15:24

Re: How to get zone extension from a room extension.

Postby truongnt » 04 May 2018, 14:55

Oh. :idea:
Maybe I know reason why get zone extension is null.
Refer to log,
21:57:23,830 INFO [main] Extensions - {__lib__}: Zone: { Zone: BasicExamples }
21:57:23,830 INFO [main] Extensions - {__lib__}: Zone Extension :null

21:57:24,203 INFO [SFSWorker:Sys:1] v2.SmartFoxServer - SmartFoxServer 2X (2.13.0) READY!
21:57:24,205 INFO [SFSWorker:Ext:2] Extensions - {__lib__}: Init zone extension
21:57:27,146 INFO [main] v3.SessionFilter - BlueBox-2X Service (3.1.0) READY.

Seem room init happen early than zone init process.
Therefore when i try get zone extension during init room, zone extension is null.
It that true?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get zone extension from a room extension.

Postby Lapo » 04 May 2018, 15:57

There doesn't seem to be any exception on the server side when the Zone extension is launched.

I think the problem is timing.
What it seems you're doing is you're trying to obtain a reference to the Zone Extension in the init() method of your Room Extension.

When the server starts up there's a specific order in which zone elements are created:
first all Rooms are created with their Extension
then the Zone Extension is loaded.

This means that your Room Extension init() is called before the Zone Extension is created. To avoid these issues there's a specific server side event called SFSEvent.SERVER_READY that is triggered when the boot sequence is complete.
If you run your code in such listener you won't have any issues with ordering and such. I recommend you do that.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 40 guests