Room Extension can't be invoked?

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

Moderators: Lapo, Bax

UlterR
Posts: 20
Joined: 15 Jan 2017, 18:05

Room Extension can't be invoked?

Postby UlterR » 21 Feb 2017, 08:45

I tried to make an extension and attached it to a room
After that I added a request handler, but when i try to use the extension i got this error

Image

What went wrong? :(

Thanks in advance
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension can't be invoked?

Postby Lapo » 21 Feb 2017, 11:26

Can you show me the client code used to call the Extension?
Lapo
--
gotoAndPlay()
...addicted to flash games
UlterR
Posts: 20
Joined: 15 Jan 2017, 18:05

Re: Room Extension can't be invoked?

Postby UlterR » 21 Feb 2017, 12:03

Code: Select all

ISFSObject ObjOut = new SFSObject ();
      ObjOut.PutUtfString ("User", "black");
      ObjOut.PutInt ("count", 30);
      ObjOut.PutUtfString ("Room", "room1");
      //current room is room object
      sfs.Send (new ExtensionRequest ("starttimer",ObjOut,currentroom));


this one for the server side

Code: Select all

public class RoomExtension extends SFSExtension{
@Override
  public void init()
  {   
addRequestHandler("starttimer", TimerHandler.class);
}
}


timerhandler class

Code: Select all

public class TimerHandler extends BaseClientRequestHandler{
public void handleClientRequest(User user, ISFSObject ObjIn){
       
        String kuser = ObjIn.getUtfString("User");
        count = ObjIn.getInt("count");
        String kroom = ObjIn.getUtfString("Room");
        room = getParentExtension().getParentZone().getRoomByName(kroom);
        user = getParentExtension().getParentZone().getRoomByName(kroom).getUserByName(kuser);
        getApi().sendPublicMessage(room, user, "success", null);
       }
}
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension can't be invoked?

Postby Lapo » 21 Feb 2017, 14:11

Thanks.
The client code looks code.

I would recommend to double check that the Extension was launched correctly when the Room is created. You can add a trace command in your init() method to make sure everything is okay:

Code: Select all

public void init()
{
   trace("Extension started OK");
   ...
}


Also check the logs for errors at the time of the creation of the Room.

Other than that it all looks good.
Lapo

--

gotoAndPlay()

...addicted to flash games
UlterR
Posts: 20
Joined: 15 Jan 2017, 18:05

Re: Room Extension can't be invoked?

Postby UlterR » 22 Feb 2017, 14:43

It seems the problem is on the timer code that I try to inject :(

Can you help me what's wrong with my timer code
this one is a simple code trying send a public message each second

Code: Select all

room = getParentZone().getRoomByName("time");
      task = new TimerTask()
              {
                  public void run(){
                    getApi().sendPublicMessage(room, null, "t" , null);

                  }
              };
     
       timer.scheduleAtFixedRate(task, null, 1000);


The location is currently in main extension of a zone extension
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Extension can't be invoked?

Postby Lapo » 22 Feb 2017, 15:34

Is there a specific error? If so post the stack trace.

Also make sure to review how to create tasks to be submitted to the Scheduler, your code is not handling exceptions as we recommend.
http://docs2x.smartfoxserver.com/Gettin ... wtos#item7

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
UlterR
Posts: 20
Joined: 15 Jan 2017, 18:05

Re: Room Extension can't be invoked?

Postby UlterR » 22 Feb 2017, 15:49

I tried the scheduler and it works like charm
So finally I noticed that the problem is not only timer but also the sending a message from the server side and after changing to admin message, even room extension now works

Thanks for the help :)

Now i just need to find the way to attach room extension on the client's script when they make a room

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 89 guests