From 09dfc821f42f6e238343e00ad74763fcca008951 Mon Sep 17 00:00:00 2001 From: beepbeat Date: Thu, 16 Nov 2017 21:57:44 +0100 Subject: [PATCH] rewrote rendering code changed stuff around still no secretFile in here theunk0wn asked for this SSL problems in binaries, runs fine when launched from IDE --- .idea/libraries/JHyperlink.xml | 11 + .../com_baulsupp_kolja_jcurses_0_9_5_3.xml | 15 -- ...com_googlecode_lanterna_lanterna_3_0_0.xml | 14 ++ .idea/modules/untitled1.iml | 3 +- build.gradle | 3 +- lib/JHyperlink.jar | Bin 0 -> 10234 bytes src/AuthHandler.kt | 40 ++-- src/LogHandler.kt | 4 +- src/Main.kt | 203 ++++++++++++------ src/Stuff.kt | 15 +- src/WebSocketHandler.kt | 49 +++-- 11 files changed, 215 insertions(+), 142 deletions(-) create mode 100644 .idea/libraries/JHyperlink.xml delete mode 100644 .idea/libraries/com_baulsupp_kolja_jcurses_0_9_5_3.xml create mode 100644 .idea/libraries/com_googlecode_lanterna_lanterna_3_0_0.xml create mode 100644 lib/JHyperlink.jar diff --git a/.idea/libraries/JHyperlink.xml b/.idea/libraries/JHyperlink.xml new file mode 100644 index 0000000..97d3992 --- /dev/null +++ b/.idea/libraries/JHyperlink.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/com_baulsupp_kolja_jcurses_0_9_5_3.xml b/.idea/libraries/com_baulsupp_kolja_jcurses_0_9_5_3.xml deleted file mode 100644 index 674bc79..0000000 --- a/.idea/libraries/com_baulsupp_kolja_jcurses_0_9_5_3.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/com_googlecode_lanterna_lanterna_3_0_0.xml b/.idea/libraries/com_googlecode_lanterna_lanterna_3_0_0.xml new file mode 100644 index 0000000..9cc0e98 --- /dev/null +++ b/.idea/libraries/com_googlecode_lanterna_lanterna_3_0_0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/untitled1.iml b/.idea/modules/untitled1.iml index 863ac90..1c63d52 100644 --- a/.idea/modules/untitled1.iml +++ b/.idea/modules/untitled1.iml @@ -26,7 +26,6 @@ - @@ -34,5 +33,7 @@ + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index c46207d..087d295 100644 --- a/build.gradle +++ b/build.gradle @@ -16,13 +16,14 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib" compile "org.jetbrains.kotlin:kotlin-reflect" compile "commons-io:commons-io:2.5" - compile "com.baulsupp.kolja:jcurses:0.9.5.3" + compile "com.googlecode.lanterna:lanterna:3.0.0" compile "com.google.code.gson:gson:2.8.2" compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.19" compile "org.java-websocket:Java-WebSocket:1.3.5" compile "org.dmfs:httpurlconnection-executor:0.15.1" compile "org.dmfs:oauth2-essentials:0.8.1" compile "org.dmfs:http-client-types:0.15.1" + compile files("lib/JHyperlink.jar") } sourceSets{ diff --git a/lib/JHyperlink.jar b/lib/JHyperlink.jar new file mode 100644 index 0000000000000000000000000000000000000000..4b8ae5950f2362ec38a5accf8aaf4dc13f78ab7b GIT binary patch literal 10234 zcmaKS1yCN%((a49y9IX$?oNWcI|O%kcY?cn(BLob`r__xL4!NNxyh;j-Y@6eI)88N zR!>#WOwa7j?9=nKq6`EiJm8Nsg0BevOZlG%Bmfd%?_|#OHVObJ{#PsH-`0PuoZT($ z%pGi8otggFVgg`)UzY#TBGLb6D=q2iVCrOJX=nY>%FxYlKugDdjThYyCH`Ib;fL_# z)37a2VL}RR$&tX_S*w2%`mikDRNIU^f)~?th+wb#f~&|xrYZZjZVfB`GZ_!4)sM}j zP2wwzZ%TCo;$fJlNET7I=W}X~bzaU*Xm%Yv-nf{Hhl7U$EkuHe(de}a9Xp$IuNUnQ z1HBpVse!1uGUe&AKZsv@nyy6qED02xGO9JM!Jrhjp85U zl_u;-kt{1`wr-Sd?-GA_(Q;720M(`&dq&o1x#I1HQJ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git a/src/AuthHandler.kt b/src/AuthHandler.kt index 6710f11..aec555e 100644 --- a/src/AuthHandler.kt +++ b/src/AuthHandler.kt @@ -1,21 +1,21 @@ import javafx.application.Application -import javafx.scene.Scene +import javafx.embed.swing.JFXPanel import javafx.scene.layout.StackPane -import javafx.scene.text.Text import javafx.stage.Stage -import org.dmfs.httpessentials.client.HttpRequestExecutor -import org.dmfs.httpessentials.httpurlconnection.HttpUrlConnectionExecutor +import kotlinx.coroutines.experimental.launch import org.dmfs.oauth2.client.BasicOAuth2AuthorizationProvider import org.dmfs.oauth2.client.BasicOAuth2Client import org.dmfs.oauth2.client.BasicOAuth2ClientCredentials -import org.dmfs.oauth2.client.OAuth2AccessToken import org.dmfs.oauth2.client.grants.AuthorizationCodeGrant import org.dmfs.oauth2.client.scope.BasicScope import org.dmfs.rfc3986.encoding.Encoded import org.dmfs.rfc3986.uris.LazyUri import org.dmfs.rfc5545.Duration +import org.swingplus.JHyperlink +import java.awt.Rectangle import java.net.URI +import javax.swing.JFrame /** @@ -28,21 +28,18 @@ class AuthHandler{ var redirectUrl : String = "" } - var executor: HttpRequestExecutor = HttpUrlConnectionExecutor() - lateinit var token : OAuth2AccessToken - - fun authorize(){ val provider = BasicOAuth2AuthorizationProvider(URI.create("https://beta.fuelrats.com/authorize"), URI.create("https://dev.api.fuelrats.com/oauth2/token"), Duration(1,0,3600)) val credentials = BasicOAuth2ClientCredentials(secret.clientID, secret.clientSecret) - val client = BasicOAuth2Client(provider, credentials, LazyUri(Encoded("https://localhost:13370"))) + val client = BasicOAuth2Client(provider, credentials, LazyUri(Encoded("http://localhost:13370"))) val grant = AuthorizationCodeGrant(client, BasicScope("rescue.read", "rat.read")) url = grant.authorizationUrl()!! println(url) val auth = Auth.Authenticator("") - Application.launch(UrlDialog().javaClass) + launch{Application.launch(UrlDialog().javaClass)} val result = auth.awaitAccessToken() + UrlDialog.frame.isVisible = false println("$result") if (!result){ throw IllegalStateException("couldnt start Server " + auth.authenticationError?.name + "," + auth.authenticationError?.description) @@ -50,7 +47,6 @@ class AuthHandler{ while (!auth.hasAccessToken()){ ; } - //token = grant.withRedirect(client.redirectUri()).accessToken(executor) } @@ -58,13 +54,25 @@ class AuthHandler{ } class UrlDialog : Application() { + companion object { + val frame = JFrame() + } + + + override fun start(stage: Stage?) { val url = AuthHandler.url.toString() val root = StackPane() - root.children.add(Text(200.0, 32.0, url)) - val scene = Scene(root, 800.0, 64.0) - stage!!.scene = scene - stage.show() + val pane = JFXPanel() + //pane.add(JHyperlink("Click here!", url)) + //root.children.add(pane.) + frame.bounds = Rectangle(800, 600) + frame.add(JHyperlink("Click here!", url)) + frame.isVisible = true + //val scene = Scene(root, 800.0, 64.0) + + //stage!!.scene = scene + //stage.show() } } diff --git a/src/LogHandler.kt b/src/LogHandler.kt index dbc8741..8684003 100644 --- a/src/LogHandler.kt +++ b/src/LogHandler.kt @@ -111,7 +111,7 @@ open class listener : TailerListenerAdapter(){ if (message.split(" ", limit = 3).size < 3) return val rt = message.split(" ", limit = 3)[2] var rats = ArrayList() - rt.split(" ").mapTo(rats) { Rat("", Status("")).setNameCorrectly(it) } + rt.split(" ").mapTo(rats) { Rat(it, Status("")).setNameCorrectly() } if (number.contains("#").and(containsNumber(number)) || number.toIntOrNull() != null) { number = getNumber(number) rescues.filter { it.number == number.toInt() }.forEach { val tmp = it.rats; it.rats.addAll(rats.filter { !tmp.contains(it) && it.name.isNotBlank() }) } @@ -124,7 +124,7 @@ open class listener : TailerListenerAdapter(){ var number = message.split(" ")[1] val rt = message.split(" ", limit = 3)[2] var rats = ArrayList() - rt.split(" ").mapTo(rats) { Rat("", Status("")).setNameCorrectly(it) } + rt.split(" ").mapTo(rats) { Rat(it, Status("")).setNameCorrectly() } if (number.contains("#").and(containsNumber(number)) || number.toIntOrNull() != null) { number = getNumber(number) diff --git a/src/Main.kt b/src/Main.kt index 6d5a693..b8a53e7 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -1,23 +1,54 @@ import Trilean.* -import jcurses.system.CharColor -import jcurses.system.Toolkit +import com.googlecode.lanterna.SGR +import com.googlecode.lanterna.TextColor +import com.googlecode.lanterna.input.KeyType +import com.googlecode.lanterna.terminal.DefaultTerminalFactory +import com.googlecode.lanterna.terminal.Terminal import kotlinx.coroutines.experimental.launch +import java.awt.event.KeyEvent +import java.awt.event.KeyListener import java.util.* import kotlin.collections.ArrayList import kotlin.concurrent.fixedRateTimer +class KeyProcessor : KeyListener{ + override fun keyTyped(e: KeyEvent?) { + when(e!!.keyChar){ + 'x', 'X' -> {terminal?.exitPrivateMode();java.lang.System.exit(0)} + } + } + + override fun keyPressed(e: KeyEvent?) = Unit + + override fun keyReleased(e: KeyEvent?) = Unit + +} + + fun main(args: Array) { initConfig() readConfig() saveConfig() tailerfr.delay tailerrc.delay - Toolkit.init() - Toolkit.clearScreen(color) - color.foreground = CharColor.CYAN + color = Pair(TextColor.ANSI.CYAN, color.second) + terminal = DefaultTerminalFactory().createTerminal() + initTimers() + + + launch { while(true) { + val keyStroke = terminal?.pollInput() ?: continue + if (keyStroke.keyType != KeyType.Character) continue + when (keyStroke.character){ + 'x', 'X' -> { + terminal?.exitPrivateMode() + java.lang.System.exit(0) + } + } + } + } - //always last call launch{inpThr.run()} launch{ WebSocket.instance().init() @@ -27,8 +58,15 @@ fun main(args: Array) { while(true); } -//val screenupdate = fixedRateTimer("ScreenUpdater", false, 500, 1000, ::updateScreen) -val tailerdog = fixedRateTimer("TailerWatchdog", true, 500, 1000, ::checkTailer) +var screenupdate : Timer? = null +var tailerdog : Timer? = null +@Volatile +var terminal: Terminal? = null + +fun initTimers(){ + screenupdate = fixedRateTimer("ScreenUpdater", true, 500, 1000, ::updateScreen) + tailerdog = fixedRateTimer("TailerWatchdog", true, 500, 1000, ::checkTailer) +} fun checkTailer(task : TimerTask) { @@ -47,46 +85,73 @@ fun checkTailer(task : TimerTask) { var toPrint = ArrayList() fun updateScreen(timerTask: TimerTask) { - launch { - Toolkit.clearScreen(blackwhite) - var linecount = 0 - //toPrint.add(Random().nextDouble().toString()) - Toolkit.printString("Welcome to JAFRDB", Toolkit.getScreenWidth() / 2 - 17 /* welcome string length*/, 0, color) - Toolkit.printString("Cases: ", 2, 1, blackwhite) - linecount = printRescues() - -// for (str in toPrint){ - // Toolkit.printString(str, 0, linecount + 2, blackwhite) - // linecount++ - //} + with(terminal!!) { + enterPrivateMode() + setBackgroundColor(TextColor.ANSI.BLACK) + setForegroundColor(TextColor.ANSI.WHITE) + clearScreen() + setCursorPosition(0, 0) + enableSGR(SGR.BOLD) + } + var linecount = 0 + terminal?.printString("Welcome to JAFRDB", terminal!!.terminalSize.columns / 2 - 17 /* welcome string length*/, 0) + terminal?.printString("Cases: ", 2, 1) + linecount = printRescues() + + val iter = toPrint.iterator() + while(iter.hasNext()){ + val tmp = iter.next() + terminal?.printString(tmp, 2, linecount) + linecount++ + //iter.remove() } } -fun printRescues() : Int{ +fun Terminal.printString(input : String, x : Int, y : Int, color : Pair = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK), reversed : Boolean = false){ + @Suppress("NAME_SHADOWING") + val color = if (reversed){Pair(color.second, color.first)} else {color} + val coords = this.cursorPosition + this.setCursorPosition(x, y) + this.setForegroundColor(color.first) + this.setBackgroundColor(color.second) + input.toCharArray().forEach { + this.putCharacter(it) + } + flush() + this.cursorPosition = coords +} + +fun printRescues() : Int { var linecount = 0 - var colors = CharColor(CharColor.BLACK, CharColor.WHITE) + var colors = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK) try { - for (res in rescues){ - var charCount = 0 - if (res.cr) {colors.foreground = CharColor.RED} - if (!res.active) {colors.colorAttribute = CharColor.REVERSE} - - Toolkit.printString(res.number.toString() + " |", charCount + 2, linecount + 2, colors) - charCount += res.number.toString().length + 2 - Toolkit.printString(" " + res.client + " |", charCount + 2, linecount + 2, colors) - charCount += res.client.length + 3 - Toolkit.printString(" " + res.language + " |", charCount + 2, linecount + 2, colors) - charCount += res.language.length + 3 - Toolkit.printString(" " + res.platform + " |", charCount + 2, linecount + 2, colors) - charCount += res.platform.length + 3 - Toolkit.printString(" " + res.clientSystem.name, charCount + 2, linecount + 2, colors) - charCount += res.clientSystem.name.length + 1 - linecount = printStatus(res, linecount) - //printNotes - - colors = CharColor(CharColor.BLACK, CharColor.WHITE) + for (res in rescues) { + var charCount = 0 + if (res.cr) { + colors = Pair(TextColor.ANSI.RED, colors.second) + } + if (!res.active) { + terminal?.enableSGR(SGR.REVERSE) + } + terminal?.printString("${res.number} |", charCount + 2, linecount + 2, colors) + charCount += res.number.toString().length + 2 + terminal?.printString(" ${res.client} |", charCount + 2, linecount + 2, colors) + charCount += res.client.length + 3 + terminal?.printString(" ${res.language} |", charCount + 2, linecount + 2, colors) + charCount += res.language.length + 3 + terminal?.printString(" ${res.platform} |", charCount + 2, linecount + 2, colors) + charCount += res.platform.length + 3 + terminal?.printString(" ${res.clientSystem.name}", charCount + 2, linecount + 2, colors) + charCount += res.clientSystem.name.length + 1 + if (!res.active) { + terminal?.disableSGR(SGR.REVERSE) + } + linecount = printStatus(res, linecount) + //printNotes + + colors = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK) } - } catch(e: Exception) { + } catch (e: Exception) { } return linecount } @@ -95,52 +160,52 @@ fun printStatus(res: Rescue, lCount : Int) : Int{ var lineCount = lCount + 1 for ((name, status) in res.rats) { var charCount = 0 - Toolkit.printString(name + ": ", charCount + 3, lineCount + 2, blackwhite) + terminal?.printString(name + ": ", charCount + 3, lineCount + 2, blackwhite) charCount += name.length + 2 - if (status.friended == TRUE) Toolkit.printString("FR+", charCount + 3, lineCount + 2, CharColor(CharColor.MAGENTA, CharColor.WHITE)) - if (status.friended == NEUTRAL) {Toolkit.printString("FR-", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE))} - if (status.friended == FALSE) {Toolkit.printString("FR-", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE))} + if (status.friended == TRUE) terminal?.printString("FR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.MAGENTA, TextColor.ANSI.WHITE), true) + if (status.friended == NEUTRAL) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)} + if (status.friended == FALSE) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)} charCount += 3 + 1 - if (status.winged == TRUE) Toolkit.printString("WR+", charCount + 3, lineCount + 2, CharColor(CharColor.CYAN, CharColor.WHITE)) - if (status.winged == NEUTRAL) Toolkit.printString("WR-", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) - if (status.winged == FALSE) Toolkit.printString("WR-", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE)) + if (status.winged == TRUE) terminal?.printString("WR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.CYAN, TextColor.ANSI.WHITE), true) + if (status.winged == NEUTRAL) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) + if (status.winged == FALSE) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true) charCount += 3 + 1 - if (status.beacon == TRUE) Toolkit.printString("Beacon+", charCount + 3, lineCount + 2, CharColor(CharColor.BLUE, CharColor.WHITE)) - if (status.beacon == NEUTRAL) Toolkit.printString("Beacon-", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) - if (status.beacon == FALSE) Toolkit.printString("Beacon-", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE)) + if (status.beacon == TRUE) terminal?.printString("Beacon+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLUE, TextColor.ANSI.WHITE), true) + if (status.beacon == NEUTRAL) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) + if (status.beacon == FALSE) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true) charCount += 7 + 1 - if (status.inSys == TRUE) Toolkit.printString("Sys+", charCount + 3, lineCount + 2, CharColor(CharColor.YELLOW, CharColor.WHITE)) - if (status.inSys == NEUTRAL) Toolkit.printString("Sys-", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) + if (status.inSys == TRUE) terminal?.printString("Sys+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.YELLOW, TextColor.ANSI.WHITE), true) + if (status.inSys == NEUTRAL) terminal?.printString("Sys-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) charCount += 4 + 1 - if (status.fueled == TRUE) Toolkit.printString("Fuel+", charCount + 3, lineCount + 2, CharColor(CharColor.GREEN, CharColor.WHITE)) - else Toolkit.printString("", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) + if (status.fueled == TRUE) terminal?.printString("Fuel+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.GREEN, TextColor.ANSI.WHITE), true) + else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) charCount += 5 + 1 - if (status.disconnected == TRUE) Toolkit.printString("DC", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE)) - else Toolkit.printString("", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) + if (status.disconnected == TRUE) terminal?.printString("DC", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true) + else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) charCount += 2 + 1 - if (status.instancingP == TRUE) Toolkit.printString("Inst-", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE)) - if (status.instancingP == NEUTRAL) Toolkit.printString("", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) - if (status.instancingP == FALSE) Toolkit.printString("", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.GREEN)) + if (status.instancingP == TRUE) terminal?.printString("Inst-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true) + if (status.instancingP == NEUTRAL) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) + if (status.instancingP == FALSE) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN), true) charCount += 5 + 1 - if (status.interdicted == TRUE) Toolkit.printString("INT", charCount + 3, lineCount + 2, CharColor(CharColor.RED, CharColor.WHITE)) - else Toolkit.printString("", charCount + 3, lineCount + 2, CharColor(CharColor.BLACK, CharColor.WHITE)) + if (status.interdicted == TRUE) terminal?.printString("INT", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true) + else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true) charCount += 3 + 1 lineCount++ } return lineCount } -val color = CharColor(CharColor.BLACK, CharColor.WHITE) +var color = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK) @Volatile -var blackwhite = CharColor(CharColor.BLACK, CharColor.WHITE) +var blackwhite = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK) fun times(i : Int, function: (i : Int) -> Unit){ var x : Int = 0 while (x < i){ @@ -150,12 +215,14 @@ fun times(i : Int, function: (i : Int) -> Unit){ } -fun beep(){ print(7.toChar())} -enum class Rank{none, recruit, rat, overseer, techrat, op, netadmin, admin} +fun beep(){ + if ("${config.varMap["${entries.beep}"]}" == "true") + terminal?.bell() +} data class Rat( var name : String, var status : Status){ - fun setNameCorrectly(value : String) : Rat { + fun setNameCorrectly() : Rat { name.replace(" ", "_").replaceAfter("[", "") return this } diff --git a/src/Stuff.kt b/src/Stuff.kt index d121dae..141f087 100644 --- a/src/Stuff.kt +++ b/src/Stuff.kt @@ -1,5 +1,3 @@ -import jcurses.system.PlatformUtil -import jcurses.system.Toolkit import java.util.regex.Pattern import kotlin.system.exitProcess @@ -11,7 +9,6 @@ val inpThr : Thread = Thread(fun (){ line = line!! if (line == "exit") { - Toolkit.shutdown() exitProcess(0) } var nick : String = "" @@ -59,16 +56,6 @@ fun String.reduce() : String{ fun ArrayList.asStringArray(): ArrayList { var retV = ArrayList() - this.mapTo(retV) { it.number.toString() + "|" + it.client + "|" + it.language + "|" + it.clientSystem.name + "|" + it.platform + "|" + it.active.toString() } + this.mapTo(retV) { "${it.number}|${it.client}|${it.language}|${it.clientSystem.name}|${it.platform}|${it.active}" } return retV; } - -fun getLibraryName() : String{ - var library: String? = null - when { - PlatformUtil.isWindowsX86() -> library = "/META-INF/windows-x86/libjcurses.dll" - PlatformUtil.isMacOsx() -> library = "/META-INF/osx/libjcurses.jnilib" - PlatformUtil.isLinuxX86() -> library = "/META-INF/linux-x86/libjcurses.so" - } - return library!! -} \ No newline at end of file diff --git a/src/WebSocketHandler.kt b/src/WebSocketHandler.kt index 9f3cedb..13724d2 100644 --- a/src/WebSocketHandler.kt +++ b/src/WebSocketHandler.kt @@ -17,7 +17,6 @@ val parser = JsonParser() class WebSocket{ lateinit var client: WebSocketClient - //lateinit var writer : BufferedWriter companion object { var inst : WebSocket? = null fun instance(): WebSocket { @@ -30,19 +29,15 @@ class WebSocket{ suspend fun init(){ - client = WebSocketClient(URI("wss://dev.api.fuelrats.com")) - //println("Connecting blocking") - client.connectBlocking() - //println("Connected") - - // delay(2000) - //while (!client.isOpen){} - // client.send("{\"action\":[\"rescues\",\"read\"],\"meta\":{\"action\":\"rescues:read\"},\"status\":{\"\$not\":\"closed\"}}") - // writer = client.socket.getOutputStream().bufferedWriter() - } + client = WebSocketClient(URI("wss://dev.api.fuelrats.com/?bearer=${config.varMap["${entries.token}"]}")) + var i = 1 + var result = client.connectBlocking() + while (!result){ + toPrint.add("WebSocket Connection failed! Tries: $i") + i++ + result = client.connectBlocking() + } - fun send(msg: String){ - client.send(msg) } fun request(controller : String, action : String, params : Map = emptyMap(), metaPar : Map = emptyMap()){ @@ -80,7 +75,7 @@ class WebSocketClient(uri: URI) : org.java_websocket.client.WebSocketClient(uri) } @Suppress("NAME_SHADOWING") var message : String = message - //println("message: " + message) + println("message: " + message) handleWSMessage(message) } @@ -92,19 +87,23 @@ class WebSocketClient(uri: URI) : org.java_websocket.client.WebSocketClient(uri) fun handleWSMessage(msg: String){ val origElement = parser.parse(msg) - var meta = origElement. - asJsonObject. - get("meta"). - asJsonObject + try { + var meta = origElement. + asJsonObject. + get("meta"). + asJsonObject - if (meta.asJsonObject.has("event")) return + if (meta.asJsonObject.has("event")) return - var data = origElement.asJsonObject.get("data").asJsonArray + var data = origElement.asJsonObject.get("data").asJsonArray - when (meta.get("action").asString){ - "rescues:read" -> parseRescueRead(meta, data) - "rats:read" -> parseRatNameResolution(meta, data) + when (meta.get("action").asString){ + "rescues:read" -> parseRescueRead(meta, data) + "rats:read" -> parseRatNameResolution(meta, data) + } + } catch (e: Exception) { + e.printStackTrace(listenfr.stackFile) } } @@ -135,8 +134,8 @@ fun parseRescueRead(meta: JsonObject, data : JsonArray){ .get("relationships").asJsonObject .get("rats").asJsonObject .get("data").asJsonArray - .forEach { resc.rats.add(Rat(resolveRatName(""), Status("")).setNameCorrectly(it.asJsonObject.get("id").asString)) } - attributes.get("unidentifiedRats").asJsonArray.forEach { resc.rats.add(Rat("", Status("")).setNameCorrectly(it.asString)) } + .forEach { resc.rats.add(Rat(resolveRatName(it.asJsonObject.get("id").asString), Status("")).setNameCorrectly()) } + attributes.get("unidentifiedRats").asJsonArray.forEach { resc.rats.add(Rat(it.asString, Status("")).setNameCorrectly()) } //println("adding rescue. name: $name, cr: $cr, system: $system, lang: $lang, number: $number, platform: $platform") rescues.add(resc)