Room creation issue

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

Moderators: Lapo, Bax

zerokuhhl
Posts: 7
Joined: 05 Aug 2010, 20:03

Room creation issue

Postby zerokuhhl » 19 Feb 2011, 04:21

Hi SFS guys,

I have an issue I can't solve.

We have created a function so a user can create a regular room on the fly.
However, whenever new room is created, all existing users become auto joined to that newly created room automatically.
All the users get ported to that created room and duplicates of the users stay in the rooms they were in.


What are we doing wrong?

This is the code that is placed client side in the interface.



Code: Select all

public function createRoom(roomName:String, auto_join:Boolean):Void {
 
 
  this._targetRoomName = roomName;
  trace("function createRoom called");

 
  var gameRoom:Object  = new Object()
  gameRoom.name    = roomName
  gameRoom.password   = ''
  gameRoom.maxUsers   = 12
  gameRoom.maxSpectators  = 0;
  gameRoom.isGame   = false
  gameRoom.isTemp   = false
  gameRoom.isDynamic  = true
 
 

 
  var MapPath = _root.selectedroompath_raw+""+_root.selectedindex;
  trace("create room function trigered "+roomName+" and mappath = "+MapPath);
  var vars:Array = new Array()
  vars.push( {name:"MapPath", val:MapPath} )
  gameRoom.vars = vars;
  this.onUserCountChange();
 

  this._fox.onRoomAdded = onRoomAddedHandler

  var found = false;
  var result:Array = new Array();
 
  for(var i in this._fox.roomList){
   var r:TheoRoomData = new TheoRoomData();
   r.name = Room(this._fox.roomList[i]).getName();
   
   if(roomName == Room(this._fox.roomList[i]).getName())
   {
    found = true;
    //getURL("javascript:alert('room exists = "+Room(this._fox.roomList[i]).getName()+"');");
   }

  }
 
  if(found)
  {
          this.joinRoom(roomName,"");
  }else
  {
   var roomcreating_result = this._fox.createRoom(gameRoom,null)
   
  }
 

   
  function onRoomAddedHandler(room:Room):Void
      {
       trace("Room " + room.getName() + " was created")
     this._fox.setRoomVariables(room.getVariables())
     this.joinRoom(room.getName(),"");
       //getURL("javascript:alert(' created room = "+room.getName()+"');");
       // TODO: update available rooms list in the application interface
     }
   
 
 }
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 19 Feb 2011, 12:40

hi. Currently your code seems to be ok. How are you checking if the users stay in the previous room? Via adminTool? If not, pls check with it
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.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 19 Feb 2011, 18:36

However, whenever new room is created, all existing users become auto joined to that newly created room automatically.
All the users get ported to that created room and duplicates of the users stay in the rooms they were in.


I assume that the part where the user didn't leave the previous room is the only problem? All existing users joining the newly created room is an expected behavior?

Who's not leaving the previous room? Everyone, including the creator? How was this found out? Did you receive a room list in the first place, and joined to an existing room before this code was carried out?

By the way, your solution of creating the room and checking whether it exists on client side isn't ideal. What if two separate clients created a room simultaneously and both rooms has the same name? It would be far better if all this was done on server side. The pixel game example (http://www.smartfoxserver.com/docs/docPages/tutorials_pro/10_pixelGame/index.htm) shows how it's done.
Smartfox's forum is my daily newspaper.
zerokuhhl
Posts: 7
Joined: 05 Aug 2010, 20:03

Postby zerokuhhl » 19 Feb 2011, 20:06

Hi gang,

Here's the background.

1) All users have one or more rooms.
2) Each space/room has a unique name that user gives and the name is stored in MySQL. It's like "their room".
3) We fetch the names of their places from php/MySQL and display the names with an icon in the interface.
4) When the owner(user) clicks their button, it creates the room on the fly and the owner/user joins the room.
5) While in their room, they either transport ALL other users online to their place or they get joined to another dynamic room. I haven't been able to figure out why.
6) Users remain in the room they joined, stay in the Lobby while in another room and there are multiple instances of the avatars - they lose their clothes etc.

Please see the screenshot attached.



It doesn't make sense.


Image

I'm really stuck...

~Zero
[/list]
Vishwas
Posts: 81
Joined: 25 Dec 2008, 22:06

Re: Room creation issue

Postby Vishwas » 21 Feb 2011, 14:15

Hi!
My doubt is , what you are calling as duplicates, are actually occupying both the rooms. This is
I think you must use leaveRoom function to force the users to leave the room before joining another one.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 82 guests