Getting room state back.
Options
How should I get room state back when I have already forwarded it to web (using playfab webhooks)?
0
Comments
-
Hi @Mahnoor47,
Thank you for choosing Photon!
Assuming you saved the room state already somewhere, first load it.
If you saved it as a stringified JSON or another format, parse it to its original format.
Return it in PathCreate webhooks in the "State" JSON property of the response:{"ReturnCode":0, "State": state}
Read more:
Photon Realtime Webhooks
PlayFab integration
Example PlayFab CloudScript for Memory Demo.1 -
@JohnTube I get you but..
I don't know how to save room state( by room state I mean room properties and all), can you help with it?
I have just done this to web forward it:Hashtable last = new Hashtable(); last["WN"] = PhotonNetwork.player.NickName; Hashtable expectedValue = new Hashtable(); PhotonNetwork.room.SetCustomProperties(last, expectedValue, true);
0 -
Hi @Mahnoor47,
In the PathClose, Type="Save": save the State somewhere in PlayFab.
I'm not sure what's the best practice nowadays, you should ask on their forum.
When I did the Memory Demo CloudScript I used SharedGroups.
So a room state would be, stripped first to not exceed PlayFab limits (or even split into two parts) then saved as stringified JSON in the one or two (or more) key/values. The keys could contain the GameId / Room name.
In PathCreate, Type="Load" retrieve that State, parse it and reconstruct it then return it to Photon.0 -
@JohnTube
I uploaded your script on cloud and it gives this error.
Operation 226 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: Failed to load state from https://67FF.playfablogic.com/webhook/1/prod/MCX9XTHYP9NAHOZZ7OEJPCH83IPFWGAUFZMXYKXRS4E47BCWMF/RoomCreated? : Newtonsoft.Json.JsonSerializationException: Error converting value -1 to type 'System.Byte'. Path 'ResultCode', line 1, position 16. ---> System.OverflowException: Value was either too large or too small for an unsigned byte.
at System.Convert.ToByte(Int64 value)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
what should I do?0 -
Hi @Mahnoor47,
Sorry about the delay!
replaceResultCode: -1
withResultCode: 255
(or any other value from 1 to 255).
I have committed the fix. Thanks for pointing this out, it used to work before as we have updated the Newtonsoft.Json library on the server and is now more strict.0 -
Operation 226 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: Failed to load state from https://67FF.playfablogic.com/webhook/1/prod/MCX9XTHYP9NAHOZZ7OEJPCH83IPFWGAUFZMXYKXRS4E47BCWMF/RoomCreated? : Error response ResultCode='255' Message='undefined: undefined'.
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1636)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
This is the error I get now?
I have used exactly your script. Is there any changes I suppose to do?0 -
Hmm weird, it could be that the error caught is a custom PlayFab error that has no 'name' and no 'message'.
Could you try replacingreturn {ResultCode: 255, Message: e.name + ': ' + e.message};
withreturn {ResultCode: 255, Message: e};
0 -
Operation 226 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: Failed to load state from https://67FF.playfablogic.com/webhook/1/prod/MCX9XTHYP9NAHOZZ7OEJPCH83IPFWGAUFZMXYKXRS4E47BCWMF/RoomCreated? : Error reading string. Unexpected token: StartObject. Path 'Message', line 1, position 29.
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1636)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)
This is the error now.
What should I do now?0 -
I see, the error object 'e' is not a typical JavaScript error object, it does not have "message" or "name" properties and can't be serialized to string.
My bet is that it's a custom PlayFab error object.
So let's try replacing:return {ResultCode: 255, Message: e};
with:return {ResultCode: 255, Message: JSON.stringify(e)};
or:return {ResultCode: 255, Message: 'error:'+e};
We are doing all this in order to find out what is the unexpected error happening in RoomCreated handler.
You could temporarily add:logException(getISOTimestamp(), e, 'RoomCreated handler error');
beforereturn {ResultCode: 255, Message:...
logException
will add the log as title data entry that you should clean up later.0