Show Rooms only for certain users

AndreWeAndreWe
edited July 17 in Photon Server
Hi,

We want to create rooms, which can be listed/e.g. seen only by certain users (player-a/b/c).

Creating the Room:
RoomOptions roomOptions = new RoomOptions();
            roomOptions.MaxPlayers = 8;
            roomOptions.PublishUserId = true;
            roomOptions.IsVisible = false; //not everybody should see this room
            roomOptions.IsOpen = true;
            roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0" };
            roomOptions.CustomRoomProperties = new Hashtable() { { "C0", "' player-a player-b player-c '" } }
            
            TypedLobby typedLobby = new TypedLobby();
            typedLobby.Name = GetTypedLobbyName();
            typedLobby.Type = LobbyType.SqlLobby;
            
            b = PhotonNetwork.CreateRoom(roomName,
                roomOptions,
                typedLobby);

Filtering the Room:
TypedLobby sqlLobby = new TypedLobby(GetTypedLobbyName(), 
                LobbyType.SqlLobby);
            string sqlLobbyFilter = "C0 LIKE ('% " + "player-a" + " %')";
            PhotonNetwork.GetCustomRoomList(sqlLobby, sqlLobbyFilter);


This should show in "OnReceivedRoomListUpdate" some results, but the method is not called.

It gets called when "roomOptions.IsVisible" is set to "true", but in this case, the "sqlLobbyFilter" and "PhotonNetwork.GetCustomRoomList" does not make much sense, because everybody can see the room (without setting the filter, or calling GetCustomRoomList).

Have you an Idea?

The only solution we came up with:
Store room names somewhere else (web/api) and retrieve the names from there and call "JoinRoom" explicitly with the names from the "web/api"?

Thank you very much

