login.c

skylib_mudos_v1/mudlib/secure/login.c · 46.2 KB

From the archive skylib_mudos_v1.tar.gz

Download the archive   « Back to the archive contents

/**
 * The main login object.
 * <p>
 * Originally written by Pinkfish, who knows when.
 * <p>
 * Mangled bunches of times by Pinkfish since then and various other wombles
 * all over the place.
 * <p>
 * Put in the random names and the delete character menu options in
 * January 1996.
 * <p>
 * Got excited again in June 1996 and modified the random name stuff
 * and made the new player ban code a bit keener - Pinkfish.
 * <p>
 * So excited in January 1997 that I wrote a login queue.  Most of it
 * works.  Bug fixing in progress forever.
 * @author Pinkfish
 */

#include <random_names.h>
#include <player_handler.h>
#include <login_handler.h>
#include <clubs.h>
#include <access.h>

inherit "/global/player/family";

#define QUOTE_HANDLER "/handlers/pqf_handler"

#define MAX_RETRYS 3
#define MIN_LEN 3
#define MAX_LEN 12

#undef DEBUG
#undef LOOKUP_IDENT

#define IDENT "/net/daemon/out_auth"

#define GUEST    1
#define NEW      2
#define CURRENT  3
#define DELETE   4
#define UNDELETE 5

#define LOGON_MENU    1
#define RANDOM_OR_NOT 2
#define MAIN_RANDOM   3
#define RANDOM_NAME   4

#define TIMEOUT_TIME 120
#define THROWOUT_TIME ( 3 * TIMEOUT_TIME )

inherit OBJECT_OBJ;

int cols;
int Str;
int Dex;
int gender;
int creator;
int app_creator;
int time_on;
int last_log_on;
int activity_counter;
int start_time;
string password;
string title;
string al_title;
string cap_name;
string deity;
string real_name;
string email;
string last_on_from;
string which_player;
mapping new_skills;
/* Used for a few of the off line call things */
mapping aliases;
nosave int auto_authorise;
nosave int go_invis;
nosave int no_times;
nosave int the_rows;
nosave int the_cols;
nosave int login_port;
nosave int login_start_time;
nosave string player_ob;
nosave string terminal_name;
nosave string *random_names;
nosave object other_copy;
nosave object new_copy;

/* Used to get the property stuff while not logged on working. */
nosave string prop_var_name = "map_prop ";

/* for login queue handling */
nosave int can_login;
nosave int login_num;
nosave int net_dead;
nosave string name;

#ifdef LOOKUP_IDENT
nosave string my_ident;
nosave int got_return;
nosave object ident_player_ob;
#endif

mapping restore_stats;

/* prototypes */
private void logon_menu();
protected void delete_character_menu();
void enter_name( string str, string prompt, int type, mixed *args );
varargs void name_menu(int guest);
protected void delete_character_menu();
void random_name_menu(string lang, int guest, int re_gen);
void main_random_name_menu(int guest);
protected void logon3();
protected void logon4(int bing);
protected void logon5(int new_pl);
protected void begin(int new_pl);
protected void begin2(int new_player);
protected void try_throw_out(int new_pl);
string query_player_file_name(string name);
string query_delete_player_file_name(string name);
protected void check_terms(string str, int new_pl);
void finger_player(string str);
void just_name_menu(int guest);

void create() {
    ::create();
    cols = 79;
    gender = -1;
    Str = -1;
    Dex = -1;
    start_time = time();
    map_prop = ([ ]);
    aliases = ([ ]);
    seteuid( "Root" );
    set_name( "logon" );
    player_ob = "/global/player";
} /* create() */

private void set_name(string nam) {
    name = nam;
} /* set_name() */

/** @ignore yes */
string query_name() {
    return name;
} /* query_name() */

/** @ignore yes */
int query_cols() { return cols; }
/** @ignore yes */
string query_title() { return "the title-less"; }
/** @ignore yes */
int query_creator() { return creator; }

/** @ignore yes */
string query_cap_name() {
    if (!cap_name)
        return "Logon";
    return cap_name;
} /* query_cap_name() */

/** @ignore yes */
int query_login_port() { return login_port; }
/** @ignore yes */
void set_login_port(int port) {
    if ( master() == previous_object() ) {
        login_port = port;
    }
} /* set_login_port() */

private int check_valid_name(string str) {
    int i;

    for (i=0;i<strlen(str);i++) {
        if (str[i] < 'a' || str[i] > 'z') {
            return i;
        }
    }
    return -1;
} /* check_valid_name() */

/** @ignore yes */
void logon() {
    int tim;

    call_out( "time_out", TIMEOUT_TIME );
    login_start_time = time();

    if ( SHUTDOWN_H->query_shutdown()<60 && login_port != 4243 ) {
        tim = (int)SHUTDOWN_H->query_shutdown();
        if ( tim < 60 )
            switch ( tim ) {
        case 1 .. 60 :
            write( mud_name()+" is shutting down in "+ tim +" minutes.\n" );
            break;
        default :
            write( mud_name()+" is shutting down NOW!\n");
        }
        if ( tim < 5 ) {
            write( "It is too close to the shut-down to attempt to log in.\n"+
              "Please try again in a few minutes.\n" );
            return dest_me();
        }
    }

    if( LOGIN_H->is_discworld_full(0) ) {
        write("***  Warning there are no player slots available  ***\n");
        write("***   If you login you will be placed in a queue  ***\n");
    }

#ifdef LOOKUP_IDENT
    /* This is a bit of a hassle.  Make it less likely to blow up */
    catch(IDENT->query_auth("finished_auth"));
#endif
    if( TP == TO )
        cat( choice( ({ "/doc/login/LOGON",
                        "/doc/login/LOGON2",
                        "/doc/login/LOGON3" }) ) );

    // write( LOGIN_H->get_message("/doc/login/LOGON") );
    logon_menu();

} /* logon() */

