login_interface.coldc

./CDC-1.1/login_interface.coldc · 5.1 KB

From the archive CDC-1.1.tar.gz

Download the archive   « Back to the archive contents

parent $connection_interface
object $login_interface

var $root dbref 'login_interface
var $root child_index 0
var $root fertile 0
var $root manager $login_interface
var $root owned [$login_interface]
var $root owners [$login_interface]
var $root writable []
var $root readable ['parameters, 'methods, 'code]
var $has_commands commands [["@quit|QUIT", 'quit_cmd], ["h?elp", 'quit_cmd], ["@who|WHO", 'quit_cmd], ["c?onnect guest *", 'quit_cmd], ["c?onnect *", 'quit_cmd], ["m?otd", 'quit_cmd]]
var $has_commands shortcuts []
var $root inited 1

method connect_cmd
    arg com, words;
    var words, u, password, salt, syn, name, passwd, line;
    
    (> .perms(sender(), 'this) <);
    
    //
    syn = "`connect <name> <pass>' (last word is taken as the password)";
    
    // parse name / password
    words = explode(words);
    if (listlen(words) < 2)
        $parse.tell_error(syn);
    passwd = words[listlen(words)];
    name = $list.to_string(sublist(words, 1, listlen(words) - 1));
    
    // find name in the db
    catch ~namenf {
        user = $user_db.find(name);
    } with handler {
        line = "Either that user does not exist or has a different password.";
        $parse.tell_error(line, syn);
    }
    
    // validate password
    if (!(user.check_password(passwd))) {
        line = "Either that user does not exist or has a different password.";
        $parse.tell_error(line, syn);
    }
    
    // change connection objects
    connection.change_interface_object(user);
    user.connection_logged_in(addr, port);
    
    // this is redundant, as .change_interface_object will shut us down
    .close();
.

method create_cmd
    arg com, words;
    var words, syn;
    
    syn = "!  Usage: `create <name> <password> <email@host>'";
    if (sender() != this())
        throw(~perm, "Sender is not this.");
    
    // Get user name, password, and email.
    words = explode(words);
    if (listlen(words) != 3)
        return .tell(syn);
    
    // Create a new user object.
    catch any {
        user = $sys.create_user(words[1], words[2], words[3]);
    } with handler {
        .tell(syn);
        switch (error()) {
            case ~duplicate:
                .tell(("!  The user " + toliteral(words[1])) + " already exists.");
            default:
                .tell("!  There was a problem creating you:");
                .tell("!  => " + ((traceback()[1])[2]));
                .tell("!  If there is a problem contact: " + ($sys.get_system_email('login)));
    
                // $sys.log(traceback());
        }
        if (user) {
            (| user.destroy() |);
            user = 0;
        }
        return;
    }
    
    // Log the user in.
    user.connection_logged_in(addr, port);
.

method quit_cmd
    arg dummy;
    
    if (sender() != this())
        throw(~perm, "Sender is not this.");
    .tell("Goodbye.");
    disconnect();
.

method connect_guest_cmd
    arg com, com2, words;
    var syn, email, name, result;
    
    .perms(sender(), 'this);
    syn = "=> Syntax: 'connect guest <name> <email>' (type 'help' for more help)";
    
    // Get user name and password.
    words = explode(words);
    if (listlen(words) < 2)
        return .tell(syn);
    name = $list.to_string(sublist(words, 1, listlen(words) - 1));
    email = words[listlen(words)];
    result = $code.valid_email(email);
    if ((result[1]) != 'valid) {
        switch (result[1]) {
            case 'invalid:
                .tell("!  The given email address is not a legitimate address.");
                .tell("!  Specify both username and hostname (do not use brackets).");
                return;
            case 'invip, 'invhostname:
                .echo($string.wrap_line(((("The hostname \"" + (result[3])) + "\" is invalid, when in actuality you are connecting from \"") + ((addr == "-1") ? ip | addr)) + "\".  The server is not currently locking out invalid email addresses, although your connection has been noted (We do realize that some hosts may not function normally).", 79, "!  ", 1));
                $channels.announce('System, ((((((("Invalid Connection Email: " + email) + " <") + addr) + ":") + ip) + "> (") + name) + ")");
        }
    }
    catch any {
        user = $sys.create_user(name, 0, email, 'anonymous_class);
    } with handler {
        .tell(syn);
        switch (error()) {
            case ~duplicate:
                .tell(("!  The name " + toliteral(words[1])) + " is already in use.");
            default:
                .tell("!  There was a problem creating you:");
                .tell("!  => " + ((traceback()[1])[2]));
                .tell("!  If there is a problem contact: " + ($sys.get_system_email('login)));
        }
        // $sys.log(traceback());
        return;
    }
    
    // Log the user in.
    $sys.log((("GUEST: " + (words[1])) + " ") + (words[2]));
    user.connection_logged_in(addr, port);
.

method who_cmd
    arg com;
    var l;
    
    for l in ($code.generate_listing($user_db.connected()))
        .tell(l);
.

method help_cmd
    arg com;
    var l;
    
    .perms(sender(), 'this);
    for l in ($login_interface.connect_help())
        .tell(l);
.

Site Stats

Snippets: 1791
Codebases: 571