mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
feat: add unified Discord bot and dashboard
This commit is contained in:
1 parent
113bf9342e
commit
b11ae1dfa8
14 files changed
+1708
-14
No files matched your search
@@ -161,6 +161,26 @@ const THEME_PATH_PREFIX = "theme_"; // lib/http.js looks for this
|
||||
const chatLines = limits.limiter(config.chatLinesPerWindow, config.chatWindowMs);
|
||||
const online = new Map(); // lowercased username -> session
|
||||
const rooms = new Map(); // "path.name#shard" -> room
|
||||
const gameActivityListeners = new Set();
|
||||
|
||||
// An intentionally small, privacy-safe activity feed for optional
|
||||
// integrations. It names only the player and lifecycle event—never IPs,
|
||||
// device identifiers, game tokens or chat text.
|
||||
const gameActivity = entry => {
|
||||
for (const listener of gameActivityListeners) {
|
||||
try {
|
||||
listener(entry);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`[world] activity listener failed: ${logText(err.message)}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onGameActivity = listener => {
|
||||
gameActivityListeners.add(listener);
|
||||
return () => gameActivityListeners.delete(listener);
|
||||
};
|
||||
|
||||
// worlds (config.shards): a land room's name ends in "#<world>"; dens,
|
||||
// parties and adventures have none and belong to no world. each player has
|
||||
@@ -384,6 +404,7 @@ const login = (session, msg) => {
|
||||
accounts.save(account);
|
||||
online.set(key, session);
|
||||
console.log(`[world] ${logText(account.username)} logged in as sfs user ${logText(session.id)}`);
|
||||
gameActivity({type: "login", username: account.username, at: Math.floor(Date.now() / 1000)});
|
||||
session.sendXtJson(-1, {_cmd: "login", status: "1", params: loginParams(session)});
|
||||
// every custom colour, before anything that might be drawn with one
|
||||
// (XtReplyDemuxer -> PaletteHelper.handleCustomColors in the patched SWF).
|
||||
@@ -1379,6 +1400,8 @@ setInterval(() => {
|
||||
}, 60000).unref();
|
||||
|
||||
const leaveWorld = session => {
|
||||
const username = session.account && session.account.username;
|
||||
const playedSeconds = session.playStarted ? Math.max(0, Math.round((Date.now() - session.playStarted) / 1000)) : 0;
|
||||
minigames.leave(session);
|
||||
trades.forget(session);
|
||||
leaveRoom(session);
|
||||
@@ -1390,6 +1413,7 @@ const leaveWorld = session => {
|
||||
accounts.release(session.account);
|
||||
accounts.save(session.account);
|
||||
buddies.announce(session.account);
|
||||
gameActivity({type: "logout", username, at: Math.floor(Date.now() / 1000), playedSeconds});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2134,4 +2158,5 @@ module.exports = {
|
||||
room: session.room ? session.room.name.replace(/#(\d+)$/, (whole, id) => (worldOf(whole) ? ` (${worldName(Number(id))})` : whole)) : null,
|
||||
address: session.address,
|
||||
})),
|
||||
onGameActivity,
|
||||
};
|
||||
Reference in new issue
Block a user