Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MongoDB saving and leaderboard integration
- Loading branch information
Showing
13 changed files
with
153 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var mongoose = require('mongoose'); | ||
var GlobalModel = require('./models/globalModel.js'); | ||
var UserInfo = require('./models/userInfo.js'); | ||
|
||
// Connect to MongoDB | ||
mongoose.connect('mongodb://localhost/ctf'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
// schema for global tracking of games played | ||
var GlobalModel = new Schema({ | ||
gamesPlayed : Number, | ||
redWins : Number, | ||
blueWins : Number, | ||
tags : Number, | ||
totalCaptures : Number | ||
}); | ||
|
||
module.exports = GlobalModel = mongoose.model('GlobalModel', GlobalModel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
// schema for tracking of users | ||
var UserInfoSchema = new Schema({ | ||
name : String, | ||
gamesPlayed : Number, | ||
wins : Number, | ||
losses : Number, | ||
tags : Number, | ||
captures : Number | ||
}) | ||
|
||
module.exports = UserInfo = mongoose.model('UserInfo', UserInfoSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
var app = angular.module('myApp', []); | ||
function leaderboard($scope, $http){ | ||
|
||
$http.get("/userInfo").success(function (response) { | ||
console.dir(response); | ||
$scope.names = response.records; | ||
}); | ||
}; | ||
var app = angular.module('ctf', []); | ||
|
||
function leaderboard($scope, $http) { | ||
$scope.leaderboardInit = function() { | ||
$http.get("/userInfo").success(function (response) { | ||
console.log(response); | ||
$scope.stats = response.stats; | ||
$scope.users = response.users; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,58 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
// MongoDB dependencies | ||
var mongoose = require('mongoose'); | ||
var GlobalModel = mongoose.model('GlobalModel'); | ||
var UserInfo = mongoose.model('UserInfo'); | ||
|
||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.render('index', { title: 'CTF' }); | ||
}); | ||
|
||
router.get('/leaderboard',function(req,res,next){ | ||
res.render('leaderboard',{title:'CTF'}); | ||
router.get('/leaderboard', function(req, res, next){ | ||
res.render('leaderboard', { title:'CTF Leaderboard' }); | ||
}); | ||
|
||
router.get('/userInfo', function(req, res, next) { | ||
// clear the db for testing purposes | ||
// response.stats = [{ | ||
// gamesPlayed : 100, | ||
// redWins : 50, | ||
// blueWins : 50, | ||
// tags : 14276, | ||
// totalCaptures : 2000 | ||
// }]; | ||
|
||
// newGlobal = new GlobalModel(response.stats); | ||
// newGlobal.save({}); | ||
|
||
// response.users = [ | ||
// { name: 'Plotka', gamesPlayed: 10, wins: 10, losses: 0, tags: 100, captures: 50 }, | ||
// { name: 'Shirly', gamesPlayed: 5, wins: 4, losses: 1, tags: 25, captures: 3 }, | ||
// { name: 'Ahmed', gamesPlayed: 20, wins: 10, losses: 10, tags: 250, captures: 25 } | ||
// ] | ||
|
||
// UserInfo.create(response.users, function(err, _) { | ||
// res.json(response); | ||
// }); | ||
|
||
UserInfo.find({}, function(err, users) { | ||
GlobalModel.find({}, function(err, stats) { | ||
res.json({ users: users, stats: stats }); | ||
}); | ||
}); | ||
}); | ||
|
||
router.post('game_results', function(req, res, next) { | ||
// Expects { gamesPlayed, redWins, blueWins, tags, totalCaptures } | ||
var stats = req.body.stats; | ||
console.log("yo" + req.body.stats); | ||
|
||
GlobalModel.update({}, stats, function() { | ||
res.json({ result: true }); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
extends layout | ||
html | ||
head | ||
title Capture The Flag | ||
|
||
block content | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} | ||
body | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters