From 8cd6db79f5382aefe3f0f66b583a35b678f62f35 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Wed, 23 Oct 2024 14:40:31 +1100 Subject: [PATCH] Update client for new server API --- client-cli/src/main/kotlin/Main.kt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/client-cli/src/main/kotlin/Main.kt b/client-cli/src/main/kotlin/Main.kt index c582520..0387c12 100644 --- a/client-cli/src/main/kotlin/Main.kt +++ b/client-cli/src/main/kotlin/Main.kt @@ -21,7 +21,7 @@ suspend fun main(args: Array) { var port = "" var hasHTTPS = "" var password = "" - var configFile = File(".chookpen.profile") + var configFile = File("${System.getProperty("user.home")}/chookpen.profile") if (!configFile.exists()) { println("You don't have a Chookpen profile set up yet. If you've got a Chookpen profile, type 'l' to login and press enter. Otherwise, just press enter.") @@ -31,13 +31,13 @@ suspend fun main(args: Array) { name = readln() println("Password:") password = readln() - val request = Fuel.get("http://localhost:8000/api/createAccount/username:{$name}token:{${md5(password)}}").body.string() - if (request == "Invalid token! Please try putting in your password right") { - println("Invalid password! Please rerun the program and put in the right password") + val request = Fuel.get("http://localhost:7070/api/logintest/username:{$name}token:{${md5(password)}}").body.string() + if (request == "Invalid token") { + println("Invalid password. Please rerun the program and put in the right password") exitProcess(1) } else { configFile.createNewFile() - configFile.writeText("$name:$password:localhost:8000:0") + configFile.writeText("$name:$password:localhost:7070:0") println("Logged in! Run the command again to start talking!") exitProcess(0) } @@ -53,13 +53,13 @@ suspend fun main(args: Array) { println("Please choose a password! Rerun the program and try again") exitProcess(1) } - val request = Fuel.get("http://localhost:8000/api/createAccount/username:{$newName}token:{${md5(newPassword)}}").body.string() + val request = Fuel.get("http://localhost:7070/api/createAccount/username:{$newName}token:{${md5(newPassword)}}").body.string() if (request == "That username already exists on the server! Please choose a different username") { println("That username already exists on the server! Rerun the program and choose a different username") exitProcess(1) } else { configFile.createNewFile() - configFile.writeText("$newName:$newPassword:localhost:8000:0") + configFile.writeText("$newName:$newPassword:localhost:7070:0") println("Account created!") exitProcess(0) } @@ -96,10 +96,14 @@ suspend fun main(args: Array) { val protocol = "https" } if (args.count() == 0) { - println(Fuel.get("$protocol://$server:$port/api/username:{$name}token:{${md5(password)}}").body.string()) + println(Fuel.get("$protocol://$server:$port/api/syncmessages/username:{$name}token:{${md5(password)}}").body.string()) } else { val message = args[0] - println(Fuel.get("$protocol://$server:$port/api/username:{$name}token:{${md5(password)}}message:{$message}").body.string()) + val isSuccessful = Fuel.get("$protocol://$server:$port/api/send/username:{$name}token:{${md5(password)}}message:{$message}").body.string() + if (isSuccessful != "Success") { + println(isSuccessful) + } + println(Fuel.get("$protocol://$server:$port/api/syncmessages/username:{$name}token:{${md5(password)}}").body.string()) } exitProcess(0) }