Add Chookpen config file
This commit is contained in:
		| @@ -26,20 +26,48 @@ fun md5(input:String): String { | ||||
|     val md = MessageDigest.getInstance("MD5") | ||||
|     return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0') | ||||
| } | ||||
| /* | ||||
| fun removeLines(fileName: String, lineNumber: String) { | ||||
|     require(!fileName.isEmpty() && startLine >= 1 && numLines >= 1) | ||||
|     val f = File(fileName) | ||||
|     var lines = f.readLines() | ||||
|     if (startLine > size) { | ||||
|         println("The starting line is beyond the length of the file") | ||||
|         return | ||||
|  | ||||
| object config { | ||||
|     var address = "" | ||||
|     var port = "" | ||||
|     var security = ""  | ||||
|     var serviceName = "" | ||||
|  | ||||
|     fun getConfig() { | ||||
|         val configFile = File("chookpen.config") | ||||
|         try { | ||||
|             val config = configFile.readLines() | ||||
|             var type = "" | ||||
|             var isEditing = 0 | ||||
|             for (line in config) { | ||||
|                 for (char in line) { | ||||
|                     if (char == ':') { | ||||
|                         isEditing = 1 | ||||
|                     } else if (char == ';') { | ||||
|                         isEditing = 0 | ||||
|                         type = "" | ||||
|                     } else { | ||||
|                         if (isEditing == 0) { | ||||
|                             type += char | ||||
|                         } else if (isEditing == 1) | ||||
|                             if (type == "address") { | ||||
|                                 address += char | ||||
|                             } else if (type == "port") { | ||||
|                                 port += char | ||||
|                             } else if (type == "security") { | ||||
|                                 security += char | ||||
|                             } else if (type == "serviceName") { | ||||
|                                 serviceName += char | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|         } catch (e: Exception) { | ||||
|             println("Something went wrong :/ Here's the error: $e") | ||||
|         } | ||||
|     } | ||||
|     lines = lines.take(startLine - 1) + lines.drop(startLine + n - 1) | ||||
|     val text = lines.joinToString(System.lineSeparator()) | ||||
|     f.writeText(text) | ||||
| } | ||||
| */ | ||||
|  | ||||
| object WsSessionManager { | ||||
|     val peopleOnline = mutableListOf("") | ||||
|     val sessionsList = mutableListOf("") | ||||
| @@ -352,13 +380,41 @@ fun handleServerCommand(command: String): String { | ||||
|     return("I'm not sure how to ${commandArgs.toString()}") | ||||
| } | ||||
|  | ||||
| fun buildHTML(): String { | ||||
|     try { | ||||
|         config.getConfig() | ||||
|         val htmlFile = File("resources/index.html") | ||||
|         val html = htmlFile.readLines() | ||||
|         var editedhtml = "" | ||||
|         for (line in html) { | ||||
|             if (line == """                    <input type="text" id="serverUrl" value="bobcompass.online" placeholder="Server URL"><br>""") {  | ||||
|                 editedhtml += """                    <input type="text" id="serverUrl" value="${config.address}" placeholder="Server URL"><br>"""  | ||||
|             } else if (line == """                    <input type="text" id="serverPort" value="443" placeholder="Server Port"><br>""") { | ||||
|                 editedhtml += """                    <input type="text" id="serverPort" value="${config.port}" placeholder="Server Port"><br>""" | ||||
|             } else if (line == """                    <input type="checkbox" id="securityStatus" checked>""" && config.security == "false") { | ||||
|                 editedhtml += """                    <input type="checkbox" id="securityStatus">""" | ||||
|             } else if (line == """                    <h3>Chookchat</h3>""") { | ||||
|                 editedhtml += """                    <h3>${config.serviceName}</h3>"""  | ||||
|             } else { | ||||
|                 editedhtml += line | ||||
|             } | ||||
|         } | ||||
|         return(editedhtml) | ||||
|     } catch (e: Exception) { | ||||
|         println(e) | ||||
|         return("There was an error! If you're the server's admin, here are the details: $e") | ||||
|     } | ||||
|     return("dingus") | ||||
| } | ||||
|  | ||||
| fun main(args: Array<String>) { | ||||
|     WsSessionManager.peopleOnline.removeAt(0) | ||||
|     WsSessionManager.sessionsList.removeAt(0) | ||||
|     val app = Javalin.create { config -> | ||||
|             config.staticFiles.add("/public") | ||||
|         }.get("/") { ctx ->  | ||||
|             ctx.redirect("/index.html")  | ||||
|         }.get("/") { ctx ->   | ||||
|             ctx.html(buildHTML()) | ||||
|             //ctx.redirect("/index.html")  | ||||
|         } | ||||
|         .get("/api/createaccount/{content}") { ctx -> ctx.result(createAccount(ctx.pathParam("content")))} | ||||
|         .post("/api/upload") { ctx -> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Maxwell Jeffress
					Maxwell Jeffress