aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Handler/Json/ApiDoc.pm
blob: bbfe62028272ba37ba673b0f5376e3d1acc18300 (plain)
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package MasterWebInterface::Handler::Json::ApiDoc;
use strict;
use TUWF ':html';
use Exporter 'import';
use JSON;

TUWF::register(
  qr{json} => \&json_docs,
);

################################################################################
# Json Documentation
# Documentation about the Json API
################################################################################
sub json_docs 
{
    my $self = shift;
    $self->htmlHeader(title => "Json API");
    $self->htmlSearchBox(title => "Servers", action => "/s", sel => 'j', fq => '');
    
    div class => "mainbox apidoc";
        div class => "header";
            h1 "Json API";
            p "333networks has a Json API. With this API, it is possible to obtain server lists and specific server information for your own banners, ubrowser or other application.";
        end;
        
        #
        # ToS
        #
        
        h2 "Permission & Terms of Use";
        p;
            txt "The following permissions and conditions are in effect for making use of the Json API: ";
        end;
        
        p "You are allowed to access our API with any application and/or script, self-made or not, to obtain our server lists and server information on the condition that somewhere, anywhere in your application or script you mention that the information is obtained from 333networks.";
        
        p "You are not allowed to flood the API with requests or query our API continuously or with a short interval. If you draw too much network traffic from 333networks, we consider this flooding and will terminate your ability to query our API. Server information is updated every 15 minutes, there is no point in requesting information at a faster rate as there will be no new information available.";
        
        p "Intended use: use the serverlist request to get show a list of all servers. After loading the list, your visitors/users can select a single server to display detailed information. Do NOT use the serverlist to immediately show detailed information for ALL servers, this causes a ludicrous amount of information requests and will get you excluded from our API. Not sure whether you are doing it right? Contact us!";
        
        #
        # use
        #
        h2 "Use";
        p "The Json API consists of three functions to query for information. The methods occur over HTTP and are presented as Json data. The first function requests the \"Message of the Day\", often used to make announcements about the game. The second method returns a list of servers and can be manipulated by gamename. The third method returns detailed server information for an individual server.";
        
        
        h2 "Message of the Day";
        p;
            txt "It is possible to pull announcements from the 333networks Json API with the ";
            span class => "code", "motd";
            txt " command. This command returns an html string with the current 333networks announcements for the selected ";
            span class => "code", "gamename";
            txt ". This string is suitable for direct JQuery's ";
            span class => "code", ".html()";
            txt " function. Additionally, it contains the amount of servers and players as described for the serverlist. This method can be used to announce service messages.";
        end;
        
        div class => "code";
            txt "$self->{site_url}/json/(.[\\w]{1,20})/motd";
        end;
        
        
        h2 "Serverlist";
        p "With the API you can pull a serverlist directly from the masterserver. The API applies the following regex to process your request:";
        div class => "code";
            txt "$self->{site_url}/json/(.[\\w]{1,20})";
        end;
        p;
            txt "In this regex, ";
            span class => "code", "(.[\\w]{1,20})";
            txt " refers to the ";
            span class => "ext", "gamename";
            txt ". This is the abbreviation that every game specifies in their masterserver protocol. A comprehensive list of gamenames is found on the ";
            a href => "/g/all", "games";
            txt " page by looking at the last part of the URL.";
        end;
        
        p;
            txt "It is also possible to provide ";
            span class => "code", "GET";
            txt " information in the url. Allowed options are:";
        end;
        
        ul;
            li; 
                span class => "code", "s"; 
                txt " - sort by country, hostname, gametype, ip, hostport, numplayers and mapname.";
            end;
            li; 
                span class => "code", "o"; 
                txt " - sorting order: 'a' for ascending and 'd' for descending."; 
            end;
            li; 
                span class => "code", "r"; 
                txt " - number of results. Defaults to 50 if not specified. Minimum 1, maximum 1000."; 
            end;
            li; 
                span class => "code", "p"; 
                txt " - page. Show the specified page with results. Total number of entries is included in the result."; 
            end;
            li; 
                span class => "code", "q"; 
                txt " - search query. Identical to the search query on the "; 
                a href => "/s", "servers"; 
                txt " page. Maximum query length is 90 characters."; 
            end;
        end;
        
        #
        # list request format
        #
        
        h2 "Serverlist request examples:";
        p;
            txt "The following examples have different outcomes. In the first example, we request a serverlist of ";
            span class => "code", "all";
            txt " servers, regardless of type and/or name. The second example requests only servers of the game ";
            span class => "code", "Unreal"; 
            txt ". In the last example, we request a serverlist with the gamename ";
            span class => "code", "333networks";
            txt ", with only ";
            span class => "code", "2";
            txt " results per page, page ";
            span class => "code", "1";
            txt " and with the search word ";
            span class => "code", "master";
            txt ".";
        end;
        
        div class => "code";
            txt "$self->{site_url}/json/";
            span class => "ext", "all";
            br;
            txt "$self->{site_url}/json/";
            span class => "ext", "unreal";
            br;
            txt "$self->{site_url}/json/";
            span class => "ext", "333networks";
            txt "?r=";
            span class => "ext", "2";
            txt "&p=";
            span class => "ext", "1";
            txt "&q=";
            span class => "ext", "master";
        end;
        
        h2 "Serverlist result examples:";
        p "The API returns Json data in the following format, using the third request as an example. This is example data and may vary from what you receive when performing the same query.";
        
        div class => "code";
            pre json_result_1();
        end;
        
        p;
            txt "The result contains an array of server entries and the ";
            span class => "code", "total";
            txt " amount of entries. In this case, that is ";
            span class => "code", "2";
            txt " entries listed and ";
            span class => "code", "5"; 
            txt " total entries, implying that there is one more server not shown or on a next page. With the specified number of results specified by the user and the total amount of servers provided by the API, you can calculate how many pages there are to be specified. If applicable, it also shows the current number of ";
            span class => "code", "players"; 
            txt " that are currently in the selected servers. Every server entry has a number of unsorted keywords. Timestamps are linux epoch, in UTC.";
        end;
        
        p "The available keywords that are returned by the API are: ";
        div class => "code", join (" ", qw| id ip hostport hostname gamename label country numplayers maxplayers maptitle mapname gametype dt_added dt_updated|);

        p "There are more keywords available for individual servers. Detailed information about a server is obtained with the individual request as described below. Keywords of both requests are described in the tables below. ";

        
        h2 "Server details";
        p "Your application or script can also request detailed information for a single server. This is done in a similar way as requesting a server list. The following general regex is used by 333networks:";
        
        div class => "code";
            txt  "$self->{site_url}/json/(.[\\w]{1,20})/([\\:\\.\\w]{9,35})";
        end;
        
        p;
            txt "This restricts requests to the correct url with a gamename ";
            span class => "code", "(.[\\w]{1,20})";
            txt " and an IP:port ";
            span class => "code", "([\\:\\.\\w]{9,35})";
            txt " for IPv4 and IPv6 addresses and numerical port number. There are no additional query options or GET options. It is possible that the gamename specified does not match the ";
            txt "gamename";
            txt " as stored in our database. The result will include the correct gamename that was specified in our database.";
        end;
        
        p "The following example requests detailed information by IP address and hostport.";
        
        #
        # individual server details request format
        #
        
        h3 "Server details request:";
        div class => "code";
            txt "$self->{site_url}/json/";
            span class => "ext", "333networks";
            txt "/";
            span class => "ext", "84.83.176.234";
            txt ":";
            span class => "ext", "28900";
        end;
        
        h3 "Server details result:";
        p "The API returns Json data in the following format, using the requests above as an example. This is example data and may vary from what you receive when performing the same query.";
        
        div class => "code";
            # snippet 1, below
            pre json_result_2();
        end;
        
        p "The result has a single entry of parameters with a number of unsorted keywords. The available keywords are in addition to the keywords are specified in multiple tables below.";
        
        p;
            txt "The player object ";
            span class => "code", "player_n";
            txt " represent the players in the server. This is a Json object as part of the larger object above. The available keywords are specified in the table below.";
        end;
        
        h2 "Keyword reference";
        p "Values, type and descriptions of fields that are returned by the Json API:";
        
        # generate reference tables
        json_database_ref();
        
        h2 "Feedback";
        p;
            txt "We wrote the Json API with the intention to make the 333networks masterserver data as accessible as possible. If you feel like any functionality is missing or incorrectly shared, do not hesitate to contact us to provide feedback. Additionally, we request that you follow the advise on usage as we described under the Terms of Use on top of this page, so we can keep providing this API.";
        end;

    end; # mainbox
    $self->htmlFooter(last_change => "May 2021");
}

