-
Notifications
You must be signed in to change notification settings - Fork 4
Who Service
CaffeinatedRat edited this page Mar 20, 2013
·
4 revisions
This service exposes the online player information.
These are the properties that are available from this service:
- Maximum number of players the server can support concurrently.
- Total number of players online.
- Player's name.
- Player's online time formatted.
- Player's online time in milliseconds.
- Player's environment.
- Player's operator status.
You can query the who service by invoking the service name who.
The following is an example of how to invoke the service.
var ws = new WebSocket('ws://192.168.1.1:25564' ); ws.onopen = function() { ws.send('who'); };
The following is the format of the response generated by the service.
{ MaxPlayers: number, Players: [ { name(0): string, onlineTime(0): string, onlineTimeSpan(0): long, environment(0): string {NORMAL | NETHER | THE_END}, isOperator(0): boolean } ... { name(n): string, onlineTime(n): string, onlineTimeSpan(n): long, environment(n): string {NORMAL | NETHER | THE_END}, isOperator(n): boolean } ] Status: string }
The following is an example of the JSON data that is returned by this service.
{ "MaxPlayers": "20", "Players": [ { "name": "caffeinatedrat", "onlineTime": "0d 0h 2m 41s", "onlineTimeSpan": 161292, "environment": "NORMAL", "isOperator":true } ], "Status": "SUCCESSFUL" }
The following is an example of how to use JQuery to parse the JSON data.
var json = jQuery.parseJSON(msg.data); if(json.Status == "SUCCESSFUL") { $('#maxNumberOfPlayers').text(json.MaxPlayers); $('#totalPlayersOnline').text(json.Players.length); if(json.Players.length > 0) { $('#playerList').text(''); for(i = 0; i < json.Players.length; i++) { //Open the player element. var element = '<li><div class="playerElement">' //Show the mod icon if the user is a moderator. if(json.Players[i].isOperator) { element += '<div class="inline"><div title="Moderator" class="tiles modTile"></div></div>'; } else { element += '<div class="inline"><div title="Player" class="tiles playerTile"></div></div>'; } //Show the player's face. element += '<div id="test" class="inline"><canvas class="playersFace" id="can'; element += json.Players[i].name; element += '"></canvas></div>'; //Show the player's name with profile link. var environment = json.Players[i].environment.replace('_', '').toLowerCase(); element += '<div class="inline">'; element += '<strong><a class="playerName" href="#" data-name="'; element += json.Players[i].name; element += '" data-environment="'; element += environment; element += '" click="javascript:return false;">'; element += json.Players[i].name; element += '</a></strong>'; element += '</div>'; //Show the total time the player has been online. element += '<div class="inline">(Online: ' + json.Players[i].onlineTime + ')</div>'; //Display the environment the player is currently in. element += '<div class="inline" style="padding-left: 5px;">'; element += '<div title="'; element += json.Players[i].environment.replace('_', ' '); element += '" class="tiles '; element += environment; element += 'Tile"></div>'; //Close the player element. element += '</div></li>'; $('#playerList').append(element); //Resize the player's face. $('#playerList').append('<script>drawPlayersFace("can' + json.Players[i].name + '", "' + json.Players[i].name + '");</script>'); } //END OF for(i = 0; i < json.Players.length; i++) {... } else { $('#playerList').text('<li>No one is online.</li>'); } //END OF if(json.Players.length > 0) {... } //END OF if(json.Status == "SUCCESSFUL") {...