Setup:
Code: Select all
smartFox.AddLogListener(LogLevel.INFO, onInfoMessage);
smartFox.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, onUserVariableUpdate);
private void onInfoMessage(Sfs2X.Core.BaseEvent evt)
{
string message = (string)evt.Params["message"];
UnityEngine.Debug.LogFormat("[SFS INFO] {0}", message);
}
private void onUserVariableUpdate(Sfs2X.Core.BaseEvent evt)
{
User user = (User)evt.Params[ "user"];
ArrayList changedVars = (ArrayList)evt.Params["changedVars"];
foreach(string var in changedVars)
{
UnityEngine.Debug.Log("Changed " + var + " to " + user.GetVariable(var));
}
}
Working example log from setting a user variable:
Code: Select all
[SFS INFO] Message: SetUserVariables { Message id: 12 }
{ Dump: }
(int) u: 9
(sfs_array) vl:
(sfs_array)
(utf_string) con_prop
(byte) 4
(utf_string)
"actionCount":1
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onInfoMessage(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:1328)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Changed con_prop to [UVar: con_prop, type: STRING, value: {"actionCount":1}]
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onUserVariableUpdate(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:279)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Now the log from the race condition situation:
Code: Select all
[SFS INFO] Message: SetUserVariables { Message id: 12 }
{ Dump: }
(int) u: 9
(sfs_array) vl:
(sfs_array)
(utf_string) con_prop
(byte) 4
(utf_string)
"actionCount":0
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onInfoMessage(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:1328)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Changed con_prop to
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onUserVariableUpdate(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:279)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
[SFS INFO] Message: SetUserVariables { Message id: 12 }
{ Dump: }
(int) u: 9
(sfs_array) vl:
(sfs_array)
(utf_string) con
(byte) 0
(null) NULL
(sfs_array)
(utf_string) con_prop
(byte) 0
(null) NULL
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onInfoMessage(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:1328)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Changed con to
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onUserVariableUpdate(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:279)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Changed con_prop to
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
SmartFoxGameServerClient:onUserVariableUpdate(BaseEvent) (at Assets\SmartFoxGameServerClient.cs:279)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
What's going on here is on the server I'm setting the user variable to a value and then immediately afterwards removing it. The network messages are as I'd expect (variable with a value, followed by variable set to null). And 2 events are dispatched to the USER_VARIABLES_UPDATE listener as expected. However when the first of the 2 events is dispatched the User object variables are already set as I'm expecting them to be during second dispatch.
I'm at a bit of a loss in finding a way around this behaviour, I could delay the user variable clearing on the server side, but presumably this client behaviour would still occur under certain network conditions.