B
B
BonBon Slick2017-10-13 19:08:33
JavaScript
BonBon Slick, 2017-10-13 19:08:33

Limit the user on the number of messages in the chat by time?

Chat on sockets from the example, you can send as many messages as you like in it. I'm wondering how you can programmatically restrict a user from trying to send a bunch of messages in a short amount of time. Of course, validation must be set on the server, namely index.js as from the example.

https://socket.io/demos/chat/
https://socket.io/get-started/chat/

Session storage and cookies disappear as soon as the database. For logging and storing all this is a quiet horror ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Welaurs, 2017-10-13
@Welaurs

It may be unprofessional and inefficient, but if sessions, cookies and storage (the same Redis) disappear, then store everything in an object ...

var messagesInfo = {};

// Когда приходит сообщение
if(messagesInfo[nickname] < Date.getTime() / 1000) {
    // Не отправляем сообщение
    return false;
}
// Отправляем сообщение
messagesInfo[nickname] = Date.getTime() / 1000;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question