/** @ignore yes */
private void logon_menu() {
    string mess;

    // check if the IP has been locked down due to excessive login failures.
    if( LOGIN_H->site_lockeddown(query_ip_number(TO)) ) {
        write("Sorry, your site has been locked down for excessive failed login "
          "attempts.  If you have forgotten your password please email "
          +ADMIN_EMAIL+".  If you have not failed to login "
          "please try again later.\n");
        mess = sprintf("Attempted login from locked down site: %s.",
          query_ip_number(TO));

        log_file("BAD_PASSWORD", ctime(time())+" "+mess+"\n");
        event( efun::users(), "inform", mess, "bad-password");
        dest_me();
    }

    write( "Do you wish to log on as:\n"
      "Q - Quit               M - Print this menu again\n"
      "N - New character      U - Short list of who is on-line\n"
      "G - Guest character    D - Delete your character\n"
      "F - Finger someone\n"
      "\nOr, enter your current character's name\n\n" );
    write ( "Your choice [D,F,G,M,N,U,Q,<name>]: " );
    input_to("login_choice");
} /* logon_menu() */

/** @ignore yes */
void login_choice(string bing) {
    bing = lower_case(bing);
    while (bing[0] == ' ' || bing[0] == '\t') {
        bing = bing[1..];
    }
    if (!strlen(bing)) {
        bing = "z";
    }
    if (strlen(bing) >= MIN_LEN) {
        /* It is probably someone entering a name. */
        return enter_name( bing, 0, CURRENT, ({ LOGON_MENU }) );
    }
    switch (bing[0]) {
    case 'n' :
        if (BASTARDS_H->no_new_players(TO)) {
            write( "New player logins are disabled from this site.  If you wish "
              "to create a character, please email "
              +ADMIN_EMAIL+" with the player name you would "
              "like to use.\n");
            break;
        }
        write( LOGIN_H->get_message("/doc/login/NEW_USER") );
        name_menu(NEW);
        return ;
    case 'c' :
        write("Enter your name: ");
        input_to( "enter_name", 0, "Enter your name: ", CURRENT,
          ({ LOGON_MENU }) );
        return;
    case 'g' :
        if (BASTARDS_H->no_new_players(TO)) {
            write( "New player logins are disabled from this site.  If you wish "
              "to create a character, please email "+ADMIN_EMAIL+".\n" );
            break;
        }
        write( LOGIN_H->get_message("/doc/login/GUEST_LOGIN") );
        write("Enter the name to use: ");
        input_to( "enter_name", 0, "Enter the name to use: ", GUEST,
          ({ LOGON_MENU }) );
        return;
    case 'm' :
        logon_menu();
        return;
    case 'q' :
        write("Come back soon!\n");
        dest_me();
        return ;
    case 'd' :
        delete_character_menu();
        return ;
    case 'u' :
        write("Here is a list of the people currently playing "+mud_name()+":\n"+
          implode(
            sort_array(
              map_array(
                filter_array(users(), (: !$1->query_invis() :)),
                (: $1->query_cap_name() :)),
              (: strcmp :))
            , ", ")
          +"\n");
        break;
    case 'f' :
        write( "Who do you wish to finger? " );
        bing = bing[1..];
        if (bing[0] == ' ') {
            while (bing[0] == ' ') {
                bing = bing[1..];
            }
            finger_player(bing);
        } else {
            input_to("finger_player");
        }
        return ;
    default :
        write( "Incorrect choice.\n");
        break;
    }
    write ( "Your choice [M,N,G,U,D,F,Q,<name>]: " );
    input_to("login_choice");
    return;
} /* login_choice() */

/** @ignore yes */
void finger_player( string str ) {
    string ret;

    if( stringp(str) && strlen(str) > 2 ) {
        ret = FINGER_H->finger_info( str, 1 );
        if( !ret ) {
            write("I am sorry, the player "+str+" does not appear to "
                "exist.\n");
        } else {
            write( strip_colours( ret ) );
        }
    } else {
        write("Invalid name, returning to the login menu.\n");
    }
    write("Your choice [M,N,G,U,D,F,Q,<name>]: ");
    input_to("login_choice");
    return;
} /* finger_player() */

/** @ignore yes */
protected void delete_character_menu() {
    write( LOGIN_H->get_message("/doc/login/DELETE") );
    write( "\n\nThis is for PERMANENT deletion of your character.\n\n"
      "Which character would you like to delete? " );
    input_to( "enter_name", 0, 0, DELETE, ({ LOGON_MENU }) );
} /* delete_character_menu() */

/* Name is set to the name of the character to delete */
/** @ignore yes */
protected void delete_character() {
    /*
     * To delete ourselves, we move the player file from where it is now
     * into the deleted character dir.
     */
    if (!unguarded((: rename, query_player_file_name(query_name()) + ".o",
          query_delete_player_file_name(query_name()) + ".o" :))) {
        /* To update the time... */
        unguarded((: write_file, query_delete_player_file_name(query_name())+".o",
            "junkjunkjunk 0\n" :));
        write("\n\nPLEASE READ:\nCharacter deleted.  You have 10 days "
          "cooling off time, during "
          "which you may reinstate your character.  To reinstate it "
          "simply log on again and it will reinstate it for you.\n\n\n");
    } else {
        write("WARNING! Unable to delete your character.\n");
    }
    logon_menu();
} /* delete_character() */

/** @ignore yes */
varargs void name_menu(int guest) {
    if ( SHUTDOWN_H->query_shutdown()<3 ) {
        write( "It is too close to the shut-down to attempt to log in.\n"+
          "Please try again in a few minutes.\n" );
        return dest_me();
    }
    just_name_menu(guest);
} /* name_menu() */

