📄 editor.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 *//*** Creates a new entity** Input: <create_entity name="x" type="x" [...]/>* Ouput: <create_entity id="x"/>** @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_entity(&$connection, &$user, &$character, $command){ global $entities; try { // Filter type $type = $entities->get_type_from_name($command["type"]); // Try to create the entity $entity = $entities->add_entity('', '', $type); } catch(exception $exception) { $answer = array( "ok" => "0", "name" => $command['name'], "msg" => $exception->get_msg()); return($answer); } // Save the world :) $entities->save(); // Log $msg = "Created new ".$command['type']; $msg.= " id ".$entity->get_key(); log_msg($msg, "game", $connection); // ok, all done :) $answer = array( "id" => $entity->get_key(), "ok" => "1", "msg" => "entity created"); return($answer);}/*** Removes an entity. Must have no childs.** Input: <drop_entity id="x"/>* Ouput: <drop_entity id="x" ok="<0|1>" [msg="x"]/>** @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_entity(&$connection, &$user, &$character, $command){ global $entities; try { $entity = & $entities->get_entity($command["id"]); $name = $entity->game_vars['name']; $entities->del_entity($entity); } catch(exception $exception) { $answer = array( "id" => $command["id"], "ok" => "0", "msg" => $exception->get_msg()); return($answer); } // Save the world :) $entities->save(); // Log $msg = "Deleted entity named ".$name." id ".$command["id"]; log_msg($msg, "game", $connection); // ok, all done :) $answer = array( "id" => $entity->get_key(), "ok" => "1", "msg" => "entity $name removed"); return($answer);}/*** Update some propreties (not id) of an entity** Input: <update_entity id="x" [...]/>* Ouput: <update_entity id="x" ok="<0|1>" [msg="x"]/>** @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_update_entity(&$connection, &$user, &$character, $command){ global $entities; try { $entity = & $entities->get_entity($command["id"]); $game_vars = $command; unset($game_vars["id"]); $props = ''; // update game vars if needed if(is_array($game_vars)) { $entity->update_game_vars($game_vars); } } catch(exception $exception) { $answer = array( "id" => $command["id"], "ok" => "0", "msg" => $exception->get_msg()); return($answer); } // Save the world :) $entities->save(); // Log $msg = "Update entity id ".$command["id"]; log_msg($msg, "game", $connection); // ok, all done :) $answer = array( "id" => $entity->get_key(), "ok" => "1", "msg" => "entity updated"); return($answer);}/*** List all entities (can filter by type)** Input: <list_entity [type="x"]/>* Ouput: <list_entity id="x" type="x"/>...** @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_list_entity(&$connection, &$user, &$character, $command){ global $entities; try { if(!empty($command["type"])) { $type = $entities->get_type_from_name($command["type"]); } $list = array(); foreach (array_keys($entities->list) as $key) { if(!empty($type)) { if($entities->list[$key]->type != $type) continue; } $entity = & $entities->list[$key]; $list[] = array ( "id" => $entity->get_key(), "name" => $entity->game_vars['name'], "type" => $entities->get_type_name($entity->type)); } } catch(exception $exception) { $answer = array( "id" => $command['id'], "ok" => "0", "msg" => $exception->get_msg()); return($answer); } // ok, all done :) return($list);}/*** Move an entity from place to place** Input: <move_entity id="x" parent_id="x"/>* Ouput: <move_entity id="x" parent_id="x" ok="<0|1>" [msg="x"]/>** @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_move_entity(&$connection, &$user, &$character, $command){ global $entities; try { $entity = & $entities->get_entity($command["id"]); $parent = & $entities->get_entity($command["parent_id"]); $entities->move_entity_to($entity, $parent); } catch(exception $exception) { $answer = array( "id" => $command["id"], "ok" => "0", "parent_id" => $command["parent_id"], "msg" => $exception->get_msg()); return($answer); } // Log $e_name = $entity->game_vars['name']; $p_name = $parent->game_vars['name']; $msg = "Moving entity named ".$e_name." id ".$entity->get_key(); $msg.= " to entity named $p_name id ".$parent->get_key(); log_msg($msg, "game", $connection); // ok, all done :) $answer = array( "id" => $entity->get_key(), "ok" => "1", "msg" => "entity ".$e_name." moved to ".$p_name); return($answer);}/*** Forces saving the world data to disk** Input: <save_entities/>* Ouput: <save_entities ok="<0|1>" [msg="x"]/>** @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_save_entities(&$connection, &$user, &$character, $command){ global $entities; // Save the world :) if($entities->save() == FALSE) { $answer = array( "ok" => "0", "msg" => $entities->get_last_error()); return($answer); } // Log $msg = "World saved by ".$user->get_login(); log_msg($msg, "game", $connection); // ok, all done :) $answer = array( "ok" => "1", "msg" => "entities saved"); return($answer);}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -