Last active
August 29, 2015 14:22
-
-
Save AlexFrazer/1b531c85a07ac7db9153 to your computer and use it in GitHub Desktop.
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
Games = new Mongo.Collection("games"); | |
if (Meteor.isClient) { | |
Template.leaderboard.helpers({ | |
/** | |
* For user 'corvid', this should return both 'starcraft' and 'warcraft' | |
* because he is a player in the Roles.GLOBAL_GROUP | |
*/ | |
games: function () { | |
return Games.find({ | |
_id: { | |
$in: Roles.getRolesForUser(Meteor.userId(), 'player') | |
} | |
}); | |
}, | |
players: function (gameId) { | |
return Roles.getUsersInRole(gameId, 'player'); | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
var games = ['starcraft', 'warcraft']; | |
var starcraftPlayers = ['HuK', 'Idra', 'Bomber']; | |
var warcraftPlayers = ['swifty', 'HuK', 'kassiklaani']; | |
_.each(games, function (game) { | |
if (Games.find({ name: game }).count() === 0) { | |
Games.insert({ name: game }); | |
} | |
}); | |
var addPlayersToGame = function (playerList, group) { | |
_.each(playerList, function (p) { | |
if (Meteor.users.find({ "profile.name": p }).count() === 0) { | |
var userId = Accounts.createUser({ | |
profile: { name: p } | |
}); | |
Roles.addUsersToRoles(userId, 'player', group); | |
} | |
}); | |
} | |
// add all the warcraft players | |
addPlayersToGames(warcraftPlayers, Games.findOne({ name: 'warcraft' })._id); | |
addPlayersToGames(starcraftPlayers, Games.findOne({ name: 'starcraft' })._id); | |
addPlayersToGames(['corvid'], Roles.GLOBAL_GROUP); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment