playMaker

Author Topic: PhotonNetworkGetNextRoomProperties - Bugged with custom properties[SOLVED]  (Read 3887 times)

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Hello,

I am with Unity 4.5.3 , Playmaker 1.7.7.2 , Photon Networking Actions 1.28.3 from: https://hutonggames.fogbugz.com/default.asp?W928

When you are inside a Room , PhotonNetworkGetRoomProperties working fine with "custom properties":



But when you are in Lobby , PhotonNetworkGetNextRoomProperties is bugged and not getting "custom properties":



This is very bad thing, because you can't show usefull information in Lobby like a Map, Game Modes...

This is the code of PhotonNetworkGetRoomProperties and working fine:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Photon")]
[Tooltip("Get the room we are currently in. If null, we aren't in any room.")]
[HelpUrl("https://hutonggames.fogbugz.com/default.asp?W910")]
public class PhotonNetworkGetRoomProperties : FsmStateAction
{

[UIHint(UIHint.Variable)]
[Tooltip("True if we are in a room.")]
public FsmBool isInRoom;


[ActionSection("room properties")]
[UIHint(UIHint.Variable)]
[Tooltip("the name of the room.")]
public FsmString RoomName;

[UIHint(UIHint.Variable)]
[Tooltip("the number of players inthe room.")]
public FsmInt playerCount;


[UIHint(UIHint.Variable)]
[Tooltip("The limit of players to this room. This property is shown in lobby, too.\n" +
"If the room is full (players count == maxplayers), joining this room will fail..")]
public FsmInt maxPlayers;

[UIHint(UIHint.Variable)]
[Tooltip("Defines if the room can be joined. If not open, the room is excluded from random matchmaking. \n" +
"This does not affect listing in a lobby but joining the room will fail if not open.")]
public FsmBool open;

[UIHint(UIHint.Variable)]
[Tooltip("Defines if the room is listed in its lobby.")]
public FsmBool visible;

[Tooltip("Custom Properties you have assigned to this room.")]
[CompoundArray("Room Custom Properties", "property", "value")]
public FsmString[] customPropertyKeys;
[UIHint(UIHint.Variable)]
public FsmVar[] customPropertiesValues;


[ActionSection("Events")]


[Tooltip("Send this event if we are in a room.")]
public FsmEvent isInRoomEvent;

[Tooltip("Send this event if we aren't in any room.")]
public FsmEvent isNotInRoomEvent;

[Tooltip("Send this event if the room properties were found.")]
public FsmEvent successEvent;

[Tooltip("Send this event if the room properties access failed, likely because we are not in a room or because a custom property was not found")]
public FsmEvent failureEvent;

public override void Reset()
{

RoomName = null;
maxPlayers = null;
open = null;
visible = null;

playerCount = 0;

isInRoom = null;
isInRoomEvent = null;
isNotInRoomEvent = null;

customPropertyKeys = new FsmString[0];
customPropertiesValues = new FsmVar[0];

successEvent = null;
failureEvent = null;

}

public override void OnEnter()
{
bool ok = getRoomProperties();


if (ok)
{
Fsm.Event(successEvent);
}else{
Fsm.Event(failureEvent);
}

Finish();
}


bool getRoomProperties()
{
Room _room = PhotonNetwork.room;
bool _isInRoom = _room!=null;

isInRoom.Value = _isInRoom;

if (_isInRoom )
{
if (isInRoomEvent!=null)
{
Fsm.Event(isInRoomEvent);
}
}else{

if (isNotInRoomEvent!=null)
{
Fsm.Event(isNotInRoomEvent);
}
return false;
}

// we get the room properties
RoomName.Value = _room.name;
maxPlayers.Value = _room.maxPlayers;
open.Value = _room.open;
visible.Value = _room.visible;
playerCount.Value = _room.playerCount;

// get the custom properties
int i = 0;
foreach(FsmString key in customPropertyKeys)
{
if (_room.customProperties.ContainsKey(key.Value))
{
PlayMakerPhotonProxy.ApplyValueToFsmVar(this.Fsm,customPropertiesValues[i],_room.customProperties[key.Value]);
}else{
return false;
}
i++;
}

return true;
}

}
}

This is the code of PhotonNetworkGetNextRoomProperties and not working:

Code: [Select]
using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Photon")]
[Tooltip("Let's you loop through the available Photon rooms. This action works only when you are in the Lobby, use PhotonNetworkGetRoomProperties when you are in a room")]
[HelpUrl("https://hutonggames.fogbugz.com/default.asp?W1115")]
public class PhotonNetworkGetNextRoomProperties : FsmStateAction
{

[ActionSection("room properties")]

[UIHint(UIHint.Variable)]
[Tooltip("the room index in the list.")]
public FsmInt roomListIndex;

[UIHint(UIHint.Variable)]
[Tooltip("the name of the room.")]
public FsmString RoomName;

[UIHint(UIHint.Variable)]
[Tooltip("the number of players in the room.")]
public FsmInt playerCount;

[UIHint(UIHint.Variable)]
[Tooltip("The limit of players to this room. This property is shown in lobby, too.\n" +
"If the room is full (players count == maxplayers), joining this room will fail..")]
public FsmInt maxPlayers;

[UIHint(UIHint.Variable)]
[Tooltip("Defines if the room can be joined. If not open, the room is excluded from random matchmaking. \n" +
"This does not affect listing in a lobby but joining the room will fail if not open.")]
public FsmBool open;

[UIHint(UIHint.Variable)]
[Tooltip("Defines if the room is listed in its lobby.")]
public FsmBool visible;

[Tooltip("Custom Properties you have assigned to this room.")]
[CompoundArray("room Custom Properties", "property", "value")]
public FsmString[] customPropertyKeys;
[UIHint(UIHint.Variable)]
[Tooltip("Values of each properties")]
public FsmVar[] customPropertiesValues;

[ActionSection("Events")]

[Tooltip("Event to send if we are not in the lobby. We can only get the list of rooms if we are in the lobby")]
public FsmEvent notInLobbyEvent;

[RequiredField]
[Tooltip("Event to send to get the next room.")]
public FsmEvent loopEvent;

[Tooltip("Event to send if there is no rooms at all")]
public FsmEvent noRoomsEvent;

[RequiredField]
[Tooltip("Event to send when there are no more rooms to loop.")]
public FsmEvent finishedEvent;

public override void Reset()
{
roomListIndex = null;
RoomName = null;
maxPlayers = null;
open = null;
visible = null;
playerCount = 0;

customPropertyKeys = new FsmString[0];
customPropertiesValues = new FsmVar[0];

notInLobbyEvent = null;
loopEvent = null;
finishedEvent = null;
noRoomsEvent = null;
}

// cache the rooms
private RoomInfo[] rooms;

// increment a room index as we loop through the hits
private int nextRoomIndex;
private RoomInfo _room;

public override void OnEnter()
{

//check if we are in a room or not
//if (PhotonNetwoek.is)
if (!PhotonNetwork.insideLobby)
{
Fsm.Event(notInLobbyEvent);
Finish();
return;
}

if (nextRoomIndex==0)
{
rooms = PhotonNetwork.GetRoomList();
}

if (rooms.Length==0)
{
nextRoomIndex = 0;
Fsm.Event(noRoomsEvent);
Fsm.Event(finishedEvent);
Finish();
return;
}

if (nextRoomIndex>=rooms.Length)
{
nextRoomIndex = 0;
Fsm.Event(finishedEvent);
Finish();
return;
}

_room = rooms[nextRoomIndex];

// we get the room properties
RoomName.Value = _room.name;
maxPlayers.Value = _room.maxPlayers;
open.Value = _room.open;
visible.Value = _room.visible;
playerCount.Value = _room.playerCount;



// get the custom properties
int i = 0;
foreach(FsmString key in customPropertyKeys)
{
if (_room.customProperties.ContainsKey(key.Value))
{
PlayMakerPhotonProxy.ApplyValueToFsmVar(this.Fsm,customPropertiesValues[i],_room.customProperties[key.Value]);
}
i++;
}


nextRoomIndex++;

Fsm.Event(loopEvent);

Finish();
}
}
}

