Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.82 KB | None | 0 0
  1. <?php
  2.  
  3.     class user {
  4.    
  5.         public $nick = '';
  6.         public $address = '';
  7.         public $network = '';
  8.         public $chans = array();
  9.         public $idle = 0;
  10.         public $login = '';
  11.         public $dead = FALSE;
  12.        
  13.        
  14.         public function __construct($network, $nick, $address, $chans) {
  15.             $this->network = $network;
  16.             $this->nick = $nick;
  17.             $this->address = $address;
  18.             $this->chans = (is_array($chans)) ? $chans : array($chans);
  19.             $this->idle = time();          
  20.         }
  21.        
  22.         public function join($chan) {
  23.             //  Adds a common channel (one shared with the bot) to the list.
  24.             if (!isset($this->chans[$chan])) {
  25.                 $this->chans[$chan] = '';
  26.             }
  27.         }
  28.        
  29.         public function part($chan) {
  30.             //  Removes a common channel from the list.
  31.             if (!isset($this->chans[$chan])) {
  32.                 unset($this->chans[$chan]);
  33.             }
  34.         }
  35.        
  36.         public function mode($chan, $mode) {
  37.             //  Updates the information for the user's status on the given channel (e.g., op, voice, etc).
  38.             if (substr($mode, 0, 1) == '+' && stripos($this->chans[$chan], $mode) === FALSE) {
  39.                 $this->chans[$chan] .= $mode;
  40.             }
  41.             elseif (substr($mode, 0, 1) == '-' && stripos($this->chans[$chan], $mode) !== FALSE) {
  42.                 $this->chans[$chan] = str_replace($mode, '', $this->chans[$chan]);
  43.             }
  44.         }
  45.        
  46.         public function idle() {
  47.             //  Returns total time idle in seconds, as the difference of the current timestamp and that of the user's last activity.
  48.             return (time() - $this->idle);
  49.         }
  50.        
  51.         public function login($user, $pass) {
  52.             //  Logs the user into the specificed account.
  53.             irc::db();
  54.             mysql_select_db('datassbot');
  55.             if ($qu = mysql_query('SELECT user, level FROM users WHERE network=\''. $this->network. '\' AND user=\''. $user '\' AND password=\''. md5($pass). '\'')) {
  56.                 $cur = mysql_fetch_array($qu);
  57.                 $this->login = $user;
  58.                 return 'You have successfully logged into your account '. irc::bold($cur['user']). '. Your access level is '. irc::bold($cur['level']). '.';
  59.             }
  60.             else {
  61.                 return 'Unknown username or bad password. Please try again.';
  62.             }
  63.         }
  64.        
  65.         public function logout() {
  66.             //  Logs the user out of their account.
  67.             if (!$this->login) {
  68.                 return 'You have not yet logged in.';
  69.             }
  70.             $t = $this->login;
  71.             $this->login = '';
  72.             return 'You have successfully logged out of '. irc::bold($t). '.';
  73.         }
  74.        
  75.         public function setpass($pass) {
  76.             //  Change the user's password.
  77.             if (!$this->login) {
  78.                 return 'You must first log in before changing your password.';
  79.             }
  80.             irc::db();
  81.             mysql_select_db('datassbot');
  82.             if (mysql_query('UPDATE users SET password=\'' mysql_real_escape_string(md5($pass)). '\' WHERE network=\''. $this->network.
  83.                 '\' AND user=\''. $this->login. '\'')) {
  84.                 return 'Your password has been successfully changed to '. irc::bold($pass). '. Please remember it for later use.';
  85.             }
  86.             else {
  87.                 return 'There was an error changing your password. Please try again.';
  88.             }
  89.         }
  90.        
  91.         public function auto($cmd, $host = '') {
  92.             //  Manage auto-login settings.
  93.             if (!$this->login) {
  94.                 return 'You must first log in before managing auto-login settings.';
  95.             }
  96.             irc::db();
  97.             mysql_select_db('datassbot');
  98.             switch ($cmd) {
  99.                 case 'set':
  100.                     if (mysql_query('UPDATE users SET auto=\'' mysql_real_escape_string($host). '\' WHERE network=\''. $this->network.
  101.                         '\' AND user=\''. $this->login. '\'')) {
  102.                         if ($host) {
  103.                             return 'You will now be automatically logged in to hosts matching '. irc::bold($host);
  104.                         }
  105.                         else {
  106.                             return 'Auto-login has been disabled for your account.';
  107.                         }
  108.                     }
  109.                     else {
  110.                         return 'There was an error changing your auto-login host. Please try again.';
  111.                     }
  112.                 break;
  113.                
  114.                 case 'view':
  115.                     if ($qu = mysql_query('SELECT auto FROM users WHERE network=\''. $this->network. '\' AND user=\''. $this->login. '\'')) {
  116.                         $cur = mysql_fetch_array($qu);
  117.                         if ($cur['auto']) {
  118.                             return 'Your account is automatically logged in to hosts matching '. irc::bold($cur['auto']);
  119.                         }
  120.                         else {
  121.                             return 'Auto-login is currently disabled for your account.';
  122.                         }
  123.                     }
  124.                     else {
  125.                         return 'There was an error retrieving your auto-login host. Please try again.';
  126.                     }
  127.                 break;
  128.                
  129.                 default:
  130.                     return 'Unknown auto-login command '. irc::bold($cmd). '. Please enter a valid option.';
  131.                 break;
  132.             }
  133.         }
  134.        
  135.         public function access() {
  136.             //  Returns the access level for this user.
  137.             if (!$this->login) {
  138.                 return -1;
  139.             }
  140.             irc::db();
  141.             mysql_select_db('datassbot');
  142.             $qu = mysql_query('SELECT level FROM users WHERE network=\''. $this->network. '\' AND user=\''. $this->login. '\'');
  143.             $cur = mysql_fetch_array($qu);
  144.             return $cur['level'];
  145.         }
  146.        
  147.         public function __toString() {
  148.             //  Conversion of the user object to a String yields the current nickname.
  149.             return $this->nick;
  150.         }
  151.        
  152.     }
  153. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement