[DGD]Re: Timeouts (ugh)

Mikael Lind z94lind at mtek.chalmers.se
Thu Jan 18 12:45:10 CET 2001


Quoting Imo Wright from 07:48, January 17, 2001:

> >Another solution, easier but less precise, is to do it
> >in the users daemon. Every couple of minutes, go through
> >the list of users and force to quit all users who are
> >idle more than X time. The problem is that you wouldn't
> >get disconnected after X time of idle, but after X plus
> >the time to the next sweep.
> 
> I thought about that, but it is imprecise.  It would be easier
> to code, though...

To get a precise timeout, you could indeed make a call-out each time
the user types something, remembering to remove the last call-out at
the same time. I'm not sure how expensive it is to add and remove
lots of call-outs. Maybe the cost is very low in comparison to the
other costs associated with each command. For most modern muds, some
kind of housekeeping and resource management is done for call-outs,
increasing the cost of adding and removing them. Anyway, an
alternative solution goes something like this:

# define IDLE_TIMEOUT  (45 * 60) /* 45 minutes. */

private int input_time;
private int timeout_handle;

static create() {
    input_time = time();
    timeout_handle = call_out("check_idle_time", IDLE_TIMEOUT);
}

static receive_message(string message) {
    input_time = time();
}

int query_idle_time() {
    return time() - input_time;
}

static check_idle_time() {
    int remaining_timeout;

    remaining_timeout = IDLE_TIMEOUT - query_idle_time();
    if (remaining_timout > 0) {
        timeout_handle = call_out("check_idle_time",
                                  remaining_timeout);
    } else {
        /* Disconnect the user. */
    }
}

The example above is stripped down for readability. You'd probably
want to replace the crude TIMEOUT #define with functionality to get
the idle timeout of this specific user, checking for some flag value
like -1 to allow some users to idle indefinitely. Also, some more
code should most likely go into create() and receive_message().

> >I think most LPMuds use method 1, since they usually
> >have heart_beat on anyway, in which case the cost of
> >doing this as well isn't high. If you plan to have a
> >permanent heart_beat also, that's what I'd recommend.
> >Otherwise I'd probably suggest method 3.
> 
> A permanent heart_beat?  Didn't think about that...

Personally, I now try to separate users from their bodies, using the
same bodies for players and NPCs. Given that, sticking connection
timeouts together with bodily functions doesn't make sense. I also
don't use heart-beats. I go for a similar system but have delays of
varying duration and only use them when the body needs to.

// Mikael / Elemel

--
Give up yourself unto the moment / The time is now / Give up yourself
unto the moment / Let's make this moment last // Moloko


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list