⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_user.php

📁 一个基于web的rpg游戏源代码
💻 PHP
字号:
<?php/*** Netlands World Server is the coordinator of the VR in the Netlands Project* Copyright (C) 2002 Ricard Pillosu* * This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.* * This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.* * You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*//*** Manages logins/passwd/etc...** They will be stored in files just before any connection wants to "login" in* the System.** @see connection** @version $Id: class_user.php,v 1.4 2002/09/29 02:31:51 doneval Exp $* @author Ricard Pillosu <ricardpillosu@dorna.com>* @copyright Ricard Pillosu 2002* @since Tue, 13 Aug 2002 21:11:48 +0200*/class user {   /**    * @var string    */    private $login;    /**    * @var string    */    private $password;    /**    * @var string    */    private $email;    /**    * @var string    */    private $language;    /**    * @var int    */    private $access;    /**    * @var array List of references to characters he can control    */    var $character_list;    /**    * @var object References to the active TCP connection    */    var $connection;    /**    * @var string Stores last_ip used    */    var $last_ip;    /**    * @var string Stores timestamp of last time onnected    */    var $last_connected;    /**    * @var string Stores last error    */    private $last_error;    function __construct() {        global $users;        // The rest get values by default        $this->connection = NULL;        $this->character_list = array();        $this->language = $users->languages["default"];    }    function __destruct() {    }    function get_login() {        return($this->login);    }    function set_login($string) {        if($this->is_login($string) != TRUE) {            return(FALSE);        }        $this->login = $string;        return(TRUE);    }    function get_password() {        return($this->password);    }    function set_password($string) {        // The same rules from the login are applied to the password        if($this->is_login($string) != TRUE) {            return(FALSE);        }        // Maybe crypt to md5 here ?        $this->password = $string;        return(TRUE);    }        function get_access() {        return($this->access);    }    function set_access($string) {        // Access (100, 200, 300, ...)        $expr = "^[0-9]{3}$";        if(!ereg($expr, $string)) {            return(FALSE);        }        $this->access = $string;        return(TRUE);    }    function get_email() {        return($this->email);    }        function set_email($string) {        // Email Filter        $expr = "^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$";        if(!eregi($expr, $string)) { // Maybe PCRE better?            return(FALSE);        }        $this->email = $string;        return(TRUE);    }        function get_language() {        return($this->language);    }    function set_language($string) {        global $users;        // Language Filter        if(!in_array($string, $users->languages)) {            return(FALSE);        }        // Maybe crypt to md5 here ?        $this->language = $string;        return(TRUE);    }        function get_last_ip() {        return($this->last_ip);    }    function set_last_ip($string = "") {        // No argument        if(empty($string)) {            if(is_a($this->connection , "connection") == FALSE) {                // return TRUE ... here passess most newly created users                $this->last_ip = "0.0.0.0";                return(TRUE);            }            $this->last_ip = $this->connection->remote_ip;            return(TRUE);        }        // Filter #.#.#.#        $expr = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$";        if(!ereg($expr, $string)) {            return(FALSE);        }        $this->last_ip = $string;        return(TRUE);    }    function get_last_connected() {        return($this->last_connected);    }    function set_last_connected($string = "") {        if(empty($string)) {            $this->last_connected = time();            return(TRUE);        }        // Is number ?        if(!is_numeric($string)) {            return(FALSE);        }        // This (1030569466) is from Wed, 28 Aug 2002 23:19:20 +0200        // I'm developing right now, I won't belive that anyone made        // a user before :)        if($string < 1030569466) {            return(FALSE);        }        $this->last_connected = $string;        return(TRUE);    }    /**    * Filters logins & passwords strings    */    function is_login($string) {        // Maybe PCRE here?        $expr = "^[a-z0-9\.-_]{3,16}$";        if(!ereg($expr, $string)) {            return(FALSE);        }        return(TRUE);    }    function set_data($data) {        global $users;        // Fill with default values        $default_values = array(                "login"             =>  "", // won't accept                "password"          =>  "", // won't accept                "access"            =>  "200",                "language"          =>  $users->languages["default"],                "email"             =>  "nobody@mail.com",                "last_ip"           =>  "",                "last_connected"    =>  "");        $values = array_merge($default_values, $data);        // go        if($this->set_login($values['login']) != TRUE) {            $this->last_error = "invalid login";            return(FALSE);        }        if($this->set_password($values['password']) != TRUE) {            $this->last_error = "invalid password";            return(FALSE);        }        if($this->set_access($values['access']) != TRUE) {            $this->last_error = "invalid access";            return(FALSE);        }        if($this->set_language($values['language']) != TRUE) {            $this->last_error = "invalid language";            return(FALSE);        }        if($this->set_email($values['email']) != TRUE) {            $this->last_error = "invalid email";            return(FALSE);        }        if($this->set_last_ip($values['last_ip']) != TRUE) {            $this->last_error = "invalid last ip";            return(FALSE);        }        if($this->set_last_connected($values['last_connected']) != TRUE) {            $this->last_error = "invalid last connected";            return(FALSE);        }        // Ok all        $this->flush_error();        return(TRUE);    }    function flush_error() {        $this->last_error = "Success";        return(TRUE);    }    function get_last_error() {        return($this->last_error);    }    /**    * Simply add a reference to a new entity    *    * @param object $entity    */    function add_character(&$char) {        if(is_a($char, "character") !== TRUE) {            $this->last_error = "character not a valid character";            throw new exception($this->last_error, debug_backtrace());            return(FALSE);        }        $key = $char->get_key();        $this->character_list["$key"] = & $char;        // Fill character $user prop        $char->user = & $this;        $this->flush_error();        return(TRUE);    }    /**    * Delete a reference to a charcater    *    * @param object $entity    */    function del_character(&$char) {        if(is_a($char, "character") !== TRUE) {            $this->last_error = "char not a valid character";                throw new exception($this->last_error, debug_backtrace());            return(FALSE);        }        $key = $char->get_key();        if(isset($this->character_list["$key"]) != TRUE) {            $this->last_error = "character not found";                throw new exception($this->last_error, debug_backtrace());            return(FALSE);        }        unset($this->character_list["$key"]);         // Empty char property pointing to us        $char->user = NULL;        $this->flush_error();        return(TRUE);    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -