From 01a11263ce51be52fcb3091a7a1d443c8d2b73a7 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 04:49:54 -0600 Subject: [PATCH 01/21] Use names instead of IPs --- lib/util.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index 0e9914b..2f06c02 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,10 @@ +var logger = require('./logger'); + var config = require('../config.json'); var servers = require('../servers.json'); +var serverNameLookup = {}; + // Checks if we have a server in config.json with the IP. function serverWithIpExists(ip) { for (var i = 0; i < servers.length; i++) { @@ -14,6 +18,24 @@ function serverWithIpExists(ip) { 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. // 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. @@ -103,11 +125,19 @@ exports.convertPingsToGraph = function(sqlData) { for (var i = 0; i < sqlData.length; i++) { var entry = sqlData[i]; - if (!graphData[entry.ip]) { - graphData[entry.ip] = []; + var name = getServerNameByIp(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. From 1483a62711d430826c973d04d603e7b30ba68fd8 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 04:53:40 -0600 Subject: [PATCH 02/21] Fix some bad references --- app.js | 6 +++--- lib/util.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 6501a98..8114766 100644 --- a/app.js +++ b/app.js @@ -104,11 +104,11 @@ function handlePing(network, res, err) { // Don't have too much data! util.trimOldPings(graphData); - if (!graphData[network.ip]) { - graphData[network.ip] = []; + if (!graphData[network.name]) { + graphData[network.name] = []; } - graphData[network.ip].push([timeMs, res ? res.players.online : 0]); + graphData[network.name].push([timeMs, res ? res.players.online : 0]); // Send the update. server.io.sockets.emit('updateHistoryGraph', { diff --git a/lib/util.js b/lib/util.js index 2f06c02..39c4039 100644 --- a/lib/util.js +++ b/lib/util.js @@ -29,7 +29,7 @@ function getServerNameByIp(ip) { var entry = servers[i]; if (entry.ip === ip) { - lookupName[entry.ip] = entry.name; + serverNameLookup[entry.ip] = entry.name; return entry.name; } From 3dc10f571fe29da0c6b1940886846e6a837fc913 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 04:55:37 -0600 Subject: [PATCH 03/21] Correctly ignore old servers in the db --- lib/util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/util.js b/lib/util.js index 39c4039..1801726 100644 --- a/lib/util.js +++ b/lib/util.js @@ -36,6 +36,16 @@ function getServerNameByIp(ip) { } } +function getServerIps() { + var ips = []; + + for (var i = 0; i < servers.length; i++) { + ips.push(servers[i].ip); + } + + return ips; +} + // 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. // This is done by iterating over the list, since the time between each ping can be completely arbitrary. @@ -120,11 +130,16 @@ exports.setIntervalNoDelay = function(func, delay) { }; exports.convertPingsToGraph = function(sqlData) { + var serverIps = getServerIps(); var graphData = {}; for (var i = 0; i < sqlData.length; i++) { var entry = sqlData[i]; + if (serverIps.indexOf(entry.ip) === -1) { + continue; + } + var name = getServerNameByIp(entry.ip); if (!name) { From 6d8ab212e01f78d40f43d4245b585fedeb0e1daf Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 04:58:05 -0600 Subject: [PATCH 04/21] Fix incorrect IP references --- app.js | 1 + assets/js/site.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 8114766..7b235c1 100644 --- a/app.js +++ b/app.js @@ -113,6 +113,7 @@ function handlePing(network, res, err) { // Send the update. server.io.sockets.emit('updateHistoryGraph', { ip: network.ip, + name: network.name, players: (res ? res.players.online : 0), timestamp: timeMs }); diff --git a/assets/js/site.js b/assets/js/site.js index 11d9e8f..12093b6 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -308,14 +308,14 @@ $(document).ready(function() { } // If it's not in our display group, use the hidden group instead. - var targetGraphData = displayedGraphData[rawData.ip] ? displayedGraphData : hiddenGraphData; + var targetGraphData = displayedGraphData[rawData.name] ? displayedGraphData : hiddenGraphData; trimOldPings(targetGraphData, graphDuration); - targetGraphData[rawData.ip].push([rawData.timestamp, rawData.players]); + targetGraphData[rawData.name].push([rawData.timestamp, rawData.players]); // Redraw if we need to. - if (displayedGraphData[rawData.ip]) { + if (displayedGraphData[rawData.name]) { historyPlot.setData(convertGraphData(displayedGraphData)); historyPlot.setupGrid(); From 266eff4668c591e423de73ea696cdc4c68ed9b61 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:05:14 -0600 Subject: [PATCH 05/21] Tweak the color hashing system --- assets/js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/util.js b/assets/js/util.js index b128990..af6420b 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -96,7 +96,7 @@ function convertGraphData(rawData) { function stringToColor(base) { var hash; - for (var i = 0, hash = 0; i < base.length; i++) { + for (var i = base.length - 1, hash = 0; i >= 0; i--) { hash = base.charCodeAt(i) + ((hash << 5) - hash); } From f6a27f04697d499ba90281173d6e27b08c118bea Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:09:56 -0600 Subject: [PATCH 06/21] Fix legacy code problems --- lib/util.js | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/lib/util.js b/lib/util.js index 1801726..44921e6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -5,19 +5,6 @@ var servers = require('../servers.json'); var serverNameLookup = {}; -// Checks if we have a server in config.json with the IP. -function serverWithIpExists(ip) { - for (var i = 0; i < servers.length; i++) { - var entry = servers[i]; - - if (entry.ip === ip) { - return true; - } - } - - return false; -} - function getServerNameByIp(ip) { var lookupName = serverNameLookup[ip]; @@ -52,16 +39,7 @@ function getServerIps() { function trimUselessPings(data) { var keys = Object.keys(data); - var keysToRemove = []; - for (var i = 0; i < keys.length; i++) { - // Don't bother we servers we deleted from config.json - if (!serverWithIpExists(keys[i])) { - keysToRemove.push(keys[i]); - - continue; - } - var listing = data[keys[i]]; var lastTimestamp = 0; @@ -87,11 +65,6 @@ function trimUselessPings(data) { data[keys[i]] = filteredListing; } - - // Delete data for any networks we don't care about anymore. - for (var i = 0; i < keysToRemove.length; i++) { - delete data[keysToRemove[i]]; - } } exports.trimOldPings = function(data) { @@ -142,12 +115,6 @@ exports.convertPingsToGraph = function(sqlData) { var name = getServerNameByIp(entry.ip); - if (!name) { - logger.warn('Missing name for ' + entry.ip); - - continue; - } - if (!graphData[name]) { graphData[name] = []; } From 37fdf25eae5884336269839b61c752e6e31bcbe5 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:14:33 -0600 Subject: [PATCH 07/21] Add some comments --- lib/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/util.js b/lib/util.js index 44921e6..98639e4 100644 --- a/lib/util.js +++ b/lib/util.js @@ -5,6 +5,8 @@ var servers = require('../servers.json'); var serverNameLookup = {}; +// Finds a server in servers.json with a matching IP. +// If it finds one, it caches the result for faster future lookups. function getServerNameByIp(ip) { var lookupName = serverNameLookup[ip]; @@ -23,6 +25,7 @@ function getServerNameByIp(ip) { } } +// Returns a list of configured server IPs from servers.json function getServerIps() { var ips = []; From c4177abaaf62f11ccd94cebcee612e97c34c995e Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:20:25 -0600 Subject: [PATCH 08/21] Start work on saving graph controls --- assets/js/site.js | 4 ++++ assets/js/util.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/assets/js/site.js b/assets/js/site.js index 12093b6..10d2f5a 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -460,9 +460,13 @@ $(document).ready(function() { delete hiddenGraphData[serverIp]; } + // Redraw the graph historyPlot.setData(convertGraphData(displayedGraphData)); historyPlot.setupGrid(); historyPlot.draw(); + + // Update our localStorage + saveGraphControls(); }); }); diff --git a/assets/js/util.js b/assets/js/util.js index af6420b..5b83b60 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -2,6 +2,24 @@ var MISSING_FAVICON_BASE64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAA var tooltip = $('#tooltip'); +function saveGraphControls(displayedServers) { + if (typeof(localStorage) !== undefined) { + var json = JSON.stringify(displayedServers); + + localStorage.setItem('displayedServers', json); + } +} + +function loadGraphControls() { + if (typeof(localStorage) !== undefined) { + var item = localStorage.getItem('displayedServers'); + + if (item) { + return JSON.parse(item); + } + } +} + function getTimestamp(ms, timeOnly) { var date = new Date(0); From 01c427eea2e2abdcf1a0f25936c16953a090ba0e Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:21:46 -0600 Subject: [PATCH 09/21] Fix hooking --- assets/js/site.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/js/site.js b/assets/js/site.js index 10d2f5a..704fdd0 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -214,6 +214,9 @@ function setAllGraphVisibility(visible) { historyPlot.setupGrid(); historyPlot.draw(); + + // Update our localStorage + saveGraphControls(Object.keys(displayedGraphData)); } function toggleControlsDrawer() { @@ -467,6 +470,6 @@ $(document).ready(function() { historyPlot.draw(); // Update our localStorage - saveGraphControls(); + saveGraphControls(Object.keys(displayedGraphData)); }); }); From 1e5b5efc4867c6d8c4710e117069f4a769fed28d Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:23:42 -0600 Subject: [PATCH 10/21] Remove the data if needed --- assets/js/site.js | 12 ++++++++++-- assets/js/util.js | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/assets/js/site.js b/assets/js/site.js index 704fdd0..d9c459e 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -216,7 +216,11 @@ function setAllGraphVisibility(visible) { historyPlot.draw(); // Update our localStorage - saveGraphControls(Object.keys(displayedGraphData)); + if (visible) { + resetGraphControls(); + } else { + saveGraphControls(Object.keys(displayedGraphData)); + } } function toggleControlsDrawer() { @@ -470,6 +474,10 @@ $(document).ready(function() { historyPlot.draw(); // Update our localStorage - saveGraphControls(Object.keys(displayedGraphData)); + if (Object.keys(hiddenGraphData).length === 0) { + resetGraphControls(); + } else { + saveGraphControls(Object.keys(displayedGraphData)); + } }); }); diff --git a/assets/js/util.js b/assets/js/util.js index 5b83b60..449effc 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -20,6 +20,12 @@ function loadGraphControls() { } } +function resetGraphControls() { + if (typeof(localStorage) !== undefined) { + localStorage.removeItem('displayedServers'); + } +} + function getTimestamp(ms, timeOnly) { var date = new Date(0); From ae018acba482e7f3ea722dbe143f604052946ade Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:29:09 -0600 Subject: [PATCH 11/21] Load back the graph controls --- assets/js/site.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/assets/js/site.js b/assets/js/site.js index d9c459e..8a1590e 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -277,11 +277,27 @@ $(document).ready(function() { }); socket.on('historyGraph', function(rawData) { - displayedGraphData = rawData; + var shownServers = loadGraphControls(); + + if (shownServers) { + var keys = Object.keys(rawData); + + for (var i = 0; i < keys.length; i++) { + var name = keys[i]; + + if (shownServers.indexOf(name) !== -1) { + displayedGraphData[name] = rawData[name]; + } else { + hiddenGraphData[name] = rawData[name]; + } + } + } else { + displayedGraphData = rawData; + } $('#big-graph').css('height', '400px'); - historyPlot = $.plot('#big-graph', convertGraphData(rawData), bigChartOptions); + historyPlot = $.plot('#big-graph', convertGraphData(displayedGraphData), bigChartOptions); $('#big-graph').bind('plothover', handlePlotHover); @@ -293,7 +309,13 @@ $(document).ready(function() { keys.sort(); for (var i = 0; i < keys.length; i++) { - html += ' ' + keys[i] + ''; + var checkedString = ''; + + if (displayedGraphData[keys[i]]) { + checkedString = 'checked=checked'; + } + + html += ' ' + keys[i] + ''; if (sinceBreak >= 7) { sinceBreak = 0; From 808418f6bd2ce025e17d60688fdcabfa276899ab Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:31:00 -0600 Subject: [PATCH 12/21] Correctly init these --- assets/js/site.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/site.js b/assets/js/site.js index 8a1590e..fe9b9a8 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -282,6 +282,9 @@ $(document).ready(function() { if (shownServers) { var keys = Object.keys(rawData); + hiddenGraphData = []; + displayedGraphData = []; + for (var i = 0; i < keys.length; i++) { var name = keys[i]; From 4af3d8a85f17e36a9e97525a25b0aee24c9346db Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:32:00 -0600 Subject: [PATCH 13/21] Avoid race conditions --- assets/js/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/site.js b/assets/js/site.js index fe9b9a8..0175218 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -335,7 +335,7 @@ $(document).ready(function() { socket.on('updateHistoryGraph', function(rawData) { // Prevent race conditions. - if (!graphDuration) { + if (!graphDuration || !displayedGraphData || !hiddenGraphData) { return; } From 41c5b46f5192831fc22420b78e3b27516c7c43d8 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:34:51 -0600 Subject: [PATCH 14/21] Create CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6cb9cdb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +**2.0.0** +- Servers are now referenced by their name on the graph controls instead of their IP. +- Servers now display their name on hover instead of their IP. +- Graph controls are now saved and loaded automatically. From 3f1323970b271b80b506c0f70ae4aa5fcc7bdbcd Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:36:12 -0600 Subject: [PATCH 15/21] Include a link to the CHANGELOG in the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 08d09b7..fb1bab3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ You can see an up-to-date copy of the master branch running on http://minetrack. Database logging is disabled by default. You can enable it in ```config.json``` by setting ```logToDatabase``` to true. This requires sqlite3 drivers to be installed. +#### What's being changed? +For the changelog, check out the[CHANGELOG](CHANGELOG.md) file. + #### How do I get added? At the moment, the main "minetrack.me" site is only accepting networks that average roughly 1,000 players at peak for **PC** servers, and 100 players at peak for **PE** servers. This is due to limited capacity and it's functionality. If you fit this description, you're welcome to open a Pull Request adding the network to ```config.json```. From c5e37a3f0d6b2c67fb3e68a5402f8b218c5d7eb6 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:36:26 -0600 Subject: [PATCH 16/21] Increase version to 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b277459..f33df8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minetrack", - "version": "1.0.0", + "version": "2.0.0", "description": "A Minecraft server tracker that lets you focus on the basics.", "main": "app.js", "dependencies": { From 6e6595598308d25f8019e18e682b4e2bb988cc29 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:36:41 -0600 Subject: [PATCH 17/21] Fix spacing typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb1bab3..a2757be 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Database logging is disabled by default. You can enable it in ```config.json``` This requires sqlite3 drivers to be installed. #### What's being changed? -For the changelog, check out the[CHANGELOG](CHANGELOG.md) file. +For the changelog, check out the [CHANGELOG](CHANGELOG.md) file. #### How do I get added? At the moment, the main "minetrack.me" site is only accepting networks that average roughly 1,000 players at peak for **PC** servers, and 100 players at peak for **PE** servers. This is due to limited capacity and it's functionality. If you fit this description, you're welcome to open a Pull Request adding the network to ```config.json```. From b1e2f8007de79c9413fcbdc1b3b18401b045a4f7 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:37:16 -0600 Subject: [PATCH 18/21] Note the movement of server listing --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb9cdb..5b4213d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ - Servers are now referenced by their name on the graph controls instead of their IP. - Servers now display their name on hover instead of their IP. - Graph controls are now saved and loaded automatically. +- Moved server configuration into servers.json from config.json. From 5edd13ac5dfefd6116e1913a24361184af26ad85 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:43:23 -0600 Subject: [PATCH 19/21] Log this for debug purposes --- lib/util.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/util.js b/lib/util.js index 98639e4..2ecea4f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -109,6 +109,8 @@ exports.convertPingsToGraph = function(sqlData) { var serverIps = getServerIps(); var graphData = {}; + var startTime = getCurrentTimeMs(); + for (var i = 0; i < sqlData.length; i++) { var entry = sqlData[i]; @@ -131,5 +133,7 @@ exports.convertPingsToGraph = function(sqlData) { // Drop old data. exports.trimOldPings(graphData); + logger.inf('Converted data structure in ' + (getCurrentTimeMs() - startTime) + 'ms'); + return graphData; }; \ No newline at end of file From c1c66c8f5014b31f4e6a44709b441ba88f805e1d Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:44:07 -0600 Subject: [PATCH 20/21] Fix bad references --- lib/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 2ecea4f..c5d9892 100644 --- a/lib/util.js +++ b/lib/util.js @@ -109,7 +109,7 @@ exports.convertPingsToGraph = function(sqlData) { var serverIps = getServerIps(); var graphData = {}; - var startTime = getCurrentTimeMs(); + var startTime = exports.getCurrentTimeMs(); for (var i = 0; i < sqlData.length; i++) { var entry = sqlData[i]; @@ -133,7 +133,7 @@ exports.convertPingsToGraph = function(sqlData) { // Drop old data. exports.trimOldPings(graphData); - logger.inf('Converted data structure in ' + (getCurrentTimeMs() - startTime) + 'ms'); + logger.inf('Converted data structure in ' + (exports.getCurrentTimeMs() - startTime) + 'ms'); return graphData; }; \ No newline at end of file From 08376575abaff6e4f89bf0539c78bbdaae78aced Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Mon, 1 Feb 2016 05:44:56 -0600 Subject: [PATCH 21/21] I should probably sleep. --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index c5d9892..de946a1 100644 --- a/lib/util.js +++ b/lib/util.js @@ -133,7 +133,7 @@ exports.convertPingsToGraph = function(sqlData) { // Drop old data. exports.trimOldPings(graphData); - logger.inf('Converted data structure in ' + (exports.getCurrentTimeMs() - startTime) + 'ms'); + logger.info('Converted data structure in ' + (exports.getCurrentTimeMs() - startTime) + 'ms'); return graphData; }; \ No newline at end of file