📄 create_user.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 *//*** create user** Will create a new user. Simply create the instance of the class,* then save it** @param connection object Reference to connection* @param user object Reference to the user* @param character object Reference to character* @param command array Contains command received*/function command_create_user(&$connection, &$user, &$character, $command){ global $users; extract($command, EXTR_SKIP); // Check if user already exists $result = $users->get_user_by_login($login, FALSE); if($result != FALSE) { $answer = array( "ok" => "0", "login" => $login, "msg" => "user already exists"); return($answer); } try { // Try to create the user unset($command["xml_name"]); $t_user = $users->create_user($command); // Ok, now save it to disk $result = $users->save_user($t_user); } catch(exception $exception) { $answer = array( "ok" => "0", "login" => $login, "msg" => $exception->get_msg()); return($answer); } // Log $msg = "Created new user >$login"; log_msg($msg, "game", $connection); // Notify the user $answer = array( "ok" => "1", "login" => $login, "msg" => "user ".$login." created successfully"); return($answer);}/*** Drop a user** Deletes a user from the database. Only if the user is not connected** @param connection object Reference to connection* @param user object Reference to the user* @param character object Reference to character* @param command array Contains command received*/function command_drop_user(&$connection, &$user, &$character, $command){ global $users; $login = $command["login"]; try { // Check if user exists & is connected $result = $users->get_user_by_login($login); if(is_object($result) == TRUE) { throw new exception("cannot drop connected users"); } // now check password $t_user = $users->load_user($login); if($command['password'] != $t_user->get_password()) { throw new exception("bad password"); } // Ok, all check verified $result = $users->destroy_user($login); } catch(exception $exception) { $answer = array( "ok" => "0", "login" => $login, "msg" => $exception->get_msg()); return($answer); } // Log $msg = "Destroyed user >$login"; log_msg($msg, "game", $connection); // Notify the user $answer = array( "ok" => "1", "login" => $login, "msg" => "user $login removed euccessfully"); return($answer);}/*** Link a character with a user** Will create a cross-reference from user to his characters** @param connection object Reference to connection* @param user object Reference to the user* @param character object Reference to character* @param command array Contains command received*/function command_link_character_to_user(&$connection, &$user, &$character, $command){ // Right now, we will require the user to be connected. Maybe later could // be interesting to allow it when the user is not logged. global $users, $entities; // Look for a reference to the user $login = $command['login']; try { $t_user = $users->get_user_by_login($login); // Ok, we have the user. Go for the character $character = & $entities->get_entity($command["character"]); // Save a reference to the user that is controlling the character // right now $old_login = $character->user; $old_user = $users->get_user_by_login($old_login); // Do the link $result = $users->link_character_to_user($character, $t_user); } catch(exception $exception) { $answer = array( "ok" => "0", "login" => $login, "character" => $command["character"], "msg" => $exception->get_msg()); return($answer); } // Message old user that he is losing control of character X $c_name = $character->game_vars['name']; if($old_user == TRUE) { $answer = array( "ok" => "0", "character" => $character->key, "msg" => "you lost control of $c_name"); $data = get_xml_from_array($answer, "link_character_to_user"); write_data_to_socket($old_user->connection, $data); } // Message user that he gains control of character X $answer = array( "ok" => "1", "character" => $character->key, "msg" => "you gain control of $c_name"); $data = get_xml_from_array($answer, "link_character_to_user"); write_data_to_socket($t_user->connection, $data); // Log $msg = "User >".$t_user->login."< linked with character >".$c_name; log_msg($msg, "game", $connection); // OK all! $answer = array( "ok" => "1", "msg" => "now ".$c_name." is controlled by ".$t_user->login); return($answer);}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -