-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNetwork--PacketParser.html
More file actions
292 lines (242 loc) · 11.8 KB
/
Copy pathNetwork--PacketParser.html
File metadata and controls
292 lines (242 loc) · 11.8 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Network::PacketParser - Server message parsing : OpenKore source code documentation</title>
<link rel="stylesheet" type="text/css" href="openkore.css">
<link rel="stylesheet" type="text/css" href="highlight.css">
<!-- Fix broken PNG transparency for IE/Win5-6+ -->
<!--[if gte IE 5.5000]>
<script type="text/javascript" src="pngfix.js"></script>
<![endif]-->
</head>
<body>
<div id="title">OpenKore source code documentation</div>
<div id="navigation">
<ul>
<li><a href="http://www.openkore.com/">Main website</a></li>
<li><a href="index.html">Table of contents</a></li>
<li><b>Network::PacketParser</b></li>
</ul>
</div>
<div id="main">
<h1>Network::PacketParser - Server message parsing</h1>
This class is responsible for parsing messages that are sent by the RO
server to Kore. Information in the messages are stored in global variables
(in the module Globals).
<p>
Please also read <a href="http://wiki.openkore.com/index.php/Network_subsystem">the
network subsystem overview.</a>
<p><table class="functionIndex">
<tr><th colspan="3">Class methods</th></tr><tr onclick="location.href='#Network::PacketParser->create';">
<td class="return-type"></td>
<td class="func"><a href="#Network::PacketParser->create">Network::PacketParser->create</a></td>
<td class="decl">(<span class="type">Network</span> net, String serverType)</td>
</tr>
</table>
<p><table class="functionIndex">
<tr><th colspan="3">Hash members</th></tr><tr onclick="location.href='#{packet_list}';">
<td class="return-type">Hash*</td>
<td class="func"><a href="#{packet_list}">{packet_list}</a></td>
<td class="decl"></td>
</tr><tr onclick="location.href='#{packet_lut}';">
<td class="return-type">Hash*</td>
<td class="func"><a href="#{packet_lut}">{packet_lut}</a></td>
<td class="decl"></td>
</tr>
</table>
<p><table class="functionIndex">
<tr><th colspan="3">Methods</th></tr><tr onclick="location.href='#$packetParser->mangle';">
<td class="return-type">boolean</td>
<td class="func"><a href="#$packetParser->mangle">$packetParser->mangle</a></td>
<td class="decl">(<span class="type">Array*</span> args)</td>
</tr><tr onclick="location.href='#$packetParser->parse';">
<td class="return-type">Hash*</td>
<td class="func"><a href="#$packetParser->parse">$packetParser->parse</a></td>
<td class="decl">(<span class="type">Bytes</span> msg)</td>
</tr><tr onclick="location.href='#$packetParser->reconstruct';">
<td class="return-type">Bytes</td>
<td class="func"><a href="#$packetParser->reconstruct">$packetParser->reconstruct</a></td>
<td class="decl">(<span class="type">Hash*</span> args)</td>
</tr><tr onclick="location.href='#$packetParser->willMangle';">
<td class="return-type">boolean</td>
<td class="func"><a href="#$packetParser->willMangle">$packetParser->willMangle</a></td>
<td class="decl">(<span class="type">Bytes</span> messageID)</td>
</tr>
</table>
<p><hr class="details_sep">
<h2>Details</h2>
<div class="details">
<p>
<div class="function"><a name="$packetParser->mangle"></a>
<h3>$packetParser->mangle</h3>
<dl>
<dt class="decl">
<span class="return-type"> boolean</span> <strong>$packetParser->mangle</strong>(<span class="type">Array*</span> args)
</dt>
<dd>
<div class="desc">Calls the appropriate plugin function to mangle the packet, which
destructively modifies <code>$args</code>.
Returns false if the packet should be suppressed.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$packetParser->parse"></a>
<h3>$packetParser->parse</h3>
<dl>
<dt class="decl">
<span class="return-type"> Hash*</span> <strong>$packetParser->parse</strong>(<span class="type">Bytes</span> msg)
</dt>
<dd>
<div class="desc">Parses a raw packet using {packet_list}.
<p>
Result hashref would contain parsed arguments and the following information:
<ul>
<li>switch: packet switch</li>
<li>RAW_MSG: original message passed</li>
<li>RAW_MSG_SIZE: length of original message passed</li>
<li>KEYS: list of argument names from {packet_list}
</li>
</ul></div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$packetParser->reconstruct"></a>
<h3>$packetParser->reconstruct</h3>
<dl>
<dt class="decl">
<span class="return-type"> Bytes</span> <strong>$packetParser->reconstruct</strong>(<span class="type">Hash*</span> args)
</dt>
<dd>
<div class="desc">Reconstructs a raw packet from <code>$args</code> using {packet_list} and {packet_lut}.
<p>
<code>$args</code>->{switch} may contain a packet switch or a handler name.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="$packetParser->willMangle"></a>
<h3>$packetParser->willMangle</h3>
<dl>
<dt class="decl">
<span class="return-type"> boolean</span> <strong>$packetParser->willMangle</strong>(<span class="type">Bytes</span> messageID)
</dt>
<dd>
<dl class="params_and_returns">
<dt class="params"><strong>Parameters:</strong></dt>
<dd class="param"><code>messageID</code> : a message ID, such as "008A".</dd>
</dl><p>
<div class="desc">Check whether the message with the specified message ID will be mangled.
If the bot is running in X-Kore mode, then messages that will be mangled will not
be sent to the RO client.
<p>
By default, a message will never be mangled. Plugins can register mangling procedures
though. This is done by using the following hooks:
<ul>
<li>"Network::Receive/willMangle" - This hook has arguments 'messageID' (Bytes) and 'name' (String).
'name' is a human-readable description of the message, and may be undef. Plugins
should set the 'return' argument to 1 if they want <code>willMangle()</code> to return 1.</li>
<li>"Network::Receive/mangle" - This hook has arguments 'messageArgs' and 'messageName' (the latter may be undef).
</li>
</ul>
The following example demonstrates how this is done:
<pre class="example">
Plugins<span class="hl sym">::</span><span class="hl kwd">addHook</span><span class="hl sym">(</span><span class="hl str">"Network::Receive/willMangle"</span><span class="hl sym">,</span> \<span class="hl sym">&</span>willMangle<span class="hl sym">);</span>
Plugins<span class="hl sym">::</span><span class="hl kwd">addHook</span><span class="hl sym">(</span><span class="hl str">"Network::Receive/mangle"</span><span class="hl sym">,</span> \<span class="hl sym">&</span>mangle<span class="hl sym">);</span>
<span class="hl kwa">sub</span> willMangle <span class="hl sym">{</span>
<span class="hl kwc">my</span> <span class="hl sym">(</span>undef<span class="hl sym">,</span> <span class="hl kwb">$args</span><span class="hl sym">) =</span> <span class="hl kwb">@_</span><span class="hl sym">;</span>
<span class="hl kwa">if</span> <span class="hl sym">(</span><span class="hl kwb">$args</span><span class="hl sym">->{</span>messageID<span class="hl sym">}</span> <span class="hl kwa">eq</span> <span class="hl str">'008A'</span><span class="hl sym">) {</span>
<span class="hl kwb">$args</span><span class="hl sym">->{</span>willMangle<span class="hl sym">} =</span> <span class="hl num">1</span><span class="hl sym">;</span>
<span class="hl sym">}</span>
<span class="hl sym">}</span>
<span class="hl kwa">sub</span> mangle <span class="hl sym">{</span>
<span class="hl kwc">my</span> <span class="hl sym">(</span>undef<span class="hl sym">,</span> <span class="hl kwb">$args</span><span class="hl sym">) =</span> <span class="hl kwb">@_</span><span class="hl sym">;</span>
<span class="hl kwc">my</span> <span class="hl kwb">$message_args</span> <span class="hl sym">=</span> <span class="hl kwb">$args</span><span class="hl sym">->{</span>messageArgs<span class="hl sym">};</span>
<span class="hl kwa">if</span> <span class="hl sym">(</span><span class="hl kwb">$message_args</span><span class="hl sym">->{</span><span class="hl kwa">switch</span><span class="hl sym">}</span> <span class="hl kwa">eq</span> <span class="hl str">'008A'</span><span class="hl sym">) {</span>
<span class="hl sym">...</span>Modify <span class="hl kwb">$message_args</span> as necessary<span class="hl sym">....</span>
<span class="hl sym">}</span>
<span class="hl sym">}</span>
</pre>
<p>
You can also mangle packets by defining <code>$args</code>->{mangle} in other plugin hooks. The options avalable are:
<ul>
<li>0 = no mangle</li>
<li>1 = mangle (change packet and reconstruct)</li>
<li>2 = drop
</li>
</ul>
The following example will drop all public chat messages:
<pre class="example">
Plugins<span class="hl sym">::</span><span class="hl kwd">addHook</span><span class="hl sym">(</span><span class="hl str">"packet_pre/public_chat"</span><span class="hl sym">,</span> \<span class="hl sym">&</span>mangleChat<span class="hl sym">);</span>
<span class="hl kwa">sub</span> mangleChat
<span class="hl sym">{</span>
<span class="hl kwc">my</span><span class="hl sym">(</span>undef<span class="hl sym">,</span> <span class="hl kwb">$args</span><span class="hl sym">) =</span> <span class="hl kwb">@_</span><span class="hl sym">;</span>
<span class="hl kwb">$args</span><span class="hl sym">->{</span>mangle<span class="hl sym">} =</span> <span class="hl num">2</span><span class="hl sym">;</span>
<span class="hl sym">}</span>
</pre></div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="Network::PacketParser->create"></a>
<h3>Network::PacketParser->create</h3>
<dl>
<dt class="decl">
<span class="return-type"> </span><strong>Network::PacketParser->create</strong>(<span class="type">Network</span> net, String serverType)
</dt>
<dd>
<dl class="params_and_returns">
<dt class="params"><strong>Parameters:</strong></dt>
<dd class="param"><code>net</code> : An object compatible with the '<code>Network</code>' class.</dd>
<dd class="param"><code>serverType</code> : A server type.</dd>
</dl><p>
<div class="desc">Create a new server message parsing object for the specified server type.
<p>
Throws FileNotFoundException, ModuleLoadException.</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="{packet_list}"></a>
<h3>{packet_list}</h3>
<dl>
<dt class="decl">
<span class="return-type"> Hash*</span> <strong>{packet_list}</strong>
</dt>
<dd>
<div class="desc">A list of packet handlers and decoding information.
<p>
'packet switch' => ['handler function', 'unpack string', [qw(argument names)]]</div>
</dd>
</dl>
</div>
<p><hr class="function_sep"><p>
<div class="function"><a name="{packet_lut}"></a>
<h3>{packet_lut}</h3>
<dl>
<dt class="decl">
<span class="return-type"> Hash*</span> <strong>{packet_lut}</strong>
</dt>
<dd>
<div class="desc">Lookup table for currently used packet switches.
Used for constructing packets by handler name.
<p>
'handler function' => 'packet switch'</div>
</dd>
</dl>
</div>
</div>
<p><hr><p>
<div id="footer">
<ul>
<li><a href="http://validator.w3.org/check?uri=referer" title="Valid HTML 4.01!"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a></li>
<li><a href="http://www.mozilla.com/" title="Get Firefox - Take Back the Web"><img width="104" height="32" src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox - Take Back the Web"></a></li>
<li><a href="http://www.mozilla.com/" title="If you were looking at this page in any browser but Microsoft Internet Explorer, it would look and run better and faster"><img width="45" height="45" src="http://linuxart.com/img/noIE-small.png" alt="If you were looking at this page in any browser but Microsoft Internet Explorer, it would look and run better and faster"></a></li>
</ul>
Last modified: Fri Nov 16 10:05:11 2012
</div>
</div>
</body>
</html>