Skip to content
Permalink
Browse files

Reimplemented spam blocker

  • Loading branch information...
grant committed Mar 23, 2014
1 parent 4159e5b commit 80e085d241bd16b63c480068eec7642273dcc342
Showing with 25 additions and 2 deletions.
  1. +12 −1 app.js
  2. +13 −1 public/js/keyboard_input_manager.js
13 app.js
@@ -98,9 +98,20 @@ io.sockets.on('connection', function (socket) {
});

// When someone moves
var numMovesPerSecond = 2;
var pastEvents = [];
for (var i = 0; i < numMovesPerSecond; i++) {
pastEvents.push(0);
}
socket.on('move', function (direction) {
if (democracy) {
if (!voted) {
// Keep track of events
pastEvents.push(new Date().getTime());
pastEvents.splice(0, pastEvents.length - numMovesPerSecond);

// Multiplayer
var spamming = pastEvents[pastEvents.length - 1] - pastEvents[0] < 1000;
if (!voted && !spamming) {
voted = true;
votes[direction]++;

@@ -11,10 +11,22 @@ KeyboardInputManager.prototype.on = function (event, callback) {
this.events[event].push(callback);
};

// Keep track of the past events (queue)
var numMovesPerSecond = 2;
var pastEvents = [];
for (var i = 0; i < numMovesPerSecond; i++) {
pastEvents.push(0);
}
KeyboardInputManager.prototype.emit = function (event, data) {
var callbacks = this.events[event];

if (Multiplayer[event]) {
// Keep track of events
pastEvents.push(new Date().getTime());
pastEvents.splice(0, pastEvents.length - numMovesPerSecond);

// Multiplayer
var spamming = pastEvents[pastEvents.length - 1] - pastEvents[0] < 1000;
if (Multiplayer[event] && !spamming) {
Multiplayer[event](data);
}
};

0 comments on commit 80e085d

Please sign in to comment.
You can’t perform that action at this time.