The server don't send back anymore messages to their sender

This commit is contained in:
Yann Flory
2016-04-07 11:27:14 +02:00
parent eb4ea7a6b0
commit cf9f60bd57
4 changed files with 37 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ const LAG_MAX_BEFORE_PING = 15000;
const HISTORY_KEEPER_ID = Crypto.randomBytes(8).toString('hex');
const USE_HISTORY_KEEPER = true;
const USE_FILE_BACKUP_STORAGE = true;
let dropUser;
@@ -86,7 +87,7 @@ const handleMessage = function (ctx, user, msg) {
return;
}
let chanName = obj || randName();
sendMsg(ctx, user, [seq, 'ACK']);
sendMsg(ctx, user, [seq, 'JACK', chanName]);
let chan = ctx.channels[chanName] = ctx.channels[chanName] || [];
chan.id = chanName;
if (USE_HISTORY_KEEPER) {
@@ -131,11 +132,11 @@ const handleMessage = function (ctx, user, msg) {
let err;
let chan;
let idx;
if (!obj) { err = 'EINVAL'; }
if (!obj) { err = 'EINVAL'; obj = 'undefined';}
if (!err && !(chan = ctx.channels[obj])) { err = 'ENOENT'; }
if (!err && (idx = chan.indexOf(user)) === -1) { err = 'NOT_IN_CHAN'; }
if (err) {
sendMsg(ctx, user, [seq, 'ERROR', err]);
sendMsg(ctx, user, [seq, 'ERROR', err, obj]);
return;
}
sendMsg(ctx, user, [seq, 'ACK']);
@@ -153,7 +154,7 @@ let run = module.exports.run = function (storage, socketServer) {
let ctx = {
users: {},
channels: {},
store: LogStore.create('messages.log', storage)
store: (USE_FILE_BACKUP_STORAGE) ? LogStore.create('messages.log', storage) : storage
};
setInterval(function () {
Object.keys(ctx.users).forEach(function (userId) {
@@ -161,7 +162,7 @@ let run = module.exports.run = function (storage, socketServer) {
if (now() - u.timeOfLastMessage > LAG_MAX_BEFORE_DISCONNECT) {
dropUser(ctx, u);
} else if (!u.pingOutstanding && now() - u.timeOfLastMessage > LAG_MAX_BEFORE_PING) {
sendMsg(ctx, u, [0, 'PING', now()]);
sendMsg(ctx, u, [0, '', 'PING', now()]);
u.pingOutstanding = true;
}
});