How add a Spectator to Game Room

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

Moderators: Lapo, Bax

Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

How add a Spectator to Game Room

Postby Ardito » 29 Jan 2020, 14:24

Hi,
I want to add in a room a spectator, but when I do joinRoom server side () I get this error:

Code: Select all

com.smartfoxserver.v2.exceptions.SFSJoinRoomException: Join Error - Room is full: 2-3, Zone: { Zone: Login } - Can't add User: ( User Name: 7, Id: 7, Priv: 0, Sess: 79.13.165.136:53024 )
        at com.smartfoxserver.v2.api.SFSApi.joinRoom(SFSApi.java:1008)
        at loginserver.MainMenuHandler.handleClientRequest(MainMenuHandler.java:905)
        at com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:208)
        at com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:174)
        at com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


I want it to run the whole server, how do I set the user type to the server-side spectator?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How add a Spectator to Game Room

Postby Lapo » 29 Jan 2020, 14:37

Hi,
it looks like the Room is already full.
I would double check a couple of things:
1) only game Rooms support spectators, double check you're joining the User in a game Room
2) check the limits you have set for players and spectators (maxUsers, maxSpectators)

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: How add a Spectator to Game Room

Postby Ardito » 29 Jan 2020, 14:51

This is my code for creating a game room:

Code: Select all

RoomExtensionSettings res = new RoomExtensionSettings("Server", "gamedata.MatchExtension");
      CreateRoomSettings crs = new CreateRoomSettings(); 
    
      crs.setName(user0_id + "-" + user1_id);
      crs.setMaxVariablesAllowed(6);
      crs.setMaxUsers(2);
      crs.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
      crs.setDynamic(false);   
      crs.setGame(true);
      crs.setExtension(res);
      crs.setGroupId("game");
      crs.setMaxSpectators(99999);


I used this line of code, but I think it's the wrong way to insert a viewer into a Room

Code: Select all

getApi().joinRoom(user, roomGame, "", false, roomGame, true, true);


Now I'm trying this, but what are the two Boolean values?

Code: Select all

getApi().playerToSpectator(user, roomGame, arg2, arg3);
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: How add a Spectator to Game Room

Postby Ardito » 29 Jan 2020, 14:57

I tried to put TRUE in the two Boolean values, I got an error:

Code: Select all

15:56:59,120 ERROR [SFSWorker:Ext:2] v290.ExtensionReqController     - java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error while handling client request in extension: { Ext: Server, Type: JAVA, Lev: ZONE, { Zone: Login }, {} }
Extension Cmd: mainmenu
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.api.response.SFSResponseApi.notifyRequestError(SFSResponseApi.java:950)
com.smartfoxserver.v2.api.response.SFSResponseApi.notifyRequestError(SFSResponseApi.java:932)
com.smartfoxserver.v2.api.SFSApi.playerToSpectator(SFSApi.java:2246)
loginserver.MainMenuHandler.handleClientRequest(MainMenuHandler.java:906)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:208)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:174)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How add a Spectator to Game Room

Postby Lapo » 29 Jan 2020, 15:26

The join code you are using is adding the User as player, not as spectators:
getApi().joinRoom(user, roomGame, "", false, roomGame, true, true);


Change the 4ht parameter (asSpectator) to true, to add the user as spectators instead.
Lapo

--

gotoAndPlay()

...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: How add a Spectator to Game Room

Postby Ardito » 29 Jan 2020, 15:30

Yessss!!! Work it!! Thank's!!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 100 guests