const request = require('request') const minecraftAgent = { name: 'Minecraft', version: 1 } const authpath = 'https://authserver.mojang.com' const statuses = [ { service: 'minecraft.net', status: 'grey', name: 'Minecraft.net' }, { service: 'api.mojang.com', status: 'grey', name: 'Public API' }, { service: 'textures.minecraft.net', status: 'grey', name: 'Minecraft Skins' }, { service: 'authserver.mojang.com', status: 'grey', name: 'Authentication Service' }, { service: 'sessionserver.mojang.com', status: 'grey', name: 'Multiplayer Session Service' }, { service: 'account.mojang.com', status: 'grey', name: 'Mojang accounts website' } ] /** * Converts a Mojang status color to a hex value. Valid statuses * are 'green', 'yellow', 'red', and 'grey'. Grey is a custom status * to our project which represents an unknown status. * * @param {string} status A valid status code. * @returns {string} The hex color of the status code. */ exports.statusToHex = function(status){ switch(status.toLowerCase()){ case 'green': return '#a5c325' case 'yellow': return '#eac918' case 'red': return '#c32625' case 'grey': default: return '#848484' } } /** * Retrieves the status of Mojang's services. * The response is condensed into a single object. Each service is * a key, where the value is an object containing a status and name * property. * * @see http://wiki.vg/Mojang_API#API_Status */ exports.status = function(){ return new Promise(function(fulfill, reject) { request.get('https://status.mojang.com/check', { json: true }, function(error, response, body){ if(error || response.statusCode !== 200){ console.warn('Unable to retrieve Mojang status.') console.debug('Error while retrieving Mojang statuses:', error) reject(error || response.statusCode) } else { for(let i=0; i