diff --git a/server/chookchat.eggs.config b/server/chookchat.eggs.config new file mode 100644 index 0000000..d5b4b91 --- /dev/null +++ b/server/chookchat.eggs.config @@ -0,0 +1 @@ +notepad diff --git a/server/eggs/notepad/index.html b/server/eggs/notepad/index.html new file mode 100644 index 0000000..77a49f2 --- /dev/null +++ b/server/eggs/notepad/index.html @@ -0,0 +1,4 @@ + diff --git a/server/eggs/notepad/index.js b/server/eggs/notepad/index.js new file mode 100644 index 0000000..30a0914 --- /dev/null +++ b/server/eggs/notepad/index.js @@ -0,0 +1,21 @@ +function eggNotepad() { + const eggsList = document.getElementById("eggs-list"); + eggsList.style.display = "none"; + const eggNotepad = document.getElementById("egg-notepad"); + eggNotepad.style.display = "block"; + const eggNotepadTextArea = document.getElementById("egg-notepad-textarea"); + eggNotepadTextArea.addEventListener('input', function(event) { + const eggNotepadMessage = { + "type": "egg-notepad", + "username": username, + "token": md5(password), + "content": event.target.value + }; + ws.send(JSON.stringify(eggNotepadMessage)); + }, false); +} + +function closeEggNotepad() { + const eggNotepad = document.getElementById("egg-notepad"); + eggNotepad.style.display = "none"; +} diff --git a/server/eggs/notepad/message.js b/server/eggs/notepad/message.js new file mode 100644 index 0000000..66f3aef --- /dev/null +++ b/server/eggs/notepad/message.js @@ -0,0 +1,4 @@ +else if (message.type == "egg-notepad") { + const eggNotepadTextArea = document.getElementById("egg-notepad-textarea"); + eggNotepadTextArea.value = message.content +} diff --git a/server/src/main/kotlin/Main.kt b/server/src/main/kotlin/Main.kt index bdc6c5f..a07fcf2 100644 --- a/server/src/main/kotlin/Main.kt +++ b/server/src/main/kotlin/Main.kt @@ -34,6 +34,10 @@ object config { var serviceName = "" fun getConfig() { + address = "" + port = "" + security = "" + serviceName = "" val configFile = File("chookchat.config") try { val config = configFile.readLines() @@ -395,10 +399,21 @@ fun buildHTML(): String { editedhtml += """ """ } else if (line == """

Chookchat

""") { editedhtml += """

${config.serviceName}

""" + } else if (line == """ """) { + val eggsFile = File("chookchat.eggs.config") + val eggs = eggsFile.readLines() + for (line in eggs) { + val eggHTMLFile = File("eggs/$line/index.html") + if (eggHTMLFile.exists()) { + val eggHTML = eggHTMLFile.readText() + editedhtml += eggHTML + } + } } else { editedhtml += line } } + return(editedhtml) } catch (e: Exception) { println(e) @@ -407,6 +422,42 @@ fun buildHTML(): String { return("dingus") } +fun buildJS(): String { + try { + val eggsFile = File("chookchat.eggs.config") + val eggs = eggsFile.readLines() + val jsFile = File("resources/index.js") + val js = jsFile.readLines() + var editedJS = "" + for (line in js) { + if (line == " // Egg message logic") { + for (line in eggs) { + val eggJSMessageFile = File("eggs/$line/message.js") + if (eggJSMessageFile.exists()) { + val eggJSMessage = eggJSMessageFile.readText() + editedJS += eggJSMessage + } + } + } else { + editedJS += "$line\n" + } + } + //editedJS += js + for (line in eggs) { + val eggJSFile = File("eggs/$line/index.js") + if (eggJSFile.exists()) { + val eggJS = eggJSFile.readText() + editedJS += eggJS + } + } + return(editedJS) + } catch (e: Exception) { + println(e) + return("console.log(`There was an error! If you're the server's admin, here are the details: $e`)") + } + return("dingus") +} + fun main(args: Array) { WsSessionManager.peopleOnline.removeAt(0) WsSessionManager.sessionsList.removeAt(0) @@ -416,6 +467,9 @@ fun main(args: Array) { ctx.html(buildHTML()) //ctx.redirect("/index.html") } + .get("/index.js") { ctx -> + ctx.result(buildJS()) + } .get("/api/createaccount/{content}") { ctx -> ctx.result(createAccount(ctx.pathParam("content")))} .post("/api/upload") { ctx -> val uploadedFiles = ctx.uploadedFiles()