}
// The user has guessed both track and artist
- return spark.send('stoptrying');
+ spark.send('stoptrying');
};
/**
}
// Check if the sender can kick other players
- if ((role || 0) < 1) {
+ if (role < 1) {
return callback(false);
}
var target = sparks[who];
if (duration) {
- usersdb.setex(['ban:' + target.address.ip, duration, who], function(err) {
- if (err) {
- console.error(err.message);
- }
- });
+ usersdb.setex('ban:' + target.address.ip, duration, who);
}
target.send('chatmsg', notice, 'binb', who);
*/
var config = require('../config')
- , db = require('../lib/redis-clients').users
+ , db = require('./redis-clients').users
, forwarded = require('forwarded-for')
, fs = require('fs')
, minify = require('uglify-js').minify
room.onKick(who, why, spark.nickname, callback);
}
});
+ spark.on('unban', function(ip, callback) {
+ if (isString(ip) && isFunction(callback)) {
+ utils.unban(ip, spark, callback);
+ }
+ });
spark.on('unignore', function(who) {
if (isString(who)) {
room.onUnignore(who, spark.nickname);
+/**
+ * Module dependencies.
+ */
+
+var db = require('./redis-clients').users;
+
/**
* Convert the duration of a ban from minutes to seconds and return the value.
* Default duration is 15 minutes.
];
return params;
};
+
+/**
+ * Handle `unban` command.
+ */
+
+exports.unban = function(ip, spark, callback) {
+ var issuedby = spark.nickname;
+
+ db.hget(['user:' + issuedby, 'role'], function(err, role) {
+ if (err) {
+ console.error(err.message);
+ // Fail silently in case of error
+ return callback(true);
+ }
+
+ if (role < 1) {
+ return callback(false);
+ }
+
+ // At this point consider the command successfully executed
+ callback(true);
+
+ if (ip !== ':list') {
+ return db.del('ban:' + ip);
+ }
+
+ // List all banned players
+ db.keys(['ban:*'], function(err, replies) {
+ if (err) {
+ return console.error(err.message);
+ }
+
+ if (!replies.length) {
+ spark.send('chatmsg', 'the ban list is empty.', 'binb', issuedby);
+ return;
+ }
+
+ replies.forEach(function(key) {
+ var bannedip = key.slice(4);
+ db.get([key], function(err, reply) {
+ if (err) {
+ return console.error(err.message);
+ }
+ spark.send('chatmsg', bannedip + ' → ' + reply, 'binb', issuedby);
+ });
+ });
+ });
+ });
+};
addChatEntry(outcome);
};
+ // Unban a player
+ var unbanPlayer = function(args, outcome) {
+ outcome.append('you are not allowed to unban a player.');
+ if (!subscriber) {
+ return addChatEntry(outcome);
+ }
+
+ primus.send('unban', args[0], function(success) {
+ if (!success) {
+ addChatEntry(outcome);
+ }
+ });
+ };
+
// Remove a player from the ignore list
var unignorePlayer = function(args, outcome) {
if (!ignoredplayers[args[0]]) {
checkrecipient: true,
fn: punishPlayer('ban'),
minargs: 1,
- usage: 'usage: /ban <player name> [message] [duration]'
+ usage: 'usage: /ban <player> [<message>] [<duration>]'
},
clear: {
fn: function() {
minargs: 0
},
ignore: {
- checkrecipient: true, // Assume that the first argument (argv[0]) is the recipient
+ checkrecipient: true,
fn: ignorePlayer,
minargs: 1,
- usage: 'usage: /ignore <player name>'
+ usage: 'usage: /ignore <player>'
},
kick: {
checkrecipient: true,
fn: punishPlayer('kick'),
minargs: 1,
- usage: 'usage: /kick <player name> [message]'
+ usage: 'usage: /kick <player> [<message>]'
+ },
+ unban: {
+ fn: unbanPlayer,
+ minargs: 1,
+ usage: 'usage: /unban <IP>|:list'
},
unignore: {
checkrecipient: true,
fn: unignorePlayer,
minargs: 1,
- usage: 'usage: /unignore <player name>'
+ usage: 'usage: /unignore <player>'
}
};