Browse Source

bugfix

pull/6/head
Aditya Kulkarni 5 years ago
parent
commit
a3a3a8ab4b
  1. 15
      src/main/kotlin/com/zecqtwallet/wormhole/Service.kt

15
src/main/kotlin/com/zecqtwallet/wormhole/Service.kt

@ -34,6 +34,8 @@ fun main(args : Array<String>) {
sendError(session, "Message too big") sendError(session, "Message too big")
} }
println("Recieved $message")
// Parse the message as json // Parse the message as json
try { try {
val j = Parser.default().parse(StringBuilder(message)) as JsonObject val j = Parser.default().parse(StringBuilder(message)) as JsonObject
@ -53,9 +55,13 @@ fun main(args : Array<String>) {
s[0].send(message) s[0].send(message)
return@onMessage return@onMessage
} else {
println("There was no 'to' in the message")
sendError(session,"Missing 'to' field")
return@onMessage
} }
} catch (e: Throwable) { } catch (e: Throwable) {
println("Exception: ${e.localizedMessage}")
session.close(1000, "Invalid json") session.close(1000, "Invalid json")
} }
} }
@ -70,11 +76,8 @@ fun main(args : Array<String>) {
} }
fun doRegister(session: WsSession, id: String) { fun doRegister(session: WsSession, id: String) {
if (usermap.contains(session)) { if (usermap.containsKey(session)) {
sendError(session, "Already registered a session, so disconnecting for bad behaviour") println("Already registered a session")
usermap.remove(session)
session.close()
} }
println("Registered $id") println("Registered $id")

Loading…
Cancel
Save