/** @ignore yes */
void just_name_menu(int guest) {
    write( LOGIN_H->get_message("/doc/login/NEW_USER_NAME") );
    write("\nEnter the name you wish to play on "+mud_name()+": " );
    input_to("just_name", 0, guest);
} /* just_name_menu() */

/** @ignore yes */
void random_or_not(string str, int guest) {
    if (str[0] == 'y' || str[0] == 'Y') {
        main_random_name_menu(guest);
    } else if (str[0] == 'n' || str[0] == 'N') {
        just_name_menu(guest);
    } else {
        name_menu(guest);
    }
} /* random_or_not() */

/** @ignore yes */
void just_name(string str, int guest) {
    if (strlen(str) > 2) {
        write("\n");
        enter_name( str, 0, guest, ({ RANDOM_OR_NOT, guest }) );
        return ;
    }
    switch (str[0]) {
    case 'm' :
    case 'M' :
        logon_menu();
        break;
    case 'r' :
    case 'R' :
        main_random_name_menu(guest);
        break;
    default :
        just_name_menu(guest);
        break;
    }
} /* just_name() */

/** @ignore yes */
void main_random_name_menu(int guest) {
    string *langs;
    int i;

    i = 1;
    langs = RANDOM_NAME_GENERATOR->query_languages();
    for (i=0;i<sizeof(langs);i++)
        langs[i] = sprintf("%c - %s", (i+'1'), capitalize(langs[i]));

    write("You are choosing a name for the first time on "+mud_name()+".\n"
      "You can choose a name which is generated to sound something "
      "like:\n"+
      implode(langs, "\n")+
      "\nM - Main Menu\n"
      "Q - Quit\n"
      "\nOr you can type in a name of your choice now.\n\n"
      "Your choice? ");
    input_to("name_choice", 0, sizeof(langs), guest);
} /* main_random_name_menu() */

/** @ignore yes */
void name_choice(string str, int len, int guest) {
    string lang;

    if (strlen(str) == 1) {
        if (str[0] >= '1' && str[0] <= ('1'+len-1)) {
            lang = RANDOM_NAME_GENERATOR->query_languages()[str[0]-'1'];
            random_name_menu(lang, guest, 1);
            return ;
        }
        if (str[0] == 'm' || str[0] == 'M') {
            logon_menu();
            return ;
        }
        if (str[0] == 'q' || str[0] == 'Q') {
            write("See you again soon!\n");
            dest_me();
            return ;
        }
        write("Incorrect choice.\n");
    } else if (str != "") {
        enter_name( str, 0, guest, ({ MAIN_RANDOM, guest }) );
        return ;
    }
    main_random_name_menu(guest);
} /* name_choice() */

/** @ignore yes */
void random_name_menu(string lang, int guest, int re_gen) {
    int i;

    write("Here is a list of 9 random names.  Please choose one:\n");
    if (re_gen) {
        random_names = allocate(9);
        for (i=0;i<sizeof(random_names);i++) {
            random_names[i] = RANDOM_NAME_GENERATOR->unique_name(lang);
            write(sprintf("%c - %s\n", i+'1', random_names[i]));
        }
    } else {
        for (i=0;i<sizeof(random_names);i++) {
            write(sprintf("%c - %s\n", i+'1', random_names[i]));
        }
    }
    write("M - Main Menu\n"
      "N - Name Menu\n"
      "G - Generate a new set of names\n"
      "Q - Quit\n"
      "Or, type in your name of choice\n\n"
      "Your choice? ");
    input_to("random_name_choice", 0, lang, guest);
} /* random_name_menu() */

/** @ignore yes */
void random_name_choice(string str, string lang, int guest) {
    if (strlen(str) == 1) {
        switch (str[0]) {
        case '1' :
        case '2' :
        case '3' :
        case '4' :
        case '5' :
        case '6' :
        case '7' :
        case '8' :
        case '9' :
            enter_name( random_names[ str[ 0 ] - '1' ], 0, guest,
              ({ RANDOM_NAME, lang, guest }) );
            return;
        case 'n' :
        case 'N' :
            main_random_name_menu(0);
            return ;
        case 'm' :
        case 'M' :
            logon_menu();
            return ;
        case 'g' :
        case 'G' :
            random_name_menu(lang, guest, 1);
            return ;
        case 'q' :
        case 'Q' :
            write("See you again soon!\n");
            dest_me();
            return ;
        default :
            write("Incorrect choice.\n");
            break;
        }
    } else {
        if (str != "") {
            enter_name( str, 0, guest, ({ RANDOM_NAME, lang, guest }) );
            return ;
        }
    }
    random_name_menu(lang, guest, 0);
} /* random_name_choice() */

/** @ignore yes */
void next_menu( mixed *args ) {
    switch ( args[ 0 ] ) {
    case LOGON_MENU :
        return logon_menu();
    case RANDOM_OR_NOT :
        return random_or_not( "n", args[ 1 ] );
    case MAIN_RANDOM :
        return main_random_name_menu( args[ 1 ] );
    case RANDOM_NAME :
        return random_name_menu( args[ 1 ], args[ 2 ], 0 );
    default :
        write( "An error has occurred in next_menu().\n" );
        dest_me();
    }
} /* next_menu() */

