Unity WebGL Smartfox Login Exception

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

ersindemir
Posts: 30
Joined: 30 Apr 2016, 07:23
Location: Turkey

Unity WebGL Smartfox Login Exception

Postby ersindemir » 04 Feb 2017, 06:24

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)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebGL Smartfox Login Exception

Postby Lapo » 04 Feb 2017, 12:10

Hi,
are you sending custom object/data with the login response? If so can you show us the relative code?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
ersindemir
Posts: 30
Joined: 30 Apr 2016, 07:23
Location: Turkey

Re: Unity WebGL Smartfox Login Exception

Postby ersindemir » 04 Feb 2017, 18:45

Yes, smartfox backend throw exception when client want to login , but smartfox client not parse correctly.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unity WebGL Smartfox Login Exception

Postby Bax » 06 Feb 2017, 08:26

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?
Paolo Bax
The SmartFoxServer Team
ersindemir
Posts: 30
Joined: 30 Apr 2016, 07:23
Location: Turkey

Re: Unity WebGL Smartfox Login Exception

Postby ersindemir » 06 Feb 2017, 08:55

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 )
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unity WebGL Smartfox Login Exception

Postby Bax » 06 Feb 2017, 10:08

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
Paolo Bax
The SmartFoxServer Team
ersindemir
Posts: 30
Joined: 30 Apr 2016, 07:23
Location: Turkey

Re: Unity WebGL Smartfox Login Exception

Postby ersindemir » 06 Feb 2017, 11:02

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.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unity WebGL Smartfox Login Exception

Postby Bax » 06 Feb 2017, 11:26

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.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 24 guests