Page 1 of 1

Unity WebGL Smartfox Login Exception

Posted: 04 Feb 2017, 06:24
by ersindemir
I can not login to game.
Smartfox client can connect , but can not login to zone ,This exception is handled on client side.

InvalidCastException: Unable to cast object of type 'SFSObjectLite' to type 'String'.
at Sfs2X.Entities.Data.SFSArray.GetValue[Object] (Int32 index) [0x00000] in <filename unknown>:0
at Sfs2X.Entities.Data.SFSArray.GetUtfString (Int32 index) [0x00000] in <filename unknown>:0
at Sfs2X.Entities.Data.SFSObjectLite.GetUtfStringArray (System.String key) [0x00000] in <filename unknown>:0
at Sfs2X.Controllers.SystemController.FnLogin (IMessage msg) [0x00000] in <filename unknown>:0
at Sfs2X.Controllers.RequestDelegate.Invoke (IMessage msg) [0x00000] in <filename unknown>:0
at Sfs2X.Controllers.SystemController.HandleMessage (IMessage message) [0x00000] in <filename unknown>:0
at Sfs2X.Core.WSProtocolCodec.DispatchRequest (ISFSObject requestObject) [0x00000] in <filename unknown>:0
at Sfs2X.Core.WSProtocolCodec.OnPacketRead (ISFSObject packet) [0x00000] in <filename unknown>:0
at Sfs2X.Core.WSIOHandler.OnDataRead (System.String jsonData) [0x00000] in <filename unknown>:0
at Sfs2X.Bitswarm.WebSocketClient.OnSocketData (System.String data) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.OnStringDataDelegate.Invoke (System.String msg) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.WebSocketLayer.CallOnData (System.String data) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.WebSocketLayer.ProcessState () [0x00000] in <filename unknown>:0
at Sfs2X.SmartFox.ProcessEvents () [0x00000] in <filename unknown>:0


Unity Version : 5.5.1
Platform : WebGL ( No exception occur on Android , IOS , Windows)
Smartfox Backend : 2.12.0 (Java)
Client smartfox version : 1.6.6 (same problem 1.7.2 version)

Re: Unity WebGL Smartfox Login Exception

Posted: 04 Feb 2017, 12:10
by Lapo
Hi,
are you sending custom object/data with the login response? If so can you show us the relative code?

Thanks

Re: Unity WebGL Smartfox Login Exception

Posted: 04 Feb 2017, 18:45
by ersindemir
Yes, smartfox backend throw exception when client want to login , but smartfox client not parse correctly.

Re: Unity WebGL Smartfox Login Exception

Posted: 06 Feb 2017, 08:26
by Bax
ersindemir wrote:Yes, smartfox backend throw exception when client want to login, but smartfox client not parse correctly.

Can you please post an excerpt of your server side Extension, showing the login response?

Re: Unity WebGL Smartfox Login Exception

Posted: 06 Feb 2017, 08:55
by ersindemir
Ps: we use custom SFSLoginException

SFSErrorData sfsErrorData = new SFSErrorData(SFSErrorCode.GENERIC_ERROR);
sfsErrorData.addParameter("{ \"ErrorCode\" :-1, \"error_message\" :\"Unkown\" }");
throw new SFSLoginException("Error Message",sfsErrorData);

I can see this exception on backend side console, but Client can not parse correctly on WebGL platform. ( No problem Android,ios )

Re: Unity WebGL Smartfox Login Exception

Posted: 06 Feb 2017, 10:08
by Bax
You can't send that error message as a JSON string. Instead of a generic error, send a specific error (for example SFSErrorCode.LOGIN_BAD_USERNAME) passing the expected parameters (in the example, the wrong name).
On the client side you will get a composed error message based on the parameters you sent and the error type.
See this link for the server side example: http://docs2x.smartfoxserver.com/Gettin ... wtos#item3
and this link for the client side error message customization: http://docs2x.smartfoxserver.com/Advanc ... r-messages

Re: Unity WebGL Smartfox Login Exception

Posted: 06 Feb 2017, 11:02
by ersindemir
If I can not use sfsErrorData.addParameter function with JSON data . How can I send GENERIC_ERROR with additional SFSObject data ? Because I need to send addictional data with login error.

Re: Unity WebGL Smartfox Login Exception

Posted: 06 Feb 2017, 11:26
by Bax
You may "url encode" data. For example:

Code: Select all

"{'some':'object', 'list':[1,2,3,4]}"

becomes

Code: Select all

'%7B%27some%27%3A%27object%27%2C+%27list%27%3A%5B1%2C2%2C3%2C4%5D%7D’

You can then decode the string on the client side and convert it back to an object.