/** @ignore yes */
void enter_name( string str, string prompt, int type, mixed *args ) {
    int tmp;
    string s1;
    string s2;

    go_invis = 0;
    auto_authorise = 0;
    if( str == "" ) {
        /* Redo from start */
        return next_menu( args );
    }

    /* Everything blows up on a banishment. */
    if( str[0] == ':' )
        str = str[1..];
    if( str[0] == '#' ) {
        go_invis = 1;
        str = str[1..];
    } else if( str[0] == '@' ) {
        go_invis = -1;
        str = str[1..];
    }

    set_name(lower_case(str));

    if( PLAYER_H->test_banished(query_name()) ) {
        write("Sorry, the player name ["+query_name()+"] has been banished.\n");
        if (prompt) {
            write(prompt);
            input_to( "enter_name", 0, prompt, type, args );
        } else
            next_menu( args );
        return;
    }
    if (strlen(query_name()) < MIN_LEN && type != CURRENT && type != DELETE) {
        write("Sorry, the player name ["+query_name()+"] is too short (min "+
            MIN_LEN+" characters).\n");
        if (prompt) {
            write(prompt);
            input_to( "enter_name", 0, prompt, type, args );
        } else
            next_menu( args );
        return;
    }
    if (strlen(query_name()) > MAX_LEN) {
        write("Sorry, the player name "+query_name()+" is too long (max " +
          MAX_LEN + " characters).\n");
        if (prompt) {
            write(prompt);
            input_to( "enter_name", 0, prompt, type, args );
        } else
            next_menu( args );
        return;
    }
    if ((tmp = check_valid_name(query_name())) != -1) {
        write("Invalid character '"+str[tmp..tmp]+"'  ("+str+").\n\n");
        if (prompt) {
            write(prompt);
            input_to( "enter_name", 0, prompt, type, args );
        } else
            next_menu( args );
        return;
    }

    switch (type) {
    case GUEST :
        if( LOGIN_H->is_discworld_full(0) ) {
            write("Yesterday is too old, today is much newer.\n"
              "Don't give away your dreams, store them in streams.\n"
              "\nSorry, guests cannot login currently, too many players.\n");
            logon_menu();
            return ;
        }
    case NEW :
        if( ( sscanf( query_name(), "%sblack%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sblood%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%scyber%s", s1, s2 ) == 2) ||
            ( sscanf( query_name(), "%sdark%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%spenis%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%scock%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%spussy%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sfuck%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sshit%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sdeath%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sdragon%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sfish%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%spimp%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%shell%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%smage%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%spink%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%slord%s", s1, s2 ) == 2 ) ||
            ( sscanf( query_name(), "%sevil%s", s1, s2 ) == 2) ||
            ( sscanf( query_name(), "%skiller%s", s1, s2 ) == 2) ||
            ( sscanf( query_name(), "%sslayer%s", s1, s2 ) == 2) ) {
            write( "Invalid name.  Please retry.\n");
            if (prompt) {
                write(prompt);
                input_to( "enter_name", 0, prompt, type, args );
            } else
                next_menu( args );
            return;
        }
        if( PLAYER_H->test_user( query_name() ) ||
            CLUB_HANDLER->is_family(query_name() ) ) {
            write("The name ["+query_name()+"] is already in use by another "
                  "character.\n"+
                  "Please choose another name.\n");
            if (prompt) {
                write(prompt);
                input_to( "enter_name", 0, prompt, type, args );
            } else
                next_menu( args );
            return;
        }
        if (type == GUEST) {
            title = "the Guest of "+mud_name();
            add_property("guest", 1);
            return logon3();
        }
        write( "You have typed in the name ["+ query_name() +
          "], is this correct? " );
        input_to( "check_name_correct", 0, args );
        break;
    case DELETE :
    case CURRENT :
        if (unguarded((: restore_object,
              query_delete_player_file_name(query_name()), 1 :))) {
            if (type == DELETE) {
                write("\n\n\nYour character is already deleted.\n\n\n");
                if (prompt) {
                    write(prompt);
                    input_to( "enter_name", 0, prompt, type, args );
                } else {
                    next_menu( args );
                }
                return;
            }

        } else if (!unguarded((: restore_object,
              query_player_file_name(query_name()), 1 :))) {
            write("The name ["+query_name()+
              "] is not in our annals, please try again.\n");
            if (prompt) {
                write(prompt);
                input_to( "enter_name", 0, prompt, type, args );
            } else {
                next_menu( args );
            }
            return;
        } else {
            if (Str == -1) {
                type = NEW;
            }
        }

        if( !password && type == DELETE) {
            write("\nSorry, you cannot delete this character.\n"+
                  "Please see an admin if you have questions.\n\n");
            if (prompt) {
                write(prompt);
                input_to( "enter_name", 0, prompt, type, args );
            } else {
                next_menu( args );
            }
            return;
        }

        if( creator && type == DELETE ) {
            write("\nSorry, you cannot delete a creator character.\n"+
                  "Please ask an admin to demote you first.\n\n");
            if (prompt) {
                write(prompt);
                input_to( "enter_name", 0, prompt, type, args );
            } else {
                next_menu( args );
            }
            return;
        }

        if ( BASTARDS_H->no_new_players( TO ) &&
          !query_property( "authorised player" ) ) {
            string place, addr;
            /*
             * This is put in so it is possible to reactively allow people to
             * log in fdrom a site, by deleting their last login address.
             */
            if (!last_on_from) {
                addr = query_ip_number(TO);
            } else {
                sscanf( last_on_from, "%s (%s)", place, addr );
            }

            /*
             * If it is new player banned and we last logged on from here
             * (or another banned site -- this copes with dynamic ips :).
             * we are automatically authorised.
             */
            /* Allow creators to log in from banned sites. */
            /* And players over 2 days old. */
            if ( !creator &&
              time_on > -(2*24*60*60) &&
              BASTARDS_H->query_access(explode(addr, "."), "*") ==
              DEFAULT) {

                write( "This character is not authorised to play from here.\n" );
                write( "For more information please email "
                  +ADMIN_EMAIL+".  Don't forget to include "
                  "your characters name!\n\n" );
                user_event( "inform", query_name() +" ("+ addr +
                  ") tries to log in from "+
                  query_ip_number( TO ),
                  "cheat" );
                log_file( "CHEAT", ctime( time() ) +": "+ query_name() +" ("+ addr +
                  ") tried to log in from "+ query_ip_number(TO) +
                  "\n" );
                return next_menu( args );
            } else {
                auto_authorise = 1;
            }
        }

        if (!password) {
            return logon3();
        }
        creator = ( creator || app_creator );
        write("\n");
        if( type != DELETE )
            write( LOGIN_H->get_message("/doc/login/WELCOME") );
        write("Enter your password: ");
        input_to( "logon2", 1, type, args );
        break;
    default :
        write("Break down in the system.\n");
        return dest_me();
    }
} /* enter_name() */

