replace logger with System.out until we find a way to log version agnostic
This commit is contained in:
parent
7d02199eb1
commit
fb4d94f718
|
@ -45,7 +45,7 @@ shadowJar {
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = mc_version + "-" + forge_version
|
version = mc_version + "-" + forge_version
|
||||||
runDir = "../run"
|
runDir = "run"
|
||||||
|
|
||||||
mappings = mcp_mappings
|
mappings = mcp_mappings
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,14 @@ import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import net.minecraftforge.fml.common.Mod
|
import net.minecraftforge.fml.common.Mod
|
||||||
import net.minecraftforge.fml.common.event.*
|
import net.minecraftforge.fml.common.event.*
|
||||||
|
import org.apache.logging.log4j.Logger
|
||||||
|
|
||||||
const val MODID = "matterlink"
|
const val MODID = "matterlink"
|
||||||
const val NAME = "MatterLink"
|
const val NAME = "MatterLink"
|
||||||
const val VERSION = "@VERSION@"
|
const val VERSION = "@VERSION@"
|
||||||
|
|
||||||
|
lateinit var logger: Logger
|
||||||
|
|
||||||
@Mod(
|
@Mod(
|
||||||
modid = MODID,
|
modid = MODID,
|
||||||
name = NAME, version = VERSION,
|
name = NAME, version = VERSION,
|
||||||
|
|
|
@ -45,7 +45,7 @@ shadowJar {
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = mc_version + "-" + forge_version
|
version = mc_version + "-" + forge_version
|
||||||
runDir = "../run"
|
runDir = "run"
|
||||||
|
|
||||||
mappings = mcp_mappings
|
mappings = mcp_mappings
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,14 @@ import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import net.minecraftforge.fml.common.Mod
|
import net.minecraftforge.fml.common.Mod
|
||||||
import net.minecraftforge.fml.common.event.*
|
import net.minecraftforge.fml.common.event.*
|
||||||
|
import org.apache.logging.log4j.Logger
|
||||||
|
|
||||||
const val MODID = "matterlink"
|
const val MODID = "matterlink"
|
||||||
const val NAME = "MatterLink"
|
const val NAME = "MatterLink"
|
||||||
const val VERSION = "@VERSION@"
|
const val VERSION = "@VERSION@"
|
||||||
|
|
||||||
|
lateinit var logger: Logger
|
||||||
|
|
||||||
@Mod(
|
@Mod(
|
||||||
modid = MODID,
|
modid = MODID,
|
||||||
name = NAME, version = VERSION,
|
name = NAME, version = VERSION,
|
||||||
|
|
15
build.gradle
15
build.gradle
|
@ -3,18 +3,17 @@ plugins {
|
||||||
id 'idea'
|
id 'idea'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
apply plugin: "kotlin"
|
apply plugin: "kotlin"
|
||||||
apply plugin: 'idea'
|
apply plugin: "idea"
|
||||||
|
|
||||||
idea {
|
|
||||||
module {
|
|
||||||
excludeDirs += [file("run")]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(name != "core") {
|
if(name != "core") {
|
||||||
|
idea {
|
||||||
|
module {
|
||||||
|
excludeDirs += [file("run")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
|
|
@ -20,7 +20,7 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.apache.httpcomponents:httpclient:4.3.3'
|
compile 'org.apache.httpcomponents:httpclient:4.3.3'
|
||||||
compile 'commons-logging:commons-logging:1.1.3'
|
compile 'commons-logging:commons-logging:1.1.3'
|
||||||
compile group: "org.apache.logging.log4j", name: "log4j-api", version: '2.8.1'
|
// compile group: "org.apache.logging.log4j", name: "log4j-api", version: '2.8.1'
|
||||||
compile 'com.google.code.gson:gson:2.8.0'
|
compile 'com.google.code.gson:gson:2.8.0'
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandler
|
||||||
import org.apache.logging.log4j.Logger
|
//import org.apache.logging.log4j.Logger
|
||||||
|
|
||||||
lateinit var instance: IMatterLink
|
lateinit var instance: IMatterLink
|
||||||
lateinit var logger: Logger
|
//lateinit var logger: Logger
|
||||||
|
|
||||||
abstract class IMatterLink {
|
abstract class IMatterLink {
|
||||||
var interrupted: Boolean = false
|
var interrupted: Boolean = false
|
||||||
|
@ -15,9 +15,9 @@ abstract class IMatterLink {
|
||||||
|
|
||||||
fun connect() {
|
fun connect() {
|
||||||
if (MessageHandler.start(clear = true)) {
|
if (MessageHandler.start(clear = true)) {
|
||||||
logger.info("Connected to matterbridge relay")
|
println("Connected to matterbridge relay")
|
||||||
} else {
|
} else {
|
||||||
logger.error("Connection to matterbridge relay failed.")
|
System.err.println("Connection to matterbridge relay failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ abstract class IMatterLink {
|
||||||
|
|
||||||
fun reconnect(tick: Int) {
|
fun reconnect(tick: Int) {
|
||||||
if(tick % 20 == 0 && interrupted) {
|
if(tick % 20 == 0 && interrupted) {
|
||||||
logger.info("Trying to reconnect")
|
println("Trying to reconnect")
|
||||||
if (MessageHandler.start(clear = false)) {
|
if (MessageHandler.start(clear = false)) {
|
||||||
logger.info("Reconnected to matterbridge relay")
|
println("Reconnected to matterbridge relay")
|
||||||
} else {
|
} else {
|
||||||
logger.error("Reconnection to matterbridge relay failed.")
|
System.err.println("Reconnection to matterbridge relay failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package matterlink.bridge;
|
package matterlink.bridge;
|
||||||
|
|
||||||
import matterlink.instance
|
import matterlink.instance
|
||||||
import matterlink.logger
|
//import matterlink.logger
|
||||||
import org.apache.http.client.methods.HttpGet
|
import org.apache.http.client.methods.HttpGet
|
||||||
import org.apache.http.impl.client.HttpClients
|
import org.apache.http.impl.client.HttpClients
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
@ -24,7 +24,7 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe
|
||||||
if (clear) {
|
if (clear) {
|
||||||
val r = client.execute(clearGet)
|
val r = client.execute(clearGet)
|
||||||
r.entity.content.bufferedReader().forEachLine {
|
r.entity.content.bufferedReader().forEachLine {
|
||||||
logger.debug("skipping $it")
|
println("DEBUG: skipping $it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val response = client.execute(get)
|
val response = client.execute(get)
|
||||||
|
@ -39,7 +39,7 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe
|
||||||
if (chars > 0) {
|
if (chars > 0) {
|
||||||
buffer += String(buf.dropLast(buf.count() - chars).toByteArray())
|
buffer += String(buf.dropLast(buf.count() - chars).toByteArray())
|
||||||
|
|
||||||
logger.debug(buffer)
|
println("DEBUG: " + buffer)
|
||||||
|
|
||||||
while (buffer.contains("\n")) {
|
while (buffer.contains("\n")) {
|
||||||
val line = buffer.substringBefore("\n")
|
val line = buffer.substringBefore("\n")
|
||||||
|
@ -52,14 +52,14 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe
|
||||||
}
|
}
|
||||||
} catch (e: SocketException) {
|
} catch (e: SocketException) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
logger.error("Bridge Connection interrupted...")
|
System.err.println("Bridge Connection interrupted...")
|
||||||
instance.interrupted = true
|
instance.interrupted = true
|
||||||
//TODO: mark connection as interrupted and try to reconnect
|
//TODO: mark connection as interrupted and try to reconnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("closing stream")
|
println("DEBUG: closing stream")
|
||||||
content.close()
|
content.close()
|
||||||
logger.debug("thread finished")
|
println("DEBUG: thread finished")
|
||||||
onClose()
|
onClose()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package matterlink.bridge
|
package matterlink.bridge
|
||||||
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.logger
|
//import matterlink.logger
|
||||||
import org.apache.http.client.methods.HttpGet
|
import org.apache.http.client.methods.HttpGet
|
||||||
import org.apache.http.client.methods.HttpPost
|
import org.apache.http.client.methods.HttpPost
|
||||||
import org.apache.http.client.methods.HttpRequestBase
|
import org.apache.http.client.methods.HttpRequestBase
|
||||||
|
@ -30,7 +30,7 @@ object MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createThread(clear: Boolean = true): HttpStreamConnection {
|
private fun createThread(clear: Boolean = true): HttpStreamConnection {
|
||||||
logger.info("Attempting to open bridge connection.")
|
println("Attempting to open bridge connection.")
|
||||||
return HttpStreamConnection(
|
return HttpStreamConnection(
|
||||||
{
|
{
|
||||||
HttpGet(cfg!!.connect.url + "/api/stream").apply {
|
HttpGet(cfg!!.connect.url + "/api/stream").apply {
|
||||||
|
@ -46,10 +46,10 @@ object MessageHandler {
|
||||||
rcvQueue.add(
|
rcvQueue.add(
|
||||||
ApiMessage.decode(it)
|
ApiMessage.decode(it)
|
||||||
)
|
)
|
||||||
logger.debug("Received: " + it)
|
// println("Received: " + it)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
logger.info("Bridge connection closed!")
|
println("Bridge connection closed!")
|
||||||
connected = false
|
connected = false
|
||||||
},
|
},
|
||||||
clear
|
clear
|
||||||
|
@ -58,13 +58,13 @@ object MessageHandler {
|
||||||
|
|
||||||
fun transmit(msg: ApiMessage) {
|
fun transmit(msg: ApiMessage) {
|
||||||
if (connected && streamConnection.isAlive) {
|
if (connected && streamConnection.isAlive) {
|
||||||
logger.debug("Transmitting: " + msg)
|
println("Transmitting: " + msg)
|
||||||
transmitMessage(msg)
|
transmitMessage(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
logger.info("Closing bridge connection...")
|
println("Closing bridge connection...")
|
||||||
// MessageHandler.transmit(ApiMessage(text="bridge closing", username="Server"))
|
// MessageHandler.transmit(ApiMessage(text="bridge closing", username="Server"))
|
||||||
streamConnection.close()
|
streamConnection.close()
|
||||||
}
|
}
|
||||||
|
@ -93,14 +93,14 @@ object MessageHandler {
|
||||||
val response = client.execute(post)
|
val response = client.execute(post)
|
||||||
val code = response.statusLine.statusCode
|
val code = response.statusLine.statusCode
|
||||||
if (code != 200) {
|
if (code != 200) {
|
||||||
logger.error("Server returned $code for $post")
|
System.err.println("Server returned $code for $post")
|
||||||
}
|
}
|
||||||
sendErrors = 0
|
sendErrors = 0
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
logger.error("sending message caused $e")
|
System.err.println("sending message caused $e")
|
||||||
sendErrors++
|
sendErrors++
|
||||||
if (sendErrors > 5) {
|
if (sendErrors > 5) {
|
||||||
logger.error("caught too many errors, closing bridge")
|
System.err.println("caught too many errors, closing bridge")
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package matterlink.bridge
|
package matterlink.bridge
|
||||||
|
|
||||||
import matterlink.logger
|
//import matterlink.logger
|
||||||
import matterlink.instance
|
import matterlink.instance
|
||||||
import matterlink.bridge.command.BridgeCommandRegistry
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
@ -13,7 +13,7 @@ object ServerChatHandler {
|
||||||
fun writeIncomingToChat(tick: Int) {
|
fun writeIncomingToChat(tick: Int) {
|
||||||
instance.reconnect(tick)
|
instance.reconnect(tick)
|
||||||
if (MessageHandler.rcvQueue.isNotEmpty())
|
if (MessageHandler.rcvQueue.isNotEmpty())
|
||||||
logger.debug("incoming: " + MessageHandler.rcvQueue.toString())
|
println("incoming: " + MessageHandler.rcvQueue.toString())
|
||||||
val nextMessage = MessageHandler.rcvQueue.poll()
|
val nextMessage = MessageHandler.rcvQueue.poll()
|
||||||
|
|
||||||
if (nextMessage != null && nextMessage.gateway == cfg!!.connect.gateway) {
|
if (nextMessage != null && nextMessage.gateway == cfg!!.connect.gateway) {
|
||||||
|
@ -30,11 +30,11 @@ object ServerChatHandler {
|
||||||
val user = nextMessage.username
|
val user = nextMessage.username
|
||||||
val text = nextMessage.text
|
val text = nextMessage.text
|
||||||
val json = nextMessage.encode()
|
val json = nextMessage.encode()
|
||||||
logger.debug("Threw out message with unhandled event: ${nextMessage.event}")
|
println("Threw out message with unhandled event: ${nextMessage.event}")
|
||||||
logger.debug(" Message contents:")
|
println(" Message contents:")
|
||||||
logger.debug(" User: $user")
|
println(" User: $user")
|
||||||
logger.debug(" Text: $text")
|
println(" Text: $text")
|
||||||
logger.debug(" JSON: $json")
|
println(" JSON: $json")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.logger
|
//import matterlink.logger
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object BridgeCommandRegistry {
|
object BridgeCommandRegistry {
|
||||||
|
@ -23,7 +23,7 @@ object BridgeCommandRegistry {
|
||||||
|
|
||||||
fun register(cmd: IBridgeCommand): Boolean {
|
fun register(cmd: IBridgeCommand): Boolean {
|
||||||
if (cmd.name.isBlank() || commandMap.containsKey(cmd.name)) {
|
if (cmd.name.isBlank() || commandMap.containsKey(cmd.name)) {
|
||||||
logger.error("Failed to register command: '${cmd.name}'")
|
System.out.println("Failed to register command: '${cmd.name}'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
commandMap[cmd.name] = cmd
|
commandMap[cmd.name] = cmd
|
||||||
|
|
|
@ -2,7 +2,7 @@ package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import matterlink.bridge.ApiMessage
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandler
|
||||||
import matterlink.logger
|
//import matterlink.logger
|
||||||
|
|
||||||
object ChatHandler {
|
object ChatHandler {
|
||||||
fun handleChat(user: String, msg: String) {
|
fun handleChat(user: String, msg: String) {
|
||||||
|
@ -12,7 +12,7 @@ object ChatHandler {
|
||||||
username = user,
|
username = user,
|
||||||
text = message
|
text = message
|
||||||
))
|
))
|
||||||
else -> logger.warn("dropped blank message by '$user'")
|
else -> println("WARN: dropped blank message by '$user'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue