Mistake in blog article

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

Moderators: Lapo, Bax

kevinfoley
Posts: 10
Joined: 07 Sep 2018, 21:10

Mistake in blog article

Postby kevinfoley » 19 Sep 2018, 22:56

There is a mistake in the example code on page two of the blog article "Best of Both Worlds: SFS2x Server Side Unity For Realtime Games" ( https://smartfoxserver.com/blog/best-of ... -games-p2/ );

You have this code in the "init()" function of the Room Extension:

Code: Select all

AirHockeyZoneExtension ext = (AirHockeyZoneExtension) getParentZone().getExtension();


According to Lapo, it is not possible to get the Zone Extension from the init() function of a Room Extension: viewtopic.php?t=20524 Even if we try to do the same thing later, it doesn't work because the Zone Extension and Room Extension are loaded by separate class loaders.

What's the correct way to handle this?
User avatar
Lapo
Site Admin
Posts: 20276
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Mistake in blog article

Postby Lapo » 21 Sep 2018, 08:03

kevinfoley wrote:https://www.smartfoxserver.com/forums/viewtopic.php?t=20524 Even if we try to do the same thing later, it doesn't work because the Zone Extension and Room Extension are loaded by separate class loaders.

It depends on how you deploy the Extensions.
If you deploy them under the extensions/__lib__/ folder you won't incur in the class loader issues as all code is loaded in the main class loader.

Alternatively, if you don't want to do that, you can always use this code instead:

Code: Select all

SFSExtension ext = getParentZone().getExtension();

In other words you avoid casting the Extension to its specific type (which is not loaded in the current context) and you can still interact with it using the handleInternalMessage() calls.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
kevinfoley
Posts: 10
Joined: 07 Sep 2018, 21:10

Re: Mistake in blog article

Postby kevinfoley » 21 Sep 2018, 17:19

Thanks for the reply and tips. I'm sure future users would appreciate it if you'd correct the code in the article as well.

In other words you avoid casting the Extension to its specific type (which is not loaded in the current context) and you can still interact with it using the handleInternalMessage() calls.


This still wouldn't allow us to retrieve the PortManager instance as demonstrated in the article, since that's also loaded with the class loader, but we could use handleInternalMessage() to forward a request to the PortManager to get the port number.
User avatar
Lapo
Site Admin
Posts: 20276
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Mistake in blog article

Postby Lapo » 22 Sep 2018, 08:18

kevinfoley wrote:Thanks for the reply and tips. I'm sure future users would appreciate it if you'd correct the code in the article as well.

Sure, we'll add clarification on using the __lib__ folder for deployment.

This still wouldn't allow us to retrieve the PortManager instance as demonstrated in the article, since that's also loaded with the class loader

With the deployment mentioned above it does work.
Rooms are created dynamically on demand, therefore they run when the Zone has already been initialized, so there is no problem in accessing the PortManager object.
Lapo

--

gotoAndPlay()

...addicted to flash games
kevinfoley
Posts: 10
Joined: 07 Sep 2018, 21:10

Re: Mistake in blog article

Postby kevinfoley » 24 Sep 2018, 22:55

Thanks, but I think you misunderstood. You mentioned using handleInternalMessage() to have the Room Extension communicate with the Zone Extension, as an alternative to deploying the extension in __lib__. However, if we don't deploy the extension in __lib__, we cannot use handleInternalMessage() to pass the PortManager instance to the Room Extension. In such a scenario, the Room and Zone extension would still be loaded by different class loaders, and so the Room Extension would not be able to recognize the PortManager type sent to it by the Zone Extension. I already tested and verified this.

However, we could use handleInternalMessage() to send a "get port number" request to the Zone Extension, have the Zone Extension get a port number from the Port Manager, and return this value without ever passing the actual port manager back to the Room Extension.
User avatar
Lapo
Site Admin
Posts: 20276
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Mistake in blog article

Postby Lapo » 25 Sep 2018, 07:47

Yes I understand what you're saying, but the article does not mention to use handleInternalMessage() as a solution to interact across extensions. It suggests to deploy Extension in the same class loader.

If you want to use the separate class loader it is fine as well and yes, it will require a few changes in the code to make it work, as you have mentioned.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 14 guests