Unity WebSockets MMORoom creation troubles

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

Moderators: Lapo, Bax

User avatar
Chadrien
Posts: 5
Joined: 30 Sep 2016, 11:40
Location: Paris

Unity WebSockets MMORoom creation troubles

Postby Chadrien » 30 Sep 2016, 12:01

Hi,

I have some problems when i send a room creation request to the server.
With TCP protocol all work fine but when i switch to WS protocol i have the following exception on server.

13:39:54,192 WARN [SFSWorker:Sys:2] v290.SystemReqController - java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
com.smartfoxserver.v2.entities.data.SFSArray.getInt(SFSArray.java:281)
com.smartfoxserver.v2.entities.data.SFSObjectLite.getIntArray(SFSObjectLite.java:103)
com.smartfoxserver.v2.controllers.system.CreateRoom.preProcess(CreateRoom.java:220)
com.smartfoxserver.v2.controllers.system.CreateRoom.execute(CreateRoom.java:264)
com.smartfoxserver.v2.controllers.v290.SystemReqController.processRequest(SystemReqController.java:157)
com.smartfoxserver.v2.controllers.v290.SystemReqController.enqueueRequest(SystemReqController.java:114)
com.smartfoxserver.bitswarm.io.protocols.AbstractProtocolCodec.dispatchRequestToController(AbstractProtocolCodec.java:39)
com.smartfoxserver.bitswarm.websocket.WebSocketProtocolCodec.dispatchRequest(WebSocketProtocolCodec.java:139)
com.smartfoxserver.bitswarm.websocket.WebSocketProtocolCodec.onPacketRead(WebSocketProtocolCodec.java:65)
com.smartfoxserver.bitswarm.websocket.netty.WebSocketServerHandler$WSIOExecutor.run(WebSocketServerHandler.java:105)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)

I have found the reason of the exception, the server wait for an integer DefaultAoi when i use WebSockets.
I tried to send integer values for the MMORoomSetting.DefaultAoI but when i call the MMOAPi.SetUserPosition on server, i have troubles too:

com.smartfoxserver.v2.exceptions.SFSRuntimeException: Provided position doesn't match coordinate type used in [ MMORoom: District_01, Id: 1, Group: default, AOI: ( 10, 10, 0) ]. Expected: Int, Found: Float

So i tried to set user position for the MMO Api with integer value (it work but it is not really good :/).
Now my room be correctly created and i can use the AoI but when i receive users positions in the OnUserVariablesUpdate, i have client-side exception due to invalid cast when i use SFSUserVariable.GetDouble() to get position of a remote user.

All work fine when i use TCP protocol but i have real difficulties to make my game work with WebSockets.
The code i use is the same as the MMORoomDemo.

Thanks for your help.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebSockets MMORoom creation troubles

Postby Lapo » 30 Sep 2016, 14:37

Hi,
yes it's a known issue in the websocket protocol. Will be fixed in the coming 2.12 release.

For the time being I suggest to create the MMORoom from server side to bypass the problem.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Chadrien
Posts: 5
Joined: 30 Sep 2016, 11:40
Location: Paris

Re: Unity WebSockets MMORoom creation troubles

Postby Chadrien » 01 Oct 2016, 13:21

Hi Lapo,

Thanks for your answer.
What about concerning the invalid cast exception thrown on client side when we use User.GetVariable(string key).GetDouble() with WebSockets protocol.
I tried again you MMORoomDemo project an i get the same error.

Regards.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebSockets MMORoom creation troubles

Postby Lapo » 01 Oct 2016, 14:29

First I recommend fixing the creation problem so that you can use floating points for the AOI etc... then if the problem with the client persists, can you please show me the relevant code and the stack trace with the error?

Also it wouldn't hurt to know which SFS2X you're using, which SFS API version, and Unity version.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Chadrien
Posts: 5
Joined: 30 Sep 2016, 11:40
Location: Paris

Re: Unity WebSockets MMORoom creation troubles

Postby Chadrien » 03 Oct 2016, 08:24

Hi,

I have understood about the room creation server-side, it's ok.
The other trouble is about the the users variables receive on client using Websockets.
I use the latest version of SFS2X and the Unity C# client, when i launch your MMORoomDemo project (with room already created from other client using TCP), i have the following error in unity when i receive values from remote users:

InvalidCastException: Cannot cast from source type to destination type.
Sfs2X.Entities.Variables.SFSUserVariable.GetDoubleValue ()
GameManager.OnProximityListUpdate (Sfs2X.Core.BaseEvent evt) (at Assets/Scripts/GameManager.cs:101)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt)
Rethrow as Exception: Error dispatching event proximityListUpdate: Cannot cast from source type to destination type. at Sfs2X.Entities.Variables.SFSUserVariable.GetDoubleValue ()
GameManager.OnProximityListUpdate (Sfs2X.Core.BaseEvent evt) (at Assets/Scripts/GameManager.cs:101)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt)
Sfs2X.Core.EventDispatcher.DispatchEvent (Sfs2X.Core.BaseEvent evt)
Sfs2X.SmartFox.ProcessEvents ()
GameManager.FixedUpdate () (at Assets/Scripts/GameManager.cs:62)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebSockets MMORoom creation troubles

Postby Lapo » 03 Oct 2016, 08:58

Can you show me the code used for creating the Room by the other client?
Also, are you testing with the standard MMORoomDemo found in our package or is it modified? If so what changes have been done?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Chadrien
Posts: 5
Joined: 30 Sep 2016, 11:40
Location: Paris

Re: Unity WebSockets MMORoom creation troubles

Postby Chadrien » 05 Oct 2016, 07:59

I tested the MMORoomDemo without making any changes in code.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Unity WebSockets MMORoom creation troubles

Postby Lapo » 05 Oct 2016, 08:13

Thanks, we are going to try and reproduce it.
Stay tuned.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unity WebSockets MMORoom creation troubles

Postby Bax » 05 Oct 2016, 11:10

I just retested using the latest version of the MMORoomDemo example, but I can't reproduce the issue. Maybe we are not doing the same test.
I'm using SFS2X v2.11 and the latest C# API. These are the steps I followed:

1) export the example as standalone application (so using standard socket connection) and run it: the MMORoom is created successfully and the avatar appears on screen; also che NPCs start moving around;
2) in the Unity Editor, switch to WebGL (so using a web socket connection) and run the example: the previous MMORoom is joined and the avatar created; both clients now see each other's avatar;
3) on both clients move the avatar around with the expected result and no errors;
4) stop the Unity Editor and export the WebGL build; open it in FireFox: again everything is ok and avatars can see each other move around.

Can you follow the same steps and confirm it works? Or show what you are doing different in your test.
Thanks.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 27 guests