mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-10 07:11:53 +00:00
Merge pull request #167 from AngelRionCervi/remove-gatherer-timeout
kick after delay when afk
This commit is contained in:
commit
3a2abd76c9
5 changed files with 68 additions and 27 deletions
|
@ -28,6 +28,8 @@ npm install # Install deps
|
|||
npm run watch # Compile and watch frontend assets
|
||||
|
||||
RANDOM_USER=true npm run dev # Run dev server, loading yourself as a random user
|
||||
# or
|
||||
Fixed_USER=989 npm run dev # Run dev server, loading yourself as any user with the specified id
|
||||
```
|
||||
|
||||
## Run in production
|
||||
|
|
|
@ -933,7 +933,6 @@ const GathererListItem = React.createClass({
|
|||
let idleStatus;
|
||||
if (!gatherer.user.online) {
|
||||
const mins = lastSeenInMinutes(gatherer);
|
||||
|
||||
if (mins > 60) {
|
||||
const hours = Math.round(mins / 6) / 10;
|
||||
idleStatus = [
|
||||
|
|
|
@ -23,10 +23,23 @@ var assignRandomUser = (socket, next) => {
|
|||
});
|
||||
};
|
||||
|
||||
var assignFixedUser = (socket, next, userId) => {
|
||||
usersHelper.getFixedUser(userId, function (error, user) {
|
||||
if (error) {
|
||||
winston.error(error);
|
||||
return next(new Error("Authentication Failed"))
|
||||
}
|
||||
socket._user = user;
|
||||
return next();
|
||||
});
|
||||
};
|
||||
|
||||
var handleFailedAuth = (socket, next) => {
|
||||
if (process.env.RANDOM_USER) {
|
||||
return assignRandomUser(socket, next);
|
||||
} else {
|
||||
} else if (process.env.FIXED_USER) {
|
||||
return assignFixedUser(socket, next, process.env.FIXED_USER);
|
||||
} else {
|
||||
return next(new Error("Authentication Failed"));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@ const ArchivedGather = mongoose.model("ArchivedGather");
|
|||
const Event = mongoose.model("Event");
|
||||
const _ = require("lodash");
|
||||
const winston = require("winston");
|
||||
const kickTimeout = 300 // sec
|
||||
|
||||
module.exports = function (namespace) {
|
||||
const emitGather = (socket, gather) => {
|
||||
|
@ -33,7 +34,40 @@ module.exports = function (namespace) {
|
|||
type: gather ? gather.type : null,
|
||||
maps: Map.list,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const removeGatherer = (gather, user) => {
|
||||
let gatherLeaver = gather.getGatherer(user);
|
||||
|
||||
if (!gatherLeaver) {
|
||||
winston.info(`${user.username} ${user.id} attempted to leave ${gather.type} gather, but was not in gather.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (gather.can("removeGatherer")) {
|
||||
gather.removeGatherer(user);
|
||||
}
|
||||
if (user.cooldown) gather.applyCooldown(user);
|
||||
|
||||
Event.leaver(gatherLeaver.user);
|
||||
refreshGather(gather.type);
|
||||
}
|
||||
|
||||
|
||||
const removeAfkGathererTimer = (gather, user) => {
|
||||
const interval = setInterval(() => {
|
||||
if (gather.getGatherer(user).user.online) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
const now = Date.now();
|
||||
const awayDuration = (now / 1000) - (user.lastSeen / 1000);
|
||||
if (awayDuration >= kickTimeout) {
|
||||
console.log("kicked from being afk : ");
|
||||
removeGatherer(gather, user);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const refreshArchive = () => {
|
||||
ArchivedGather.recent((error, recentGathers) => {
|
||||
|
@ -72,12 +106,14 @@ module.exports = function (namespace) {
|
|||
if (gatherer.user.id == userId && gatherer.user.online) {
|
||||
gatherer.user.online = false;
|
||||
gatherer.user.lastSeen = Date.now();
|
||||
|
||||
removeAfkGathererTimer(gatherManager.current, { ...gatherer.user, cooldown: false });
|
||||
refreshGather(type);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
const gatherRefreshers = {}; // Stores debounced procedures to refresh gathers
|
||||
|
||||
|
@ -180,22 +216,7 @@ module.exports = function (namespace) {
|
|||
emitGather(socket, gatherManager.current)
|
||||
});
|
||||
|
||||
const removeGatherer = (gather, user) => {
|
||||
let gatherLeaver = gather.getGatherer(user);
|
||||
|
||||
if (!gatherLeaver) {
|
||||
winston.info(`${user.username} ${user.id} attempted to leave ${gather.type} gather, but was not in gather.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (gather.can("removeGatherer")) {
|
||||
gather.removeGatherer(user);
|
||||
}
|
||||
if (user.cooldown) gather.applyCooldown(user);
|
||||
|
||||
Event.leaver(gatherLeaver.user);
|
||||
refreshGather(gather.type);
|
||||
}
|
||||
|
||||
|
||||
socket.on("gather:leave", function (data) {
|
||||
if (!data) data = {};
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
"use strict";
|
||||
|
||||
var User = require("../user/user");
|
||||
var client = require("../ensl/client")();
|
||||
var async = require("async");
|
||||
const User = require("../user/user");
|
||||
|
||||
var getRandomUser = callback => {
|
||||
let id = Math.floor(Math.random() * 5000) + 1;
|
||||
const getRandomUser = callback => {
|
||||
const id = Math.floor(Math.random() * 5000) + 1;
|
||||
User.find(id, function (error, user) {
|
||||
if (error) return getRandomUser(callback);
|
||||
return callback(error, user);
|
||||
})
|
||||
};
|
||||
|
||||
const getFixedUser = (id, callback) => {
|
||||
User.find(id, function (error, user) {
|
||||
if (error) return getRandomUser(callback);
|
||||
return callback(error, user);
|
||||
|
@ -13,7 +18,8 @@ var getRandomUser = callback => {
|
|||
};
|
||||
|
||||
module.exports = {
|
||||
getRandomUser: getRandomUser
|
||||
getRandomUser,
|
||||
getFixedUser
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue