Need Real Persistent RoomVariable

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

Moderators: Lapo, Bax

User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Need Real Persistent RoomVariable

Postby mhdside » 04 May 2008, 08:10

Hello There,

I`m working on an online multiplayer cards game for my company. I`m facing a problem with smartfoxserver, Now if I set the property 'persistent = true' for a RoomVar it`ll persist till this the room owner disconnects, what I need is a permanent roomVar that doest gets removed when its owner disconnects, only removed when the room it belongs to is removed or I remove it explicitly, this missing behavior is causing me lotta effort and work arrounds to handle my situation

In case you want to know what I need this for read below:
The game is played by 4 players, players can be humans or PCs, for humans a RoomVar is set on each player connecting to the game room (as in the documentation xtres example), for PCs I set also a room var for each PC player (set by the room creator), now if the room creator left the game all the PC players will leave too which I dont want, I need the PC roomVariables to persist as long as the game room exists, is there a solution?

One other issue: I tried to clear a room variable by setting its val to null but it didnt fire onRoomVariablesUpdate event, I needed also a work arround by setting its value to "" (empty string) instead of nullifying it, and inside the onRoomVariablesUpdate I set it again to null.

I think something isnt correct with RoomVariables or maybe my falut I`m not sure. I`m using AS3 / Flash CS3

Please answer me anybody.

Thanks
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 04 May 2008, 09:11

I'm having the same problem with mhdside. It seems that it is not possible to make a real room persistent value with no users. I've been trying to work out how to do it.

I found a solution to this problem and it also took me a lot of effort. It would be great if it was simple as it is. Room values that doesn't depend on user connection/disconnect... i afraid it isn't possible at the moment, but I've added it to the wish list...

In your situation for var for each PC player.. I made an array in the extension to hold all CPU players values.. i.e. cpuArray[] and the "host" calls them to behave.

In my situation: I have:

if (_global.iAmHost) {
setInterval(moveCPU; 100)
}

function moveCPU() {
smartfox.sendXtMessage(extensionName, "moveCPU", [], str)
}

and in the server side..

gets a random CPU from the cpuArray[] , then send the new value of that CPU to all other human players.

If the host disconnect, the extension will handle this in userLeave. Get it to find a new host from all avaiable players and set it to him, and send the "you are the new host" to that player, then he will set the _global.iAmHost to true.

I hope this helps
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 04 May 2008, 10:48

thanks BigFIsh for your answer, I`m not using a server-side extension for my game but I`m working on a work arround that does something similar to your idea, but as you said it takes effor and also makes the code messy. I hope SmartFoxServer can handle this problem in a future update, it`ll make things much easier
Menser
Posts: 111
Joined: 13 Nov 2007, 18:32

Postby Menser » 04 May 2008, 16:07

Hello-

In order to get room properties to persist, you need to use server side extensions in order to make this happen.

To do so simply create a room with the owner as the server, then when you add the room properties they also belong to the server because the room they are in belongs to it, so they wont poof when people disconnect.

_-Menser-_
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 04 May 2008, 16:48

Thanks Menser for your information, they look reasonable, I`ll try them soon and I really hope this works as the other solution is very messy and hard. But even if it works I still think that roomVariables persistency should have a value to make it persist whether its creator is connected or not.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 04 May 2008, 20:29

In order to get room properties to persist, you need to use server side extensions in order to make this happen.

To do so simply create a room with the owner as the server, then when you add the room properties they also belong to the server because the room they are in belongs to it, so they wont poof when people disconnect.


Hey Menser. I tried what you told me, but it doesn't seem to work. The _server.createRoom or _server.setRoomVariables function doesn't work for me.. Maybe I'm doing something wrong. If you can provide us an example how to do it, that'll be great. I had a look at your code that you made about creating dynamic rooms.

It seems pretty big, and I want something small and simple. Or is it not possible? Like.. room creater calls the server to make room, passing on the variables i.e. name, pass, max users to the server and the server makes the room by using _server.createRoom?

_server.setRoomVariables(...) << Does such thing exist? I've been trying to play around with that code and it doesn't seem to work. Zzzz... Because if that works then that is all I need.

---EDIT----

Yay! I got it working! :D I was passing on the wrong room object... ops :oops:

If you want to know how i did it..

When a user join the room.. userJoin in handleInternalEvent is called.. then get the server to set the variables like Menser said,

Server extension code:

var thisRoom = _server.getCurrentRoom();
vars = new Array();
vars.push({name:"varone",val:12,priv:false,persistent:true});
vars.push({name:"vartwo",val:"Some string",priv:false,persistent:true});
_server.setRoomVariables(thisRoom, null, vars, false, true);

where thisRoom = room, null = user (null = server owns it), vars = variables, false = setOwnership (i think) and true is BoardcastAll (i think)
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 May 2008, 06:03

A variable can be persisted for the entire existence of a Room by simply declaring it in the config.xml
If you do it programmatically simply assign the variable to the Server (passing a null as the owner)
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

can this be done on the client side?

Postby mhdside » 05 May 2008, 06:33

thank you people for your help, I`m happy it can be done in an extension. one last question

lapo is there any mean that can be done without the use of extensions?

I`m creating the rooms dynamically using sfc.createRoom() function
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Postby marsoups » 22 May 2008, 00:02

I too am having problems with setting variables in the room.

I have found that on the occasion, I can't work out when this occasion is, that when the user enters the room not all the variables in the room are sent to that user. If, for example, one user is in another room when the room variables is set in Room A, and this user enters room A, that user will not be sent all of the variables that it should be in room A.

Also if Room A is kept open because another user (not the owner of the room) is still in this room, and the owner of this room logs out and back in, the owner of the room cannot see any of the variables that they set previously either (I realise this has been covered above, though).

There seems to be a problem though that sometimes other users are not sent all of the room variables that they should be, so I'm thinking that the normal useage of room variables is unreliable without the use of server-side extensions.
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Postby marsoups » 22 May 2008, 00:09

Okay here's how this problem can be recreated.

case 1 :
USER A create room (room A)
USER A set var in room A
USER B Enter
(correct)

case 2 :
USER A create room (room A)
USER A set var in room A
USER A join another room
USER B join room A
(incorrect - user B is not shown any room vars!)
USER A join room A
(incorrect - user A is shown all the room vars!)

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 107 guests