Can't create a room in JS Server API

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

trueicecold
Posts: 84
Joined: 11 Oct 2009, 11:46
Contact:

Can't create a room in JS Server API

Postby trueicecold » 30 Nov 2017, 09:50

Hey there,

I'm trying to do something very simple: open a room in the zone extension:

Server code:

Code: Select all

function init() {
   addRequestHandler("FindRoom", onFindRoom);
}

function onFindRoom(event, sender) {
   var cfg = new CreateRoomSettings();
 
   cfg.setName("232323s");
   cfg.setGame(true);
   cfg.setMaxUsers(10);
   cfg.setMaxSpectators(5);
   cfg.setDynamic(true);
   
   var myNewRoom = getApi().createRoom(getParentZone(), cfg, null);
}


Client code:

Code: Select all

//Server.connection is the SmartFox instance
Server.connection.send(new SFS2X.ExtensionRequest("FindRoom", null));


I get an exception:

Code: Select all

java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: Cannot cast jdk.nashorn.internal.runtime.Undefined to com.smartfoxserver.v2.entities.Room
Description: Java Error invoking Javascript function: $$handleClientRequest


I thought this was pretty straight-forward, am I missing something?

Thanks!
User avatar
Lapo
Site Admin
Posts: 19741
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can't create a room in JS Server API

Postby Lapo » 01 Dec 2017, 08:28

Hi,
I was able to reproduce the issue. It seems that one of the missing optional parameters is causing the exception, even though the Room is actually created. I don't know if you've noticed that.

In any case if you call createRoom(...) with the complete list of parameters it will go away.
For example:

Code: Select all

var room = getApi().createRoom(getParentZone(), cfg, null, false, null, true, false);

This should fix the problem you've encountered.
The parameters (in order) are:
zone -> the zone where to create the Room
cfg -> the room config
owner -> the creator of the Room (null == server)
autoJoin -> auto-join the owner upon creation
roomToLeave -> if auto-join is true you can pass another Room that the owner will leave upon auto-joining the new one
fireClientEvent-> notify the clients about the new Room
fireServerEvent-> notify other Extensions about the new Room

For more, check the documentation here:
http://docs2x.smartfoxserver.com/api-do ... FSApi.html

We'll investigate this further and release a patch as soon as possible.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 15 guests