character.php

来自「一个基于web的rpg游戏源代码」· PHP 代码 · 共 157 行

PHP
157
字号
<?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 *//*** Shows characters that user is using right now** Input: <character_list />* Ouput: <character_list .../>** @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_list_character(&$connection, &$user, &$character, $command){    // loop char list and stores id and name    $character_list = array();    foreach(array_keys($user->character_list) as $key) {        $character_list[] = array(                "xml_name"  => "character",                "id"        => $user->character_list[$key]->key,                "name"      => $user->character_list[$key]->game_vars['name']);    }    $character_list[0]["_xml_name"] = $command["xml_name"];    return($character_list);}/*** Create new character** Input: <create_character />* Ouput: <create_character .../>** @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_create_character(&$connection, &$user, &$character, $command){    global $entities, $users;    $name = $command["name"];    try {        // Create the entity        $t_character = $entities->add_entity('', '', entity_list::T_CHAR);        // Update game_vars        $t_character->update_game_vars(array("name"=>$name));        // Link the char with the user        $result = $user->add_character($t_character);    } catch(exception $exception) {        $answer = array(            "ok"    => "0",            "name"  => $name,            "msg"   => $exception->get_msg());        return($answer);    }        // Save user links with character created    $users->save_user($user);    // Log    $msg = "User ".$user->get_login()." created new character ";    $msg.= $t_character->game_vars['name']." (".$t_character->key.")";    log_msg($msg, "game", $connection);    // ok, all done :)    $answer = array(        "id"    => $t_character->key,        "name"  => $t_character->game_vars['name']);    return($answer);}/*** Delete character** Input: <drop_character />* Ouput: <drop_character .../>** @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_drop_character(&$connection, &$user, &$character, $command){    global $entities;    try {        // Look for the character to drop        $t_character = & $entities->get_entity($command["id"]);        // If not ADMIN, check you control this character        if($user->access < user_list::L_ADMIN) {            if($t_character->user->get_login() != $user->login) {                 throw new exception("you don't control this character");            }        }        // Break the link with the user        $result = $user->del_character($t_character);    } catch(exception $exception) {        $answer = array(            "ok"    => "0",            "msg"   => $exception->get_msg());        return($answer);    }    // Delete the entity (here I have to use rollback, that's why we cannot    // use exceptions    $result = $entities->del_entity($t_character);    if($result == FALSE) {        // Try to rollback        $user->add_character($t_character);        $answer = array(            "ok"  => "0",            "msg" => $entities->get_last_error());        return($answer);    }    // Log    $msg = "User ".$user->get_login()." removed character ";    $msg.= $t_character->game_vars['name']." (".$t_character->key.")";    log_msg($msg, "game", $connection);    // ok, all done :)    $answer = array(        "ok"    => "1",        "id"    => $t_character->key,        "msg"   => "character ".$t_character->game_vars['name']." deleted succesfully");    return($answer);}?>

⌨️ 快捷键说明

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