Multiple Extension

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

Moderators: Bax, Lapo, rjgtav

Multiple Extension

Postby dimooze » 02 Jan 2012, 21:46

Hi all !

I'm actually developping a game with this logic :
- login
- Then i do a PHP request to retrieive users that can play and then i create a room game for them. The room is created by the server and have its own extension to manage connection and disconnection.
- When all the users are connected to this new room i send a response to my client and i create a new AS3 class that use another extension that is the game logic.

But i think i'm wrong by doing this, because my last extension for the game logic is not associated to the room and is initialised at the start of the server. I do this because there will be different games to play randomly in order to clarify my code and not to put all my code in one extension for 6 games...

So i'm wondering if it's possible to instantiate new extension in my "general" extension
I've seen this post : http://www.smartfoxserver.com/forums/viewtopic.php?t=11724&highlight=add+extension+another+extension
Or is it possible to attach multiple extension to one room ? Is it a good way ?

I really appreciate if you can help me :)

Thanks
dimooze
 
Posts: 10
Joined: 17 Oct 2011, 14:42

Postby Bax » 03 Jan 2012, 10:57

I suggest using 1 Zone Extension to handle rooms creation, users connections and disconnections.
And then 1 Room Extension per room, which handles the game logic.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
 
Posts: 3797
Joined: 29 Mar 2005, 09:50
Location: Italy

Postby dimooze » 03 Jan 2012, 19:03

Thanks Bax !
I already proceed like this, but my extension for the 6 games is very very big and it's a mess to manage with it...

I've also read that it's possible to import code from another as file, in an OOP manner.

But i have to say i'm completly lost doing this in as1 is there some examples ?
dimooze
 
Posts: 10
Joined: 17 Oct 2011, 14:42

Postby Bax » 03 Jan 2012, 23:03

I don't get why you have 1 extension for 6 games. Create 6 separate Room Extensions, each one specific to one game type, and when you create the room, attach the proper Extension to it.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
 
Posts: 3797
Joined: 29 Mar 2005, 09:50
Location: Italy

Postby dimooze » 11 Jan 2012, 21:37

Hi Bax !

Thanks for you reply :)

I think i poorly explained my situation.
I create a room with one extension for 3 to 5 people. Then they play 3 minutes one game at the end of the first three minutes they play another game and so on for another one...
Then i can't move all my players to another room for each games every 3 minutes ?
dimooze
 
Posts: 10
Joined: 17 Oct 2011, 14:42

Postby Bax » 12 Jan 2012, 10:12

Well you could simply divide the logic of the various games into separate classes, which are then managed by the Room extension.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
 
Posts: 3797
Joined: 29 Mar 2005, 09:50
Location: Italy

Postby A51Integrated » 12 Jan 2012, 12:02

An easy way to do this would be to set a RoomVariable from the server side as each game starts and finishes indicating to the server which game they are playing.

Then, when an extension call is received, you can perform a switch statement on the RoomVariable and fork the handler to the correct place for that game.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Postby dimooze » 02 Feb 2012, 11:06

Thanks guys for your reply ! i was in holidays so, that's why i was not answering.

@bax : Ok so it was what i was thinking. But I don't know how to make it in as1, is there some examples ?

@A51 : I'm not sure to understand very well what you mean, i'm sorry. Do you mean that i have to move all people to a specific room with the game extension ?
dimooze
 
Posts: 10
Joined: 17 Oct 2011, 14:42

Postby A51Integrated » 02 Feb 2012, 11:55

Not necessarily a new room (you could), but a new Java handler for the logic. Create a switch (if/else-if) statement in the code and direct the logic to a class that handles the appropriate logic.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada

Postby dimooze » 02 Feb 2012, 11:57

Thanks !

Ok so it's the same way than bax no ?
I code my extension with actionscript, do you know how van i do that ?
dimooze
 
Posts: 10
Joined: 17 Oct 2011, 14:42

Postby A51Integrated » 02 Feb 2012, 12:13

Try something like this.....been a while since I wrote AS1, so I hope it works!!

Code: Select all
function init()
{
        trace("Extension init")
}

function destroy()
{
        trace("Extension destroy")
}

function handleRequest(cmd, params, user, fromRoom)
{
        var handler;
        if (cmd == "game_cmd")
        {
                switch (params.values.myGameVal)
                {
                     case 1:
                          handler = new HandlerOne(params,user,fromRoom);
                          break;
                     case 2:
                          handler = new HandlerTwo(params,user,fromRoom);
                          break;
                     //........
                }
        }
}
A51 Integrated
http://a51integrated.com / +1 416-703-2300
User avatar
A51Integrated
 
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada


Return to Server Side Extension Development

Who is online

Users browsing this forum: No registered users and 2 guests