1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
---
redirect_from: "/Remote-Access"
---
# Remote Access
## Introduction
Azerothcore has 4 ways of interfacing with the world server.
- In Game
- The Console
- Telnet (RA)
- HTTP (SOAP)
The in game menus and the console are pretty self explanatory, however you are not always able to administer the server locally nor do the first two options provide many opportunities for automation. If you want to provide a way to access your server remotely, or let software manage it then you have two options.
## Choosing the Correct Protocol
### Remote Access
Remote access is basically a telnet connection and has all of the downsides a telnet connection brings. These would be:
- Data is sent over cleartext which can be intercepted easily.
- You use distinct sessions, meaning you open and close a connection each time.
- It can be difficult to parse the return since it just returns what you would see in the CLI
However, it has upsides as well, namely:
- It is simple with little overhead.
- It is well established and documented.
- Platform independent.
Remote access is good for running on a local server, and accessing it securely over SSH to send it commands. Its simplicity is its strength. On top of that it is built in to most machines without any configuration needed.
### SOAP
It stands for simple object access protocol and is a format for sharing structured data between machines. It is a common xml analogue to ReST and json, and lets two pieces of software interact with each other despite running on different code bases, languages, and operating systems. Lets get on to the weaknesses.
- No default encoding meaning that you can get away with almost anything. Some people may see it as a bonus but it can be confusing.
- Little security
And its strengths.
- XML is a well established format supported in most programming languages.
- Uses standard HTTP
In a more simplified format: SOAP for websites, telnet for command line.
## Using the Protocol of Choice
### Setup
1. Both protocols must be enabled via the [worldserver config files](https://github.com/azerothcore/azerothcore-wotlk/blob/master/src/server/apps/worldserver/worldserver.conf.dist#L3122).
2. When they are enabled, in order to authorize access to the database, you need to find the `account_access` table in the auth database and make sure the realmID of your user is -1 (meaning all realms).
3. When that is done you are set up to use telnet and SOAP
### Access
#### Telnet
Due to it's ubiquity telnet is easy to use from almost anywhere.
1. open up a terminal session (or PuTTY) and type in `telnet localhost 3443`
2. Enter your username and password.
#### Soap
Soap works using standard HTTP POST. The entire post payload is XML.
```xml
<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:executeCommand>
<command>server status</command>
</ns1:executeCommand>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
```
The response will look like this:
```xml
<?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. 6f4f0043c2ab+ 2021-05-18 02:16:59 +0200 (master branch) (Win64, RelWithDebInfo)
Connected players: 0. Characters in world: 0.
Connection peak: 0.
Server uptime: 5 second(s).
Update time diff: 10ms, average: 10ms.
</result>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
```
Error response looks like this
```xml
<?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>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Error 401: HTTP 401 Unauthorized</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
```
You need to authenticate by putting the username and password in the URI like this: `http://soapuser:abcd1234@localhost:7878/` (this is also known as "basic auth")
setting request header `Content-Type: application/xml` is not needed. For now.
## Code Examples
<details>
<summary>PHP</summary>
using built-in [SoapClient](https://www.php.net/manual/en/class.soapclient.php)
```php
$conn = new SoapClient(NULL, array(
'location' => "http://{{ ip }}:{{ port }}/",
'uri' => 'urn:AC',
'style' => SOAP_RPC,
'login' => 'soapuser',
'password' => 'abcd1234'
));
echo $conn->executeCommand(new SoapParam('server info', 'command'));
```
</details>
<details>
<summary>NodeJS (TypeScript)</summary>
using [xml2js](https://www.npmjs.com/package/xml2js) to parse the response. Please make sure to sanitize the inputs.
```typescript
function AzerothCore_Soap(command){
return new Promise((resolve, reject)=>{
const req = http.request({
port: 7878,
method: "POST",
hostname: "localhost",
auth: "soapuser:abcd1234",
headers: { 'Content-Type': 'application/xml' }
}, res=>{
res.on('data', async d => {
const xml = await xml2js.parseStringPromise(d.toString());
const body = xml["SOAP-ENV:Envelope"]["SOAP-ENV:Body"][0];
const fault = body["SOAP-ENV:Fault"];
if(fault){
resolve({
faultCode : fault[0]["faultcode"][0],
faultString: fault[0]["faultstring"][0],
});
return;
}
const response = body["ns1:executeCommandResponse"];
if(response){
resolve({
result: response[0]["result"][0]
});
return;
}
console.log(d.toString());
})
});
req.write(
'<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:executeCommand>' +
'<command>'+command+'</command>' +
'</ns1:executeCommand>' +
'</SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>'
);
req.end();
});
}
```
</details>
|