Binato/server/Packets/Logout.js

30 lines
1,020 B
JavaScript
Raw Normal View History

const osu = require("osu-packet"),
consoleHelper = require("../../consoleHelper.js");
2020-08-27 13:09:35 +01:00
module.exports = function(CurrentUser) {
if (CurrentUser.uuid === "bot") throw "Tried to log bot out, WTF???";
const logoutStartTime = Date.now();
2020-08-27 13:09:35 +01:00
const streamList = global.StreamsHandler.getStreams();
2020-08-27 13:09:35 +01:00
for (let i = 0; i < streamList.length; i++) {
if (global.StreamsHandler.isUserInStream(streamList[i], CurrentUser.uuid)) {
global.StreamsHandler.removeUserFromStream(streamList[i], CurrentUser.uuid);
}
}
2020-08-27 13:09:35 +01:00
// Remove user from user list
global.users.remove(CurrentUser.uuid);
2020-08-27 13:09:35 +01:00
const osuPacketWriter = new osu.Bancho.Writer();
osuPacketWriter.SendMessage({
sendingClient: global.botUser.username,
message: `User ${CurrentUser.username} has logged out.`,
target: "#userlog",
senderId: global.botUser.id
});
global.StreamsHandler.sendToStream("#userlog", osuPacketWriter.toBuffer);
2020-08-27 13:09:35 +01:00
consoleHelper.printBancho(`User logged out, took ${Date.now() - logoutStartTime}ms. [User: ${CurrentUser.username}]`);
2020-08-27 13:09:35 +01:00
}