Compare commits

...

2 Commits

Author SHA1 Message Date
sky
55e3f5a3c4 fix websocket server 2025-10-26 15:21:43 -04:00
sky
496bc61c7d remove ads from some places 2025-10-26 14:47:13 -04:00
6 changed files with 53 additions and 10 deletions

View File

@ -44,7 +44,6 @@
<!-- seo + other things --> <!-- seo + other things -->
<title>{{ name }}'s Profile | Selenite</title> <title>{{ name }}'s Profile | Selenite</title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
<script> <script>
document.addEventListener("DOMContentLoaded", ()=>{ document.addEventListener("DOMContentLoaded", ()=>{
let music = {{ is_music }}; let music = {{ is_music }};

View File

@ -44,7 +44,6 @@
<!-- seo + other things --> <!-- seo + other things -->
<title>{{ name }}'s Profile | Selenite</title> <title>{{ name }}'s Profile | Selenite</title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
<!-- <script> <!-- <script>
let audioObject; let audioObject;
document.addEventListener("DOMContentLoaded", ()=>{ document.addEventListener("DOMContentLoaded", ()=>{

View File

@ -123,7 +123,7 @@
}); });
</script> </script>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
</head> </head>
<alerts> </alerts> <alerts> </alerts>
<body> <body>

View File

@ -45,10 +45,20 @@ import WebSocket, { WebSocketServer } from "ws";
const wss = new WebSocketServer({ noServer: true }); const wss = new WebSocketServer({ noServer: true });
// let openSockets = 0; // let openSockets = 0;
wss.on("connection", function connection(ws, req, res) { wss.on("connection", function connection(ws, req, res) {
ws.send(`online=${wss.clients.size}`); // ws.send(`online=${wss.clients.size}`);
setInterval(() => { // setInterval(() => {
ws.send(`online=${wss.clients.size}`); // ws.send(`online=${wss.clients.size}`);
}, 10000); // }, 10000);
let server = new WebSocket("ws://localhost:7910");
server.on("message", async function message(data) {
let message = Buffer.from(data).toString();
if(message.startsWith("online")) {
ws.send(message);
} else if(message.startsWith("annc")) {
ws.send(message);
}
})
ws.on("error", console.error); ws.on("error", console.error);
@ -67,9 +77,10 @@ wss.on("connection", function connection(ws, req, res) {
} else if (message.startsWith("annc")) { } else if (message.startsWith("annc")) {
let splitMessage = message.split(";;"); let splitMessage = message.split(";;");
if(await isAdmin(splitMessage[1])) { if(await isAdmin(splitMessage[1])) {
wss.clients.forEach(client => { // wss.clients.forEach(client => {
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`); // client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
}) // })
server.send(message);
} }
} }
}); });

View File

@ -4,6 +4,7 @@
"description": "", "description": "",
"exports": "./index.js", "exports": "./index.js",
"scripts": { "scripts": {
"websocket_server": "bun --watch websocket.js",
"start": "bun --watch index.js", "start": "bun --watch index.js",
"svg": "node svg-converter.js" "svg": "node svg-converter.js"
}, },

33
websocket.js Normal file
View File

@ -0,0 +1,33 @@
import WebSocket, { WebSocketServer } from "ws";
const wss = new WebSocketServer({ noServer: true });
wss.on("connection", function connection(ws, req, res) {
ws.send(`online=${wss.clients.size}`);
setInterval(() => {
ws.send(`online=${wss.clients.size}`);
}, 10000);
ws.on("message", async function message(data, isBinary) {
let message = Buffer.from(data).toString();
if (message.startsWith("annc")) {
let splitMessage = message.split(";;");
wss.clients.forEach(client => {
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
})
}
});
ws.on("close", () => {});
});
let port = 7910;
import express from "express";
const app = express();
const server = app.listen(port, () => {
console.log("Websocket server is online.");
console.log("- http://localhost:" + port);
});
server.on("upgrade", (request, socket, head) => {
wss.handleUpgrade(request, socket, head, (socket) => {
wss.emit("connection", socket, request);
});
});