Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class user {
- public $nick = '';
- public $address = '';
- public $network = '';
- public $chans = array();
- public $idle = 0;
- public $login = '';
- public $dead = FALSE;
- public function __construct($network, $nick, $address, $chans) {
- $this->network = $network;
- $this->nick = $nick;
- $this->address = $address;
- $this->chans = (is_array($chans)) ? $chans : array($chans);
- $this->idle = time();
- }
- public function join($chan) {
- // Adds a common channel (one shared with the bot) to the list.
- if (!isset($this->chans[$chan])) {
- $this->chans[$chan] = '';
- }
- }
- public function part($chan) {
- // Removes a common channel from the list.
- if (!isset($this->chans[$chan])) {
- unset($this->chans[$chan]);
- }
- }
- public function mode($chan, $mode) {
- // Updates the information for the user's status on the given channel (e.g., op, voice, etc).
- if (substr($mode, 0, 1) == '+' && stripos($this->chans[$chan], $mode) === FALSE) {
- $this->chans[$chan] .= $mode;
- }
- elseif (substr($mode, 0, 1) == '-' && stripos($this->chans[$chan], $mode) !== FALSE) {
- $this->chans[$chan] = str_replace($mode, '', $this->chans[$chan]);
- }
- }
- public function idle() {
- // Returns total time idle in seconds, as the difference of the current timestamp and that of the user's last activity.
- return (time() - $this->idle);
- }
- public function login($user, $pass) {
- // Logs the user into the specificed account.
- irc::db();
- mysql_select_db('datassbot');
- if ($qu = mysql_query('SELECT user, level FROM users WHERE network=\''. $this->network. '\' AND user=\''. $user '\' AND password=\''. md5($pass). '\'')) {
- $cur = mysql_fetch_array($qu);
- $this->login = $user;
- return 'You have successfully logged into your account '. irc::bold($cur['user']). '. Your access level is '. irc::bold($cur['level']). '.';
- }
- else {
- return 'Unknown username or bad password. Please try again.';
- }
- }
- public function logout() {
- // Logs the user out of their account.
- if (!$this->login) {
- return 'You have not yet logged in.';
- }
- $t = $this->login;
- $this->login = '';
- return 'You have successfully logged out of '. irc::bold($t). '.';
- }
- public function setpass($pass) {
- // Change the user's password.
- if (!$this->login) {
- return 'You must first log in before changing your password.';
- }
- irc::db();
- mysql_select_db('datassbot');
- if (mysql_query('UPDATE users SET password=\'' mysql_real_escape_string(md5($pass)). '\' WHERE network=\''. $this->network.
- '\' AND user=\''. $this->login. '\'')) {
- return 'Your password has been successfully changed to '. irc::bold($pass). '. Please remember it for later use.';
- }
- else {
- return 'There was an error changing your password. Please try again.';
- }
- }
- public function auto($cmd, $host = '') {
- // Manage auto-login settings.
- if (!$this->login) {
- return 'You must first log in before managing auto-login settings.';
- }
- irc::db();
- mysql_select_db('datassbot');
- switch ($cmd) {
- case 'set':
- if (mysql_query('UPDATE users SET auto=\'' mysql_real_escape_string($host). '\' WHERE network=\''. $this->network.
- '\' AND user=\''. $this->login. '\'')) {
- if ($host) {
- return 'You will now be automatically logged in to hosts matching '. irc::bold($host);
- }
- else {
- return 'Auto-login has been disabled for your account.';
- }
- }
- else {
- return 'There was an error changing your auto-login host. Please try again.';
- }
- break;
- case 'view':
- if ($qu = mysql_query('SELECT auto FROM users WHERE network=\''. $this->network. '\' AND user=\''. $this->login. '\'')) {
- $cur = mysql_fetch_array($qu);
- if ($cur['auto']) {
- return 'Your account is automatically logged in to hosts matching '. irc::bold($cur['auto']);
- }
- else {
- return 'Auto-login is currently disabled for your account.';
- }
- }
- else {
- return 'There was an error retrieving your auto-login host. Please try again.';
- }
- break;
- default:
- return 'Unknown auto-login command '. irc::bold($cmd). '. Please enter a valid option.';
- break;
- }
- }
- public function access() {
- // Returns the access level for this user.
- if (!$this->login) {
- return -1;
- }
- irc::db();
- mysql_select_db('datassbot');
- $qu = mysql_query('SELECT level FROM users WHERE network=\''. $this->network. '\' AND user=\''. $this->login. '\'');
- $cur = mysql_fetch_array($qu);
- return $cur['level'];
- }
- public function __toString() {
- // Conversion of the user object to a String yields the current nickname.
- return $this->nick;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement