Room Creation Question

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

Moderators: Lapo, Bax

wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Room Creation Question

Postby wallis2xk » 04 Sep 2006, 12:46

Hi,

Sorry if this has been covered before, but I've been looking through your tutorials and docs and am considering using SmartFox for a multiuser game solution and have a question:

If I have a game which has several lobbies(rooms) of 50 users, and in each lobby there is the ability for users to create a game room, the server functionality seems to be that whenever a game room is created the notification of this is sent to the entire zone, i.e. the whole game, every lobby. This seems potentially a large waste of bandwidth, am I missing something here?

Thanks

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

Postby Lapo » 04 Sep 2006, 15:39

Actually I don't see this potential waste, but I am not sure about what you exactly have in mind.

Basically the Zone represents the root-container of all (game and non game) rooms. By default, each time a new room is created, each user in that Zone is notified.

You can however override the default behavior by implementing your own application logic using server side extensions, and avoid sending those notifications, if it's needed.

The server is highly flexible and allows all sorts of simple or advanced behaviors.

:)
Lapo
--
gotoAndPlay()
...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 04 Sep 2006, 15:52

Hi Lapo, thanks for the reply.

I was just looking at the logic in one of your examples (tic tac toe one) and tested out adding another room and found that game room creation notifications were sent to both rooms. And if you had 1000 users in a zone, spread over 20 rooms then in an ideal world you don't want to send a game room update to up to 950 users who don't need to see that update.

SmartFox does look a great solution and look forward to building some apps once I get my head round the architecture I need :)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 04 Sep 2006, 16:01

I was just looking at the logic in one of your examples (tic tac toe one) and tested out adding another room and found that game room creation notifications were sent to both rooms.


If they are "normal" room then they will receive that notification. If they are game room they won't.

This is because each chat room presents a real-time update of all available rooms. That's how we inteded those samples.

And if you had 1000 users in a zone, spread over 20 rooms then in an ideal world you don't want to send a game room update to up to 950 users who don't need to see that update.

Yeah! Of course you can do that if you wish :)

SmartFox does look a great solution and look forward to building some apps once I get my head round the architecture I need


cool :)
Lapo

--

gotoAndPlay()

...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 04 Sep 2006, 17:30

Ok, thanks.

One more question if I may - Our system is intended to have several games using the server, in their own zone and we're implementing a global chat feature, which is kept separate from the games, but so that anyone playing any game can chat with anyone else.

On other servers this would require two servers. But having seen your multiroom feature, I thought it might be possible to do it all on the same connection and simply create a global chat zone and room which everyone can connect to. But then I saw the zone is defined in the login. Is it possible to join more than one zone at a time? Or is there another way we could do this?

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

Postby Lapo » 05 Sep 2006, 08:43

Premise:
what do you mean exactly by global chat? A place where any client can talk to someone else? Seeing all the available clients connected?
IMHO this would quickly become a mess... you know even with "only" 300 clients trying to talk to each other the chat would become unusable.

Moreover a single global chat room would create a huge traffic, because each single message should be broadcasted to all clients (imagine what happens when you have 2000 clients or more)

I'd suggest to split the global chat into a set of chat rooms with a limit of 30 to 50 max users.

Using the multi-room feature you can keep the user logged in two or more rooms simultaneously (i.e. game room and chat room)

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 05 Sep 2006, 09:12

I guess I wasn't particularly clear, there would be no global chat room as such, just the ability to have a one-to-one conversation with anyone connected to the server. So there would be no more than a packet being sent from one person to another. The traffic with this would be minimal.

In my mind this would be relatively straightforward if I was able to assign one zone and one room to this system, have everyone join it as soon as they connect, and disable all the custom events on the zone, so there is no traffic except users sending chat to each other.

This way the player is then able to go around from game to game (zone to zone) and is still able to talk to anyone else on the server as everyone is still in the global room/zone.

Workable without creating 2 connections? :)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 Sep 2006, 09:45

I guess I wasn't particularly clear, there would be no global chat room as such, just the ability to have a one-to-one conversation with anyone connected to the server. So there would be no more than a packet being sent from one person to another. The traffic with this would be minimal.


Ok, great. This is much clearer :)
You just need one Zone, as it represent your application.
A user can chat with any other user in a one on one fashion by just knowing its id. We recently added a simple IM like example that show how implement this, using also a buddy list for keeping your contacts.

Also that example can be expanded using a database and more sophisticated server side code to create a pretty advanced instant messenger.

You find the source code of the example in the Examples/MX2004/ folder of SmartFoxServer 1.4.0

hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 05 Sep 2006, 09:53

Right, that's great, that would be what I need, but I was also hoping to allow users to be in this chat system and to be playing a game (in a different zone) at the same time. So anyone playing any game can chat with anyone else playing any other game. For example

Dave is playing in Chess (Chess <zone>)

Lapo is playing in Checkers (Checkers <zone>)

now if they were also both in a zone called chat they would be able to communicate?

It looks to me to come down to allowing users to be in two zones at the same time? If this is not possible, will I have to create 2 connections per user, one for the games and one for the chat?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 Sep 2006, 10:37

Right, that's great, that would be what I need, but I was also hoping to allow users to be in this chat system and to be playing a game (in a different zone) at the same time. So anyone playing any game can chat with anyone else playing any other game.


The idea here is that you can achieve this using a single Zone. Many games can live within the same Zone and this way users are all in the same place. If you use more Zones things start to get very complicated and we usually don't reccomend to take that route.

A couple of tips for the architecture of the game.

Scenario 1:
- Single Zone
- Main extension at Zone Level, if needed, controls the main features of the application
- One Room level Extensions for each game available: each time you create a game room, you dynamically attach the its game extension, that controls the game logic

Scenario 2:
- Single Zone
- Main extension at Zone Level that controls the main features of the application and all the games, without using Room Level estensions. (better for very high traffic)

To do this you will have to carefully design your extension so that you can recognize messages of game from the messages of another one.
You can adopt a very simple convention, like a prefix in front of each request that identifies the game.

Example:
poker_getScore
chess_sendMove
etc...

the first 5 chars plus the "_" will identify a class inside your extension that handles the game logic.
The you will build a class for each game so that you keep your code clean and extendable (when you add a new game, you just create a new class for it etc...)

Hope it helps :)
Lapo

--

gotoAndPlay()

...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 05 Sep 2006, 10:48

Ah, ok, I now see what you're saying. Where you mention using a class inside the extension, I assume this only apply to Java extensions currently?
Last edited by wallis2xk on 05 Sep 2006, 10:54, edited 2 times in total.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 Sep 2006, 10:54

Nay. You can create classes in Actionscript 1 too.

Example:

Code: Select all

MyClass = function(x, y, name)
{
   this.x = x
   this.y = y
   this.name = name
}

MyClass.prototype.getX = function()
{
   return this.x
}

MyClass.prototype.getY = function()
{
   return this.y
}

MyClass.prototype.getName = function()
{
   return this.name
}


then you create the object:

Code: Select all

myObj = new MyClass(10, 20, "test")
Lapo

--

gotoAndPlay()

...addicted to flash games
wallis2xk
Posts: 43
Joined: 01 Sep 2006, 10:00
Location: United Kingdom

Postby wallis2xk » 05 Sep 2006, 11:05

Of course, thanks for all your help.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 42 guests