BUGFIX: train, untrain, purchase, sell while spying
This commit is contained in:
@@ -24,8 +24,12 @@ let excluded = [ //messages that should not be logged
|
||||
|
||||
'Can\'t train while attacking',
|
||||
'Can\'t untrain while attacking',
|
||||
'Can\'t train while spying',
|
||||
'Can\'t untrain while spying',
|
||||
'Can\'t purchase while attacking',
|
||||
'Can\'t sell while attacking',
|
||||
'Can\'t purchase while spying',
|
||||
'Can\'t sell while spying',
|
||||
|
||||
'Purchase made',
|
||||
'Sale made',
|
||||
|
||||
+22
-2
@@ -4,7 +4,7 @@ require('dotenv').config();
|
||||
//utilities
|
||||
let { log } = require('../common/utilities.js');
|
||||
|
||||
let { getStatistics, getOwned, isAttacking } = require('./utilities.js');
|
||||
let { getStatistics, getOwned, isAttacking, isSpying } = require('./utilities.js');
|
||||
|
||||
const equipmentRequest = (connection) => (req, res) => {
|
||||
//validate the credentials
|
||||
@@ -95,6 +95,15 @@ const purchaseRequest = (connection) => (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
isSpying(connection, req.body.id, (err, spying) => {
|
||||
if (err) throw err;
|
||||
|
||||
if (spying) {
|
||||
res.status(400).write(log('Can\'t purchase while spying', req.body.id, req.body. token, req.body.type, req.body.name));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
//get the player's gold
|
||||
let query = 'SELECT gold, scientists FROM profiles WHERE accountId = ?;';
|
||||
connection.query(query, [req.body.id], (err, results) => {
|
||||
@@ -178,6 +187,7 @@ const purchaseRequest = (connection) => (req, res) => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const sellRequest = (connection) => (req, res) => {
|
||||
@@ -202,6 +212,15 @@ const sellRequest = (connection) => (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
isSpying(connection, req.body.id, (err, spying) => {
|
||||
if (err) throw err;
|
||||
|
||||
if (spying) {
|
||||
res.status(400).write(log('Can\'t sell while spying', req.body.id, req.body. token, req.body.type, req.body.name));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
//get the player's item quantity
|
||||
let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = ? AND name = ?;';
|
||||
connection.query(query, [req.body.id, req.body.type, req.body.name], (err, results) => {
|
||||
@@ -260,7 +279,8 @@ const sellRequest = (connection) => (req, res) => {
|
||||
log('Cleaned database', 'equipment sale');
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+21
-1
@@ -4,7 +4,7 @@ require('dotenv').config();
|
||||
//libraries
|
||||
let CronJob = require('cron').CronJob;
|
||||
|
||||
let { isAttacking } = require('./utilities.js');
|
||||
let { isAttacking, isSpying } = require('./utilities.js');
|
||||
|
||||
//utilities
|
||||
let { logDiagnostics } = require('./diagnostics.js');
|
||||
@@ -189,6 +189,15 @@ const trainRequest = (connection) => (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
isSpying(connection, req.body.id, (err, spying) => {
|
||||
if (err) throw err;
|
||||
|
||||
if (spying) {
|
||||
res.status(400).write(log('Can\'t train while spying', req.body.id));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
//determine the cost of the training TODO: make these global for the client too
|
||||
let cost = 0;
|
||||
switch(req.body.role) {
|
||||
@@ -255,6 +264,7 @@ const trainRequest = (connection) => (req, res) => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const untrainRequest = (connection) => (req, res) => {
|
||||
@@ -286,6 +296,15 @@ const untrainRequest = (connection) => (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
isSpying(connection, req.body.id, (err, spying) => {
|
||||
if (err) throw err;
|
||||
|
||||
if (spying) {
|
||||
res.status(400).write(log('Can\'t untrain while spying', req.body.id, req.body.token));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
//verify that the user has a high enough balance
|
||||
let query = 'SELECT soldiers, spies, scientists FROM profiles WHERE accountId = ?;';
|
||||
connection.query(query, [req.body.id], (err, results) => {
|
||||
@@ -357,6 +376,7 @@ const untrainRequest = (connection) => (req, res) => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const ladderRequest = (connection) => (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user