How to get an instance of a room level plugin

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

manx
Posts: 11
Joined: 25 Mar 2009, 10:05

How to get an instance of a room level plugin

Postby manx » 05 Apr 2009, 06:11

We are making a four player game so for each gameroom created we add an plugin as follows:

Code: Select all

       Room newRoom = null;
   // Here we pass the room parameters
   HashMap map = new HashMap();
   map.put("name", ScriptConst.GAME_NAME+romcounter);
   map.put("pwd", "");
   map.put("maxU", "4");
   map.put("maxS", "0");
   map.put("isGame", "true");
   map.put("xtName", "SFS_Game");
   map.put("xtClass", "SFS_Game");
        helper.createRoom(zone, map, null, true, true);

We are assuming this creates a room level plugin.
In Electroserver we can access this plugin in the following manner:

Code: Select all

SFS_Game game = (SFS_Game)getApi().getRoomPlugin(zoneid, roomid, "SFS_Game");

Is there an equivalent for this in SFS .
If not,How can we access the plugin for a specific room.

Thanks in advance,
Manx
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 06 Apr 2009, 06:59

In SmartFoxServer you usually don't even need a reference to an extension, especially if it is at Room-Level.
Extensions get all their server events in the handleInternalEvent handler and usually don't need to talk to each other.

Can I ask what would you need it for?
Lapo
--
gotoAndPlay()
...addicted to flash games
manx
Posts: 11
Joined: 25 Mar 2009, 10:05

Postby manx » 06 Apr 2009, 12:50

Actually i have a main lobby plugin and am creating various Room-Level plugins from there. i.e Each game room will have a plugin associated with it.

Now once the game starts i want some information that is stored in a particular room plugin i.e In SFS_Game class.

Is there any way of doing so.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Apr 2009, 13:18

Just one small note: what you call "plugin" is (I think) an extension for SmartFoxServer. Sorry for being picky, it's just that you'll see references to extensions mentioned all over the place in the docs, forums and examples :)

Back to your question:
usually the game start logic runs in the Room Level Extension.
For instance, when you detect the "right" number of players in the room you can start the game, right?
Then your code can store any kind of data in any global variable as you please.

If you check the SFSTris game (the version running with a server side extension) you will find an example of what I am talking about
(Chapter 8.8 of the docs)

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
manx
Posts: 11
Joined: 25 Mar 2009, 10:05

Postby manx » 08 Apr 2009, 07:56

Yes by "plugin" i do mean extension .
Sorry am stuck between server notations!!!!

The method what you mention is the right way if you have one game in many rooms.
But what we are doing is slightly different.
We create game room based on the level and difficulty selected by a user.
Now these rooms are created on the fly and i need to get some info from a game room with x level and y difficulty so that's were my question comes into the picture.

Anyways i am looking for a work around myself will update you if i get anything and do let me know if you get my problem and hopefully a solution too

Thanks for your time
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Apr 2009, 09:07

Now these rooms are created on the fly and i need to get some info from a game room with x level and y difficulty so that's were my question comes into the picture.


Each room exposes a properties object (of type java.util.Map) which can be used to store any state, data and whatnot

There are also Room Variables which can be accessed from outside of each Room. The only difference is that Room Variables are broadcasted to all clients in the Room while data in the properties object stay server-side only.

hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
manx
Posts: 11
Joined: 25 Mar 2009, 10:05

Postby manx » 10 Apr 2009, 08:02

Makes sense

I was using room variables till now . i will try out properties as it seems to be a better option.

Thanks for the help..

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 22 guests