Multiple Extension

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

Moderators: Lapo, Bax

Post Reply
dimooze
Posts: 10
Joined: 17 Oct 2011, 14:42

Multiple Extension

Post by dimooze »

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://forums.smartfoxserver.com/viewto ... +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
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

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
dimooze
Posts: 10
Joined: 17 Oct 2011, 14:42

Post by dimooze »

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 ?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

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
dimooze
Posts: 10
Joined: 17 Oct 2011, 14:42

Post by dimooze »

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 ?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

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
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Post by A51Integrated »

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
dimooze
Posts: 10
Joined: 17 Oct 2011, 14:42

Post by dimooze »

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 ?
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Post by A51Integrated »

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
dimooze
Posts: 10
Joined: 17 Oct 2011, 14:42

Post by dimooze »

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 ?
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Post by A51Integrated »

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
Post Reply