Skip to content

Commit ed9b551

Browse files
committed
bug fixes and inprovements
made things more stable, fixed some bugs, added some features even, more will be in release note once ready
1 parent 15c6da6 commit ed9b551

File tree

30 files changed

+1173
-583
lines changed

30 files changed

+1173
-583
lines changed

index.mjs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export let server; // = http.createServer(app);
2121
import {Server} from 'socket.io';
2222

2323
import nodefetch from "node-fetch";
24-
const { FormData, fileFrom } = nodefetch;
24+
25+
const {FormData, fileFrom} = nodefetch;
2526
const fetch = nodefetch.default;
2627

2728
import getSize from 'get-folder-size';
@@ -75,19 +76,19 @@ export let socketToIP = [];
7576

7677
export let allowLogging = false;
7778
export let debugmode = false;
78-
export let versionCode = 745;
79+
export let versionCode = 756;
7980

8081
// dSync Libs
8182
import dSyncAuth from '@hackthedev/dsync-auth';
8283
//import dSyncAuth from '../../../dSyncAuth/index.mjs';
83-
import { dSyncSign } from "@hackthedev/dsync-sign";
84+
import {dSyncSign} from "@hackthedev/dsync-sign";
8485
//import { dSyncSign } from "../dSyncSign/index.mjs"
8586
import dSync from "@hackthedev/dsync";
8687

