Other cant acces to Room Variables if other allready connected

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

mers
Posts: 16
Joined: 20 Dec 2017, 16:17

Other cant acces to Room Variables if other allready connected

Postby mers » 04 Apr 2018, 05:51

Hello,
I have a litle problem with acces room vars

[PROBLEM]
1) 2 Players, p1 and p2 are connected.
2) p1 create room > server create room var...
3) p2 refresh list room
4) p2 client side cant find RoomVariable

[WORK FINE]
1) 2 Players, p1 is connected, P2 Not Connected
2) p1 create room > server create room var..
3) p2 connect to smartfox...
4) p2 refresh list room
5) p2 client side get variables without problem and display all room

Any idea ?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Other cant acces to Room Variables if other allready connected

Postby Lapo » 04 Apr 2018, 08:00

Hi,
it could depend on many things.
For starters are we talking about global Room Variables?
Since you never mention any user joining a Room I suppose they must be.

The "refresh room list" part is not clear to me. There is no "refresh", once you login you receive the list of Rooms for the default Room Groups configured in your Zone.
After that the server will keep updating the client about any new Room created or removed, provided your client is listening to SFSEvent.ROOM_ADD and SFSEvent.ROOM_REMOVE:

When you receive an event about a new Room added you will also get all it's global RoomVariables. What you will not be able to see are the non-global variables as those are visibile only to users who join the Room.

Makes sense?
Lapo
--
gotoAndPlay()
...addicted to flash games
mers
Posts: 16
Joined: 20 Dec 2017, 16:17

Re: Other cant acces to Room Variables if other allready connected

Postby mers » 04 Apr 2018, 11:44

Yes we talking about global Room Variables

My refresh system is just a Client side code who GetAllRooms and AllRoomVariable attached for create my UIRoom List (custom var > Room Vars GameMod et..).

All user allready connected to sfs (not join room) cant get room variable global, User who connected to sfs ( not join room ) after room are created he can get room variable global without problem.

I need refresh system from AddRoom Event ?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Other cant acces to Room Variables if other allready connected

Postby Lapo » 05 Apr 2018, 07:03

I am not sure what you're doing, but as I explained you don't need to get the list of Rooms manually.
It is already sent to you in the login response from the server. From there you just receive updates via those two events I mentioned.

I would highly recommend that you take a look at our simple examples we provide here:
http://smartfoxserver.com/download#p=examples

They come with source code and tutorials for every platform:
http://docs2x.smartfoxserver.com/

Try to follow those and you'll have no problems.
If something is not clear let us know.
Lapo

--

gotoAndPlay()

...addicted to flash games
mers
Posts: 16
Joined: 20 Dec 2017, 16:17

Re: Other cant acces to Room Variables if other allready connected

Postby mers » 05 Apr 2018, 09:09

Yes i did the same, but I still have the same problem

SFS C# Script

Code: Select all

   public void OnAddRoom(BaseEvent evt)
    {
        Debug.Log("Room Add");

        SM.MM.RefreshListRoom(sfs.RoomList);
    }


Code: Select all

 private void OnLogin(BaseEvent evt)
    {
        User user = (User)evt.Params["user"];

        List<UserVariable> userVars = new List<UserVariable>();
        userVars.Add(new SFSUserVariable("steamId", SM.PP.mySteamId));

        sfs.Send(new SetUserVariablesRequest(userVars));

        SM.MM.RefreshListRoom(sfs.RoomList);
    }


MainMenu c#Script

Code: Select all

    public void RefreshListRoom(List<Room> _rooms)
    {
        foreach (GameObject _goUIRoom in curUIRoom)
        {
            Destroy(_goUIRoom);
        }
        foreach (Room _room in _rooms)
        {
            SM.MM.AddUIRoom(_room);
        }
        //SM.SF.GetAllRoom();

    }


Code: Select all

 public void AddUIRoom(Room _room)
    {
        GameObject _goRoom = Instantiate(prefabUIRoom, menuMultiUIRoom.transform);
        UIRoom _uiRoom = _goRoom.GetComponent<UIRoom>();

        curUIRoom.Add(_goRoom);


        _uiRoom.roomId = _room.Id;

        _uiRoom.roomName.text = _room.Name;

        RoomVariable _rv = _room.GetVariable("mise"); //<< ERROR Line
        _uiRoom.mise.text = "€" + _rv.GetIntValue().ToString();


        _rv = _room.GetVariable("mod");

        int _modID = _rv.GetIntValue();
        FigthMod _fm = (FigthMod)_modID;
        _uiRoom.mod.text = prefixeFigthMod[_fm];
    }




SERVER SIDE

Code: Select all

public class CreateRoom extends BaseClientRequestHandler
{
   @Override
    public void handleClientRequest(User user, ISFSObject params)
    {
        CreateRoomSettings rs = new CreateRoomSettings();

        rs.setGame(true);
         rs.setDynamic(true);
        
         rs.setName(params.getUtfString("name"));
         rs.setMaxUsers(params.getInt("cntPlayer"));
         rs.setMaxVariablesAllowed(12);
        
        
     try
     {
        Room _room = getApi().createRoom(getParentExtension().getParentZone(), rs, user);
       
         // OWNER
          RoomVariable gm = new SFSRoomVariable("owner", user.getId());
          gm.setPrivate(false);
          gm.setGlobal(true);
          gm.setPersistent(false);
          gm.setOwner(user);
          try
          {
            _room.setVariable(gm);
          }
          catch (SFSVariableException e)
          {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
       
       
          // MOD
          gm = new SFSRoomVariable("mod", params.getInt("mod"));
          gm.setPrivate(false);
          gm.setGlobal(true);
          gm.setPersistent(false);
         // gm.setOwner(user);
          try
          {
            _room.setVariable(gm);
          }
          catch (SFSVariableException e)
          {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        //
          // MISE
          gm = new SFSRoomVariable("mise", params.getInt("mise"));
          gm.setPrivate(false);
          gm.setGlobal(true);
          gm.setPersistent(false);
          gm.setOwner(user);
         
          try
          {
            _room.setVariable(gm);
          }
          catch (SFSVariableException e)
          {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
       
   
       ISFSObject objOut = new SFSObject();     
         objOut.putInt("hostId", _room.getOwner().getId());
         objOut.putInt("roomId", _room.getId());
       send("RoomCreated", objOut, user);
      
     }
     catch (SFSCreateRoomException e)
     {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
    }
}
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Other cant acces to Room Variables if other allready connected

Postby Lapo » 05 Apr 2018, 14:50

You're creating the Room in the wrong way on the server side.
The variables you want to create can be specified directly in the CreateRoomSettings object that you use to create the Room.

Even if you want to create the variables in a second step, after having created the Room, the problem with your code is this:

_room.setVariable(gm);

If you call setVariable() you're creating the variables on the server side but no update is ever sent to clients.

Instead you must call getApi.setRoomVariables()
Make sure to read the documentation here:
http://docs2x.smartfoxserver.com/Extens ... ension-api

Also you don't need to send a custom notification to the client because variables created on the server side will be updated on the client side via the SFSEvent.ROOM_VARIABLE_UPDATE event.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
mers
Posts: 16
Joined: 20 Dec 2017, 16:17

Re: Other cant acces to Room Variables if other allready connected

Postby mers » 05 Apr 2018, 15:31

effectively.. I'm not paying enough attention excuse me for the inconvenience, now it works very well and I thank you

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Bing [Bot], Seo-Ul-Kex and 41 guests