implement connection between servers

This commit is contained in:
marlonerler
2024-07-05 16:04:12 +02:00
parent 979657508b
commit dd5d1b7e26
113 changed files with 6062 additions and 113 deletions
+36 -4
View File
@@ -1,5 +1,11 @@
import Colors from "colors";
import Fs from "fs/promises";
import { WebSocketMessage } from "./websocket-handler";
// CONFIG
const indent = 25;
// METHODS
export function guardStringNotEmpty(
data: any,
cb: (data: string) => void
@@ -8,10 +14,36 @@ export function guardStringNotEmpty(
cb(data);
}
export function writeInfo(label: string, value: string) {
console.log(label.padEnd(20, " "), Colors.bold.green(value));
// writing
async function writeToLogFile(message: string): Promise<void> {
await Fs.appendFile("logs", `${message}\n`);
}
export function writeStat(label: string, value: number) {
console.log(label.padEnd(20, " "), Colors.bold.blue(value.toString()));
export function writeInfo(label: string, value: string): void {
console.log(`${label.padEnd(indent, " ")} ${Colors.bold.green(value)}`);
}
export function writeStat(label: string, value: number): void {
console.log(
`${label.padEnd(indent, " ")} ${Colors.bold.blue(value.toString())}`
);
}
export function writeError(message: string): void {
console.log(Colors.bold.red(message));
writeToLogFile(message);
}
export function writeSuccess(message: string): void {
console.log(Colors.bold.green(message));
writeToLogFile(message);
}
// messages
export function stringifyMessage(messageObject: WebSocketMessage): string {
return JSON.stringify(messageObject);
}
export function parseMessage(messageString: string): Object {
return JSON.parse(messageString);
}