diff --git a/common/utilities.js b/common/utilities.js index 788431a..b854cf4 100644 --- a/common/utilities.js +++ b/common/utilities.js @@ -15,7 +15,9 @@ let excluded = [ //messages that should not be logged 'Profile sent', 'Ladder sent', 'attacking', - 'idle' + 'idle', + + 'Combat log sent' ]; const log = (msg, ...args) => { diff --git a/server/combat.js b/server/combat.js index 8d51099..97541fb 100644 --- a/server/combat.js +++ b/server/combat.js @@ -85,6 +85,16 @@ const attackStatusRequest = (connection) => (req, res) => { }); } +const combatLogRequest = (connection) => (req, res) => { + let query = 'SELECT pastCombat.*, atk.username AS attackerUsername, def.username AS defenderUsername FROM pastCombat JOIN accounts AS atk ON pastCombat.attackerId = atk.id JOIN accounts AS def ON pastCombat.defenderId = def.id WHERE def.username = ? ORDER BY eventTime DESC LIMIT ?, ?;'; + connection.query(query, [req.body.username, req.body.start, req.body.length], (err, results) => { + if (err) throw err; + + res.status(200).json(results); + log('Combat log sent', req.body.username, req.body.start, req.body.length, JSON.stringify(results)); + }); +} + const runCombatTick = (connection) => { let combatTick = new CronJob('* * * * * *', () => { //find each pending combat @@ -178,6 +188,7 @@ const isAttacking = (connection, user, cb) => { module.exports = { attackRequest: attackRequest, attackStatusRequest: attackStatusRequest, + combatLogRequest: combatLogRequest, runCombatTick: runCombatTick } diff --git a/server/index.js b/server/index.js index fc8b5b3..c4e2b86 100644 --- a/server/index.js +++ b/server/index.js @@ -43,6 +43,7 @@ profiles.runGoldTick(connection); let combat = require('./combat.js'); app.post('/attackrequest', combat.attackRequest(connection)); app.post('/attackstatusrequest', combat.attackStatusRequest(connection)); +app.post('/combatlogrequest', combat.combatLogRequest(connection)); combat.runCombatTick(connection); //static directories diff --git a/src/components/pages/home.jsx b/src/components/pages/home.jsx index 75c9742..ed6e67e 100644 --- a/src/components/pages/home.jsx +++ b/src/components/pages/home.jsx @@ -26,6 +26,7 @@ class Home extends React.Component {
Username:
-{this.state.username}
- - +Username:
+{this.state.username}
+ + +Gold:
+{this.state.gold}
+Recruits:
+{this.state.recruits}
+ +Soldiers:
+{this.state.soldiers}
+ + +Spies:
+{this.state.spies}
+ + +Scientists:
+{this.state.scientists}
+ + +Gold:
-{this.state.gold}
-Recruits:
-{this.state.recruits}
- -Soldiers:
-{this.state.soldiers}
- - -Spies:
-{this.state.spies}
- - -Scientists:
-{this.state.scientists}
- - -Username:
-{this.state.username}
- - -Username:
+{this.state.username}
+ + +Gold:
-{this.state.gold}
- - -Gold:
+{this.state.gold}
+ + +Recruits:
-{this.state.recruits}
-Recruits:
+{this.state.recruits}
+Soldiers:
-{this.state.soldiers}
- - -Soldiers:
+{this.state.soldiers}
+ + +Spies:
-{this.state.spies}
- - -Spies:
+{this.state.spies}
+ + +Scientists:
-{this.state.scientists}
- - +Scientists:
+{this.state.scientists}
+ + +Username:
-{this.state.username}
- - -Username:
+{this.state.username}
+ + +Gold:
-{this.state.gold}
- - -Gold:
+{this.state.gold}
+ + +Recruits:
-{this.state.recruits}
- - -Recruits:
+{this.state.recruits}
+ + +Soldiers:
-{this.state.soldiers}
- - -Soldiers:
+{this.state.soldiers}
+ + +Spies:
-{this.state.spies}
- - -Spies:
+{this.state.spies}
+ + +Scientists:
-{this.state.scientists}
- - +Scientists:
+{this.state.scientists}
+ + +When
+Attacker
+Attacking Force
+Defending Force
+Undefended?
+Victor
+Gold Lost
+Victor Casualties
+{ this.parseDate(this.state.data[key].eventTime) }
+{this.state.data[key].attackerUsername}
+{this.state.data[key].attackingUnits}
+{this.state.data[key].defendingUnits}
+{this.state.data[key].undefended ? 'yes' : 'no'}
+{this.state.data[key].victor}
+{this.state.data[key].spoilsGold}
+{this.state.data[key].casualtiesVictor}
+Username
-Soldiers
-Recruits
-Gold
+Username
+Soldiers
+Recruits
+Gold
{this.state.data[key].soldiers}
{this.state.data[key].recruits}
{this.state.data[key].gold}
{this.state.data[key].username}
+{this.state.data[key].soldiers}
+{this.state.data[key].recruits}
+{this.state.data[key].gold}
+