Page 2 of 2

Just to make sure I understand this.

Posted: 22 Feb 2010, 06:29
by bpresnell
If I want an NPC that isn't regularly logged out, I need to create a server extension that uses createNPC to create a user object. Then to keep the NPC from being logged out for being idle, I must have an instance of a smart fox server client that sends requests to the server on behalf of the NPC? If so does this client have to run as a separate process?

Posted: 22 Feb 2010, 08:23
by Lapo
No, you can simply use a Scheduler Task which is very light and doesn't require to run a dedicated thread for each NPC.
If you take a look at our NPC example (found under the Examples/ folder in your sfs installation directory) you can see how we use the Scheduler to run timed tasks.

Further Clarifying

Posted: 23 Feb 2010, 19:56
by bpresnell
So in my extension I do the follow:

User u = extensionHelper.createNPC() to create a user
have u join a room.
Set up a task that gets called every 30 seconds(Assuming the idle timeout > 30).
In this task I send a public message from u.

Should npc u get logged out for being idle?
Or do I need to create a smartFoxClient for u, and have the task do:
client.sendXtRequest("npcManager","ping");

Currently I have it sending a public message every 30 seconds. But the NPC gets logged out for being idle. And I'm not sure if I'm not doing what I need to do to cause the idle timer to reset, or if I have done something else wrong.

Posted: 24 Feb 2010, 13:45
by Lapo
Set up a task that gets called every 30 seconds(Assuming the idle timeout > 30).
In this task I send a public message from u.
Just wanted to point out that the keep-alive task could also do nothing besides calling npcUser.updateMessageTime(), which updates the idle timer and avoids disconnection.

If your maxIdleTime is 30 seconds your taks should be running a little faster than that, like 20 seconds.