Use names instead of IPs

This commit is contained in:
Cryptkeeper 2016-02-01 04:49:54 -06:00
parent ff99e1a828
commit 01a11263ce

@ -1,6 +1,10 @@
var logger = require('./logger');
var config = require('../config.json'); var config = require('../config.json');
var servers = require('../servers.json'); var servers = require('../servers.json');
var serverNameLookup = {};
// Checks if we have a server in config.json with the IP. // Checks if we have a server in config.json with the IP.
function serverWithIpExists(ip) { function serverWithIpExists(ip) {
for (var i = 0; i < servers.length; i++) { for (var i = 0; i < servers.length; i++) {
@ -14,6 +18,24 @@ function serverWithIpExists(ip) {
return false; return false;
} }
function getServerNameByIp(ip) {
var lookupName = serverNameLookup[ip];
if (lookupName) {
return lookupName;
}
for (var i = 0; i < servers.length; i++) {
var entry = servers[i];
if (entry.ip === ip) {
lookupName[entry.ip] = entry.name;
return entry.name;
}
}
}
// This method is a monstrosity. // This method is a monstrosity.
// Since we loaded ALL pings from the database, we need to filter out the pings so each entry is a minute apart. // Since we loaded ALL pings from the database, we need to filter out the pings so each entry is a minute apart.
// This is done by iterating over the list, since the time between each ping can be completely arbitrary. // This is done by iterating over the list, since the time between each ping can be completely arbitrary.
@ -103,11 +125,19 @@ exports.convertPingsToGraph = function(sqlData) {
for (var i = 0; i < sqlData.length; i++) { for (var i = 0; i < sqlData.length; i++) {
var entry = sqlData[i]; var entry = sqlData[i];
if (!graphData[entry.ip]) { var name = getServerNameByIp(entry.ip);
graphData[entry.ip] = [];
if (!name) {
logger.warn('Missing name for ' + entry.ip);
continue;
} }
graphData[entry.ip].push([entry.timestamp, entry.playerCount]); if (!graphData[name]) {
graphData[name] = [];
}
graphData[name].push([entry.timestamp, entry.playerCount]);
} }
// Break it into minutes. // Break it into minutes.