# list of value / type / descriptions directly from database
sub json_database_ref
{
    my @keyval = (
    { title => "Server identifier information",
      table => [
        ["id",          "int",  "gameserver ID in list database"],
        ["sid",         "int",  "reference ID for detailed information"],
        ["ip",          "text", "server IP address (in IPv6 format)"],
        ["queryport",   "int",  "UDP status query port"],
        ["hostport",    "int",  "hostport to join the server"],
        ["hostname",    "text", "name of the specific server"],
        ["country",     "text", "2-letter country code where the server is hosted"],
        ["location",    "text", "GameSpy regional indication (continent index or 0 for world)"],
        ],
    },
    { title => "Server flags \& datetime",
      table => [
        ["f_protocol",          "int",  "protocol index to distinguish between GameSpy v0 and others"],
        ["f_blacklist",         "int",  "server blacklisted?"],
        ["f_auth",              "int",  "authenticated response to the secure/validate challenge?"],
        ["f_direct",            "int",  "direct beacon to the masterserver?"],
        ["dt_added",            "long", "UTC epoch time that the server was added"],
        ["dt_beacon",           "long", "UTC epoch time that the server sent a heartbeat"],
        ["dt_sync",             "long", "UTC epoch time that the server was last synced from another masterserver"],
        ["dt_updated",          "long", "UTC epoch time that the server information was updated"],
        ["dt_serverinfo",       "long", "UTC epoch time that the detailed server information was updated"],
        ],
    },
    { title => "Gamedata",
      table => [
        # gamedata
        ["gamename",    "text", "gamename of the server"],
        ["label",       "text", "comprehensible game title associated with gamename"],
        ["gamever",     "text", "game version of the server"],
        ["minnetver",   "text", "minimal required game version to join"],
        ],
    },
    { title => "Game settings (detailed information)",
      table => [
        ["listenserver",        "text", "dedicated server indication"],
        ["adminname",           "text", "server administrator's name"],
        ["adminemail",          "text", "server administrator's contact information"],
        ["password",            "text", "passworded or non-public server"],
        ["gametype",            "text", "type of game: capture the flag, deathmatch, assault and more"],
        ["gamestyle",           "text", "in-game playing style"],
        ["changelevels",        "text", "automatically change levels after match end"],
        ["mapurl",              "text", "direct url of the map thumbnail relative from this site's domain"],
        ["mapname",             "text", "filename of current map"],
        ["maptitle",            "text", "title or description of current map"],
        ["minplayers",          "int", "minimum number of players to start the game"],
        ["numplayers",          "int", "current number of players"],
        ["maxplayers",          "int", "maximum number of players simultaneously allowed on the server"],
        ["botskill",            "text", "skill level of bots"],
        ["balanceteams",        "text", "team balancing on join"],
        ["playersbalanceteams", "text", "players can toggle automatic team balancing"],
        ["friendlyfire",        "text", "friendly fire rate"],
        ["maxteams",            "text", "maximum number of teams"],
        ["timelimit",           "text", "time limit per match"],
        ["goalteamscore",       "text", "score limit per match"],
        ["fraglimit",           "text", "score limit per deathmatch"],
        ["mutators",            "text", "comma-separated mutator/mod list"],
        ["misc",                "text", "miscellaneous server attributes (reserved)"],
        ["player_#",            "text", "player information as Json object for player #, see table below"],
        ],
    },
    { title => "Player information",
      table => [
        ["sid",         "int",  "associated server ID (per player)"],
        ["name",        "text", "player display name"],
        ["team",        "text", "player indication as team number, color code or text string"],
        ["frags",       "int",  "number of frags or points"],
        ["mesh",        "text", "player model / mesh"],
        ["skin",        "text", "player body texture"],
        ["face",        "text", "player facial texture"],
        ["ping",        "int",  "player ping"],
        ["misc",        "text", "miscellaneous player attributes (reserved)"],
        ["dt_player",   "long", "UTC epoch time that the player information was updated"],
        ],
    },
    ); 
    
    
    use Data::Dumper 'Dumper';
    
    for my $keytype (@keyval)
    {
        h3 $keytype->{title};
        table class => "keyval";
            Tr;
                th class => "tc1", "Value";
                th class => "tc2", "Type";
                th "Description";
            end;
            
            for my $r (@{$keytype->{table}})
            {
                my @tr = @{$r};
                Tr;
                    td class => "tc1";
                        span class => "code", $tr[0]; 
                    end;
                    td class => "tc2", $tr[1]; 
                    td $tr[2];
                end;
            }
        end;
    }
}

# json output for example 1
sub json_result_1
{
    return '[
    [
        {
            "id":1990,
            "ip":"::ffff:84.83.176.234"                    
            "hostport":28900,
            "hostname":"master.333networks.com (333networks MasterServer)",
            "gamename":"333networks",
            "gametype":"MasterServer",
            "label":"333networks Masterserver",
            "country":"NL",
            "numplayers":15,
            "maxplayers":2966,
            "maptitle":null,
            "mapname":"333networks",
            "dt_added":1616895602,
            "dt_updated":1621019250,            
        },
        {
            "id":1117,        
            "ip":"::ffff:162.154.33.129",
            "hostport":28900
            "hostname":"master.gonespy.com",
            "gamename":"333networks",
            "gametype":"Masterserver",
            "label":"333networks Masterserver",
            "country":"US",
            "numplayers":5,
            "maxplayers":847,
            "maptitle":"",
            "mapname":"333networks",
            "dt_added":1616593343,
            "dt_updated":1621019247,
        }
    ],
    {
        "players":20,
        "total":5
    }
]';
}

sub json_result_2
{
    return '{
        "id":3,
        "ip":"::ffff:45.74.100.250",
        "hostport":10205,
        "mapname":"DXMP_iceworld2",
        "adminname":"Canna the visionary l Disciple Derp191 and RoninMastaFX",
        "hostname":"~Canna\'s Buddhist Server~",
        "mapurl":"/map/default/333networks.jpg",
        "gamever":"1100",
        "gametype":"CDX BDM",
        "gamename":"deusex",
        "country":"CA",
        "dt_updated":1621022768,      
        "player_0":
            {
                "sid":3,
                "name":"Dark191",                            
                "team":"0",            
                "frags":8,
                "mesh":"cmJCDenton",
                "skin":"None",
                "face":""
                "ping":63,
                "dt_player":1621022768,
                "misc":"",
            },
        "player_1":
            {
                "sid":3,
                "name":"Anya",                            
                "team":"0",            
                "frags":12,
                "mesh":"cmJCDenton",
                "skin":"None",
                "face":""
                "ping":54,
                "dt_player":1621022768,
                "misc":"",
            },
        }';
}

1;