/*
* interactive.c
*
* Is the object interactive? i.e a user with a link.
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
/* pointer to user object */
private static object __user;
/* set/get user object (if any) */
nomask int __set_user(object ob) {
if (DRIVER_PRIV())
/* we got permission */
__user = ob;
else
illegal();
}
nomask object __query_user() {
return __user;
}
/* return array of all interactive objects */
static object *users() {
return GLOBAL->users();
}
/* check if object is connected to an USER object */
static int userp(object ob) {
return GLOBAL->userp(ob);
}
/* find player by living_name and optionally index */
#ifdef MUDOS_LIVING
# ifdef MUDOS_USER_LIVING_NAME
static varargs object find_player(string name, int i) {
return GLOBAL->find_player(name, i);
}
# endif
#endif
/* user is interactive? */
static varargs int interactive(object ob) {
if (!ob) return __user != 0;
return ob->__query_user() != 0;
}
/* idletime of user */
static int query_idle(object ob) {
object usr;
if ((ob && (usr = ob->__query_user())))
return usr->query_idle();
}
/* ip-number */
static varargs string query_ip_number(object ob) {
object usr;
if (!ob) usr = __user;
else usr = ob->__query_user();
return ::query_ip_number(usr);
}
/* ip-name (not finished) */
static varargs string query_ip_name(object ob) {
return query_ip_number(ob);
}
/* user in input_to? */
static int in_input(object ob) {
object usr;
if (!ob) usr = __user;
else usr = ob->__query_user();
return usr->query_input_to();
}
/* user in edit? */
static int in_edit(object ob) {
object usr;
if (!ob) usr = __user;
else usr = ob->__query_user();
return usr->query_editing();
}
/* transfer user in <from> to <to> */
static int exec(object to, object from) {
object usr;
if (!from || !(usr=from->__query_user()))
return 0;
if (to && to->__query_user()) /* <to> may be 0 which makes user lose link */
return 0;
/* check master if it is legal */
if (!call_other(master(), __VALID_EXEC_FUNC, to, from, this_object())) {
illegal();
return 0;
}
if (to) {
/* do the interactive switch from <from> to <to> */
usr->set_player(to);
return 1;
}
/* force a close of connection */
usr->force_close();
return 1;
}
/* start ed in this_object(), optionally with command cmd */
static varargs int ed(string cmd) {
if (__user) {
return __user->do_editor(cmd);
}
}
/* make next user input call a local function with our args */
static varargs int input_to(string fun, int flag, mixed args...) {
if (__user) {
__user->set_input_to(this_object(), fun, flag, args...);
return 1;
}
return 0;
}
/* set screen term for an interactive user */
static int set_screen_term(string t) {
if (__user) {
__user->set_screen_term(t);
return 1;
}
return 0;
}
/* set screen width of an interactive user */
static int set_screen_width(int i) {
if (__user) {
__user->set_screen_width(i);
return 1;
}
return 0;
}
/* set screen height of an interactive user */
static int set_screen_height(int i) {
if (__user) {
__user->set_screen_height(i);
return 1;
}
return 0;
}