/** @ignore yes */
void check_name_correct( string str, mixed *args ) {
    if (strlen(str) < 1 || (str[0] != 'y' && str[0] != 'Y')) {
        if (str[0] == 'n' || str[0] == 'N')
            return next_menu( args );
        write( "Please enter \"y\" or \"n\".\n"+
          "You have typed in the name ["+query_name()+"], is this correct? " );
        input_to( "check_name_correct", 0, args );
        return ;
    }
    write( LOGIN_H->get_message("/doc/login/NEW_USER_PASSWORD") );
    write( "Okay, you have chosen the name ["+ query_name() +"] for your time "
      "at "+mud_name()+".\nHave fun, and remember: don't explode.\n");
    write( "Enter password: " );
    add_property("new player",1);
    input_to( "logon2", 1, GUEST, args );
} /* check_name_correct() */

/** @ignore yes */
int do_su(string str) {
    object ob, tp;

    ob = TP;
    tp = TO;

    terminal_name = ob->query_cur_term();
    the_cols = ob->query_cols();
    the_rows = ob->query_rows();

    exec(tp, ob);
    ob->quit();

    login_choice(str);
    return 1;
} /* do_su() */


void retry_logon(int guest, mixed *args) {
    write("Try again: ");
    input_to("logon2", 1, guest, args);
}

/** @ignore yes */
void time_out() {
    if ( !interactive( TO ) )
        return dest_me();

    /* time them out if they are not in the queue and either idle or
       not idle but have been sitting around too long */
    if((query_idle( TO ) > TIMEOUT_TIME ||
        (time() > login_start_time + THROWOUT_TIME)) &&
      member_array( TO, LOGIN_H->query_login_queue() ) == -1) {
        write( "Time out.\n\n" );
        return dest_me();
    }
    call_out( "time_out", TIMEOUT_TIME );
} /* time_out() */

/** @ignore yes */
protected void logon2( string str, int type, mixed *args ) {
    string mess;

    write( "\n" );
    if ( !str || ( str == "" ) ) {
        password = 0;
        return next_menu( args );
    }

    // Force a 6 character or greater password.
    if(Dex == -1 && strlen(str) < 6) {
        write("Password is too short, must be at least 6 characters.\n");
        write( "Enter password: " );
        input_to( "logon2", 1, type, args );
        return;
    }

    str = crypt(str,password);

    // Password failure.
    if (password && str != password) {

        // new char entering their password, don't count this as a failed login,
        // hence it's before the failed login stuff.
        if (Dex == -1) {
            write( "Didn't match up with first password.\n" );
            write( "Enter password again: " );
            Str = -1;
            input_to( "logon2", 1, type, args );
            return;
        }

        // If they've gone over the max_retrys record it as a failed login.
        if (++no_times > MAX_RETRYS) {

            // record a failed login from this IP.
            LOGIN_H->failed_login(query_ip_number(TO));

            write("Too many retries, please wait...\n");
            mess = capitalize(query_name()) + " failed to login, " +
            (query_ip_name(TO) != query_ip_number(TO)
              ? query_ip_name(TO) + " (" +
              query_ip_number(TO) + ")"
              : query_ip_number(TO));
            event(users(), "inform", mess, "bad-password");
            log_file("BAD_PASSWORD", ctime(time()) + ": " + mess + "\n");
            no_times = 0;
            // Make this delay a bit...
            call_out((: logon_menu :), 30);
            //logon_menu();
            return ;
        }
        write( "Wrong, please wait...\n" );
        call_out( (: retry_logon :), 1, type, args );
        return;
    }

    password = str;
    if (Str == -1) {
        Str = 13;
        write( "Please enter that password again: " );
        input_to( "logon2", 1, type, args );
        return;
    }
    if (Dex == -1) {
        Dex = 13;
    }

    /* Check to see if we are reinstating a deleted character... */
    if (type != DELETE) {
        if (unguarded((: file_size,
              query_delete_player_file_name(query_name()) + ".o" :)) != -1) {
            if (!unguarded((: rename,
                  query_delete_player_file_name(query_name())+".o",
                  query_player_file_name(query_name())+".o" :))) {
                write("Reinstating deleted character!  Good to see you back "
                  "again.\n");
            } else {
                write("\n\n\nUnable to reinstate your character, please send an "
                  "email to "+ADMIN_EMAIL+" if you require further "
                  "assistance.\n\n\n");
                logon_menu();
                return;
            }
        }
        logon3();
    } else {
        delete_character();
    }
} /* logon2() */

/** @ignore yes */
protected void logon3() {
    //  if (!cap_name || lower_case(cap_name) != query_name()) {
    cap_name = capitalize(query_name());
    //    write( "How do you want your name capitalized? ["+ cap_name +"] " );
    //    input_to("get_capitalize");
    //    return ;
    //  }
    logon4(!query_property("guest"));
} /* logon3() */

/** @ignore yes */
protected void get_sex(string str, int bing) {
    int i;
    str = lower_case(str);
    if (str != "")
        i = str[0];
    if (i == 'm')
        gender = 1;
    else if (i== 'f')
        gender = 2;
    else {
        write( "That's too weird even for this game!\n" );
        write( "Try male or female: " );
        input_to("get_sex");
        return ;
    }

    logon5(bing);
} /* get_sex() */

