tmi2_fluffos_v2/
tmi2_fluffos_v2/bin/
tmi2_fluffos_v2/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/ChangeLog.old/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/Win32/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/simuls/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/clone/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/command/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/data/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/master/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/log/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/compiler/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/efuns/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/operators/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/u/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/tmp/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/windows/
tmi2_fluffos_v2/lib/
tmi2_fluffos_v2/lib/adm/
tmi2_fluffos_v2/lib/adm/daemons/languages/
tmi2_fluffos_v2/lib/adm/daemons/network/I3/
tmi2_fluffos_v2/lib/adm/daemons/virtual/
tmi2_fluffos_v2/lib/adm/daemons/virtual/template/
tmi2_fluffos_v2/lib/adm/news/
tmi2_fluffos_v2/lib/adm/obj/
tmi2_fluffos_v2/lib/adm/obj/master/
tmi2_fluffos_v2/lib/adm/priv/
tmi2_fluffos_v2/lib/adm/shell/
tmi2_fluffos_v2/lib/adm/tmp/
tmi2_fluffos_v2/lib/cmds/
tmi2_fluffos_v2/lib/d/
tmi2_fluffos_v2/lib/d/Conf/
tmi2_fluffos_v2/lib/d/Conf/adm/
tmi2_fluffos_v2/lib/d/Conf/boards/
tmi2_fluffos_v2/lib/d/Conf/cmds/
tmi2_fluffos_v2/lib/d/Conf/data/
tmi2_fluffos_v2/lib/d/Conf/logs/
tmi2_fluffos_v2/lib/d/Conf/obj/
tmi2_fluffos_v2/lib/d/Conf/text/help/
tmi2_fluffos_v2/lib/d/Fooland/adm/
tmi2_fluffos_v2/lib/d/Fooland/data/
tmi2_fluffos_v2/lib/d/Fooland/data/attic/
tmi2_fluffos_v2/lib/d/Fooland/items/
tmi2_fluffos_v2/lib/d/TMI/
tmi2_fluffos_v2/lib/d/TMI/adm/
tmi2_fluffos_v2/lib/d/TMI/boards/
tmi2_fluffos_v2/lib/d/TMI/data/
tmi2_fluffos_v2/lib/d/TMI/rooms/
tmi2_fluffos_v2/lib/d/grid/
tmi2_fluffos_v2/lib/d/grid/adm/
tmi2_fluffos_v2/lib/d/grid/data/
tmi2_fluffos_v2/lib/d/std/
tmi2_fluffos_v2/lib/d/std/adm/
tmi2_fluffos_v2/lib/data/adm/
tmi2_fluffos_v2/lib/data/adm/daemons/
tmi2_fluffos_v2/lib/data/adm/daemons/doc_d/
tmi2_fluffos_v2/lib/data/adm/daemons/emoted/
tmi2_fluffos_v2/lib/data/adm/daemons/network/http/
tmi2_fluffos_v2/lib/data/adm/daemons/network/services/mail_q/
tmi2_fluffos_v2/lib/data/adm/daemons/network/smtp/
tmi2_fluffos_v2/lib/data/adm/daemons/news/archives/
tmi2_fluffos_v2/lib/data/attic/connection/
tmi2_fluffos_v2/lib/data/attic/user/
tmi2_fluffos_v2/lib/data/std/connection/b/
tmi2_fluffos_v2/lib/data/std/connection/l/
tmi2_fluffos_v2/lib/data/std/user/a/
tmi2_fluffos_v2/lib/data/std/user/b/
tmi2_fluffos_v2/lib/data/std/user/d/
tmi2_fluffos_v2/lib/data/std/user/f/
tmi2_fluffos_v2/lib/data/std/user/l/
tmi2_fluffos_v2/lib/data/std/user/x/
tmi2_fluffos_v2/lib/data/u/d/dm/working/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/smtp/
tmi2_fluffos_v2/lib/doc/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/interactive/
tmi2_fluffos_v2/lib/doc/driverdoc/concepts/
tmi2_fluffos_v2/lib/doc/driverdoc/driver/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/arrays/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/buffers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/compile/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/ed/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/filesystem/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/floats/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/functions/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/general/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/mappings/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/numbers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/parsing/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/constructs/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/preprocessor/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/types/
tmi2_fluffos_v2/lib/doc/driverdoc/platforms/
tmi2_fluffos_v2/lib/doc/mudlib/
tmi2_fluffos_v2/lib/ftp/
tmi2_fluffos_v2/lib/include/driver/
tmi2_fluffos_v2/lib/log/
tmi2_fluffos_v2/lib/log/driver/
tmi2_fluffos_v2/lib/obj/net/
tmi2_fluffos_v2/lib/obj/shells/
tmi2_fluffos_v2/lib/obj/tools/
tmi2_fluffos_v2/lib/std/adt/
tmi2_fluffos_v2/lib/std/board/
tmi2_fluffos_v2/lib/std/body/
tmi2_fluffos_v2/lib/std/fun/
tmi2_fluffos_v2/lib/std/living/
tmi2_fluffos_v2/lib/std/object/
tmi2_fluffos_v2/lib/std/shop/
tmi2_fluffos_v2/lib/std/socket/
tmi2_fluffos_v2/lib/std/user/
tmi2_fluffos_v2/lib/std/virtual/
tmi2_fluffos_v2/lib/student/
tmi2_fluffos_v2/lib/student/kalypso/
tmi2_fluffos_v2/lib/student/kalypso/armor/
tmi2_fluffos_v2/lib/student/kalypso/rooms/
tmi2_fluffos_v2/lib/student/kalypso/weapons/
tmi2_fluffos_v2/lib/u/l/leto/
tmi2_fluffos_v2/lib/u/l/leto/cmds/
tmi2_fluffos_v2/lib/www/errors/
tmi2_fluffos_v2/lib/www/gateways/
tmi2_fluffos_v2/lib/www/images/
tmi2_fluffos_v2/old/
tmi2_fluffos_v2/win32/
 
//	File	:  /std/connection.c
//	Creator	:  Buddha@TMI  (1/93)
//	Updated	:  Watcher@TMI (2/28/93) to move wizard flag from user
//		    object to the connection object.
//		   Watcher@TMI (3/16/93) to setup new body connection system
//
//	This is a generic user connection object which is linked 
//	to a specific user body.

#include <uid.h>
#include <login.h>
#include <daemons.h>
#include <config.h>
#include <driver/origin.h>

string name, password, body, email, real_name, ip, userid;
mapping domains;
mixed *passwd_fail;
int wizard, last_on, dead, hibernate;

static object body_ob, tmp_body;
static string termtype;

int remove();
int save_data_conn();
static void terminal_type(string term);

//  It would be Bad (tm) to allow a connection object to be shadowed.

int query_prevent_shadow() {  return 1;  }
 
// Keep this static so that only driver can call this.
static void logon() {
	seteuid(0);
//	seteuid("Logon") ;
	wizard = 0;
         termtype = "UNKNOWN";
	call_out("check_status", 5 * 60);
	LOGIN_D->logon(this_object());
}

int connect() {
	if (geteuid(previous_object()) != ROOT_UID) return 0;
	if (!body_ob) return 0;
	if (!interactive(this_object())) {
		if (!interactive(body_ob)) body_ob->remove();
		remove();
	} 

/*  I think this is not needed but I might be wrong ;)
	ip = query_ip_name( this_object() );
	last_on = time();
*/
 
	if (!exec(body_ob, this_object())) {
		write("Error connecting to your body... try again...\n");
		body_ob->remove();
		remove();
		return 0;
	}
	body_ob->set_link(this_object());
	return 1;
}
 
int switch_body() {

   if((geteuid(previous_object()) != ROOT_UID && 
       previous_object() != body_ob) || !tmp_body)  return 0;
 
   if(interactive(tmp_body) || !interactive(body_ob) ||
      !exec(tmp_body, body_ob))  return 0;
 
   body_ob = tmp_body;
   export_uid(body_ob);
   tmp_body = 0;
 
   body_ob->set_link(this_object());
   body_ob->restore_body();

return 1; }
 

nomask void receive_message(string Class, string msg) {
	receive(msg);
}

void link_dead() {
	save_data_conn();
	remove();
}

// We need this function in case a player is queried for his link while he<
// is in login or for some other reason has no body.

object query_link() {
	return this_object() ;
}

 
int save_data_conn() {
	if (!name || name == "logon" || !password) return 0;

      // A fix from Dm, after an idea from Robo, added by Leto
  // if(file_size(PDATA_DIR+name+".o") < 1) return 0;
	assure_user_save_dir(this_object());
	save_object(user_data_file(this_object())+__SAVE_EXTENSION__);
	return 1;
}


int restore() {

	int success ;

   if( !name || geteuid( previous_object() ) != ROOT_UID ) return 0;
// printf( "Debug: PO is %O\n", previous_object() );
// printf( "Debug: geteuid(PO) is %O\n",  geteuid( previous_object() ) );
// printf( "Debug: getuid(PO) is %O\n",  getuid( previous_object() ) );
//    printf("Debug: Euid is %s.\n", geteuid());
// seteuid(name);
// Removed by Blue.  It appears to have no effect. 940425.
//    printf("Debug: Euid is %s.\n", geteuid());
#if 0
	return restore_object(user_data_file(this_object()));
#else
// Log data files which don't load...don't exist? wrong permissions at
// Unix level?
        if (catch(success = restore_object(user_data_file(this_object())+__SAVE_EXTENSION__))) {
                log_file("restore_err",
                sprintf("[%s] Unable to restore_object(\"%s\")\n", name,
                      user_data_file(this_object())+__SAVE_EXTENSION__ ));
                      success = 0;
        }
        return success;
#endif
}

int restore_body() {
	if (geteuid(previous_object()) != ROOT_UID) return 0;
	if (!name || !body) return 0;
	seteuid(name);
	if(catch( body_ob = new(body) ))  return 0;
	export_uid(body_ob);
	if (!body_ob) {
		write("Could not create a " + body + " for you to log into.\n");
		return 0;
	}
	return (int) body_ob->restore_body();
}

int remove() {

// Leto added this 95-04-09
    if (previous_object()) {
        if (this_player(1) &&
            !adminp(geteuid(this_player(1))))
            return 0;
        if (geteuid(previous_object()) != ROOT_UID &&
            geteuid(previous_object()) != geteuid(this_object()) &&
            file_name(previous_object()) != FINGER_D)
            return 0;
    }
    save_data_conn();
    destruct(this_object());
    return 1;
}

int remove_user() {  call_out("remove", 0);  return 1;  }
 
int clean_up() {
	if (!body_ob || !interactive(body_ob)) return remove();
	save_data_conn();
	return 1;
}

nomask mixed query(string what) {

	if (!what) return 0;
	switch (what) {
		case "name" :
			return (name ? name : "logon");
		case "cap_name" :
			return (name ? capitalize(name) :"Logon");
		case "password" : return password;
		case "wizard" : return wizard;
		case "body" : return body;
		case "dead" : return dead;
		case "tmp_body" : return tmp_body;
		case "hibernate" : return hibernate;
		case "real_name" : return real_name;
		case "passwd_fail" : return passwd_fail;
		case "email" : return email;
		case "body_ob" : return body_ob;
		case "last_on" : return last_on;
		case "ip" : return ip;
                case "termtype" : return termtype;
		case "userid" : {
		  if(geteuid(previous_object()) != ROOT_UID) return 0;
	 	  else return userid;
		}
		case "domains" : {
			if (geteuid(previous_object()) == ROOT_UID)
	{
				return domains;
			}
			else return copy(domains);
		}
		default : return 0;
	}
}

nomask void set(string what, mixed val) {
        if (!what) return 0;
 
	if(geteuid(previous_object()) != ROOT_UID &&
	   previous_object() != body_ob)  return;
 
//    if (what == "body") {
// Commented out for now, Leto 04-06-95
        //log_file("conn_body_set", sprintf("prev: %s, time: %s, euid: %s\n", identify(previous_object()), ctime(time()), geteuid(previous_object())));
//    }
        switch (what) {
                case "name" : name = val; seteuid(name); break;
                case "password" : password = val; break;
		case "wizard" : wizard = val; break;
		case "passwd_fail" : passwd_fail = val; break;
                case "body" : body = val; break;
		case "tmp_body" : tmp_body = val; break;
		case "real_name" : real_name = val; break;
                case "email" : email = val; break;
		case "body_ob" : body_ob = val; break;
		case "hibernate" : hibernate = val; break;
		case "dead" : dead = val; break;
		case "domains" : domains = val; break;
		case "userid" : userid = val; break;
		case "last_on" : last_on = val; break;
		case "ip" : ip = val; break;
		case "termtype" : termtype = val; break; // Leto
		default : return;
        }
	save_data_conn();
}

int check_status() {

   remove_call_out("check_status");
 
   if(interactive(this_object()) || !body_ob || !interactive(body_ob))
	remove();

return 1; }

 

void terminal_type(string term) {

termtype = term;
}