-
Notifications
You must be signed in to change notification settings - Fork 33
/
mumble.c
72 lines (59 loc) · 1.61 KB
/
mumble.c
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
/*
* qstat
* by Steve Jankowski
*
* Mumble protocol
* Copyright 2012 Steven Hartland
*
* Licensed under the Artistic License, see LICENSE.txt for license terms
*
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef _WIN32
#include <arpa/inet.h>
#endif
#include "debug.h"
#include "qstat.h"
#include "packet_manip.h"
query_status_t
send_mumble_request_packet(struct qserver *server)
{
return (send_packet(server, server->type->status_packet, server->type->status_len));
}
query_status_t
deal_with_mumble_packet(struct qserver *server, char *rawpkt, int pktlen)
{
// skip unimplemented ack, crc, etc
char *pkt = rawpkt;
char bandwidth[11];
char version[12];
server->ping_total += time_delta(&packet_recv_time, &server->packet_time1);
if ((24 != pktlen) || (0 != memcmp(pkt + 4, server->type->status_packet + 4, 8))) {
// unknown packet
return (PKT_ERROR);
}
// version
server->protocol_version = ntohl(*(unsigned long *)pkt);
sprintf(version, "%u.%u.%u", (unsigned char)*pkt + 1, (unsigned char)*pkt + 2, (unsigned char)*pkt + 3);
add_rule(server, "version", version, NO_FLAGS);
pkt += 4;
// ident
pkt += 8;
// num players
server->num_players = ntohl(*(unsigned long *)pkt);
pkt += 4;
// max players
server->max_players = ntohl(*(unsigned long *)pkt);
pkt += 4;
// allowed bandwidth
sprintf(bandwidth, "%d", ntohl(*(unsigned long *)pkt));
add_rule(server, "allowed_bandwidth", bandwidth, NO_FLAGS);
pkt += 4;
// Unknown details
server->map_name = strdup("N/A");
server->server_name = strdup("Unknown");
add_rule(server, "gametype", "Unknown", NO_FLAGS);
return (DONE_FORCE);
}