Login system
Posted by `Slipknot-
Tuesday, April 12, 2005
Description: Login system using hash tables.


alias loggedon {
  if ($1 !isnum) {
    if ($prop == account) return $hget(users,$address($1,2))
    elseif ($prop == access) return $hget($hget(users,$address($1,2)),access)
    else return $iif($hfind(users,$address($1,2),0,w),$true,$false)
  }
  elseif ($1 isnum) {
    if (!$prop) return $hget(users,$1).item
    elseif ($prop == account) return $hget(users,$1).data
    elseif ($prop == access) return $hget($hget(users,$1).data,access)
  }
}
on *:text:register*:?: {
  if ($loggedon($nick)) .notice $nick [^B]Error![^B] You are already logged on.
  elseif ($hget($+(acc_,$2))) .notice $nick [^B]Error![^B] $2 is already an account.
  elseif ($0 != 4) .notice $nick [^B]Error![^B] Insufficient parameters. Please use /msg $me register account password email
  else {
    var %reg ^[_\.0-9a-zA-Z]+@([.-0-9a-zA-Z][.-0-9a-zA-Z]+\.)+[a-zA-Z]{2,3}$
    if (!$regex($4,%reg)) .notice $nick [^B]Error![^B] Please use a proper email.
    else {
      hmake $+(acc_,$2) 10
      hadd $+(acc_,$2) Password $encode($3,m)
      hadd $+(acc_,$2) Email $4
      hadd $+(acc_,$2) Hostmask $mask($fulladdress,2)
      hadd $+(acc_,$2) Ctime $ctime
      hadd $+(acc_,$2) Nick $nick
      hadd $+(acc_,$2) access default
      hadd $+(acc_,$2) hideemail 0
      hadd -m users $mask($fulladdress,2) $+(acc_,$2)
      .notice $nick Registration successful. You have automatically been logged on to account [^B] $+ $2 $+ [^B].
    }
  }
}
on *:text:unregister*:?: {
  if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Please login before trying to access that command.
  elseif ($loggedon($nick).access != leader) .notice $nick [^B]Error![^B] You lack sufficient access to use that command.
  elseif ($0 != 2) .notice $nick [^B]Error![^B] Insufficient parameters. Please use /msg $me unregister nick|*account
  elseif ($left($2,1) != $chr(42)) && (!$loggedon($2)) .notice $nick [^B]Error![^B] $2 is not logged on. Please use *account.
  else {
    if ($left($2,1) != $chr(42)) && (!$loggedon($2)) .notice $nick [^B]Error![^B]: $2 is not logged on. Please use *account.
    elseif ($left($2,1) == $chr(42)) && (!$hget($+(acc_,$right($2,-1)))) .notice $nick [^B]Error![^B] Account $right($2,-1) does not exist.
    else {
      if ($left($2,1) == $chr(42)) {
        var %nick. [ $+ [ $2 ] ] $hget($+(acc_,$right($2,-1)),nick)
        if ($hfind(users,$+(acc_,$right($2,-1)),1).data) .notice %nick. [ $+ [ $2 ] ] Your account ( $+ $right($2,-1) $+ ) has been deleted by [^B] $+ $nick $+ [^B]. If you think the deletion was a mistake, please msg $nick $+ .
        .hfree $+(acc_,$right($2,-1))
        .remove $+(databases\,$+(acc_,$right($2,-1)),.dbu)
        .notice $nick Account [^B] $+ $right($2,-1) $+ [^B] has been deleted.
        if ($hfind(users,$+(acc_,$right($2,-1)),0).data) .hdel users $hfind(users,$+(acc_,$right($2,-1)),1).data
      }
      elseif ($left($2,1) != $chr(42)) {
        .var %account. [ $+ [ $2 ] ] $right($loggedon($2).account,-4)
        .hfree $loggedon($2).account
        .remove $+(databases\,$loggedon($2).account,.dbu)
        if ($loggedon($2)) .notice $2 Your account ( $+ %account. [ $+ [ $2 ] ] $+ ) has been deleted by [^B] $+ $nick $+ [^B]. If you think the deletion was a mistake, please msg $nick $+ .
        .notice $nick Account [^B] $+ %account. [ $+ [ $2 ] ] $+ [^B] has been deleted.
        if ($hfind(users,$+(acc_,%account. [ $+ [ $2 ] ]),0).data) .hdel users $hfind(users,$+(acc_,%account. [ $+ [ $2 ] ]),1).data
      }
    }
  }
}
on *:text:auth*:?: {
  if ($loggedon($nick)) .notice $nick [^B]Error![^B] You are already logged on.
  elseif ($0 != 3) .notice $nick [^B]Error![^B] Insufficient parameters. Please use /msg $me auth account password
  elseif (!$hget($+(acc_,$2))) .notice $nick [^B]Error![^B] That account does not exist.
  elseif ($3 != $decode($hget($+(acc_,$2),password),m)) .notice $nick [^B]Error![^B] The password you supplied does not match the one I have stored.
  else {
    if ($mask($fulladdress,2) != $hget($+(acc_,$2),Hostmask)) hadd $+(acc_,$2) Hostmask $mask($fulladdress,2)
    elseif ($nick != $hget($+(acc_,$2),Nick)) hadd $+(acc_,$2) Nick $nick
    hadd $+(acc_,$2) Ctime $ctime
    hadd -m users $mask($fulladdress,2) $+(acc_,$2)
    .notice $nick Welcome back, $nick $+ .
  }
}
on *:text:users:?: {
  .notice $nick Accounts on [^B] $+ $me $+ [^B]:
  var %i 1
  var %accounts 0
  while ($hget(%i)) {
    if (acc_* iswm $hget(%i)) {
      .notice $nick $remove($hget(%i),acc_) ( $+ $hget(%i,access) $+ )
      inc %accounts
    }
    inc %i
  }
  .notice $nick Totalling [^B] $+ %accounts $+ [^B] $iif(%accounts == 1,account,accounts) $+ .
}
on *:text:accountinfo*:?: {
  if (!$2) && ($loggedon($nick)) {
    .notice $nick Account info for [^B] $+ $nick $+ [^B]:
    .notice $nick [^B]Account[^B]: $right($loggedon($nick).account,-4)
    .notice $nick [^B]Password[^B]: $decode($hget($loggedon($nick).account,password),m)
    .notice $nick [^B]Email[^B]: $hget($loggedon($nick).account,email) ([^B]Hide email[^B]: $hget($loggedon($nick).account,hideemail) $+ )
    .notice $nick [^B]Access[^B]: $loggedon($nick).access
    .notice $nick [^B]Last Used Hostmask[^B]: $hget($loggedon($nick).account,hostmask)
    .notice $nick [^B]Logged On For[^B]: $iif(!$hget($loggedon($nick).account,ctime),$+($chr(40),not logged on,$chr(41)),$duration($calc($ctime - $hget($loggedon($nick).account,ctime))))
    .notice $nick [^B]Infoline[^B]: $iif($hget($loggedon($nick).account,info),$hget($loggedon($nick).account,info),$+($chr(40),none,$chr(41))))
  }
  elseif (!$2) && (!$loggedon($nick)) .notice $nick [^B]Error![^B] You are not logged on.
  elseif ($left($2,1) == $chr(42)) {
    if ($hget($+(acc_,$right($2,-1)))) {
      .notice $nick Account info for [^B] $+ $right($2,-1) $+ [^B]:
      .notice $nick [^B]Account[^B]: $right($2,-1)
      if ($loggedon($nick).account == $+(acc_,$right($2,-1))) .notice $nick [^B]Password[^B]: $decode($hget($+(acc_,$right($2,-1)),password),m)
      if ($loggedon($nick).account == $+(acc_,$right($2,-1))) || (!$hget($+(acc_,$right($2,-1)),hideemail)) .notice $nick [^B]Email[^B]: $hget($+(acc_,$right($2,-1)),email) $iif($loggedon($nick).account == $+(acc_,$right($2,-1)),$+($chr(40),[^B]Hide email[^B]: $hget($loggedon($nick).account,hideemail),$chr(41)))
      .notice $nick [^B]Access[^B]: $hget($+(acc_,$right($2,-1)),access)
      .notice $nick [^B]Last Used Hostmask[^B]: $hget($+(acc_,$right($2,-1)),hostmask)
      .notice $nick [^B]Logged On For[^B]: $iif(!$hget($+(acc_,$right($2,-1)),ctime),$+($chr(40),not logged on,$chr(41)),$duration($calc($ctime - $hget($+(acc_,$right($2,-1)),ctime))))
      .notice $nick [^B]Infoline[^B]: $iif($hget($+(acc_,$right($2,-1)),info),$hget($+(acc_,$right($2,-1)),info),$+($chr(40),none,$chr(41)))
    }
    elseif (!$hget($+(acc_,$right($2,-1)))) .notice $nick [^B]Error![^B] Unknown account. ( $+ $right($2,-1) $+ )
  }
  elseif ($left($2,1) != $chr(42)) {
    if (!$loggedon($2)) .notice $nick [^B]Error![^B] $2 is not logged on.
    elseif ($loggedon($2)) {
      .notice $nick Account info for [^B] $+ $2 $+ [^B]:
      .notice $nick [^B]Account[^B]: $right($loggedon($2).account,-4)
      if ($nick == $2) .notice $nick [^B]Email[^B]: $hget($loggedon($2).account,email) ([^B]Hide email[^B]: $hget($loggedon($2).account,hideemail) $+ )
      elseif ($nick != $2) && (!$hget($loggedon($2).account,hideemail)) .notice $nick [^B]Email[^B]: $hget($loggedon($2).account,email)
      .notice $nick [^B]Access[^B]: $loggedon($2).access
      .notice $nick [^B]Last Used Hostmask[^B]: $hget($loggedon($2).account,hostmask)
      .notice $nick [^B]Logged On For[^B]: $iif(!$hget($loggedon($2).account,ctime),$+($chr(40),not logged on,$chr(41)),$duration($calc($ctime - $hget($loggedon($2).account,ctime))))
      .notice $nick [^B]Infoline[^B]: $iif($hget($loggedon($2).account,info),$hget($loggedon($2).account,info),$+($chr(40),none,$chr(41)))
    }
  }
}


on *:text:access*:?: {
  if (!$2) {
    if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Log in or specify a nickname/account to check.
    elseif ($loggedon($nick)) {
      .notice $nick $nick has the access level [^B] $+ $loggedon($nick).access $+ [^B].
    }
  }
  elseif ($2) {
    if ($left($2,1) == $chr(42)) {
      if ($hget($+(acc_,$right($2,-1)))) {
        .notice $nick $right($2,-1) has the access level [^B] $+ $loggedon($nick).access $+ [^B].
      }
      elseif (!$hget($+(acc_,$right($2,-1)))) .notice $nick [^B]Error![^B] Account doesn't exist. ( $+ $right($2,-1) $+ )
    }
    else {
      if (!$loggedon($2)) .notice $nick [^B]Error![^B] $2 is not logged on. Please use *account.
      elseif ($loggedon($2)) {
        .notice $nick $2 ( $+ $right($loggedon($2).account,-4) $+ ) has the access level [^B] $+ $loggedon($2).access $+ [^B].
      }
    }
  }
}
on *:text:-access*:#: {
  if (!$2) {
    if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Log in or specify a nickname/account to check.
    elseif ($loggedon($nick)) {
      .notice $nick $nick has the access level [^B] $+ $loggedon($nick).access $+ [^B].
    }
  }
  elseif ($2) {
    if ($left($2,1) == $chr(42)) {
      if ($hget($+(acc_,$right($2,-1)))) {
        .notice $nick $right($2,-1) has the access level [^B] $+ $loggedon($nick).access $+ [^B].
      }
      elseif (!$hget($+(acc_,$right($2,-1)))) .notice $nick [^B]Error![^B] Account doesn't exist. ( $+ $right($2,-1) $+ )
    }
    else {
      if (!$loggedon($2)) .notice $nick [^B]Error![^B] $2 is not logged on. Please use *account.
      elseif ($loggedon($2)) {
        .notice $nick $2 ( $+ $right($loggedon($2).account,-4) $+ ) has the access level [^B] $+ $loggedon($2).access $+ [^B].
      }
    }
  }
}
on *:text:clvl*:?: {
  if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Please login before trying to access that command.
  elseif (!$regex($loggedon($nick).access,(leader|coleader))) .notice $nick [^B]Error![^B] You lack sufficient access to use that command.
  elseif ($0 != 3) .notice $nick [^B]Error![^B] Insufficient parameters. Please use /msg $me clvl nick|*account newlevel
  elseif ($left($2,1) != $chr(42)) && (!$loggedon($2)) .notice $nick [^B]Error![^B] $2 is not logged on. Please use *account.
  elseif (!$hget($iif($left($2,1) == $chr(42),$+(acc_,$right($2,-1)),$loggedon($2).account))) .notice $nick [^B]Error![^B]: Account $2 doesn't exist.
  elseif ($loggedon($nick).access == coleader) && ($hget($iif($left($2,-1) == $chr(42),$+(acc_,$right($2,-1)),$loggedon($2).account),access) == leader) .notice $nick [^B]Error![^B] You cannot clvl the leader!
  else {
    if ($left($2,1) == $chr(42)) {
      if ($hget($+(acc_,$right($2,-1)),access) == $3-) .notice $nick [^B]Error![^B] $2 already has the access level [^B] $+ $3- $+ [^B].
      elseif ($hget($+(acc_,$right($2,-1)),access) != $3-) {
        var %access. [ $+ [ $2 ] ] $hget($+(acc_,$right($2,-1)),access)
        hadd $+(acc_,$right($2,-1)) access $3-
        .notice $nick $+($2,'s) access level is now [^B] $+ $3- $+ [^B]. (It was: %access. [ $+ [ $2 ] ] $+ )
      }
    }
    else {
      if ($loggedon($2).access == $3-) .notice $nick [^B]Error![^B] $2 already has the access level [^B] $+ $3- $+ [^B].
      else {
        var %access. [ $+ [ $2 ] ] $loggedon($2).access
        hadd $loggedon($2).account access $3-
        .notice $nick $+($2,'s) access level is now [^B] $+ $3- $+ [^B]. (It was: %access. [ $+ [ $2 ] ])
      }
    }
  }
}
on *:text:uset*:?: {
  if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Please login before trying to access that command.
  else {
    if (!$2) {
      .notice $nick Possible user settings:
      .notice $nick /msg $me uset email <email@host.com> (Sets your email)
      .notice $nick /msg $me uset password <password> (Sets your password)
      .notice $nick /msg $me uset hideemail <1 or 0> (Hide your email from others with 1, don't hide it with 0)
      .notice $nick /msg $me uset info <info> (Set your infoline)
    }
    elseif ($0 == 3) {
      if ($2 == hideemail) {
        if ($3 == $hget($loggedon($nick).account,hideemail)) .notice $nick The setting [^B]hide email[^B] is already set to $3 $+ .
        elseif ($3 !isnum 0-1) .notice $nick [^B]Error![^B] Please use [^B]1[^B] or [^B]0[^B] as the setting value. (eg. /msg $me uset hideemail 1)
        else {
          hadd $loggedon($nick).account hideemail $3
          .notice $nick The user setting [^B]hide email[^B] is now set to $3 $+ .
        }
      }
      elseif ($2 == info) {
        if ($3- == $hget($loggedon($nick).account,info)) .notice $nick The setting [^B]infoline[^B] is already set to $3- $+ .
        else {
          hadd $loggedon($nick).account info $3-
          .notice $nick The user setting [^B]infoline[^B] is now set to $3- $+ .
        }
      }
      elseif ($2 == email) {
        var %reg ^[_\.0-9a-zA-Z]+@([0-9a-zA-Z][0-9a-zA-Z]+\.)+[a-zA-Z]{2,3}$
        if (!$regex($3,%reg)) .notice $nick [^B]Error![^B] Please insert a correct email. (email@host.com)
        elseif ($3 == $hget($loggedon($nick).account,email)) .notice $nick The setting [^B]email[^B] is already set to $3 $+ .
        else {
          hadd $loggedon($nick).account email $3
          .notice $nick The user setting [^B]email[^B] is now set to $3 $+ .
        }
      }
      elseif ($2 == password) {
        if ($encode($3,m) == $hget($loggedon($nick).account,password)) .notice $nick [^B]Error![^B] The user setting password is already set to $3 $+ .
        else {
          hadd $loggedon($nick).account password $encode($3,m)
          .notice $nick The uset setting [^B]password[^B] is now set to $3 $+ .
        }
      }
    }
  }
}
on *:text:forceleader:?: {
  if (!$loggedon($nick)) .notice $nick [^B]Error![^B] Please login before trying to access that command.
  elseif ($loggedon($nick).access == leader) .notice $nick [^B]Error![^B] You are already the leader.
  elseif ($loggedon($nick)) && ($loggedon($nick).access != leader) {
    var %i 1, %i2
    while ($hget(%i)) {
      if (acc_* iswm $hget(%i)) && ($hfind(%i,leader,0).data) inc %i2
      inc %i
    }
    if (%i2 >= 1) .notice $nick [^B]Error![^B] There is already a leader.
    elseif (!%i2) {
      .notice $nick Success! You are now a leader.
      hadd $loggedon($nick).account access leader
    }
  }
}
on *:nick: {
  if ($loggedon($nick)) hadd $loggedon($nick).account nick $newnick
}
on *:quit: {
  if ($loggedon($nick)) {
    hdel $loggedon($nick).account ctime
    hdel users $mask($fulladdress,2)
  }
}


Yes a lot of the code could be cleaned up.
Yes the length of the script could probably be cut in half without losing any features.
No this will not happen.

Add the script, then create an account with a different irc. Then do /msg botname forceleader.

Commands are:

register account pass email
auth account password
unregister account
accountinfo [nick|*account]
clvl nick|*account newlevel
users
access [nick|*account]
-access [nick|*account] (in channel)
uset <setting> <value> (/msg botname uset for a list of user settings)
I need help.
Posted by Zoiut
Saturday, April 15, 2006 10:30am PDT
How can you save the hash tables, everytime I turn IRC off it deletes all my users.
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world