impl#

Agent implementation.

class acore_soap_app.agent.impl.Base[source]#

Base class for SOAPRequest and SOAPResponse.

classmethod from_dict(dct: dict)[source]#

Construct an object from a dict.

to_dict() dict[source]#

Convert the object to a dict.

classmethod from_json(json_str: str)[source]#

Construct an object from a JSON string.

to_json() str[source]#

Convert the object to a JSON string.

classmethod batch_load_from_s3(s3_client, s3uri: str)[source]#

从 S3 中加载多个对象.

classmethod batch_dump_to_s3(s3_client, instances: Iterable, s3uri: str)[source]#

将多个对象以 JSON 格式保存到 S3 中.

class acore_soap_app.agent.impl.SOAPRequest(command: str, username: Optional[str] = None, password: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None)[source]#

SOAPRequest is a dataclass to represent the SOAP XML request.

Usage example

# this code only works in EC2 environment
>>> request = SOAPRequest(command=".server info")
>>> response = request.send()
>>> response.to_json()
{
    "body": "<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:ns1="urn:AC"><SOAP-ENV:Body><ns1:executeCommandResponse><result>AzerothCore rev. 85311fa55983 2023-03-25 22:36:05 +0000 (master branch) (Unix, RelWithDebInfo, Static)&#xD;Connected players: 0. Characters in world: 0.&#xD;Connection peak: 0.&#xD;Server uptime: 54 minute(s) 3 second(s)&#xD;Update time diff: 10ms, average: 10ms.&#xD;</result></ns1:executeCommandResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>",
    "message": "AzerothCore rev. 85311fa55983 2023-03-25 22:36:05 +0000 (master branch) (Unix, RelWithDebInfo, Static)Connected players: 0. Characters in world: 0.Connection peak: 0.Server uptime: 54 minute(s) 3 second(s)Update time diff: 10ms, average: 10ms.",
    "succeeded": true
}
Parameters:
  • command – the command to execute.

  • username – the in game GM account username, default “admin”.

  • password – the in game GM account password, default “admin”.

  • host – wow world server host, default “localhost”.

  • port – wow world server SOAP port, default 7878.

More methods from base class:

set_default(username: Optional[str], password: Optional[str])[source]#

Set default values for username and password if they are not set.

property endpoint: str#

Construct the Soap service endpoint URL.

send() SOAPResponse[source]#

Run soap command via HTTP request. This function “has to” be run on the game server and talk to the localhost. You should NEVER open SOAP port to public!

classmethod batch_load(request_like: Union[str, List[str], SOAPRequest, List[SOAPRequest]], username: Optional[str] = None, password: Optional[str] = None, s3_client=None) List[SOAPRequest][source]#

从各种形式的输入中加载 SOAPRequest. 该方法总是返回一个列表.

输入参数 request_like 代表着要运行的 GM 命令, 它可能是以下几种形式中的一种:

  • 如果是一个字符串:
    • 如果是以 s3:// 开头, 那么就去 S3 读数据, 此时需要给定 s3_client 参数.

      通常用于 payload 比较大的情况: - 如果读到的数据是单个字典, 那么就视为一个 SOAPRequest. - 如果读到的数据是一个列表, 那么就视为多个 SOAPRequest.

    • 如果不是以 s3:// 开头, 那么就视为一个 GM command.

  • 如果是一个字符串列表, 那么就视为多个 GM 命令.

  • 它还可以是单个 SOAPRequest 或 SOAPRequest 列表.

  • 这个参数最终都会被转换成 SOAPRequest 的列表.

Parameters:
  • request_like – 上面已经说过了.

  • username – 默认的用户名, 只有当 request.username 为 None 的时候才会用到.

  • password – 默认的密码, 只有当 request.password 为 None 的时候才会用到.

  • s3_client – boto3.client(“s3”)

class acore_soap_app.agent.impl.SOAPResponse(body: str, message: str, succeeded: bool)[source]#

SOAPResponse is a dataclass to represent the SOAP XML response.

Usage:

>>> res = SOAPResponse.parse(
...  '''
...      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
...      ...<result>Account created: test&#xD;</result>...</SOAP-ENV:Envelope>
...  '''
... )
>>> res.message
Account created: test
>>> res.succeeded
True
Parameters:
  • body – the raw SOAP XML response

  • message – if succeeded, it is the <result>...</result> part. if failed, it is the <faultstring>...</faultstring> part

  • succeeded – a boolean flag to indicate whether the command is succeeded

More methods from base class:

classmethod parse(body: str) SOAPResponse[source]#

Parse the SOAP XML response.

print()[source]#

Print the dataclass, ignore the raw response body.