Page 1 of 1

Room creation issue

Posted: 19 Feb 2011, 04:21
by zerokuhhl
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
     }
   
  
 }

Posted: 19 Feb 2011, 12:40
by rjgtav
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

Posted: 19 Feb 2011, 18:36
by BigFIsh
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/docP ... /index.htm) shows how it's done.

Posted: 19 Feb 2011, 20:06
by zerokuhhl
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]

Re: Room creation issue

Posted: 21 Feb 2011, 14:15
by Vishwas
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.