Snapshot: full project state
This commit is contained in:
32
honest_online.py
Normal file
32
honest_online.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Honest online counter for SatsSpin chat: real presence tracking + zero default."""
|
||||
import io
|
||||
|
||||
# 1. Server: track chat pollers, return honest onlineUsersCount
|
||||
P = "/opt/casino/server-prod-new.cjs"
|
||||
src = io.open(P, encoding="utf-8").read()
|
||||
old = 'app.get("/api/chat/messages", (req, res) => res.json({ messages: state.chat.slice(-50) }));'
|
||||
new = '''const chatPresence = {};
|
||||
app.get("/api/chat/messages", (req, res) => {
|
||||
const now = Date.now();
|
||||
const auth = req.headers.authorization || "";
|
||||
const tok = auth.startsWith("Bearer ") ? auth.slice(7) : "";
|
||||
const uid = tok && state.sessions && state.sessions[tok];
|
||||
const who = uid ? "u:" + uid : "ip:" + (req.ip || "?");
|
||||
chatPresence[who] = now;
|
||||
for (const k in chatPresence) if (now - chatPresence[k] > 60000) delete chatPresence[k];
|
||||
res.json({ messages: state.chat.slice(-50), onlineUsersCount: Object.keys(chatPresence).length });
|
||||
});'''
|
||||
assert old in src, "chat/messages handler not found"
|
||||
src = src.replace(old, new, 1)
|
||||
io.open(P, "w", encoding="utf-8").write(src)
|
||||
print("SERVER PRESENCE ADDED")
|
||||
|
||||
# 2. Frontend: no fake 432 default — start at 0 until the first real poll
|
||||
B = "/opt/casino/dist/assets/index-CzzrlZy-.js"
|
||||
bundle = io.open(B, encoding="utf-8").read()
|
||||
old2 = "[A,v]=C.useState(432)"
|
||||
assert old2 in bundle, "useState(432) not found"
|
||||
bundle = bundle.replace(old2, "[A,v]=C.useState(0)", 1)
|
||||
io.open(B, "w", encoding="utf-8").write(bundle)
|
||||
print("BUNDLE DEFAULT ZEROED")
|
||||
Reference in New Issue
Block a user