/** @ignore yes */
protected void logon4(int bing) {
    if (gender == -1) {
        write( "Are you male or female? " );
        input_to("get_sex", bing);
        return ;
    }
    logon5(bing);
} /* logon4() */

/** @ignore yes */
protected void get_capitalize(string str) {

    cap_name = str;

    logon4(!query_property("guest"));
} /* get_capitalize() */

/** @ignore yes */
protected void check_terms(string str, int new_pl) {
    write( LOGIN_H->get_message("/doc/login/WELCOME") );
    logon5(new_pl);
}

/** @ignore yes */
protected void logon5(int new_pl) {
    object ob;
    object tmp;
    object* obs;

    if (query_name() != "root" && query_name() != "guest")
        other_copy = find_player(query_name());

    /* This is the check for upgrade calls */
    if (other_copy == TP)
        return begin(new_pl);

    /* Check to see if they are in the login queue already */
    if( member_array( query_name(), map( LOGIN_H->query_login_queue(),
          (: $1->query_name() :) ) ) != -1 ) {
        write("You are already in the login queue.\n");
        obs = filter( LOGIN_H->query_login_queue(),
          (: $1->query_name() == $2 :), query_name() );
        other_copy = obs[0];
        if (other_copy && other_copy->query_login_ob()) {
            //
            // They are already in the login queue.
            //
            write("Reconnecting to you in the login queue.\n");

            if (interactive(other_copy)) {
                tell_object(other_copy, "Disconnected by someone from " +
                  query_ip_name(TO) + ".\n");
                ob = clone_object(OBJECT_OBJ);
                tmp = other_copy;
                exec(ob, other_copy);
                ob->dest_me();
            }
            tmp = other_copy;
            ob = TO;
            exec(other_copy, ob);
            return ;
        } else {
            dest_me();
        }
        return ;
    }

    /* Check to see if mud is full and then shove em into a queue... */
    if( LOGIN_H->is_discworld_full(WITHOUT_LOGINS_NOT_IN_QUEUE) ||
        sizeof( LOGIN_HANDLER->query_login_queue()) ) {
        /* Admins fast track into the game. */
        /* allow creators in too */
        if (!creator && !query_property("test character")) {
            write("Sorry, there are no player slots available.\n\n");
            LOGIN_H->add_to_login_queue(TO);
            login_num = sizeof(LOGIN_H->query_login_queue());
            if (other_copy) {
                /*
                 * Hack!  Hack!  Warning!  No idea why reconnection to net
                 * deads is not working.  So force them to quit instead.
                 */
                other_copy->quit();
                write("You were net dead when you left, shuffling you to the "
                  "start of the queue...\n");
                net_dead = 1;
            } else {
                write("Placing you in the login queue: you have position "+
                  login_num + ".\nPlease wait.  Type \"quit\" to escape.\n" );
            }
            remove_call_out("time_out");
            call_out("check_status", 30, new_pl);
            input_to("idle_loop", 0, new_pl);
            return ;
        }
    }

    if (other_copy) {
        try_throw_out(new_pl);
        return ;
    }

    begin(new_pl);
} /* logon5() */

/*
 * This is the idle loop stuff.  It checks to see if the people want to
 * leave the queue nicely.  Not absolutely nessessary I guess.
 */
/** @ignore yes */
void idle_loop(string str, int new_pl) {
    if (can_login == 2) {
        try_throw_out(new_pl);
    } else if (can_login == 3) {
        begin(new_pl);
    } else if (strlen(str) && lower_case(str)[0] == 'q') {
        dest_me();
    } else {
        input_to("idle_loop", 0, new_pl);
    }
} /* idle_loop() */

/*
 * This is called from the login_handle when we are ready to leave the
 * login queue.
 */
/** @ignore yes */
void remove_from_login_queue() {
    object other_copy;

    can_login = 1;
    other_copy = find_player(query_name());
    if (other_copy) {
        can_login = 2;
    } else {
        can_login = 3;
        tell_object(TO, "\n\n\n\nYou have exited the login queue!  "
          "Please press return to continue:");
        call_out("time_out", TIMEOUT_TIME);
    }
    /* Just in case... */
    LOGIN_H->remove_from_login_queue(TO);
} /* remove_from_login_queue() */

/*
 * This is the call out done now and then.  It prints the cute messages.
 */
/** @ignore yes */
void check_status(int new_pl) {
    int tmp_num;
    object other_copy;
    //  string *stuff;

    if (!can_login) {
        tmp_num = member_array(TO, LOGIN_H->query_login_queue())+1;
        if (tmp_num == 0) {
            /* Oh dear, we got deleted...  Put ourselves back in */
            LOGIN_H->add_to_login_queue(TO);
            tmp_num = member_array(TO, LOGIN_H->query_login_queue())+1;
        }
        if (tmp_num > 0 && tmp_num != login_num && !other_copy) {
            if(!net_dead)
                write("You now have position "+tmp_num+" in the queue.\n");
        }
        login_num = tmp_num;
        switch (random(100)) {
        case 0 :
            write("Boring message 1.\n");
            break;
        case 1 :
            write("Boring message 2.\n");
            break;
        case 2 :
            write("Boring message 3.\n");
            break;
        case 3 :
            write("Boring message 4.\n");
            break;
        case 4 :
            write("Boring message 5.\n");
            break;
        case 5 :
            write("Boring message 6.\n");
            break;
        case 6 :
            write("Boring message 7.\n");
            break;
        case 7 :
            write("Boring message 8.\n");
            break;
        case 8 :
            write("Boring Message 9.\n");
            break;
        case 9 :
            write("Boring Message 10.\n");
            break;
        default :
            write("Boring message 11.\n");
            break;
        }
        call_out("check_status", 30, new_pl);
    }
} /* check_status() */

