Added submodule api

This commit is contained in:
nikky 2018-05-08 00:45:34 +02:00
parent 10ac3bf92b
commit 1522269e44
33 changed files with 147 additions and 454 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
# Created by https://www.gitignore.io/api/gradle,kotlin,intellij+iml
### Intellij ###

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "api"]
path = api
url = https://github.com/NikkyAI/MatterLinkApi.git

View File

@ -31,14 +31,8 @@ dependencies {
shadowJar {
classifier ''
relocate "org.apache.http", "matterlink.repack.org.apache.http"
relocate "org.apache.commons.logging", "matterlink.repack.org.apache.commons.logging"
dependencies {
include(project(":core"))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3'))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'))
include(dependency(group: 'commons-logging', name: 'commons-logging', version: '1.1.3'))
}
exclude 'dummyThing'

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.bridge.USER_ACTION
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -30,14 +30,8 @@ dependencies {
shadowJar {
classifier ''
relocate "org.apache.http", "matterlink.repack.org.apache.http"
relocate "org.apache.commons.logging", "matterlink.repack.org.apache.commons.logging"
dependencies {
include(project(":core"))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3'))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'))
include(dependency(group: 'commons-logging', name: 'commons-logging', version: '1.1.3'))
}
exclude 'dummyThing'

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.bridge.USER_ACTION
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -30,15 +30,9 @@ dependencies {
shadowJar {
classifier ''
relocate "org.apache.http", "matterlink.repack.org.apache.http"
relocate "org.apache.commons.logging", "matterlink.repack.org.apache.commons.logging"
dependencies {
include(project(":core"))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3'))
include(dependency(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'))
include(dependency(group: 'commons-logging', name: 'commons-logging', version: '1.1.3'))
}
}
exclude 'dummyThing'
}

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.bridge.USER_ACTION
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -42,7 +42,7 @@ object MatterLink : IMatterLink() {
@Mod.EventHandler
fun serverAboutToStart(event: FMLServerAboutToStartEvent) {
// MessageHandler.start(clear = true)
// MessageHandlerInst.start(clear = true)
}
@Mod.EventHandler

View File

@ -38,7 +38,7 @@ minecraft {
srgExtra "PK: kotlin matterlink/repack/kotlin"
srgExtra "PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations"
srgExtra "PK: org/apache/http matterlink/repack/org/apache/http"
// srgExtra "PK: org/apache/http matterlink/repack/org/apache/http"
//srgExtra "PK: org/apache/commons matterlink/repack/org/apache/commons"
srgExtra "PK: org/intellij matterlink/repack/org/intellij"
}

View File

@ -3,7 +3,7 @@ package matterlink
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.PlayerEvent
import cpw.mods.fml.common.gameevent.TickEvent
import matterlink.bridge.USER_ACTION
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

5
Jenkinsfile vendored
View File

@ -1,6 +1,11 @@
pipeline {
agent any
stages {
stage("init") {
steps {
sh 'git submodule update --init --recursive'
}
}
stage("1.7.10") {
steps {
sh './gradlew :1.7.10:setupCiWorkspace'

1
api Submodule

@ -0,0 +1 @@
Subproject commit 444536373a5fa091c9254a433472971a5b5cc342

View File

@ -17,10 +17,9 @@ repositories {
}
dependencies {
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'
compile project(':api')
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'com.google.code.gson', name: 'gson', version: '+'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: project.kotlin_version
}

View File

@ -1,9 +1,10 @@
package matterlink
import matterlink.bridge.MessageHandler
import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.IMinecraftCommandSender
import matterlink.config.cfg
import matterlink.update.UpdateChecker
lateinit var instance: IMatterLink
@ -16,22 +17,35 @@ abstract class IMatterLink {
abstract fun wrappedSendToPlayers(msg: String)
fun start() {
MessageHandlerInst.setLogger({ level, msg ->
when (level) {
"FATAL" -> fatal(msg)
"ERROR" -> error(msg)
"WARN" -> warn(msg)
"INFO" -> info(msg)
"DEBUG" -> debug(msg)
"TRACE" -> trace(msg)
}
})
serverStartTime = System.currentTimeMillis()
MessageHandler.start(clear = true, firstRun = true, message = "Server started, connecting to matterbridge API")
if (cfg.connect.autoConnect)
MessageHandlerInst.start("Server started, connecting to matterbridge API", true)
UpdateChecker.run()
}
fun stop() {
MessageHandler.stop(message = "Server shutting down, disconnecting from matterbridge API")
MessageHandlerInst.stop("Server shutting down, disconnecting from matterbridge API")
}
abstract fun log(level: String, formatString: String, vararg data: Any)
fun fatal(formatString: String, vararg data: Any) = log("^FATAL", formatString, *data)
fun fatal(formatString: String, vararg data: Any) = log("FATAL", formatString, *data)
fun error(formatString: String, vararg data: Any) = log("ERROR", formatString, *data)
fun warn(formatString: String, vararg data: Any) = log("WARN", formatString, *data)
fun info(formatString: String, vararg data: Any) = log("INFO", formatString, *data)
fun debug(formatString: String, vararg data: Any) {
if (cfg.debug.logLevel == "DEBUG" || cfg.debug.logLevel == "TRACE")
log("INFO", "DEBUG: " + formatString.replace("\n", "\nDEBUG: "), *data)

View File

@ -1,52 +0,0 @@
package matterlink.bridge
import com.google.gson.Gson
import matterlink.antiping
import matterlink.config.cfg
import matterlink.mapFormat
const val USER_ACTION: String = "user_action"
const val JOIN_LEAVE: String = "join_leave"
data class ApiMessage(
val username: String = cfg.outgoing.systemUser,
val text: String = "",
val gateway: String = cfg.connect.gateway,
val channel: String = "",
val userid: String = "",
val avatar: String = "",
val account: String = "",
val event: String = "",
val protocol: String = "",
// val timestamp: Date,
val id: String = ""
// val Extra: Any? = null
) {
companion object {
val gson = Gson()
fun decode(json: String): ApiMessage {
return gson.fromJson(json, ApiMessage::class.java)
}
}
fun encode(): String {
return gson.toJson(this)
}
fun format(fmt: String): String {
return fmt.mapFormat(
mapOf(
"{username}" to username,
"{text}" to text,
"{gateway}" to gateway,
"{channel}" to channel,
"{protocol}" to protocol,
"{username:antiping}" to username.antiping
)
)
}
}

View File

@ -1,173 +0,0 @@
package matterlink.bridge
import matterlink.config.cfg
import matterlink.instance
import matterlink.stackTraceString
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpRequestBase
import org.apache.http.impl.client.HttpClients
import java.io.InputStream
import java.net.SocketException
import java.net.UnknownHostException
import java.util.concurrent.ConcurrentLinkedQueue
const val BUFFER_SIZE = 1000
/**
* adds the correct headers for MatterBridge authorization
*/
fun HttpRequestBase.authorize() {
if (cfg.connect.authToken.isNotEmpty() && getHeaders("Authorization").isEmpty())
setHeader("Authorization", "Bearer " + cfg.connect.authToken)
}
class HttpStreamConnection(private val rcvQueue: ConcurrentLinkedQueue<ApiMessage>,
private val clear: Boolean = true,
private val messageHandler: MessageHandler
) : Thread() {
var connected = false
private set
var connecting = false
private set
var cancelled: Boolean = false
private set
init {
name = "MsgRcvThread"
}
private fun onClose() {
instance.warn("Bridge connection closed!")
connected = false
connecting = false
}
private fun setSuccess(success: Boolean) {
connecting = false
if (success) {
instance.info("connected successfully")
messageHandler.connectErrors = 0
messageHandler.reconnectCoodown = 0
connected = true
} else {
messageHandler.reconnectCoodown = messageHandler.connectErrors
messageHandler.connectErrors++
connected = false
instance.warn("connectErrors: ${messageHandler.connectErrors}")
}
}
private val client = HttpClients.createDefault()
private var stream: InputStream? = null
val get = HttpGet(cfg.connect.url + "/api/stream").apply {
authorize()
}
private val clearGet = HttpGet(cfg.connect.url + "/api/messages").apply {
authorize()
}
override fun run() {
try {
instance.info("Attemping to open Bridge Connection")
if (clear) {
val r = client.execute(clearGet)
r.entity.content.bufferedReader().forEachLine {
instance.debug("skipping $it")
}
//connection was not refused, url and token should be correct
setSuccess(true)
}
val response = client.execute(get)
if (response.statusLine.statusCode != 200) {
instance.error("Bridge Connection rejected... status code ${response.statusLine.statusCode}")
setSuccess(false) //TODO: pass message
onClose()
when (response.statusLine.statusCode) {
400 -> {
instance.warn("Missing token, please use /bridge reload after entering correct information")
messageHandler.enabled = false
}
401 -> {
instance.warn("Incorrect token, please use /bridge reload after entering correct information")
messageHandler.enabled = false
}
}
return
} else {
instance.debug("Bridge Connection accepted")
setSuccess(true) //TODO: pass message
}
val content = response.entity.content.buffered()
stream = content
var buffer = ""
val buf = ByteArray(BUFFER_SIZE)
instance.info("initialized buffer")
while (!get.isAborted) {
val chars = content.read(buf)
if (chars > 0) {
buffer += String(buf.dropLast(buf.count() - chars).toByteArray())
instance.trace(buffer)
while (buffer.contains("\n")) {
val line = buffer.substringBefore("\n")
buffer = buffer.substringAfter("\n")
rcvQueue.add(
ApiMessage.decode(line)
)
}
} else if (chars < 0) {
break
}
}
instance.debug("closing stream")
content.close()
} catch (e: SocketException) {
instance.error(e.stackTraceString)
if (!cancelled) {
instance.error("Bridge Connection interrupted...")
setSuccess(false)
}
} catch (e: UnknownHostException) {
instance.error(e.message ?: e.stackTraceString)
// instance.error(e.stackTraceString())
setSuccess(false)
} finally {
instance.debug("thread finished")
onClose()
}
return
}
fun open() {
if (!isAlive) {
connecting = true
super.start()
// MessageHandler.transmit(ApiMessage(text="bridge connected", username="Server"))
}
if (isAlive) {
instance.info("Bridge is connecting")
}
}
fun close() {
instance.info("Closing bridge connection...")
// MessageHandler.transmit(ApiMessage(text="bridge closing", username="Server"))
try {
cancelled = true
get.abort()
join()
} catch (e: SocketException) {
instance.error("exception: $e")
}
}
}

View File

@ -1,127 +0,0 @@
package matterlink.bridge
import matterlink.config.cfg
import matterlink.instance
import matterlink.update.UpdateChecker
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
import java.io.IOException
import java.util.concurrent.ConcurrentLinkedQueue
object MessageHandler {
var enabled: Boolean = false
private var sendErrors = 0
var connectErrors = 0
var reconnectCoodown = 0
private var streamConnection: HttpStreamConnection
var rcvQueue = ConcurrentLinkedQueue<ApiMessage>()
private set
val connected get() = streamConnection.connected
init {
//initialized here so we can make sure rcvQueue is never null
streamConnection = createThread()
}
private fun createThread(clear: Boolean = true): HttpStreamConnection {
return HttpStreamConnection(
rcvQueue,
clear,
this
)
}
fun transmit(msg: ApiMessage) {
if ((streamConnection.connected || streamConnection.connecting) && streamConnection.isAlive) {
instance.debug("Transmitting: " + msg)
transmitMessage(msg)
}
}
fun stop(message: String?) {
if (message != null && cfg.outgoing.announceDisconnect) {
transmit(ApiMessage(
text = message
))
}
enabled = false
streamConnection.close()
}
fun start(message: String?, clear: Boolean = true, firstRun: Boolean = false) {
enabled = when {
firstRun -> cfg.connect.autoConnect
else -> true
}
if (!connected) {
streamConnection = createThread(clear)
}
if (enabled) {
streamConnection.open()
}
if (message != null && cfg.outgoing.announceConnect) {
transmit(ApiMessage(
text = message //?: "Connected to matterbridge API"
))
}
if (firstRun) {
UpdateChecker.run()
}
}
private fun transmitMessage(message: ApiMessage) {
try {
//open a connection
val client = HttpClients.createDefault()
val post = HttpPost(cfg.connect.url + "/api/message")
val json = message.encode()
instance.trace("Transmitting $json")
post.entity = StringEntity(json, ContentType.APPLICATION_JSON)
post.authorize()
val response = client.execute(post)
val code = response.statusLine.statusCode
if (code != 200) {
instance.error("Server returned $code for $post")
sendErrors++
if (sendErrors > 5) {
instance.error("Caught too many errors, closing bridge")
stop("Interrupting Connection to matterbridge API due status code $code")
}
}
sendErrors = 0
} catch (e: IOException) {
instance.error("sending message caused $e")
sendErrors++
if (sendErrors > 5) {
instance.error("Caught too many errors, closing bridge")
stop("Interrupting connection to matterbridge API, too many errors trying to send message")
}
}
}
fun checkConnection() {
if (enabled && !streamConnection.connected && !streamConnection.connecting) {
if (connectErrors >= 10) {
instance.fatal("Caught too many errors, closing bridge")
stop("Interrupting connection to matterbridge API due to accumulated connection errors")
return
}
if (reconnectCoodown <= 0) {
instance.info("Trying to reconnect")
MessageHandler.start(clear = false, message = "Reconnecting to matterbridge API after connection error")
} else {
reconnectCoodown--
}
}
}
}

View File

@ -0,0 +1,21 @@
package matterlink.bridge
import matterlink.antiping
import matterlink.api.ApiMessage
import matterlink.api.MessageHandler
import matterlink.mapFormat
object MessageHandlerInst : MessageHandler()
fun ApiMessage.format(fmt: String): String {
return fmt.mapFormat(
mapOf(
"{username}" to username,
"{text}" to text,
"{gateway}" to gateway,
"{channel}" to channel,
"{protocol}" to protocol,
"{username:antiping}" to username.antiping
)
)
}

View File

@ -1,6 +1,7 @@
package matterlink.bridge
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.format
import matterlink.config.cfg
import matterlink.instance
@ -10,9 +11,9 @@ object ServerChatHandler {
* This method must be called every server tick with no arguments.
*/
fun writeIncomingToChat() {
if (MessageHandler.rcvQueue.isNotEmpty())
instance.debug("incoming: " + MessageHandler.rcvQueue.toString())
val nextMessage = MessageHandler.rcvQueue.poll()
if (MessageHandlerInst.queue.isNotEmpty())
instance.debug("incoming: " + MessageHandlerInst.queue.toString())
val nextMessage = MessageHandlerInst.queue.poll()
if (nextMessage != null && nextMessage.gateway == cfg.connect.gateway) {
if (!nextMessage.text.isBlank()) {

View File

@ -1,6 +1,6 @@
package matterlink.bridge.command
import matterlink.bridge.ApiMessage
import matterlink.api.ApiMessage
import matterlink.config.CommandConfig
import matterlink.config.PermissionConfig
import matterlink.config.cfg

View File

@ -1,7 +1,7 @@
package matterlink.bridge.command
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.handlers.TickHandler
import matterlink.instance
import matterlink.lazyFormat
@ -28,7 +28,9 @@ data class CustomCommand(
}
if (!canExecute(userId, server)) {
MessageHandler.transmit(ApiMessage(text = "$user is not permitted to perform command: $alias"))
MessageHandlerInst.transmit(ApiMessage()
.setText("$user is not permitted to perform command: $alias")
)
return false
}
@ -42,7 +44,9 @@ data class CustomCommand(
commandSender.execute("$execute $args") || commandSender.reply.isNotBlank()
}
CommandType.RESPONSE -> {
MessageHandler.transmit(ApiMessage(text = response.lazyFormat(getReplacements(user, userId, server, args))))
MessageHandlerInst.transmit(ApiMessage()
.setText(response.lazyFormat(getReplacements(user, userId, server, args)))
)
true
}
}

View File

@ -1,7 +1,7 @@
package matterlink.bridge.command
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
object HelpCommand : IBridgeCommand {
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
@ -15,7 +15,9 @@ object HelpCommand : IBridgeCommand {
"$it: ${BridgeCommandRegistry.getHelpString(it)}"
}
}
MessageHandler.transmit(ApiMessage(text = msg))
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
)
return true
}

View File

@ -1,7 +1,7 @@
package matterlink.bridge.command
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
abstract class IMinecraftCommandSender(val user: String, val userId: String, val server: String) {
/**
@ -23,8 +23,8 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
fun sendReply(text: String) {
reply = text
MessageHandler.transmit(ApiMessage(
text = text
))
MessageHandlerInst.transmit(ApiMessage()
.setText(text)
)
}
}

View File

@ -1,6 +1,6 @@
package matterlink.command
import matterlink.bridge.MessageHandler
import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.config.cfg
@ -16,18 +16,20 @@ object CommandCore {
return when (cmd) {
"connect" -> {
MessageHandler.start(message = "Bridge connected by console")
MessageHandlerInst.start( "Bridge connected by console", true)
"Attempting bridge connection!"
}
"disconnect" -> {
MessageHandler.stop(message = "Bridge disconnected by console")
MessageHandlerInst.stop("Bridge disconnected by console")
"Bridge disconnected!"
}
"reload" -> {
if (MessageHandler.connected) MessageHandler.stop(message = "Bridge restarting (reload command issued by console)")
// if (MessageHandlerInst.connected)
MessageHandlerInst.stop("Bridge restarting (reload command issued by console)")
cfg = cfg.load()
BridgeCommandRegistry.reloadCommands()
if (!MessageHandler.connected) MessageHandler.start(message = "Bridge reconnected")
// if (!MessageHandlerInst.connected)
MessageHandlerInst.start("Bridge reconnected", false)
"Bridge config reloaded!"
}
else -> {

View File

@ -1,5 +1,6 @@
package matterlink.config
import matterlink.bridge.MessageHandlerInst
import java.io.File
import java.util.regex.Pattern
@ -27,7 +28,8 @@ abstract class BaseConfig(rootDir: File) {
val url: String = "http://localhost:4242",
val authToken: String = "",
val gateway: String = "minecraft",
val autoConnect: Boolean = true
val autoConnect: Boolean = true,
val reconnectWait: Long = 500
)
data class DebugOptions(
@ -296,6 +298,17 @@ abstract class BaseConfig(rootDir: File) {
"Enable Update checking"
)
)
MessageHandlerInst.config.url = connect.url
MessageHandlerInst.config.token = connect.authToken
MessageHandlerInst.config.gateway = connect.gateway
MessageHandlerInst.config.reconnectWait = connect.reconnectWait
MessageHandlerInst.config.systemUser = outgoing.systemUser
MessageHandlerInst.config.announceConnect = outgoing.announceConnect
MessageHandlerInst.config.announceDisconnect = outgoing.announceDisconnect
}
abstract fun load(): BaseConfig

View File

@ -1,18 +1,18 @@
package matterlink.handlers
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.instance
object ChatProcessor {
fun sendToBridge(user: String, msg: String, event: String) {
val message = msg.trim()
when {
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
username = user,
text = message,
event = event
))
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage()
.setUsername(user)
.setText(message)
.setEvent(event)
)
else -> instance.warn("WARN: dropped blank message by '$user'")
}
}

View File

@ -1,8 +1,8 @@
package matterlink.handlers
import matterlink.antiping
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import java.util.*
@ -22,9 +22,9 @@ object DeathHandler {
val damageEmoji = emojis[random.nextInt(emojis.size)]
msg += " $damageEmoji"
}
MessageHandler.transmit(ApiMessage(
text = msg
))
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
)
}
}
}

View File

@ -1,9 +1,9 @@
package matterlink.handlers
import matterlink.antiping
import matterlink.bridge.ApiMessage
import matterlink.bridge.JOIN_LEAVE
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.api.ApiMessage.JOIN_LEAVE
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import matterlink.mapFormat
@ -16,10 +16,10 @@ object JoinLeaveHandler {
"{username:antiping}" to player.antiping
)
)
MessageHandler.transmit(ApiMessage(
text = msg,
event = JOIN_LEAVE
))
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
.setEvent(ApiMessage.JOIN_LEAVE)
)
}
}
@ -31,10 +31,10 @@ object JoinLeaveHandler {
"{username:antiping}" to player.antiping
)
)
MessageHandler.transmit(ApiMessage(
text = msg,
event = JOIN_LEAVE
))
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
.setEvent(JOIN_LEAVE)
)
}
}
}

View File

@ -1,8 +1,8 @@
package matterlink.handlers
import matterlink.antiping
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
object ProgressHandler {
@ -10,8 +10,8 @@ object ProgressHandler {
fun handleProgress(name: String, message: String, display: String) {
if (!cfg.outgoing.advancements) return
val usr = name.antiping
MessageHandler.transmit(ApiMessage(
text = "$usr $message $display"
))
MessageHandlerInst.transmit(ApiMessage()
.setText("$usr $message $display")
)
}
}

View File

@ -1,6 +1,6 @@
package matterlink.handlers
import matterlink.bridge.MessageHandler
import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.ServerChatHandler
import matterlink.update.UpdateChecker
@ -17,7 +17,7 @@ object TickHandler {
fun handleTick() {
tickCounter++
if (tickCounter % 100 == 0) {
MessageHandler.checkConnection()
MessageHandlerInst.checkConnection()
}
ServerChatHandler.writeIncomingToChat()

View File

@ -2,14 +2,13 @@ package matterlink.update
import com.google.gson.FieldNamingPolicy
import com.google.gson.GsonBuilder
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import matterlink.instance
import org.apache.http.HttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClients
import java.io.BufferedReader
import java.net.HttpURLConnection
import java.net.URL
class UpdateChecker : Thread() {
companion object {
@ -40,18 +39,19 @@ class UpdateChecker : Thread() {
instance.info("Checking for new versions...")
val client = HttpClients.createDefault()
val request = HttpGet("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323")
val url = URL("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323")
val con = url.openConnection() as HttpURLConnection
with(instance) {
val useragent = "MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)"
instance.debug("setting User-Agent: '$useragent'")
request.setHeader("User-Agent", useragent)
con.setRequestProperty("User-Agent", useragent)
}
val response: HttpResponse = client.execute(request)
val apiUpdateList = if (200 == response.statusLine.statusCode) { //HTTP 200 OK
val buffer: BufferedReader = response.entity.content.bufferedReader()
con.connect()
val apiUpdateList = if (200 == con.responseCode) { //HTTP 200 OK
val buffer: BufferedReader = con.inputStream.bufferedReader()
//put all of the buffer content onto the string
val content = buffer.readText()
@ -108,9 +108,8 @@ class UpdateChecker : Thread() {
}
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
MessageHandler.transmit(ApiMessage(
username = cfg.outgoing.systemUser,
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
))
MessageHandlerInst.transmit(ApiMessage()
.setText("MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}")
)
}
}

View File

@ -1,2 +1,2 @@
rootProject.name = 'MatterLink'
include 'core', '1.12.2', '1.11.2', '1.10.2', '1.7.10'
include 'core', 'api', '1.12.2', '1.11.2', '1.10.2', '1.7.10'