Permalink
Browse files

Merge pull request #153 from Rylius/development

1.0.11
  • Loading branch information...
2 parents 16fa781 + 0d07bf8 commit 78c14b5b40fd3977e64fec06b6a985d428720e13 @Rylius committed on GitHub Jun 25, 2016
Showing with 74 additions and 42 deletions.
  1. +4 −1 app.js
  2. +8 −0 changes.json
  3. +3 −29 lib/game.js
  4. +22 −0 lib/users.js
  5. +1 −1 package.json
  6. +36 −11 routes/ajax/game.js
View
@@ -242,9 +242,12 @@ game.load(__dirname, config);
log.info('Loaded game data (' + game.cards.sets.length + ' sets, ' + game.cards.expansions.length + ' expansions, ' +
game.cards.blackCards.length + ' black cards, ' + game.cards.whiteCards.length + ' white cards' + ')');
+// bans
+users.loadBans();
+
// pages
-log.debug('Loading application...');
+log.debug('Loading application... (environment: ' + config.env + ')');
app.use(app.router);
View
@@ -1,5 +1,13 @@
[
{
+ "date": "Jun 25, 2016",
+ "version": "1.0.11",
+ "changes": [
+ "Improved ban list",
+ "Added CAH Creator watermarks"
+ ]
+ },
+ {
"date": "Jun 6, 2016",
"version": "1.0.10",
"changes": [
View
@@ -37,31 +37,6 @@ var trace = function (game, message) {
log.trace('Game ' + game.id + ': ' + message);
};
-/**
- * for converting a custom set card into the format for the game
- * @author tjhorner
- */
-var formatCustomSetCard = function(card, index, watermark){
- var cardText;
- if (card.text) { // then it's a black card
- cardText = card.text;
- } else if (typeof(card) === 'string') { // else it's white
- cardText = card;
- }
-
- // TODO Properly validate card data (string length, pick set to a reasonable number)
-
- return {
- id: -index,
- text: cardText,
- pick: card.pick,
- toJSON: function () {
- // yes, custom set IDs are negative.
- return {id: -index, text: cardText, watermark: watermark, pick: card.pick};
- }
- };
-};
-
var Player = function (user) {
this.user = user;
@@ -329,15 +304,14 @@ var Game = function (host) {
});
});
- var customCardIndex = 0;
_.forEach(this.customSets, function (deck) {
_.forEach(deck.blackCards, function (card) {
- self.blackCards.push(formatCustomSetCard(card, customCardIndex++, 'Custom'));
+ self.blackCards.push(card);
});
_.forEach(deck.whiteCards, function (card) {
- self.whiteCards.push(formatCustomSetCard(card, customCardIndex++, 'Custom'));
- self.allWhiteCards.push(formatCustomSetCard(card, customCardIndex++, 'Custom'));
+ self.whiteCards.push(card);
+ self.allWhiteCards.push(card);
});
});
View
@@ -2,6 +2,7 @@ var log = require('logule').init(module);
var _ = require('underscore');
var crypto = require('crypto');
+var fs = require('fs');
var Chat = require('./chat');
@@ -71,6 +72,7 @@ exports.findByName = function (name) {
exports.addBan = function (ip, name, reason) {
bans.push({ip: ip, name: name, reason: reason});
log.info('Added ban for IP ' + ip + ', name ' + name + ' (' + reason + ')');
+ exports.saveBans();
};
exports.findBan = function (ip) {
@@ -81,12 +83,32 @@ exports.findBan = function (ip) {
exports.removeBan = function (ban) {
bans.splice(_.indexOf(bans, ban), 1);
+ exports.saveBans();
};
exports.getBans = function () {
return bans;
};
+exports.loadBans = function () {
+ try {
+ var data = fs.readFileSync('bans.json');
+ bans = JSON.parse(data);
+ } catch (error) {
+ log.info('bans.json not found');
+ }
+};
+
+exports.saveBans = function () {
+ fs.writeFile('bans.json', JSON.stringify(bans), function (err) {
+ if (err) {
+ log.warn('Failed to save bans.json: ' + error);
+ return;
+ }
+ log.info('bans.json updated');
+ });
+};
+
exports.login = function (session, name, password, id, callback) {
log.trace('Attempting login for ' + name + '/' + id + ' (session: ' + (!!session) + ')');
View
@@ -1,6 +1,6 @@
{
"name": "cards-against-equestria",
- "version": "1.0.10",
+ "version": "1.0.11",
"homepage": "https://github.com/Rylius/CardsAgainstEquestria",
"private": true,
"scripts": {
View
@@ -120,27 +120,52 @@ var addSet = function (req, res) {
// Custom set has already been added, ignore
res.send(200);
} else if (deckId) {
- creatorApi.getDeck(deckId, function (deck) {
- if (!deck || deck.error) {
+ creatorApi.getDeck(deckId, function (deckData) {
+ if (!deckData || deckData.error) {
res.send(404);
return;
}
- deck.id = deckId;
+ var deck = {};
+
+ deck.id = 'custom-' + deckId + '-';
+ deck.expansion = true;
try {
// This does NOT make these strings 'safe'!
// Just avoiding a parser issue when embedding JSON in HTML.
// This is shit; all embedded JSON needs to be replaced with API calls.
- deck.name = deck.name.replace(/[<>]/g, ' ');
- deck.description = deck.description.replace(/[<>]/g, ' ');
-
- // Cards allow HTML so we need to make them safe here
- _.forEach(deck.blackCards, function (card) {
- card.text = xssFilters.inHTMLData(card.text);
+ deck.name = deckData.name.replace(/[<>]/g, ' ');
+ deck.description = deckData.description.replace(/[<>]/g, ' ');
+ if(deckData.watermark) {
+ deck.watermark = deckData.watermark.replace(/[<>]/g, '').substring(0, 12);
+ } else {
+ deck.watermark = 'Custom';
+ }
+
+ var cardId = 0;
+
+ deck.blackCards = _.map(deckData.blackCards, function (card) {
+ var text = xssFilters.inHTMLData(card.text);
+ var draw = card.draw ? +card.draw : 1;
+ var pick = card.pick ? +card.pick : 1;
+ var toJSON = function () {
+ return {id: card.id, text: card.text, watermark: card.watermark, draw: card.draw, pick: card.pick};
+ };
+
+ var obj = {id: deck.id + (cardId++), draw: draw, pick: pick, text: text, watermark: deck.watermark};
+ obj.toJSON = function () {
+ return obj;
+ };
+ return obj;
});
- deck.whiteCards = _.map(deck.whiteCards, function (text) {
- return xssFilters.inHTMLData(text);
+ deck.whiteCards = _.map(deckData.whiteCards, function (text) {
+ text = xssFilters.inHTMLData(text);
+ var card = {id: deck.id + (cardId++), text: text, watermark: deck.watermark};
+ card.toJSON = function () {
+ return card;
+ };
+ return card;
});
gameInstance.customSets.push(deck);

0 comments on commit 78c14b5

Please sign in to comment.