Using db connection of the zone level in the room level.

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

Moderators: Lapo, Bax

User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Using db connection of the zone level in the room level.

Postby yuvallahav » 26 Jan 2012, 09:34

Hello.
Can I use a connection to a db I have created on the zone level inside a dynamically created room, and if so, how?

Thanks.

Yuval.
Bosskafett
Posts: 41
Joined: 24 Jan 2012, 00:04

db

Postby Bosskafett » 26 Jan 2012, 21:34

I suppose you blend db zone with your wanted zone.

:oops:
if(_global.is_rocketsnail == 1){
mc.snail._visible = true;
smartfox.setUserVariables({snl:1, init:false})
}
The Re-creator of Old Games ;D
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 21:37

Yeah, this makes no sense to me, sorry, was that a joke or am I missing something?

Anyway, I really need an answer for this, do I need to create a new connection to the db in my room level extension, even if I already have an open connection to my db set up on my zone level? and if I can use that zone level connection, how would I go about doing so.

Anyone? please?

Yuval.
Bosskafett
Posts: 41
Joined: 24 Jan 2012, 00:04

db

Postby Bosskafett » 26 Jan 2012, 21:43

Ah yes this is possible, dig out dbExtentionAdvanced.as in sfsExtentions and include that in your zone. Also use the functions inside the db examples fla within your actionscript. Such as getData() would fetch from a database.

I hope this matches what you need,

Bosska
if(_global.is_rocketsnail == 1){
mc.snail._visible = true;
smartfox.setUserVariables({snl:1, init:false})
}
The Re-creator of Old Games ;D
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 21:50

I see you misunderstand my question.
I know how to use a db, I know how to set up a connection to it, I'm using my own db, not the built in db that comes with smartfox, there is no problem there.
My problem is that I need to use a db connection in a ROOM level, and not in a ZONE level, where my db connection was initially set up, the question is if there is a way for me to use the connection I set up in my zone level to read/write information with from my ROOM level (a room a create dynamically, and has it's own room level extension), or do I need to create a new connection instance also on the ROOM level.

Yuval.
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 21:51

Also, just to make sure everything is clear, I'm not talking about doing this in the client, but on the server side, inside my extension.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 26 Jan 2012, 22:30

Hi.

My suggestion is to just have 1 connection in your Zone extension, which will be the only extension to be able to manage the db.

Despite not being much documented, in the extensions you have a method called handleInternalRequest, which is used for communicating between extensions. In this case, I suggest you to, in the Room extension, when you need to access the database, you call that handleInternalRequest method of the Zone extension, this way you only need 1 connection to the db.

For more information regarding the handleInternalRequest method, I suggest you to read this chapter of the docs, as well as the Server-Side Java Documentation, as the ActionScript one is a little outdated but AS Extensions support the same methods as Java ones.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 22:34

Hey there rjgtav, as always, you come to the rescue, I was talking from the start about the need to have only the one zone level connection to be used by all rooms I create in that zone, and I was looking for the way to "talk" to that zone level connection from the room extension, as you said, I didn't know I can invoke the zone's "handleInternalRequest" but I will try that, can I do the same from the zone to the room? I mean, use the "handleInternalRequest" if the room extension invoked by the zone with any replay from the db I will get there?
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 22:39

It's still very weird for me to know there is nothing built in for this kind of action that is needed, as we are talking not about different zones communicating, but a room, in a zone, using a zone's resources, and a heavy and important one as a db connection as that.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 26 Jan 2012, 22:43

Hehe thanks :).

Yes you can also invoke that method of the Room extension. But, in the handleInternalRequest() method of the Zone, if you at the end return an object, it will be returned to the Room Extension. To retrieve that object (from the room extension), you do something like:

Code: Select all

var myObject = myZone.getExtension("extensionName").handleInternalRequest(myParams);


And on the Zone Extension you have:

Code: Select all

function handleInternalRequest(params){
//super complex logic here
var resObj = {};
resObj.dummyValue = 1;
return resObj;
}
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 22:45

I'll give it a go, but... I have a fear, maybe it's not based, but... if I start using a "handleInternalEvent" function I custom to my needs on the zone extension, does it not overwrite all the actual zone action for that function, like room created, user logged on and so forth?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 26 Jan 2012, 22:49

It looks like you're needing a rest :).

This method I'm talking about is the handleInternalRequest, which is specifically used to communicate between different extensions.

The handleInternalEvent is another method, used by the server, as you said, to handle internal events.

So no, handleInternalRequest method is totally independent form the handleInternalEvent, and everything will work correctly :)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 22:50

I do need a rest, but the show must go on, and I must show my boss some results by, I hope, tomorrow morning, I'm trying this right now, stay tuned for an update in a minute.
Last edited by yuvallahav on 26 Jan 2012, 22:58, edited 1 time in total.
User avatar
yuvallahav
Posts: 247
Joined: 07 Oct 2008, 13:03
Location: Rome, Italy
Contact:

Postby yuvallahav » 26 Jan 2012, 22:55

Slap me silly and call me an ass, it works!!

Thanks rjgtav, now I can go to sleep, and fall asleep knowing I can go on working tomorrow with a clean mind, until the next problem!

Good night, and thanks again!
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 26 Jan 2012, 22:59

Ahah no problem
Good night for you too, happy coding :P
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 25 guests