Squelch an MSVC++ complaint.
[obnox/wireshark/wip.git] / packet-quake3.c
1 /* packet-quake3.c
2  * Routines for Quake III Arena packet dissection
3  *
4  * Uwe Girlich <uwe@planetquake.com>
5  *
6  * $Id: packet-quake3.c,v 1.4 2001/10/13 07:43:25 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * Copied from packet-quake2.c
13  * 
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29
30 /*
31    All informations used in this decoding were gathered from
32         * some own captures of a private server,
33         * the "Server commands howto" document written by id Software
34                 (http://www.quake3arena.com/tech/ServerCommandsHowto.html)
35         * source code of the game server browser tool qstat
36                 (http://www.qstat.org).
37 */
38
39
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #ifdef HAVE_SYS_TYPES_H
45 # include <sys/types.h>
46 #endif
47
48 #include <string.h>
49 #include <glib.h>
50 #include "packet.h"
51 #include "prefs.h"
52 #include "resolv.h"
53
54 static int proto_quake3 = -1;
55
56 static int hf_quake3_direction = -1;
57 static int hf_quake3_connectionless = -1;
58 static int hf_quake3_game = -1;
59 static int hf_quake3_connectionless_marker = -1;
60 static int hf_quake3_connectionless_text = -1;
61 static int hf_quake3_connectionless_command = -1;
62 static int hf_quake3_server_addr = -1;
63 static int hf_quake3_server_port = -1;
64 static int hf_quake3_game_seq1 = -1;
65 static int hf_quake3_game_rel1 = -1;
66 static int hf_quake3_game_seq2 = -1;
67 static int hf_quake3_game_rel2 = -1;
68 static int hf_quake3_game_qport = -1;
69
70 static gint ett_quake3 = -1;
71 static gint ett_quake3_connectionless = -1;
72 static gint ett_quake3_connectionless_text = -1;
73 static gint ett_quake3_server = -1;
74 static gint ett_quake3_game = -1;
75 static gint ett_quake3_game_seq1 = -1;
76 static gint ett_quake3_game_seq2 = -1;
77 static gint ett_quake3_game_clc = -1;
78 static gint ett_quake3_game_svc = -1;
79
80
81 #define QUAKE3_SERVER_PORT 27960
82 #define QUAKE3_MASTER_PORT 27950
83 static unsigned int gbl_quake3_server_port=QUAKE3_SERVER_PORT;
84 static unsigned int gbl_quake3_master_port=QUAKE3_MASTER_PORT;
85
86
87 static const value_string names_direction[] = {
88 #define DIR_UNKNOWN 0
89         { DIR_UNKNOWN, "Unknown" },
90 #define DIR_C2S 1
91         { DIR_C2S, "Client to Server" },
92 #define DIR_S2C 2
93         { DIR_S2C, "Server to Client" },
94 #define DIR_C2M 3
95         { DIR_C2M, "Client to Master" },
96 #define DIR_M2C 4
97         { DIR_M2C, "Master to Client" },
98         { 0, NULL }
99 };
100
101
102 #define string_starts_with(s1, s2) (strncmp((s1), (s2), strlen(s2)) == 0)
103
104
105 static const value_string names_command[] = {
106 #define COMMAND_UNKNOWN                 0
107         { COMMAND_UNKNOWN,              "Unknown" },
108 #define COMMAND_statusResponse          1
109         { COMMAND_statusResponse,       "Reply Status" },
110 #define COMMAND_getstatus               2
111         { COMMAND_getstatus,            "Request Status" },
112 #define COMMAND_infoResponse            3
113         { COMMAND_infoResponse,         "Reply Info" },
114 #define COMMAND_getinfo                 4
115         { COMMAND_getinfo,              "Request Info" },
116 #define COMMAND_challengeResponse       5
117         { COMMAND_challengeResponse,    "Reply Challenge" },
118 #define COMMAND_getchallenge            6
119         { COMMAND_getchallenge,         "Request Challenge" },
120 #define COMMAND_connectResponse         7
121         { COMMAND_connectResponse,      "Reply Connect" },
122 #define COMMAND_connect                 8
123         { COMMAND_connect,              "Request Connect" },
124 #define COMMAND_rconResponse            9
125         { COMMAND_rconResponse,         "Reply Remote Command" },
126 #define COMMAND_rcon                    10
127         { COMMAND_rcon,                 "Request Remote Command" },
128 #define COMMAND_getmotdResponse         11
129         { COMMAND_getmotdResponse,      "Reply Motto of the Day" },
130 #define COMMAND_getmotd                 12
131         { COMMAND_getmotd,              "Request Motto of the Day" },
132 #define COMMAND_getserversResponse      13
133         { COMMAND_getserversResponse,   "Reply Servers" },
134 #define COMMAND_getservers              14
135         { COMMAND_getservers,           "Request Servers" },
136 #define COMMAND_getKeyAuthorize         15
137         { COMMAND_getKeyAuthorize,      "Request Key Authorization" },
138 #define COMMAND_getIpAuthorize          16
139         { COMMAND_getIpAuthorize,       "Request IP Authorization" },
140 #define COMMAND_ipAuthorize             17
141         { COMMAND_ipAuthorize,          "Reply IP Authorization" },
142         { 0, NULL }
143 };
144
145
146 static void
147 dissect_quake3_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
148         proto_tree *tree, int* direction)
149 {
150         proto_tree      *cl_tree = NULL;
151         proto_item      *cl_item = NULL;
152         proto_item      *text_item = NULL;
153         proto_tree      *text_tree = NULL;
154         guint8          text[2048];
155         int             maxbufsize = 0;
156         int             len;
157         int             offset;
158         guint32         marker;
159         int             command;
160         int             command_len;
161         int             command_finished = FALSE;
162
163         marker = tvb_get_ntohl(tvb, 0);
164         if (tree) {
165                 cl_item = proto_tree_add_text(tree, tvb,
166                                 0, tvb_length(tvb), "Connectionless");
167                 if (cl_item)
168                         cl_tree = proto_item_add_subtree(
169                                 cl_item, ett_quake3_connectionless);
170         }
171
172         if (cl_tree) {
173                 proto_tree_add_uint(cl_tree, hf_quake3_connectionless_marker,
174                                 tvb, 0, 4, marker);
175         }
176
177         /* all the rest of the packet is just text */
178         offset = 4;
179
180         maxbufsize = MIN((gint)sizeof(text), tvb_length_remaining(tvb, offset));
181         len = tvb_get_nstringz0(tvb, offset, maxbufsize, text);
182         if (cl_tree) {
183                 text_item = proto_tree_add_string(cl_tree,
184                                 hf_quake3_connectionless_text,
185                                 tvb, offset, len + 1, text);
186                 if (text_item) {
187                         text_tree = proto_item_add_subtree(
188                                         text_item,
189                                         ett_quake3_connectionless_text);
190                 }
191         }
192
193         command = COMMAND_UNKNOWN;
194         command_len = 0;
195
196         if (strncmp(text, "statusResponse", 14) == 0) {
197                 command = COMMAND_statusResponse;
198                 *direction = DIR_S2C;
199                 command_len = 14;
200         }
201         else if (strncmp(text, "getstatus", 9) == 0) {
202                 command = COMMAND_getstatus;
203                 *direction = DIR_C2S;
204                 command_len = 9;
205         }
206         else if (strncmp(text, "infoResponse", 12) == 0) {
207                 command = COMMAND_infoResponse;
208                 *direction = DIR_S2C;
209                 command_len = 12;
210         }
211         else if (strncmp(text, "getinfo", 7) == 0) {
212                 command = COMMAND_getinfo;
213                 *direction = DIR_C2S;
214                 command_len = 7;
215         }
216         else if (strncmp(text, "challengeResponse", 17) == 0) {
217                 command = COMMAND_challengeResponse;
218                 *direction = DIR_S2C;
219                 command_len = 17;
220         }
221         else if (strncmp(text, "getchallenge", 12) == 0) {
222                 command = COMMAND_getchallenge;
223                 *direction = DIR_C2S;
224                 command_len = 12;
225         }
226         else if (strncmp(text, "connectResponse", 15) == 0) {
227                 command = COMMAND_connectResponse;
228                 *direction = DIR_S2C;
229                 command_len = 15;
230         }
231         else if (strncmp(text, "connect", 7) == 0) {
232                 command = COMMAND_connect;
233                 *direction = DIR_C2S;
234                 command_len = 7;
235         }
236         else if (strncmp(text, "rconResponse", 12) == 0) {
237                 command = COMMAND_rconResponse;
238                 *direction = DIR_S2C;
239                 command_len = 12;
240         }
241         else if (strncmp(text, "rcon", 4) == 0) {
242                 command = COMMAND_rcon;
243                 *direction = DIR_C2S;
244                 command_len = 4;
245         }
246         else if (strncmp(text, "getmotdResponse", 15) == 0) {
247                 command = COMMAND_getmotdResponse;
248                 *direction = DIR_M2C;
249                 command_len = 15;
250         }
251         else if (strncmp(text, "getmotd", 7) == 0) {
252                 command = COMMAND_getmotd;
253                 *direction = DIR_C2M;
254                 command_len = 7;
255         }
256         else if (strncmp(text, "getserversResponse", 18) == 0) {
257                 int base;
258                 command = COMMAND_getserversResponse;
259                 *direction = DIR_M2C;
260                 command_len = 18;
261                 /* The data can contain 0's, and the text string is binary
262                 anyway, so better replace the text string after the first
263                 \ with "<DATA>". */
264                 if (text_item) {
265                         /* first correct the length until the end of the packet */
266                         proto_item_set_len(text_item, tvb_length_remaining(tvb, offset));
267                         /* then replace the text */
268                         proto_item_set_text(text_item, "Text: getserversResponse<DATA>");
269                 }
270                 if (text_tree)
271                         proto_tree_add_string(text_tree, hf_quake3_connectionless_command,
272                                         tvb, offset, command_len,
273                                         val_to_str(command, names_command, "Unknown"));
274                 command_finished = TRUE;
275
276                 /* now we decode all the rest */
277                 base = offset + 18;
278                 /* '/', ip-address in network order, port in network order */
279                 while (tvb_length_remaining(tvb, base) >= 7) {
280                         guint32         ip_addr;
281                         guint16         udp_port;
282                         proto_item      *server_item = NULL;
283                         proto_tree      *server_tree = NULL;
284
285                         ip_addr = tvb_get_ntohl(tvb, base + 1);
286                         udp_port = tvb_get_ntohs(tvb, base + 5);
287
288                         /* It may be a good idea to create a conversation for
289                                 every server in this list, as we'll see at
290                                 least a getinfo request to each of them and they
291                                 may run on totally unusual ports.  */
292
293                         if (text_tree) {
294                                 server_item = proto_tree_add_text(text_tree,
295                                         tvb, base, 7, 
296                                         "Server: %s:%u",
297                                                 get_hostname(htonl(ip_addr)),
298                                                 udp_port);
299                                 if (server_item)
300                                         server_tree = proto_item_add_subtree(
301                                                 server_item,
302                                                 ett_quake3_server);
303                         }
304                         if (server_tree) {
305                                 /* I'm not sure about all this ordering stuff
306                                 but so it works on my (le) machine */
307                                 proto_tree_add_ipv4(server_tree, hf_quake3_server_addr, 
308                                         tvb, base + 1, 4, htonl(ip_addr));
309                                 proto_tree_add_uint(server_tree, hf_quake3_server_port, 
310                                         tvb, base + 5, 2, udp_port);
311                         }
312
313                         base += 7;
314                 }
315         }
316         else if (strncmp(text, "getservers", 10) == 0) {
317                 command = COMMAND_getservers;
318                 *direction = DIR_C2M;
319                 command_len = 10;
320         }
321         else if (strncmp(text, "getKeyAuthorize", 15) == 0) {
322                 command = COMMAND_getKeyAuthorize;
323                 *direction = DIR_C2M;
324                 command_len = 15;
325         }
326         else if (strncmp(text, "getIpAuthorize", 14) == 0) {
327                 command = COMMAND_getIpAuthorize;
328                 *direction = DIR_C2M;
329                 command_len = 14;
330         }
331         else if (strncmp(text, "ipAuthorize", 11) == 0) {
332                 command = COMMAND_ipAuthorize;
333                 *direction = DIR_M2C;
334                 command_len = 11;
335         }
336         else {
337                 *direction = DIR_UNKNOWN;
338         }
339
340         if (text_tree && command_finished == FALSE) {
341                 proto_tree_add_string(text_tree, hf_quake3_connectionless_command,
342                                         tvb, offset, command_len,
343                                         val_to_str(command, names_command, "Unknown"));
344         }
345
346         offset += len + 1;
347
348 }
349
350
351 static void
352 dissect_quake3_client_commands(tvbuff_t *tvb, packet_info *pinfo,
353         proto_tree *tree)
354 {
355         /* this shouldn't be too difficult */
356         dissect_data(tvb, 0, pinfo, tree);
357 }
358
359
360 static void
361 dissect_quake3_server_commands(tvbuff_t *tvb, packet_info *pinfo,
362         proto_tree *tree)
363 {
364         /* It is totally forbidden to decode this any further,
365         I wont do it. */
366         dissect_data(tvb, 0, pinfo, tree);
367 }
368
369
370 static const value_string names_reliable[] = {
371         { 0, "Non Reliable" },
372         { 1, "Reliable" },
373         { 0, NULL }
374 };
375
376
377 static void
378 dissect_quake3_GamePacket(tvbuff_t *tvb, packet_info *pinfo,
379         proto_tree *tree, int *direction)
380 {
381         proto_tree      *game_tree = NULL;
382         proto_item      *game_item = NULL;
383         guint32         seq1;
384         guint32         seq2;
385         int             rel1;
386         int             rel2;
387         int             offset;
388         guint           rest_length;
389
390         *direction = (pinfo->destport == gbl_quake3_server_port) ?
391                         DIR_C2S : DIR_S2C;
392
393         if (tree) {
394                 game_item = proto_tree_add_text(tree, tvb,
395                                 0, tvb_length(tvb), "Game");
396                 if (game_item)
397                         game_tree = proto_item_add_subtree(
398                                 game_item, ett_quake3_game);
399         }
400
401         offset = 0;
402
403         seq1 = tvb_get_letohs(tvb, offset);
404         rel1 = seq1 & 0x8000 ? 1 : 0;
405         seq1 &= ~0x8000;
406         if (game_tree) {
407                 proto_item *seq1_item = proto_tree_add_text(game_tree,
408                         tvb, offset, 2, "Current Sequence: %u (%s)",
409                         seq1, val_to_str(rel1,names_reliable,"%u"));
410                 if (seq1_item) {
411                         proto_tree *seq1_tree = proto_item_add_subtree(
412                                 seq1_item, ett_quake3_game_seq1);
413                         proto_tree_add_uint(seq1_tree, hf_quake3_game_seq1,
414                                         tvb, offset, 2, seq1);
415                         proto_tree_add_boolean(seq1_tree, hf_quake3_game_rel1,
416                                         tvb, offset+1, 1, rel1);
417                 }
418         }
419         offset += 2;
420
421         seq2 = tvb_get_letohs(tvb, offset);
422         rel2 = seq2 & 0x8000 ? 1 : 0;
423         seq2 &= ~0x8000;
424         if (game_tree) {
425                 proto_item *seq2_item = proto_tree_add_text(game_tree,
426                         tvb, offset, 2, "Acknowledge Sequence: %u (%s)",
427                         seq2, val_to_str(rel2,names_reliable,"%u"));;
428                 if (seq2_item) {
429                         proto_tree *seq2_tree = proto_item_add_subtree(
430                                 seq2_item, ett_quake3_game_seq2);
431                         proto_tree_add_uint(seq2_tree, hf_quake3_game_seq2,
432                                         tvb, offset, 2, seq2);
433                         proto_tree_add_boolean(seq2_tree, hf_quake3_game_rel2,
434                                         tvb, offset+1, 1, rel2);
435                 }
436         }
437         offset += 2;
438
439         if (*direction == DIR_C2S) {
440                 /* client to server */
441                 guint16 qport = tvb_get_letohs(tvb, offset);
442                 if (game_tree) {
443                         proto_tree_add_uint(game_tree, hf_quake3_game_qport, 
444                                 tvb, offset, 2, qport);
445                 }
446                 offset +=2;
447         }
448
449         /* all the rest is pure game data */
450         rest_length = tvb_reported_length(tvb) - offset;
451         if (rest_length) {
452                 tvbuff_t *next_tvb =
453                 tvb_new_subset(tvb, offset, rest_length , rest_length);
454
455                 if (*direction == DIR_C2S) {
456                         proto_item *c_item = NULL;
457                         proto_tree *c_tree = NULL;
458                         if (tree) {
459                                 c_item = proto_tree_add_text(game_tree, next_tvb,
460                                 0, tvb_length(next_tvb),
461                                 "Client Commands");
462                                 if (c_item) {
463                                         c_tree = proto_item_add_subtree(
464                                                 c_item, ett_quake3_game_clc);
465                                 }
466                         }
467                         dissect_quake3_client_commands(next_tvb, pinfo, c_tree);
468                 }
469                 else {
470                         proto_item *c_item = NULL;
471                         proto_tree *c_tree = NULL;
472                         if (tree) {
473                                 c_item = proto_tree_add_text(game_tree, next_tvb,
474                                 0, tvb_length(next_tvb),
475                                 "Server Commands");
476                                 if (c_item) {
477                                         c_tree = proto_item_add_subtree(
478                                         c_item, ett_quake3_game_svc);
479                                 }
480                         }
481                         dissect_quake3_server_commands(next_tvb, pinfo, c_tree);
482                 }
483         }
484 }
485
486
487 static void
488 dissect_quake3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
489 {
490         proto_tree      *quake3_tree = NULL;
491         proto_item      *quake3_item = NULL;
492         proto_item      *dir_item = NULL;
493         int             direction;
494
495         direction = DIR_UNKNOWN;
496
497         pinfo->current_proto = "QUAKE3";
498
499         if (check_col(pinfo->fd, COL_PROTOCOL))
500                 col_set_str(pinfo->fd, COL_PROTOCOL, "QUAKE3");
501
502         if (tree) {
503                 quake3_item = proto_tree_add_item(tree, proto_quake3,
504                                 tvb, 0, tvb_length(tvb), FALSE);
505                 if (quake3_item)
506                         quake3_tree = proto_item_add_subtree(
507                                 quake3_item, ett_quake3);
508
509                         if (quake3_tree) {
510                                 dir_item = proto_tree_add_none_format(
511                                         quake3_tree,
512                                         hf_quake3_direction, tvb, 0, 0,
513                                         "Direction: %s", 
514                                         val_to_str(direction,
515                                                 names_direction, "%u"));
516                         }
517         }
518
519         if (tvb_get_ntohl(tvb, 0) == 0xffffffff) {
520                 if (check_col(pinfo->fd, COL_INFO)) {
521                         col_set_str(pinfo->fd, COL_INFO, "Connectionless ");
522                 }
523                 if (quake3_tree)
524                         proto_tree_add_uint_format(quake3_tree,
525                                 hf_quake3_connectionless,
526                                 tvb, 0, 0, 1,
527                                 "Type: Connectionless");
528                 dissect_quake3_ConnectionlessPacket(
529                         tvb, pinfo, quake3_tree, &direction);
530         }
531         else {
532                 if (check_col(pinfo->fd, COL_INFO)) {
533                         col_set_str(pinfo->fd, COL_INFO, "Game ");
534                 }
535                 if (quake3_tree)
536                         proto_tree_add_uint_format(quake3_tree,
537                                 hf_quake3_game,
538                                 tvb, 0, 0, 1,
539                                 "Type: Game");
540                 dissect_quake3_GamePacket(
541                         tvb, pinfo, quake3_tree, &direction);
542         }
543         if (direction != DIR_UNKNOWN && dir_item)
544                 proto_item_set_text(dir_item, 
545                                         "Direction: %s", 
546                                         val_to_str(direction,
547                                                 names_direction, "%u"));
548
549         if (check_col(pinfo->fd, COL_INFO))
550                 col_append_str(pinfo->fd, COL_INFO, val_to_str(direction,
551                         names_direction, "%u"));
552 }
553
554
555 void
556 proto_reg_handoff_quake3(void)
557 {
558         static int initialized=FALSE;
559         static int server_port;
560         static int master_port;
561         int i;
562  
563         if (initialized) {
564                 for (i=0;i<4;i++)
565                         dissector_delete("udp.port", server_port+i, dissect_quake3);
566                 for (i=0;i<4;i++)
567                         dissector_delete("udp.port", master_port+i, dissect_quake3);
568         } else {
569                 initialized=TRUE;
570         }
571  
572         /* set port for future deletes */
573         server_port = gbl_quake3_server_port;
574         master_port = gbl_quake3_master_port;
575  
576         /* add dissectors */
577         for (i=0;i<4;i++)
578                 dissector_add("udp.port", gbl_quake3_server_port + i,
579                         dissect_quake3, proto_quake3);
580         for (i=0;i<4;i++)
581                 dissector_add("udp.port", gbl_quake3_master_port + i,
582                         dissect_quake3, proto_quake3);
583 }
584
585
586 void
587 proto_register_quake3(void)
588 {
589         static hf_register_info hf[] = {
590                 { &hf_quake3_direction,
591                         { "Direction", "quake3.direction",
592                         FT_NONE, BASE_DEC, NULL, 0x0,
593                         "Packet Direction", HFILL }},
594                 { &hf_quake3_connectionless,
595                         { "Connectionless", "quake3.connectionless",
596                         FT_UINT32, BASE_DEC, NULL, 0x0,
597                         "Connectionless", HFILL }},
598                 { &hf_quake3_game,
599                         { "Game", "quake3.game",
600                         FT_UINT32, BASE_DEC, NULL, 0x0,
601                         "Game", HFILL }},
602                 { &hf_quake3_connectionless_marker,
603                         { "Marker", "quake3.connectionless.marker",
604                         FT_UINT32, BASE_HEX, NULL, 0x0,
605                         "Marker", HFILL }},
606                 { &hf_quake3_connectionless_text,
607                         { "Text", "quake3.connectionless.text",
608                         FT_STRING, BASE_DEC, NULL, 0x0,
609                         "Text", HFILL }},
610                 { &hf_quake3_connectionless_command,
611                         { "Command", "quake3.connectionless.command",
612                         FT_STRING, BASE_DEC, NULL, 0x0,
613                         "Command", HFILL }},
614                 { &hf_quake3_server_addr,
615                         { "Server Address", "quake3.server.addr",
616                         FT_IPv4, BASE_DEC, NULL, 0x0,
617                         "Server IP Address", HFILL }},
618                 { &hf_quake3_server_port,
619                         { "Server Port", "quake3.server.port",
620                         FT_UINT16, BASE_DEC, NULL, 0x0,
621                         "Server UDP Port", HFILL }},
622                 { &hf_quake3_game_seq1,
623                         { "Sequence Number", "quake3.game.seq1",
624                         FT_UINT32, BASE_DEC, NULL, 0x0,
625                         "Sequence number of the current packet", HFILL }},
626                 { &hf_quake3_game_rel1,
627                         { "Reliable", "quake3.game.rel1",
628                         FT_BOOLEAN, BASE_DEC, NULL, 0x0,
629                         "Packet is reliable and may be retransmitted", HFILL }},
630                 { &hf_quake3_game_seq2,
631                         { "Sequence Number", "quake3.game.seq2",
632                         FT_UINT32, BASE_DEC, NULL, 0x0,
633                         "Sequence number of the last received packet", HFILL }},
634                 { &hf_quake3_game_rel2,
635                         { "Reliable", "quake3.game.rel2",
636                         FT_BOOLEAN, BASE_DEC, NULL, 0x0,
637                         "Packet was reliable and may be retransmitted", HFILL }},
638                 { &hf_quake3_game_qport,
639                         { "QPort", "quake3.game.qport",
640                         FT_UINT32, BASE_DEC, NULL, 0x0,
641                         "Quake III Arena Client Port", HFILL }}
642         };
643         static gint *ett[] = {
644                 &ett_quake3,
645                 &ett_quake3_connectionless,
646                 &ett_quake3_connectionless_text,
647                 &ett_quake3_server,
648                 &ett_quake3_game,
649                 &ett_quake3_game_seq1,
650                 &ett_quake3_game_seq2,
651                 &ett_quake3_game_clc,
652                 &ett_quake3_game_svc
653         };
654         module_t *quake3_module;
655
656         proto_quake3 = proto_register_protocol("Quake III Arena Network Protocol",
657                                                 "QUAKE3", "quake3");
658         proto_register_field_array(proto_quake3, hf, array_length(hf));
659         proto_register_subtree_array(ett, array_length(ett));
660
661         /* Register a configuration option for port */
662         quake3_module = prefs_register_protocol(proto_quake3,
663                 proto_reg_handoff_quake3);
664         prefs_register_uint_preference(quake3_module, "udp.arena_port",
665                                         "Quake III Arena Server UDP Base Port",
666                                         "Set the UDP base port for the Quake III Arena Server",
667                                         10, &gbl_quake3_server_port);
668         prefs_register_uint_preference(quake3_module, "udp.master_port",
669                                         "Quake III Arena Master Server UDP Base Port",
670                                         "Set the UDP base port for the Quake III Arena Master Server",
671                                         10, &gbl_quake3_master_port);
672 }
673