What is wrong ?

Please, can anyone confirm this bug too ?

Thanks!
« Last Edit: February 16, 2015, 02:43:28 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PhotonNetworkGetNextRoomProperties - Bugged with custom properties
« Reply #1 on: February 14, 2015, 10:30:50 AM »
Hi,
 
Everything is fine, let me explain:

- Room properties are only accessible when they are flagged as visible in the lobby

to do so , use the advanced room creation action: PhotonNetworkCreateRoomAdvanced

and then you'll be able to see them custom properties when player is in the lobby.

 Does that make sense? study the Photon documentation ( even if there are codes, simply skip the code samples and just read the rest, it's important to understand how it all works.

I think they did this for security and performance reasons, so that someone sniffing or trying to fake a client can not get senseitive data to win a game or use it against players or publishers, and I think it's also to prevent bandwidth consuption on data that is unecessary, so in that regard, ONLY flag custom properties you really need, your game will be safer and perform better.


 Let me know how you progress on this.

 Bye,

 Jean


ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Re: PhotonNetworkGetNextRoomProperties - Bugged with custom properties
« Reply #2 on: February 14, 2015, 01:59:14 PM »
Hi jeanfabre,
I am very happy to see you :)

Yes, I was with PhotonNetworkCreateRoom.
With PhotonNetworkCreateRoomAdvanced custom properties
working fine in "Lobby".

I don't ask very often in the forum, but sometimes I really stuck in problem.

I do not claim that the code of PhotonNetworkGetNextRoomProperties is wrong,
so I just ask:

"Please, can anyone confirm this bug too ?"

I was not sure it's bug or not... for that I asked for confirmation or for advise
where is my mistake.

Anyway I will check Photon documentation for other interesting things,
but if you can answer me of few question more I will be grateful too:

1. PhotonNetworkInstantiate and PhotonNetworkInstantiateSceneObject working or not in Photon 1.50.3? Reference to this:
http://hutonggames.com/playmakerforum/index.php?topic=9377.0

2. If player disconnect from Room, after this lobby require 5-10 sec. to refresh
players count for this room? And no matter what action you will be used : PhotonNetworkLeaveRoom or PhotonNetworkDisconnect, waiting needed?

3. PhotonNetworkSetIsMessageQueueRunning - If this is OFF (runtime set in lobby or room) and I disconnect and after this connect, QueueRunning will be automatically set to ON again? And is not needed manually to set it ON?

4. If PhotonNetworkSetIsMessageQueueRunning is set to OFF these
things will not work:

- PhotonViewRpcBroadcastFsmEvent
- Game objects with "Photon View" component
- Playmaker Photon Global Events from "PlayMaker Photon Proxy" game object
like a : PHOTON / JOINED LOBBY , Left lobby / room ...

But I will have access to last set of properties (added from others Players) here:
PhotonNetworkGetNextRoomProperties, PhotonNetworkGetRoomProperties
and PhotonNetworkGetNextPlayerProperties? So, for example I can join room (in special room scene) with game that is already running (in another scene) and I will set QueueRunning to OFF , because I don't want to receive network game objects/RPCs from level running scene to my room scene. But I will know what are the last set of CustomProperties for this Room and Players inside (until Queue OFF action calling)?

Thank you so much for answers and advices!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PhotonNetworkGetNextRoomProperties - Bugged with custom properties
« Reply #3 on: February 16, 2015, 02:43:12 AM »
Hi,

You don't have to justify your post, it's perfectly valid and expected that you need validation and confirmation of features and behaviors. It's ok :)

1: thanks for pointing this thread, I replied, and there is no issues with this, I think it's just an authoring error ( I have replied to get more info)

2: Yes, there is a latency, it's expected and I think built in the Photon server backend itself.

3,4: You should double check on Photon Forum, I am not 100% sure of the behavior here, and I agree it's tricky to fully grasp. I would force the ON switch in all cases.


You can be running several games on one client, so I am not sure how you are setting this up, but for a given Player, running one instance of your game, that instance can only be one room at a time, and it can't only be either in the lobby or in the room, not both at the same time.

Bye,

 Jean