~denisebitca/lowf

0e1276b2601be59e0cd15d3f7dd8290c12695683 — Rafael Bitca 2 years ago f261c46
Added log and report dirs to config
M src/classes/ChatServer.ts => src/classes/ChatServer.ts +0 -8
@@ 1,10 1,8 @@
'use strict';
import express from "express";
import http from "node:http";
//import https from "https";
import ws from "ws";
import random from "random";
import fs from "fs";

import { ChatUser } from "./ChatUser";
import { Pair } from "./Pair";


@@ 15,12 13,6 @@ var debug : boolean = config.debug;

//SSL unneeded - i am running this through a reverse proxy

/*if(!debug){
    var privateKey  = fs.readFileSync('/etc/letsencrypt/live/lowf.codes/privkey.pem', 'utf8');
    var certificate = fs.readFileSync('/etc/letsencrypt/live/lowf.codes/fullchain.pem', 'utf8');
    var credentials = {key: privateKey, cert: certificate, ciphers: 'ECDHE-RSA-AES256-SHA:AES256-SHA:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM', honorCipherOrder: true};
}*/

export class ChatServer {

    //variables

M src/classes/ChatUser.ts => src/classes/ChatUser.ts +4 -6
@@ 42,7 42,7 @@ export class ChatUser {
        this.ip = ip;
        this.socket = socket;
        this.pair = null;
	this.joindate = Date.now().toString();
	    this.joindate = Date.now().toString();

        //personal event handlers



@@ 53,7 53,7 @@ export class ChatUser {
            }
            try{
                var parsedMsg : Message = JSON.parse(message.data);
                //TODO: why am i not checking whether or not these properties exist?
                
                if(parsedMsg.type === "command"){
                    //command parse
                    if(parsedMsg.body === ChatUser._search){


@@ 100,7 100,7 @@ export class ChatUser {
                                        user2name: this.pair.user2.name
                                    }
                                }
                                fs.writeFileSync(__dirname + '/../report/' + uuidv4() + ".json", JSON.stringify(reportprep));
                                fs.writeFileSync(config.reportDir + uuidv4() + ".json", JSON.stringify(reportprep));
                            }
                        }



@@ 127,6 127,7 @@ export class ChatUser {
                } else throw new Error();
    
            } catch(error) {
                //TODO: Chief, I don't know if this is the best way of checking for malformed commands. Look into this please.
                log("error/P1", "Malformed request from IP " + this.ip);
                log("error/P2", "Request was " + message.data);
                this.terminate();


@@ 223,9 224,6 @@ export class ChatUser {
           this.pair?.unpair()
           this.pair = null;
        }
        /*if(this.socket.readyState != ws.CLOSING && this.socket.readyState != ws.CLOSED){
            this.socket.close();
        }*/
        ChatServer.delUser(this);
    }


M src/classes/Pair.ts => src/classes/Pair.ts +4 -3
@@ 1,5 1,6 @@
import { Message } from "./Message";
import { ChatUser } from "./ChatUser";
import config from "../config.json";
import { v4 as uuidv4 } from "uuid";
import fs from "fs";



@@ 21,7 22,7 @@ export class Pair{
        this.user2.setState(ChatUser.PAIRED);

        //Start logging
        this.lfile = fs.writeFileSync(__dirname + '/../public/logs/' + this.id + ".txt", "lowf.codes conversation\n\nThis is a conversation between " + this.user1.name + ' and ' + this.user2.name + '.\n\n');
        this.lfile = fs.writeFileSync(config.logDir + this.id + ".txt", config.websitedomain + " conversation\n\nThis is a conversation between " + this.user1.name + ' and ' + this.user2.name + '.\n\n');
    }
    unpair() : void {
        if(this.active){


@@ 32,9 33,9 @@ export class Pair{
    }
    send(msg : Message) : void {
        if(typeof(msg.body) === "string"){
            fs.appendFileSync(__dirname + '/../public/logs/' + this.id + ".txt", msg.body + ": " + msg.message + '\n');
            fs.appendFileSync(config.logDir + this.id + ".txt", msg.body + ": " + msg.message + '\n');
        } else {
            fs.appendFileSync(__dirname + '/../public/logs/' + this.id + ".txt", msg.message + '\n');
            fs.appendFileSync(config.logDir + this.id + ".txt", msg.message + '\n');
        }
        this.user1.send(msg);
        this.user2.send(msg);

M src/config.json => src/config.json +4 -1
@@ 1,4 1,7 @@
{
    "port": 8082,
    "debug": false
    "debug": false,
	"websitedomain": "lowf.codes",
    "logDir": "",
    "reportDir": ""
}

M src/functions/DebugTools.ts => src/functions/DebugTools.ts +1 -1
@@ 11,7 11,7 @@ export function log(type : string, message : string) : void{
}

export function runTesting() : void{
    var client : ws = new ws("ws://localhost:3000");
    var client : ws = new ws("ws://localhost:" + config.port);
    ws.once(client, "open").then(()=>{
        log("debug", "Client connection open! Testing messages...");
        client.onclose = ()=>{