MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

[APROG] re: overflow output buffer



This is code I use with 1.7.9, it allow to have two different buffers (one
for general purpose notify and one for communication between the MOO and
the client (out-of-band communications ?)) It should avoid losing any line
of text and avoid mixing the text for the client and the text for the
player.
(Note: to work you need to change $player:notify to pass() rather than notify())

@prop #1.notify_task 0 ""
@prop #1.notify_buffer {} ""
@prop #1.client_notify_buffer {} ""

@verb $root_class:"notify*_lines client_notify*_lines" tnt rxd
@program $root_class:notify
if (is_player(this) && this in connected_players())
  if (!$perm_utils:controls(caller_perms(), this))
    return E_PERM;
  endif
  if (index(verb, "client"))
    buffer = "client_notify_buffer";
    other_buffer = "notify_buffer";
    notify = "notify_lines";
  else
    buffer = "notify_buffer";
    other_buffer = "client_notify_buffer";
    notify = "client_notify_lines";
  endif
  if (typeof(lines = args[1]) != LIST)
    lines = {args[1]};
  endif
  if (typeof(this.(buffer)) == LIST)
    this.(buffer) = {@this.(buffer), @lines};
  else
    "the buffer is corrupted.";
    this.(buffer) = lines;
  endif
  if ($code_utils:task_valid(this.notify_task))
    "There is already a notify task in charge of emptying the notify
buffers -- Janus";
  else
    this.notify_task = task_id();
    while (this.(buffer))
      if (ticks_left() < 300 || seconds_left() <= 1)
        suspend(0);
        this.notify_task = task_id();
      endif
      line = this.(buffer)[1];
      this.(buffer) = listdelete(this.(buffer), 1);
      while (notify(this, line, 1) == 0)
        "Network buffer full... wait and see... -- Janus";
        suspend(0);
        this.notify_task = task_id();
      endwhile
    endwhile
    this.notify_task = 0;
    if (this.(other_buffer))
      this:(notify)({});
    endif
  endif
endif
.

---
"640K ought to be enough for anybody."
    -- Bill Gates, 1981





Home | Subject Index | Thread Index