Is there a QuickJoinGameRequest in SFS1 ?

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

Moderators: Lapo, Bax

Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Is there a QuickJoinGameRequest in SFS1 ?

Postby Rashomon » 29 Aug 2011, 13:39

I see there's a QuickJoinGameRequest in SFS2X. What about in SFS1?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 13:47

Hi. No there isn't a QuickJoinGameRequest in SFS1x, you need to code your own :-)
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Aug 2011, 15:19

That's what I figured.

Can you give me a hand with getting the roomList?

I've searched the docs, and I can only find roomList used with the onRoomListUpdate event. How can I get the roomList on demand (through my own function)?

I'm currently using SmartFoxBits. I can't get the roomList from the RoomList component, either either. The roomList.rowCount shows the number of possible rooms that I can show in my list, NOT the number of rooms that are actually created.

I would prefer to work directly with SFS at this point. If you know how to get Bits to work, that will be a bonus. :)
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 15:24

Hi. You can use the roomList property of the SmartFoxClient class

When you receive the onRoomListUpdate event, the client automatically stores the roomList in that property.
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Aug 2011, 15:49

Thanks. That's just what I was looking for.

The links you gave me were to AS2 code, and I'm using AS3. Once I knew what I was looking for, though, I was able to find the AS3 equivalent (smartFox.getAllRooms());

Here's a link to the AS3 API for others.

And here's my final code that works:

Code: Select all

showRooms_btn.addEventListener (MouseEvent.CLICK, onShowRooms);
function onShowRooms( evt:MouseEvent ):void
{
   var rooms:Array = smartFox.getAllRooms()
   for (var r:String in rooms)
   {
      var room:Room = rooms[r]
      trace("Room: " + room.getName())
   }
}   


Thanks a ton, rjgtav!!!! :)
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 16:04

You Welcome :-) Oh, on future posts, please specify which scripting language are you using, that makes things easy :-)
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Aug 2011, 16:49

Will do.

One more thing. I'm trying to set a roomVariable when the game has started. I plan to cycle through the rooms in the roomList and check the isStarted roomVar to determine whether or not someone can join the game.

I'm setting the roomVar like so:

Code: Select all

var rVarsStart:Array = new Array();
rVarsStart.push({name:"isStarted", val:"true", persistent:true})
smartFox.setRoomVariables(rVarsStart);


I then check the roomVars from another client/user, like so:

Code: Select all

showRooms_btn.addEventListener (MouseEvent.CLICK, onShowRooms);
function onShowRooms( evt:MouseEvent ):void
{
   var rooms:Array = smartFox.getAllRooms()
   for (var r:String in rooms)
   {
      var room:Room = rooms[r]
      trace("Room: " + room.getName())

      trace("isStarted = " + room.getVariable("isStarted") as String);
      
      var roomVars:Array = room.getVariables()
      for (var v:String in roomVars)
         trace("Name:" + v + " | Value:" + roomVars[v])         
   }
}


Unfortunately, I cannot seem to access the room variables. Here's my output:

Code: Select all

Room: game1
isStarted = undefined
Room: Lobby
isStarted = undefined


If, however, I enter the room and then leave it, then I'm able to access the isStarted roomVar. What's going on? How can I access the roomVars in my roomList without actually entering the rooms?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 17:04

Hi. You need to set the roomListVars property of the zone to true.
More information here
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Aug 2011, 17:40

Sorry... It's me again. :)

I read the link you provided, and I found some examples where others set this tag, like here. However, I'm still getting "undefined" values.

Here's my zone config:

Code: Select all

<Zone name="myZone" roomListVars="true">
   <Rooms>
      <Room name="Lobby" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true"/>
   </Rooms>
   <Extensions>
      <extension name="myExtension"  className="myExtension.as" type="script" />
   </Extensions>         
   <DatabaseManager active="true">
   ... (a bunch of stuff deleted)
   </DatabaseManager>
</Zone>


What am I missing, here?

Could the problem be with the way I'm creating my game rooms?

Code: Select all

function createRoom( name:String, pwd:String, spec:Number ):void
{
   hideWindow( "newGameWindow" )
   var gameRoom:Object = new Object()
   gameRoom.name = name
   gameRoom.password = pwd
   gameRoom.maxUsers = 3
   gameRoom.maxSpectators = spec
   gameRoom.isGame = true
   gameRoom.isTemp = true
   var xt:Object = {}
   xt.name = "myGame"
   xt.script = "myExtension.as"
   gameRoom.extension = xt
   smartFox.createRoom( gameRoom )
}


While we're at it, is this a good approach? Is it also possible to just completely remove the room from the roomList? If so, would that cause problems later on, by not being able to find the room?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 17:52

Hum... do the variables appear on the adminTool (when in the client it shows undefined?

Also, do you test this with 2 clients (one sets the variable and the other tries to get)?

Finally, the persistent=true just lets the variable there until the user that created it disconnects from the server, so to make a variable to stay until the room gets deleted, you have to create it on the server side, set persistent to true and set its owner to null.

More info here.
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Aug 2011, 19:40

I'm making progress. It works... sort of. :)

The variable was (and still is) appearing in the adminTool.

I am testing with 4 clients. Three to create a full game, and one to check the room vars from the lobby.

Following your link, I removed my client-side code where I was setting my isStarted roomVar.

I added code to my server-side extension to create the isStarted roomVar. I'm using priv:false, persistent:true, and passing null as the owner, like so:

Code: Select all

function startGame()
{
   gameStarted = true
   
   var room = _server.getCurrentRoom()
   trace("Extension is running in room: " + room.getName())
   trace("Users in this room: " + room.getUserCount())
   
   var rVars = []
   rVars.push( {name:"isStarted", val:"true", priv:false, persistent:true} )
   _server.setRoomVariables(room, null, rVars)
   
   var res = {}
   res._cmd = "start"
   
   res.p1 = {id:p1id, name:users[p1id].getName()}
   res.p2 = {id:p2id, name:users[p2id].getName()}
   res.p3 = {id:p3id, name:users[p3id].getName()}
   
   _server.sendResponse(res, currentRoomId, null, users)
}


I say this "sort of works", because my "lobby" client can correctly read the room variables if the game has started before it enters the zone. If, however, the client is already in the lobby, and THEN a game starts, the lobby client does not get the room vars. I tried calling smartFox.getRoomList() before trying to pull the roomVars, but no luck.

Do you have any idea what's going on with the lobby/game order?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 29 Aug 2011, 21:25

Hi. Yes when a variable updates on another room you don't receive the update. And I think the roomList method only works at the login time.

Usually, is advisable for you to create your own startGame method, so when a game starts, you send an extension response to the players in the lobby saying that that game has started, so they can remove it from the room list.

I think there's no other way to achieve this, can't remember now.
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.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 27 Sep 2011, 13:57

you send an extension response to the players in the lobby saying that that game has started, so they can remove it from the room list.


How do you remove a room from the roomList? I can only find getRoomList and onRoomListUpdate.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 27 Sep 2011, 16:39

Hi. I was referring to removing the room from the list where you show the rooms available to join, not from the SmartFoxClient's roomList, as you can't do that.
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 “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 14 guests