About Java API to simulate Openspace npc problem.

Post here all your questions related with SmartFoxServer Java API

Moderators: Lapo, Bax

bpresnell
Posts: 3
Joined: 22 Feb 2010, 06:13

Just to make sure I understand this.

Postby bpresnell » 22 Feb 2010, 06:29

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?
User avatar
Lapo
Site Admin
Posts: 20437
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 22 Feb 2010, 08:23

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.
Lapo
--
gotoAndPlay()
...addicted to flash games
bpresnell
Posts: 3
Joined: 22 Feb 2010, 06:13

Further Clarifying

Postby bpresnell » 23 Feb 2010, 19:56

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.
User avatar
Lapo
Site Admin
Posts: 20437
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 24 Feb 2010, 13:45

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.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Java2SE / Android Client API”

Who is online

Users browsing this forum: No registered users and 1 guest