8788
export let syncer = new dSync("dcts", app)
8889
export const signer = new dSyncSign();
89-
export const auther = new dSyncAuth(app, signer, async function(data) {
90-
if(data.valid === true){
90+
export const auther = new dSyncAuth(app, signer, async function (data) {
91+
if (data.valid === true) {
9192
changeKeyVerification(data.publicKey, data.valid);
9293
}
9394
});
@@ -208,10 +209,9 @@ const registerPluginSocketEvents = async (socket, pluginSocketsDir) => {
208209
const fileUrl = pathToFileURL(filePath).href;
209210
const {default: handler} = await import(fileUrl);
210211

211-
try{
212+
try {
212213
handler(socket);
213-
}
214-
catch(e){
214+
} catch (e) {
215215
Logger.error(fileUrl)
216216
Logger.error(e)
217217
}
@@ -253,7 +253,7 @@ const processPlugins = async () => {
253253
for (const pluginName of pluginDirs) {
254254

255255
// ignore files
256-
if(fs.lstatSync(path.join(pluginsDir, pluginName)).isFile() === true) continue;
256+
if (fs.lstatSync(path.join(pluginsDir, pluginName)).isFile() === true) continue;
257257

258258
const pluginDir = path.join(pluginsDir, pluginName);
259259
const pluginFunctionsDir = path.join(pluginDir, 'functions');
@@ -263,7 +263,7 @@ const processPlugins = async () => {
263263
let pluginConfigPath = path.join(pluginDir, 'config.json');
264264
let pluginConfig = null;
265265

266-
if(fs.existsSync(pluginConfigPath)) {
266+
if (fs.existsSync(pluginConfigPath)) {
267267
pluginConfig = JSON.parse(fs.readFileSync(pluginConfigPath));
268268
}
269269

@@ -274,7 +274,7 @@ const processPlugins = async () => {
274274
let pluginVersion = pluginConfig?.version || 0;
275275

276276
// skip disabled plugin
277-
if(pluginEnabled !== true) {
277+
if (pluginEnabled !== true) {
278278
Logger.warn(`Skipped loading plugin ${pluginTitle} (${pluginName}) because its not enabled`)
279279
continue;
280280
}
@@ -325,10 +325,11 @@ if (serverconfig.serverinfo.sql.enabled == true) {
325325
{name: 'authorId', type: 'varchar(100) NOT NULL'},
326326
{name: 'messageId', type: 'varchar(100) NOT NULL'},
327327
{name: 'room', type: 'text NOT NULL'},
328-
{name: 'message', type: 'longtext NOT NULL'}
328+
{name: 'message', type: 'longtext NOT NULL'},
329+
{name: 'createdAt', type: 'bigint NOT NULL DEFAULT (UNIX_TIMESTAMP() * 1000)'}
329330
],
330331
keys: [
331-
{name: 'UNIQUE KEY', type: 'messageId (messageId)'}
332+
{name: 'UNIQUE KEY', type: 'messageId (messageId)'},
332333
]
333334
},
334335
{
@@ -698,30 +699,29 @@ server.listen(port, function () {
698699
});
699700

700701

701-
702702
const API_KEY = serverconfig.serverinfo.livekit.key;
703703
const API_SECRET = serverconfig.serverinfo.livekit.secret;
704704

705705
const webhookReceiver = new WebhookReceiver(API_KEY, API_SECRET);
706706

707707
// --- Token Endpoint ---
708-
app.post("/token", async (req, res) => {
709-
const { roomName, participantName } = req.body;
708+
app.post("/token", async (req, res) => {
709+
const {roomName, participantName} = req.body;
710710

711711
if (!roomName || !participantName) {
712-
res.status(400).json({ errorMessage: "roomName and participantName are required" });
712+
res.status(400).json({errorMessage: "roomName and participantName are required"});
713713
return;
714714
}
715715

716-
const at = new AccessToken(API_KEY, API_SECRET, { identity: participantName });
717-
at.addGrant({ roomJoin: true, room: roomName });
716+
const at = new AccessToken(API_KEY, API_SECRET, {identity: participantName});
717+
at.addGrant({roomJoin: true, room: roomName});
718718
const token = await at.toJwt();
719719

720-
res.json({ token });
720+
res.json({token});
721721
});
722722

723723
// --- Webhook Endpoint ---
724-
app.post("/livekit/webhook", express.raw({ type: "*/*" }), async (req, res) => {
724+
app.post("/livekit/webhook", express.raw({type: "*/*"}), async (req, res) => {
725725
try {
726726
const event = await webhookReceiver.receive(req.body, req.get("Authorization"));
727727
console.log(event);
@@ -732,7 +732,6 @@ app.post("/livekit/webhook", express.raw({ type: "*/*" }), async (req, res) => {
732732
});
733733

734734

735-
736735
//app.use(express.urlencoded({extended: true})); // Parses URL-encoded data
737736
registerTemplateMiddleware(app, __dirname, fs, path, serverconfig);
738737
app.use(
@@ -747,7 +746,6 @@ app.use(
747746
);
748747

749748

750-
751749
// Process plugins at server start
752750
processPlugins().catch(err => console.error(err));
753751

@@ -822,7 +820,7 @@ const registerSocketEvents = (socket) => {
822820
}
823821
})();
824822

825-
export async function checkPow(socket){
823+
export async function checkPow(socket) {
826824
if (powVerifiedUsers.includes(socket.id)) {
827825
socket.powValidated = true;
828826
return;

modules/functions/main.mjs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import Logger from "./logger.mjs";
2222
import path from "path";
2323
import {powVerifiedUsers} from "../sockets/pow.mjs";
2424
import {sendSystemMessage} from "../sockets/home/general.mjs";
25-
import {encodeToBase64} from "./mysql/helper.mjs";
25+
import {decodeFromBase64, encodeToBase64} from "./mysql/helper.mjs";
2626
import {exec, spawn} from "node:child_process";
27+
import {queryDatabase} from "./mysql/mysql.mjs";
2728

2829
var serverconfigEditable;
2930

@@ -216,6 +217,25 @@ export async function handleTerminalCommands(command, args) {
216217
serverconfigEditable = checkEmptyConfigVar(serverconfigEditable, serverconfig);
217218

218219
try {
220+
if (command === 'migrateMessages') {
221+
if(serverconfig.serverinfo.sql.enabled === true){
222+
let messages = await queryDatabase("SELECT * FROM messages");
223+
if(messages.length > 0){
224+
for(let message of messages){
225+
let decodedMessage = JSON.parse(decodeFromBase64(message.message));
226+
227+
Logger.info(`Migrating message ${decodedMessage.messageId}, setting timestamp to ${decodedMessage.timestamp}`)
228+
await queryDatabase(`UPDATE messages set createdAt = ? WHERE messageId = ?`, [decodedMessage.timestamp, decodedMessage.messageId])
229+
}
230+
Logger.success("Migration done!")
231+
}
232+
}
233+
else{
234+
Logger.warn("SQL needs to be enabled and configurated inside the config.json. Its currently disabled!")
235+
}
236+
237+
return;
238+
}
219239
if (command == 'reload') {
220240
reloadConfig();
221241
consolas("Reloaded config".cyan);
@@ -861,13 +881,18 @@ export function validateMemberId(id, socket, token, bypass = false) {
861881
if(serverconfig.servermembers[id]?.token !== token){
862882
return false;
863883
}
864-
}
865884

866-
if (id.length === 12 && isNaN(id) === false) {
867-
return true;
868-
} else {
869-
return false;
885+
// if is banned deny all connections
886+
if(serverconfig.servermembers[id]?.isBanned === 1){
887+
return false;
888+
}
889+
890+
// update last online
891+
serverconfig.servermembers[id].lastOnline = new Date().getTime();
892+
saveConfig(serverconfig)
870893
}
894+
895+
return id.length === 12 && isNaN(id) === false;
871896
}
872897

873898
export function escapeHtml(text) {
@@ -1068,6 +1093,10 @@ export function checkMemberBan(socket, member) {
10681093
}
10691094
}
10701095

1096+
if(serverconfig.servermembers[member?.id.isBanned] === 1){
1097+
return {result: true, timestamp: null};
1098+
}
1099+
10711100
return {result: false};
10721101
}
10731102

0 commit comments

Comments
 (0)