/** @ignore yes */
protected void try_throw_out(int new_pl) {
    object tmp, ob;

    if (!other_copy) {
        write("Oh dear.  Your other copy has been eaten.  Logging in normally.\n");
        begin(new_pl);
        return ;
    }

    if (interactive(other_copy)) {
        ob = clone_object(OBJECT_OBJ);
        tmp = other_copy;
        exec(ob, other_copy);
        ob->dest_me();
    }
    tmp = other_copy;
    ob = TO;
    exec(other_copy, ob);
    /* force a look ;) */
#ifdef LOOKUP_IDENT
    other_copy->set_my_ident(my_ident);
#endif
    other_copy->look_me();

    LOGIN_H->player_reconnected(other_copy->query_name());

    tell_room(environment(other_copy), other_copy->query_cap_name()+
      " has reconnected.\n", ({ other_copy }) );

    if (function_exists("inform_reconnect_game", other_copy)) {
        other_copy->inform_reconnect_game();
    }

#ifdef LOOKUP_IDENT
    if (got_return)
        return dest_me();
    ident_player_ob = other_copy;
#else
    dest_me();
#endif
} /* try_throw_out() */

/** @ignore yes */
protected void begin( int new_pl ) {
    if( query_name() == "shutdown" ) {
        shutdown();
        return ;
    }

    player_ob = BASTARDS_H->query_player_ob( query_name(), 1 );

    if( !player_ob ) {
        logon_menu();
        return ;
    }

    if( go_invis > 0 ) {
        go_invis = creatorp( query_name() )+
                   lordp( query_name() )+
                   adminp( query_name() );
        unguarded( (: write_file, query_player_file_name(query_name())+".o",
                "invis "+go_invis+"\n" :) );
    } else if( go_invis == -1 )
        unguarded( (: write_file, query_player_file_name(query_name())+".o",
            "invis 0\n" :) );

    if( !find_object(player_ob) ) {
        write("Please wait... Loading player object.\n");
        call_out("begin2", 0, new_pl );
    } else {
        begin2( new_pl );
    }

} /* begin() */

/** @ignore yes */
protected void begin2(int new_player) {
    object tp;

    // Clone the player object.
    if( catch( new_copy = clone_object(player_ob) ) ) {
        write("Oh no, someone has broken the player object!  "+
          "Come back later.\n");
        return dest_me();
    }

    if( !new_copy ) {
        write( "Argh!  Something bad happened.\n");
        return dest_me();
    }

    new_copy->set_name( query_name() );
    new_copy->set_password( password );

    tp = TO;
    exec( new_copy, tp );

    if( tp != TO )
        tp->quit();
    if( query_property("guest") ) {
        new_copy->add_property("guest", 1 );
        new_copy->set_title(title);
    }

    //  if(query_property("Accepted Terms"))
    //    new_copy->add_property("Accepted Terms", 1);

#ifdef LOOKUP_IDENT
    new_copy->move_player_to_start( query_name(), query_property("new player"),
                                    cap_name, my_ident );
#else
    new_copy->move_player_to_start( query_name(), query_property("new player"),
                                    cap_name );
#endif

    new_copy -> set_gender(gender);
    if( new_player )
        new_copy->add_skill_level("general.language.common", 100 );

    // Wheee.
    if( terminal_name )
        new_copy->terminal_type( terminal_name );
    if( the_cols && the_rows )
        new_copy->window_size( the_cols, the_rows );
    if( auto_authorise )
        new_copy->add_property( "authorised player",
            query_ip_number( new_copy ) );

    if( query_ip_number(new_copy) == query_ip_name(new_copy) )
        resolve(query_ip_number(new_copy), "query_level");

#ifdef LOOKUP_IDENT
    if( got_return )
        return dest_me();
    ident_player_ob = new_copy;
#endif
    dest_me();
} /* begin2() */

/** @ignore yes */
int query_level() { return 1; }
/** @ignore yes */
int query_gender() { return gender; }

private void do_special_add_property(string fname, string prop, mixed val) {
    string frog, *bits;
    mapping glue;
    int i, len;

    frog = read_file(fname);

    if( !frog ) {
#ifdef DEBUG
        log_file("LOGIN_ERROR", ctime(time())+ ": Could not read file "+
            fname+" .\n");
#endif
        return;
    }

    bits = explode( frog, "\n");
    len = strlen( prop_var_name ) - 1;
    for( i = 0; i < sizeof(bits); i++ ) {
        if( bits[i][0..len] == prop_var_name ) {
            glue = restore_variable( bits[i][len + 1..] );
            glue[prop] = val;
            bits[i] = prop_var_name + save_variable(glue);
            break;
        }
    }

    reset_eval_cost();
    // We really do not want to break in here...
    if( !write_file( fname, implode( bits, "\n"), 1 ) ) {
        tell_creator("shaydz", "Unable to write to %s prop %s\n",
            fname, prop );
    }

    write_file( fname, "\n");

} /* do_special_add_property() */

/**
 * This method allows you to add properties onto players who are not
 * currently logged on.
 * @param pname name of player to change
 * @param prop the property to change
 * @param val the new value for it.
 */
void special_add_property(string pname, string prop, mixed val) {
    object ob;
    string tmp_name;

    if( !stringp(prop) || !stringp(pname) )
        return;

    if( !rank(pname) )
        return;

    if( ob = find_player(pname) ) {
        ob->add_property( prop, val );
    } else {
        tmp_name = query_player_file_name(pname) + ".o";
        unguarded( (: do_special_add_property( $(tmp_name), $(prop), $(val) ) :) );
        PLAYER_H->special_add_property( pname, prop, val );
    }
} /* special_add_property() */