Comments

  • JohnTubeJohnTube mod
    edited July 17
    Hi @AndreWe,

    Thank you for choosing Photon!

    It gets called when "roomOptions.IsVisible" is set to "true", but in this case, the "sqlLobbyFilter" and "PhotonNetwork.GetCustomRoomList" does not make much sense, because everybody can see the room (without setting the filter, or calling GetCustomRoomList).
    Why do you need to join lobbies at all? If clients don't join the lobby then they can't see the rooms.

    Another option would be to "private" lobbies used only by certain users. e.g. name it "' player-a player-b player-c '".

    I'm curious to know the use case. Why is this lobby special and restricted?
  • Thank you very much for the feedback.
    The use case is the following:

    * The host will create a session, and can invite users on the fly during a session
    * The other clientes are in a browsing area and will receive a "user a has invited you, do you like to join?" message. They can accept or decline. This would be triggered if a new RoomInfo was found.

    That is the basic idea behind this.

    If we do not handle this by a filter, every user in the lobby will receive this info, or can see what kind of rooms are existing. This is something we do not want.

    Do you have any advice for this?

    Thank you.
  • So you're trying to come up with a workaround to exchange invitations in the lobby.
    I wouldn't go that way and instead use another third party service to do that like Photon Chat, Steam or Facebook or whatever your game and target platform(s) can support.
    Or the WebAPI you mentioned above. You could use a special WebRPC to get custom game lists and even more stuff as WebRPCs work both on Master (not joined to a room) and Game (joined to a room) servers

    But if you think you can do it, you can try.
    I still do not see how I can send an invitation and how I can receive one.
    I think you're constantly polling using GetGameList and some filter.
    Why not use FindFriends?
    I see "host" and "session"...how such things are shared or known by others? do they join a "session"? is the "host" a friend? maybe use "SessionId" and maybe "HostId" as SQL filters?

    If we do not handle this by a filter, every user in the lobby will receive this info, or can see what kind of rooms are existing. This is something we do not want.

    Did you read my suggestions above? About not joining lobbies or using special lobbies? What do you think?
  • Thank you for your detailed feedback!


    Facebook, Steam etc.:

    Our target group will not use a facebook account or the like.
    Just emails registered to our system.

    Invitation:
    Invitation can be send to an email address or to a certain user-id (friends). An email address can have multiple user-ids.
    So when sending it to an email address, all user-id's will get an invite.

    WebRPC:
    Good point, we will check this.

    Photon Chat:
    Photon Chat sounds interesting; maybe we give this a try as well.

    Lobby:
    The idea for using a lobby was, to not use the frequent "calling"/"polling" on a web service.
    This will always take some seconds after we receive an update.
    When using photon lobby, the new rooms etc. are received "instantly" which feels much better.

    Friends:
    We can also call frequent updates for FindFriends and see where they are (in which room etc.).
    But at this point we do not know if the friend has invited us, or not.

    Host and Session:
    The host (a user) will create a session (e.g. room).
    Then clicks on "invite" and can invite user's he already know (friend/user-id we get from our webApi) or type in an email address.

    If the email address exists in our webApi, all users belonging to this address will be informed/invited.

    If an invited user is in the app, he will receive an message, that a certain user has invited them for a session and he can accept/decline that.

    When the host closes a session (e.g. leaves the room) the invitation for all users is deleted.

    We want to use your lobby system to get an overview for each user of there currently "invitations".
    This is because all filtered rooms ("GetCustomRoomList") for this user contain his user-id and/or email-address in the CustomPropertirs.

    Summary:
    * We want to use the lobby to get invited rooms/sessions for a user.
    * It would be nice to not use frequent calls/polling to get a list of rooms/sessions

    * Currently we think of not using a lobby at all, use a webApi/webRPC to get a list of invites etc. and handle these for create/join a room/session.

    What is your Opinion?


  • JohnTubeJohnTube mod
    edited July 18
    OK.

    The 'host' creates 'sessions' which are special rooms with an SQL property set to the expected/invited users' IDs.
    A user can get the list of 'sessions' where he is invited using GetCustomRoomList and a special SQL filter.
    Rooms should be created visible but not all users should be aware of their existence.

    Simply do not join any lobby at all.
    This way no one will see any room list.
    GetCustomRoomList works even outside of lobbies.

    Since my first post here I have been suggesting this and you did not answer it:
    Do you need to join lobbies?
    Did you try this?

    If an invited user is in the app, he will receive a message, that a certain user has invited them for a session and he can accept/decline that.
    I'm assuming you are sending the room name (GameId) somehow using an external service right?

    In the snippet of the first post, I see that MaxPlayers is 8 and there are only "player a", "b" and "c".
    How are you planning to add the 5 other players?
    If all invited users are known since creation, maybe make use of the Expected Users (Slot Reservation) feature to make sure not invited users can't join because the room is full.
  • Thank you.

    We do not need a lobby, so we will try GetCustomRoomList without logging in into a lobby. We will set the IsVisible = true so the filtering works.

    The lobby name will be hardCoded currently and later be received by an apiCall, because otherwise some people can list all rooms by just joining the lobby (with a own script/app). Is this correct?

    I'm assuming you are sending the room name (GameId) somehow using an external service right?

    Currently not, but this is planed.

    In the snippet of the first post, I see that MaxPlayers is 8 and there are only "player a", "b" and "c".
    How are you planning to add the 5 other players?

    This is done on the fly. So if the host decieds during a session to invite a new user, this will be extended. The maximum possibles invites for a host depends on the hosts-selected plan (free, premium etc.)

    If all invited users are known since creation, maybe make use of the Expected Users (Slot Reservation) feature to make sure not invited users can't join because the room is full.
    • Can expectedUsers be set during a running session?
    • Can only expetedUsers join this session, or is it just a "reservation" and any other user can join as well? Because this would be the feature we need: only reserverd users are allowed to join a session.
  • Is this correct?
    Correct but if you're planning on making an app that has plans you need to secure it and make sure it's genuine and users are authentic. You could make use of "Custom Authentication" for that. You could also make use of AuthCookie if you ever use WebRPCs/WebHooks...

    Can expectedUsers be set during a running session?
    Yes Expected Users is an array, it is a well-known (native/predefined) room property. It can be changed post room creation. Same as MaxPlayers.

    Can only expetedUsers join this session, or is it just a "reservation" and any other user can join as well? Because this would be the feature we need: only reserverd users are allowed to join a session.
    If MaxPlayers is equal to Expected Users length then only reserved users are allowed otherwise a room can have mixed users.
  • Very nice! The reserverd user stuff is exactly what we are looking for :smiley:
    We will try this.
  • But can MaxPlayers be changed during a running session?
  • Yes that's what I have hinted to in my previous message.
  • Creating a Room for just one user works as follows:
    
    roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = 1; //Just one slot for parking
    roomOptions.PublishUserId = true;
    roomOptions.IsVisible = true;
    roomOptions.IsOpen = true;
    
    //..
    
    b = PhotonNetwork.CreateRoom(roomName,
    	roomOptions,
    	null,
    	null,
    	null);            
    
    If we want to create a room for two players, and reserver one or more slots we get the following error message:
    Operation failed: OperationResponse 227: ReturnCode: -2 (Reserved slots count is bigger then max player value). Parameters: {} Server: GameServer
    
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = 2; //me and someone else
    roomOptions.PublishUserId = true;
    roomOptions.IsVisible = true;
    roomOptions.IsOpen = true;
    
    //..
    
    b = PhotonNetwork.CreateRoom(roomName,
    	roomOptions,
    	null,
    	null,
    	new string[] { "user-2" }); //or array with 2 ids like: myId (the user who calls CreateRoom) and the invited user           
    
    When setting the values after CreateRoom we get the following error:
    Operation failed: OperationResponse 252: ReturnCode: -2 (Not enough places to reserve all requested slots). Parameters: {} Server: GameServer
    
    string[] expectedUsers = new string[] { "user-1", "user-2" };
    
    PhotonNetwork.room.MaxPlayers = ClampValueToMaxPlayers(expectedUsers) + 1; //does not work
    PhotonNetwork.room.MaxPlayers = ClampValueToMaxPlayers(expectedUsers); //does not work
    PhotonNetwork.room.SetExpectedUsers(expectedUsers);   
    
    Maybe we have overseen something, but it looks like that setting maxPlayers to the length of expected uers does not work (there must be at least one slot open?)?
    Does the expected user array also include the user who calls CreateRoom?
    Have you any idea what we are doing wrong?
  • Short info: ClampValueToMaxPlayers will just return the length of the string array
  • Thank you very much. We will check this :smiley:
  • Thank you very much for the Feedback!
    We have now implemented everything without a friends list, but without a lobby and with using a SQL filter.

    Everything works just fine :smiley:
Sign In or Register to comment.