mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 17:37:50 -05:00
Compare commits
19
Commits
6645bf66b3
...
494f252c5b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
494f252c5b | ||
|
|
6b707fbc1d | ||
|
|
b45fd195df | ||
|
|
e2454447d9 | ||
|
|
0da5daabc9 | ||
|
|
3b53c8dab8 | ||
|
|
83c2fc3b0b | ||
|
|
c1a85f9b5d | ||
|
|
d44612bd08 | ||
|
|
9156c6e392 | ||
|
|
3930d2dabe | ||
|
|
9985ae7625 | ||
|
|
3139384ef3 | ||
|
|
e67fbe95e1 | ||
|
|
3423df10f8 | ||
|
|
8839f86e6c | ||
|
|
92ebb4d07c | ||
|
|
974f68490e | ||
|
|
43f2717b44 |
No files matched your search
@@ -5,6 +5,7 @@
|
||||
"cdn.jsdelivr.net",
|
||||
"challenges.cloudflare.com",
|
||||
"discord.com",
|
||||
"duckduckgo.com",
|
||||
"play.burrow.moe",
|
||||
"player.vimeo.com",
|
||||
"vision.googleapis.com",
|
||||
|
||||
@@ -101,6 +101,10 @@ module.exports = {
|
||||
// tried or an account is made, with both set. off without them.
|
||||
turnstile: env.AJ_TURNSTILE_SITE_KEY && env.AJ_TURNSTILE_SECRET
|
||||
? {siteKey: env.AJ_TURNSTILE_SITE_KEY, secret: env.AJ_TURNSTILE_SECRET} : null,
|
||||
// A stalled CAPTCHA provider must not consume all of the VPS's outbound
|
||||
// sockets. This only limits simultaneous verification requests; normal
|
||||
// players use one, and a rejected request can safely be retried.
|
||||
maxConcurrentCaptchaChecks: Math.max(1, Math.min(100, Number(env.AJ_CAPTCHA_MAX_CONCURRENT) || 24)),
|
||||
|
||||
// Account-recovery mail is delivered to this HTTPS webhook. It receives
|
||||
// {to, subject, text}; point it at the transactional-mail provider or
|
||||
|
||||
+33
-1
@@ -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)
|
||||
@@ -737,6 +741,34 @@ const register = (username, password, avatar = {}) => {
|
||||
return {account};
|
||||
};
|
||||
|
||||
// Public sign-ups can arrive in a burst. scryptSync is fine for the local,
|
||||
// legacy Create Account socket but it would freeze all players while each web
|
||||
// registration is derived. Keep the same validation and database insert on
|
||||
// the main thread, but derive its password on libuv's worker pool. Check the
|
||||
// username again after awaiting: another request may have claimed it first.
|
||||
const registerAsync = async (username, password, avatar = {}) => {
|
||||
username = typeof username === "string" ? username.trim() : username;
|
||||
let error = usernameProblem(username) || passwordProblem(password, username) || (defpacks.avatarDef(avatar.type) ? null : "choose_animal");
|
||||
if (error) {
|
||||
return {error};
|
||||
}
|
||||
const salt = crypto.randomBytes(16).toString("hex");
|
||||
const hash = await hashPasswordAsync(password, salt);
|
||||
error = usernameProblem(username) || passwordProblem(password, username) || (defpacks.avatarDef(avatar.type) ? null : "choose_animal");
|
||||
if (error) {
|
||||
return {error};
|
||||
}
|
||||
const type = Number(avatar.type);
|
||||
const account = insert(username, salt, hash, now(), {
|
||||
avatars: [newAvatar({perUserAvId: 1, avInvId: 1}, avatar.name || username, type, -1)],
|
||||
activeAvatar: 1,
|
||||
badges: byId.size < EARLY_MEMBERS ? [EARLY_BADGE] : [],
|
||||
recoveryEmail: typeof avatar.email === "string" && EMAIL_PATTERN.test(avatar.email.trim()) ? avatar.email.trim().toLowerCase() : "",
|
||||
});
|
||||
console.log(`[accounts] registered "${logText(username)}" (id ${logText(account.id)})`);
|
||||
return {account};
|
||||
};
|
||||
|
||||
const authenticate = (username, password) => {
|
||||
// "name" and "name " are the same account.
|
||||
const account = typeof username === "string" ? touch(byKey.get(username.trim().toLowerCase())) : null;
|
||||
@@ -954,4 +986,4 @@ const all = () => [...byId.values()];
|
||||
|
||||
const database = () => db;
|
||||
|
||||
module.exports = {FEATURES, featureOn, recordLogin, revokeTokens, load, save, flush, hold, release, startBackups, database, setLoginChoices, setPassword, rename, remove, setting, setSetting, hashPassword, register, usernameProblem, authenticate, authenticateAsync, issueToken, byToken, byName, nameOf, byId: accountById, newAvatar, freeAvatarSlot, all};
|
||||
module.exports = {FEATURES, featureOn, recordLogin, revokeTokens, load, save, flush, hold, release, startBackups, database, setLoginChoices, setPassword, rename, remove, setting, setSetting, hashPassword, register, registerAsync, usernameProblem, authenticate, authenticateAsync, issueToken, byToken, byName, nameOf, byId: accountById, newAvatar, freeAvatarSlot, all};
|
||||
+1
-1
@@ -282,7 +282,7 @@ const handle = async (route, params, body, from) => {
|
||||
if (!STARTER_ANIMALS.includes(avatarType)) {
|
||||
return {status: 400, body: {error: "choose_animal"}};
|
||||
}
|
||||
const result = accounts.register(username, password, {type: avatarType, email});
|
||||
const result = await accounts.registerAsync(username, password, {type: avatarType, email});
|
||||
if (result.account) {
|
||||
result.account.agreed = {version: config.termsVersion, at: Math.floor(Date.now() / 1000)};
|
||||
accounts.save(result.account);
|
||||
|
||||
@@ -97,6 +97,12 @@ module.exports = ({others, findOnline, findBySfsId, refreshForOthers, petFields}
|
||||
const messageRoom = session.room ? session.room.id : -1;
|
||||
const common = [1, session.id, avatar.perUserAvId, avatar.avInvId, avatar.customAvId, avatar.type, ...avatar.colors, avatar.name];
|
||||
session.sendXt("as", messageRoom, ...common, avatar.petInvId, avatar.questLevel || 0);
|
||||
// Nothing more goes to the switching player here. The client swaps the
|
||||
// animals during the transform animation (AvatarSwitch "hideAvatar"),
|
||||
// copying the in-world avatar into the switcher slot first and asking
|
||||
// for "ad" itself when it needs to. An unasked "ad"/"il" lands on the
|
||||
// in-world avatar before that copy, so the old animal vanished from the
|
||||
// switcher and the new one showed twice.
|
||||
if (session.pos) {
|
||||
for (const other of others(session)) {
|
||||
other.sendXt("as", messageRoom, ...common, ...petFields(activePet(account)), avatar.questLevel || 0);
|
||||
|
||||
+13
-1
@@ -26,10 +26,12 @@ const MAX_ANSWER_LENGTH = 2048;
|
||||
const PASS_MS = 600000;
|
||||
const PASS_USES = 5;
|
||||
const MAX_PASSES = 10000;
|
||||
const MAX_VERIFYING = config.maxConcurrentCaptchaChecks;
|
||||
|
||||
const on = Boolean(config.turnstile);
|
||||
const passes = new Map(); // SHA-256 of a pass -> {id: account id, key: address key, expiry, uses}
|
||||
const sha256 = text => crypto.createHash("sha256").update(String(text)).digest("hex");
|
||||
let verifying = 0;
|
||||
|
||||
// for the pages: what each answer means
|
||||
const MESSAGES = {
|
||||
@@ -70,6 +72,13 @@ const verify = async (answer, from, action) => {
|
||||
if (typeof answer !== "string" || !answer || answer.length > MAX_ANSWER_LENGTH) {
|
||||
return "captcha_required";
|
||||
}
|
||||
// A burst of valid-looking tokens should not turn an upstream Turnstile
|
||||
// slowdown into thousands of open fetches on this VPS. Refuse quickly;
|
||||
// the browser can reset its widget and retry after the short outage.
|
||||
if (verifying >= MAX_VERIFYING) {
|
||||
return "captcha_unavailable";
|
||||
}
|
||||
verifying++;
|
||||
const form = new URLSearchParams({secret: config.turnstile.secret, response: answer});
|
||||
if (!limits.isLoopback(from.address)) {
|
||||
form.set("remoteip", from.address);
|
||||
@@ -83,6 +92,9 @@ const verify = async (answer, from, action) => {
|
||||
console.log(`[captcha] cloudflare did not answer: ${logText(err.message)}`);
|
||||
return "captcha_unavailable";
|
||||
}
|
||||
finally {
|
||||
verifying--;
|
||||
}
|
||||
// an answer made for another form is no answer for this one. cloudflare's
|
||||
// test keys give none.
|
||||
if (!result || result.success !== true || (result.action && result.action !== action)) {
|
||||
@@ -107,7 +119,7 @@ const check = async (body, from, action, account) => {
|
||||
// a page's security policy: public/captcha.js always (the page calls it even
|
||||
// when off), and the widget too when it is on.
|
||||
const policy = csp => (on
|
||||
? `${csp.replace("script-src ", `script-src 'self' ${ORIGIN} `)}; frame-src ${ORIGIN}`
|
||||
? `${csp.replace("script-src ", `script-src 'self' ${ORIGIN} `).replace("connect-src ", `connect-src 'self' ${ORIGIN} `)}; frame-src ${ORIGIN}`
|
||||
: csp.replace("script-src ", "script-src 'self' "));
|
||||
|
||||
// a page with public/captcha.js asked for under a name that changes with the
|
||||
|
||||
@@ -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};
|
||||
+110
-26
@@ -42,6 +42,7 @@ const EPHEMERAL = 1 << 6;
|
||||
const STATUS_MESSAGE_SETTING = "discordBotStatusMessage";
|
||||
const STATUS_TITLE_SETTING = "discordBotStatusTitle";
|
||||
const STATUS_NOTE_SETTING = "discordBotStatusNote";
|
||||
const STATUS_BANNER_SETTING = "discordBotStatusBanner";
|
||||
const STATUS_EVERY_MS = 5 * 60000;
|
||||
const REPORT_BUTTON_PREFIX = "burrow:report:";
|
||||
const MAX_GITHUB_WEBHOOK_BYTES = 512 * 1024;
|
||||
@@ -71,18 +72,36 @@ let lastRaidAlertAt = 0;
|
||||
const safe = (value, max = 1000) => String(value === undefined || value === null ? "" : value)
|
||||
.replace(/@/g, "@\u200b").replace(/`/g, "'").replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, max);
|
||||
|
||||
// Discord fetches the banner itself, so only absolute http(s) URLs work.
|
||||
// Blank means the card has no banner; null means the URL was rejected.
|
||||
const bannerUrl = value => {
|
||||
const text = String(value || "").trim();
|
||||
if (!text) return "";
|
||||
try {
|
||||
const url = new URL(text);
|
||||
return /^https?:$/.test(url.protocol) && text.length <= 500 ? url.toString() : null;
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const statusSettings = () => ({
|
||||
title: safe(accounts.setting(STATUS_TITLE_SETTING) || "Burrow status", 80) || "Burrow status",
|
||||
note: safe(accounts.setting(STATUS_NOTE_SETTING) || "", 500),
|
||||
banner: bannerUrl(accounts.setting(STATUS_BANNER_SETTING)) || "",
|
||||
});
|
||||
|
||||
const setStatusSettings = ({title, note}) => {
|
||||
const setStatusSettings = ({title, note, banner}) => {
|
||||
const next = {
|
||||
title: safe(title || "Burrow status", 80) || "Burrow status",
|
||||
note: safe(note || "", 500),
|
||||
banner: bannerUrl(banner),
|
||||
};
|
||||
if (next.banner === null) return {error: "Banner must be an http(s) image URL of 500 characters or fewer, or blank for none."};
|
||||
accounts.setSetting(STATUS_TITLE_SETTING, next.title);
|
||||
accounts.setSetting(STATUS_NOTE_SETTING, next.note);
|
||||
accounts.setSetting(STATUS_BANNER_SETTING, next.banner);
|
||||
return next;
|
||||
};
|
||||
|
||||
@@ -223,6 +242,33 @@ const success = (title, sections, ephemeral = true) => card({title, sections, to
|
||||
const warning = (message, ephemeral = true) => card({title: "Burrow", sections: [message], tone: 0xfee75c, ephemeral});
|
||||
const failure = (message, ephemeral = true) => card({title: "Burrow", sections: [message], tone: 0xed4245, ephemeral});
|
||||
|
||||
// Staff audit streams use the same compact Components V2 pattern as SRP-Bot:
|
||||
// a brief summary, structured fields, and a durable log timestamp.
|
||||
const logCard = ({title, description = "", fields = [], tone = 0x5865f2}) => {
|
||||
const shown = fields.filter(field => field && field.name && field.value !== undefined && field.value !== null).slice(0, 12);
|
||||
const components = [{type: 10, content: [
|
||||
`## ${safe(title, 160)}`,
|
||||
description ? safe(description, 900) : "",
|
||||
].filter(Boolean).join("\n")}];
|
||||
|
||||
if (shown.length) {
|
||||
components.push({type: 14, divider: true, spacing: 1});
|
||||
components.push({type: 10, content: shown
|
||||
.map(field => `• **${safe(field.name, 80)}:** ${safe(field.value, 500)}`)
|
||||
.join("\n")
|
||||
.slice(0, 1800)});
|
||||
}
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
components.push({type: 14, divider: false, spacing: 1});
|
||||
components.push({type: 10, content: `_Logged <t:${now}:F> (<t:${now}:R>)_`});
|
||||
return {
|
||||
flags: COMPONENTS_V2,
|
||||
allowedMentions: {parse: []},
|
||||
components: [{type: 17, accent_color: tone, components}],
|
||||
};
|
||||
};
|
||||
|
||||
const commandDefinitions = () => [
|
||||
new SlashCommandBuilder().setName("burrow").setDescription("View Burrow server and player information")
|
||||
.addSubcommand(command => command.setName("status").setDescription("Show the live Burrow server status"))
|
||||
@@ -276,7 +322,9 @@ const commandDefinitions = () => [
|
||||
.addSubcommand(command => command.setName("close").setDescription("Close this support ticket")),
|
||||
].map(command => command.toJSON());
|
||||
|
||||
const actorFor = interaction => modpanel.discordBot.actor(interaction.user.id);
|
||||
// a command or button counts for a staff member signed in to the panel with
|
||||
// their 2FA code (modpanel.discordBot.commandActor): Discord alone is not them.
|
||||
const actorFor = interaction => modpanel.discordBot.commandActor(interaction.user.id);
|
||||
|
||||
const reportButton = report => new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder().setCustomId(`${REPORT_BUTTON_PREFIX}${report.id}:handled`).setLabel("Mark handled").setStyle(ButtonStyle.Success),
|
||||
@@ -302,12 +350,33 @@ const playerCard = player => success(`Player: ${player.username}`, [
|
||||
|
||||
const statusCard = status => {
|
||||
const settings = statusSettings();
|
||||
return card({title: settings.title, tone: 0x5865f2, sections: [
|
||||
settings.note ? `**Status message**\n${settings.note}` : "",
|
||||
`**Online**\n${status.players} players in ${status.rooms} room${status.rooms === 1 ? "" : "s"}`,
|
||||
`**Moderation queue**\n${status.reports} open report${status.reports === 1 ? "" : "s"}`,
|
||||
`**Server**\nUptime: <t:${Math.floor(Date.now() / 1000 - status.uptimeSeconds)}:R>\nMemory: ${status.memoryMb} MB`,
|
||||
]});
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const startedAt = now - status.uptimeSeconds;
|
||||
const rooms = `${status.rooms} room${status.rooms === 1 ? "" : "s"}`;
|
||||
const playUrl = new URL("gameClient/game/index.html", config.siteUrl).toString();
|
||||
|
||||
// This is intentionally public-only: moderation reports and queue depth are
|
||||
// staff data and do not belong in a community-facing server-status post.
|
||||
return {
|
||||
flags: COMPONENTS_V2,
|
||||
allowedMentions: {parse: []},
|
||||
components: [{
|
||||
type: 17,
|
||||
accent_color: 0x7c5ce7,
|
||||
components: [
|
||||
{type: 10, content: `## ${safe(settings.title, 80)}`},
|
||||
{type: 14, divider: true, spacing: 1},
|
||||
{type: 10, content: ["### STATUS", "🟢 **Online**", settings.note ? `\n${safe(settings.note, 500)}` : ""].filter(Boolean).join("\n")},
|
||||
{type: 14, divider: true, spacing: 1},
|
||||
{type: 10, content: `### PLAYERS\n\`${status.players} online\` • \`${rooms}\``},
|
||||
{type: 14, divider: true, spacing: 1},
|
||||
{type: 10, content: `### UPTIME\nStarted <t:${startedAt}:R> • ${status.memoryMb} MB memory`},
|
||||
...settings.banner ? [{type: 12, items: [{media: {url: settings.banner}}]}] : [],
|
||||
{type: 1, components: [{type: 2, style: 5, label: "Play Burrow", url: playUrl}]},
|
||||
{type: 10, content: `_Last updated <t:${now}:R>_`},
|
||||
],
|
||||
}],
|
||||
};
|
||||
};
|
||||
|
||||
const staffCard = staff => success("Burrow staff", staff.length
|
||||
@@ -476,7 +545,7 @@ const handleTicket = async interaction => {
|
||||
return;
|
||||
}
|
||||
const owner = ticketOwner(interaction.channel);
|
||||
const staff = actorFor(interaction);
|
||||
const staff = modpanel.discordBot.actor(interaction.user.id);
|
||||
if (!owner || (owner !== interaction.user.id && !staff)) {
|
||||
await interaction.editReply(failure("Only the ticket opener or linked Burrow staff can close this ticket."));
|
||||
return;
|
||||
@@ -528,7 +597,9 @@ const postCard = async (channelId, payload, label) => {
|
||||
const publishStatus = async () => {
|
||||
const channel = await channelFor(config.discord.statusChannelId);
|
||||
if (!channel) return {error: "The public status channel is not configured or the Discord bot is not connected."};
|
||||
const payload = statusCard({players: 0, rooms: 0, reports: reports.openCount(), uptimeSeconds: Math.floor(process.uptime()), memoryMb: Math.round(process.memoryUsage().rss / 1048576)});
|
||||
const players = world.players();
|
||||
const payload = statusCard({players: players.length, rooms: new Set(players.map(player => player.room).filter(Boolean)).size,
|
||||
reports: reports.openCount(), uptimeSeconds: Math.floor(process.uptime()), memoryMb: Math.round(process.memoryUsage().rss / 1048576)});
|
||||
// The public status card needs no staff actor; it exposes only aggregate
|
||||
// counts. Store its message id in the server database so restarts edit it.
|
||||
const saved = accounts.setting(STATUS_MESSAGE_SETTING);
|
||||
@@ -555,41 +626,54 @@ const notifyReport = async report => {
|
||||
|
||||
const notifyGameActivity = async entry => {
|
||||
const minutes = Math.max(1, Math.ceil((entry.playedSeconds || 0) / 60));
|
||||
const played = entry.type === "logout" ? `\nSession: ${minutes} minute${minutes === 1 ? "" : "s"}` : "";
|
||||
await postCard(config.discord.gameLogsChannelId, card({
|
||||
title: "In-game player activity",
|
||||
tone: entry.type === "login" ? 0x57f287 : 0x5865f2,
|
||||
sections: [`**${safe(entry.username, 40)}** ${entry.type === "login" ? "signed in" : "signed out"}.${played}`],
|
||||
const signedIn = entry.type === "login";
|
||||
await postCard(config.discord.gameLogsChannelId, logCard({
|
||||
title: "In-game activity",
|
||||
description: signedIn ? "A player signed in." : "A player signed out.",
|
||||
tone: signedIn ? 0x57f287 : 0x5865f2,
|
||||
fields: [
|
||||
{name: "Player", value: entry.username},
|
||||
{name: "Event", value: signedIn ? "Signed in" : "Signed out"},
|
||||
...(!signedIn ? [{name: "Session", value: `${minutes} minute${minutes === 1 ? "" : "s"}`}] : []),
|
||||
],
|
||||
}), "game activity log");
|
||||
};
|
||||
|
||||
const notifyModeration = async entry => {
|
||||
await postCard(config.discord.moderationLogsChannelId, card({
|
||||
await postCard(config.discord.moderationLogsChannelId, logCard({
|
||||
title: "Moderation audit",
|
||||
description: "A Burrow staff action was recorded.",
|
||||
tone: 0xfee75c,
|
||||
sections: [
|
||||
`**${safe(entry.by, 50)}** — ${safe(entry.action, 120)}`,
|
||||
entry.target ? `Player: **${safe(entry.target, 50)}**` : "",
|
||||
entry.detail ? `Details: ${safe(entry.detail, 500)}` : "",
|
||||
fields: [
|
||||
{name: "Staff", value: entry.by},
|
||||
{name: "Action", value: entry.action},
|
||||
...(entry.target ? [{name: "Player", value: entry.target}] : []),
|
||||
...(entry.detail ? [{name: "Details", value: entry.detail}] : []),
|
||||
],
|
||||
}), "moderation log");
|
||||
};
|
||||
|
||||
const notifyBot = async (interaction, action) => {
|
||||
const actor = modpanel.discordBot.actor(interaction.user.id);
|
||||
await postCard(config.discord.botLogsChannelId, card({
|
||||
await postCard(config.discord.botLogsChannelId, logCard({
|
||||
title: "Discord bot audit",
|
||||
description: "A Discord command or control was used.",
|
||||
tone: actor ? 0x5865f2 : 0xed4245,
|
||||
sections: [
|
||||
`Discord user: **${safe(interaction.user.username, 80)}** (\`${safe(interaction.user.id, 30)}\`)`,
|
||||
`Action: ${safe(action, 160)}`,
|
||||
actor ? `Linked staff account: **${safe(actor.username, 40)}**` : "No active linked Burrow staff account.",
|
||||
fields: [
|
||||
{name: "Discord user", value: `${interaction.user.username} (${interaction.user.id})`},
|
||||
{name: "Action", value: action},
|
||||
{name: "Linked staff account", value: actor ? actor.username : "No active linked Burrow staff account."},
|
||||
],
|
||||
}), "Discord bot audit log");
|
||||
};
|
||||
|
||||
const securityIncident = async (title, sections, detail = "") => {
|
||||
await postCard(config.discord.moderationLogsChannelId, card({title, tone: 0xed4245, sections}), "Discord security log");
|
||||
await postCard(config.discord.moderationLogsChannelId, logCard({
|
||||
title,
|
||||
description: "Discord security activity detected.",
|
||||
tone: 0xed4245,
|
||||
fields: [{name: "Details", value: sections.filter(Boolean).join("\n")}],
|
||||
}), "Discord security log");
|
||||
modlog.record("discord security", title.toLowerCase(), "", detail);
|
||||
};
|
||||
|
||||
|
||||
+2
-1
@@ -251,7 +251,8 @@ module.exports = ({findOnline, blocks}) => {
|
||||
// silenced: no words of their own reach anyone, in a card either.
|
||||
if (!to || to === account || !art.cards.includes(Number(card)) || !art.stamps.includes(Number(stamp))
|
||||
|| !accounts.featureOn(account, "jamagrams") || (isSilenced(account) && clean(message || "") !== "")
|
||||
|| !sendsPerTenMinutes.allow(account.id)) {
|
||||
// The client also skips its per-recipient cap for moderators.
|
||||
|| (!account.isModerator && !sendsPerTenMinutes.allow(account.id))) {
|
||||
reply(FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1008,6 +1008,10 @@ const handle = async (req, res) => {
|
||||
res.setHeader("Cache-Control", "public, max-age=86400");
|
||||
send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "ban-icon.png")), MIME[".png"]);
|
||||
return;
|
||||
case "GET /burrow-status-banner.png": // public banner used by the Discord status card
|
||||
res.setHeader("Cache-Control", "public, max-age=86400");
|
||||
send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "burrow-status-banner.png")), MIME[".png"]);
|
||||
return;
|
||||
case "GET /bio-icon.png": // the button of the card's Bio tab
|
||||
res.setHeader("Cache-Control", "public, max-age=86400");
|
||||
send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "bio-icon.png")), MIME[".png"]);
|
||||
|
||||
+31
-1
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const net = require("net");
|
||||
const config = require("../config.js");
|
||||
|
||||
// small in-memory rate limits for the parts of the server that strangers can
|
||||
@@ -28,6 +29,25 @@ const key = address => {
|
||||
|
||||
const isLoopback = address => LOOPBACK.includes(String(address || "").replace(/^::ffff:/i, ""));
|
||||
|
||||
// the addresses Cloudflare's edge connects from, as it publishes them at
|
||||
// https://www.cloudflare.com/ips/ (they seldom change; add any new range here).
|
||||
const CLOUDFLARE = new net.BlockList();
|
||||
for (const range of ["173.245.48.0/20", "103.21.244.0/22", "103.22.200.0/22", "103.31.4.0/22", "141.101.64.0/18",
|
||||
"108.162.192.0/18", "190.93.240.0/20", "188.114.96.0/20", "197.234.240.0/22", "198.41.128.0/17", "162.158.0.0/15",
|
||||
"104.16.0.0/13", "104.24.0.0/14", "172.64.0.0/13", "131.0.72.0/22"]) {
|
||||
const [prefix, bits] = range.split("/");
|
||||
CLOUDFLARE.addSubnet(prefix, Number(bits), "ipv4");
|
||||
}
|
||||
for (const range of ["2400:cb00::/32", "2606:4700::/32", "2803:f800::/32", "2405:b500::/32", "2405:8100::/32",
|
||||
"2a06:98c0::/29", "2c0f:f248::/32"]) {
|
||||
const [prefix, bits] = range.split("/");
|
||||
CLOUDFLARE.addSubnet(prefix, Number(bits), "ipv6");
|
||||
}
|
||||
const fromCloudflare = address => {
|
||||
const family = net.isIP(address);
|
||||
return family !== 0 && CLOUDFLARE.check(address, family === 4 ? "ipv4" : "ipv6");
|
||||
};
|
||||
|
||||
// is this address the server's own machine, and does that count for
|
||||
// anything here? (It must not when a local reverse proxy forwards everyone.)
|
||||
const isTrustedLocal = address => config.trustLocalRequests && isLoopback(address);
|
||||
@@ -45,7 +65,17 @@ const clientOf = req => {
|
||||
const own = String(req.socket.remoteAddress || "").replace(/^::ffff:/i, "");
|
||||
const forwarded = req.headers["x-forwarded-for"] || req.headers.forwarded || req.headers["cf-connecting-ip"] || req.headers["x-real-ip"];
|
||||
const hops = String(req.headers["x-forwarded-for"] || "").split(",").map(hop => hop.trim()).filter(Boolean);
|
||||
const address = config.trustedProxy && isLoopback(own) && hops.length ? hops[hops.length - 1].replace(/^::ffff:/i, "").slice(0, 60) : own;
|
||||
// the last X-Forwarded-For entry is the one the local proxy appended: who
|
||||
// connected to it (the first is whatever the visitor sent, so it is never
|
||||
// used). Behind Cloudflare that is Cloudflare's own edge, which made every
|
||||
// visitor one address (and left remoteip out of the Turnstile check), so
|
||||
// then CF-Connecting-IP is the visitor. Only when that hop is Cloudflare:
|
||||
// anyone who reaches the server directly can send the header too. Neither
|
||||
// header counts unless the local reverse proxy has been trusted.
|
||||
const lastHop = (hops.at(-1) || "").replace(/^::ffff:/i, "");
|
||||
const cloudflareAddress = String(req.headers["cf-connecting-ip"] || "").trim().replace(/^::ffff:/i, "");
|
||||
const reported = net.isIP(cloudflareAddress) && fromCloudflare(lastHop) ? cloudflareAddress : lastHop;
|
||||
const address = config.trustedProxy && isLoopback(own) && reported ? reported.replace(/^::ffff:/i, "").slice(0, 60) : own;
|
||||
const direct = isLoopback(own) && !forwarded;
|
||||
return {address, key: key(address), direct, local: direct && config.trustLocalRequests};
|
||||
};
|
||||
|
||||
+53
-5
@@ -24,6 +24,8 @@ 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");
|
||||
const roles = require("./roles.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
|
||||
@@ -63,6 +65,20 @@ const failuresByAddress = limits.limiter(config.failedLoginsPerTenMinutes, TEN_M
|
||||
const WRONG_PASSWORDS_ALLOWED = 5;
|
||||
const wrongPasswords = limits.limiter(WRONG_PASSWORDS_ALLOWED, TEN_MINUTES_MS);
|
||||
const recoveryRequests = limits.limiter(5, TEN_MINUTES_MS);
|
||||
// recovery mail sent for one account, from any address: a few an hour.
|
||||
const recoveryMailsPerAccount = limits.limiter(3, 3600000);
|
||||
// a 2FA reset by email waits this long after a password reset by email, so
|
||||
// that someone who has only the mailbox cannot do one after the other.
|
||||
const EMAIL_RESET_GAP_MS = 7 * 24 * 3600000;
|
||||
// why a 2FA reset by email cannot be done for this account now, or null.
|
||||
// it also needs the account's password (recover/complete). staff ask the
|
||||
// admin (lib/panel.js), whose 2FA reset ends their role's use until they
|
||||
// turn it on again: a mailbox must not make someone staff.
|
||||
const twoStepResetProblem = account => roles.roleOf(account)
|
||||
? "Staff accounts cannot remove 2FA by email. Ask the admin."
|
||||
: account.emailPasswordResetAt && Date.now() - account.emailPasswordResetAt < EMAIL_RESET_GAP_MS
|
||||
? "2FA cannot be removed by email within 7 days of a password reset by email."
|
||||
: null;
|
||||
// what may be done from the page of a ban (above).
|
||||
const BANNED_MAY = ["password", "twoStepStart", "twoStepConfirm", "twoStepOff", "forgetDevices", "delete", "appeal"];
|
||||
// and from the page of a rejected username: the same, with a new name in
|
||||
@@ -168,6 +184,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 +445,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.
|
||||
@@ -551,7 +579,8 @@ const handle = async (req, res, url, from, web) => {
|
||||
const account = accounts.byName(String(body.username || ""));
|
||||
const email = String(body.email || "").trim().toLowerCase();
|
||||
const kind = body.kind === "twoStep" ? "twoStep" : "password";
|
||||
if (account && account.recoveryEmail && account.recoveryEmail === email && recoveryMail.available()) {
|
||||
if (account && account.recoveryEmail && account.recoveryEmail === email && recoveryMail.available()
|
||||
&& recoveryMailsPerAccount.allow(account.id)) {
|
||||
const token = crypto.randomBytes(32).toString("hex");
|
||||
account.recoveryTokens = (account.recoveryTokens || []).filter(entry => entry.expires > Date.now());
|
||||
account.recoveryTokens.push({hash: recoveryHash(token), kind, expires: Date.now() + RECOVERY_TOKEN_MS});
|
||||
@@ -571,7 +600,8 @@ const handle = async (req, res, url, from, web) => {
|
||||
const token = String(body.token || "");
|
||||
const account = [...accounts.all()].find(candidate => (candidate.recoveryTokens || []).some(entry => entry.hash === recoveryHash(token) && entry.expires > Date.now()));
|
||||
const entry = account && account.recoveryTokens.find(candidate => candidate.hash === recoveryHash(token) && candidate.expires > Date.now());
|
||||
reply(entry ? 200 : 400, entry ? {kind: entry.kind} : {error: "This recovery link is invalid or expired."});
|
||||
const refused = entry && entry.kind === "twoStep" ? twoStepResetProblem(account) : null;
|
||||
reply(entry && !refused ? 200 : 400, entry && !refused ? {kind: entry.kind} : {error: refused || "This recovery link is invalid or expired."});
|
||||
return;
|
||||
}
|
||||
case "POST /account/api/recover/complete": {
|
||||
@@ -588,10 +618,28 @@ const handle = async (req, res, url, from, web) => {
|
||||
reply(400, {error: problem === "weak_password" ? "That password is too easy to guess." : "Use 10+ characters with an uppercase letter, lowercase letter and digit."});
|
||||
return;
|
||||
}
|
||||
account.emailPasswordResetAt = Date.now();
|
||||
}
|
||||
else if (totp.isOn(account)) {
|
||||
totp.turnOff(account);
|
||||
accounts.revokeTokens(account);
|
||||
else {
|
||||
const refused = twoStepResetProblem(account);
|
||||
if (refused) {
|
||||
reply(400, {error: refused});
|
||||
return;
|
||||
}
|
||||
// the mailbox and the password: the link alone does not remove 2FA.
|
||||
if (!from.local && failuresByAddress.blocked(from.key)) {
|
||||
reply(429, {error: "Too many attempts. Try later."});
|
||||
return;
|
||||
}
|
||||
if (await accounts.authenticateAsync(account.username, body.password) !== account) {
|
||||
failuresByAddress.record(from.key);
|
||||
reply(401, {error: "Wrong password."});
|
||||
return;
|
||||
}
|
||||
if (totp.isOn(account)) {
|
||||
totp.turnOff(account);
|
||||
accounts.revokeTokens(account);
|
||||
}
|
||||
}
|
||||
account.recoveryTokens = [];
|
||||
accounts.save(account);
|
||||
|
||||
+105
-14
@@ -30,6 +30,7 @@ const sfs = require("./sfs.js");
|
||||
const support = require("./support.js");
|
||||
const totp = require("./totp.js");
|
||||
const world = require("./world.js");
|
||||
const {logText} = require("./logtext.js");
|
||||
|
||||
// the moderator panel at /mod: what a moderator needs to look after the
|
||||
// players, and no more. it is apart from the admin panel (lib/panel.js),
|
||||
@@ -66,7 +67,17 @@ const PROJECT_ROOT = path.resolve(__dirname, "..");
|
||||
const failuresByAddress = limits.limiter(config.failedLoginsPerTenMinutes, TEN_MINUTES_MS);
|
||||
const actionsPerTenMinutes = limits.limiter(300, TEN_MINUTES_MS); // per moderator
|
||||
|
||||
const sessions = new Map(); // SHA-256 of a session token -> {id: account id, expiry: ms}
|
||||
// SHA-256 of a session token -> {id: account id, expiry: ms, code}. `code`:
|
||||
// a 2FA code was given for it (the password sign-in, and Discord's with a
|
||||
// code after it), which the Discord bot's commands need (discordCommandActor).
|
||||
const sessions = new Map();
|
||||
// a Discord sign-in waiting for its 2FA code: SHA-256 of the token in its
|
||||
// cookie -> {id, expiry, tries}. Discord says who it is; the code says it is
|
||||
// still them, as the password sign-in asks.
|
||||
const pendingDiscord = new Map();
|
||||
const PENDING_COOKIE = "ajc_mod_pending";
|
||||
const PENDING_MINUTES = 5;
|
||||
const PENDING_TRIES = 5;
|
||||
const addressSearched = new Map(); // moderator's account id -> the address they last searched for
|
||||
|
||||
const sha256 = text => crypto.createHash("sha256").update(text).digest("hex");
|
||||
@@ -127,7 +138,12 @@ const cookieHeader = (token, maxAgeSeconds) =>
|
||||
const discordCookie = (value, maxAgeSeconds) =>
|
||||
`${DISCORD_COOKIE}=${value}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${maxAgeSeconds}${config.secureCookies ? "; Secure" : ""}`;
|
||||
|
||||
const beginSession = (account, res, address, detail = "") => {
|
||||
const pendingCookieHeader = (token, maxAgeSeconds) =>
|
||||
`${PENDING_COOKIE}=${token}; Path=/; HttpOnly; SameSite=Strict; Max-Age=${maxAgeSeconds}${config.secureCookies ? "; Secure" : ""}`;
|
||||
const pendingToken = req => (new RegExp(`(?:^|;\\s*)${PENDING_COOKIE}=([0-9a-f]{48})(?:;|$)`).exec(req.headers.cookie || "") || [])[1] || null;
|
||||
|
||||
// `extraCookies` go out with the session's own.
|
||||
const beginSession = (account, res, address, detail = "", code = true, extraCookies = []) => {
|
||||
accounts.recordLogin(account, "mod", address);
|
||||
accounts.save(account);
|
||||
for (const [hash, session] of sessions) {
|
||||
@@ -136,8 +152,8 @@ const beginSession = (account, res, address, detail = "") => {
|
||||
}
|
||||
}
|
||||
const token = crypto.randomBytes(24).toString("hex");
|
||||
sessions.set(sha256(token), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000});
|
||||
res.setHeader("Set-Cookie", cookieHeader(token, SESSION_HOURS * 3600));
|
||||
sessions.set(sha256(token), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000, code});
|
||||
res.setHeader("Set-Cookie", [cookieHeader(token, SESSION_HOURS * 3600), ...extraCookies]);
|
||||
modlog.record(account.username, "signed in", "", detail);
|
||||
};
|
||||
|
||||
@@ -159,6 +175,11 @@ const forget = account => {
|
||||
sessions.delete(hash);
|
||||
}
|
||||
}
|
||||
for (const [hash, pending] of pendingDiscord) {
|
||||
if (pending.id === account.id) {
|
||||
pendingDiscord.delete(hash);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const playerRow = (account, playing) => {
|
||||
@@ -433,13 +454,22 @@ const handle = async (req, res, url, from, web) => {
|
||||
result.ok = false;
|
||||
result.error = "denied";
|
||||
}
|
||||
// Discord has said who this is; the panel opens once their 2FA code is
|
||||
// given too (POST /mod/api/discord/code), so a Discord account alone,
|
||||
// taken over or linked by someone else, opens nothing.
|
||||
const cookies = [discordCookie("", 0)];
|
||||
if (result.ok) {
|
||||
beginSession(result.account, res, from.address, "through Discord");
|
||||
console.log(`[mod] ${result.account.username} signed in with Discord from ${from.address}`);
|
||||
for (const [hash, pending] of pendingDiscord) {
|
||||
if (pending.expiry < Date.now()) {
|
||||
pendingDiscord.delete(hash);
|
||||
}
|
||||
}
|
||||
const token = crypto.randomBytes(24).toString("hex");
|
||||
pendingDiscord.set(sha256(token), {id: result.account.id, expiry: Date.now() + PENDING_MINUTES * 60000, tries: 0});
|
||||
cookies.push(pendingCookieHeader(token, PENDING_MINUTES * 60));
|
||||
}
|
||||
const sessionCookie = res.getHeader("Set-Cookie");
|
||||
res.setHeader("Set-Cookie", sessionCookie ? [sessionCookie, discordCookie("", 0)] : discordCookie("", 0));
|
||||
res.writeHead(302, {Location: `/dashboard/staff?discord=${result.ok ? "ok" : result.error}`});
|
||||
res.setHeader("Set-Cookie", cookies);
|
||||
res.writeHead(302, {Location: `/dashboard/staff?discord=${result.ok ? "code" : result.error}`});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
@@ -503,12 +533,52 @@ const handle = async (req, res, url, from, web) => {
|
||||
}
|
||||
}
|
||||
const token = crypto.randomBytes(24).toString("hex");
|
||||
sessions.set(sha256(token), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000});
|
||||
sessions.set(sha256(token), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000, code: true});
|
||||
res.setHeader("Set-Cookie", cookieHeader(token, SESSION_HOURS * 3600));
|
||||
modlog.record(account.username, "signed in");
|
||||
reply(200, {ok: true, username: account.username});
|
||||
return;
|
||||
}
|
||||
// the second half of a Discord sign-in (GET /mod/discord/callback): the
|
||||
// account's 2FA code, from the browser Discord sent back here. a few
|
||||
// wrong codes and the sign-in is gone; it must start again at Discord.
|
||||
case "POST /mod/api/discord/code": {
|
||||
if (!from.local && failuresByAddress.blocked(from.key)) {
|
||||
reply(429, {error: "Too many attempts. Try later."});
|
||||
return;
|
||||
}
|
||||
const token = pendingToken(req);
|
||||
const hash = token ? sha256(token) : null;
|
||||
const pending = hash ? pendingDiscord.get(hash) : null;
|
||||
const account = pending && pending.expiry > Date.now() ? accounts.byId(pending.id) : null;
|
||||
if (!account || !mayModerate(account)) {
|
||||
if (hash) {
|
||||
pendingDiscord.delete(hash);
|
||||
}
|
||||
res.setHeader("Set-Cookie", pendingCookieHeader("", 0));
|
||||
reply(401, {error: "The Discord sign-in expired. Sign in with Discord again.", expired: true});
|
||||
return;
|
||||
}
|
||||
if (!totp.verify(account, String(body.code || ""))) {
|
||||
failuresByAddress.record(from.key);
|
||||
accounts.recordLogin(account, "mod", from.address, false);
|
||||
accounts.save(account);
|
||||
pending.tries++;
|
||||
if (pending.tries >= PENDING_TRIES) {
|
||||
pendingDiscord.delete(hash);
|
||||
res.setHeader("Set-Cookie", pendingCookieHeader("", 0));
|
||||
reply(401, {error: "Too many wrong codes. Sign in with Discord again.", expired: true});
|
||||
return;
|
||||
}
|
||||
reply(401, {error: "Wrong code."});
|
||||
return;
|
||||
}
|
||||
pendingDiscord.delete(hash);
|
||||
beginSession(account, res, from.address, "through Discord", true, [pendingCookieHeader("", 0)]);
|
||||
console.log(`[mod] ${logText(account.username)} signed in with Discord and a code from ${logText(from.address)}`);
|
||||
reply(200, {ok: true, username: account.username});
|
||||
return;
|
||||
}
|
||||
// signed in through the game instead: a client the moderator is playing
|
||||
// in hands over the game's login token, so they need not type their
|
||||
// password and a code again. taken only for active staff with 2FA on
|
||||
@@ -547,7 +617,8 @@ const handle = async (req, res, url, from, web) => {
|
||||
}
|
||||
}
|
||||
const cookie = crypto.randomBytes(24).toString("hex");
|
||||
sessions.set(sha256(cookie), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000});
|
||||
// no code given here, so not one the Discord bot's commands count
|
||||
sessions.set(sha256(cookie), {id: account.id, expiry: Date.now() + SESSION_HOURS * 3600000, code: false});
|
||||
res.setHeader("Set-Cookie", cookieHeader(cookie, SESSION_HOURS * 3600));
|
||||
modlog.record(account.username, "signed in", "", "through the game");
|
||||
reply(200, {ok: true, username: account.username});
|
||||
@@ -1089,13 +1160,33 @@ const moderators = () => accounts.all().filter(account => roles.roleOf(account))
|
||||
// linked to one Burrow account. From there these methods use the same role,
|
||||
// rank, permission and action checks as POST /mod/api/act, and log every
|
||||
// successful change under the staff member's normal Burrow username.
|
||||
// whose Discord this is: the active staff member it is linked to, or null.
|
||||
// it says who someone is (the bot leaves staff alone), not that they may act.
|
||||
const discordActor = discordId => {
|
||||
const account = accounts.all().find(candidate => candidate.discordId === String(discordId));
|
||||
return mayModerate(account) ? account : null;
|
||||
};
|
||||
|
||||
// who may use the bot's commands: the staff member above, while they are
|
||||
// signed in to the panel with a code (a session above with `code`). a
|
||||
// Discord account alone is not them, and a new password, signing out
|
||||
// everywhere or 2FA turned off end those sessions (forget), and the bot's
|
||||
// use with them.
|
||||
const discordCommandActor = discordId => {
|
||||
const account = discordActor(discordId);
|
||||
if (!account) {
|
||||
return null;
|
||||
}
|
||||
for (const session of sessions.values()) {
|
||||
if (session.id === account.id && session.code && session.expiry > Date.now()) {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const discordError = (actor, permission) => !actor
|
||||
? {error: "Link this Discord account to an active Burrow staff account first."}
|
||||
? {error: "Link this Discord account to your active Burrow staff account, then sign in to the staff dashboard with your 2FA code. Discord commands work while that sign-in lasts (12 hours)."}
|
||||
: !roles.can(actor, permission) ? {error: "Your Burrow role cannot do that."} : null;
|
||||
|
||||
const discordStatus = actor => {
|
||||
@@ -1153,7 +1244,7 @@ const discordHandleReport = (actor, id) => {
|
||||
|
||||
const discordAct = (actor, username, body) => {
|
||||
if (!actor) {
|
||||
return {error: "Link this Discord account to an active Burrow staff account first."};
|
||||
return discordError(null);
|
||||
}
|
||||
const target = accounts.byName(String(username || "").trim());
|
||||
if (!target) {
|
||||
@@ -1166,7 +1257,7 @@ const discordAct = (actor, username, body) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const discordBot = {actor: discordActor, authorize: discordError, status: discordStatus, player: discordPlayer, reports: discordReports,
|
||||
const discordBot = {actor: discordActor, commandActor: discordCommandActor, authorize: discordError, status: discordStatus, player: discordPlayer, reports: discordReports,
|
||||
staff: discordStaff, announce: discordAnnounce, handleReport: discordHandleReport, act: discordAct};
|
||||
|
||||
module.exports = {handle, forget, moderators, signedInAs, itemRoutes, reviewRoutes, discordBot};
|
||||
+79
-10
@@ -119,7 +119,22 @@ const cookieHeader = (token, maxAgeSeconds) =>
|
||||
const discordCookie = (value, maxAgeSeconds) =>
|
||||
`${DISCORD_COOKIE}=${value}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${maxAgeSeconds}${config.secureCookies ? "; Secure" : ""}`;
|
||||
|
||||
const signIn = res => {
|
||||
// a Discord sign-in waiting for the 2FA code of the account it is linked
|
||||
// to: SHA-256 of the token in its cookie -> {id, expiry, tries}. Discord
|
||||
// alone does not open this panel, as the password alone does not open the
|
||||
// moderator panel.
|
||||
const pendingDiscord = new Map();
|
||||
const PENDING_COOKIE = "ajc_admin_pending";
|
||||
const PENDING_MINUTES = 5;
|
||||
const PENDING_TRIES = 5;
|
||||
const pendingCookieHeader = (token, maxAgeSeconds) =>
|
||||
`${PENDING_COOKIE}=${token}; Path=/; HttpOnly; SameSite=Strict; Max-Age=${maxAgeSeconds}${config.secureCookies ? "; Secure" : ""}`;
|
||||
const pendingToken = req => (new RegExp(`(?:^|;\\s*)${PENDING_COOKIE}=([0-9a-f]{48})(?:;|$)`).exec(req.headers.cookie || "") || [])[1] || null;
|
||||
// may this account still sign in here with Discord?
|
||||
const discordAdmin = account => Boolean(account && account.adminDashboardAccess && account.discordId && totp.isOn(account) && !account.locked);
|
||||
|
||||
// `extraCookies` go out with the session's own.
|
||||
const signIn = (res, extraCookies = []) => {
|
||||
for (const [hash, expiry] of sessions) {
|
||||
if (expiry < Date.now()) {
|
||||
sessions.delete(hash);
|
||||
@@ -127,7 +142,7 @@ const signIn = res => {
|
||||
}
|
||||
const token = crypto.randomBytes(24).toString("hex");
|
||||
sessions.set(sha256(token), Date.now() + SESSION_HOURS * 3600000);
|
||||
res.setHeader("Set-Cookie", cookieHeader(token, SESSION_HOURS * 3600));
|
||||
res.setHeader("Set-Cookie", [cookieHeader(token, SESSION_HOURS * 3600), ...extraCookies]);
|
||||
};
|
||||
|
||||
const signOut = (req, res) => {
|
||||
@@ -692,13 +707,25 @@ const handle = async (req, res, url, from, web) => {
|
||||
const nonce = (new RegExp(`(?:^|;\\s*)${DISCORD_COOKIE}=([0-9a-f]{48})(?:;|$)`).exec(req.headers.cookie || "") || [])[1];
|
||||
const result = url.searchParams.get("error") ? {error: "cancelled"}
|
||||
: await discordLinks.finishAdmin(url.searchParams.get("state"), nonce, url.searchParams.get("code"));
|
||||
if (result.ok) {
|
||||
signIn(res);
|
||||
console.log(`[admin] ${logText(result.account.username)} signed in with Discord from ${logText(from.address)}`);
|
||||
// Discord has said who this is; the panel opens once that account's 2FA
|
||||
// code is given too (POST /admin/api/discord/code).
|
||||
if (result.ok && !discordAdmin(result.account)) {
|
||||
result.ok = false;
|
||||
result.error = totp.isOn(result.account) ? "denied" : "twostep";
|
||||
}
|
||||
const adminCookie = res.getHeader("Set-Cookie");
|
||||
res.setHeader("Set-Cookie", adminCookie ? [adminCookie, discordCookie("", 0)] : discordCookie("", 0));
|
||||
res.writeHead(302, {Location: `/dashboard/admin?discord=${result.ok ? "ok" : result.error}`});
|
||||
const cookies = [discordCookie("", 0)];
|
||||
if (result.ok) {
|
||||
for (const [hash, pending] of pendingDiscord) {
|
||||
if (pending.expiry < Date.now()) {
|
||||
pendingDiscord.delete(hash);
|
||||
}
|
||||
}
|
||||
const token = crypto.randomBytes(24).toString("hex");
|
||||
pendingDiscord.set(sha256(token), {id: result.account.id, expiry: Date.now() + PENDING_MINUTES * 60000, tries: 0});
|
||||
cookies.push(pendingCookieHeader(token, PENDING_MINUTES * 60));
|
||||
}
|
||||
res.setHeader("Set-Cookie", cookies);
|
||||
res.writeHead(302, {Location: `/dashboard/admin?discord=${result.ok ? "code" : result.error}`});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
@@ -760,6 +787,44 @@ const handle = async (req, res, url, from, web) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// the second half of a Discord sign-in: the linked account's 2FA code.
|
||||
case "POST /admin/api/discord/code": {
|
||||
if (tooManyFailures(from.key)) {
|
||||
reply(429, {error: "Too many attempts. Try again in a few minutes."});
|
||||
return;
|
||||
}
|
||||
const token = pendingToken(req);
|
||||
const hash = token ? sha256(token) : null;
|
||||
const pending = hash ? pendingDiscord.get(hash) : null;
|
||||
const account = pending && pending.expiry > Date.now() ? accounts.byId(pending.id) : null;
|
||||
if (!discordAdmin(account)) {
|
||||
if (hash) {
|
||||
pendingDiscord.delete(hash);
|
||||
}
|
||||
res.setHeader("Set-Cookie", pendingCookieHeader("", 0));
|
||||
reply(401, {error: "The Discord sign-in expired. Sign in with Discord again.", expired: true});
|
||||
return;
|
||||
}
|
||||
if (!totp.verify(account, String(body.code || ""))) {
|
||||
recordFailure(from.key);
|
||||
console.log(`[admin] wrong 2FA code after Discord for ${logText(account.username)} from ${logText(from.address)}`);
|
||||
pending.tries++;
|
||||
if (pending.tries >= PENDING_TRIES) {
|
||||
pendingDiscord.delete(hash);
|
||||
res.setHeader("Set-Cookie", pendingCookieHeader("", 0));
|
||||
reply(401, {error: "Too many wrong codes. Sign in with Discord again.", expired: true});
|
||||
return;
|
||||
}
|
||||
reply(401, {error: "Wrong code."});
|
||||
return;
|
||||
}
|
||||
pendingDiscord.delete(hash);
|
||||
signIn(res, [pendingCookieHeader("", 0)]);
|
||||
console.log(`[admin] ${logText(account.username)} signed in with Discord and a code from ${logText(from.address)}`);
|
||||
reply(200, {ok: true});
|
||||
return;
|
||||
}
|
||||
|
||||
case "POST /admin/api/logout":
|
||||
signOut(req, res);
|
||||
reply(200, {ok: true});
|
||||
@@ -814,8 +879,12 @@ const handle = async (req, res, url, from, web) => {
|
||||
return;
|
||||
|
||||
case "POST /admin/api/discord/status": {
|
||||
const statusCard = discordBot.setStatusSettings({title: body.title, note: body.note});
|
||||
modlog.record("admin", "Discord public status card changed", "", `title: ${statusCard.title}`);
|
||||
const statusCard = discordBot.setStatusSettings({title: body.title, note: body.note, banner: body.banner});
|
||||
if (statusCard.error) {
|
||||
reply(400, {error: statusCard.error});
|
||||
return;
|
||||
}
|
||||
modlog.record("admin", "Discord public status card changed", "", `title: ${statusCard.title}, banner: ${statusCard.banner || "none"}`);
|
||||
reply(200, {ok: "Status-card text saved. Use Publish now to update Discord.", statusCard});
|
||||
return;
|
||||
}
|
||||
|
||||
+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.
|
||||
@@ -1917,12 +1941,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+215
-1
@@ -116,7 +116,7 @@
|
||||
line-height: 17px;
|
||||
text-align: center;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
|
||||
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
|
||||
.wrap { max-width: 760px; margin: 0 auto; }
|
||||
label.check { display: flex; align-items: center; color: var(--text); font-size: 14px; cursor: pointer; }
|
||||
/* dark on white whatever the page: that is what a phone's camera reads. */
|
||||
@@ -175,6 +175,26 @@
|
||||
.ban-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
|
||||
.ban-head img { width: 44px; height: 44px; flex: none; }
|
||||
.ban-head h2 { margin: 0; font-size: 22px; }
|
||||
.chat-style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
|
||||
.chat-style-grid input[type="color"] { width: 100%; height: 42px; padding: 3px; cursor: pointer; }
|
||||
.gradient-editor { margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
|
||||
.gradient-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
|
||||
.gradient-stops { display: grid; gap: 8px; }
|
||||
.gradient-ramp { height: 22px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 999px; }
|
||||
.gradient-stop { display: grid; grid-template-columns: 50px minmax(100px, 1fr) 72px auto; align-items: center; gap: 8px; }
|
||||
.gradient-stop input[type="color"] { width: 50px; height: 36px; padding: 2px; cursor: pointer; }
|
||||
.gradient-stop input[type="range"] { margin: 0; }
|
||||
.gradient-stop output { color: var(--muted); font-size: 12px; text-align: right; }
|
||||
.chat-preview { min-height: 74px; display: grid; place-items: center; margin-top: 14px; padding: 12px 18px; border: 1px solid var(--line); border-radius: 18px; text-align: center; font-weight: 700; background: linear-gradient(120deg, #fff, #dfe8ff); color: #445559; }
|
||||
.chat-preview.pulse { animation: chatPulse 1.5s ease-in-out infinite alternate; }
|
||||
.chat-preview.shimmer { background-size: 250% 100%; animation: chatShimmer 1.5s linear infinite; }
|
||||
.chat-preview.flow { background-size: 220% 220%; animation: chatFlow 1.5s linear infinite alternate; }
|
||||
.chat-preview.rainbow { animation: chatRainbow 2s linear infinite; }
|
||||
@keyframes chatPulse { to { opacity: .55; } }
|
||||
@keyframes chatShimmer { to { background-position: 100% 0; } }
|
||||
@keyframes chatFlow { to { background-position: 100% 100%; } }
|
||||
@keyframes chatRainbow { to { filter: hue-rotate(360deg); } }
|
||||
@media (max-width: 440px) { .chat-style-grid { grid-template-columns: 1fr; } }
|
||||
#ban-section pre { margin: 0 0 12px; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
#ban-section h3 { margin: 18px 0 0; }
|
||||
</style>
|
||||
@@ -354,6 +374,35 @@
|
||||
<p class="status" id="bio-status" role="status"></p>
|
||||
</section>
|
||||
|
||||
<section id="chat-bubble">
|
||||
<h2>Chat bubble</h2>
|
||||
<p>Choose how your spoken chat bubbles look for everyone using Burrow's current client.</p>
|
||||
<form id="chat-style-form">
|
||||
<div class="gradient-editor">
|
||||
<div class="gradient-editor-head"><b>Gradient colours</b><button id="chat-stop-add" type="button">Add colour</button></div>
|
||||
<div class="gradient-ramp" id="chat-ramp"></div>
|
||||
<div class="gradient-stops" id="chat-stops"></div>
|
||||
</div>
|
||||
<div class="chat-style-grid">
|
||||
<div hidden><input id="chat-background" type="color" value="#ffffff"></div>
|
||||
<div hidden><input id="chat-accent" type="color" value="#dfe8ff"></div>
|
||||
<div><label for="chat-text-colour">Text colour</label><input id="chat-text-colour" type="color" value="#445559"></div>
|
||||
<div><label for="chat-border">Border</label><input id="chat-border" type="color" value="#9aabb0"></div>
|
||||
<div><label for="chat-opacity">Opacity <span class="hint" id="chat-opacity-value"></span></label><input id="chat-opacity" type="range" min="25" max="100" value="75"></div>
|
||||
<div><label for="chat-gradient">Gradient</label><select id="chat-gradient"><option value="linear">Linear</option><option value="radial">Radial</option><option value="solid">Solid</option></select></div>
|
||||
<div><label for="chat-angle">Direction</label><select id="chat-angle"><option value="0">0°</option><option value="45">45°</option><option value="90">90°</option><option value="135">135°</option><option value="180">180°</option><option value="225">225°</option><option value="270">270°</option><option value="315">315°</option></select></div>
|
||||
<div><label for="chat-strength">Gradient strength <span class="hint" id="chat-strength-value"></span></label><input id="chat-strength" type="range" min="0" max="100" value="100"></div>
|
||||
<div><label for="chat-outline">Outline thickness <span class="hint" id="chat-outline-value"></span></label><input id="chat-outline" type="range" min="0" max="4" step="1" value="1"></div>
|
||||
<div><label for="chat-animation">Animation</label><select id="chat-animation"><option value="none">Still</option><option value="pulse">Pulse</option><option value="shimmer">Shimmer</option><option value="flow">Flow</option><option value="rainbow">Rainbow</option></select></div>
|
||||
<div><label for="chat-speed">Animation speed <span class="hint" id="chat-speed-value"></span></label><input id="chat-speed" type="range" min="40" max="300" value="100"></div>
|
||||
</div>
|
||||
<div class="chat-preview" id="chat-preview">Your chat bubble preview</div>
|
||||
<div class="row"><button id="chat-style-swap" type="button">Swap gradient</button><button id="chat-style-random" type="button">Random gradient</button></div>
|
||||
<div class="row"><button class="primary" type="submit">Save chat style</button><button id="chat-style-reset" type="button">Use original bubble</button></div>
|
||||
</form>
|
||||
<p class="status" id="chat-style-status" role="status"></p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Playtime</h2>
|
||||
<p id="playtime-text"></p>
|
||||
@@ -504,8 +553,12 @@
|
||||
];
|
||||
const VIA = {game: "Game", launcher: "Client", web: "This page", mod: "Moderator panel"};
|
||||
const ANIMALS = {1: "Tiger", 4: "Wolf", 5: "Koala", 6: "Panda", 7: "Monkey", 8: "Bunny", 13: "Rhino", 18: "Seal", 24: "Penguin"};
|
||||
const DEFAULT_CHAT_STYLE = {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"};
|
||||
|
||||
let account = null;
|
||||
let chatStops = [];
|
||||
let twoStepSetup = null; // {secret, uri} while two-step sign-in is being turned on
|
||||
let twoStepCodes = null; // the recovery codes, until the player says they kept them
|
||||
|
||||
@@ -527,6 +580,126 @@
|
||||
$(id).classList.toggle("bad", bad);
|
||||
};
|
||||
|
||||
const parseChatStops = style => {
|
||||
const parsed = String(style.stops || "").split(";").map(value => {
|
||||
const match = /^([0-9a-f]{6}):(100|[1-9]?\d)$/i.exec(value);
|
||||
return match ? {color: match[1].toLowerCase(), position: Number(match[2])} : null;
|
||||
});
|
||||
return parsed.length >= 2 && parsed.length <= 5 && parsed.every(Boolean)
|
||||
? parsed : [{color: style.background, position: 0}, {color: style.accent, position: 100}];
|
||||
};
|
||||
|
||||
const styleValue = () => {
|
||||
if (chatStops.length < 2) chatStops = parseChatStops(DEFAULT_CHAT_STYLE);
|
||||
chatStops.sort((one, two) => one.position - two.position);
|
||||
chatStops[0].position = 0;
|
||||
chatStops.at(-1).position = 100;
|
||||
const background = chatStops[0].color;
|
||||
const accent = chatStops.at(-1).color;
|
||||
$("chat-background").value = `#${background}`;
|
||||
$("chat-accent").value = `#${accent}`;
|
||||
return {
|
||||
background, accent,
|
||||
text: $("chat-text-colour").value.slice(1).toLowerCase(),
|
||||
border: $("chat-border").value.slice(1).toLowerCase(),
|
||||
opacity: Number($("chat-opacity").value),
|
||||
animation: $("chat-animation").value,
|
||||
speed: Number($("chat-speed").value),
|
||||
gradient: $("chat-gradient").value,
|
||||
angle: Number($("chat-angle").value),
|
||||
strength: Number($("chat-strength").value),
|
||||
outline: Number($("chat-outline").value),
|
||||
stops: chatStops.map(stop => `${stop.color}:${stop.position}`).join(";"),
|
||||
};
|
||||
};
|
||||
|
||||
const paintChatPreview = () => {
|
||||
const style = styleValue();
|
||||
const preview = $("chat-preview");
|
||||
preview.className = `chat-preview ${style.animation}`;
|
||||
const mix = (one, two, amount) => one.map((part, index) => Math.round(part + (two[index] - part) * amount));
|
||||
const rgb = hex => [0, 2, 4].map(at => parseInt(hex.slice(at, at + 2), 16));
|
||||
const stops = parseChatStops(style).map((stop, index) => {
|
||||
const colour = index ? mix(rgb(style.background), rgb(stop.color), style.strength / 100) : rgb(stop.color);
|
||||
return `#${colour.map(part => part.toString(16).padStart(2, "0")).join("")} ${stop.position}%`;
|
||||
}).join(", ");
|
||||
preview.style.background = style.gradient === "solid" ? `#${style.background}` : style.gradient === "radial"
|
||||
? `radial-gradient(circle, ${stops})`
|
||||
: `linear-gradient(${style.angle}deg, ${stops})`;
|
||||
preview.style.color = `#${style.text}`;
|
||||
preview.style.borderColor = `#${style.border}`;
|
||||
preview.style.borderWidth = `${style.outline}px`;
|
||||
preview.style.opacity = String(style.opacity / 100);
|
||||
preview.style.animationDuration = `${Math.max(.25, 1.5 * 100 / style.speed)}s`;
|
||||
$("chat-opacity-value").textContent = `${style.opacity}%`;
|
||||
$("chat-speed-value").textContent = `${style.speed}%`;
|
||||
$("chat-strength-value").textContent = `${style.strength}%`;
|
||||
$("chat-outline-value").textContent = `${style.outline}px`;
|
||||
};
|
||||
|
||||
const renderChatStops = () => {
|
||||
chatStops.sort((one, two) => one.position - two.position);
|
||||
const holder = $("chat-stops");
|
||||
holder.replaceChildren();
|
||||
$("chat-ramp").style.background = `linear-gradient(90deg, ${chatStops.map(stop => `#${stop.color} ${stop.position}%`).join(", ")})`;
|
||||
chatStops.forEach((stop, index) => {
|
||||
const row = el("div", undefined, "gradient-stop");
|
||||
const colour = document.createElement("input");
|
||||
colour.type = "color";
|
||||
colour.value = `#${stop.color}`;
|
||||
colour.setAttribute("aria-label", `Gradient colour ${index + 1}`);
|
||||
const position = document.createElement("input");
|
||||
position.type = "range";
|
||||
position.min = String(index ? chatStops[index - 1].position + 1 : 0);
|
||||
position.max = String(index < chatStops.length - 1 ? chatStops[index + 1].position - 1 : 100);
|
||||
position.value = String(stop.position);
|
||||
position.disabled = index === 0 || index === chatStops.length - 1;
|
||||
const value = document.createElement("output");
|
||||
value.textContent = index === 0 ? "Start" : index === chatStops.length - 1 ? "End" : `${stop.position}%`;
|
||||
const remove = document.createElement("button");
|
||||
remove.type = "button";
|
||||
remove.textContent = "Remove";
|
||||
remove.disabled = chatStops.length <= 2;
|
||||
colour.addEventListener("input", () => {
|
||||
stop.color = colour.value.slice(1).toLowerCase();
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
});
|
||||
position.addEventListener("input", () => {
|
||||
stop.position = Number(position.value);
|
||||
value.textContent = `${stop.position}%`;
|
||||
$("chat-ramp").style.background = `linear-gradient(90deg, ${chatStops.map(item => `#${item.color} ${item.position}%`).join(", ")})`;
|
||||
paintChatPreview();
|
||||
});
|
||||
remove.addEventListener("click", () => {
|
||||
chatStops.splice(index, 1);
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
});
|
||||
row.append(colour, position, value, remove);
|
||||
holder.append(row);
|
||||
});
|
||||
$("chat-stop-add").disabled = chatStops.length >= 5;
|
||||
};
|
||||
|
||||
const fillChatStyle = style => {
|
||||
style = {...DEFAULT_CHAT_STYLE, ...style};
|
||||
chatStops = parseChatStops(style);
|
||||
$("chat-background").value = `#${style.background}`;
|
||||
$("chat-accent").value = `#${style.accent}`;
|
||||
$("chat-text-colour").value = `#${style.text}`;
|
||||
$("chat-border").value = `#${style.border}`;
|
||||
$("chat-opacity").value = String(style.opacity);
|
||||
$("chat-animation").value = style.animation;
|
||||
$("chat-speed").value = String(style.speed);
|
||||
$("chat-gradient").value = style.gradient;
|
||||
$("chat-angle").value = String(style.angle);
|
||||
$("chat-strength").value = String(style.strength);
|
||||
$("chat-outline").value = String(style.outline);
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
};
|
||||
|
||||
const api = async (path, body) => {
|
||||
try {
|
||||
const response = await fetch(`/account/api/${path}`, body === undefined ? {} : {
|
||||
@@ -757,6 +930,9 @@
|
||||
}
|
||||
renderMyItems();
|
||||
$("lock-notice").hidden = !account.locked;
|
||||
if (!$("chat-style-form").contains(document.activeElement)) {
|
||||
fillChatStyle(account.chatStyle);
|
||||
}
|
||||
|
||||
const tiles = [
|
||||
[account.online ? "Playing now" : account.lastSeen ? when(account.lastSeen) : "Not played yet", "Last seen"],
|
||||
@@ -1343,6 +1519,44 @@
|
||||
});
|
||||
$("bio-remove").addEventListener("click", () => act({action: "bio", text: ""}, "bio-status"));
|
||||
|
||||
["chat-background", "chat-accent", "chat-text-colour", "chat-border", "chat-opacity", "chat-gradient", "chat-angle", "chat-strength", "chat-outline", "chat-animation", "chat-speed"].forEach(id => {
|
||||
$(id).addEventListener("input", paintChatPreview);
|
||||
$(id).addEventListener("change", paintChatPreview);
|
||||
});
|
||||
$("chat-style-form").addEventListener("submit", async event => {
|
||||
event.preventDefault();
|
||||
await act({action: "chatStyle", style: styleValue()}, "chat-style-status");
|
||||
});
|
||||
$("chat-stop-add").addEventListener("click", () => {
|
||||
if (chatStops.length >= 5) return;
|
||||
let gapAt = 0;
|
||||
for (let index = 1; index < chatStops.length - 1; index++) {
|
||||
if (chatStops[index + 1].position - chatStops[index].position > chatStops[gapAt + 1].position - chatStops[gapAt].position) gapAt = index;
|
||||
}
|
||||
const before = chatStops[gapAt];
|
||||
const after = chatStops[gapAt + 1];
|
||||
const rgb = hex => [0, 2, 4].map(at => parseInt(hex.slice(at, at + 2), 16));
|
||||
const mixed = rgb(before.color).map((part, index) => Math.round((part + rgb(after.color)[index]) / 2).toString(16).padStart(2, "0")).join("");
|
||||
chatStops.splice(gapAt + 1, 0, {color: mixed, position: Math.round((before.position + after.position) / 2)});
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
});
|
||||
$("chat-style-swap").addEventListener("click", () => {
|
||||
chatStops = chatStops.slice().reverse().map(stop => ({color: stop.color, position: 100 - stop.position}));
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
});
|
||||
$("chat-style-random").addEventListener("click", () => {
|
||||
const randomColour = () => Math.floor(Math.random() * 0x1000000).toString(16).padStart(6, "0");
|
||||
chatStops.forEach(stop => { stop.color = randomColour(); });
|
||||
renderChatStops();
|
||||
paintChatPreview();
|
||||
});
|
||||
$("chat-style-reset").addEventListener("click", async () => {
|
||||
fillChatStyle(DEFAULT_CHAT_STYLE);
|
||||
await act({action: "chatStyle", style: DEFAULT_CHAT_STYLE}, "chat-style-status");
|
||||
});
|
||||
|
||||
// off to Discord's sign-in; it comes back to /account?discord=<how it went>
|
||||
$("discord-link").addEventListener("click", () => {
|
||||
location.href = "/account/discord/link";
|
||||
|
||||
+58
-2
@@ -392,6 +392,12 @@
|
||||
</div>
|
||||
<button class="primary" id="gate-button">Sign in</button>
|
||||
</form>
|
||||
<form id="discord-code-form" hidden>
|
||||
<p class="hint">Discord confirmed who you are. Enter that account's 2FA code to finish signing in.</p>
|
||||
<label for="discord-code">2FA code</label>
|
||||
<input id="discord-code" inputmode="numeric" autocomplete="one-time-code" maxlength="20" spellcheck="false" required>
|
||||
<button class="primary" id="discord-code-button">Finish signing in</button>
|
||||
</form>
|
||||
<button type="button" id="discord-sign-in" hidden>Sign in with Discord</button>
|
||||
<p class="hint" id="discord-gate-hint" hidden>Only Discord accounts explicitly allowed by the owner can use this.</p>
|
||||
<p class="status" id="gate-status" role="status"></p>
|
||||
@@ -490,6 +496,8 @@
|
||||
<input id="discord-status-title" maxlength="80" placeholder="Burrow status" aria-label="Discord public status-card title">
|
||||
<label for="discord-status-note">Status message</label>
|
||||
<textarea id="discord-status-note" rows="3" maxlength="500" placeholder="Optional message shown above the live player and moderation counts." aria-label="Discord public status-card message"></textarea>
|
||||
<label for="discord-status-banner">Banner image URL</label>
|
||||
<input id="discord-status-banner" type="url" maxlength="500" placeholder="https://… (leave blank for no banner)" aria-label="Discord public status-card banner image URL">
|
||||
<div class="send-row">
|
||||
<button class="primary" type="submit">Save status card</button>
|
||||
<button type="button" id="discord-status-publish">Publish now</button>
|
||||
@@ -1259,6 +1267,38 @@
|
||||
location.href = "/dashboard/admin/discord/login";
|
||||
});
|
||||
|
||||
// after Discord: the linked account's 2FA code (POST discord/code)
|
||||
const discordGate = (codeStep, message) => {
|
||||
history.replaceState(null, "", location.pathname + location.hash);
|
||||
showGate(message);
|
||||
$("gate-form").hidden = codeStep;
|
||||
$("discord-code-form").hidden = !codeStep;
|
||||
if (codeStep) {
|
||||
$("discord-sign-in").textContent = "Start again with Discord";
|
||||
$("discord-code").focus();
|
||||
}
|
||||
};
|
||||
|
||||
$("discord-code-form").addEventListener("submit", async event => {
|
||||
event.preventDefault();
|
||||
$("discord-code-button").disabled = true;
|
||||
const result = await api("discord/code", {code: $("discord-code").value.trim()});
|
||||
$("discord-code-button").disabled = false;
|
||||
$("discord-code").value = "";
|
||||
if (result.ok) {
|
||||
$("discord-code-form").hidden = true;
|
||||
$("gate-form").hidden = false;
|
||||
state = {needsSetup: false, needsSetupCode: false, signedIn: true};
|
||||
showPanel();
|
||||
}
|
||||
else if (result.data.expired) {
|
||||
discordGate(false, result.data.error);
|
||||
}
|
||||
else {
|
||||
setStatus($("gate-status"), result.data.error || "That did not work.", true);
|
||||
}
|
||||
});
|
||||
|
||||
$("sign-out").addEventListener("click", async () => {
|
||||
await api("logout", {});
|
||||
state.signedIn = false;
|
||||
@@ -1328,10 +1368,11 @@
|
||||
? "Credentials and webhook secrets are intentionally never shown in this dashboard."
|
||||
: "Add the missing environment variables to the service that starts Burrow; dashboard settings cannot store bot secrets.";
|
||||
$("discord-bot-status").classList.toggle("bad", !configured || !data.connected);
|
||||
const editingStatusCard = ["discord-status-title", "discord-status-note"].includes(document.activeElement && document.activeElement.id);
|
||||
const editingStatusCard = ["discord-status-title", "discord-status-note", "discord-status-banner"].includes(document.activeElement && document.activeElement.id);
|
||||
if (!editingStatusCard) {
|
||||
$("discord-status-title").value = data.statusCard && data.statusCard.title || "Burrow status";
|
||||
$("discord-status-note").value = data.statusCard && data.statusCard.note || "";
|
||||
$("discord-status-banner").value = data.statusCard && data.statusCard.banner || "";
|
||||
}
|
||||
const editingRouting = document.activeElement && (document.activeElement.dataset.discordChannel || document.activeElement.id === "discord-github-repository");
|
||||
if (!editingRouting) {
|
||||
@@ -1444,12 +1485,13 @@
|
||||
event.preventDefault();
|
||||
const button = event.submitter;
|
||||
if (button) button.disabled = true;
|
||||
const result = await api("discord/status", {title: $("discord-status-title").value, note: $("discord-status-note").value});
|
||||
const result = await api("discord/status", {title: $("discord-status-title").value, note: $("discord-status-note").value, banner: $("discord-status-banner").value});
|
||||
if (button) button.disabled = false;
|
||||
setStatus($("discord-status-card-result"), said(result), !result.ok);
|
||||
if (result.ok && result.data.statusCard) {
|
||||
$("discord-status-title").value = result.data.statusCard.title;
|
||||
$("discord-status-note").value = result.data.statusCard.note;
|
||||
$("discord-status-banner").value = result.data.statusCard.banner;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3510,9 +3552,23 @@
|
||||
showGate("The server did not answer.");
|
||||
return;
|
||||
}
|
||||
const discordResult = new URLSearchParams(location.search).get("discord");
|
||||
if (state.signedIn) {
|
||||
showPanel();
|
||||
}
|
||||
else if (discordResult === "code") {
|
||||
discordGate(true, "");
|
||||
}
|
||||
else if (discordResult) {
|
||||
discordGate(false, {
|
||||
denied: "That Discord account is not allowed to sign in here.",
|
||||
twostep: "Turn on 2FA for the linked account first.",
|
||||
expired: "The Discord sign-in request expired. Try again.",
|
||||
cancelled: "Discord sign-in was cancelled.",
|
||||
discord: "Discord could not confirm that sign-in. Try again.",
|
||||
off: "Discord sign-in is not configured.",
|
||||
}[discordResult] || "");
|
||||
}
|
||||
else {
|
||||
showGate();
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
+7
-1
@@ -25,17 +25,21 @@
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
#status { margin: 0; text-align: center; }
|
||||
button { display: none; border: 1px solid #8c8c8c; border-radius: 5px; padding: 6px 12px; background: transparent; color: #ddd; font: inherit; cursor: pointer; }
|
||||
button.show { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="widget"></div>
|
||||
<p id="status" role="status">Checking…</p>
|
||||
<button id="retry" type="button">Try again</button>
|
||||
<script src="/captcha.js"></script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
const action = new URLSearchParams(location.search).get("action") === "signup" ? "signup" : "login";
|
||||
const status = document.getElementById("status");
|
||||
const retry = document.getElementById("retry");
|
||||
const done = token => {
|
||||
if (window.burrowCaptcha) {
|
||||
window.burrowCaptcha.done(token);
|
||||
@@ -53,10 +57,12 @@
|
||||
}});
|
||||
check.answer().then(token => {
|
||||
if (!token) {
|
||||
status.textContent = "Captcha failed. Close this and try again.";
|
||||
status.textContent = "Captcha could not load. Check your connection or content blocker.";
|
||||
retry.classList.add("show");
|
||||
}
|
||||
});
|
||||
}
|
||||
retry.addEventListener("click", () => location.reload());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+38
-17
@@ -10,14 +10,29 @@
|
||||
// captcha.FAILED then), and check.reset() after it: an answer is good once.
|
||||
window.captcha = (() => {
|
||||
const siteKey = "{{siteKey}}";
|
||||
const LOAD_TIMEOUT_MS = 15000;
|
||||
let loading = null;
|
||||
|
||||
const load = () => {
|
||||
loading = loading || new Promise((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
|
||||
script.onload = () => resolve(window.turnstile);
|
||||
const timer = setTimeout(() => {
|
||||
loading = null;
|
||||
reject(new Error("the captcha took too long to load"));
|
||||
}, LOAD_TIMEOUT_MS);
|
||||
script.onload = () => {
|
||||
clearTimeout(timer);
|
||||
if (window.turnstile && typeof window.turnstile.render === "function") {
|
||||
resolve(window.turnstile);
|
||||
}
|
||||
else {
|
||||
loading = null;
|
||||
reject(new Error("the captcha did not start"));
|
||||
}
|
||||
};
|
||||
script.onerror = () => {
|
||||
clearTimeout(timer);
|
||||
loading = null;
|
||||
reject(new Error("the captcha did not load"));
|
||||
};
|
||||
@@ -44,21 +59,27 @@ window.captcha = (() => {
|
||||
};
|
||||
if (siteKey) {
|
||||
load().then(turnstile => {
|
||||
widget = turnstile.render(element, {
|
||||
sitekey: siteKey,
|
||||
action,
|
||||
theme: "dark",
|
||||
appearance: options.appearance || "interaction-only",
|
||||
callback: settle,
|
||||
"expired-callback": () => {
|
||||
answer = null;
|
||||
},
|
||||
// its code is cloudflare's (110200: this site's name is not on the widget)
|
||||
"error-callback": code => {
|
||||
console.log(`captcha error ${code}`);
|
||||
settle("");
|
||||
},
|
||||
});
|
||||
try {
|
||||
widget = turnstile.render(element, {
|
||||
sitekey: siteKey,
|
||||
action,
|
||||
theme: "dark",
|
||||
appearance: options.appearance || "interaction-only",
|
||||
callback: settle,
|
||||
"expired-callback": () => {
|
||||
answer = null;
|
||||
},
|
||||
// its code is cloudflare's (110200: this site's name is not on the widget)
|
||||
"error-callback": code => {
|
||||
console.log(`captcha error ${code}`);
|
||||
settle("");
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`captcha could not start: ${err.message}`);
|
||||
settle("");
|
||||
}
|
||||
}, () => settle(""));
|
||||
}
|
||||
return {
|
||||
@@ -79,5 +100,5 @@ window.captcha = (() => {
|
||||
};
|
||||
};
|
||||
|
||||
return {on: Boolean(siteKey), mount, FAILED: "Captcha could not load. Reload the page."};
|
||||
return {on: Boolean(siteKey), mount, FAILED: "Captcha could not load. Check your connection or content blocker, then reload."};
|
||||
})();
|
||||
+54
-1
@@ -135,6 +135,18 @@
|
||||
#browser-address:focus {
|
||||
border-color: #7f6744;
|
||||
}
|
||||
/* a site the client keeps out of the theatre (its own list): offered
|
||||
in the player's own browser instead */
|
||||
#browser-blocked {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font: 400 calc(12 * var(--px)) / 1 Arial, Helvetica, sans-serif;
|
||||
color: #3d2716;
|
||||
cursor: text;
|
||||
}
|
||||
#browser-bar .aj-button {
|
||||
min-width: 0;
|
||||
font-size: calc(12 * var(--px));
|
||||
@@ -258,7 +270,9 @@
|
||||
<button type="button" id="browser-forward" class="aj-round" aria-label="Forward" disabled>▶</button>
|
||||
<button type="button" id="browser-reload" class="aj-round" aria-label="Reload">↻</button>
|
||||
<input id="browser-address" type="text" placeholder="Search or type an address" autocomplete="off" spellcheck="false" aria-label="Address">
|
||||
<button type="submit" class="aj-button go">Go</button>
|
||||
<button type="submit" id="browser-go" class="aj-button go">Go</button>
|
||||
<span id="browser-blocked" role="status" hidden></span>
|
||||
<button type="button" id="browser-elsewhere" class="aj-button go" hidden>Open in your browser</button>
|
||||
<button type="button" id="browser-close" class="aj-round" aria-label="Close the browser">×</button>
|
||||
</form>
|
||||
<form id="own-video-box" class="aj-box" hidden>
|
||||
@@ -729,6 +743,10 @@
|
||||
let roomPlaying = false;
|
||||
let where = null; // the last place told, without `shown`
|
||||
let told = "";
|
||||
// an address the client would not show here (the old browser engine
|
||||
// it needs for Flash shows only the sites it lists): the bar offers
|
||||
// to open it in the player's own browser instead. "" when none.
|
||||
let elsewhere = "";
|
||||
|
||||
const tell = message => window.ipc.sendToHost("browser", message);
|
||||
const placeMessage = () => ({...where, shown: open && theatreScreen !== null && !roomPlaying});
|
||||
@@ -760,6 +778,24 @@
|
||||
opener.hidden = !allowed;
|
||||
pills.hidden = open;
|
||||
bar.hidden = !open;
|
||||
address.hidden = elsewhere !== "";
|
||||
$("browser-go").hidden = elsewhere !== "";
|
||||
$("browser-blocked").hidden = elsewhere === "";
|
||||
$("browser-elsewhere").hidden = elsewhere === "";
|
||||
};
|
||||
|
||||
const showElsewhere = (url, sites) => {
|
||||
let host = "";
|
||||
try {
|
||||
host = new URL(url).hostname;
|
||||
}
|
||||
catch (err) {
|
||||
url = "";
|
||||
}
|
||||
elsewhere = url;
|
||||
$("browser-blocked").textContent = elsewhere ? `${host} opens in your own browser, not here.` : "";
|
||||
$("browser-blocked").title = sites.length ? `The theatre shows only ${sites.join(", ")}.` : "";
|
||||
show();
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
@@ -768,6 +804,7 @@
|
||||
}
|
||||
open = false;
|
||||
told = "";
|
||||
elsewhere = "";
|
||||
tell({action: "close"});
|
||||
show();
|
||||
};
|
||||
@@ -782,6 +819,18 @@
|
||||
address.focus();
|
||||
});
|
||||
$("browser-close").addEventListener("click", close);
|
||||
// the client opens http and https addresses in the system browser
|
||||
$("browser-elsewhere").addEventListener("click", () => {
|
||||
if (/^https?:\/\//.test(elsewhere)) {
|
||||
window.ipc.sendToHost("openPage", elsewhere);
|
||||
}
|
||||
showElsewhere("", []);
|
||||
});
|
||||
// back to the address, to go somewhere else
|
||||
$("browser-blocked").addEventListener("click", () => {
|
||||
showElsewhere("", []);
|
||||
address.focus();
|
||||
});
|
||||
$("browser-back").addEventListener("click", () => tell({action: "back"}));
|
||||
$("browser-forward").addEventListener("click", () => tell({action: "forward"}));
|
||||
$("browser-reload").addEventListener("click", () => tell({action: "reload"}));
|
||||
@@ -816,6 +865,10 @@
|
||||
}
|
||||
$("browser-back").disabled = state.back !== true;
|
||||
$("browser-forward").disabled = state.forward !== true;
|
||||
const blocked = typeof state.blocked === "string" && /^https?:\/\//.test(state.blocked) ? state.blocked : "";
|
||||
if (blocked !== elsewhere) {
|
||||
showElsewhere(blocked, Array.isArray(state.sites) ? state.sites.map(String).slice(0, 10) : []);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
+44
-1
@@ -454,6 +454,12 @@
|
||||
<div id="captcha"></div>
|
||||
<button class="primary" id="gate-button">Sign in</button>
|
||||
</form>
|
||||
<form id="discord-code-form" hidden>
|
||||
<p class="hint">Discord confirmed who you are. Enter your 2FA code to finish signing in.</p>
|
||||
<label for="discord-code">2FA code</label>
|
||||
<input id="discord-code" inputmode="numeric" autocomplete="one-time-code" maxlength="20" spellcheck="false" required>
|
||||
<button class="primary" id="discord-code-button">Finish signing in</button>
|
||||
</form>
|
||||
<button type="button" id="discord-sign-in" hidden>Sign in with Discord</button>
|
||||
<p class="hint" id="discord-gate-hint" hidden>Use the Discord account linked to your active staff account.</p>
|
||||
<p class="status" id="gate-status" role="status"></p>
|
||||
@@ -3195,6 +3201,38 @@
|
||||
location.href = "/dashboard/staff/discord/login";
|
||||
});
|
||||
|
||||
// after Discord: the 2FA code, which opens the panel (POST discord/code)
|
||||
const showDiscordCode = message => {
|
||||
showGate(message);
|
||||
$("gate-form").hidden = true;
|
||||
$("discord-code-form").hidden = false;
|
||||
$("discord-sign-in").textContent = "Start again with Discord";
|
||||
$("discord-code").focus();
|
||||
};
|
||||
|
||||
$("discord-code-form").addEventListener("submit", async event => {
|
||||
event.preventDefault();
|
||||
$("discord-code-button").disabled = true;
|
||||
const result = await api("discord/code", {code: $("discord-code").value.trim()});
|
||||
$("discord-code-button").disabled = false;
|
||||
$("discord-code").value = "";
|
||||
if (result.ok) {
|
||||
history.replaceState(null, "", location.pathname + location.hash);
|
||||
$("discord-code-form").hidden = true;
|
||||
$("gate-form").hidden = false;
|
||||
showPanel(result.data.username);
|
||||
}
|
||||
else if (result.data.expired) {
|
||||
history.replaceState(null, "", location.pathname + location.hash);
|
||||
$("discord-code-form").hidden = true;
|
||||
$("gate-form").hidden = false;
|
||||
showGate(said(result));
|
||||
}
|
||||
else {
|
||||
setStatus($("gate-status"), said(result), true);
|
||||
}
|
||||
});
|
||||
|
||||
$("sign-out").addEventListener("click", async () => {
|
||||
await api("logout", {});
|
||||
showGate("");
|
||||
@@ -3215,7 +3253,12 @@
|
||||
discord: "Discord could not confirm that sign-in. Try again.",
|
||||
off: "Discord sign-in is not configured.",
|
||||
}[discordResult] || "";
|
||||
showGate(result.status === 0 ? result.data.error : discordMessage);
|
||||
if (discordResult === "code" && result.status !== 0) {
|
||||
showDiscordCode("");
|
||||
}
|
||||
else {
|
||||
showGate(result.status === 0 ? result.data.error : discordMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -4,5 +4,5 @@
|
||||
<style>@font-face{font-family:d;src:url('/fonts/CCDigitalDelivery-Regular.otf')}*{box-sizing:border-box}body{margin:0;padding:48px 16px;background:#000;color:#fff;font:16px/1.45 d,system-ui}main{max-width:420px;margin:auto;padding:28px;background:#0d0d0d;border:1px solid #2e2e2e;border-radius:18px}.logo{height:62px}h1{font-size:25px;margin:10px 0}p,label{color:#aaa}label{display:block;margin:14px 0 5px}input,select,button{width:100%;font:inherit;color:#fff;background:#000;border:1px solid #444;border-radius:12px;padding:10px 12px}button{margin-top:20px;background:#fff;color:#000;font-weight:bold;cursor:pointer}.status{min-height:24px;margin:14px 0 0;color:#aaa}a{color:#fff}</style></head>
|
||||
<body><main><img class="logo" src="/logo.png" alt=""><h1>Account recovery</h1>
|
||||
<div id="request"><p>We’ll send a one-time recovery link to the email saved on your account.</p><form id="request-form"><label>Username<input id="username" autocomplete="username" required></label><label>Recovery email<input id="email" type="email" autocomplete="email" required></label><label>What do you need to recover?<select id="kind"><option value="password">Password</option><option value="twoStep">2FA</option></select></label><button>Send recovery link</button></form></div>
|
||||
<div id="complete" hidden><p id="intro"></p><form id="complete-form"><label id="password-label">New password<input id="password" type="password" autocomplete="new-password" minlength="10"></label><button>Complete recovery</button></form></div><p class="status" id="status" role="status"></p><p><a href="/account">Back to sign in</a></p></main>
|
||||
<script>"use strict";const $=id=>document.getElementById(id),token=new URLSearchParams(location.search).get('token');const post=async(path,body)=>{const r=await fetch(path,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});return {ok:r.ok,data:await r.json()}};const status=(text)=>$('status').textContent=text;if(token){post('/account/api/recover/check',{token}).then(r=>{if(!r.ok){status(r.data.error);return}$('request').hidden=true;$('complete').hidden=false;const two=r.data.kind==='twoStep';$('intro').textContent=two?'Confirm that you want to remove 2FA from this account.':'Choose a new password.';$('password-label').hidden=two;$('password').required=!two}).catch(()=>status('The server did not answer.'))}$('request-form').addEventListener('submit',async e=>{e.preventDefault();const r=await post('/account/api/recover/request',{username:$('username').value,email:$('email').value,kind:$('kind').value});status(r.data.ok||'Could not start recovery.')});$('complete-form').addEventListener('submit',async e=>{e.preventDefault();const r=await post('/account/api/recover/complete',{token,password:$('password').value});status(r.data.ok||r.data.error||'Could not complete recovery.')});</script></body></html>
|
||||
<div id="complete" hidden><p id="intro"></p><form id="complete-form"><label id="password-label"><span id="password-text">New password</span><input id="password" type="password" autocomplete="new-password" minlength="10" required></label><button>Complete recovery</button></form></div><p class="status" id="status" role="status"></p><p><a href="/account">Back to sign in</a></p></main>
|
||||
<script>"use strict";const $=id=>document.getElementById(id),token=new URLSearchParams(location.search).get('token');const post=async(path,body)=>{const r=await fetch(path,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});return {ok:r.ok,data:await r.json()}};const status=(text)=>$('status').textContent=text;if(token){post('/account/api/recover/check',{token}).then(r=>{if(!r.ok){status(r.data.error);return}$('request').hidden=true;$('complete').hidden=false;const two=r.data.kind==='twoStep';$('intro').textContent=two?'Enter your password to remove 2FA from this account.':'Choose a new password.';$('password-text').textContent=two?'Your password':'New password';$('password').autocomplete=two?'current-password':'new-password';$('password').minLength=two?1:10}).catch(()=>status('The server did not answer.'))}$('request-form').addEventListener('submit',async e=>{e.preventDefault();const r=await post('/account/api/recover/request',{username:$('username').value,email:$('email').value,kind:$('kind').value});status(r.data.ok||'Could not start recovery.')});$('complete-form').addEventListener('submit',async e=>{e.preventDefault();const r=await post('/account/api/recover/complete',{token,password:$('password').value});status(r.data.ok||r.data.error||'Could not complete recovery.')});</script></body></html>
|
||||
@@ -1,5 +1,6 @@
|
||||
package
|
||||
{
|
||||
import achievement.AchievementXtCommManager;
|
||||
import avatar.AvatarManager;
|
||||
import avatar.AvatarWorldView;
|
||||
import buddy.Buddy;
|
||||
@@ -1837,6 +1838,8 @@ package
|
||||
// profile changes only optional rendering work, never the
|
||||
// game's native 24 FPS (which would slow its animations).
|
||||
// 9008 Play as your pet (gui.PetInventory, lib/pets.js): 1 on.
|
||||
// 9009 Expanded Inventory (expandedInventoryOn): 1 on.
|
||||
// 9010 Items a row with it on: 3, 4 or 5; unset is 5.
|
||||
|
||||
|
||||
private static var _smoothTimer:Timer;
|
||||
@@ -2068,6 +2071,33 @@ package
|
||||
{
|
||||
return gMainFrame.userInfo.userVarCache.getUserVarValueById(9002) == 1;
|
||||
}
|
||||
|
||||
// "Expanded Inventory" (Strawberry Jam's): the clothes and item
|
||||
// pickers show more, smaller items a row. user var 9009, 1 on; the
|
||||
// + and - by the avatar editor's item counter pick 3, 4 or 5 a row,
|
||||
// user var 9010 (unset is 5, the widest, so turning it on shows).
|
||||
public static function expandedInventoryOn() : Boolean
|
||||
{
|
||||
return settingOf(9009) == 1;
|
||||
}
|
||||
|
||||
public static function inventoryColumns() : int
|
||||
{
|
||||
var _loc1_:int = settingOf(9010);
|
||||
if(!expandedInventoryOn())
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
return _loc1_ >= 3 && _loc1_ <= 5 ? _loc1_ : 5;
|
||||
}
|
||||
|
||||
// the next of 3, 4 and 5 a row, round about; param1 is 1 or -1.
|
||||
public static function stepInventoryColumns(param1:int) : void
|
||||
{
|
||||
var _loc2_:int = (inventoryColumns() - 3 + param1 + 3) % 3 + 3;
|
||||
gMainFrame.userInfo.userVarCache.updateUserVar(9010,_loc2_);
|
||||
AchievementXtCommManager.requestSetUserVar(9010,_loc2_);
|
||||
}
|
||||
|
||||
// the arrow key a key stands for: itself, or with the setting on and
|
||||
// nothing being typed, the arrow W, A, S or D stands for.
|
||||
|
||||
+113
-3
@@ -38,6 +38,8 @@ package gui
|
||||
import flash.events.MouseEvent;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Point;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
import gui.itemWindows.ItemWindowNameBarIcon;
|
||||
import gui.itemWindows.ItemWindowOriginal;
|
||||
import inventory.Iitem;
|
||||
@@ -242,6 +244,10 @@ package gui
|
||||
private var _itemClothingWindows:WindowAndScrollbarGenerator;
|
||||
|
||||
private var _itemTradeWindows:WindowAndScrollbarGenerator;
|
||||
|
||||
private var _inventoryPlusBtn:Sprite;
|
||||
|
||||
private var _inventoryMinusBtn:Sprite;
|
||||
|
||||
public var numClothingItemsInTradeListInitially:int;
|
||||
|
||||
@@ -549,6 +555,7 @@ package gui
|
||||
{
|
||||
createItemWindows(_currClothesArray,avEditor.itemBlock);
|
||||
}
|
||||
setupInventoryControls();
|
||||
addListeners();
|
||||
KeepAlive.startKATimer(avEditor);
|
||||
_loadingMediaHelper.destroy();
|
||||
@@ -1920,6 +1927,7 @@ package gui
|
||||
var _loc7_:Boolean = false;
|
||||
var _loc4_:Number = NaN;
|
||||
var _loc5_:Object = null;
|
||||
var _loc9_:int = 0;
|
||||
_loc6_ = param1 == _currTradesArray;
|
||||
if(_loc6_)
|
||||
{
|
||||
@@ -1979,7 +1987,9 @@ package gui
|
||||
}
|
||||
_loc5_ = generateItemAndIndexArray(param1);
|
||||
_loc8_ = new WindowAndScrollbarGenerator();
|
||||
_loc8_.init(param2.width,param2.height,3,_loc4_,3,4,12,2,2,2 * 0.5,0,ItemWindowOriginal,_loc5_.items,"icon",0,{
|
||||
// Expanded Inventory: more, smaller items a row (AJClient.inventoryColumns)
|
||||
_loc9_ = AJClient.inventoryColumns();
|
||||
_loc8_.init(param2.width,param2.height,3,_loc4_,_loc9_,4,_loc9_ * 4,2,2,2 * 0.5,0,ItemWindowOriginal,_loc5_.items,"icon",0,{
|
||||
"mouseDown":winMouseClick,
|
||||
"mouseOver":winMouseOver,
|
||||
"mouseOut":winMouseOut,
|
||||
@@ -1990,7 +2000,8 @@ package gui
|
||||
"showAddRemoveBtns":_loc6_,
|
||||
"isChoosingForTradeList":_loc7_,
|
||||
"indexArray":_loc5_.indexes,
|
||||
"mannequinInvIdx":(_mannequinDenItemHelper != null ? _mannequinDenItemHelper.mannequin.invIdx : -1)
|
||||
"mannequinInvIdx":(_mannequinDenItemHelper != null ? _mannequinDenItemHelper.mannequin.invIdx : -1),
|
||||
"itemScale":3 / _loc9_
|
||||
});
|
||||
if(param2 == avEditor.itemBlock)
|
||||
{
|
||||
@@ -2656,7 +2667,106 @@ package gui
|
||||
avEditor.sortPopup.visible = false;
|
||||
createItemWindows(_currClothesArray,avEditor.itemBlock);
|
||||
}
|
||||
|
||||
|
||||
// Expanded Inventory's + and - (Strawberry Jam's), by the item counter:
|
||||
// 3, 4 or 5 items a row (AJClient.inventoryColumns). they are put in
|
||||
// the counter, where Strawberry Jam puts them by it, so they are shown
|
||||
// and hidden with it.
|
||||
private function setupInventoryControls() : void
|
||||
{
|
||||
var _loc1_:MovieClip = null;
|
||||
var _loc2_:Point = null;
|
||||
if(_inventoryPlusBtn && _inventoryPlusBtn.parent)
|
||||
{
|
||||
_inventoryPlusBtn.parent.removeChild(_inventoryPlusBtn);
|
||||
}
|
||||
if(_inventoryMinusBtn && _inventoryMinusBtn.parent)
|
||||
{
|
||||
_inventoryMinusBtn.parent.removeChild(_inventoryMinusBtn);
|
||||
}
|
||||
_inventoryPlusBtn = null;
|
||||
_inventoryMinusBtn = null;
|
||||
if(!AJClient.expandedInventoryOn() || !avEditor || !("itemCounter" in avEditor) || !avEditor.itemCounter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc1_ = avEditor.itemCounter;
|
||||
_loc2_ = _loc1_.globalToLocal(avEditor.localToGlobal(new Point(_loc1_.x + _loc1_.counterTxt.width - 30,_loc1_.y - 7)));
|
||||
_inventoryPlusBtn = createSmallButton("+");
|
||||
_inventoryMinusBtn = createSmallButton("-");
|
||||
_inventoryPlusBtn.x = _loc2_.x;
|
||||
_inventoryPlusBtn.y = _loc2_.y;
|
||||
_inventoryMinusBtn.x = _loc2_.x + 18;
|
||||
_inventoryMinusBtn.y = _loc2_.y;
|
||||
_inventoryPlusBtn.addEventListener("mouseDown",onInventoryPlus,false,0,true);
|
||||
_inventoryMinusBtn.addEventListener("mouseDown",onInventoryMinus,false,0,true);
|
||||
_loc1_.addChild(_inventoryPlusBtn);
|
||||
_loc1_.addChild(_inventoryMinusBtn);
|
||||
}
|
||||
|
||||
private function createSmallButton(param1:String) : Sprite
|
||||
{
|
||||
var _loc2_:Sprite = new Sprite();
|
||||
var _loc3_:TextField = new TextField();
|
||||
_loc2_.graphics.beginFill(3355443,0.8);
|
||||
_loc2_.graphics.drawRoundRect(0,0,16,16,3,3);
|
||||
_loc2_.graphics.endFill();
|
||||
_loc2_.graphics.lineStyle(1,16777215,0.5);
|
||||
_loc2_.graphics.drawRoundRect(0,0,16,16,3,3);
|
||||
_loc3_.defaultTextFormat = new TextFormat("_sans",12,16777215,true);
|
||||
_loc3_.text = param1;
|
||||
_loc3_.x = 4;
|
||||
_loc3_.y = 1;
|
||||
_loc3_.width = 12;
|
||||
_loc3_.height = 16;
|
||||
_loc3_.selectable = false;
|
||||
_loc3_.mouseEnabled = false;
|
||||
_loc2_.addChild(_loc3_);
|
||||
_loc2_.buttonMode = true;
|
||||
_loc2_.mouseChildren = false;
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private function onInventoryPlus(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopPropagation();
|
||||
stepInventoryColumns(1);
|
||||
}
|
||||
|
||||
private function onInventoryMinus(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopPropagation();
|
||||
stepInventoryColumns(-1);
|
||||
}
|
||||
|
||||
private function stepInventoryColumns(param1:int) : void
|
||||
{
|
||||
AJClient.stepInventoryColumns(param1);
|
||||
refreshInventoryLayout();
|
||||
}
|
||||
|
||||
// the clothes drawn again as many a row as now asked for, and the + and
|
||||
// - put up or taken away (also when Settings turns the switch). only
|
||||
// while the clothes are shown (the counter is, then): the trade list's
|
||||
// windows take the new count when they are next made.
|
||||
public function refreshInventoryLayout() : void
|
||||
{
|
||||
if(!avEditor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_itemClothingWindows && "itemCounter" in avEditor && avEditor.itemCounter && avEditor.itemCounter.visible)
|
||||
{
|
||||
_itemClothingWindows.destroy();
|
||||
_itemClothingWindows = null;
|
||||
if(_currClothesArray)
|
||||
{
|
||||
createItemWindows(_currClothesArray,avEditor.itemBlock);
|
||||
}
|
||||
}
|
||||
setupInventoryControls();
|
||||
}
|
||||
|
||||
private static function sortByName(param1:Object, param2:Object) : int
|
||||
{
|
||||
var _loc3_:String = String(param1.name).toLowerCase();
|
||||
|
||||
@@ -229,6 +229,11 @@ package avatar
|
||||
|
||||
private var _chatBalloon:ChatBalloon;
|
||||
|
||||
// Set while the normal uc packet is handled, immediately before its
|
||||
// message is drawn. Keeping setMessage's original arguments preserves
|
||||
// the game's pending-message and chat-history behaviour.
|
||||
private var _nextChatStyle:String = "";
|
||||
|
||||
// "..." where the chat bubble goes, while the player is typing
|
||||
// (AJClient.onTyping). gone when a line arrives, when they stop, or
|
||||
// TYPING_SHOWN ms after they last said they were, if a "stopped" is lost.
|
||||
@@ -805,6 +810,16 @@ package avatar
|
||||
return false;
|
||||
}
|
||||
|
||||
// plays an animation and keeps it as this avatar's idle, so the client's
|
||||
// own idle refreshes don't put the avatar back to standing. Walking or
|
||||
// an action replaces it, as with any idle.
|
||||
public function holdIdleAnim(param1:int, param2:Boolean) : void
|
||||
{
|
||||
_lastIdleAnim = param1;
|
||||
_lastIdleFlip = param2;
|
||||
playAnim(param1,param2);
|
||||
}
|
||||
|
||||
public function getBaseIdle() : int
|
||||
{
|
||||
return _roomType == 1 ? 32 : 14;
|
||||
@@ -1166,6 +1181,11 @@ package avatar
|
||||
}
|
||||
}
|
||||
|
||||
public function setChatStyle(param1:String) : void
|
||||
{
|
||||
_nextChatStyle = param1;
|
||||
}
|
||||
|
||||
public function setMessage(param1:String, param2:int) : void
|
||||
{
|
||||
var _loc3_:Boolean = false;
|
||||
@@ -1181,8 +1201,9 @@ package avatar
|
||||
}
|
||||
_loc3_ = true;
|
||||
}
|
||||
_chatBalloon.setText(param1,_loc3_);
|
||||
updateOffScreenChat(param1,_loc3_);
|
||||
_chatBalloon.setText(param1,_loc3_,true,_nextChatStyle);
|
||||
updateOffScreenChat(param1,_loc3_,_nextChatStyle);
|
||||
_nextChatStyle = "";
|
||||
}
|
||||
|
||||
public function setCustomAdventureMessage(param1:String, param2:String, param3:int, param4:int, param5:Boolean = false) : void
|
||||
@@ -2583,11 +2604,11 @@ package avatar
|
||||
_secondaryEmot.y = -235 * _loc1_;
|
||||
}
|
||||
|
||||
private function updateOffScreenChat(param1:String, param2:Boolean) : void
|
||||
private function updateOffScreenChat(param1:String, param2:Boolean, param3:String = "") : void
|
||||
{
|
||||
if(shouldShowOffscreen() && gMainFrame.userInfo.myUserName != _avatar.userName && _hudViewHolder)
|
||||
{
|
||||
_hudViewHolder.questChatBalloon.setText(param1,param2,false);
|
||||
_hudViewHolder.questChatBalloon.setText(param1,param2,false,param3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+369
-5
@@ -1,12 +1,19 @@
|
||||
package gui
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.GradientType;
|
||||
import flash.display.SpreadMethod;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.TextEvent;
|
||||
import flash.filters.ConvolutionFilter;
|
||||
import flash.geom.ColorTransform;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.geom.Matrix;
|
||||
import flash.text.TextField;
|
||||
import flash.utils.setTimeout;
|
||||
import loader.MediaHelper;
|
||||
@@ -71,13 +78,36 @@ package gui
|
||||
// emoji panel, say), which the game's font has none of: each is drawn
|
||||
// as a picture of it, from the server (/emoji/<code points>.png,
|
||||
// Twemoji's). each is {at, clip}: where its gap starts in the text shown.
|
||||
// Three spaces fit the line-height-sized emoji without the noticeably
|
||||
// wide hole four spaces left between neighbouring words or emoji.
|
||||
private static const INLINE_GAP:String = " ";
|
||||
// Four spaces reserve a full inline cell. placeInline() scales wide
|
||||
// artwork to this measured slot with a one-pixel gutter on each side,
|
||||
// so consecutive emoji neither overlap nor touch surrounding text.
|
||||
private static const INLINE_GAP:String = " ";
|
||||
|
||||
private static const LONGEST_EMOTE_CODE:int = 16;
|
||||
|
||||
private var _inline:Array = [];
|
||||
|
||||
// The server appends this compact style to spoken chat packets. It is
|
||||
// deliberately drawn over the stock balloon rather than requiring new
|
||||
// artwork, so every combination of the account-page colour controls is
|
||||
// available at once.
|
||||
private var _styleFill:Sprite;
|
||||
private var _styleMask:Bitmap;
|
||||
private var _styleBorderLayer:Bitmap;
|
||||
private var _styleBackground:uint;
|
||||
private var _styleAccent:uint;
|
||||
private var _styleText:uint;
|
||||
private var _styleBorder:uint;
|
||||
private var _styleOpacity:Number;
|
||||
private var _styleAnimation:String = "none";
|
||||
private var _styleSpeed:Number = 100;
|
||||
private var _styleGradient:String = "linear";
|
||||
private var _styleAngle:Number = 45;
|
||||
private var _styleStrength:Number = 100;
|
||||
private var _styleOutline:Number = 1;
|
||||
private var _styleStops:Array = [];
|
||||
private var _styleElapsed:int = 0;
|
||||
private var _hasStyle:Boolean = false;
|
||||
|
||||
public function ChatBalloon()
|
||||
{
|
||||
@@ -112,7 +142,7 @@ package gui
|
||||
setEmoteBgOffsets();
|
||||
}
|
||||
|
||||
public function setText(param1:String, param2:Boolean = false, param3:Boolean = true) : void
|
||||
public function setText(param1:String, param2:Boolean = false, param3:Boolean = true, param4:String = "") : void
|
||||
{
|
||||
if(_emote)
|
||||
{
|
||||
@@ -142,7 +172,8 @@ package gui
|
||||
_msgTxt.height;
|
||||
// AJClient.whisperNext is set by the server's "xw" just ahead of a
|
||||
// whispered line.
|
||||
_balloonBG.transform.colorTransform = AJClient.whisperNext ? AJClient.whisperTint() : new ColorTransform();
|
||||
var _loc10_:Boolean = AJClient.whisperNext;
|
||||
_balloonBG.transform.colorTransform = _loc10_ ? AJClient.whisperTint() : new ColorTransform();
|
||||
AJClient.whisperNext = false;
|
||||
if(!_hasSbTextfield)
|
||||
{
|
||||
@@ -172,6 +203,10 @@ package gui
|
||||
{
|
||||
_msgTxt.textColor = 4477529;
|
||||
}
|
||||
// Emoji-window choices are inline chat content, so even a lone one
|
||||
// keeps the selected chat style. Standalone game emotes use
|
||||
// setEmote(), where any previous custom bubble is cleared.
|
||||
applyStyle(param4,param2,_loc10_);
|
||||
// tags (AJClient.resolveMentions): once the server says which "@"s
|
||||
// are players', light blue and underlined, each a link to that
|
||||
// player's card, if the balloon still says the same. (the field is
|
||||
@@ -199,6 +234,12 @@ package gui
|
||||
}
|
||||
});
|
||||
}
|
||||
// The stock balloon has now stretched to the measured text height;
|
||||
// redraw the custom body at its final size (also for still styles).
|
||||
if(_hasStyle)
|
||||
{
|
||||
drawStyle();
|
||||
}
|
||||
_timeout = 8000;
|
||||
if(param3 && this.parent)
|
||||
{
|
||||
@@ -212,6 +253,311 @@ package gui
|
||||
setTimeout(placeInline,42);
|
||||
}
|
||||
}
|
||||
|
||||
// `background,accent,text,border,opacity,animation,speed,gradient,angle,
|
||||
// strength,outline,stops`, emitted by
|
||||
// lib/chatstyles.js. Staff warnings and whispers intentionally retain
|
||||
// their existing colours, so those states are never made ambiguous.
|
||||
private function applyStyle(param1:String, param2:Boolean, param3:Boolean) : void
|
||||
{
|
||||
clearStyle();
|
||||
if(param1 == "" || param2 || param3 || !GuiManager.customChatBubblesEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var _loc4_:Array = param1.split(",");
|
||||
if((_loc4_.length != 7 && _loc4_.length != 10 && _loc4_.length != 11 && _loc4_.length != 12) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[0]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[1]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[2]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[3]) || !/^(?:2[5-9]|[3-9][0-9]|100)$/.test(_loc4_[4]) || !/^(?:[4-9][0-9]|[12][0-9]{2}|300)$/.test(_loc4_[6]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_styleBackground = uint(parseInt(_loc4_[0],16));
|
||||
_styleAccent = uint(parseInt(_loc4_[1],16));
|
||||
_styleText = uint(parseInt(_loc4_[2],16));
|
||||
_styleBorder = uint(parseInt(_loc4_[3],16));
|
||||
_styleOpacity = Math.max(0.25,Math.min(1,Number(_loc4_[4]) / 100));
|
||||
_styleAnimation = _loc4_[5] == "pulse" || _loc4_[5] == "shimmer" || _loc4_[5] == "flow" || _loc4_[5] == "rainbow" ? _loc4_[5] : "none";
|
||||
_styleSpeed = Math.max(40,Math.min(300,Number(_loc4_[6])));
|
||||
_styleGradient = _loc4_.length > 7 && (_loc4_[7] == "solid" || _loc4_[7] == "radial") ? _loc4_[7] : "linear";
|
||||
_styleAngle = _loc4_.length > 8 && int(_loc4_[8]) >= 0 && int(_loc4_[8]) <= 315 && int(_loc4_[8]) % 45 == 0 ? int(_loc4_[8]) : 45;
|
||||
_styleStrength = _loc4_.length > 9 ? Math.max(0,Math.min(100,int(_loc4_[9]))) : 100;
|
||||
_styleOutline = _loc4_.length > 10 ? Math.max(0,Math.min(4,int(_loc4_[10]))) : 1;
|
||||
_styleStops = parseStyleStops(_loc4_.length > 11 ? String(_loc4_[11]) : "");
|
||||
_styleElapsed = 0;
|
||||
_hasStyle = true;
|
||||
_msgTxt.textColor = _styleText;
|
||||
// The native artwork remains underneath as the exact outer border;
|
||||
// drawStyle masks the custom fill to that artwork's silhouette.
|
||||
_balloonBG.transform.colorTransform = colourTransform(_styleBorder,1);
|
||||
}
|
||||
|
||||
private function clearStyle() : void
|
||||
{
|
||||
if(_styleFill)
|
||||
{
|
||||
_styleFill.mask = null;
|
||||
}
|
||||
if(_styleFill && _styleFill.parent)
|
||||
{
|
||||
_styleFill.parent.removeChild(_styleFill);
|
||||
}
|
||||
if(_styleMask)
|
||||
{
|
||||
if(_styleMask.parent)
|
||||
{
|
||||
_styleMask.parent.removeChild(_styleMask);
|
||||
}
|
||||
if(_styleMask.bitmapData)
|
||||
{
|
||||
_styleMask.bitmapData.dispose();
|
||||
}
|
||||
}
|
||||
if(_styleBorderLayer)
|
||||
{
|
||||
if(_styleBorderLayer.parent)
|
||||
{
|
||||
_styleBorderLayer.parent.removeChild(_styleBorderLayer);
|
||||
}
|
||||
if(_styleBorderLayer.bitmapData)
|
||||
{
|
||||
_styleBorderLayer.bitmapData.dispose();
|
||||
}
|
||||
}
|
||||
_styleFill = null;
|
||||
_styleMask = null;
|
||||
_styleBorderLayer = null;
|
||||
_styleAnimation = "none";
|
||||
_styleGradient = "linear";
|
||||
_styleStops = [];
|
||||
_hasStyle = false;
|
||||
}
|
||||
|
||||
private static function colourTransform(param1:uint, param2:Number) : ColorTransform
|
||||
{
|
||||
return new ColorTransform(0,0,0,param2,param1 >> 16 & 255,param1 >> 8 & 255,param1 & 255,0);
|
||||
}
|
||||
|
||||
private static function blendColour(param1:uint, param2:uint, param3:Number) : uint
|
||||
{
|
||||
var _loc4_:Number = 1 - param3;
|
||||
var _loc5_:uint = uint((param1 >> 16 & 255) * _loc4_ + (param2 >> 16 & 255) * param3);
|
||||
var _loc6_:uint = uint((param1 >> 8 & 255) * _loc4_ + (param2 >> 8 & 255) * param3);
|
||||
var _loc7_:uint = uint((param1 & 255) * _loc4_ + (param2 & 255) * param3);
|
||||
return _loc5_ << 16 | _loc6_ << 8 | _loc7_;
|
||||
}
|
||||
|
||||
private static function rainbowColour(param1:Number) : uint
|
||||
{
|
||||
var _loc2_:int = int(param1 * 6) % 6;
|
||||
var _loc3_:Number = param1 * 6 - int(param1 * 6);
|
||||
var _loc4_:uint = uint(255 * _loc3_);
|
||||
var _loc5_:uint = 255 - _loc4_;
|
||||
if(_loc2_ == 0)
|
||||
{
|
||||
return 0xFF0000 | _loc4_ << 8;
|
||||
}
|
||||
if(_loc2_ == 1)
|
||||
{
|
||||
return _loc5_ << 16 | 0xFF00;
|
||||
}
|
||||
if(_loc2_ == 2)
|
||||
{
|
||||
return 0x00FF00 | _loc4_;
|
||||
}
|
||||
if(_loc2_ == 3)
|
||||
{
|
||||
return _loc5_ << 8 | 0xFF;
|
||||
}
|
||||
if(_loc2_ == 4)
|
||||
{
|
||||
return _loc4_ << 16 | 0xFF;
|
||||
}
|
||||
return 0xFF0000 | _loc5_ << 8;
|
||||
}
|
||||
|
||||
private function parseStyleStops(param1:String) : Array
|
||||
{
|
||||
var _loc1_:Array = [];
|
||||
var _loc2_:Array = String(param1 || "").split(";");
|
||||
var _loc3_:int = 0;
|
||||
var _loc4_:Array = null;
|
||||
var _loc5_:int = -1;
|
||||
while(_loc3_ < _loc2_.length && _loc2_.length >= 2 && _loc2_.length <= 5)
|
||||
{
|
||||
_loc4_ = String(_loc2_[_loc3_]).split(":");
|
||||
if(_loc4_.length != 2 || !/^[0-9a-fA-F]{6}$/.test(String(_loc4_[0])) || !/^100$|^[1-9]?\d$/.test(String(_loc4_[1])) || int(_loc4_[1]) <= _loc5_)
|
||||
{
|
||||
_loc1_ = [];
|
||||
break;
|
||||
}
|
||||
_loc5_ = int(_loc4_[1]);
|
||||
_loc1_.push({"color":uint(parseInt(_loc4_[0],16)),"position":_loc5_});
|
||||
_loc3_++;
|
||||
}
|
||||
if(_loc1_.length < 2 || int(_loc1_[0].position) != 0 || int(_loc1_[_loc1_.length - 1].position) != 100)
|
||||
{
|
||||
_loc1_ = [{"color":_styleBackground,"position":0},{"color":_styleAccent,"position":100}];
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
private function drawStyle() : void
|
||||
{
|
||||
if(!_hasStyle || !_balloonBG || !_msgTxt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_styleFill == null)
|
||||
{
|
||||
_styleFill = new Sprite();
|
||||
_styleFill.mouseEnabled = false;
|
||||
_styleFill.mouseChildren = false;
|
||||
// Flash uses a Bitmap mask's alpha channel only when both sides
|
||||
// are cached. Without this it masks to the bitmap's rectangle.
|
||||
_styleFill.cacheAsBitmap = true;
|
||||
// The stock background contains masks and nested timeline layers.
|
||||
// Put this beside it, directly below the text, so those masks
|
||||
// cannot hide custom colours or animated gradients.
|
||||
var _loc8_:DisplayObject = _msgTxt as DisplayObject;
|
||||
while(_loc8_ && _loc8_.parent != this)
|
||||
{
|
||||
_loc8_ = _loc8_.parent;
|
||||
}
|
||||
if(_loc8_ && _loc8_.parent == this)
|
||||
{
|
||||
addChildAt(_styleFill,getChildIndex(_loc8_));
|
||||
}
|
||||
else
|
||||
{
|
||||
addChildAt(_styleFill,Math.min(numChildren,getChildIndex(_balloonBG) + 1));
|
||||
}
|
||||
}
|
||||
var _loc9_:Rectangle = _balloonBG.getBounds(this);
|
||||
if(_styleMask == null)
|
||||
{
|
||||
// Snapshot only the native bubble's alpha and use it as a mask.
|
||||
// Eroding that silhouette by the chosen outline width leaves the
|
||||
// tinted native artwork visible as an even border, including the
|
||||
// speech tail. A rounded-rectangle inset cannot match that shape.
|
||||
var _loc10_:BitmapData = new BitmapData(Math.max(1,Math.ceil(_loc9_.width)),Math.max(1,Math.ceil(_loc9_.height)),true,0);
|
||||
var _loc11_:Matrix = _balloonBG.transform.matrix.clone();
|
||||
_loc11_.translate(-_loc9_.x,-_loc9_.y);
|
||||
_loc10_.draw(_balloonBG,_loc11_,null,null,null,true);
|
||||
var _loc20_:BitmapData = new BitmapData(_loc10_.width,_loc10_.height,true,0);
|
||||
_loc20_.threshold(_loc10_,_loc10_.rect,new Point(),">",0x08000000,0xFFFFFFFF,0xFF000000,false);
|
||||
_loc10_.dispose();
|
||||
var _loc32_:BitmapData = _loc20_.clone();
|
||||
if(_styleOutline > 0)
|
||||
{
|
||||
var _loc21_:int = int(_styleOutline) * 2 + 1;
|
||||
var _loc22_:Array = [];
|
||||
var _loc23_:int = 0;
|
||||
var _loc24_:int = 0;
|
||||
var _loc25_:int = 0;
|
||||
while(_loc24_ < _loc21_)
|
||||
{
|
||||
_loc25_ = 0;
|
||||
while(_loc25_ < _loc21_)
|
||||
{
|
||||
if(Math.abs(_loc24_ - int(_styleOutline)) + Math.abs(_loc25_ - int(_styleOutline)) <= _styleOutline)
|
||||
{
|
||||
_loc22_.push(1);
|
||||
_loc23_++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc22_.push(0);
|
||||
}
|
||||
_loc25_++;
|
||||
}
|
||||
_loc24_++;
|
||||
}
|
||||
var _loc26_:BitmapData = new BitmapData(_loc20_.width,_loc20_.height,true,0);
|
||||
// Outside the snapshot must be transparent. Clamping repeats
|
||||
// opaque edge pixels and prevents the top/side of the mask
|
||||
// from shrinking, which made thick outlines appear only at
|
||||
// the lower edge and corners.
|
||||
_loc26_.applyFilter(_loc20_,_loc20_.rect,new Point(),new ConvolutionFilter(_loc21_,_loc21_,_loc22_,_loc23_,0,false,false,0,0));
|
||||
_loc20_.fillRect(_loc20_.rect,0);
|
||||
_loc20_.threshold(_loc26_,_loc26_.rect,new Point(),">",0xFE000000,0xFFFFFFFF,0xFF000000,false);
|
||||
_loc26_.dispose();
|
||||
// Keep only the pixels removed from the inner mask. This is a
|
||||
// solid, even ring and does not inherit the stock art's uneven
|
||||
// border opacity.
|
||||
_loc32_.threshold(_loc20_,_loc20_.rect,new Point(),">",0x00000000,0x00000000,0xFF000000,false);
|
||||
_loc32_.colorTransform(_loc32_.rect,colourTransform(_styleBorder,1));
|
||||
_styleBorderLayer = new Bitmap(_loc32_,"auto",true);
|
||||
_styleBorderLayer.x = _loc9_.x;
|
||||
_styleBorderLayer.y = _loc9_.y;
|
||||
_styleBorderLayer.cacheAsBitmap = true;
|
||||
addChildAt(_styleBorderLayer,getChildIndex(_styleFill));
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc32_.dispose();
|
||||
}
|
||||
_styleMask = new Bitmap(_loc20_,"auto",true);
|
||||
_styleMask.x = _loc9_.x;
|
||||
_styleMask.y = _loc9_.y;
|
||||
_styleMask.cacheAsBitmap = true;
|
||||
addChildAt(_styleMask,getChildIndex(_styleFill));
|
||||
_styleFill.mask = _styleMask;
|
||||
}
|
||||
var _loc1_:Number = _loc9_.x;
|
||||
var _loc2_:Number = _loc9_.y;
|
||||
var _loc3_:Number = Math.max(12,_loc9_.width);
|
||||
var _loc4_:Number = Math.max(12,_loc9_.height);
|
||||
var _loc5_:Number = (_styleElapsed * _styleSpeed / 100000) % 1;
|
||||
var _loc27_:Array = [];
|
||||
var _loc28_:Array = [];
|
||||
var _loc29_:Array = [];
|
||||
var _loc30_:int = 0;
|
||||
var _loc31_:uint = 0;
|
||||
while(_loc30_ < _styleStops.length)
|
||||
{
|
||||
_loc31_ = uint(_styleStops[_loc30_].color);
|
||||
if(_loc30_ > 0)
|
||||
{
|
||||
_loc31_ = blendColour(_styleBackground,_loc31_,_styleStrength / 100);
|
||||
}
|
||||
if(_styleAnimation == "shimmer")
|
||||
{
|
||||
_loc31_ = blendColour(_loc31_,_styleBackground,(Math.sin(_loc5_ * Math.PI * 2) + 1) * 0.5);
|
||||
}
|
||||
_loc27_.push(_loc31_);
|
||||
_loc28_.push(_styleOpacity);
|
||||
_loc29_.push(int(Number(_styleStops[_loc30_].position) * 2.55));
|
||||
_loc30_++;
|
||||
}
|
||||
_styleFill.graphics.clear();
|
||||
var _loc7_:Matrix = new Matrix();
|
||||
var _loc12_:Number = _styleAngle * Math.PI / 180;
|
||||
var _loc13_:String = _styleGradient == "radial" ? GradientType.RADIAL : GradientType.LINEAR;
|
||||
_loc7_.createGradientBox(_loc3_,_loc4_,_loc12_,_loc1_,_loc2_);
|
||||
if(_styleGradient == "solid" && _styleAnimation != "rainbow")
|
||||
{
|
||||
_styleFill.graphics.beginFill(_styleBackground,_styleOpacity);
|
||||
}
|
||||
else if(_styleAnimation == "flow")
|
||||
{
|
||||
_loc7_.createGradientBox(_loc3_ * 0.75,_loc4_ * 0.75,_loc12_,_loc1_ + Math.cos(_loc12_) * (_loc5_ * 2 - 1) * _loc3_,_loc2_ + Math.sin(_loc12_) * (_loc5_ * 2 - 1) * _loc4_);
|
||||
_styleFill.graphics.beginGradientFill(_loc13_,_loc27_,_loc28_,_loc29_,_loc7_,SpreadMethod.REFLECT);
|
||||
}
|
||||
else if(_styleAnimation == "rainbow" && _styleGradient == "solid")
|
||||
{
|
||||
_styleFill.graphics.beginFill(rainbowColour(_loc5_),_styleOpacity);
|
||||
}
|
||||
else if(_styleAnimation == "rainbow")
|
||||
{
|
||||
_styleFill.graphics.beginGradientFill(_loc13_,[rainbowColour(_loc5_),rainbowColour((_loc5_ + 0.18) % 1),rainbowColour((_loc5_ + 0.36) % 1)],[_styleOpacity,_styleOpacity,_styleOpacity],[0,128,255],_loc7_);
|
||||
}
|
||||
else
|
||||
{
|
||||
_styleFill.graphics.beginGradientFill(_loc13_,_loc27_,_loc28_,_loc29_,_loc7_);
|
||||
}
|
||||
_styleFill.graphics.drawRect(_loc1_,_loc2_,_loc3_,_loc4_);
|
||||
_styleFill.graphics.endFill();
|
||||
_styleFill.alpha = _styleAnimation == "pulse" ? 0.55 + 0.45 * (Math.sin(_loc5_ * Math.PI * 2) + 1) * 0.5 : 1;
|
||||
}
|
||||
|
||||
// the text with each emote code and emoji (above) replaced by a gap, the
|
||||
// picture for it kept in _inline. what is neither stays as typed.
|
||||
@@ -428,6 +774,8 @@ package gui
|
||||
var _loc1_:Object = null;
|
||||
var _loc2_:Rectangle = null;
|
||||
var _loc3_:Rectangle = null;
|
||||
var _loc4_:Number = 0;
|
||||
var _loc5_:Number = 1;
|
||||
for each(_loc1_ in _inline)
|
||||
{
|
||||
_loc2_ = _msgTxt.getCharBoundaries(_loc1_.at);
|
||||
@@ -445,6 +793,13 @@ package gui
|
||||
_loc1_.clip.scaleX = _loc1_.clip.scaleY = 1;
|
||||
_loc1_.clip.height = _loc2_.height;
|
||||
_loc1_.clip.scaleX = _loc1_.clip.scaleY;
|
||||
_loc4_ = Math.max(1,_loc3_.x + _loc3_.width - _loc2_.x - 2);
|
||||
if(_loc1_.clip.width > _loc4_)
|
||||
{
|
||||
_loc5_ = _loc4_ / _loc1_.clip.width;
|
||||
_loc1_.clip.scaleX *= _loc5_;
|
||||
_loc1_.clip.scaleY *= _loc5_;
|
||||
}
|
||||
_loc1_.clip.x = _msgTxt.x + (_loc2_.x + _loc3_.x + _loc3_.width) / 2;
|
||||
_loc1_.clip.y = _msgTxt.y + _loc2_.y + _loc2_.height / 2;
|
||||
if(_loc1_.clip.parent != this)
|
||||
@@ -662,6 +1017,10 @@ package gui
|
||||
|
||||
public function setEmote(param1:Sprite, param2:int = -1) : void
|
||||
{
|
||||
// Native one-emote messages hide balloon_bg. Remove any independent
|
||||
// custom fill left by the preceding text message as well.
|
||||
clearStyle();
|
||||
_balloonBG.transform.colorTransform = new ColorTransform();
|
||||
clearMentionBacks();
|
||||
if(this.currentFrameLabel != "advBtn")
|
||||
{
|
||||
@@ -718,6 +1077,11 @@ package gui
|
||||
|
||||
public function heartbeat(param1:int) : void
|
||||
{
|
||||
if(_styleAnimation != "none" && visible)
|
||||
{
|
||||
_styleElapsed += param1;
|
||||
drawStyle();
|
||||
}
|
||||
if(_timeout && _permEmoteMediaId < 0)
|
||||
{
|
||||
if(param1 >= _timeout)
|
||||
|
||||
@@ -438,6 +438,7 @@ package gui
|
||||
var _loc6_:int = 0;
|
||||
var _loc9_:int = 0;
|
||||
var _loc7_:int = 0;
|
||||
var _loc17_:int = 0;
|
||||
while(_popup.itemBlock.numChildren > 1)
|
||||
{
|
||||
_popup.itemBlock.removeChildAt(_popup.itemBlock.numChildren - 1);
|
||||
@@ -627,7 +628,9 @@ package gui
|
||||
_itemDenWindows = _currItemWindow;
|
||||
}
|
||||
_popup.searchBar.mouse.searchTxt.text = "";
|
||||
_currItemWindow.init(_popup.itemBlock.width,_popup.itemBlock.height,2,_loc11_,3,4,12,2,2,0,2 * 0.5,ItemWindowOriginal,_loc3_,"icon",0,{
|
||||
// Expanded Inventory: more, smaller items a row (AJClient.inventoryColumns)
|
||||
_loc17_ = AJClient.inventoryColumns();
|
||||
_currItemWindow.init(_popup.itemBlock.width,_popup.itemBlock.height,2,_loc11_,_loc17_,4,_loc17_ * 4,2,2,0,2 * 0.5,ItemWindowOriginal,_loc3_,"icon",0,{
|
||||
"mouseDown":winMouseDown,
|
||||
"mouseOver":winMouseOver,
|
||||
"mouseOut":winMouseOut
|
||||
@@ -635,7 +638,8 @@ package gui
|
||||
"giftItemIdx":_giftItemIdx,
|
||||
"isECard":_type == 1,
|
||||
"isChoosingForTradeList":_type == 0 || _type == 3,
|
||||
"indexArray":_loc5_
|
||||
"indexArray":_loc5_,
|
||||
"itemScale":3 / _loc17_
|
||||
},onListLoaded);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -15,13 +15,10 @@ package gui
|
||||
import den.DenStateItem;
|
||||
import den.DenXtCommManager;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.geom.Point;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
import flash.utils.Timer;
|
||||
import gui.itemWindows.ItemWindowOriginal;
|
||||
import localization.LocalizationManager;
|
||||
@@ -142,8 +139,6 @@ package gui
|
||||
private var _privacyId:int;
|
||||
|
||||
private var _itemSetEvent:DenItemHolderEvent;
|
||||
|
||||
private var _layerControls:Sprite;
|
||||
|
||||
public function DenEditor()
|
||||
{
|
||||
@@ -162,7 +157,6 @@ package gui
|
||||
_roomMgr = RoomManagerWorld.instance;
|
||||
_denItemHolder = _roomMgr.denItemHolder;
|
||||
_guiLayer.addChild(_denEditor);
|
||||
createLayerControls();
|
||||
initAssetVisibility();
|
||||
setupPlayerItems();
|
||||
DenXtCommManager.denEditorDIResponseCallback = diResponseCallback;
|
||||
@@ -176,7 +170,6 @@ package gui
|
||||
_denItemHolder.removeEventListener("OnItemRemoved",onDenItemRemoved);
|
||||
_denItemHolder.removeEventListener("OnSaveState",onDenSaveState);
|
||||
removeListeners();
|
||||
destroyLayerControls();
|
||||
_guiLayer.removeChild(_denEditor);
|
||||
if(_denLockPopup)
|
||||
{
|
||||
@@ -1203,76 +1196,6 @@ package gui
|
||||
_roomMgr.spawnNewDenItem(_loc3_);
|
||||
}
|
||||
|
||||
// Small controls added at runtime so every den item can be stacked
|
||||
// deliberately, instead of relying solely on where its feet land.
|
||||
private function createLayerControls() : void
|
||||
{
|
||||
_layerControls = new Sprite();
|
||||
_layerControls.x = _denEditor.width - 258;
|
||||
_layerControls.y = 12;
|
||||
_layerControls.addChild(makeLayerLabel("Selected item layer",0,0,230,22,13,16774041));
|
||||
addLayerButton("Send behind",0,onSendBehind);
|
||||
addLayerButton("Bring on top",116,onBringOnTop);
|
||||
addLayerButton("Use natural depth",0,onResetLayer,62,230,30);
|
||||
_denEditor.addChild(_layerControls);
|
||||
}
|
||||
|
||||
private function addLayerButton(param1:String, param2:Number, param3:Function, param4:Number = 26, param5:Number = 110, param6:Number = 30) : void
|
||||
{
|
||||
var _loc6_:Sprite = new Sprite();
|
||||
_loc6_.x = param2;
|
||||
_loc6_.y = param4;
|
||||
_loc6_.buttonMode = true;
|
||||
_loc6_.mouseChildren = false;
|
||||
_loc6_.graphics.beginFill(5986842,0.96);
|
||||
_loc6_.graphics.drawRoundRect(0,0,param5,param6,8,8);
|
||||
_loc6_.graphics.endFill();
|
||||
_loc6_.addChild(makeLayerLabel(param1,0,5,param5,param6 - 5,12,16777215));
|
||||
_loc6_.addEventListener("mouseDown",param3,false,0,true);
|
||||
_layerControls.addChild(_loc6_);
|
||||
}
|
||||
|
||||
private function makeLayerLabel(param1:String, param2:Number, param3:Number, param4:Number, param5:Number, param6:int, param7:uint) : TextField
|
||||
{
|
||||
var _loc8_:TextField = new TextField();
|
||||
_loc8_.x = param2;
|
||||
_loc8_.y = param3;
|
||||
_loc8_.width = param4;
|
||||
_loc8_.height = param5;
|
||||
_loc8_.selectable = false;
|
||||
_loc8_.mouseEnabled = false;
|
||||
_loc8_.defaultTextFormat = new TextFormat("Arial",param6,param7,true,null,null,null,null,"center");
|
||||
_loc8_.text = param1;
|
||||
return _loc8_;
|
||||
}
|
||||
|
||||
private function onSendBehind(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
_denItemHolder.sendSelectedBehind();
|
||||
}
|
||||
|
||||
private function onBringOnTop(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
_denItemHolder.bringSelectedToFront();
|
||||
}
|
||||
|
||||
private function onResetLayer(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
_denItemHolder.resetSelectedStacking();
|
||||
}
|
||||
|
||||
private function destroyLayerControls() : void
|
||||
{
|
||||
if(_layerControls && _layerControls.parent)
|
||||
{
|
||||
_layerControls.parent.removeChild(_layerControls);
|
||||
}
|
||||
_layerControls = null;
|
||||
}
|
||||
|
||||
private function onClose(param1:MouseEvent) : void
|
||||
{
|
||||
SBTracker.pop();
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
package ecard
|
||||
{
|
||||
import buddy.BuddyManager;
|
||||
import com.sbi.client.SFEvent;
|
||||
import com.sbi.popup.SBOkPopup;
|
||||
import gui.DarkenManager;
|
||||
import gui.GuiManager;
|
||||
import gui.SafeChatManager;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class ECardXtCommManager
|
||||
{
|
||||
private static var _requestCallback:Function;
|
||||
private static var _readResponseCallback:Function;
|
||||
private static var _sendResponseCallback:Function;
|
||||
private static var _privacyResponseCallback:Function;
|
||||
private static var _giftResponseCallback:Function;
|
||||
private static var _giftRequestCallbackQueue:Object;
|
||||
public static var _deleteResponseCallback:Function;
|
||||
private static var NUM_JAGS_PER_NON_BUDDY_PER_SESSION:int = 5;
|
||||
private static var NUM_JAGS_PER_BUDDY_PER_SESSION:int = 25;
|
||||
private static var _jaggedPlayers:Object;
|
||||
private static var _privacySettingId:int;
|
||||
|
||||
public function ECardXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
_jaggedPlayers = {};
|
||||
_giftRequestCallbackQueue = {};
|
||||
}
|
||||
|
||||
public static function sendECardListRequest(param1:Function = null) : void
|
||||
{
|
||||
var _loc2_:int = 0;
|
||||
if(param1 != null)
|
||||
{
|
||||
_loc2_ = 1;
|
||||
_requestCallback = param1;
|
||||
}
|
||||
gMainFrame.server.setXtObject_Str("el",[_loc2_]);
|
||||
}
|
||||
|
||||
public static function sendECardReadRequest(param1:int, param2:Function = null) : void
|
||||
{
|
||||
if(!gMainFrame.clientInfo.invisMode)
|
||||
{
|
||||
if(param2 != null)
|
||||
{
|
||||
_readResponseCallback = param2;
|
||||
}
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
gMainFrame.server.setXtObject_Str("er",[param1]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendECardSendRequest(param1:String, param2:String, param3:int, param4:int, param5:int, param6:String, param7:int, param8:int, param9:int, param10:Function = null) : Boolean
|
||||
{
|
||||
if(_jaggedPlayers[param1] == null)
|
||||
{
|
||||
_jaggedPlayers[param1] = 0;
|
||||
}
|
||||
var _loc11_:int = BuddyManager.isBuddy(param1) ? NUM_JAGS_PER_BUDDY_PER_SESSION : NUM_JAGS_PER_NON_BUDDY_PER_SESSION;
|
||||
// Moderators need to be able to send follow-up cards while helping
|
||||
// players, so do not apply the local per-recipient session cap.
|
||||
if(gMainFrame.userInfo.isModerator || _jaggedPlayers[param1] < _loc11_)
|
||||
{
|
||||
_jaggedPlayers[param1]++;
|
||||
if(param10 != null)
|
||||
{
|
||||
_sendResponseCallback = param10;
|
||||
}
|
||||
gMainFrame.server.setXtObject_Str("es",[param1,param3,param4,param5,param6,param7,param8,param9]);
|
||||
return true;
|
||||
}
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
new SBOkPopup(GuiManager.guiLayer,LocalizationManager.translateIdAndInsertOnly(14691,param2));
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function sendECardDeleteRequest(param1:int, param2:Function = null) : void
|
||||
{
|
||||
if(param2 != null)
|
||||
{
|
||||
_deleteResponseCallback = param2;
|
||||
}
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
gMainFrame.server.setXtObject_Str("ed",[param1]);
|
||||
}
|
||||
|
||||
public static function sendECardBuddyRequest(param1:int, param2:Boolean) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("eb",[param1,param2 ? 1 : 0]);
|
||||
}
|
||||
|
||||
public static function sendECardAcceptDiscardGiftRequest(param1:int, param2:Boolean, param3:Function, param4:int = -1, param5:ECard = null) : void
|
||||
{
|
||||
if(!gMainFrame.clientInfo.invisMode)
|
||||
{
|
||||
if(param3 != null)
|
||||
{
|
||||
_giftResponseCallback = param3;
|
||||
}
|
||||
_giftRequestCallbackQueue[param1] = param5;
|
||||
gMainFrame.server.setXtObject_Str("eg",param4 >= 0 ? [param1,param2 ? 1 : 0,param4] : [param1,param2 ? 1 : 0]);
|
||||
}
|
||||
else if(param3 != null)
|
||||
{
|
||||
param3(0,true,param5);
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendECardClearCache() : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("ec",[]);
|
||||
}
|
||||
|
||||
public static function sendECardPrivacySettingUpdateRequest(param1:int, param2:Function) : void
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
_privacyResponseCallback = param2;
|
||||
_privacySettingId = param1;
|
||||
gMainFrame.server.setXtObject_Str("ei",[param1]);
|
||||
}
|
||||
|
||||
public static function handleXtReply(param1:SFEvent) : void
|
||||
{
|
||||
var _loc2_:Object = param1.obj;
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
switch(_loc2_[0])
|
||||
{
|
||||
case "el":
|
||||
eCardListResponse(_loc2_);
|
||||
break;
|
||||
case "er":
|
||||
eCardReadResponse(_loc2_);
|
||||
break;
|
||||
case "ed":
|
||||
eCardDeleteResponse(_loc2_);
|
||||
break;
|
||||
case "es":
|
||||
eCardSendResponse(_loc2_);
|
||||
break;
|
||||
case "eg":
|
||||
eCardGiftResponse(_loc2_);
|
||||
break;
|
||||
case "eb":
|
||||
eCardBuddyResponse(_loc2_);
|
||||
break;
|
||||
case "ep":
|
||||
eCardPushHandler(_loc2_);
|
||||
break;
|
||||
case "eu":
|
||||
eCardUpdateHandler(_loc2_);
|
||||
break;
|
||||
case "ei":
|
||||
eCardIsolationHandler(_loc2_);
|
||||
break;
|
||||
default:
|
||||
throw new Error("ECardXtCommManager: Received illegal cmd: " + _loc2_[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardListResponse(param1:Object) : void
|
||||
{
|
||||
var _loc7_:ECard = null;
|
||||
var _loc5_:int = 0;
|
||||
if(!SafeChatManager.hasLoadedLists)
|
||||
{
|
||||
SafeChatManager.safeChatStringForCode(eCardListResponse,[param1],"",1);
|
||||
return;
|
||||
}
|
||||
var _loc2_:int = int(param1[2]);
|
||||
var _loc3_:Array = new Array(_loc2_);
|
||||
if(_loc2_ == -1)
|
||||
{
|
||||
_loc2_ = 0;
|
||||
}
|
||||
var _loc4_:int = 0;
|
||||
var _loc6_:int = 3;
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < _loc2_)
|
||||
{
|
||||
_loc7_ = new ECard();
|
||||
_loc7_.init(int(param1[_loc6_++]),param1[_loc6_++],int(param1[_loc6_++]),int(param1[_loc6_++]),param1[_loc6_++] == "1",param1[_loc6_++],int(param1[_loc6_++]),int(param1[_loc6_++]),uint(param1[_loc6_++]),param1[_loc6_++],int(param1[_loc6_++]),int(param1[_loc6_++]),int(param1[_loc6_++]),int(param1[_loc6_++]),int(param1[_loc6_++]),param1[_loc6_++],param1[_loc6_++]);
|
||||
setGiftName(_loc7_);
|
||||
_loc3_[_loc2_ - 1 - _loc5_] = _loc7_;
|
||||
if(!_loc7_.isRead)
|
||||
{
|
||||
_loc4_++;
|
||||
}
|
||||
_loc5_++;
|
||||
}
|
||||
ECardManager.processECardList(_loc3_,_loc4_);
|
||||
if(_requestCallback != null)
|
||||
{
|
||||
_requestCallback(_loc3_);
|
||||
_requestCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setGiftName(param1:ECard) : void
|
||||
{
|
||||
if(param1.msg.match("(^[0-9]{1,2},[0-9]{1,2}$)|(^[0-9]{1,2}$)"))
|
||||
{
|
||||
param1.msg = SafeChatManager.safeChatStringForCode(null,null,param1.msg,1);
|
||||
}
|
||||
if(param1.type == 4)
|
||||
{
|
||||
param1.giftName = LocalizationManager.translateIdAndInsertOnly(param1.giftName == "1" ? 11114 : 11097,Utility.convertNumberToString(int(param1.giftName)));
|
||||
}
|
||||
else if(param1.type == 9)
|
||||
{
|
||||
param1.giftName = LocalizationManager.translateIdAndInsertOnly(param1.giftName == "1" ? 11116 : 11103,Utility.convertNumberToString(int(param1.giftName)));
|
||||
}
|
||||
else if(param1.type == 5)
|
||||
{
|
||||
param1.giftName = LocalizationManager.translateIdAndInsertOnly(15000,LocalizationManager.translateIdOnly(int(param1.giftName)));
|
||||
}
|
||||
else
|
||||
{
|
||||
param1.giftName = LocalizationManager.translateIdOnly(int(param1.giftName));
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardReadResponse(param1:Object) : void
|
||||
{
|
||||
if(_readResponseCallback != null)
|
||||
{
|
||||
_readResponseCallback(int(param1[2]),param1[3] == "1");
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardDeleteResponse(param1:Object) : void
|
||||
{
|
||||
var _loc2_:int = 0;
|
||||
var _loc6_:Boolean = param1[2] == "1" ? true : false;
|
||||
var _loc4_:int = int(param1[3]);
|
||||
var _loc3_:int = 4;
|
||||
var _loc5_:Array = new Array(_loc4_);
|
||||
_loc2_ = 0;
|
||||
while(_loc2_ < _loc4_)
|
||||
{
|
||||
_loc5_[_loc2_] = param1[_loc3_++];
|
||||
_loc2_++;
|
||||
}
|
||||
if(_deleteResponseCallback != null)
|
||||
{
|
||||
_deleteResponseCallback(_loc5_,_loc6_);
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardSendResponse(param1:Object) : void
|
||||
{
|
||||
if(_sendResponseCallback != null)
|
||||
{
|
||||
_sendResponseCallback(param1[2]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardGiftResponse(param1:Object) : void
|
||||
{
|
||||
var _loc2_:ECard = null;
|
||||
if(_giftResponseCallback != null)
|
||||
{
|
||||
_loc2_ = _giftRequestCallbackQueue[int(param1[2])];
|
||||
delete _giftRequestCallbackQueue[int(param1[2])];
|
||||
_giftResponseCallback(int(param1[2]),param1[3] == "1",_loc2_);
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardBuddyResponse(param1:Object) : void
|
||||
{
|
||||
if(param1[2] == -1)
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
new SBOkPopup(GuiManager.guiLayer,LocalizationManager.translateIdOnly(14692));
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardIsolationHandler(param1:Object) : void
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
var _loc2_:Boolean = param1[2] == "1";
|
||||
if(_loc2_)
|
||||
{
|
||||
gMainFrame.userInfo.eCardPrivacySettings = _privacySettingId;
|
||||
}
|
||||
if(_privacyResponseCallback != null)
|
||||
{
|
||||
_privacyResponseCallback(_loc2_,_privacySettingId);
|
||||
_privacyResponseCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function eCardPushHandler(param1:Object) : void
|
||||
{
|
||||
if(!SafeChatManager.hasLoadedLists)
|
||||
{
|
||||
SafeChatManager.safeChatStringForCode(eCardPushHandler,[param1],"",1);
|
||||
return;
|
||||
}
|
||||
var _loc2_:ECard = new ECard();
|
||||
var _loc3_:int = 2;
|
||||
_loc2_.init(int(param1[_loc3_++]),param1[_loc3_++],int(param1[_loc3_++]),int(param1[_loc3_++]),param1[_loc3_++] == "1",param1[_loc3_++],int(param1[_loc3_++]),int(param1[_loc3_++]),uint(param1[_loc3_++]),param1[_loc3_++],int(param1[_loc3_++]),int(param1[_loc3_++]),int(param1[_loc3_++]),int(param1[_loc3_++]),int(param1[_loc3_++]),param1[_loc3_++],param1[_loc3_++]);
|
||||
setGiftName(_loc2_);
|
||||
ECardManager.processECardPush(_loc2_);
|
||||
}
|
||||
|
||||
private static function eCardUpdateHandler(param1:Object) : void
|
||||
{
|
||||
ECardManager.processECardUpdate(param1[2],param1[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,8 @@ package gui
|
||||
private static var _namebarBadgeList:Array;
|
||||
|
||||
private static var _sharedObj:SharedObject;
|
||||
|
||||
private static var _customChatBubbles:Boolean = true;
|
||||
|
||||
private static var _giftGemsMediaHelper:MediaHelper;
|
||||
|
||||
@@ -365,11 +367,13 @@ package gui
|
||||
public static function setupSharedObject() : void
|
||||
{
|
||||
_sharedObj = null;
|
||||
_customChatBubbles = true;
|
||||
if(gMainFrame.myFlashVarUserName != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_sharedObj = SharedObject.getLocal(gMainFrame.myFlashVarUserName);
|
||||
_customChatBubbles = _sharedObj.data.customChatBubbles !== false;
|
||||
if(_sharedObj.data.cursor == null || _sharedObj.data.cursor == "custom")
|
||||
{
|
||||
CursorManager.switchToCursor("custom_cursor");
|
||||
@@ -459,6 +463,31 @@ package gui
|
||||
{
|
||||
return _sharedObj;
|
||||
}
|
||||
|
||||
// A local accessibility/preference switch: players can keep their own
|
||||
// saved style visible to others while rendering every bubble normally
|
||||
// on this installation.
|
||||
public static function customChatBubblesEnabled() : Boolean
|
||||
{
|
||||
return _customChatBubbles;
|
||||
}
|
||||
|
||||
public static function setCustomChatBubblesEnabled(param1:Boolean) : void
|
||||
{
|
||||
_customChatBubbles = param1;
|
||||
if(_sharedObj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_sharedObj.data.customChatBubbles = param1;
|
||||
try
|
||||
{
|
||||
_sharedObj.flush();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static function startFFM(param1:Boolean = false) : void
|
||||
{
|
||||
|
||||
@@ -61,7 +61,11 @@ package gui.itemWindows
|
||||
private var _hasSetState:Boolean;
|
||||
|
||||
private var _isSellShop:Boolean;
|
||||
|
||||
|
||||
// smaller with Expanded Inventory on (AJClient.inventoryColumns): 3
|
||||
// over the items a row, so a row is as wide as the game's three.
|
||||
private var _itemScale:Number = 1;
|
||||
|
||||
public function ItemWindowOriginal(param1:Function, param2:Object, param3:String, param4:int, param5:Function = null, param6:Function = null, param7:Function = null, param8:Function = null, param9:Object = null)
|
||||
{
|
||||
var _loc11_:int = 0;
|
||||
@@ -89,6 +93,10 @@ package gui.itemWindows
|
||||
_loc11_ = int(param9.indexArray.length);
|
||||
_loc10_ = int(_loc11_ - 1 >= param4 ? param9.indexArray[param4] : param4);
|
||||
}
|
||||
if(param9.itemScale > 0)
|
||||
{
|
||||
_itemScale = param9.itemScale;
|
||||
}
|
||||
}
|
||||
super("itemWindow",param1,param2,param3,_loc10_,param5,param6,param7,param8,true);
|
||||
}
|
||||
@@ -576,6 +584,19 @@ package gui.itemWindows
|
||||
|
||||
override protected function onWindowLoadCallback() : void
|
||||
{
|
||||
// the generator spaces the windows by their width and height,
|
||||
// which are sizeCont's (ItemWindowBase) and do not shrink with the
|
||||
// window, so sizeCont is made as much smaller.
|
||||
if(_itemScale != 1 && _window)
|
||||
{
|
||||
if(_window.hasOwnProperty("sizeCont") && _window.sizeCont)
|
||||
{
|
||||
_window.sizeCont.width *= _itemScale;
|
||||
_window.sizeCont.height *= _itemScale;
|
||||
}
|
||||
this.scaleX = _itemScale;
|
||||
this.scaleY = _itemScale;
|
||||
}
|
||||
if(_windowLoadedCallback != null)
|
||||
{
|
||||
resetVisibility();
|
||||
|
||||
+936
-1
@@ -7,12 +7,20 @@ package gui.itemWindows
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.GradientType;
|
||||
import flash.display.SpreadMethod;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.geom.Matrix;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.Event;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.navigateToURL;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldType;
|
||||
import flash.text.TextFormat;
|
||||
import flash.utils.getTimer;
|
||||
import gamePlayFlow.GamePlay;
|
||||
import gui.CursorManager;
|
||||
import gui.GuiHud;
|
||||
@@ -24,9 +32,49 @@ package gui.itemWindows
|
||||
|
||||
public class ItemWindowToggle extends ItemWindowBase
|
||||
{
|
||||
|
||||
|
||||
private static const SLIDER_RECT:Rectangle = new Rectangle(15,15.5,82,0);
|
||||
|
||||
// A lightweight editor made from native Flash display objects. Keeping it
|
||||
// here lets the existing Settings button open it without a browser bridge.
|
||||
private static const CHAT_COLOUR_KEYS:Array = ["background","accent","text","border"];
|
||||
private static const CHAT_ANIMATIONS:Array = ["none","pulse","shimmer","flow","rainbow"];
|
||||
private static const CHAT_GRADIENTS:Array = ["linear","radial","solid"];
|
||||
private static const CHAT_ANGLES:Array = [0,45,90,135,180,225,270,315];
|
||||
private static const CHAT_STRENGTHS:Array = [0,25,50,75,100];
|
||||
private static const CHAT_OUTLINES:Array = [0,1,2,3,4];
|
||||
private static const CHAT_OPACITIES:Array = [25,40,55,70,85,100];
|
||||
private static const CHAT_SPEEDS:Array = [40,70,100,150,200,300];
|
||||
private static const CHAT_PALETTE:Array = [
|
||||
"ffffff","f3ead1","ffd6d6","ffe0b2","fff3b0","dff2bd","bcebcf","b9efff",
|
||||
"cbd5ff","e1d0ff","ffd6f3","d6d6d6","9aabb0","ff5a68","ff8a3d","ffd23f",
|
||||
"54a96b","26c6da","41a9df","5b7cfa","734fd1","ef5da8","8f5a3c","445559",
|
||||
"1f2937","5b203e","214d31","16435b","18264b","342018","000000","ff0069"
|
||||
];
|
||||
private static const CHAT_PRESETS:Array = [
|
||||
{"name":"Ocean","background":"d9fbff","accent":"41a9df","text":"16435b","border":"237ba9","opacity":85,"gradient":"linear","angle":45,"strength":100,"animation":"shimmer","speed":100,"outline":1},
|
||||
{"name":"Sunset","background":"ffcf70","accent":"ef5da8","text":"5b203e","border":"d74277","opacity":85,"gradient":"linear","angle":135,"strength":100,"animation":"flow","speed":100,"outline":1},
|
||||
{"name":"Forest","background":"dff2bd","accent":"54a96b","text":"214d31","border":"387747","opacity":85,"gradient":"radial","angle":45,"strength":75,"animation":"pulse","speed":70,"outline":1},
|
||||
{"name":"Midnight","background":"18264b","accent":"734fd1","text":"ffffff","border":"9c83ef","opacity":85,"gradient":"radial","angle":45,"strength":100,"animation":"shimmer","speed":100,"outline":2},
|
||||
{"name":"Candy","background":"ffe1f1","accent":"9ce7ff","text":"8f1f63","border":"ef6bb2","opacity":85,"gradient":"linear","angle":90,"strength":100,"animation":"flow","speed":150,"outline":1},
|
||||
{"name":"Rainbow","background":"ff5a68","accent":"7b67ff","text":"ffffff","border":"ff3d94","opacity":85,"gradient":"linear","angle":0,"strength":100,"animation":"rainbow","speed":100,"outline":1}
|
||||
];
|
||||
private static var _chatStyle:Object = {"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"};
|
||||
private static var _chatPopup:Sprite;
|
||||
private static var _chatFields:Array;
|
||||
private static var _chatButtons:Object;
|
||||
private static var _chatStatus:TextField;
|
||||
private static var _chatPreview:Sprite;
|
||||
private static var _chatSwatches:Array;
|
||||
private static var _chatPanel:Sprite;
|
||||
private static var _chatPalette:Sprite;
|
||||
private static var _chatColourIndex:int = -1;
|
||||
private static var _chatStops:Array = [{"color":"ffffff","position":0},{"color":"dfe8ff","position":100}];
|
||||
private static var _chatSelectedStop:int = 0;
|
||||
private static var _chatStopSprites:Array;
|
||||
private static var _chatTrack:Sprite;
|
||||
private static var _chatPreset:int = -1;
|
||||
|
||||
private var _lock:MovieClip;
|
||||
|
||||
private var _currHeight:int;
|
||||
@@ -173,6 +221,7 @@ package gui.itemWindows
|
||||
case "itemFinder":
|
||||
case "itemMaker":
|
||||
case "chatFilter":
|
||||
case "chatBubble":
|
||||
case "themeMenu":
|
||||
case "themePick":
|
||||
case "savedMenu":
|
||||
@@ -181,6 +230,10 @@ package gui.itemWindows
|
||||
_window.goNowBtn.mouse.mouse.txt.text = _currItem.btnLabel;
|
||||
_window.goNowBtn.mouse.up.txt.text = _currItem.btnLabel;
|
||||
_window.labelTxtCont.labelTxt.text = _currItem.labelLabel;
|
||||
if(_currItem.frame == "chatBubble")
|
||||
{
|
||||
_window.icon["" + _window.icon.currentFrameLabel].gotoAndStop("startingOn");
|
||||
}
|
||||
break;
|
||||
case "hideBlocked":
|
||||
showHideBlocked();
|
||||
@@ -188,6 +241,9 @@ package gui.itemWindows
|
||||
case "customArt":
|
||||
showCustomArt();
|
||||
break;
|
||||
case "expandedInventory":
|
||||
showExpandedInventory();
|
||||
break;
|
||||
case "wasd":
|
||||
showWasd();
|
||||
break;
|
||||
@@ -498,6 +554,879 @@ package gui.itemWindows
|
||||
AchievementXtCommManager.requestSetUserVar(9006,param1 ? 0 : 1);
|
||||
showCustomArt();
|
||||
}
|
||||
|
||||
// "Expanded Inventory" (Strawberry Jam's): more, smaller items a row in
|
||||
// the clothes and item pickers, how many by the + and - at the avatar
|
||||
// editor's item counter (AJClient.inventoryColumns). user var 9009.
|
||||
private function showExpandedInventory() : void
|
||||
{
|
||||
var _loc1_:String = AJClient.expandedInventoryOn() ? "Turn off" : "Turn on";
|
||||
_window.goNowBtn.down.txt.text = _loc1_;
|
||||
_window.goNowBtn.mouse.mouse.txt.text = _loc1_;
|
||||
_window.goNowBtn.mouse.up.txt.text = _loc1_;
|
||||
_window.labelTxtCont.labelTxt.text = "Expanded Inventory";
|
||||
}
|
||||
|
||||
private function setExpandedInventory(param1:Boolean) : void
|
||||
{
|
||||
gMainFrame.userInfo.userVarCache.updateUserVar(9009,param1 ? 1 : 0);
|
||||
AchievementXtCommManager.requestSetUserVar(9009,param1 ? 1 : 0);
|
||||
if(GuiManager.avatarEditor)
|
||||
{
|
||||
GuiManager.avatarEditor.refreshInventoryLayout();
|
||||
}
|
||||
showExpandedInventory();
|
||||
}
|
||||
|
||||
// `xcs` is the account's saved chat style: [background, accent, text,
|
||||
// border, opacity, animation, speed, gradient, angle, strength, outline,
|
||||
// stops]. The server sends it when this
|
||||
// popup opens and whenever it saves, so its state remains authoritative.
|
||||
public static function chatStyleState(param1:Object) : void
|
||||
{
|
||||
if(param1 == null || param1.length < 9)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_chatStyle = {
|
||||
"background":String(param1[2]).toLowerCase(),
|
||||
"accent":String(param1[3]).toLowerCase(),
|
||||
"text":String(param1[4]).toLowerCase(),
|
||||
"border":String(param1[5]).toLowerCase(),
|
||||
"opacity":int(param1[6]),
|
||||
"animation":String(param1[7]),
|
||||
"speed":int(param1[8]),
|
||||
"gradient":param1.length > 9 ? String(param1[9]) : "linear",
|
||||
"angle":param1.length > 10 ? int(param1[10]) : 45,
|
||||
"strength":param1.length > 11 ? int(param1[11]) : 100,
|
||||
"outline":param1.length > 12 ? int(param1[12]) : 1,
|
||||
"stops":param1.length > 13 ? String(param1[13]) : String(param1[2]) + ":0;" + String(param1[3]) + ":100"
|
||||
};
|
||||
_chatStops = parseChatStops(_chatStyle.stops);
|
||||
_chatSelectedStop = 0;
|
||||
_chatPreset = findChatPreset();
|
||||
if(_chatPopup != null)
|
||||
{
|
||||
refreshChatPopup();
|
||||
_chatStatus.text = "Saved. Send a chat message to see it in the room.";
|
||||
}
|
||||
}
|
||||
|
||||
private static function showChatBubbleEditor() : void
|
||||
{
|
||||
var _loc1_:Sprite = null;
|
||||
var _loc2_:Sprite = null;
|
||||
var _loc3_:TextField = null;
|
||||
var _loc4_:int = 0;
|
||||
var _loc5_:String = null;
|
||||
var _loc6_:Number = NaN;
|
||||
var _loc7_:Number = NaN;
|
||||
if(_chatPopup != null || GuiManager.guiLayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_chatPopup = new Sprite();
|
||||
// guiLayer uses the SWF's design coordinates even when the browser
|
||||
// stretches the Stage. Using stageWidth here scaled the popup twice.
|
||||
_loc6_ = 900;
|
||||
_loc7_ = 550;
|
||||
_chatPopup.mouseEnabled = false;
|
||||
_chatPopup.graphics.beginFill(0,0.48);
|
||||
_chatPopup.graphics.drawRect(0,0,_loc6_,_loc7_);
|
||||
_chatPopup.graphics.endFill();
|
||||
_loc1_ = new Sprite();
|
||||
_loc1_.x = (_loc6_ - 660) * 0.5;
|
||||
_loc1_.y = (_loc7_ - 500) * 0.5;
|
||||
_loc1_.mouseEnabled = false;
|
||||
_loc1_.graphics.lineStyle(5,0x73431F,1,true);
|
||||
_loc1_.graphics.beginFill(0xF2E2B9,1);
|
||||
_loc1_.graphics.drawRoundRect(0,0,660,500,28,28);
|
||||
_loc1_.graphics.endFill();
|
||||
_chatPopup.addChild(_loc1_);
|
||||
_chatPanel = _loc1_;
|
||||
_loc3_ = chatText("Chat Bubble",28,22,390,28,0x5A2C19,true);
|
||||
_loc1_.addChild(_loc3_);
|
||||
_loc1_.addChild(chatText("Click a colour square for the palette, or type a six-digit hex.",28,58,590,15,0x5A2C19,false));
|
||||
_chatFields = [];
|
||||
_chatSwatches = [];
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
_loc5_ = String(CHAT_COLOUR_KEYS[_loc4_]);
|
||||
_loc1_.addChild(chatText(_loc4_ == 0 ? "Gradient start" : _loc4_ == 1 ? "Gradient end" : _loc5_.charAt(0).toUpperCase() + _loc5_.substr(1),30,95 + _loc4_ * 44,130,15,0x5A2C19,false));
|
||||
_loc3_ = chatText("",155,90 + _loc4_ * 44,105,17,0x342018,false);
|
||||
_loc3_.type = TextFieldType.INPUT;
|
||||
_loc3_.selectable = true;
|
||||
_loc3_.restrict = "0-9a-fA-F";
|
||||
_loc3_.maxChars = 6;
|
||||
_loc3_.background = true;
|
||||
_loc3_.backgroundColor = 0xFFFFFF;
|
||||
_loc3_.border = true;
|
||||
_loc3_.borderColor = 0x9A6A45;
|
||||
_loc3_.addEventListener(Event.CHANGE,onChatFieldChange,false,0,true);
|
||||
_loc1_.addChild(_loc3_);
|
||||
_chatFields.push(_loc3_);
|
||||
_loc2_ = new Sprite();
|
||||
_loc2_.x = 270;
|
||||
_loc2_.y = 92 + _loc4_ * 44;
|
||||
_loc2_.name = "chat-colour-" + _loc4_;
|
||||
_loc2_.mouseEnabled = true;
|
||||
_loc2_.buttonMode = true;
|
||||
_loc2_.addEventListener("mouseDown",onChatPopupMouse,false,0,true);
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatSwatches.push(_loc2_);
|
||||
_loc4_++;
|
||||
}
|
||||
_chatButtons = {};
|
||||
_chatPreview = new Sprite();
|
||||
_chatPreview.x = 335;
|
||||
_chatPreview.y = 92;
|
||||
_chatPreview.mouseEnabled = false;
|
||||
_chatPreview.mouseChildren = false;
|
||||
_chatPreview.addChild(chatText("Preview message",5,29,280,17,0x445559,true,"center"));
|
||||
_chatPreview.addEventListener(Event.ENTER_FRAME,onChatPreviewFrame,false,0,true);
|
||||
_loc1_.addChild(_chatPreview);
|
||||
_chatTrack = new Sprite();
|
||||
_chatTrack.x = 335;
|
||||
_chatTrack.y = 181;
|
||||
_loc1_.addChild(_chatTrack);
|
||||
_chatStopSprites = [];
|
||||
_loc2_ = chatButton("",335,215,175,"chat-preset");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.preset = _loc2_;
|
||||
_loc2_ = chatButton("",520,215,115,"chat-position");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.position = _loc2_;
|
||||
_loc1_.addChild(chatButton("Add",335,259,68,"chat-stop-add"));
|
||||
_loc1_.addChild(chatButton("Remove",410,259,68,"chat-stop-remove"));
|
||||
_loc1_.addChild(chatButton("Swap",485,259,68,"chat-swap"));
|
||||
_loc1_.addChild(chatButton("Random",560,259,75,"chat-random"));
|
||||
_loc2_ = chatButton("",30,307,180,"chat-gradient");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.gradient = _loc2_;
|
||||
_loc2_ = chatButton("",240,307,180,"chat-angle");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.angle = _loc2_;
|
||||
_loc2_ = chatButton("",450,307,180,"chat-strength");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.strength = _loc2_;
|
||||
_loc2_ = chatButton("",30,351,180,"chat-animation");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.animation = _loc2_;
|
||||
_loc2_ = chatButton("",240,351,180,"chat-opacity");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.opacity = _loc2_;
|
||||
_loc2_ = chatButton("",450,351,180,"chat-speed");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.speed = _loc2_;
|
||||
_loc2_ = chatButton("",30,397,190,"chat-enabled");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.enabled = _loc2_;
|
||||
_loc2_ = chatButton("",235,397,130,"chat-outline");
|
||||
_loc1_.addChild(_loc2_);
|
||||
_chatButtons.outline = _loc2_;
|
||||
_loc1_.addChild(chatButton("Reset",380,397,110,"chat-reset"));
|
||||
_loc1_.addChild(chatButton("Save",505,397,125,"chat-save"));
|
||||
_chatStatus = chatText("",30,451,590,14,0x5A2C19,false);
|
||||
_loc1_.addChild(_chatStatus);
|
||||
_loc1_.addChild(chatButton("X",600,18,36,"chat-close"));
|
||||
GuiManager.guiLayer.addChild(_chatPopup);
|
||||
refreshChatPopup();
|
||||
// A request also handles a popup opened before the login response.
|
||||
gMainFrame.server.setXtObject_Str("xcs",[]);
|
||||
}
|
||||
|
||||
private static function chatText(param1:String, param2:Number, param3:Number, param4:Number, param5:int, param6:uint, param7:Boolean, param8:String = null) : TextField
|
||||
{
|
||||
var _loc8_:TextField = new TextField();
|
||||
var _loc9_:TextFormat = new TextFormat("Arial",param5,param6,param7);
|
||||
_loc8_.x = param2;
|
||||
_loc8_.y = param3;
|
||||
_loc8_.width = param4;
|
||||
_loc8_.height = param5 + 8;
|
||||
if(param8 != null)
|
||||
{
|
||||
_loc9_.align = param8;
|
||||
}
|
||||
_loc8_.defaultTextFormat = _loc9_;
|
||||
_loc8_.text = param1;
|
||||
_loc8_.setTextFormat(_loc9_);
|
||||
_loc8_.selectable = false;
|
||||
return _loc8_;
|
||||
}
|
||||
|
||||
private static function chatButton(param1:String, param2:Number, param3:Number, param4:Number, param5:String) : Sprite
|
||||
{
|
||||
var _loc6_:Sprite = new Sprite();
|
||||
var _loc7_:TextField = null;
|
||||
_loc6_.name = param5;
|
||||
_loc6_.x = param2;
|
||||
_loc6_.y = param3;
|
||||
_loc6_.buttonMode = true;
|
||||
_loc6_.mouseChildren = false;
|
||||
_loc6_.graphics.lineStyle(2,0x73431F,1,true);
|
||||
_loc6_.graphics.beginFill(0xE7C779,1);
|
||||
_loc6_.graphics.drawRoundRect(0,0,param4,37,14,14);
|
||||
_loc6_.graphics.endFill();
|
||||
_loc7_ = chatText(param1,5,7,param4 - 10,16,0x5A2C19,true,"center");
|
||||
_loc7_.mouseEnabled = false;
|
||||
_loc6_.addChild(_loc7_);
|
||||
_loc6_.addEventListener("mouseDown",onChatPopupMouse,false,0,true);
|
||||
return _loc6_;
|
||||
}
|
||||
|
||||
private static function setChatButton(param1:Sprite, param2:String) : void
|
||||
{
|
||||
TextField(param1.getChildAt(0)).text = param2;
|
||||
}
|
||||
|
||||
private static function refreshChatPopup(param1:Boolean = true) : void
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(_chatFields == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(param1)
|
||||
{
|
||||
while(_loc1_ < CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
TextField(_chatFields[_loc1_]).text = String(_chatStyle[CHAT_COLOUR_KEYS[_loc1_]]);
|
||||
_loc1_++;
|
||||
}
|
||||
}
|
||||
setChatButton(_chatButtons.preset,"Preset: " + (_chatPreset >= 0 ? CHAT_PRESETS[_chatPreset].name : "Custom"));
|
||||
setChatButton(_chatButtons.gradient,"Gradient: " + _chatStyle.gradient);
|
||||
setChatButton(_chatButtons.angle,"Direction: " + _chatStyle.angle + " degrees");
|
||||
setChatButton(_chatButtons.strength,"Strength: " + _chatStyle.strength + "%");
|
||||
setChatButton(_chatButtons.animation,"Animation: " + _chatStyle.animation);
|
||||
setChatButton(_chatButtons.opacity,"Opacity: " + _chatStyle.opacity + "%");
|
||||
setChatButton(_chatButtons.speed,"Speed: " + _chatStyle.speed + "%");
|
||||
setChatButton(_chatButtons.outline,"Outline: " + _chatStyle.outline + " px");
|
||||
setChatButton(_chatButtons.enabled,"Custom bubbles: " + (GuiManager.customChatBubblesEnabled() ? "On" : "Off"));
|
||||
if(_chatSelectedStop < 0 || _chatSelectedStop >= _chatStops.length)
|
||||
{
|
||||
_chatSelectedStop = 0;
|
||||
}
|
||||
setChatButton(_chatButtons.position,(_chatSelectedStop + 1) + "/" + _chatStops.length + (_chatSelectedStop == 0 || _chatSelectedStop == _chatStops.length - 1 ? ": fixed" : ": " + _chatStops[_chatSelectedStop].position + "%"));
|
||||
drawChatGradientTrack();
|
||||
drawChatSwatches();
|
||||
drawChatPreview();
|
||||
_chatStatus.text = "";
|
||||
}
|
||||
|
||||
private static function onChatFieldChange(param1:Event) : void
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
while(_loc1_ < CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
if(validChatHex(TextField(_chatFields[_loc1_]).text))
|
||||
{
|
||||
_chatStyle[CHAT_COLOUR_KEYS[_loc1_]] = TextField(_chatFields[_loc1_]).text.toLowerCase();
|
||||
}
|
||||
_loc1_++;
|
||||
}
|
||||
if(_chatStops && _chatStops.length >= 2)
|
||||
{
|
||||
_chatStops[0].color = _chatStyle.background;
|
||||
_chatStops[_chatStops.length - 1].color = _chatStyle.accent;
|
||||
syncChatStops();
|
||||
}
|
||||
_chatPreset = -1;
|
||||
setChatButton(_chatButtons.preset,"Preset: Custom");
|
||||
drawChatSwatches();
|
||||
drawChatPreview();
|
||||
}
|
||||
|
||||
private static function parseChatStops(param1:String) : Array
|
||||
{
|
||||
var _loc1_:Array = [];
|
||||
var _loc2_:Array = String(param1 || "").split(";");
|
||||
var _loc3_:int = 0;
|
||||
var _loc4_:Array = null;
|
||||
while(_loc3_ < _loc2_.length && _loc2_.length >= 2 && _loc2_.length <= 5)
|
||||
{
|
||||
_loc4_ = String(_loc2_[_loc3_]).split(":");
|
||||
if(_loc4_.length != 2 || !validChatHex(String(_loc4_[0])) || isNaN(Number(_loc4_[1])))
|
||||
{
|
||||
_loc1_ = [];
|
||||
break;
|
||||
}
|
||||
_loc1_.push({"color":String(_loc4_[0]).toLowerCase(),"position":Math.max(0,Math.min(100,int(_loc4_[1])))});
|
||||
_loc3_++;
|
||||
}
|
||||
if(_loc1_.length < 2)
|
||||
{
|
||||
_loc1_ = [{"color":String(_chatStyle.background),"position":0},{"color":String(_chatStyle.accent),"position":100}];
|
||||
}
|
||||
_loc1_.sortOn("position",Array.NUMERIC);
|
||||
_loc1_[0].position = 0;
|
||||
_loc1_[_loc1_.length - 1].position = 100;
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
private static function syncChatStops() : void
|
||||
{
|
||||
var _loc1_:Array = [];
|
||||
var _loc2_:int = 0;
|
||||
if(_chatStops == null || _chatStops.length < 2)
|
||||
{
|
||||
_chatStops = [{"color":String(_chatStyle.background),"position":0},{"color":String(_chatStyle.accent),"position":100}];
|
||||
}
|
||||
_chatStops.sortOn("position",Array.NUMERIC);
|
||||
_chatStops[0].position = 0;
|
||||
_chatStops[_chatStops.length - 1].position = 100;
|
||||
while(_loc2_ < _chatStops.length)
|
||||
{
|
||||
_loc1_.push(String(_chatStops[_loc2_].color) + ":" + int(_chatStops[_loc2_].position));
|
||||
_loc2_++;
|
||||
}
|
||||
_chatStyle.background = String(_chatStops[0].color);
|
||||
_chatStyle.accent = String(_chatStops[_chatStops.length - 1].color);
|
||||
_chatStyle.stops = _loc1_.join(";");
|
||||
}
|
||||
|
||||
private static function drawChatGradientTrack() : void
|
||||
{
|
||||
var _loc1_:Array = [];
|
||||
var _loc2_:Array = [];
|
||||
var _loc3_:Array = [];
|
||||
var _loc4_:int = 0;
|
||||
var _loc5_:Sprite = null;
|
||||
var _loc6_:Matrix = null;
|
||||
if(_chatTrack == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while(_chatTrack.numChildren > 0)
|
||||
{
|
||||
_chatTrack.removeChildAt(0);
|
||||
}
|
||||
_chatTrack.graphics.clear();
|
||||
while(_loc4_ < _chatStops.length)
|
||||
{
|
||||
_loc1_.push(uint(parseInt(_chatStops[_loc4_].color,16)));
|
||||
_loc2_.push(1);
|
||||
_loc3_.push(int(Number(_chatStops[_loc4_].position) * 2.55));
|
||||
_loc4_++;
|
||||
}
|
||||
_loc6_ = new Matrix();
|
||||
_loc6_.createGradientBox(300,14,0,0,0);
|
||||
_chatTrack.graphics.lineStyle(2,0x73431F,1,true);
|
||||
_chatTrack.graphics.beginGradientFill(GradientType.LINEAR,_loc1_,_loc2_,_loc3_,_loc6_);
|
||||
_chatTrack.graphics.drawRoundRect(0,0,300,14,8,8);
|
||||
_chatTrack.graphics.endFill();
|
||||
_chatStopSprites = [];
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _chatStops.length)
|
||||
{
|
||||
_loc5_ = new Sprite();
|
||||
_loc5_.name = "chat-stop-" + _loc4_;
|
||||
_loc5_.x = Number(_chatStops[_loc4_].position) * 3 - 8;
|
||||
_loc5_.y = 14;
|
||||
_loc5_.buttonMode = true;
|
||||
_loc5_.graphics.lineStyle(_loc4_ == _chatSelectedStop ? 3 : 1,_loc4_ == _chatSelectedStop ? 0xFFFFFF : 0x73431F,1,true);
|
||||
_loc5_.graphics.beginFill(uint(parseInt(_chatStops[_loc4_].color,16)),1);
|
||||
_loc5_.graphics.drawCircle(8,8,7);
|
||||
_loc5_.graphics.endFill();
|
||||
_loc5_.addEventListener("mouseDown",onChatPopupMouse,false,0,true);
|
||||
_chatTrack.addChild(_loc5_);
|
||||
_chatStopSprites.push(_loc5_);
|
||||
_loc4_++;
|
||||
}
|
||||
}
|
||||
|
||||
private static function chatBlend(param1:uint, param2:uint, param3:Number) : uint
|
||||
{
|
||||
var _loc4_:Number = 1 - param3;
|
||||
return uint((param1 >> 16 & 255) * _loc4_ + (param2 >> 16 & 255) * param3) << 16 |
|
||||
uint((param1 >> 8 & 255) * _loc4_ + (param2 >> 8 & 255) * param3) << 8 |
|
||||
uint((param1 & 255) * _loc4_ + (param2 & 255) * param3);
|
||||
}
|
||||
|
||||
private static function chatHex(param1:uint) : String
|
||||
{
|
||||
var _loc2_:String = param1.toString(16);
|
||||
while(_loc2_.length < 6)
|
||||
{
|
||||
_loc2_ = "0" + _loc2_;
|
||||
}
|
||||
return _loc2_.substr(-6);
|
||||
}
|
||||
|
||||
private static function chatRainbow(param1:Number) : uint
|
||||
{
|
||||
var _loc2_:int = int(param1 * 6) % 6;
|
||||
var _loc3_:Number = param1 * 6 - int(param1 * 6);
|
||||
var _loc4_:uint = uint(255 * _loc3_);
|
||||
var _loc5_:uint = 255 - _loc4_;
|
||||
if(_loc2_ == 0) return 0xFF0000 | _loc4_ << 8;
|
||||
if(_loc2_ == 1) return _loc5_ << 16 | 0xFF00;
|
||||
if(_loc2_ == 2) return 0x00FF00 | _loc4_;
|
||||
if(_loc2_ == 3) return _loc5_ << 8 | 0xFF;
|
||||
if(_loc2_ == 4) return _loc4_ << 16 | 0xFF;
|
||||
return 0xFF0000 | _loc5_ << 8;
|
||||
}
|
||||
|
||||
private static function onChatPreviewFrame(param1:Event) : void
|
||||
{
|
||||
if(_chatStyle.animation != "none")
|
||||
{
|
||||
drawChatPreview();
|
||||
}
|
||||
}
|
||||
|
||||
private static function drawChatSwatches() : void
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
while(_chatSwatches && _loc1_ < _chatSwatches.length)
|
||||
{
|
||||
Sprite(_chatSwatches[_loc1_]).graphics.clear();
|
||||
Sprite(_chatSwatches[_loc1_]).graphics.lineStyle(1,0x73431F,1,true);
|
||||
Sprite(_chatSwatches[_loc1_]).graphics.beginFill(uint(parseInt(_chatStyle[CHAT_COLOUR_KEYS[_loc1_]],16)),1);
|
||||
Sprite(_chatSwatches[_loc1_]).graphics.drawRoundRect(0,0,24,24,7,7);
|
||||
Sprite(_chatSwatches[_loc1_]).graphics.endFill();
|
||||
_loc1_++;
|
||||
}
|
||||
}
|
||||
|
||||
private static function closeChatPalette() : void
|
||||
{
|
||||
if(_chatPalette && _chatPalette.parent)
|
||||
{
|
||||
_chatPalette.parent.removeChild(_chatPalette);
|
||||
}
|
||||
_chatPalette = null;
|
||||
_chatColourIndex = -1;
|
||||
}
|
||||
|
||||
private static function openChatPalette(param1:int) : void
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
var _loc2_:String = null;
|
||||
var _loc3_:Sprite = null;
|
||||
if(_chatPanel == null || param1 < 0 || param1 > CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
closeChatPalette();
|
||||
_chatColourIndex = param1;
|
||||
_chatPalette = new Sprite();
|
||||
_chatPalette.x = 296;
|
||||
_chatPalette.y = 76;
|
||||
_chatPalette.graphics.lineStyle(3,0x73431F,1,true);
|
||||
_chatPalette.graphics.beginFill(0xF8EDCE,1);
|
||||
_chatPalette.graphics.drawRoundRect(0,0,342,166,18,18);
|
||||
_chatPalette.graphics.endFill();
|
||||
_chatPalette.addChild(chatText("Choose " + (param1 == CHAT_COLOUR_KEYS.length ? "selected stop" : param1 == 0 ? "gradient start" : param1 == 1 ? "gradient end" : CHAT_COLOUR_KEYS[param1]),14,10,275,16,0x5A2C19,true));
|
||||
_chatPalette.addChild(chatButton("X",298,8,30,"chat-palette-close"));
|
||||
while(_loc1_ < CHAT_PALETTE.length)
|
||||
{
|
||||
_loc2_ = String(CHAT_PALETTE[_loc1_]);
|
||||
_loc3_ = new Sprite();
|
||||
_loc3_.name = "chat-pick-" + _loc2_;
|
||||
_loc3_.x = 15 + _loc1_ % 8 * 40;
|
||||
_loc3_.y = 46 + int(_loc1_ / 8) * 28;
|
||||
_loc3_.buttonMode = true;
|
||||
_loc3_.graphics.lineStyle(2,0x73431F,1,true);
|
||||
_loc3_.graphics.beginFill(uint(parseInt(_loc2_,16)),1);
|
||||
_loc3_.graphics.drawRoundRect(0,0,31,21,7,7);
|
||||
_loc3_.graphics.endFill();
|
||||
_loc3_.addEventListener("mouseDown",onChatPopupMouse,false,0,true);
|
||||
_chatPalette.addChild(_loc3_);
|
||||
_loc1_++;
|
||||
}
|
||||
_chatPanel.addChild(_chatPalette);
|
||||
}
|
||||
|
||||
private static function drawChatPreview() : void
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
var _loc2_:uint = 0;
|
||||
var _loc3_:uint = 0;
|
||||
var _loc4_:Matrix = null;
|
||||
var _loc5_:String = null;
|
||||
var _loc7_:Number = 0;
|
||||
var _loc8_:Array = [];
|
||||
var _loc9_:Array = [];
|
||||
var _loc10_:Array = [];
|
||||
var _loc11_:int = 0;
|
||||
var _loc12_:uint = 0;
|
||||
if(_chatPreview == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc1_ = uint(parseInt(_chatStyle.background,16));
|
||||
_loc2_ = chatBlend(_loc1_,uint(parseInt(_chatStyle.accent,16)),Number(_chatStyle.strength) / 100);
|
||||
_loc3_ = uint(parseInt(_chatStyle.border,16));
|
||||
_loc7_ = (getTimer() * Number(_chatStyle.speed) / 100000) % 1;
|
||||
while(_loc11_ < _chatStops.length)
|
||||
{
|
||||
_loc12_ = uint(parseInt(_chatStops[_loc11_].color,16));
|
||||
if(_loc11_ > 0)
|
||||
{
|
||||
_loc12_ = chatBlend(_loc1_,_loc12_,Number(_chatStyle.strength) / 100);
|
||||
}
|
||||
if(_chatStyle.animation == "shimmer")
|
||||
{
|
||||
_loc12_ = chatBlend(_loc12_,_loc1,(Math.sin(_loc7_ * Math.PI * 2) + 1) * 0.5);
|
||||
}
|
||||
_loc8_.push(_loc12_);
|
||||
_loc9_.push(Number(_chatStyle.opacity) / 100);
|
||||
_loc10_.push(int(Number(_chatStops[_loc11_].position) * 2.55));
|
||||
_loc11_++;
|
||||
}
|
||||
_chatPreview.graphics.clear();
|
||||
_chatPreview.graphics.lineStyle(Math.max(0,Number(_chatStyle.outline)),_loc3_,1,true);
|
||||
if(_chatStyle.gradient == "solid")
|
||||
{
|
||||
_chatPreview.graphics.beginFill(_chatStyle.animation == "rainbow" ? chatRainbow(_loc7_) : _loc1_,Number(_chatStyle.opacity) / 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = new Matrix();
|
||||
_loc4_.createGradientBox(280,82,Number(_chatStyle.angle) * Math.PI / 180,0,0);
|
||||
_loc5_ = _chatStyle.gradient == "radial" ? GradientType.RADIAL : GradientType.LINEAR;
|
||||
if(_chatStyle.animation == "rainbow")
|
||||
{
|
||||
_chatPreview.graphics.beginGradientFill(_loc5_,[chatRainbow(_loc7_),chatRainbow((_loc7_ + 0.18) % 1),chatRainbow((_loc7_ + 0.36) % 1)],[Number(_chatStyle.opacity) / 100,Number(_chatStyle.opacity) / 100,Number(_chatStyle.opacity) / 100],[0,128,255],_loc4_);
|
||||
}
|
||||
else if(_chatStyle.animation == "flow")
|
||||
{
|
||||
_loc4_.createGradientBox(210,62,Number(_chatStyle.angle) * Math.PI / 180,(_loc7_ * 2 - 1) * 280,(_loc7_ * 2 - 1) * 82);
|
||||
_chatPreview.graphics.beginGradientFill(_loc5_,_loc8_,_loc9_,_loc10_,_loc4_,SpreadMethod.REFLECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
_chatPreview.graphics.beginGradientFill(_loc5_,_loc8_,_loc9_,_loc10_,_loc4_);
|
||||
}
|
||||
}
|
||||
_chatPreview.graphics.drawRoundRect(0,0,280,82,22,22);
|
||||
_chatPreview.graphics.endFill();
|
||||
_chatPreview.alpha = _chatStyle.animation == "pulse" ? 0.6 + 0.4 * (Math.sin(_loc7_ * Math.PI * 2) + 1) * 0.5 : 1;
|
||||
TextField(_chatPreview.getChildAt(0)).textColor = uint(parseInt(_chatStyle.text,16));
|
||||
}
|
||||
|
||||
private static function nextChatValue(param1:Array, param2:*) : *
|
||||
{
|
||||
var _loc3_:int = param1.indexOf(param2);
|
||||
return param1[(_loc3_ + 1 + param1.length) % param1.length];
|
||||
}
|
||||
|
||||
private static function findChatPreset() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
var _loc2_:String = null;
|
||||
var _loc3_:Boolean = false;
|
||||
while(_loc1_ < CHAT_PRESETS.length)
|
||||
{
|
||||
_loc3_ = true;
|
||||
for(_loc2_ in CHAT_PRESETS[_loc1_])
|
||||
{
|
||||
if(_loc2_ != "name" && String(CHAT_PRESETS[_loc1_][_loc2_]) != String(_chatStyle[_loc2_]))
|
||||
{
|
||||
_loc3_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(_loc3_ && String(_chatStyle.stops) != String(CHAT_PRESETS[_loc1_].background) + ":0;" + String(CHAT_PRESETS[_loc1_].accent) + ":100")
|
||||
{
|
||||
_loc3_ = false;
|
||||
}
|
||||
if(_loc3_)
|
||||
{
|
||||
return _loc1_;
|
||||
}
|
||||
_loc1_++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static function validChatHex(param1:String) : Boolean
|
||||
{
|
||||
return /^[0-9a-fA-F]{6}$/.test(param1);
|
||||
}
|
||||
|
||||
public static function closeChatBubbleEditor() : void
|
||||
{
|
||||
closeChatPalette();
|
||||
if(_chatPopup != null)
|
||||
{
|
||||
if(_chatPopup.parent != null)
|
||||
{
|
||||
_chatPopup.parent.removeChild(_chatPopup);
|
||||
}
|
||||
}
|
||||
_chatPopup = null;
|
||||
_chatFields = null;
|
||||
_chatButtons = null;
|
||||
_chatStatus = null;
|
||||
if(_chatPreview)
|
||||
{
|
||||
_chatPreview.removeEventListener(Event.ENTER_FRAME,onChatPreviewFrame);
|
||||
}
|
||||
_chatPreview = null;
|
||||
_chatSwatches = null;
|
||||
_chatPanel = null;
|
||||
_chatTrack = null;
|
||||
_chatStopSprites = null;
|
||||
}
|
||||
|
||||
private static function onChatPopupMouse(param1:MouseEvent) : void
|
||||
{
|
||||
var _loc2_:DisplayObject = param1.target as DisplayObject;
|
||||
var _loc3_:String = null;
|
||||
var _loc4_:int = 0;
|
||||
var _loc9_:int = 0;
|
||||
var _loc10_:String = null;
|
||||
var _loc11_:int = 0;
|
||||
var _loc12_:int = 0;
|
||||
var _loc13_:int = 0;
|
||||
var _loc14_:int = 0;
|
||||
var _loc15_:String = null;
|
||||
var _loc16_:int = 0;
|
||||
var _loc17_:int = 0;
|
||||
var _loc18_:int = 0;
|
||||
var _loc19_:Array = null;
|
||||
param1.stopPropagation();
|
||||
while(_loc2_ != null && _loc2_ != _chatPopup && _loc2_.name.indexOf("chat-") != 0)
|
||||
{
|
||||
_loc2_ = _loc2_.parent;
|
||||
}
|
||||
if(_loc2_ == null || _loc2_ == _chatPopup)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc3_ = _loc2_.name;
|
||||
if(_loc3_.indexOf("chat-stop-") == 0)
|
||||
{
|
||||
_chatSelectedStop = Math.max(0,Math.min(_chatStops.length - 1,int(_loc3_.substr(10))));
|
||||
refreshChatPopup(false);
|
||||
openChatPalette(CHAT_COLOUR_KEYS.length);
|
||||
}
|
||||
else if(_loc3_.indexOf("chat-colour-") == 0)
|
||||
{
|
||||
_loc9_ = int(_loc3_.substr(12));
|
||||
openChatPalette(_loc9_);
|
||||
}
|
||||
else if(_loc3_.indexOf("chat-pick-") == 0)
|
||||
{
|
||||
_loc10_ = _loc3_.substr(10).toLowerCase();
|
||||
if(_chatColourIndex >= 0 && _chatColourIndex <= CHAT_COLOUR_KEYS.length && validChatHex(_loc10_))
|
||||
{
|
||||
if(_chatColourIndex == CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
_chatStops[_chatSelectedStop].color = _loc10_;
|
||||
}
|
||||
else
|
||||
{
|
||||
_chatStyle[CHAT_COLOUR_KEYS[_chatColourIndex]] = _loc10_;
|
||||
TextField(_chatFields[_chatColourIndex]).text = _loc10_;
|
||||
if(_chatColourIndex == 0)
|
||||
{
|
||||
_chatStops[0].color = _loc10_;
|
||||
}
|
||||
else if(_chatColourIndex == 1)
|
||||
{
|
||||
_chatStops[_chatStops.length - 1].color = _loc10_;
|
||||
}
|
||||
}
|
||||
syncChatStops();
|
||||
TextField(_chatFields[0]).text = _chatStyle.background;
|
||||
TextField(_chatFields[1]).text = _chatStyle.accent;
|
||||
_chatPreset = -1;
|
||||
closeChatPalette();
|
||||
refreshChatPopup(false);
|
||||
setChatButton(_chatButtons.preset,"Preset: Custom");
|
||||
}
|
||||
}
|
||||
else if(_loc3_ == "chat-palette-close")
|
||||
{
|
||||
closeChatPalette();
|
||||
}
|
||||
else if(_loc3_ == "chat-close")
|
||||
{
|
||||
closeChatBubbleEditor();
|
||||
}
|
||||
else if(_loc3_ == "chat-reset")
|
||||
{
|
||||
_chatStyle = {"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"};
|
||||
_chatStops = parseChatStops(_chatStyle.stops);
|
||||
_chatSelectedStop = 0;
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup();
|
||||
}
|
||||
else if(_loc3_ == "chat-preset")
|
||||
{
|
||||
_chatPreset = (_chatPreset + 1) % CHAT_PRESETS.length;
|
||||
var _loc5_:Object = CHAT_PRESETS[_chatPreset];
|
||||
for(var _loc6_:String in _loc5_)
|
||||
{
|
||||
if(_loc6_ != "name")
|
||||
{
|
||||
_chatStyle[_loc6_] = _loc5_[_loc6_];
|
||||
}
|
||||
}
|
||||
_chatStyle.stops = String(_chatStyle.background) + ":0;" + String(_chatStyle.accent) + ":100";
|
||||
_chatStops = parseChatStops(_chatStyle.stops);
|
||||
_chatSelectedStop = 0;
|
||||
refreshChatPopup();
|
||||
}
|
||||
else if(_loc3_ == "chat-stop-add")
|
||||
{
|
||||
if(_chatStops.length >= 5)
|
||||
{
|
||||
_chatStatus.text = "A gradient can have up to five colours.";
|
||||
return;
|
||||
}
|
||||
_loc11_ = 0;
|
||||
_loc12_ = -1;
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _chatStops.length - 1)
|
||||
{
|
||||
_loc13_ = int(_chatStops[_loc4_ + 1].position) - int(_chatStops[_loc4_].position);
|
||||
if(_loc13_ > _loc12_)
|
||||
{
|
||||
_loc12_ = _loc13_;
|
||||
_loc11_ = _loc4_;
|
||||
}
|
||||
_loc4_++;
|
||||
}
|
||||
_loc14_ = int((int(_chatStops[_loc11_].position) + int(_chatStops[_loc11_ + 1].position)) * 0.5);
|
||||
_loc15_ = chatHex(chatBlend(uint(parseInt(_chatStops[_loc11_].color,16)),uint(parseInt(_chatStops[_loc11_ + 1].color,16)),0.5));
|
||||
_chatStops.splice(_loc11_ + 1,0,{"color":_loc15_,"position":_loc14_});
|
||||
_chatSelectedStop = _loc11_ + 1;
|
||||
syncChatStops();
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup();
|
||||
openChatPalette(CHAT_COLOUR_KEYS.length);
|
||||
}
|
||||
else if(_loc3_ == "chat-stop-remove")
|
||||
{
|
||||
if(_chatStops.length <= 2)
|
||||
{
|
||||
_chatStatus.text = "A gradient needs at least two colours.";
|
||||
return;
|
||||
}
|
||||
_chatStops.splice(_chatSelectedStop,1);
|
||||
_chatSelectedStop = Math.max(0,Math.min(_chatSelectedStop,_chatStops.length - 1));
|
||||
syncChatStops();
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup();
|
||||
}
|
||||
else if(_loc3_ == "chat-position")
|
||||
{
|
||||
if(_chatSelectedStop == 0 || _chatSelectedStop == _chatStops.length - 1)
|
||||
{
|
||||
_chatStatus.text = "The first and last colours stay at 0% and 100%.";
|
||||
return;
|
||||
}
|
||||
_loc16_ = int(_chatStops[_chatSelectedStop - 1].position) + 5;
|
||||
_loc17_ = int(_chatStops[_chatSelectedStop + 1].position) - 5;
|
||||
_loc18_ = int(_chatStops[_chatSelectedStop].position) + 5;
|
||||
_chatStops[_chatSelectedStop].position = _loc18_ > _loc17_ ? _loc16_ : _loc18_;
|
||||
syncChatStops();
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-swap")
|
||||
{
|
||||
_loc19_ = [];
|
||||
_loc4_ = _chatStops.length - 1;
|
||||
while(_loc4_ >= 0)
|
||||
{
|
||||
_loc19_.push({"color":String(_chatStops[_loc4_].color),"position":100 - int(_chatStops[_loc4_].position)});
|
||||
_loc4_--;
|
||||
}
|
||||
_chatStops = _loc19_;
|
||||
_chatSelectedStop = _chatStops.length - 1 - _chatSelectedStop;
|
||||
syncChatStops();
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup();
|
||||
}
|
||||
else if(_loc3_ == "chat-random")
|
||||
{
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _chatStops.length)
|
||||
{
|
||||
_chatStops[_loc4_].color = chatHex(uint(Math.random() * 0x1000000));
|
||||
_loc4_++;
|
||||
}
|
||||
syncChatStops();
|
||||
_chatStyle.border = chatHex(uint(Math.random() * 0x1000000));
|
||||
var _loc8_:uint = uint(parseInt(_chatStyle.background,16));
|
||||
_chatStyle.text = ((_loc8_ >> 16 & 255) * 299 + (_loc8_ >> 8 & 255) * 587 + (_loc8_ & 255) * 114) / 1000 > 145 ? "342018" : "ffffff";
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup();
|
||||
}
|
||||
else if(_loc3_ == "chat-gradient")
|
||||
{
|
||||
_chatStyle.gradient = nextChatValue(CHAT_GRADIENTS,_chatStyle.gradient);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-angle")
|
||||
{
|
||||
_chatStyle.angle = nextChatValue(CHAT_ANGLES,_chatStyle.angle);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-strength")
|
||||
{
|
||||
_chatStyle.strength = nextChatValue(CHAT_STRENGTHS,_chatStyle.strength);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-animation")
|
||||
{
|
||||
_chatStyle.animation = nextChatValue(CHAT_ANIMATIONS,_chatStyle.animation);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-opacity")
|
||||
{
|
||||
_chatStyle.opacity = nextChatValue(CHAT_OPACITIES,_chatStyle.opacity);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-speed")
|
||||
{
|
||||
_chatStyle.speed = nextChatValue(CHAT_SPEEDS,_chatStyle.speed);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-outline")
|
||||
{
|
||||
_chatStyle.outline = nextChatValue(CHAT_OUTLINES,_chatStyle.outline);
|
||||
_chatPreset = -1;
|
||||
refreshChatPopup(false);
|
||||
}
|
||||
else if(_loc3_ == "chat-enabled")
|
||||
{
|
||||
GuiManager.setCustomChatBubblesEnabled(!GuiManager.customChatBubblesEnabled());
|
||||
refreshChatPopup(false);
|
||||
_chatStatus.text = GuiManager.customChatBubblesEnabled() ? "Custom bubbles are visible on this client." : "Custom bubbles are hidden only on this client.";
|
||||
}
|
||||
else if(_loc3_ == "chat-save")
|
||||
{
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < CHAT_COLOUR_KEYS.length)
|
||||
{
|
||||
if(!validChatHex(TextField(_chatFields[_loc4_]).text))
|
||||
{
|
||||
_chatStatus.text = "Each colour must be exactly six hexadecimal characters.";
|
||||
return;
|
||||
}
|
||||
_chatStyle[CHAT_COLOUR_KEYS[_loc4_]] = TextField(_chatFields[_loc4_]).text.toLowerCase();
|
||||
_loc4_++;
|
||||
}
|
||||
_chatStatus.text = "Saving…";
|
||||
_chatStops[0].color = _chatStyle.background;
|
||||
_chatStops[_chatStops.length - 1].color = _chatStyle.accent;
|
||||
syncChatStops();
|
||||
gMainFrame.server.setXtObject_Str("xcs",[_chatStyle.background,_chatStyle.accent,_chatStyle.text,_chatStyle.border,_chatStyle.opacity,_chatStyle.animation,_chatStyle.speed,_chatStyle.gradient,_chatStyle.angle,_chatStyle.strength,_chatStyle.outline,_chatStyle.stops]);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleMouseDown(param1:MouseEvent) : void
|
||||
{
|
||||
@@ -693,6 +1622,9 @@ package gui.itemWindows
|
||||
}
|
||||
AJClient.openTool(1);
|
||||
break;
|
||||
case "chatBubble":
|
||||
showChatBubbleEditor();
|
||||
break;
|
||||
case "themeMenu":
|
||||
if(_mySettingsThemesFunction != null)
|
||||
{
|
||||
@@ -727,6 +1659,9 @@ package gui.itemWindows
|
||||
case "customArt":
|
||||
setCustomArt(!AJClient.customArtOn());
|
||||
break;
|
||||
case "expandedInventory":
|
||||
setExpandedInventory(!AJClient.expandedInventoryOn());
|
||||
break;
|
||||
case "wasd":
|
||||
setWasd(!AJClient.wasdOn());
|
||||
break;
|
||||
|
||||
+37
-14
@@ -171,8 +171,10 @@ package com.sbi.graphics
|
||||
|
||||
private var _receivedData:Array;
|
||||
|
||||
// each requested image's place in _layers: items worn in the same
|
||||
// slot are drawn in that order, the later over the earlier
|
||||
// each requested image's places in _layers: different items can use
|
||||
// the same art layer, so one image response can paint several pieces.
|
||||
// Items worn in the same slot are drawn in their original order, the
|
||||
// later over the earlier.
|
||||
private var _order:Object;
|
||||
|
||||
private var _requestedIds:Set;
|
||||
@@ -738,10 +740,16 @@ package com.sbi.graphics
|
||||
param2.push(_loc4_);
|
||||
if(param3)
|
||||
{
|
||||
param3[_loc4_] = _loc5_.c;
|
||||
if(_order)
|
||||
{
|
||||
_order[_loc4_] = _loc6_;
|
||||
if(!_order[_loc4_])
|
||||
{
|
||||
_order[_loc4_] = [];
|
||||
}
|
||||
_order[_loc4_].push({
|
||||
"p":_loc6_,
|
||||
"c":_loc5_.c
|
||||
});
|
||||
}
|
||||
}
|
||||
_loc6_++;
|
||||
@@ -761,6 +769,8 @@ package com.sbi.graphics
|
||||
{
|
||||
var _loc2_:* = 0;
|
||||
var _loc3_:int = 0;
|
||||
var _loc8_:Array = null;
|
||||
var _loc9_:Object = null;
|
||||
if(_preloadRequestedIds.remove(param1.id))
|
||||
{
|
||||
if(_preloadRequestedIds.isEmpty())
|
||||
@@ -778,18 +788,31 @@ package com.sbi.graphics
|
||||
if(_requestedIds.remove(param1.id))
|
||||
{
|
||||
_loc3_ = param1.layer;
|
||||
if(_loc3_ > 0)
|
||||
{
|
||||
_loc2_ = uint(_colors[param1.id]);
|
||||
}
|
||||
if(param1.success)
|
||||
{
|
||||
_receivedData.push({
|
||||
"l":_loc3_,
|
||||
"d":param1.imageData,
|
||||
"c":_loc2_,
|
||||
"p":(_order && _order.hasOwnProperty(param1.id) ? int(_order[param1.id]) : -1)
|
||||
});
|
||||
_loc8_ = _order && _order.hasOwnProperty(param1.id) ? _order[param1.id] as Array : null;
|
||||
if(_loc8_ && _loc8_.length > 0)
|
||||
{
|
||||
for each(_loc9_ in _loc8_)
|
||||
{
|
||||
_receivedData.push({
|
||||
"l":_loc3_,
|
||||
"d":param1.imageData,
|
||||
"c":uint(_loc9_.c),
|
||||
"p":int(_loc9_.p)
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the animal's base has no entry in _order
|
||||
_receivedData.push({
|
||||
"l":_loc3_,
|
||||
"d":param1.imageData,
|
||||
"c":_loc2_,
|
||||
"p":-1
|
||||
});
|
||||
}
|
||||
}
|
||||
if(_requestedIds.isEmpty())
|
||||
{
|
||||
|
||||
@@ -77,6 +77,9 @@ package gui
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
// Never leave the editor's full-screen layer behind to swallow
|
||||
// clicks after Settings is closed by another path.
|
||||
ItemWindowToggle.closeChatBubbleEditor();
|
||||
removeEventListeners();
|
||||
_popupLayer.removeChild(_mySettings);
|
||||
_closeCallback = null;
|
||||
@@ -174,6 +177,15 @@ package gui
|
||||
"iconFrame":"buddyRequest",
|
||||
"labelLabel":"Chat Filter",
|
||||
"btnLabel":"Open"
|
||||
},{
|
||||
// Chat appearance is account-wide; this opens the centered
|
||||
// in-game editor rather than burying it in the emoji picker.
|
||||
"type":TOGGLE_TYPE_JOIN,
|
||||
"frame":"chatBubble",
|
||||
// Reuse Predict Chat's ABC artwork and keep it in its on state.
|
||||
"iconFrame":"predictTxt",
|
||||
"labelLabel":"Chat Bubble",
|
||||
"btnLabel":"Customize"
|
||||
},{
|
||||
"type":TOGGLE_TYPE_JOIN,
|
||||
"frame":"themeMenu",
|
||||
@@ -229,6 +241,12 @@ package gui
|
||||
"type":TOGGLE_TYPE_JOIN,
|
||||
"frame":"customArt",
|
||||
"iconFrame":"redeemCode"
|
||||
},{
|
||||
// more, smaller items a row in the clothes and item pickers
|
||||
// (AJClient.expandedInventoryOn)
|
||||
"type":TOGGLE_TYPE_JOIN,
|
||||
"frame":"expandedInventory",
|
||||
"iconFrame":"redeemCode"
|
||||
},{
|
||||
"type":TOGGLE_TYPE_JOIN,
|
||||
"frame":"redeemCode",
|
||||
|
||||
@@ -221,7 +221,9 @@ package avatar
|
||||
{
|
||||
throw new Error("setAvatarAction: sent invalid action sprite?!");
|
||||
}
|
||||
addChatMessage(_actionMgr.getActionString(param1));
|
||||
// Actions animate the avatar, but are not chat messages. Keeping the
|
||||
// wire command out of the history prevents entries such as
|
||||
// ":sitS:" and ":sitSW:" from filling the player's chat log.
|
||||
var _loc2_:AvatarWorldView = AvatarManager.avatarViewList[AvatarManager.playerSfsUserId];
|
||||
if(_loc2_ && _actionMgr.mirrorActions)
|
||||
{
|
||||
@@ -760,6 +762,13 @@ package avatar
|
||||
{
|
||||
_loc2_ = reverseSpecialWords(_loc2_);
|
||||
}
|
||||
// Burrow appends a style after the normal extra field.
|
||||
// Message and type remain at their stock indexes, so
|
||||
// pending chat and every unpatched client still work.
|
||||
if(param1.length > 6 && AvatarManager.avatarViewList[_loc19_])
|
||||
{
|
||||
AvatarManager.avatarViewList[_loc19_].setChatStyle(String(param1[6]));
|
||||
}
|
||||
AvatarManager.addAvatarMessage(_loc2_,_loc19_,int(param1[5]));
|
||||
break;
|
||||
case 2:
|
||||
@@ -775,6 +784,20 @@ package avatar
|
||||
_loc2_ = EmoticonUtility.stringForId(int(_loc2_));
|
||||
break;
|
||||
case 3:
|
||||
// "sja:<anim>,<flip>": an animation that is not one of
|
||||
// the emote-bar actions (any id the client has, 1-255),
|
||||
// sent as an action message by modded clients. The
|
||||
// normal client finds no action for it and drops it.
|
||||
if(_loc2_.indexOf("sja:") == 0)
|
||||
{
|
||||
_loc10_ = _loc2_.substr(4).split(",");
|
||||
_loc12_ = int(_loc10_[0]);
|
||||
if(_loc19_ != gMainFrame.server.userId && _loc12_ > 0 && _loc12_ <= 255 && !MinigameManager.inMinigame() && AvatarManager.avatarViewList[_loc19_])
|
||||
{
|
||||
AvatarManager.avatarViewList[_loc19_].holdIdleAnim(_loc12_,_loc10_[1] == "1");
|
||||
}
|
||||
return;
|
||||
}
|
||||
_loc5_ = _actionMgr.matchActionString(_loc2_);
|
||||
if(_loc5_)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ package
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.getTimer;
|
||||
import gui.itemWindows.ItemWindowToggle;
|
||||
|
||||
public class XtReplyDemuxer
|
||||
{
|
||||
@@ -159,6 +160,11 @@ package
|
||||
AJClient.onFilterState(param1.obj);
|
||||
return;
|
||||
}
|
||||
if(param1.obj[0] == "xcs")
|
||||
{
|
||||
ItemWindowToggle.chatStyleState(param1.obj);
|
||||
return;
|
||||
}
|
||||
if(param1.obj[0] == "xfa")
|
||||
{
|
||||
AJClient.onFilterAsk(param1.obj);
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
// loaded into the test server (NODE_OPTIONS --require, by test/signin.js):
|
||||
// Discord's OAuth2 API answered here, so a sign-in with Discord can be gone
|
||||
// through without Discord. the code Discord would send back names who signs
|
||||
// in ("mira" -> Mira's Discord account); anything else goes out as usual.
|
||||
|
||||
const USERS = {
|
||||
mira: {id: "100000000000000001", username: "mira_discord"},
|
||||
hal: {id: "100000000000000002", username: "hal_discord"},
|
||||
};
|
||||
|
||||
const realFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options = {}) => {
|
||||
const href = String(url);
|
||||
if (!href.startsWith("https://discord.com/api/")) {
|
||||
return realFetch(url, options);
|
||||
}
|
||||
const json = (status, body) => new Response(JSON.stringify(body), {status, headers: {"Content-Type": "application/json"}});
|
||||
if (href.endsWith("/oauth2/token")) {
|
||||
const code = new URLSearchParams(String(options.body || "")).get("code");
|
||||
return USERS[code] ? json(200, {access_token: `token-${code}`, token_type: "Bearer"}) : json(400, {error: "invalid_grant"});
|
||||
}
|
||||
if (href.endsWith("/users/@me")) {
|
||||
const user = USERS[String((options.headers || {}).Authorization || "").replace(/^Bearer token-/, "")];
|
||||
return user ? json(200, {...user, discriminator: "0"}) : json(401, {});
|
||||
}
|
||||
return json(404, {});
|
||||
};
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
"use strict";
|
||||
|
||||
// end to end: what a sign-in takes besides a password. Discord says who
|
||||
// someone is, but the moderator and admin panels open only with their 2FA
|
||||
// code as well (lib/modpanel.js, lib/panel.js); and a recovery email resets
|
||||
// a password, but removes 2FA only with the password too, never right after
|
||||
// a password reset by email, and never for staff (lib/manage.js). Discord's
|
||||
// API is test/fake-discord.js, and recovery mail goes to a server of ours.
|
||||
|
||||
const assert = require("assert");
|
||||
const crypto = require("crypto");
|
||||
const http = require("http");
|
||||
const path = require("path");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18096;
|
||||
const GAME_PORT = 19356;
|
||||
const MAIL_PORT = 18097;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
|
||||
// the authenticator app's side of 2FA (as in test/staff.js)
|
||||
const STEP = 30;
|
||||
const base32Decode = text => {
|
||||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
const bits = text.replace(/=+$/, "").toUpperCase().split("").map(c => alphabet.indexOf(c).toString(2).padStart(5, "0")).join("");
|
||||
const bytes = [];
|
||||
for (let i = 0; i + 8 <= bits.length; i += 8) {
|
||||
bytes.push(parseInt(bits.slice(i, i + 8), 2));
|
||||
}
|
||||
return Buffer.from(bytes);
|
||||
};
|
||||
const codeAt = (secret, step) => {
|
||||
const counter = Buffer.alloc(8);
|
||||
counter.writeBigUInt64BE(BigInt(step));
|
||||
const mac = crypto.createHmac("sha1", base32Decode(secret)).update(counter).digest();
|
||||
const offset = mac[mac.length - 1] & 0x0F;
|
||||
return String((mac.readUInt32BE(offset) & 0x7FFFFFFF) % 1000000).padStart(6, "0");
|
||||
};
|
||||
const stepNow = () => Math.floor(Date.now() / 1000 / STEP);
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
// a code is taken once: each use needs a later step than the last.
|
||||
const used = {};
|
||||
const freshCode = async (who, secret) => {
|
||||
while (used[who] !== undefined && stepNow() <= used[who]) {
|
||||
await sleep(250);
|
||||
}
|
||||
used[who] = stepNow();
|
||||
return codeAt(secret, used[who]);
|
||||
};
|
||||
|
||||
// a browser: keeps every cookie it is given, follows no redirects.
|
||||
const browser = () => {
|
||||
const jar = new Map();
|
||||
const request = async (where, {body, method} = {}) => {
|
||||
const headers = {cookie: [...jar].map(([name, value]) => `${name}=${value}`).join("; ")};
|
||||
const options = {method: method || (body === undefined ? "GET" : "POST"), headers, redirect: "manual"};
|
||||
if (body !== undefined) {
|
||||
options.headers["Content-Type"] = "application/json";
|
||||
options.body = JSON.stringify(body);
|
||||
}
|
||||
const res = await fetch(where.startsWith("http") ? where : `${BASE}${where}`, options);
|
||||
for (const line of res.headers.getSetCookie()) {
|
||||
const [pair, ...attributes] = line.split(";");
|
||||
const [name, value] = pair.split("=");
|
||||
if (attributes.some(attribute => /^\s*max-age=0$/i.test(attribute)) || value === "") {
|
||||
jar.delete(name.trim());
|
||||
}
|
||||
else {
|
||||
jar.set(name.trim(), value);
|
||||
}
|
||||
}
|
||||
return {status: res.status, location: res.headers.get("location") || "", data: await res.json().catch(() => ({})), cookies: res.headers.getSetCookie()};
|
||||
};
|
||||
request.has = name => jar.has(name);
|
||||
return request;
|
||||
};
|
||||
|
||||
// a Discord sign-in through the fake Discord: start at `start`, come back
|
||||
// to `callback` as `who`. the redirect's address.
|
||||
const throughDiscord = async (page, start, callback, who) => {
|
||||
const begun = await page(start);
|
||||
assert.strictEqual(begun.status, 302, JSON.stringify(begun));
|
||||
const state = new URL(begun.location).searchParams.get("state");
|
||||
assert.ok(state, begun.location);
|
||||
const back = await page(`${callback}?state=${state}&code=${who}`);
|
||||
assert.strictEqual(back.status, 302);
|
||||
return back;
|
||||
};
|
||||
|
||||
const run = async mail => {
|
||||
const people = {Mira: "KettlePass21", Hal: "KettlePass22", Pip: "KettlePass23"};
|
||||
for (const [username, password] of Object.entries(people)) {
|
||||
const res = await fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username, password, email: `${username.toLowerCase()}@example.com`, avatarType: 1, agreed: true})});
|
||||
assert.strictEqual(res.status, 200, await res.text());
|
||||
}
|
||||
|
||||
// Mira and Hal turn on 2FA and link their Discord accounts.
|
||||
const secrets = {};
|
||||
for (const username of ["Mira", "Hal"]) {
|
||||
const page = browser();
|
||||
assert.strictEqual((await page("/account/api/login", {body: {username, password: people[username]}})).status, 200);
|
||||
const begun = await page("/account/api/act", {body: {action: "twoStepStart", current: people[username]}});
|
||||
secrets[username] = begun.data.setup.secret;
|
||||
const confirmed = await page("/account/api/act", {body: {action: "twoStepConfirm", code: await freshCode(username, secrets[username])}});
|
||||
assert.ok(confirmed.data.ok, JSON.stringify(confirmed.data));
|
||||
const linked = await throughDiscord(page, "/account/discord/link", "/account/discord/callback", username.toLowerCase());
|
||||
assert.match(linked.location, /discord=linked/);
|
||||
}
|
||||
|
||||
// the admin makes Mira a moderator, and lets Hal into this dashboard with Discord.
|
||||
const admin = browser();
|
||||
assert.strictEqual((await admin("/admin/api/setup", {body: {password: "AdminPass99!"}})).status, 200);
|
||||
assert.strictEqual((await admin("/admin/api/login", {body: {password: "AdminPass99!"}})).status, 200);
|
||||
assert.match((await admin("/admin/api/account", {body: {username: "Mira", action: "role", role: "moderator"}})).data.ok, /moderator/);
|
||||
assert.ok((await admin("/admin/api/account", {body: {username: "Hal", action: "adminDashboardAccess", on: true}})).data.ok);
|
||||
|
||||
// --- the moderator panel: Discord, then the code
|
||||
const mod = browser();
|
||||
const back = await throughDiscord(mod, "/dashboard/staff/discord/login", "/dashboard/staff/discord/callback", "mira");
|
||||
assert.match(back.location, /discord=code$/);
|
||||
assert.ok(!mod.has("ajc_mod"), "Discord alone opened the moderator panel");
|
||||
assert.ok(mod.has("ajc_mod_pending"));
|
||||
assert.strictEqual((await mod("/dashboard/api/staff/state")).data.signedIn, false);
|
||||
assert.strictEqual((await mod("/dashboard/api/staff/players")).status, 401);
|
||||
const wrong = await mod("/dashboard/api/staff/discord/code", {body: {code: "000000"}});
|
||||
assert.strictEqual(wrong.status, 401);
|
||||
assert.strictEqual(wrong.data.expired, undefined);
|
||||
const right = await mod("/dashboard/api/staff/discord/code", {body: {code: await freshCode("Mira", secrets.Mira)}});
|
||||
assert.strictEqual(right.status, 200, JSON.stringify(right.data));
|
||||
assert.strictEqual(right.data.username, "Mira");
|
||||
assert.ok(mod.has("ajc_mod") && !mod.has("ajc_mod_pending"));
|
||||
assert.strictEqual((await mod("/dashboard/api/staff/state")).data.signedIn, true);
|
||||
// a waiting sign-in is used once
|
||||
const again = await mod("/dashboard/api/staff/discord/code", {body: {code: await freshCode("Mira", secrets.Mira)}});
|
||||
assert.strictEqual(again.data.expired, true);
|
||||
|
||||
// a few wrong codes, and it must start again at Discord
|
||||
const guesser = browser();
|
||||
await throughDiscord(guesser, "/dashboard/staff/discord/login", "/dashboard/staff/discord/callback", "mira");
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
const guess = await guesser("/dashboard/api/staff/discord/code", {body: {code: String(100000 + i)}});
|
||||
assert.strictEqual(guess.status, 401);
|
||||
assert.strictEqual(Boolean(guess.data.expired), i === 5);
|
||||
}
|
||||
assert.strictEqual((await guesser("/dashboard/api/staff/discord/code", {body: {code: await freshCode("Mira", secrets.Mira)}})).data.expired, true);
|
||||
assert.ok(!guesser.has("ajc_mod"));
|
||||
|
||||
// a Discord account linked to no staff gets nowhere
|
||||
const player = browser();
|
||||
const denied = await throughDiscord(player, "/dashboard/staff/discord/login", "/dashboard/staff/discord/callback", "hal");
|
||||
assert.match(denied.location, /discord=denied$/);
|
||||
assert.ok(!player.has("ajc_mod_pending"));
|
||||
|
||||
// --- the admin dashboard: the same
|
||||
const owner = browser();
|
||||
const adminBack = await throughDiscord(owner, "/dashboard/admin/discord/login", "/dashboard/admin/discord/callback", "hal");
|
||||
assert.match(adminBack.location, /discord=code$/);
|
||||
assert.ok(!owner.has("ajc_admin"), "Discord alone opened the admin dashboard");
|
||||
assert.strictEqual((await owner("/dashboard/api/admin/state")).data.signedIn, false);
|
||||
assert.strictEqual((await owner("/dashboard/api/admin/discord/code", {body: {code: "000000"}})).status, 401);
|
||||
const adminRight = await owner("/dashboard/api/admin/discord/code", {body: {code: await freshCode("Hal", secrets.Hal)}});
|
||||
assert.strictEqual(adminRight.status, 200, JSON.stringify(adminRight.data));
|
||||
assert.strictEqual((await owner("/dashboard/api/admin/state")).data.signedIn, true);
|
||||
|
||||
// --- recovery by email
|
||||
const recover = async (username, kind) => {
|
||||
const before = mail.length;
|
||||
const sent = await (browser())("/account/api/recover/request", {body: {username, email: `${username.toLowerCase()}@example.com`, kind}});
|
||||
assert.strictEqual(sent.status, 200);
|
||||
if (mail.length === before) {
|
||||
return null;
|
||||
}
|
||||
const message = mail.at(-1);
|
||||
assert.strictEqual(message.to, `${username.toLowerCase()}@example.com`);
|
||||
return new URL(/https?:\/\/\S+/.exec(message.text)[0]).searchParams.get("token");
|
||||
};
|
||||
const page = browser();
|
||||
|
||||
// a password, by the email alone
|
||||
const pipToken = await recover("Pip", "password");
|
||||
assert.strictEqual((await page("/account/api/recover/check", {body: {token: pipToken}})).data.kind, "password");
|
||||
assert.strictEqual((await page("/account/api/recover/complete", {body: {token: pipToken, password: "KettlePass33"}})).status, 200);
|
||||
// and then not 2FA as well, by the email, for a week
|
||||
const pipTwoStep = await recover("Pip", "twoStep");
|
||||
assert.match((await page("/account/api/recover/check", {body: {token: pipTwoStep}})).data.error, /within 7 days/);
|
||||
assert.match((await page("/account/api/recover/complete", {body: {token: pipTwoStep, password: "KettlePass33"}})).data.error, /within 7 days/);
|
||||
|
||||
// 2FA, by the email and the password
|
||||
const halToken = await recover("Hal", "twoStep");
|
||||
assert.strictEqual((await page("/account/api/recover/check", {body: {token: halToken}})).data.kind, "twoStep");
|
||||
const noPassword = await page("/account/api/recover/complete", {body: {token: halToken, password: "not it"}});
|
||||
assert.strictEqual(noPassword.status, 401);
|
||||
assert.strictEqual((await page("/account/api/recover/complete", {body: {token: halToken, password: people.Hal}})).status, 200);
|
||||
const halNow = browser();
|
||||
assert.strictEqual((await halNow("/account/api/login", {body: {username: "Hal", password: people.Hal}})).status, 200, "2FA was not removed");
|
||||
|
||||
// never for staff: a mailbox does not make anyone a moderator
|
||||
const miraToken = await recover("Mira", "twoStep");
|
||||
assert.match((await page("/account/api/recover/check", {body: {token: miraToken}})).data.error, /Staff accounts/);
|
||||
assert.match((await page("/account/api/recover/complete", {body: {token: miraToken, password: people.Mira}})).data.error, /Staff accounts/);
|
||||
assert.strictEqual((await mod("/dashboard/api/staff/state")).data.signedIn, true, "Mira's 2FA went");
|
||||
|
||||
// a few recovery emails an hour for one account, from anywhere
|
||||
assert.ok(await recover("Mira", "password"));
|
||||
assert.ok(await recover("Mira", "password"));
|
||||
assert.strictEqual(await recover("Mira", "password"), null);
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
const mail = [];
|
||||
const mailServer = http.createServer((req, res) => {
|
||||
let body = "";
|
||||
req.on("data", chunk => {
|
||||
body += chunk;
|
||||
});
|
||||
req.on("end", () => {
|
||||
assert.strictEqual(req.headers.authorization, "Bearer test-mail-token");
|
||||
mail.push(JSON.parse(body));
|
||||
res.writeHead(200);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
await new Promise(resolve => mailServer.listen(MAIL_PORT, "127.0.0.1", resolve));
|
||||
Object.assign(process.env, {
|
||||
// forward slashes: NODE_OPTIONS reads a backslash as an escape (Windows)
|
||||
NODE_OPTIONS: `${process.env.NODE_OPTIONS || ""} --require "${path.join(__dirname, "fake-discord.js").replace(/\\/g, "/")}"`.trim(),
|
||||
AJ_DISCORD_CLIENT_ID: "123456789012345678",
|
||||
AJ_DISCORD_CLIENT_SECRET: "test-secret",
|
||||
AJ_RECOVERY_MAIL_URL: `http://127.0.0.1:${MAIL_PORT}/mail`,
|
||||
AJ_RECOVERY_MAIL_TOKEN: "test-mail-token",
|
||||
});
|
||||
try {
|
||||
await harness.withServer("sign-in test", HTTP_PORT, GAME_PORT, () => run(mail));
|
||||
}
|
||||
finally {
|
||||
mailServer.close();
|
||||
}
|
||||
};
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
+13
-1
@@ -158,6 +158,17 @@ const run = async () => {
|
||||
assert.deepStrictEqual((await b.nextXt("uc")).slice(1), [roomId, String(bobId), "hi & bye", "0"]);
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[7%2]]></txt></body></msg>`); // emote: not echoed
|
||||
assert.deepStrictEqual((await a.nextXt("uc")).slice(3), ["7", "2"]);
|
||||
|
||||
// A saved bubble style is acknowledged with every customization field and
|
||||
// travels with the next public line so every patched client renders it.
|
||||
const chatStyle = ["112233", "445566", "ffffff", "abcdef", "85", "flow", "150", "radial", "225", "75", "2", "112233:0;ff0069:45;445566:100"];
|
||||
b.xt("xcs", roomId, ...chatStyle);
|
||||
assert.deepStrictEqual((await b.nextXt("xcs")).slice(2), chatStyle);
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[styled%0]]></txt></body></msg>`);
|
||||
const styledPacket = [roomId, String(bobId), "styled", "0", "", chatStyle.join(",")];
|
||||
assert.deepStrictEqual((await a.nextXt("uc")).slice(1), styledPacket);
|
||||
assert.deepStrictEqual((await b.nextXt("uc")).slice(1), styledPacket);
|
||||
|
||||
// Actions are sent to every other player in the room. The sender has
|
||||
// already applied the action locally, so it is not echoed back to them.
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[:sitS:%3%m1]]></txt></body></msg>`);
|
||||
@@ -654,7 +665,8 @@ const run = async () => {
|
||||
login_choices: {accountType: 0, isGuide: true, membershipDays: 12, isModerator: "yes"}})).json();
|
||||
assert.strictEqual((await (await fetch(`${BASE}/player`, {headers: {Authorization: `Bearer ${chosen.auth_token}`}})).json()).game_account_type, 0);
|
||||
a.xt("ag", denId, "Erin", 0);
|
||||
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["0", "1"]); // account type, guide
|
||||
// account type, guide: asking to be a guide is refused unless the admin made them one
|
||||
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["0", "0"]);
|
||||
await postJson(`${BASE}/authenticate`, {username: "Erin", password: "KettlePass05"}); // and back to normal
|
||||
a.xt("ag", denId, "Erin", 0);
|
||||
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["2", "0"]);
|
||||
|
||||
@@ -85,6 +85,7 @@ set -- \
|
||||
com.sbi.graphics.LayerAnim LayerAnim.as \
|
||||
com.sbi.graphics.LayerBitmap LayerBitmap.as \
|
||||
ecard.ECard ECard.as \
|
||||
ecard.ECardXtCommManager ECardXtCommManager.as \
|
||||
game.ArtStudioKit ArtStudioKit.as \
|
||||
game.artStudioPainting.ArtStudioPainting ArtStudioPainting.as \
|
||||
game.artStudioGridDrawing.ArtStudioGridDrawing ArtStudioGridDrawing.as \
|
||||
|
||||
@@ -22,6 +22,8 @@ package room
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
import flash.utils.Dictionary;
|
||||
import game.MinigameManager;
|
||||
import gui.AvatarEditor;
|
||||
@@ -64,6 +66,15 @@ package room
|
||||
private var _flipBtnVer:MovieClip;
|
||||
|
||||
private var _linkBtn:MovieClip;
|
||||
|
||||
// These are deliberately part of the selected item's action cluster,
|
||||
// not the den editor chrome. That keeps them out of the way of the
|
||||
// inventory and makes their scope obvious, as in the original editor.
|
||||
private var _sendBehindBtn:Sprite;
|
||||
|
||||
private var _bringToFrontBtn:Sprite;
|
||||
|
||||
private var _naturalDepthBtn:Sprite;
|
||||
|
||||
private var _themePos:Point;
|
||||
|
||||
@@ -102,6 +113,9 @@ package room
|
||||
_flipBtnVer.addEventListener("mouseDown",onFlipBtn,false,0,true);
|
||||
_linkBtn = GETDEFINITIONBYNAME("portalLinkBtnCont");
|
||||
_linkBtn.addEventListener("mouseDown",onLinkBtn,false,0,true);
|
||||
_sendBehindBtn = makeLayerButton("Back",onSendBehindBtn);
|
||||
_bringToFrontBtn = makeLayerButton("Front",onBringToFrontBtn);
|
||||
_naturalDepthBtn = makeLayerButton("Auto",onNaturalDepthBtn);
|
||||
release();
|
||||
_lastItemInvId = -1;
|
||||
}
|
||||
@@ -149,10 +163,9 @@ package room
|
||||
return _dragItem != null;
|
||||
}
|
||||
|
||||
// The original editor only sorted furniture from its y position. These
|
||||
// helpers give the replacement editor an explicit, persisted choice.
|
||||
// Bits 2-3 of `flipped` are unused by the game's flip code, so the
|
||||
// normal horizontal/vertical flip bits remain intact in bits 0-1.
|
||||
// The original editor only sorted furniture from its y position. Bits
|
||||
// 2-3 of `flipped` are unused by the game's flip code, so they safely
|
||||
// persist a selected item's deliberate stacking choice.
|
||||
public function sendSelectedBehind() : Boolean
|
||||
{
|
||||
return setSelectedStacking(1);
|
||||
@@ -170,7 +183,7 @@ package room
|
||||
|
||||
private function setSelectedStacking(param1:int) : Boolean
|
||||
{
|
||||
if(_dragItem == null || _dragItem.layerId == 1 || isTheme(_dragItem.sortCatId) || _dragItem.sortCatId == 4)
|
||||
if(!canSetSelectedStacking())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -178,10 +191,66 @@ package room
|
||||
if(_dragItem.denItemHelper && _dragItem.denItemHelper.displayObject)
|
||||
{
|
||||
_dragItem.denItemHelper.displayObject.name = String(_dragItem.denItemHelper.sortOffset);
|
||||
// SortLayer will settle on the saved offset at its next heartbeat;
|
||||
// set the visible order now so the control feels immediate.
|
||||
if(param1 == 1)
|
||||
{
|
||||
_dragItem.denItemHelper.displayObject.parent.setChildIndex(_dragItem.denItemHelper.displayObject,0);
|
||||
}
|
||||
else if(param1 == 2)
|
||||
{
|
||||
_dragItem.denItemHelper.displayObject.parent.setChildIndex(_dragItem.denItemHelper.displayObject,_dragItem.denItemHelper.displayObject.parent.numChildren - 1);
|
||||
}
|
||||
}
|
||||
saveState(_dragItem.invIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function canSetSelectedStacking() : Boolean
|
||||
{
|
||||
return _roomMode == 1 && _dragItem != null && _dragItem.layerId != 1 && !isTheme(_dragItem.sortCatId) && _dragItem.sortCatId != 4;
|
||||
}
|
||||
|
||||
private function makeLayerButton(param1:String, param2:Function) : Sprite
|
||||
{
|
||||
var _loc3_:Sprite = new Sprite();
|
||||
var _loc4_:TextField = new TextField();
|
||||
_loc3_.buttonMode = true;
|
||||
_loc3_.mouseChildren = false;
|
||||
_loc3_.graphics.beginFill(2398294,0.96);
|
||||
_loc3_.graphics.drawRoundRect(0,0,42,24,8,8);
|
||||
_loc3_.graphics.endFill();
|
||||
_loc3_.graphics.lineStyle(1,16774041,0.9);
|
||||
_loc3_.graphics.drawRoundRect(0,0,42,24,8,8);
|
||||
_loc4_.width = 42;
|
||||
_loc4_.height = 20;
|
||||
_loc4_.y = 3;
|
||||
_loc4_.selectable = false;
|
||||
_loc4_.mouseEnabled = false;
|
||||
_loc4_.defaultTextFormat = new TextFormat("Arial",9,16777215,true,null,null,null,null,"center");
|
||||
_loc4_.text = param1;
|
||||
_loc3_.addChild(_loc4_);
|
||||
_loc3_.addEventListener("mouseDown",param2,false,0,true);
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function onSendBehindBtn(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
sendSelectedBehind();
|
||||
}
|
||||
|
||||
private function onBringToFrontBtn(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
bringSelectedToFront();
|
||||
}
|
||||
|
||||
private function onNaturalDepthBtn(param1:MouseEvent) : void
|
||||
{
|
||||
param1.stopImmediatePropagation();
|
||||
resetSelectedStacking();
|
||||
}
|
||||
|
||||
public function get lastSelectedItem() : DenStateItem
|
||||
{
|
||||
@@ -618,6 +687,7 @@ package room
|
||||
{
|
||||
_linkBtn.parent.removeChild(_linkBtn);
|
||||
}
|
||||
removeLayerButtons();
|
||||
if(_itemFilter)
|
||||
{
|
||||
if(_itemFilter.denItemHelper.displayObject)
|
||||
@@ -664,6 +734,13 @@ package room
|
||||
}
|
||||
else
|
||||
{
|
||||
// The room treats a mouse-up over empty space as a deselect. The
|
||||
// selected item's action cluster lives in that empty space, so
|
||||
// keep the selection while the pointer crosses into its buttons.
|
||||
if(_dragItem && isOverLayerActionArea(param1,param2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_dragItem && _dragItem.specialType == 1)
|
||||
{
|
||||
_loc6_ = hitTest(param1,param2);
|
||||
@@ -976,6 +1053,7 @@ package room
|
||||
BuddyList.closeWorldBuddyList();
|
||||
}
|
||||
}
|
||||
updateLayerButtons();
|
||||
if(_itemFilter != _dragItem)
|
||||
{
|
||||
if(_itemFilter)
|
||||
@@ -1005,6 +1083,7 @@ package room
|
||||
_linkBtn.parent.removeChild(_linkBtn);
|
||||
BuddyList.closeWorldBuddyList();
|
||||
}
|
||||
removeLayerButtons();
|
||||
if(_itemFilter)
|
||||
{
|
||||
if(_itemFilter.denItemHelper.displayObject)
|
||||
@@ -1026,8 +1105,58 @@ package room
|
||||
_flipBtnVer.y = param2 + 90;
|
||||
_linkBtn.x = param1 + 15;
|
||||
_linkBtn.y = param2 + 125;
|
||||
_sendBehindBtn.x = param1 + 42;
|
||||
_sendBehindBtn.y = param2;
|
||||
_bringToFrontBtn.x = param1 + 42;
|
||||
_bringToFrontBtn.y = param2 + 27;
|
||||
_naturalDepthBtn.x = param1 + 42;
|
||||
_naturalDepthBtn.y = param2 + 54;
|
||||
BuddyList.updateWorldBuddyListPosition(_linkBtn);
|
||||
}
|
||||
|
||||
private function updateLayerButtons() : void
|
||||
{
|
||||
if(!canSetSelectedStacking())
|
||||
{
|
||||
removeLayerButtons();
|
||||
return;
|
||||
}
|
||||
if(_sendBehindBtn.parent != _layerManager.room_chat)
|
||||
{
|
||||
_layerManager.room_chat.addChild(_sendBehindBtn);
|
||||
_layerManager.room_chat.addChild(_bringToFrontBtn);
|
||||
_layerManager.room_chat.addChild(_naturalDepthBtn);
|
||||
}
|
||||
}
|
||||
|
||||
private function removeLayerButtons() : void
|
||||
{
|
||||
if(_sendBehindBtn.parent)
|
||||
{
|
||||
_sendBehindBtn.parent.removeChild(_sendBehindBtn);
|
||||
}
|
||||
if(_bringToFrontBtn.parent)
|
||||
{
|
||||
_bringToFrontBtn.parent.removeChild(_bringToFrontBtn);
|
||||
}
|
||||
if(_naturalDepthBtn.parent)
|
||||
{
|
||||
_naturalDepthBtn.parent.removeChild(_naturalDepthBtn);
|
||||
}
|
||||
}
|
||||
|
||||
private function isOverLayerActionArea(param1:Number, param2:Number) : Boolean
|
||||
{
|
||||
var _loc3_:Rectangle = null;
|
||||
if(_sendBehindBtn.parent == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Treat the item and its controls as one continuous selection area.
|
||||
// This bridges any empty pixels between a large item and its buttons.
|
||||
_loc3_ = _dragItem.denItemHelper.displayObject.getBounds(_layerManager.room_avatars);
|
||||
return param1 >= Math.min(_loc3_.left,_sendBehindBtn.x) - 12 && param1 <= Math.max(_loc3_.right,_sendBehindBtn.x + _sendBehindBtn.width) + 12 && param2 >= Math.min(_loc3_.top,_sendBehindBtn.y) - 12 && param2 <= Math.max(_loc3_.bottom,_naturalDepthBtn.y + _naturalDepthBtn.height) + 12;
|
||||
}
|
||||
|
||||
private function onCloseBtn(param1:Event) : void
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user