kick/logout on channel/site rank change

This commit is contained in:
rainbow napkin 2024-12-01 20:09:45 -05:00
parent ebbdcbe295
commit 0432c9d1cc
3 changed files with 60 additions and 1 deletions

View file

@ -82,6 +82,61 @@ channelSchema.pre('save', async function (next){
}
}
//Getting the affected user would be a million times easier elsewhere
//But this ensures it happens every time channel rank gets changed no matter what
if(this.isModified('rankList')){
//Get the rank list before it was modified (gross but works, find a better way if you dont like it :P)
var chanDB = await module.exports.findOne({_id: this._id});
//Create empty variable for the found rank object
var foundRank = null;
//If we're removing one
if(chanDB.rankList.length > this.rankList.length){
//Child/Parent is *WAY* to atomic family for my tastes :P
var top = chanDB;
var bottom = this;
}else{
//otherwise reverse the loops
var top = this;
var bottom = chanDB;
}
//Populate the top doc
await top.populate('rankList.user');
top.rankList.forEach((topObj) => {
//Create empty variable for the matched rank
var matchedRank = null;
//For each rank in the old copy of the rank list
bottom.rankList.forEach((bottomObj) => {
if(topObj.user._id.toString() == bottomObj.user._id.toString()){
matchedRank = bottomObj;
}
});
if(matchedRank == null || matchedRank.rank != topObj.rank){
foundRank = topObj;
}
});
//get relevant active channel
const activeChan = server.channelManager.activeChannels.get(this.name);
//if the channel is online
if(activeChan != null){
//Get the relevant user connection
const userConn = activeChan.userList.get(foundRank.user.user);
//if the user is online
if(userConn != null){
//kick the user
userConn.disconnect("Your channel rank has changed!");
}
}
}
next();
});

View file

@ -112,6 +112,10 @@ userSchema.pre('save', async function (next){
}
}
if(this.isModified("rank")){
await this.killAllSessions();
}
//All is good, continue on saving.
next();
});

View file

@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
:root{
--main-font: "open-sans", sans-serif;
--main-font: "open-sans", system-ui;
--bg0: rgb(158, 158, 158);
--bg0-alpha0: rgba(158, 158, 158, 0.4);
--bg0-alpha1: rgba(158, 158, 158, 0.75);