Incomplete King Of The Hill code

This commit is contained in:
2019-06-09 17:13:52 +10:00
parent efc6e6f150
commit a6846fd456
4 changed files with 39 additions and 4 deletions
+15 -1
View File
@@ -7,7 +7,7 @@ let CronJob = require('cron').CronJob;
//utilities
let { log } = require('../common/utilities.js');
let { logActivity, getBadgesStatistics, getBadgesOwned } = require('./utilities.js');
let { logActivity, getBadgesStatistics, getBadgesOwned, getLadderData } = require('./utilities.js');
const listRequest = (connection) => (req, res) => {
getBadgesStatistics((err, results) => {
@@ -123,6 +123,20 @@ const runBadgeTicks = (connection) => {
});
combatMasterBadgeTickJob.start();
/*
//King Of The Hill
let kingOfTheHillBadgeTickJob = new CronJob('0 * * * * *', () => {
getLadderData(connection, 0, 1, (err, ladderResults) => {
if (err) throw err;
//TODO: pull badge names into variables. Not good.
let query = 'SELECT * FROM badgesTimespan WHERE qualifyTime >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) AND name = "King Of The Hill";';
connection.query(query, (err, results) => {
if (err) throw err;
});
});
});
*/
}
module.exports = {
+2 -3
View File
@@ -4,7 +4,7 @@ require('dotenv').config();
//libraries
let CronJob = require('cron').CronJob;
let { getBadgesStatistics, getBadgesOwned, isAttacking, isSpying, logActivity } = require('./utilities.js');
let { getBadgesStatistics, getBadgesOwned, isAttacking, isSpying, getLadderData, logActivity } = require('./utilities.js');
//utilities
let { logDiagnostics } = require('./diagnostics.js');
@@ -430,8 +430,7 @@ const untrainRequest = (connection) => (req, res) => {
};
const ladderRequest = (connection) => (req, res) => {
let query = 'SELECT accounts.id AS id, username, soldiers, recruits, gold FROM accounts JOIN profiles ON accounts.id = profiles.accountId ORDER BY soldiers DESC, recruits DESC, gold DESC LIMIT ?, ?;';
connection.query(query, [req.body.start, req.body.length], (err, results) => {
getLadderData(connection, req.body.start, req.body.length, (err, results) => {
if (err) throw err;
getBadgesStatistics((err, { statistics }) => {
+9
View File
@@ -109,6 +109,14 @@ const isSpying = (connection, user, cb) => {
});
};
const getLadderData = (connection, start, length, cb) => {
//moved here for reusability
let query = 'SELECT accounts.id AS id, username, soldiers, recruits, gold FROM accounts JOIN profiles ON accounts.id = profiles.accountId ORDER BY soldiers DESC, recruits DESC, gold DESC LIMIT ?, ?;';
connection.query(query, [start, length], (err, results) => {
cb(err, results);
});
};
const logActivity = (connection, id) => {
let query = 'UPDATE accounts SET lastActivityTime = CURRENT_TIMESTAMP() WHERE id = ?;';
connection.query(query, [id], (err) => {
@@ -123,5 +131,6 @@ module.exports = {
getBadgesOwned: getBadgesOwned,
isAttacking: isAttacking,
isSpying: isSpying,
getLadderData: getLadderData,
logActivity: logActivity
};
+13
View File
@@ -191,5 +191,18 @@ CREATE TABLE IF NOT EXISTS badges (
name VARCHAR(50) NOT NULL,
active BOOLEAN NOT NULL DEFAULT FALSE,
CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS badgesTimespan ( #for recording timespan-related badges
id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY UNIQUE,
td TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
accountId INTEGER UNSIGNED,
name VARCHAR(50) NOT NULL,
qualifyTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
);