mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(chat): custom chat bubbles
Players choose how their chat bubble looks, and everyone sees it.
- style: a gradient of 2 to 5 colour stops (linear at any 45° step,
radial, or solid), its strength, text and border colours, outline
thickness 0-4, opacity 25-100%, and an animation (still, pulse, shimmer,
flow, rainbow) at 40-300% speed. lib/chatstyles.js keeps the one
canonical form: forgiving for saved accounts, strict for requests.
- in the game: Settings > Chat Bubble > Customize opens an editor with
presets (Ocean, Sunset, Forest, Midnight, Candy, Rainbow), a palette,
Swap, Random, Reset and Save, and a live preview. "Custom bubbles: Off"
draws everyone's bubbles normally on this computer only.
- on the web: the account page has a Chat bubble section with the same
choices.
- wire: xcs with no fields asks for the saved style, with twelve (or an
older client's 7, 10 or 11) saves it; the reply is the canonical twelve.
A typed line ("uc") carries its sender's style after the stock extra
field, only when it is not the default, so message and type stay where
the game reads them and unpatched clients are unaffected.
ajclient.swf is built with this and the six client commits before it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c1a85f9b5d
commit
83c2fc3b0b
14 files changed
+1697
-12
No files matched your search
@@ -61,6 +61,7 @@ const USER_VAR_SETTINGS = 363; // the settings menu's switches, a bit each (gui.
|
||||
// the chat filter an account starts with: level 1 slurs and threats, mode 1
|
||||
// the whole message left out (see account.filter below).
|
||||
const DEFAULT_FILTER = {level: 1, mode: 1, words: ""};
|
||||
const chatStyles = require("./chatstyles.js");
|
||||
const MAX_PASSWORD_LENGTH = 100;
|
||||
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
// parts of the game a player can switch off for their own account, each
|
||||
@@ -250,6 +251,9 @@ const normalize = account => {
|
||||
// the name tag: colour in the low byte, badge above it, bit 16 hides the
|
||||
// adventure level shape (avatar.NameBar.setColorAndBadge).
|
||||
account.nameBarData = Number.isInteger(account.nameBarData) ? account.nameBarData : 0;
|
||||
// Personal chat appearance. The renderer receives it with each spoken line
|
||||
// (lib/world.js), never as a client-controlled packet field.
|
||||
account.chatStyle = chatStyles.normalize(account.chatStyle);
|
||||
account.disguise = Number.isInteger(account.disguise) ? account.disguise : 0; // NPC id, see lib/disguises.js
|
||||
// shown on the player's card: lib/badges.js.
|
||||
account.discord = typeof account.discord === "string" ? account.discord : ""; // their Discord username, as Discord gave it (lib/discord.js)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
|
||||
// The style travels with a chat line, rather than with an avatar-create
|
||||
// packet, so a new choice takes effect immediately and is seen by everybody
|
||||
// who sees that line. Keep it small and entirely server-generated: clients
|
||||
// never get to choose the fields sent to other players.
|
||||
const DEFAULT = Object.freeze({background: "ffffff", accent: "dfe8ff", text: "445559", border: "9aabb0", opacity: 75,
|
||||
animation: "none", speed: 100, gradient: "linear", angle: 45, strength: 100, outline: 1,
|
||||
stops: "ffffff:0;dfe8ff:100"});
|
||||
const ANIMATIONS = new Set(["none", "pulse", "shimmer", "flow", "rainbow"]);
|
||||
const GRADIENTS = new Set(["solid", "linear", "radial"]);
|
||||
const COLOR = /^[0-9a-f]{6}$/i;
|
||||
|
||||
const color = (value, fallback) => typeof value === "string" && COLOR.test(value) ? value.toLowerCase() : fallback;
|
||||
const number = (value, fallback, low, high) => Number.isInteger(value) && value >= low && value <= high ? value : fallback;
|
||||
const direction = value => {
|
||||
const angle = number(value, DEFAULT.angle, 0, 315);
|
||||
return angle % 45 === 0 ? angle : DEFAULT.angle;
|
||||
};
|
||||
|
||||
const stops = (value, background, accent) => {
|
||||
if (typeof value === "string") {
|
||||
const parsed = value.split(";").map(stop => {
|
||||
const match = /^([0-9a-f]{6}):(100|[1-9]?\d)$/i.exec(stop);
|
||||
return match ? {color: match[1].toLowerCase(), position: Number(match[2])} : null;
|
||||
});
|
||||
if (parsed.length >= 2 && parsed.length <= 5 && parsed.every(Boolean)
|
||||
&& parsed[0].position === 0 && parsed.at(-1).position === 100
|
||||
&& parsed.every((stop, index) => index === 0 || stop.position > parsed[index - 1].position)) {
|
||||
return parsed.map(stop => `${stop.color}:${stop.position}`).join(";");
|
||||
}
|
||||
}
|
||||
return `${background}:0;${accent}:100`;
|
||||
};
|
||||
|
||||
const normalize = value => {
|
||||
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
||||
let background = color(source.background, DEFAULT.background);
|
||||
let accent = color(source.accent, DEFAULT.accent);
|
||||
const gradientStops = stops(source.stops, background, accent);
|
||||
const stopParts = gradientStops.split(";");
|
||||
background = stopParts[0].slice(0, 6);
|
||||
accent = stopParts.at(-1).slice(0, 6);
|
||||
return {
|
||||
background,
|
||||
accent,
|
||||
text: color(source.text, DEFAULT.text),
|
||||
border: color(source.border, DEFAULT.border),
|
||||
opacity: number(source.opacity, DEFAULT.opacity, 25, 100),
|
||||
animation: ANIMATIONS.has(source.animation) ? source.animation : DEFAULT.animation,
|
||||
speed: number(source.speed, DEFAULT.speed, 40, 300),
|
||||
gradient: GRADIENTS.has(source.gradient) ? source.gradient : DEFAULT.gradient,
|
||||
angle: direction(source.angle),
|
||||
strength: number(source.strength, DEFAULT.strength, 0, 100),
|
||||
outline: number(source.outline, DEFAULT.outline, 0, 4),
|
||||
stops: gradientStops,
|
||||
};
|
||||
};
|
||||
|
||||
const same = (one, two) => Object.keys(DEFAULT).every(key => one[key] === two[key]);
|
||||
|
||||
// `normalize` is intentionally forgiving when old account data is loaded.
|
||||
// Incoming editor requests are not: every field must already be canonical.
|
||||
const valid = value => Boolean(value) && typeof value === "object" && !Array.isArray(value)
|
||||
&& Object.keys(DEFAULT).every(key => value[key] === normalize(value)[key]);
|
||||
|
||||
const fields = value => {
|
||||
const style = normalize(value);
|
||||
return [style.background, style.accent, style.text, style.border, style.opacity, style.animation, style.speed,
|
||||
style.gradient, style.angle, style.strength, style.outline, style.stops];
|
||||
};
|
||||
|
||||
// Twelve comma-separated, URL-safe fields; empty means the original game bubble.
|
||||
const packet = value => {
|
||||
const style = normalize(value);
|
||||
return same(style, DEFAULT) ? "" : fields(style).join(",");
|
||||
};
|
||||
|
||||
module.exports = {DEFAULT, normalize, valid, fields, packet};
|
||||
@@ -24,6 +24,7 @@ const support = require("./support.js");
|
||||
const totp = require("./totp.js");
|
||||
const recoveryMail = require("./recoverymail.js");
|
||||
const world = require("./world.js");
|
||||
const chatStyles = require("./chatstyles.js");
|
||||
|
||||
// the account page at /account: what a player can do about their own
|
||||
// account from a browser. they sign in with the game's username and
|
||||
@@ -168,6 +169,7 @@ const profile = (account, from) => {
|
||||
logins: account.numLogins || 0,
|
||||
playtime: account.playtime,
|
||||
playtimePublic: account.playtimePublic,
|
||||
chatStyle: chatStyles.normalize(account.chatStyle),
|
||||
animals: account.avatars.length,
|
||||
animalType: avatar ? avatar.type : null,
|
||||
items: account.items.length,
|
||||
@@ -428,6 +430,17 @@ const act = (account, body, req, from, res) => {
|
||||
account.playtimePublic = body.on === true;
|
||||
accounts.save(account);
|
||||
return {ok: account.playtimePublic ? "Others can see your playtime on your card." : "Your playtime is private."};
|
||||
// A player can choose every colour, opacity, animation and animation
|
||||
// speed. Validation is deliberately here as well as in the page: saved
|
||||
// state is not trusted just because it came from our own browser UI.
|
||||
case "chatStyle": {
|
||||
if (!chatStyles.valid(body.style)) {
|
||||
return {error: "Choose valid chat colours and animation settings."};
|
||||
}
|
||||
account.chatStyle = chatStyles.normalize(body.style);
|
||||
accounts.save(account);
|
||||
return {ok: "Chat style saved. Your next message will use it."};
|
||||
}
|
||||
// their Discord account, for their card in the game: it is linked by
|
||||
// signing in to Discord (GET /account/discord/link), and only taken off
|
||||
// here, with the booster badge it brought.
|
||||
|
||||
+31
-1
@@ -21,6 +21,7 @@ const devices = require("./devices.js");
|
||||
const chatlog = require("./chatlog.js");
|
||||
const chatFilter = require("./chatfilter.js");
|
||||
const chatSpam = require("./chatspam.js");
|
||||
const chatStyles = require("./chatstyles.js");
|
||||
const buddyModule = require("./buddies.js");
|
||||
const dens = require("./dens.js");
|
||||
const disguises = require("./disguises.js");
|
||||
@@ -627,6 +628,10 @@ const sendFilter = session => {
|
||||
session.sendXt("xfl", -1, filter.chosen ? 1 : 0, filter.level, filter.mode, filter.words);
|
||||
};
|
||||
|
||||
// The in-game editor asks for this on demand too. It receives only canonical
|
||||
// values, so the Flash client never has to guess at a missing account field.
|
||||
const sendChatStyle = session => session.sendXt("xcs", -1, ...chatStyles.fields(session.account.chatStyle));
|
||||
|
||||
// the player called `username` as the senders above take one: their session
|
||||
// when they are playing, else just their account. A player's card can be
|
||||
// opened for anybody (the buddy list, the player search), and it asks for
|
||||
@@ -653,6 +658,25 @@ const handlers = {
|
||||
sendFilter(session);
|
||||
},
|
||||
|
||||
// The Settings > Chat Bubble popup. An empty request just reloads the
|
||||
// saved setting; a complete twelve-field request replaces it. Older custom
|
||||
// clients remain accepted and receive a two-stop gradient automatically.
|
||||
xcs(session, roomId, params) {
|
||||
if (params.length === 0) {
|
||||
sendChatStyle(session);
|
||||
return;
|
||||
}
|
||||
if (![7, 10, 11, 12].includes(params.length)) return;
|
||||
const [background, accent, text, border, opacity, animation, speed, gradient = "linear", angle = 45, strength = 100, outline = 1,
|
||||
stops = `${background}:0;${accent}:100`] = params;
|
||||
const style = {background, accent, text, border, opacity: Number(opacity), animation, speed: Number(speed),
|
||||
gradient, angle: Number(angle), strength: Number(strength), outline: Number(outline), stops};
|
||||
if (!chatStyles.valid(style)) return;
|
||||
session.account.chatStyle = style;
|
||||
accounts.save(session.account);
|
||||
sendChatStyle(session);
|
||||
},
|
||||
|
||||
// the patched client's hex colour picker (gui.ColorTable): [rgb1, rgb2,
|
||||
// rgb3, rgb4], the four colours of one layer. everyone online is told the
|
||||
// entry's id, the asker included, who then uses it as that layer's colour.
|
||||
@@ -1918,12 +1942,18 @@ module.exports = {
|
||||
// nobody hears a player they have blocked, and with chat switched
|
||||
// off nobody's typed lines arrive at all.
|
||||
// an invisible staff member's emotes and the like reach staff only.
|
||||
// Typed chat always gets a third (stock "extra") field, followed by
|
||||
// its style. Keeping message and type at their original indexes is
|
||||
// what clears the local "..." bubble; carrying the style on the
|
||||
// same packet prevents it being lost or applied to a later line.
|
||||
const style = echo ? chatStyles.packet(session.account.chatStyle) : "";
|
||||
for (const recipient of (echo || attachmentEcho) ? session.room.sessions : others(session)) {
|
||||
if (session.invisible && recipient !== session && !roles.isActiveStaff(recipient.account)) {
|
||||
continue;
|
||||
}
|
||||
if (recipient === session || (!blocks.has(recipient.account, session.account) && (!echo || accounts.featureOn(recipient.account, "chat")))) {
|
||||
recipient.sendXt("uc", session.room.id, session.id, ...fields);
|
||||
recipient.sendXt("uc", session.room.id, session.id,
|
||||
...(echo && style ? [fields[0], fields[1], fields[2] || "", style] : fields));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user