mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
closes #5017
This commit is contained in:
@@ -53,13 +53,9 @@ SocketModules.chats.newRoom = function(socket, data, callback) {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
var now = Date.now();
|
|
||||||
// Websocket rate limiting
|
if (rateLimitExceeded(socket)) {
|
||||||
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
|
|
||||||
if (now - socket.lastChatMessageTime < 200) {
|
|
||||||
return callback(new Error('[[error:too-many-messages]]'));
|
return callback(new Error('[[error:too-many-messages]]'));
|
||||||
} else {
|
|
||||||
socket.lastChatMessageTime = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Messaging.canMessageUser(socket.uid, data.touid, function(err) {
|
Messaging.canMessageUser(socket.uid, data.touid, function(err) {
|
||||||
@@ -76,14 +72,8 @@ SocketModules.chats.send = function(socket, data, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var now = Date.now();
|
if (rateLimitExceeded(socket)) {
|
||||||
|
|
||||||
// Websocket rate limiting
|
|
||||||
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
|
|
||||||
if (now - socket.lastChatMessageTime < 200) {
|
|
||||||
return callback(new Error('[[error:too-many-messages]]'));
|
return callback(new Error('[[error:too-many-messages]]'));
|
||||||
} else {
|
|
||||||
socket.lastChatMessageTime = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -100,7 +90,7 @@ SocketModules.chats.send = function(socket, data, callback) {
|
|||||||
Messaging.canMessageRoom(socket.uid, data.roomId, next);
|
Messaging.canMessageRoom(socket.uid, data.roomId, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Messaging.sendMessage(socket.uid, data.roomId, data.message, now, next);
|
Messaging.sendMessage(socket.uid, data.roomId, data.message, Date.now(), next);
|
||||||
},
|
},
|
||||||
function (message, next) {
|
function (message, next) {
|
||||||
Messaging.notifyUsersInRoom(socket.uid, data.roomId, message);
|
Messaging.notifyUsersInRoom(socket.uid, data.roomId, message);
|
||||||
@@ -110,6 +100,18 @@ SocketModules.chats.send = function(socket, data, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function rateLimitExceeded(socket) {
|
||||||
|
var now = Date.now();
|
||||||
|
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
|
||||||
|
var delay = meta.config.hasOwnProperty('chatMessageDelay') ? parseInt(meta.config.chatMessageDelay, 10) : 200;
|
||||||
|
if (now - socket.lastChatMessageTime < delay) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
socket.lastChatMessageTime = now;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SocketModules.chats.loadRoom = function(socket, data, callback) {
|
SocketModules.chats.loadRoom = function(socket, data, callback) {
|
||||||
if (!data || !data.roomId) {
|
if (!data || !data.roomId) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
|
|||||||
@@ -22,6 +22,12 @@
|
|||||||
<label>Maximum number of users in chat rooms</label>
|
<label>Maximum number of users in chat rooms</label>
|
||||||
<input type="text" class="form-control" value="0" data-field="maximumUsersInChatRoom">
|
<input type="text" class="form-control" value="0" data-field="maximumUsersInChatRoom">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Time between chat messages in milliseconds</label>
|
||||||
|
<input type="text" class="form-control" value="200" data-field="chatMessageDelay">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user