line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::MCBouncer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13762
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
612
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
31197
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
583
|
use JSON; |
|
1
|
|
|
|
|
7992
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
529
|
use Moo; |
|
1
|
|
|
|
|
9180
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WebService::MCBouncer - Query MCBouncer API for Minecraft bans |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
A simple module for interacting with the MCBouncer API to query for bans / notes |
19
|
|
|
|
|
|
|
for Minecraft users. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $mcbouncer = WebService::MCBouncer->new( |
23
|
|
|
|
|
|
|
api_key => '...your MCBouncer API key...', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if (my $bans = $mcbouncer->bans($player_name)) { |
27
|
|
|
|
|
|
|
for my $ban (@$bans) { |
28
|
|
|
|
|
|
|
printf "Player %s was banned from %s on %s by %s (%s)\n", |
29
|
|
|
|
|
|
|
@ban{ qw(username server issuer time reason) }; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if (my $notes = $mcbouncer->notes($player_name)) { |
34
|
|
|
|
|
|
|
for my $note (@$notes) { |
35
|
|
|
|
|
|
|
say "Note: $note->{text}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
L is a service allowing Minecraft server |
43
|
|
|
|
|
|
|
administrators to share details of bans and notes about abusive users. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MCBouncer provides a server mod to use with the service, but also provides |
46
|
|
|
|
|
|
|
an API to query for bans / notes using an API key, obtained when you |
47
|
|
|
|
|
|
|
add a server to the list via the website. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This module uses the API to allow you to fetch details of bans or notes about |
50
|
|
|
|
|
|
|
users. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has api_key => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
has user_agent => ( |
58
|
|
|
|
|
|
|
is => 'rw', |
59
|
|
|
|
|
|
|
isa => sub { my $val = shift; ref $val && $val->isa('LWP::UserAgent') }, |
60
|
|
|
|
|
|
|
default => sub { |
61
|
|
|
|
|
|
|
LWP::UserAgent->new( agent => __PACKAGE__ . "/$VERSION" ); |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 Methods |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 bans |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Given a username, returns details of any bans for that user. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns the raw JSON response from the MCBouncer API, which at the current time |
72
|
|
|
|
|
|
|
includes: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item totalcount |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The total number of bans recorded |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item data |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
An arrayref of details of each ban, each being a hashref of: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item username |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The username banned |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item reason |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The reason for the ban |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item server |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The ban this server is from |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item time |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The date and time the ban was recorded, e.g. C<2015-04-10T00:59:31.280> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item issuer |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The username of the person who placed this ban. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item page |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The page number. I don't know how paging with the MCBouncer API works yet. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item success |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Indicates whether the the API call succeeded. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=back |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub bans { |
121
|
0
|
|
|
0
|
1
|
|
my ($self, $username) = @_; |
122
|
0
|
|
|
|
|
|
my $response = $self->user_agent->get( |
123
|
|
|
|
|
|
|
"http://mcbouncer.com/api/getBans/" |
124
|
|
|
|
|
|
|
. $self->api_key . "/$username" |
125
|
|
|
|
|
|
|
); |
126
|
0
|
0
|
|
|
|
|
if (!$response->is_success) { |
127
|
0
|
|
|
|
|
|
die "Failed to query getBans for $username - " . $response->status_line; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $result = JSON::from_json($response->decoded_content); |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
return unless $result->{totalcount}; |
133
|
0
|
|
|
|
|
|
return $result; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 notes |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Given a username, returns details of any notes recorded for that user. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns the raw JSON response from the MCBouncer API, which at the current time |
141
|
|
|
|
|
|
|
includes: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item totalcount |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
The total number of notes recorded. (If this is 0, C will return undef, |
148
|
|
|
|
|
|
|
so you can use it in a conditional sensibly.) |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item data |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
An arrayref of details of each note, each being a hashref of: |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item username |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The username the note applies to |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item note |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The text of the note |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item server |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The ban this note is from |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item time |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The date and time the note was added, e.g. C<2015-04-10T00:59:31.280> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item issuer |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The username of the person who added this note |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item noteid |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The ID of this note |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item page |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
The page number. I don't know how paging with the MCBouncer API works yet. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item success |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Indicates whether the API call succeeded. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub notes { |
195
|
0
|
|
|
0
|
1
|
|
my ($self, $username) = @_; |
196
|
0
|
|
|
|
|
|
my $response = $self->user_agent->get( |
197
|
|
|
|
|
|
|
"http://mcbouncer.com/api/getNotes/" |
198
|
|
|
|
|
|
|
. $self->api_key . "/$username" |
199
|
|
|
|
|
|
|
); |
200
|
0
|
0
|
|
|
|
|
if (!$response->is_success) { |
201
|
0
|
|
|
|
|
|
die "Failed to query getBans for $username - " . $response->status_line; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
my $result = JSON::from_json($response->decoded_content); |
205
|
0
|
|
|
|
|
|
return $result; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
=head2 function2 |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
David Precious, C<< >> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 BUGS / DEVELOPMENT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Bug reports and pull requests are welcomed on GitHub: |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Deaygo for creating MCBouncer. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Copyright 2015 David Precious. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
235
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
236
|
|
|
|
|
|
|
copy of the full license at: |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
L |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
241
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
242
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
243
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
246
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
247
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
250
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
253
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
254
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
255
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
256
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
257
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
258
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
259
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
262
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
263
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
264
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
265
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
266
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
267
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
268
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; # End of WebService::MCBouncer |