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

📄 login.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.*//* vim: set expandtab tabstop=4 shiftwidth=4 *//*** Log in as "name" creature** Input: <login user="x" pass="x"/>* Ouput: <login ok="[0|1]" msg"x"/>** @param connection object  Reference to connection* @param user       object  Reference to user* @param character  object  Reference to character* @param command    array   Contains command received*/function command_login(&$connection, &$user, &$character, $command){    global $users;    try {        // Check if we are already logged as user        if(is_a($user, "user")) {            throw new exception("already logged as ".$user->get_login());        }        // Look for this user        $login = ($command["user"]);        $t_user = & $users->get_user_by_login($login);        // Is connected?        if(is_object($t_user) == TRUE) {            throw new exception("user already connected");        }        // Ok, load it        $t_user = & $users->load_user($login);        // Check password        if($command["password"] != $t_user->get_password()) {            throw new exception("bad password");        }        // Ok, all accepted. Link connection and add to global users array        $t_user->connection = & $connection;        $connection->user = & $t_user;        $result = $users->add_user($t_user);        // Update last_ip and last_connected        $last_ip        = $t_user->get_last_ip();        $last_connected = $t_user->get_last_connected();        $t_user->set_last_ip();        $t_user->set_last_connected();    } catch(exception $exception) {        $answer = array(                "ok"    => "0",                "user"  => $command["user"],                "msg"   => $exception->get_msg());        return($answer);    }    // Save    $users->save_user($t_user);    // Log    $msg = "Log in user >".$login;    log_msg($msg, "game", $connection);    // Notify the user    $answer = array (        "ok"             => "1",        "user"           => $login,        "last_ip"        => $last_ip,        "last_connected" => date("r", $last_connected),        "msg"            => "Please to meet you, $login");    return($answer);}/*** logout() will make the user to stop using his account** Input: <logout/>* Ouput: <logout ok="[0|1]" msg"x"/>** @param connection object  Reference to connection* @param user       object  Reference to user* @param character  object  Reference to character* @param command    array   Contains command received*/function command_logout(&$connection, &$user, &$character, $command){    global $users;    // Save it before deletion?    try {        $result = $users->del_user($user);    } catch(exception $exception) {        $answer = array(                "ok"    => "0",                "msg"   => $exception->get_msg());            return($answer);    }    // Log    $msg = "Log out user >".$user->get_login();    log_msg($msg, "game", $connection);    // Notify the user    $answer = array(        "ok"    => "1",        "msg"   => "See you soon, ".$user->get_login());    return($answer);}/*** Get data from $login user** Maybe we could need to restrict this one. Maybe a version for admins* and a version for logged ?** @param connection object  Reference to connection* @param user       object  Reference to user* @param character  object  Reference to character* @param command    array   Contains command received*/function command_get_user(&$connection, &$user, &$character, $command){    if(!empty($command["login"])) {        // Check permissions        if($user->access < user_list::L_ADMIN) {            $answer = array(                "xml_name"  => "access_denied",                "command"   => $command["xml_name"]);            return($answer);        }        try {            // We are admins and we are looking for some user ...            global $users;            $login = $command["login"];            $t_user = & $users->get_user_by_login($login);            $t_user = & load_user($login);        } catch(exception $exception) {            $answer = array(                "ok"    => "0",                "login" => $login,                "msg"   => $exception->get_msg());            return($answer);        }    } else {        $t_user = &$user;    }    // Ok, we are sure that $t_user contains a reference to the user    // we are looking for    $answer = array(        "login"     => $t_user->get_login(),        "password"  => $t_user->get_password(),        "access"    => $t_user->get_access(),        "language"  => $t_user->get_language(),        "email"     => $t_user->get_email(),        "last_ip"   => $t_user->get_last_ip(),        "last_connected" => $t_user->get_last_connected());    return($answer);}/*** Modify some data of the user** Update the user data** @param connection object  Reference to connection* @param user       object  Reference to user* @param character  object  Reference to character* @param command    array   Contains command received*/function command_modify_user(&$connection, &$user, &$character, $command){    if(!empty($command["login"])) {        // Check permissions        if($user->access < user_list::L_ADMIN) {            $answer = array(                "xml_name"  => "access_denied",                "command"   => $command["xml_name"]);            return($answer);        }        // We are admins and we are looking for some user ...        global $users;        try {            $login = $command["login"];            $t_user = & $users->get_connected_user($login);        } catch(exception $exception) {            $answer = array(                "ok"    => "0",                "login" => $login,                "msg"   => $exception->get_msg());            return($answer);        }    } else {        $t_user = &$user;        $login = $user->get_login();    }    // erase xml_name from the array and look if we have anytging to do    unset($command["xml_name"]);    if(count($command) < 1) {        $answer = array (            "ok"    => "0",            "login" => $login,            "msg"   => "no arguments supplied");        return($answer);    }    $bad_arg = '';    foreach($command as $key=>$value) {        switch($key) {        case "password":            if($t_user->set_password($command[$key]) != TRUE) {                $bad_arg = "password";            }            break;        case "access":            $old_access = $command["access"];            if($t_user->set_access($command[$key]) != TRUE) {                $bad_arg = "access";            }            if($old_access > $user->access) {                $t_user->set_access($old_access);                $answer = array (                    "ok"    => "0",                    "login" => $login,                    "msg"   => "you cannot increase beyond your access");                return($answer);            }            break;        case "language":            if($t_user->set_language($command[$key]) != TRUE) {                $bad_arg = "language";            }            break;        case "email":            if($t_user->set_email($command[$key]) != TRUE) {                $bad_arg = "email";            }            break;        default:            $bad_arg = $key;            break;        }    }    if(!empty($bad_arg)) {        $answer = array(            "ok"    => "0",            "login" => $login,            "msg"   => "bad $bad_arg supplied");        return($answer);    }    // ok all    $answer = array(        "ok"    => "1",        "login" => $login,        "msg"   => "user modified successfully");    return($answer);}/*** Saves all data related to user** @param connection object  Reference to connection* @param user       object  Reference to user* @param character  object  Reference to character* @param command    array   Contains command received*/function command_save_user(&$connection, &$user, &$character, $command){    global $users;    try {        $result = $users->save_user($user);    } catch(exception $exception) {        $answer = array(            "ok"    => "0",            "msg"   => $exception->get_msg());        return($answer);    }    $answer = array(        "ok"    => "1",        "msg"   => "user saved successfully");    return($answer);}?>

⌨️ 快捷键说明

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