magicoli / opensim-rest-php
OpenSimulator REST PHP库和命令行客户端
v1.0.5
2023-07-21 02:01 UTC
Requires (Dev)
- clue/phar-composer: ^1.4
- magicoli/php-bump-library: ^1.0
README
此库允许与启用了REST控制台的Robust或OpenSimulator实例通信。
它可以在PHP项目中使用,也可以作为OpenSimulator网格的命令行客户端。
可用的命令可以在这里找到:http://opensimulator.org/wiki/Server_Commands
先决条件
必须在您的Robust .ini文件中启用远程连接。
不要使用默认值!您永远不需要手动输入用户名和密码,因此您可以安全地生成长随机字符串。
您必须选择一个特定的端口,该端口尚未被其他服务使用。在防火墙设置中限制仅允许授权IP地址访问此端口是良好的做法。
[Network] ConsoleUser = arandomgeneratedstring ConsolePass = anotherrandomgeneratedstring ConsolePort = 8009 ; choose a port not already used by another service
命令行客户端
从该存储库下载可执行文件,确保opensim-rest-cli
是可执行的,并将其移动到/usr/local/bin/。
chmod +x /path/to/opensim-rest-cli sudo mv /path/to/opensim-rest-cli /usr/local/bin/opensim-rest-cli
您可以运行类似以下命令
opensim-rest-cli /path/to/Robust.ini show info opensim-rest-cli /path/to/Robust.ini show regions
如果您将凭证保存在~/.opensim-rest-cli.ini中,则可以跳过Robust.ini参数。
opensim-rest-cli show info opensim-rest-cli show regions
PHP类
将class-rest.php文件下载到您的项目中或使用composer安装。 不要在公共网站上保留opensim-rest-cli
或opensim-rest-cli.php
。
composer require --dev https://github.com/magicoli/opensim-rest-php cp magicoli/opensim-rest-php/class-rest.php lib/
在您的PHP项目中
require(dirname(__FILE__) . '/lib/class-rest.php'); $session = opensim_rest_session( array( 'uri' => "yourgrid.org:8009", 'ConsoleUser' => 'yourConsoleUsername', 'ConsolePass' => 'yourConolePassword', ) ); if ( is_opensim_rest_error($session) ) { error_log( "OpenSim_Rest error: " . $session->getMessage() ); } else { $responseLines = $session->sendCommand($command); } # Return value: an array containing the line(s) of response or a PHP Error