2015-07-22 16:28:15 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-07-29 13:50:39 +00:00
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2015-08-10 22:38:05 +00:00
|
|
|
var winston = require("winston");
|
|
|
|
var client = require(path.join(__dirname, "../ensl/client"))();
|
|
|
|
var serverFile = path.join(__dirname, "../../config/data/servers.json");
|
|
|
|
|
|
|
|
const REFRESH_INTERVAL = 1000 * 60 * 60; // Check every hour
|
2015-07-22 16:28:15 +00:00
|
|
|
|
|
|
|
function Server () {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-17 13:50:59 +00:00
|
|
|
Server.list = JSON.parse(fs.readFileSync(serverFile)).servers;
|
|
|
|
|
2015-08-10 23:12:27 +00:00
|
|
|
Server.updateServerList = () => {
|
|
|
|
client.getServers((error, result) => {
|
|
|
|
if (error) {
|
|
|
|
winston.error("Unable to download server list")
|
|
|
|
winston.error(error);
|
|
|
|
return;
|
|
|
|
};
|
2015-08-10 22:38:05 +00:00
|
|
|
Server.list = result.servers;
|
|
|
|
});
|
2015-08-10 23:12:27 +00:00
|
|
|
};
|
2015-08-10 22:38:05 +00:00
|
|
|
|
|
|
|
Server.updateServerList();
|
|
|
|
|
|
|
|
setInterval(Server.updateServerList, REFRESH_INTERVAL);
|
2015-07-29 13:50:39 +00:00
|
|
|
|
|
|
|
module.exports = Server;
|