如何使用 SOAP 将命令发送到 AzerothCore 世界服务器控制台?

How to send commands using SOAP to AzerothCore worldserver console?

在启用 SOAP 到 AzerothCore 世界服务器控制台后,如何 运行 命令?

首先,您必须设置 worldserver.conf 这些参数以启用 SOAP:

SOAP.Enabled = 1
SOAP.IP = "127.0.0.1"
SOAP.Port = 7878

之后,运行 你的 worldserver

您可以使用简单的 PHP 脚本向 AzerothCore 控制台发送 运行 命令,如下所示,

如果您没有 php-soap,在 Linux Ubuntu 上,您可以使用 sudo apt install php-soap(或 php7.2-soap)安装它。

<?php

$soap_connection_info = array(
  'soap_uri' => 'urn:AC',
  'soap_host' => '127.0.0.1',
  'soap_port' => '7878',
  'account_name' => 'USERNAME',
  'account_password' => 'PASSWORD'
);

function RemoteCommandWithSOAP($username, $password, $COMMAND)
{
    global $soap_connection_info;
    $result = '';

    try {
        $conn = new SoapClient(NULL, array(
            'location' => 'http://' . $soap_connection_info['soap_host'] . ':' . $soap_connection_info['soap_port'] . '/',
            'uri' => $soap_connection_info['soap_uri'],
            'style' => SOAP_RPC,
            'login' => $username,
            'password' => $password
        ));
        $result = $conn->executeCommand(new SoapParam($COMMAND, 'command'));
        unset($conn);
    } catch (Exception $e) {

        $result = "Have error on soap!\n";

        if (strpos($e, 'There is no such command') !== false) {
            $result = 'There is no such command!';
        }
    }
    return $result;
}

echo RemoteCommandWithSOAP($soap_connection_info['account_name'], $soap_connection_info['account_password'], ".server info");

?>

在最后一行中,您必须使用 gm 级别 3.

的帐户更改 "account_name""account_password"

echo RemoteCommandWithSOAP($soap_connection_info['account_name'], $soap_connection_info['account_password'], ".server info");

您可以用任何命令替换 .server info

注意: 这适用于其他模拟器,只需将 urn:AC 替换为:
- urn:MaNGOS 用于 CMaNGOS(和相关分支)
- urn:TC 对于 TrinityCore
- urn:SF 用于 SkyfireProject
- urn:Oregon 对于 OregonCore
等...

这是一个 perl 脚本来做同样的事情,它需要 libsoap-lite-perl,安装 apt-get install libsoap-lite-perl

将下面的代码放入名为 soap.pl:

的文件中
#!/usr/bin/perl

use strict;
use warnings;
use SOAP::Lite; # visit http://search.cpan.org/dist/SOAP-Lite/ or apt-get install libsoap-lite-perl

my ($user, $pass) = ('gm_account', '1234');
my $host          = 'http://127.0.0.1:7878/';
my $cmd           = '.server info';

BEGIN {
    sub SOAP::Transport::HTTP::Client::get_basic_credentials {
        return $user => $pass,
    }
}

my $soap = SOAP::Lite
    ->proxy($host)
    ->uri('urn:AC');

my $rc = $soap->call('executeCommand',
            SOAP::Data->name('command')->value($cmd));

die $rc->faultstring if ($rc->fault);

print
    $rc->result;

然后启动你的世界服务器并运行那样perl soap.pl

它应该return命令“.server info”的结果