handleInternalRequest - xt interoperability issue

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
CB
Posts: 45
Joined: 04 Aug 2006, 11:15

handleInternalRequest - xt interoperability issue

Post by CB »

I found the following response in the post called 'banning quitters'
You simply have to add a handleInternalRequest method in your AS server side code for handling the call.

Code:
function handleInternalRequest(obj)
{
...etc...
}


In order to call another extension you can translate the code like this:
Code:
// Get a reference to the Zone where the target extension is running
var zone = _server.instance.getZone("testZone");

// Get a reference to the Extension we want to call
var targetExtension = zone.getExtension("testExtension");

// Invoke the handleInternalRequest on the target extension and receive the response
var response = targetExtension.handleInternalRequest("Hello");

trace("Response: " + response);


hope it helps
Which works just perfectly if I'm making an internal request from a room extention to the zone extention the room sits underneath.

But I'm stuck on just how to go about sending a request from the zone down to a room extention . I assume that I need to get a reference to the room extention and have tried first getting the correct room object which works fine using (form the zone extention)

var room = zone.getRoom(roomID)

but then when I try

var targetExtension = room.getExtension("xtname");

I get an error stating: TypeError: Cannot find fuction getExtention . . .

So

HOW DO I go about getting a reference to an extention running in a room?

Thanks

C
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

The code should be this

Code: Select all

var targetExtension = room.getExtManager().getExtension("xtname"); 
Lapo
--
gotoAndPlay()
...addicted to flash games
CB
Posts: 45
Joined: 04 Aug 2006, 11:15

Still no soap

Post by CB »

I'm still having an issue with this.

Here is my code:
zone = _server.getCurrentZone()
// Get a reference to the room where the target extension is running
var room = zone.getRoom(params) //where params are the room id

// Get a reference to the Extension we want to call

var targetExtension = room.getExtManager().getExtension("utable");

// Invoke the handleInternalRequest on the target extension and receive the response
targetExtension.handleInternalRequest("calling back");


This is the error I'm getting: Type Error - cannot find fuction getExtension.

Does the internal fuction: getExtention only apply to zones? Does this interoperability only relate to extensions running in zones? ie zone to zone communication?

If I grab the roomObj and then do this:

var targetExtension1 = room.getExtManager();

and then this:

for(zlable in targetExtension1){
trace(zlable + " : " + targetExtension1[zlable]);
}

I get a list of all the functions attributable to the roomObj's extension manager, and there doesn't seem to be a function there called getExtension which I think is the issue. There IS a function listed called getExtensionList - but this doesn't seem to work.

Additionally, when the rooms in the Zone are created I use the following code with no issue:

for (i in response.db){
//trace("Town: " + response.db["Town"]);
var roomObj = {}
roomObj.name = response.db["Town"];
roomObj.maxU = response.db["MaxPlayers"];
roomObj.maxS = response.db["MaxSpectators"];
roomObj.isGame = true
roomObj.uCount = true
roomObj.xtName = "utable"
roomObj.xtClass = "utable.as"
theRoom = _server.createRoom(roomObj, null, true, true)
if (theRoom != null)
trace("Rooms Created Successfully")
else
trace("OUCH! Room was not created!!!")
}
to create the rooms in the zone based on a table in my DB.

These work just fine.

Why though, if I have the roomObj can't I do this:

trace(roomObj.xtName);

when I have no problem doing this:

trace(roomObj.name);
or
trace(roomObj.MaxU);

You've got the extension attributed to the room sitting somewhere, but where? :lol:
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

getExtension is with an S not getExtention
Lapo
--
gotoAndPlay()
...addicted to flash games
CB
Posts: 45
Joined: 04 Aug 2006, 11:15

yup

Post by CB »

Yes I know :)

var targetExtension = room.getExtManager().getExtension("utable");

like above.

But there doesn't seem to be any function getExtension available in the room level extention manager

The object returned with zone=_server.getCurrentZone has a function available named getExtension

but I don't seem to find a function in the roomObj called getExtension or in the object returned with:
roomObj.getExtManager()

C
CB
Posts: 45
Joined: 04 Aug 2006, 11:15

TA DA!!

Post by CB »

Lapo -

I believe the code should be:

var targetExtension = room.getExtManager().get("xtName");

not

var targetExtension = room.getExtManager().getExtension("xtName");


So IF you want to use handleInternalRequest between ROOMS

You need:

1) the room object
2) the extention Manager within the room object
3) a reference to the extenSION running in the room which you grab with:

var targetExtension = room.getExtManager().get("xtName");
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

You are perfectly right, I apologize :oops:
I suggested the code from memory, but I didn't check it.
Lapo
--
gotoAndPlay()
...addicted to flash games
CB
Posts: 45
Joined: 04 Aug 2006, 11:15

Post by CB »

NP! It would probably be a good idea to update the docs with the AS code for talking between rooms and zones as I'm sure this feature will be used extensively.

Best

C
Post Reply