/* This function is called by the upgrade object. */
/** @ignore yes */
void new_player(object old) {
    object new_pl;
    string name;
    string ob_name;
#ifdef LOOKUP_IDENT
    string ident;
#endif

#ifdef LOOKUP_IDENT
    ident = query_ident(old);
#endif
    name = (string)old->query_name();
    cap_name = (string)old->query_cap_name();
    creator = (int)creatorp(old);
    terminal_name = old->query_cur_term();
    the_cols = old->query_cols();
    the_rows = old->query_rows();
    exec( TO, old );
    creator = (int)creatorp(old);
    old->quit();
    creator = (int)creatorp(TP);
    ob_name = BASTARDS_H->query_player_ob( name, 1 );

    if( !ob_name ) {
        logon_menu();
        return ;
    } else {
        new_pl = clone_object(ob_name);
    }

    exec( new_pl, TO );
    new_pl->terminal_type( terminal_name );
    new_pl->window_size( the_cols, the_rows );
#ifdef LOOKUP_IDENT
    new_pl->move_player_to_start( name, 0, cap_name, ident );
#else
    new_pl->move_player_to_start( name, 0, cap_name );
#endif
    dest_me();
} /* new_player() */

/** @ignore yes */
int query_prevent_shadow() { return 1; }

/*
 * Needed so the object actually writes things to the screen.  Mildly
 * embarasing otherwise.
 */
/** @ignore yes */
void do_efun_write(string str) {
    efun::tell_object( TO, str );
} /* do_efun_write() */

/** @ignore yes */
string query_object_type() { return "X"; }

/** @ignore yes */
string query_gender_string() { return "blue"; }

#ifdef LOOKUP_IDENT
/** @ignore yes */
void finished_auth(string m_i) {
    got_return = 1;
    my_ident = m_i;
    if( ident_player_ob ) {
#ifdef DEBUG
        TCRE("shaydz", "Found ident of "+m_i+" (player_ob) "+name+"\n");
#endif
        ident_player_ob->set_my_ident(m_i);
        dest_me();
    } else
#ifdef DEBUG
        TCRE("shaydz", "Found ident "+m_i+" "+name+"\n");
#endif
} /* found_ident() */
#endif

/** @ignore yes */
void terminal_type(string type) {
    terminal_name = type;
} /* terminal_type() */

/** @ignore yes */
void window_size(int width, int height) {
    the_cols = width;
    the_rows = height;
} /* window_size() */

/** @ignore yes */
int query_invis() {
    return 1;
} /* query_login() */

/** @ignore yes */
void net_dead() {
    LOGIN_H->remove_from_login_queue(TO);
    dest_me();
} /* net_dead() */

/** @ignore yes */
void dest_me() {
    LOGIN_H->remove_from_login_queue(TO);
    ::dest_me();
} /* dest_me() */

/**
 * This method determines if the object is a login object.
 * @return always returns 1
 */
int query_login_ob() { return 1; }

/**
 * This method tells us if the object is net dead.
 * @return 1 if they are net dead, 0 if they are not
 */
int query_net_dead() { return net_dead; }

/**
 * This method returns the path to the player file.
 * This is the player files actual normal location, it was written to
 * allow moving the player files aruond easier.
 * @param name the name of hte player whose file to find
 * @see test_user()
 * @see query_delete_player_file_name()
 */
string query_player_file_name(string name) {
    return PLAYER_SAVE_DIR + name[0..0] + "/" + name;
} /* query_player_file_name() */

/**
 * This method returns the path to the deleted player file.
 * This is the deleted player files actual normal location, it was written to
 * allow moving the player files aruond easier.
 * @param name the name of hte player whose file to find
 * @see test_user()
 * @see query_delete_player_file_name()
 */
string query_delete_player_file_name(string name) {
    return PLAYER_SAVE_DIR + DELETE_DIR + "/" + name;
} /* query_player_file_name() */

/** @ignore yes */
string *parse_command_adjectiv_id_list() {
    return object::parse_command_adjectiv_id_list();
} /* parse_command_adjectiv_id_list() */

/** @ignore yes */
string *parse_command_plural_id_list() {
    return object::parse_command_plural_id_list();
} /* parse_command_plural_id_list() */

/** @ignore yes */
string *parse_command_id_list() {
    return object::parse_command_id_list();
} /* parse_command_id_list() */

/** @ignore yes */
int test_user(string str) { return PLAYER_H->test_user(str); }

/** @ignore yes */
int test_gender(string str) { return PLAYER_H->test_gender(str); }

/** @ignore yes */
int test_active(string str) { return PLAYER_H->test_active(str); }

/** @ignore yes */
int test_level(string str) { return PLAYER_H->test_level(str); }

/** @ignore yes */
int test_banished(string str) { return PLAYER_H->test_banished(str); }

/** @ignore yes */
string test_real_name(string str) {
    return PLAYER_H->test_real_name(str);
} /* test_real_name() */

/** @ignore yes */
string test_email(string str) { return PLAYER_H->test_email(str); }

/** @ignore yes */
mixed test_property(string word, string str) {
    return PLAYER_H->test_property(word, str);
} /* test_property() */

/** @ignore yes */
string test_deity(string str) { return PLAYER_H->test_deity(str); }

/** @ignore yes */
int test_age(string str) { return PLAYER_H->test_age(str); }

/** @ignore yes */
int test_last(string str) { return PLAYER_H->test_last(str); }

/** @ignore yes */
int test_start_time(string str) {
    return PLAYER_H->test_start_time(str);
} /* test_start_time() */

/** @ignore yes */
string test_family(string str) { return PLAYER_H->test_family(str); }

/** @ignore yes */
int test_password(string name, string pass) {
    return PLAYER_H->test_password(name, pass);
} /* test_password() */

/** @ignore yes */
string query_signature(string str) {
    return PLAYER_H->query_signature(str);
} /* query_signature() */

Site Stats

Snippets: 1791
Codebases: 571