editor.c

MudOSa4DGD/mudlib/dgd/lib/std/editor.c · 1.7 KB

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * editor.c
 *
 * An editor to be abused by users
 *
 * (C) Frank Schmidt, Jesus@NorseMUD
 *
 */

#define __EDITOR
#include <driver.h>


/* user for this editor */
private static object user;


/* responsible user */
object query_user() {
  if (!DRIVER_PRIV()) {
    illegal();
    return 0;
  }
  return user;
}


/* handle an editor command */
varargs void edit(string cmd) {
  if (!DRIVER_PRIV()) {
    illegal();
    return;
  }

  if (previous_object() == user)
    cmd = editor(cmd);
  else if (!user && previous_object() == this_user()) {
    user = this_user();
    cmd = editor(cmd);
  }
  if (cmd) {
    user->send_message(cmd);
  }

  /* clean up? */
  if (!query_editor(this_object()) || !user)
    __DESTROY_DEF();
}


/* attempt to rescue the currently edited file */
static void rescue_file() {
  string file, *path;

  if (user) {
    if (query_editor(this_object()) == "input")
      editor(".");

    if (sscanf(editor("f"), "\"%s\" [Modified] %*s", file) == 2) {
      path = explode(file, "/");
      RLIMITS_ON();
      catch(editor("w! " + call_other(master(), __GET_RESCUE_FILE_FUNC,
				      path[a_sizeof(path)-1], user->query_player())));
      RLIMITS_OFF();
    }
  }
}


static void __CREATE_DEF() {
  if (!IS_DRIVER_SOURCE(object_name(previous_object()))) {
    /* can only be cloned by driver objects */
    illegal();
    __DESTROY_DEF();
    return;
  }
  ::__CREATE_DEF();
#ifdef MUDOS_USER_ID
  seteuid(getuid());
#endif
}


/* unmovable */
varargs int __MOVE_DEF(object dest) {
  illegal();
}


/* we're going down! Ieeaarrrrghh.. */
void __DESTROY_DEF() {
  if (!DRIVER_PRIV()) {
    illegal();
    return;
  }
  rescue_file();
  ::__DESTROY_DEF();
}

Site Stats

Snippets: 1791
Codebases: 571