Add Chookpen config file
This commit is contained in:
parent
857a05b9ca
commit
90cf9f4325
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
.swp
|
||||
server/build
|
||||
server/.gradle
|
||||
server/uploads
|
||||
server/userDatabase
|
||||
server/chatHistory
|
||||
client-cli/build
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
# Chookpen Client (CLI)
|
||||
|
||||
This is the reference client for Chookpen. It is quite a basic client. This is a good starting point if you need an example, or are building a GUI Kotlin client.
|
||||
|
||||
## Features
|
||||
|
||||
* Profile file
|
||||
* Create account (buggy)
|
||||
* Log into existing account
|
||||
* Sync messages
|
||||
* Send message
|
||||
* Auto hash password
|
||||
* Configure whether HTTPS is used
|
||||
|
||||
## Documentation
|
||||
|
||||
To run this client, do the following:
|
||||
|
||||
1. Install Java 17+ and Gradle.
|
||||
2. `git clone https://git.maxwellj.xyz/max/chookpen`
|
||||
3. In the client-cli directory of the git repo, run `gradle installDist`.
|
||||
5. Inside build/install/bin, create a .chookpen.profile file that looks like this: ```name:password:server:port:0```
|
||||
6. Run the script in build/install/bin, or the bat file if you're a crazy weird guy who uses Windows (Make sure to use the command line otherwise it'll close instantly)
|
||||
7. If you'd like to send a message, add that as your argument after specifying the script.
|
||||
|
||||
Note: The password in .chookpen.profile is hashed by the client. If you're just testing the server, set your password to `dingus`. The hash recognised by the server for that password is `750c63441033127dccaa91c16b21614e`. Create an account with the method specified in the root README using that password.
|
|
@ -1,35 +0,0 @@
|
|||
plugins {
|
||||
kotlin("jvm") version "2.0.0"
|
||||
application
|
||||
distribution
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("xyz.maxwellj.chookpen.client.MainKt")
|
||||
layout.buildDirectory.dir("distributions/")
|
||||
}
|
||||
|
||||
group = "xyz.maxwellj.chookpen.client"
|
||||
version = "0.0.2"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks.withType<Jar> {
|
||||
manifest {
|
||||
attributes["Main-Class"] = "xyz.maxwellj.chookpen.client.MainKt"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(kotlin("test"))
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
rootProject.name = "chookpen.client"
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
package xyz.maxwellj.chookpen.client
|
||||
|
||||
import okhttp3.*
|
||||
import java.util.Scanner
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
import java.io.File
|
||||
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.security.MessageDigest
|
||||
|
||||
fun md5(input:String): String {
|
||||
val md = MessageDigest.getInstance("MD5")
|
||||
return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0')
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Variables
|
||||
var name = ""
|
||||
var server = ""
|
||||
var port = ""
|
||||
var hasHTTPS = ""
|
||||
var password = ""
|
||||
var configFile = File("${System.getProperty("user.home")}/chookpen.profile")
|
||||
|
||||
var configStage = 0
|
||||
for (char in configFile.readText()) {
|
||||
if (char == ':') {configStage ++}
|
||||
if (configStage == 0) {
|
||||
name += char
|
||||
} else if (configStage == 1) {
|
||||
password += char
|
||||
} else if (configStage == 2) {
|
||||
server += char
|
||||
} else if (configStage == 3) {
|
||||
port += char
|
||||
} else if (configStage == 4) {
|
||||
hasHTTPS += char
|
||||
}
|
||||
}
|
||||
|
||||
server = server.replace(":", "")
|
||||
port = port.replace(":", "")
|
||||
hasHTTPS = hasHTTPS.replace(":", "")
|
||||
password = password.replace(":", "")
|
||||
|
||||
if (password == "x") {
|
||||
println("Enter your password:")
|
||||
password = readln()
|
||||
}
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.pingInterval(30, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
val request = Request.Builder()
|
||||
.url("ws://localhost:7070/api/websocket")
|
||||
.build()
|
||||
|
||||
var webSocket: WebSocket? = null
|
||||
|
||||
val listener = object : WebSocketListener() {
|
||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||
println(password)
|
||||
println(md5(password))
|
||||
println("Connection opened")
|
||||
webSocket.send("username:{$name}token:{${md5(password)}}message:{Joined the room}")
|
||||
}
|
||||
|
||||
override fun onMessage(webSocket: WebSocket, text: String) {
|
||||
println("$text")
|
||||
}
|
||||
|
||||
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
|
||||
println("Connection closing: $reason")
|
||||
webSocket.close(1000, null)
|
||||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
println("Connection failed: ${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
// Set up shutdown hook for Ctrl+C handling
|
||||
Runtime.getRuntime().addShutdownHook(Thread {
|
||||
println("\nShutting down gracefully...")
|
||||
webSocket?.close(1000, "Client shutting down")
|
||||
client.dispatcher.executorService.shutdown()
|
||||
})
|
||||
|
||||
// Initialize WebSocket connection
|
||||
webSocket = client.newWebSocket(request, listener)
|
||||
|
||||
// Set up input handling
|
||||
val scanner = Scanner(System.`in`)
|
||||
println("Type your messages (press Enter to send, Ctrl+C to quit):")
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
val input = scanner.nextLine()
|
||||
if (input.isNotEmpty()) {
|
||||
webSocket?.send("username:{$name}token:{${md5(password)}}message:{$input}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Handle any input-related exceptions
|
||||
println("Error reading input: ${e.message}")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
1
server/chookpen.config
Normal file
1
server/chookpen.config
Normal file
|
@ -0,0 +1 @@
|
|||
address:localhost;port:7070;security:false;serviceName:fnkjdsnfiewnifdwsocidw;
|
1
server/resources/InterVariable.ttf
Symbolic link
1
server/resources/InterVariable.ttf
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../client-web/InterVariable.ttf
|
1
server/resources/gradient.css
Symbolic link
1
server/resources/gradient.css
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../client-web/gradient.css
|
1
server/resources/index.css
Symbolic link
1
server/resources/index.css
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../client-web/index.css
|
1
server/resources/index.html
Symbolic link
1
server/resources/index.html
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../client-web/index.html
|
1
server/resources/index.js
Symbolic link
1
server/resources/index.js
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../client-web/index.js
|
|
@ -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")
|
||||
ctx.html(buildHTML())
|
||||
//ctx.redirect("/index.html")
|
||||
}
|
||||
.get("/api/createaccount/{content}") { ctx -> ctx.result(createAccount(ctx.pathParam("content")))}
|
||||
.post("/api/upload") { ctx ->
|
||||
|
|
Loading…
Reference in New Issue
Block a user