Compare commits
85 Commits
Author | SHA1 | Date |
---|---|---|
|
dd0626b8e9 | |
|
eda95f3dfe | |
|
8df4024320 | |
|
e561423884 | |
|
b12704d507 | |
|
43ce9491b9 | |
|
e506f14f76 | |
|
e410515e05 | |
|
4392b442da | |
|
ecbb95391f | |
|
05ed3b4a9b | |
|
fe9cb31d72 | |
|
ef66087044 | |
|
4ce29f0eb6 | |
|
a0b0e3d24d | |
|
04bc439880 | |
|
d4802d372f | |
|
a12a9ae74f | |
|
4d854e5af8 | |
|
1bcafb47e1 | |
|
16c66782c6 | |
|
a2a24c6ed9 | |
|
2091d59219 | |
|
f1cc1349ef | |
|
34887a833c | |
|
3082d3e592 | |
|
79c9ac1572 | |
|
7818afc920 | |
|
e30e8132ca | |
|
6cdd7ade7c | |
|
910d2fc12b | |
|
ac9066225d | |
|
8115bada4f | |
|
e73255c8fc | |
|
a9838339d6 | |
|
ad3862f14a | |
|
43d6589572 | |
|
619e0541d7 | |
|
75a64e49ad | |
|
58ff1a3d8f | |
|
93c86463c4 | |
|
83501c867f | |
|
4627a60c9d | |
|
42dcd2c543 | |
|
13a607fcd1 | |
|
0057b3037b | |
|
254c990d76 | |
|
edbac3dfaf | |
|
c326ca2b48 | |
|
510123b6f5 | |
|
66229f4308 | |
|
0ebb89cfa8 | |
|
19e4136d88 | |
|
35d5865e5d | |
|
1356e3682f | |
|
88bee22010 | |
|
602762f371 | |
|
33c94a589c | |
|
3a79834e4c | |
|
5eb79935ba | |
|
6af52cc58e | |
|
f24ba763ac | |
|
240bff1677 | |
|
e84f616d9b | |
|
166fa8a6e1 | |
|
ff36de2446 | |
|
6cab3c9838 | |
|
451de594cd | |
|
9c52df1f98 | |
|
fcd1a148a2 | |
|
0429407547 | |
|
cee1673728 | |
|
e652a27a06 | |
|
dd07bdd386 | |
|
68144ae512 | |
|
25627c138a | |
|
41454b533d | |
|
07bc1736e6 | |
|
1400627187 | |
|
fd7fd69306 | |
|
c3b6459738 | |
|
1522269e44 | |
|
10ac3bf92b | |
|
3de56755be | |
|
928576c64b |
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/gradle,kotlin,intellij+iml
|
# Created by https://www.gitignore.io/api/gradle,kotlin,intellij+iml
|
||||||
|
|
||||||
### Intellij ###
|
### Intellij ###
|
||||||
|
@ -88,10 +87,6 @@ gradle-app.setting
|
||||||
# Cache of project
|
# Cache of project
|
||||||
.gradletasknamecache
|
.gradletasknamecache
|
||||||
|
|
||||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
|
||||||
# gradle/wrapper/gradle-wrapper.properties
|
|
||||||
|
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/gradle,kotlin,intellij+iml
|
# End of https://www.gitignore.io/api/gradle,kotlin,intellij+iml
|
||||||
|
|
||||||
### MatterLink ###
|
### MatterLink ###
|
||||||
|
@ -103,3 +98,5 @@ run/
|
||||||
|
|
||||||
\.floo
|
\.floo
|
||||||
\.flooignore
|
\.flooignore
|
||||||
|
|
||||||
|
bugreport/
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "Jankson"]
|
||||||
|
path = Jankson
|
||||||
|
url = https://github.com/falkreon/Jankson.git
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
|
"java.home": "/usr/lib/jvm/java-8-openjdk/"
|
||||||
|
}
|
|
@ -1,132 +0,0 @@
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven { url = "http://files.minecraftforge.net/maven" }
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "com.github.johnrengelman.shadow" version "1.2.4"
|
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.10'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
|
|
||||||
version = project.mc_version + "-" + project.mod_version
|
|
||||||
|
|
||||||
archivesBaseName = project.mod_name
|
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '1.8'
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile project(':core')
|
|
||||||
compile group: "net.shadowfacts", name: "Forgelin", version: project.forgelin_version
|
|
||||||
}
|
|
||||||
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = project.mc_version + "-" + project.forge_version
|
|
||||||
runDir = "run"
|
|
||||||
|
|
||||||
mappings = project.mcp_mappings
|
|
||||||
}
|
|
||||||
|
|
||||||
compileKotlin.doFirst {
|
|
||||||
def target = "src/main/kotlin/matterlink/gen"
|
|
||||||
copy {
|
|
||||||
from("src/templates/kotlin/matterlink/Constants.kt")
|
|
||||||
into(target)
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match:'@MODVERSION@', replace: project.mod_version, flags:'g', byline:true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match:'@MCVERSION@', replace: project.mc_version, flags:'g', byline:true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match:'@FORGELIN-VERSION@', replace: project.forgelin_version, flags:'g', byline:true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match:'@FORGE-VERSION@', replace: project.forge_version, flags:'g', byline:true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
|
||||||
// this will ensure that this task is redone when the versions change.
|
|
||||||
inputs.property "version", project.mod_version
|
|
||||||
inputs.property "mcversion", project.minecraft.version
|
|
||||||
|
|
||||||
// replace stuff in mcmod.info, nothing else
|
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
|
||||||
include 'mcmod.info'
|
|
||||||
|
|
||||||
// replace version and mcversion
|
|
||||||
expand 'version': project.mod_version, 'mcversion': project.minecraft.version
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
|
||||||
exclude 'mcmod.info'
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceJar {
|
|
||||||
classifier 'sources'
|
|
||||||
// copy all the minecraftforge specific classes
|
|
||||||
from sourceSets.main.allSource
|
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
|
||||||
from (project(":core").sourceSets.main.allSource) {
|
|
||||||
exclude 'mcmod.info'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
reobf {
|
|
||||||
shadowJar { mappingType = 'SEARGE' }
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.shadowJar.finalizedBy reobfShadowJar
|
|
||||||
|
|
||||||
curseforge {
|
|
||||||
if (project.hasProperty('CURSEFORGE_API_TOKEN') && project.hasProperty('release')) {
|
|
||||||
apiKey = CURSEFORGE_API_TOKEN
|
|
||||||
}
|
|
||||||
project {
|
|
||||||
id = project.curse_id
|
|
||||||
releaseType = project.curse_release_type
|
|
||||||
if (project.hasProperty('changelog_file')) {
|
|
||||||
println("changelog = $changelog_file")
|
|
||||||
changelogType = "markdown"
|
|
||||||
changelog = file(changelog_file)
|
|
||||||
}
|
|
||||||
relations {
|
|
||||||
requiredLibrary 'shadowfacts-forgelin'
|
|
||||||
}
|
|
||||||
mainArtifact(shadowJar) {
|
|
||||||
displayName = "MatterLink $version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
mc_version = 1.10.2
|
|
||||||
mcp_mappings = stable_29
|
|
||||||
forge_version = 12.18.3.2185
|
|
|
@ -1,107 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.bridge.USER_ACTION
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import matterlink.handlers.*
|
|
||||||
import net.minecraft.command.server.CommandBroadcast
|
|
||||||
import net.minecraft.command.server.CommandEmote
|
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
|
||||||
import net.minecraft.server.dedicated.DedicatedServer
|
|
||||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
|
||||||
import net.minecraftforge.event.CommandEvent
|
|
||||||
import net.minecraftforge.event.ServerChatEvent
|
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
|
||||||
import net.minecraftforge.event.entity.player.AchievementEvent
|
|
||||||
import net.minecraftforge.fml.common.Mod
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent
|
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
object EventHandler {
|
|
||||||
|
|
||||||
//MC-VERSION & FORGE DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun progressEvent(e: AchievementEvent) {
|
|
||||||
val achievement = e.achievement
|
|
||||||
val entityPlayer = e.entityPlayer as? EntityPlayerMP ?: return
|
|
||||||
val statFile = entityPlayer.statFile
|
|
||||||
|
|
||||||
if (!statFile.canUnlockAchievement(achievement) || statFile.hasAchievementUnlocked(achievement)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ProgressHandler.handleProgress(
|
|
||||||
name = e.entityPlayer.displayName.unformattedText,
|
|
||||||
message = "has earned the achievement",
|
|
||||||
display = e.achievement.statName.unformattedText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
|
||||||
ChatProcessor.sendToBridge(
|
|
||||||
user = e.player.displayName.unformattedText,
|
|
||||||
msg = e.message,
|
|
||||||
event = ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun commandEvent(e: CommandEvent) {
|
|
||||||
val sender = when {
|
|
||||||
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
|
||||||
else -> e.sender.displayName.unformattedText
|
|
||||||
}
|
|
||||||
val args = e.parameters.joinToString(" ")
|
|
||||||
val type = when {
|
|
||||||
e.command is CommandEmote -> USER_ACTION
|
|
||||||
e.command.name == "me" -> USER_ACTION
|
|
||||||
e.command is CommandBroadcast -> ""
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun deathEvent(e: LivingDeathEvent) {
|
|
||||||
if (e.entityLiving is EntityPlayer) {
|
|
||||||
DeathHandler.handleDeath(
|
|
||||||
player = e.entityLiving.displayName.unformattedText,
|
|
||||||
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
|
||||||
damageType = e.source.damageType
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
|
||||||
JoinLeaveHandler.handleJoin(e.player.displayName.unformattedText)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
|
||||||
JoinLeaveHandler.handleLeave(e.player.displayName.unformattedText)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
|
||||||
if(e.phase == TickEvent.Phase.END)
|
|
||||||
TickHandler.handleTick()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
|
||||||
import matterlink.command.CommandMatterlink
|
|
||||||
import matterlink.command.MatterLinkCommandSender
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraft.util.text.TextComponentString
|
|
||||||
import net.minecraftforge.common.ForgeVersion
|
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
|
||||||
import net.minecraftforge.fml.common.Mod
|
|
||||||
import net.minecraftforge.fml.common.event.*
|
|
||||||
import org.apache.logging.log4j.Level
|
|
||||||
import org.apache.logging.log4j.Logger
|
|
||||||
|
|
||||||
lateinit var logger: Logger
|
|
||||||
|
|
||||||
@Mod(
|
|
||||||
modid = MODID,
|
|
||||||
name = NAME, version = MODVERSION,
|
|
||||||
serverSideOnly = true,
|
|
||||||
useMetadata = true,
|
|
||||||
acceptableRemoteVersions = "*",
|
|
||||||
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter",
|
|
||||||
dependencies = DEPENDENCIES
|
|
||||||
)
|
|
||||||
object MatterLink : IMatterLink() {
|
|
||||||
init {
|
|
||||||
instance = this
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun preInit(event: FMLPreInitializationEvent) {
|
|
||||||
logger = event.modLog
|
|
||||||
logger.info("Building bridge!")
|
|
||||||
|
|
||||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun init(event: FMLInitializationEvent) {
|
|
||||||
this.registerBridgeCommands()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
|
||||||
logger.debug("Registering server commands")
|
|
||||||
event.registerServerCommand(CommandMatterlink())
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun serverStopping(event: FMLServerStoppingEvent) {
|
|
||||||
stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
override fun wrappedSendToPlayers(msg: String) {
|
|
||||||
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendChatMsg(TextComponentString(msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun log(level: String, formatString: String, vararg data: Any) =
|
|
||||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
|
||||||
|
|
||||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
|
||||||
|
|
||||||
override val mcVersion: String = MCVERSION
|
|
||||||
override val modVersion: String = MODVERSION
|
|
||||||
override val forgeVersion = ForgeVersion.getVersion()
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.config.BaseConfig
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraftforge.common.config.Configuration
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
|
||||||
init {
|
|
||||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
|
||||||
val config = Configuration(mainCfgFile)
|
|
||||||
|
|
||||||
load(
|
|
||||||
getBoolean = config::getBoolean,
|
|
||||||
getString = config::getString,
|
|
||||||
getStringValidated = config::getString,
|
|
||||||
getStringValidValues = config::getString,
|
|
||||||
getStringList = config::getStringList,
|
|
||||||
addCustomCategoryComment = config::addCustomCategoryComment
|
|
||||||
)
|
|
||||||
if (config.hasChanged()) config.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package matterlink.command
|
|
||||||
|
|
||||||
import net.minecraft.command.CommandBase
|
|
||||||
import net.minecraft.command.ICommandSender
|
|
||||||
import net.minecraft.command.WrongUsageException
|
|
||||||
import net.minecraft.server.MinecraftServer
|
|
||||||
import net.minecraft.util.text.TextComponentString
|
|
||||||
|
|
||||||
|
|
||||||
class CommandMatterlink : CommandBase() {
|
|
||||||
override fun getName(): String {
|
|
||||||
return CommandCore.getName()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getUsage(sender: ICommandSender): String {
|
|
||||||
return CommandCore.getUsage()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAliases(): List<String> {
|
|
||||||
return CommandCore.getAliases()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) {
|
|
||||||
if (args.isEmpty()) {
|
|
||||||
throw WrongUsageException("Invalid command! Valid uses: ${this.getUsage(sender)}")
|
|
||||||
}
|
|
||||||
|
|
||||||
val reply = CommandCore.execute(args)
|
|
||||||
|
|
||||||
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
|
||||||
sender.sendMessage(TextComponentString(reply))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,130 +0,0 @@
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven { url = "http://files.minecraftforge.net/maven" }
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "com.github.johnrengelman.shadow" version "1.2.4"
|
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.10'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
|
|
||||||
version = project.mc_version + "-" + project.mod_version
|
|
||||||
|
|
||||||
archivesBaseName = project.mod_name
|
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '1.8'
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile project(':core')
|
|
||||||
compile group: "net.shadowfacts", name: "Forgelin", version: project.forgelin_version
|
|
||||||
}
|
|
||||||
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = project.mc_version + "-" + project.forge_version
|
|
||||||
runDir = "run"
|
|
||||||
|
|
||||||
mappings = project.mcp_mappings
|
|
||||||
}
|
|
||||||
|
|
||||||
compileKotlin.doFirst {
|
|
||||||
def target = "src/main/kotlin/matterlink/gen"
|
|
||||||
copy {
|
|
||||||
from("src/templates/kotlin/matterlink/Constants.kt")
|
|
||||||
into(target)
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match: '@MODVERSION@', replace: project.mod_version, flags: 'g', byline: true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match: '@MCVERSION@', replace: project.mc_version, flags: 'g', byline: true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match: '@FORGELIN-VERSION@', replace: project.forgelin_version, flags: 'g', byline: true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
ant.replaceregexp(match: '@FORGE-VERSION@', replace: project.forge_version, flags: 'g', byline: true) {
|
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
|
||||||
// this will ensure that this task is redone when the versions change.
|
|
||||||
inputs.property "version", project.mod_version
|
|
||||||
inputs.property "mcversion", project.minecraft.version
|
|
||||||
|
|
||||||
// replace stuff in mcmod.info, nothing else
|
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
|
||||||
include 'mcmod.info'
|
|
||||||
|
|
||||||
// replace version and mcversion
|
|
||||||
expand 'version': project.mod_version, 'mcversion': project.minecraft.version
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
|
||||||
exclude 'mcmod.info'
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceJar {
|
|
||||||
classifier 'sources'
|
|
||||||
// copy all the minecraftforge specific classes
|
|
||||||
from sourceSets.main.allSource
|
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
|
||||||
from(project(":core").sourceSets.main.allSource) {
|
|
||||||
exclude 'mcmod.info'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
reobf {
|
|
||||||
shadowJar { mappingType = 'SEARGE' }
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.shadowJar.finalizedBy reobfShadowJar
|
|
||||||
|
|
||||||
curseforge {
|
|
||||||
if (project.hasProperty('CURSEFORGE_API_TOKEN') && project.hasProperty('release')) {
|
|
||||||
apiKey = CURSEFORGE_API_TOKEN
|
|
||||||
}
|
|
||||||
project {
|
|
||||||
id = project.curse_id
|
|
||||||
releaseType = project.curse_release_type
|
|
||||||
if (project.hasProperty('changelog_file')) {
|
|
||||||
println("changelog = $changelog_file")
|
|
||||||
changelogType = "markdown"
|
|
||||||
changelog = file(changelog_file)
|
|
||||||
}
|
|
||||||
relations {
|
|
||||||
requiredLibrary 'shadowfacts-forgelin'
|
|
||||||
}
|
|
||||||
mainArtifact(shadowJar) {
|
|
||||||
displayName = "MatterLink $version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
mc_version = 1.11.2
|
|
||||||
mcp_mappings = stable_32
|
|
||||||
forge_version = 13.20.1.2386
|
|
|
@ -1,108 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.bridge.USER_ACTION
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import matterlink.handlers.*
|
|
||||||
import net.minecraft.command.server.CommandBroadcast
|
|
||||||
import net.minecraft.command.server.CommandEmote
|
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
|
||||||
import net.minecraft.server.dedicated.DedicatedServer
|
|
||||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
|
||||||
import net.minecraftforge.event.CommandEvent
|
|
||||||
import net.minecraftforge.event.ServerChatEvent
|
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
|
||||||
import net.minecraftforge.event.entity.player.AchievementEvent
|
|
||||||
import net.minecraftforge.fml.common.Mod
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent
|
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
object EventHandler {
|
|
||||||
|
|
||||||
//MC-VERSION & FORGE DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun progressEvent(e: AchievementEvent) {
|
|
||||||
val achievement = e.achievement
|
|
||||||
val entityPlayer = e.entityPlayer as? EntityPlayerMP ?: return
|
|
||||||
val statFile = entityPlayer.statFile
|
|
||||||
|
|
||||||
if (!statFile.canUnlockAchievement(achievement) || statFile.hasAchievementUnlocked(achievement)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressHandler.handleProgress(
|
|
||||||
name = e.entityPlayer.displayName.unformattedText,
|
|
||||||
message = "has earned the achievement",
|
|
||||||
display = e.achievement.statName.unformattedText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
|
||||||
ChatProcessor.sendToBridge(
|
|
||||||
user = e.player.displayName.unformattedText,
|
|
||||||
msg = e.message,
|
|
||||||
event = ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun commandEvent(e: CommandEvent) {
|
|
||||||
val sender = when {
|
|
||||||
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
|
||||||
else -> e.sender.displayName.unformattedText
|
|
||||||
}
|
|
||||||
val args = e.parameters.joinToString(" ")
|
|
||||||
val type = when {
|
|
||||||
e.command is CommandEmote -> USER_ACTION
|
|
||||||
e.command.name == "me" -> USER_ACTION
|
|
||||||
e.command is CommandBroadcast -> ""
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun deathEvent(e: LivingDeathEvent) {
|
|
||||||
if (e.entityLiving is EntityPlayer) {
|
|
||||||
DeathHandler.handleDeath(
|
|
||||||
player = e.entityLiving.displayName.unformattedText,
|
|
||||||
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
|
||||||
damageType = e.source.damageType
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
|
||||||
JoinLeaveHandler.handleJoin(e.player.displayName.unformattedText)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
|
||||||
JoinLeaveHandler.handleLeave(e.player.displayName.unformattedText)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
|
||||||
if(e.phase == TickEvent.Phase.END)
|
|
||||||
TickHandler.handleTick()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
|
||||||
import matterlink.command.CommandMatterlink
|
|
||||||
import matterlink.command.MatterLinkCommandSender
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraft.util.text.TextComponentString
|
|
||||||
import net.minecraftforge.common.ForgeVersion
|
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
|
||||||
import net.minecraftforge.fml.common.Mod
|
|
||||||
import net.minecraftforge.fml.common.event.*
|
|
||||||
import org.apache.logging.log4j.Level
|
|
||||||
import org.apache.logging.log4j.Logger
|
|
||||||
|
|
||||||
lateinit var logger: Logger
|
|
||||||
|
|
||||||
@Mod(
|
|
||||||
modid = MODID,
|
|
||||||
name = NAME, version = MODVERSION,
|
|
||||||
serverSideOnly = true,
|
|
||||||
useMetadata = true,
|
|
||||||
acceptableRemoteVersions = "*",
|
|
||||||
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter",
|
|
||||||
dependencies = DEPENDENCIES
|
|
||||||
)
|
|
||||||
object MatterLink : IMatterLink() {
|
|
||||||
init {
|
|
||||||
instance = this
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun preInit(event: FMLPreInitializationEvent) {
|
|
||||||
logger = event.modLog
|
|
||||||
logger.info("Building bridge!")
|
|
||||||
|
|
||||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun init(event: FMLInitializationEvent) {
|
|
||||||
this.registerBridgeCommands()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
|
||||||
logger.debug("Registering server commands")
|
|
||||||
event.registerServerCommand(CommandMatterlink())
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun serverStopping(event: FMLServerStoppingEvent) {
|
|
||||||
stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
override fun wrappedSendToPlayers(msg: String) {
|
|
||||||
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun log(level: String, formatString: String, vararg data: Any) =
|
|
||||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
|
||||||
|
|
||||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
|
||||||
|
|
||||||
override val mcVersion: String = MCVERSION
|
|
||||||
override val modVersion: String = MODVERSION
|
|
||||||
override val forgeVersion = ForgeVersion.getVersion()
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.config.BaseConfig
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraftforge.common.config.Configuration
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
|
||||||
init {
|
|
||||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
|
||||||
val config = Configuration(mainCfgFile)
|
|
||||||
|
|
||||||
load(
|
|
||||||
getBoolean = config::getBoolean,
|
|
||||||
getString = config::getString,
|
|
||||||
getStringValidated = config::getString,
|
|
||||||
getStringValidValues = config::getString,
|
|
||||||
getStringList = config::getStringList,
|
|
||||||
addCustomCategoryComment = config::addCustomCategoryComment
|
|
||||||
)
|
|
||||||
if (config.hasChanged()) config.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package matterlink.command
|
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraft.command.CommandResultStats
|
|
||||||
import net.minecraft.command.ICommandSender
|
|
||||||
import net.minecraft.entity.Entity
|
|
||||||
import net.minecraft.server.MinecraftServer
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Vec3d
|
|
||||||
import net.minecraft.util.text.ITextComponent
|
|
||||||
import net.minecraft.util.text.TextComponentString
|
|
||||||
import net.minecraft.world.World
|
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
|
||||||
import javax.annotation.Nonnull
|
|
||||||
|
|
||||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
|
||||||
|
|
||||||
override fun execute(cmdString: String): Boolean {
|
|
||||||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
|
||||||
this,
|
|
||||||
cmdString
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDisplayName(): ITextComponent {
|
|
||||||
return TextComponentString(user)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getName() = accountName
|
|
||||||
|
|
||||||
override fun getEntityWorld(): World {
|
|
||||||
return FMLCommonHandler.instance().minecraftServerInstance.getWorld(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canUseCommand(permLevel: Int, commandName: String): Boolean {
|
|
||||||
//we now do permissions checking on our end
|
|
||||||
return canExecute(commandName)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getServer(): MinecraftServer? {
|
|
||||||
return FMLCommonHandler.instance().minecraftServerInstance
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
|
||||||
sendReply(component!!.unformattedComponentText)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sendCommandFeedback(): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//WtfMojangWhy
|
|
||||||
override fun getPosition(): BlockPos = BlockPos.ORIGIN
|
|
||||||
|
|
||||||
override fun setCommandStat(type: CommandResultStats.Type?, amount: Int) {}
|
|
||||||
|
|
||||||
override fun getPositionVector(): Vec3d = Vec3d.ZERO
|
|
||||||
|
|
||||||
override fun getCommandSenderEntity(): Entity? = null
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
const val MODID = "matterlink"
|
|
||||||
const val NAME = "MatterLink"
|
|
||||||
const val MODVERSION = "@MODVERSION@"
|
|
||||||
const val MCVERSION = "@MCVERSION@"
|
|
||||||
const val DEPENDENCIES = "required-after:forgelin@[@FORGELIN-VERSION@,);required-after:forge@[@FORGE-VERSION@,);"
|
|
||||||
|
|
|
@ -1,64 +1,67 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url = "http://files.minecraftforge.net/maven" }
|
maven {
|
||||||
|
url = 'http://files.minecraftforge.net/maven'
|
||||||
|
}
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url = 'https://oss.sonatype.org/content/groups/public'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url = 'https://plugins.gradle.org/m2/'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
|
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '2.3-SNAPSHOT'
|
||||||
|
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: shadowVersion
|
||||||
|
classpath group: 'gradle.plugin.com.matthewprenger', name: 'CurseGradle', version: cursegradleVersion
|
||||||
|
classpath group: 'com.vanniktech', name: 'gradle-dependency-graph-generator-plugin', version: '0.5.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "com.github.johnrengelman.shadow" version "1.2.4"
|
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.10'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
apply plugin: 'com.matthewprenger.cursegradle'
|
||||||
|
apply plugin: "com.vanniktech.dependency.graph.generator"
|
||||||
|
|
||||||
version = project.mc_version + "-" + project.mod_version
|
version = project.mc_version + '-' + project.modVersion
|
||||||
|
|
||||||
archivesBaseName = project.mod_name
|
archivesBaseName = project.modName
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = '1.8'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':core')
|
compile project(':core')
|
||||||
compile group: "net.shadowfacts", name: "Forgelin", version: project.forgelin_version
|
shadow (project(path: ':core', configuration: 'shadow')) { transitive = false }
|
||||||
|
|
||||||
|
compile group: 'net.shadowfacts', name: 'Forgelin', version: project.forgelinVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
classifier ''
|
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'
|
exclude 'dummyThing'
|
||||||
|
configurations = [project.configurations.shadow]
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = project.mc_version + "-" + project.forge_version
|
version = project.mc_version + '-' + project.forge_version
|
||||||
runDir = "run"
|
runDir = 'run'
|
||||||
|
|
||||||
mappings = project.mcp_mappings
|
mappings = project.mcp_mappings
|
||||||
|
|
||||||
replaceIn 'Constants.kt'
|
replaceIn 'Constants.kt'
|
||||||
replace '@MODVERSION@', project.mod_version
|
replace '@MODVERSION@', project.modVersion
|
||||||
replace '@MCVERSION@', project.mc_version
|
replace '@MCVERSION@', project.mc_version
|
||||||
replace '@FORGELIN-VERSION@', project.forgelin_version
|
replace '@FORGELIN-VERSION@', project.forgelinVersion
|
||||||
replace '@FORGE-VERSION@', project.forge_version
|
replace '@FORGE-VERSION@', project.forge_version
|
||||||
|
replace '-1//@BUILD_NUMBER@', System.env.BUILD_NUMBER ?: -1
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
// this will ensure that this task is redone when the versions change.
|
// this will ensure that this task is redone when the versions change.
|
||||||
inputs.property "version", project.mod_version
|
inputs.property "version", project.modVersion
|
||||||
inputs.property "mcversion", project.minecraft.version
|
inputs.property "mcversion", project.minecraft.version
|
||||||
|
|
||||||
// replace stuff in mcmod.info, nothing else
|
// replace stuff in mcmod.info, nothing else
|
||||||
|
@ -66,7 +69,7 @@ processResources {
|
||||||
include 'mcmod.info'
|
include 'mcmod.info'
|
||||||
|
|
||||||
// replace version and mcversion
|
// replace version and mcversion
|
||||||
expand 'version': project.mod_version, 'mcversion': project.minecraft.version
|
expand 'version': project.modVersion, 'mcversion': project.minecraft.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
// copy everything else except the mcmod.info
|
||||||
|
@ -77,7 +80,7 @@ processResources {
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceJar {
|
sourceJar {
|
||||||
classifier 'sources'
|
classifier = 'sources'
|
||||||
// copy all the minecraftforge specific classes
|
// copy all the minecraftforge specific classes
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
|
|
||||||
|
@ -90,7 +93,6 @@ sourceJar {
|
||||||
reobf {
|
reobf {
|
||||||
shadowJar { mappingType = 'SEARGE' }
|
shadowJar { mappingType = 'SEARGE' }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.shadowJar.finalizedBy reobfShadowJar
|
tasks.shadowJar.finalizedBy reobfShadowJar
|
||||||
|
|
||||||
curseforge {
|
curseforge {
|
||||||
|
@ -98,11 +100,11 @@ curseforge {
|
||||||
apiKey = CURSEFORGE_API_TOKEN
|
apiKey = CURSEFORGE_API_TOKEN
|
||||||
}
|
}
|
||||||
project {
|
project {
|
||||||
id = project.curse_id
|
id = project.curseId
|
||||||
releaseType = project.curse_release_type
|
releaseType = project.curseReleaseType
|
||||||
if (project.hasProperty('changelog_file')) {
|
if (project.hasProperty('changelog_file')) {
|
||||||
println("changelog = $changelog_file")
|
println("changelog = $changelog_file")
|
||||||
changelogType = "markdown"
|
changelogType = 'markdown'
|
||||||
changelog = file(changelog_file)
|
changelog = file(changelog_file)
|
||||||
}
|
}
|
||||||
relations {
|
relations {
|
||||||
|
@ -113,3 +115,7 @@ curseforge {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runServer {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
mc_version = 1.12.2
|
mc_version = 1.12.2
|
||||||
mcp_mappings = snapshot_20171003
|
mcp_mappings = stable_39
|
||||||
forge_version = 14.23.1.2599
|
forge_version = 14.23.1.2599
|
|
@ -5,4 +5,4 @@ const val NAME = "MatterLink"
|
||||||
const val MODVERSION = "@MODVERSION@"
|
const val MODVERSION = "@MODVERSION@"
|
||||||
const val MCVERSION = "@MCVERSION@"
|
const val MCVERSION = "@MCVERSION@"
|
||||||
const val DEPENDENCIES = "required-after:forgelin@[@FORGELIN-VERSION@,);required-after:forge@[@FORGE-VERSION@,);"
|
const val DEPENDENCIES = "required-after:forgelin@[@FORGELIN-VERSION@,);required-after:forge@[@FORGE-VERSION@,);"
|
||||||
|
const val BUILD_NUMBER = -1//@BUILD_NUMBER@
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
import matterlink.bridge.USER_ACTION
|
import kotlinx.coroutines.runBlocking
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.handlers.*
|
import matterlink.handlers.ChatEvent
|
||||||
|
import matterlink.handlers.ChatProcessor
|
||||||
|
import matterlink.handlers.DeathHandler
|
||||||
|
import matterlink.handlers.JoinLeaveHandler
|
||||||
|
import matterlink.handlers.ProgressHandler
|
||||||
|
import matterlink.handlers.TickHandler
|
||||||
import net.minecraft.command.server.CommandBroadcast
|
import net.minecraft.command.server.CommandBroadcast
|
||||||
import net.minecraft.command.server.CommandEmote
|
import net.minecraft.command.server.CommandEmote
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.server.dedicated.DedicatedServer
|
import net.minecraft.server.dedicated.DedicatedServer
|
||||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
|
||||||
import net.minecraftforge.event.CommandEvent
|
import net.minecraftforge.event.CommandEvent
|
||||||
import net.minecraftforge.event.ServerChatEvent
|
import net.minecraftforge.event.ServerChatEvent
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
||||||
|
@ -24,56 +28,80 @@ object EventHandler {
|
||||||
//MC-VERSION & FORGE DEPENDENT
|
//MC-VERSION & FORGE DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun progressEvent(e: AdvancementEvent) {
|
fun progressEvent(e: AdvancementEvent) = runBlocking {
|
||||||
if (e.advancement.display == null) return
|
if (e.advancement.display == null) return@runBlocking
|
||||||
ProgressHandler.handleProgress(
|
ProgressHandler.handleProgress(
|
||||||
name = e.entityPlayer.displayName.unformattedText,
|
name = e.entityPlayer.displayName.unformattedText,
|
||||||
message = "has made the advancement",
|
message = "has made the advancement",
|
||||||
display = e.advancement.displayText.unformattedText
|
display = e.advancement.displayText.unformattedText,
|
||||||
|
x = e.entityPlayer.posX.toInt(),
|
||||||
|
y = e.entityPlayer.posY.toInt(),
|
||||||
|
z = e.entityPlayer.posZ.toInt(),
|
||||||
|
dimension = e.entityPlayer.dimension
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
fun chatEvent(e: ServerChatEvent) = runBlocking {
|
||||||
ChatProcessor.sendToBridge(
|
if (e.isCanceled) return@runBlocking
|
||||||
|
e.isCanceled = ChatProcessor.sendToBridge(
|
||||||
user = e.player.displayName.unformattedText,
|
user = e.player.displayName.unformattedText,
|
||||||
msg = e.message,
|
msg = e.message,
|
||||||
event = ""
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension,
|
||||||
|
event = ChatEvent.PLAIN,
|
||||||
|
uuid = e.player.gameProfile.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) = runBlocking {
|
||||||
logger.info("commandEvent ${e.sender.javaClass.simpleName}")
|
|
||||||
logger.info("commandEvent ${e.sender.javaClass.typeName}")
|
|
||||||
val sender = when {
|
val sender = when {
|
||||||
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
||||||
else -> e.sender.displayName.unformattedText
|
else -> e.sender.displayName.unformattedText
|
||||||
}
|
}
|
||||||
val args = e.parameters.joinToString(" ")
|
val args = e.parameters.joinToString(" ")
|
||||||
val type = when {
|
val type = with(e.command) {
|
||||||
e.command is CommandEmote -> USER_ACTION
|
when {
|
||||||
e.command.name == "me" -> USER_ACTION
|
this is CommandEmote || name.equals("me", true) -> ChatEvent.ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
this is CommandBroadcast || name.equals("say", true) -> ChatEvent.BROADCAST
|
||||||
else -> return
|
else -> return@runBlocking
|
||||||
}
|
}
|
||||||
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
|
}
|
||||||
|
ChatProcessor.sendToBridge(
|
||||||
|
user = sender,
|
||||||
|
msg = args,
|
||||||
|
event = type,
|
||||||
|
x = e.sender.position.x,
|
||||||
|
y = e.sender.position.y,
|
||||||
|
z = e.sender.position.z,
|
||||||
|
dimension = when {
|
||||||
|
e.sender is DedicatedServer -> null
|
||||||
|
else -> e.sender.commandSenderEntity?.dimension ?: e.sender.entityWorld.provider.dimension
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun deathEvent(e: LivingDeathEvent) {
|
fun deathEvent(e: LivingDeathEvent) = runBlocking {
|
||||||
if (e.entityLiving is EntityPlayer) {
|
if (e.entityLiving is EntityPlayer) {
|
||||||
DeathHandler.handleDeath(
|
DeathHandler.handleDeath(
|
||||||
player = e.entityLiving.displayName.unformattedText,
|
player = e.entityLiving.displayName.unformattedText,
|
||||||
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
||||||
damageType = e.source.damageType
|
damageType = e.source.damageType,
|
||||||
|
x = e.entityLiving.posX.toInt(),
|
||||||
|
y = e.entityLiving.posY.toInt(),
|
||||||
|
z = e.entityLiving.posZ.toInt(),
|
||||||
|
dimension = e.entityLiving.dimension
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,22 +109,35 @@ object EventHandler {
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) = runBlocking {
|
||||||
JoinLeaveHandler.handleJoin(e.player.displayName.unformattedText)
|
JoinLeaveHandler.handleJoin(
|
||||||
|
player = e.player.displayName.unformattedText,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) = runBlocking {
|
||||||
JoinLeaveHandler.handleLeave(e.player.displayName.unformattedText)
|
JoinLeaveHandler.handleLeave(
|
||||||
|
player = e.player.displayName.unformattedText,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
fun serverTickEvent(e: TickEvent.ServerTickEvent) = runBlocking {
|
||||||
if(e.phase == TickEvent.Phase.END)
|
if (e.phase == TickEvent.Phase.END)
|
||||||
TickHandler.handleTick()
|
TickHandler.handleTick()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,26 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import com.mojang.authlib.GameProfile
|
||||||
import matterlink.command.CommandMatterlink
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
|
import matterlink.command.AuthCommand
|
||||||
|
import matterlink.command.MatterLinkCommand
|
||||||
import matterlink.command.MatterLinkCommandSender
|
import matterlink.command.MatterLinkCommandSender
|
||||||
|
import matterlink.config.BaseConfig
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.common.ForgeVersion
|
import net.minecraftforge.common.ForgeVersion
|
||||||
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.FMLInitializationEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent
|
||||||
import org.apache.logging.log4j.Level
|
import org.apache.logging.log4j.Level
|
||||||
import org.apache.logging.log4j.Logger
|
import org.apache.logging.log4j.core.config.Configurator
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
lateinit var logger: Logger
|
|
||||||
|
|
||||||
@Mod(
|
@Mod(
|
||||||
modid = MODID,
|
modid = MODID,
|
||||||
|
@ -24,37 +32,47 @@ lateinit var logger: Logger
|
||||||
dependencies = DEPENDENCIES
|
dependencies = DEPENDENCIES
|
||||||
)
|
)
|
||||||
object MatterLink : IMatterLink() {
|
object MatterLink : IMatterLink() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
Configurator.setLevel(MODID, Level.DEBUG)
|
||||||
instance = this
|
instance = this
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun preInit(event: FMLPreInitializationEvent) {
|
fun preInit(event: FMLPreInitializationEvent) {
|
||||||
logger = event.modLog
|
logger = with(event.modLog) {
|
||||||
|
object : Logger {
|
||||||
|
override fun info(message: String) = this@with.info(message)
|
||||||
|
override fun debug(message: String) = this@with.debug(message)
|
||||||
|
override fun error(message: String) = this@with.error(message)
|
||||||
|
override fun warn(message: String) = this@with.warn(message)
|
||||||
|
override fun trace(message: String) = this@with.trace(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Building bridge!")
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun init(event: FMLInitializationEvent) {
|
fun init(event: FMLInitializationEvent) {
|
||||||
|
logger.debug("Registering bridge commands")
|
||||||
this.registerBridgeCommands()
|
this.registerBridgeCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
fun serverAboutToStart(event: FMLServerAboutToStartEvent) {
|
|
||||||
// MessageHandler.start(clear = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) {
|
||||||
logger.debug("Registering server commands")
|
logger.debug("Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(MatterLinkCommand)
|
||||||
|
event.registerServerCommand(AuthCommand)
|
||||||
|
runBlocking {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun serverStopping(event: FMLServerStoppingEvent) {
|
fun serverStopping(event: FMLServerStoppingEvent) = runBlocking {
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +81,70 @@ object MatterLink : IMatterLink() {
|
||||||
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
|
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log(level: String, formatString: String, vararg data: Any) =
|
override fun wrappedSendToPlayer(username: String, msg: String) {
|
||||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
val profile = profileByName(username) ?: run {
|
||||||
|
logger.error("cannot find player by name $username")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
logger.error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.sendMessage(TextComponentString(msg))
|
||||||
|
}
|
||||||
|
|
||||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
|
||||||
|
val profile = profileByUUID(uuid) ?: run {
|
||||||
|
logger.error("cannot find player by uuid $uuid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
logger.error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.sendMessage(TextComponentString(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isOnline(username: String) =
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.onlinePlayerNames.contains(username)
|
||||||
|
|
||||||
|
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? =
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
|
||||||
|
|
||||||
|
private fun profileByUUID(uuid: UUID): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by uuid $uuid")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun profileByName(username: String): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by username $username")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun collectPlayers(area: Area): Set<UUID> {
|
||||||
|
val players = FMLCommonHandler.instance().minecraftServerInstance.playerList.players.filter {
|
||||||
|
(area.allDimensions || area.dimensions.contains(it.dimension))
|
||||||
|
&& area.testInBounds(it.posX.toInt(), it.posY.toInt(), it.posZ.toInt())
|
||||||
|
}
|
||||||
|
return players.map { it.uniqueID }.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
|
||||||
|
|
||||||
|
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
|
||||||
|
|
||||||
|
override fun commandSenderFor(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
) = MatterLinkCommandSender(user, env, op)
|
||||||
|
|
||||||
override val mcVersion: String = MCVERSION
|
override val mcVersion: String = MCVERSION
|
||||||
override val modVersion: String = MODVERSION
|
override val modVersion: String = MODVERSION
|
||||||
|
override val buildNumber = BUILD_NUMBER
|
||||||
override val forgeVersion = ForgeVersion.getVersion()
|
override val forgeVersion = ForgeVersion.getVersion()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.config.BaseConfig
|
|
||||||
import net.minecraftforge.common.config.Configuration
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
|
||||||
init {
|
|
||||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
|
||||||
val config = Configuration(mainCfgFile)
|
|
||||||
|
|
||||||
load(
|
|
||||||
getBoolean = config::getBoolean,
|
|
||||||
getString = config::getString,
|
|
||||||
getStringValidated = config::getString,
|
|
||||||
getStringValidValues = config::getString,
|
|
||||||
getStringList = config::getStringList,
|
|
||||||
addCustomCategoryComment = config::addCustomCategoryComment
|
|
||||||
)
|
|
||||||
if (config.hasChanged()) config.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
|
||||||
}
|
|
|
@ -3,21 +3,26 @@ package matterlink.command
|
||||||
import net.minecraft.command.CommandBase
|
import net.minecraft.command.CommandBase
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.command.WrongUsageException
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
|
|
||||||
|
|
||||||
class CommandMatterlink : CommandBase() {
|
object AuthCommand : CommandBase() {
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
return CommandCore.getName()
|
return CommandCoreAuth.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUsage(sender: ICommandSender): String {
|
override fun getUsage(sender: ICommandSender): String {
|
||||||
return CommandCore.getUsage()
|
return CommandCoreAuth.usage
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAliases(): List<String> {
|
override fun getAliases(): List<String> {
|
||||||
return CommandCore.getAliases()
|
return CommandCoreAuth.aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getRequiredPermissionLevel(): Int {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) {
|
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) {
|
||||||
|
@ -25,7 +30,8 @@ class CommandMatterlink : CommandBase() {
|
||||||
throw WrongUsageException("Invalid command! Valid uses: ${this.getUsage(sender)}")
|
throw WrongUsageException("Invalid command! Valid uses: ${this.getUsage(sender)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val reply = CommandCore.execute(args)
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreAuth.execute(args, sender.name, uuid)
|
||||||
|
|
||||||
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
||||||
sender.sendMessage(TextComponentString(reply))
|
sender.sendMessage(TextComponentString(reply))
|
|
@ -1,31 +1,34 @@
|
||||||
package matterlink.command
|
package matterlink.command
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.minecraft.command.CommandBase
|
import net.minecraft.command.CommandBase
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.command.WrongUsageException
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
|
|
||||||
|
|
||||||
class CommandMatterlink : CommandBase() {
|
object MatterLinkCommand : CommandBase() {
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
return CommandCore.getName()
|
return CommandCoreML.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUsage(sender: ICommandSender): String {
|
override fun getUsage(sender: ICommandSender): String {
|
||||||
return CommandCore.getUsage()
|
return CommandCoreML.usage
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAliases(): List<String> {
|
override fun getAliases(): List<String> {
|
||||||
return CommandCore.getAliases()
|
return CommandCoreML.aliases
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) {
|
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) = runBlocking {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
throw WrongUsageException("Invalid command! Valid uses: ${this.getUsage(sender)}")
|
throw WrongUsageException("Invalid command! Valid uses: ${getUsage(sender)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val reply = CommandCore.execute(args)
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreML.execute(args, sender.name, uuid)
|
||||||
|
|
||||||
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
||||||
sender.sendMessage(TextComponentString(reply))
|
sender.sendMessage(TextComponentString(reply))
|
|
@ -1,5 +1,7 @@
|
||||||
package matterlink.command
|
package matterlink.command
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import matterlink.bridge.command.IMinecraftCommandSender
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
|
@ -9,17 +11,23 @@ import net.minecraft.world.World
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
class MatterLinkCommandSender(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
) : IMinecraftCommandSender(user, env, op), ICommandSender {
|
||||||
|
|
||||||
override fun execute(cmdString: String): Boolean {
|
override fun execute(cmdString: String): Boolean = runBlocking {
|
||||||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||||
this,
|
this@MatterLinkCommandSender,
|
||||||
cmdString
|
cmdString
|
||||||
)
|
).apply {
|
||||||
|
sendReply(cmdString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDisplayName(): ITextComponent {
|
override fun getDisplayName(): ITextComponent {
|
||||||
return TextComponentString(user)
|
return TextComponentString(displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName() = accountName
|
override fun getName() = accountName
|
||||||
|
@ -38,7 +46,7 @@ class MatterLinkCommandSender(user: String, userId: String, server: String) : IM
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
||||||
sendReply(component!!.unformattedComponentText)
|
appendReply(component!!.unformattedComponentText)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendCommandFeedback(): Boolean {
|
override fun sendCommandFeedback(): Boolean {
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url = "http://files.minecraftforge.net/maven" }
|
maven {
|
||||||
|
url = 'http://files.minecraftforge.net/maven'
|
||||||
|
}
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url = 'https://plugins.gradle.org/m2/'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT"
|
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '1.2-SNAPSHOT'
|
||||||
|
classpath group: 'gradle.plugin.com.matthewprenger', name: 'CurseGradle', version: cursegradleVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'com.matthewprenger.cursegradle' version '1.0.10'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'forge'
|
apply plugin: 'forge'
|
||||||
|
apply plugin: 'com.matthewprenger.cursegradle'
|
||||||
|
|
||||||
version = project.mc_version + "-" + project.mod_version
|
version = project.mc_version + '-' + project.modVersion
|
||||||
|
|
||||||
archivesBaseName = project.mod_name
|
archivesBaseName = project.modName
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = '1.8'
|
||||||
|
|
||||||
|
@ -27,57 +30,75 @@ configurations {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
shade project(":core")
|
shade (project(':core')) { transitive = true }
|
||||||
|
shade (project(':Jankson')) { transitive = false }
|
||||||
|
|
||||||
|
shade group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlinVersion
|
||||||
|
|
||||||
|
shade(group: "org.jetbrains.kotlinx", name: "kotlinx-coroutines-core", version: coroutinesVersion)
|
||||||
|
shade(group: "org.jetbrains.kotlinx", name: "kotlinx-serialization-runtime", version: serializationVersion)
|
||||||
|
|
||||||
|
shade(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion)
|
||||||
|
shade(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion)
|
||||||
|
shade(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion)
|
||||||
|
shade(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion)
|
||||||
|
|
||||||
|
// shade group: 'com.github.kittinunf.fuel', name: 'fuel', version: fuelVersion
|
||||||
|
// shade group: 'com.github.kittinunf.result', name: 'result', version: resultVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = project.mc_version + "-" + project.forge_version + "-" + project.mc_version
|
version = project.mc_version + '-' + project.forge_version + '-' + project.mc_version
|
||||||
runDir = "run"
|
runDir = 'run'
|
||||||
|
|
||||||
mappings = project.mcp_mappings
|
mappings = project.mcp_mappings
|
||||||
|
|
||||||
srgExtra "PK: kotlin matterlink/repack/kotlin"
|
// srgExtra 'PK: kotlin matterlink/repack/kotlin'
|
||||||
srgExtra "PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations"
|
// srgExtra 'PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations'
|
||||||
srgExtra "PK: org/apache/http matterlink/repack/org/apache/http"
|
// srgExtra 'PK: org/intellij matterlink/repack/org/intellij'
|
||||||
//srgExtra "PK: org/apache/commons matterlink/repack/org/apache/commons"
|
// srgExtra 'PK: blue/endless/ matterlink/repack/blue/endless/'
|
||||||
srgExtra "PK: org/intellij matterlink/repack/org/intellij"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin.doFirst {
|
compileKotlin.doFirst {
|
||||||
def target = "src/main/kotlin/matterlink/gen"
|
def target = 'src/main/kotlin/matterlink/gen'
|
||||||
copy {
|
copy {
|
||||||
from("src/templates/kotlin/matterlink/Constants.kt")
|
from('src/templates/kotlin/matterlink/Constants.kt')
|
||||||
into(target)
|
into(target)
|
||||||
}
|
}
|
||||||
ant.replaceregexp(match: '@MODVERSION@', replace: project.mod_version, flags: 'g', byline: true) {
|
ant.replaceregexp(match: '@MODVERSION@', replace: project.modVersion, flags: 'g', byline: true) {
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
fileset(dir: target, includes: 'Constants.kt')
|
||||||
}
|
}
|
||||||
ant.replaceregexp(match: '@MCVERSION@', replace: project.mc_version, flags: 'g', byline: true) {
|
ant.replaceregexp(match: '@MCVERSION@', replace: project.mc_version, flags: 'g', byline: true) {
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
fileset(dir: target, includes: 'Constants.kt')
|
||||||
}
|
}
|
||||||
ant.replaceregexp(match: '@FORGELIN-VERSION@', replace: project.forgelin_version, flags: 'g', byline: true) {
|
ant.replaceregexp(match: '@FORGELIN-VERSION@', replace: project.forgelinVersion, flags: 'g', byline: true) {
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
fileset(dir: target, includes: 'Constants.kt')
|
||||||
}
|
}
|
||||||
ant.replaceregexp(match: '@FORGE-VERSION@', replace: project.forge_version, flags: 'g', byline: true) {
|
ant.replaceregexp(match: '@FORGE-VERSION@', replace: project.forge_version, flags: 'g', byline: true) {
|
||||||
fileset(dir: target, includes: 'Constants.kt')
|
fileset(dir: target, includes: 'Constants.kt')
|
||||||
}
|
}
|
||||||
|
ant.replaceregexp(match: '@BUILD_NUMBER@', replace: System.env.BUILD_NUMBER ?: -1, flags: 'g', byline: true) {
|
||||||
|
fileset(dir: target, includes: 'Constants.kt')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
// this will ensure that this task is redone when the versions change.
|
// this will ensure that this task is redone when the versions change.
|
||||||
inputs.property "version", project.mod_version
|
inputs.property 'version', project.modVersion
|
||||||
inputs.property "mcversion", project.minecraft.version
|
inputs.property 'mcversion', project.minecraft.version
|
||||||
|
|
||||||
// replace stuff in mcmod.info, nothing else
|
// replace stuff in mcmod.info, nothing else
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
from(project(':core').sourceSets.main.resources.srcDirs) {
|
||||||
include 'mcmod.info'
|
include 'mcmod.info'
|
||||||
|
|
||||||
// replace version and mcversion
|
// replace version and mcversion
|
||||||
expand 'version': project.mod_version, 'mcversion': project.minecraft.version
|
expand 'version': project.modVersion, 'mcversion': project.minecraft.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy everything else except the mcmod.info
|
// copy everything else except the mcmod.info
|
||||||
from(project(":core").sourceSets.main.resources.srcDirs) {
|
from(project(':core').sourceSets.main.resources.srcDirs) {
|
||||||
exclude 'mcmod.info'
|
exclude 'mcmod.info'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,8 +106,7 @@ processResources {
|
||||||
jar {
|
jar {
|
||||||
configurations.shade.each { dep ->
|
configurations.shade.each { dep ->
|
||||||
from(project.zipTree(dep)) {
|
from(project.zipTree(dep)) {
|
||||||
exclude "META-INF", "META-INF/**"
|
exclude 'META-INF', 'META-INF/**'
|
||||||
exclude "com/google/gson", "com/google/gson/**"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,11 +116,11 @@ curseforge {
|
||||||
apiKey = CURSEFORGE_API_TOKEN
|
apiKey = CURSEFORGE_API_TOKEN
|
||||||
}
|
}
|
||||||
project {
|
project {
|
||||||
id = project.curse_id
|
id = project.curseId
|
||||||
releaseType = project.curse_release_type
|
releaseType = project.curseReleaseType
|
||||||
if (project.hasProperty('changelog_file')) {
|
if (project.hasProperty('changelog_file')) {
|
||||||
println("changelog = $changelog_file")
|
println("changelog = $changelog_file")
|
||||||
changelogType = "markdown"
|
changelogType = 'markdown'
|
||||||
changelog = file(changelog_file)
|
changelog = file(changelog_file)
|
||||||
}
|
}
|
||||||
mainArtifact(jar) {
|
mainArtifact(jar) {
|
||||||
|
|
|
@ -3,15 +3,20 @@ package matterlink
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent
|
import cpw.mods.fml.common.gameevent.PlayerEvent
|
||||||
import cpw.mods.fml.common.gameevent.TickEvent
|
import cpw.mods.fml.common.gameevent.TickEvent
|
||||||
import matterlink.bridge.USER_ACTION
|
import kotlinx.coroutines.runBlocking
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.handlers.*
|
import matterlink.handlers.ChatEvent
|
||||||
|
import matterlink.handlers.ChatProcessor
|
||||||
|
import matterlink.handlers.DeathHandler
|
||||||
|
import matterlink.handlers.JoinLeaveHandler
|
||||||
|
import matterlink.handlers.ProgressHandler
|
||||||
|
import matterlink.handlers.TickHandler
|
||||||
import net.minecraft.command.server.CommandBroadcast
|
import net.minecraft.command.server.CommandBroadcast
|
||||||
import net.minecraft.command.server.CommandEmote
|
import net.minecraft.command.server.CommandEmote
|
||||||
|
import net.minecraft.entity.Entity
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.server.dedicated.DedicatedServer
|
import net.minecraft.server.dedicated.DedicatedServer
|
||||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
|
||||||
import net.minecraftforge.event.CommandEvent
|
import net.minecraftforge.event.CommandEvent
|
||||||
import net.minecraftforge.event.ServerChatEvent
|
import net.minecraftforge.event.ServerChatEvent
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
||||||
|
@ -22,78 +27,121 @@ object EventHandler {
|
||||||
|
|
||||||
//MC-VERSION & FORGE DEPENDENT
|
//MC-VERSION & FORGE DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun progressEvent(e: AchievementEvent) {
|
fun progressEvent(e: AchievementEvent) = runBlocking {
|
||||||
val achievement = e.achievement
|
val achievement = e.achievement
|
||||||
val entityPlayer = e.entityPlayer as? EntityPlayerMP ?: return
|
val entityPlayer = e.entityPlayer as? EntityPlayerMP ?: return@runBlocking
|
||||||
val statFile = entityPlayer.statFile
|
val statFile = entityPlayer.statFile
|
||||||
|
|
||||||
if (!statFile.canUnlockAchievement(achievement) || statFile.hasAchievementUnlocked(achievement)) {
|
if (!statFile.canUnlockAchievement(achievement) || statFile.hasAchievementUnlocked(achievement)) {
|
||||||
return
|
return@runBlocking
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressHandler.handleProgress(
|
ProgressHandler.handleProgress(
|
||||||
name = e.entityPlayer.displayName,
|
name = e.entityPlayer.displayName,
|
||||||
message = "has earned the achievement",
|
message = "has earned the achievement",
|
||||||
display = e.achievement.statName.unformattedText
|
display = e.achievement.statName.unformattedText,
|
||||||
|
x = e.entityPlayer.posX.toInt(),
|
||||||
|
y = e.entityPlayer.posY.toInt(),
|
||||||
|
z = e.entityPlayer.posZ.toInt(),
|
||||||
|
dimension = e.entityPlayer.dimension
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
fun chatEvent(e: ServerChatEvent) = runBlocking {
|
||||||
ChatProcessor.sendToBridge(
|
if (e.isCanceled) return@runBlocking
|
||||||
|
e.isCanceled = ChatProcessor.sendToBridge(
|
||||||
user = e.player.displayName,
|
user = e.player.displayName,
|
||||||
msg = e.message,
|
msg = e.message,
|
||||||
event = ""
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension,
|
||||||
|
event = ChatEvent.PLAIN,
|
||||||
|
uuid = e.player.gameProfile.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) = runBlocking {
|
||||||
val sender = when {
|
val sender = when {
|
||||||
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
||||||
else -> e.sender.commandSenderName
|
else -> e.sender.commandSenderName
|
||||||
}
|
}
|
||||||
val args = e.parameters.joinToString(" ")
|
val args = e.parameters.joinToString(" ")
|
||||||
val type = when {
|
val type = with(e.command) {
|
||||||
e.command is CommandEmote -> USER_ACTION
|
when {
|
||||||
e.command.commandName == "me" -> USER_ACTION
|
this is CommandEmote || commandName.equals("me", true) -> ChatEvent.ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
this is CommandBroadcast || commandName.equals("say", true) -> ChatEvent.BROADCAST
|
||||||
else -> return
|
else -> return@runBlocking
|
||||||
}
|
}
|
||||||
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
|
}
|
||||||
|
val s = e.sender
|
||||||
|
val (x, y, z) = when (s) {
|
||||||
|
is Entity -> Triple(s.posX.toInt(), s.posY.toInt(), s.posZ.toInt())
|
||||||
|
else -> with(s.commandSenderPosition) { Triple(posX, posY, posZ) }
|
||||||
|
}
|
||||||
|
ChatProcessor.sendToBridge(
|
||||||
|
user = sender,
|
||||||
|
msg = args,
|
||||||
|
event = type,
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
z = z,
|
||||||
|
dimension = when {
|
||||||
|
e.sender is DedicatedServer -> null
|
||||||
|
else -> e.sender.entityWorld.provider.dimensionId
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun deathEvent(e: LivingDeathEvent) {
|
fun deathEvent(e: LivingDeathEvent) = runBlocking {
|
||||||
if (e.entityLiving is EntityPlayer) {
|
if (e.entityLiving is EntityPlayer) {
|
||||||
val player = e.entityLiving as EntityPlayer
|
val player = e.entityLiving as EntityPlayer
|
||||||
DeathHandler.handleDeath(
|
DeathHandler.handleDeath(
|
||||||
player = player.displayName,
|
player = player.displayName,
|
||||||
deathMessage = e.entityLiving.combatTracker.func_151521_b().unformattedText,
|
deathMessage = e.entityLiving.combatTracker.func_151521_b().unformattedText,
|
||||||
damageType = e.source.damageType
|
damageType = e.source.damageType,
|
||||||
|
x = e.entityLiving.posX.toInt(),
|
||||||
|
y = e.entityLiving.posY.toInt(),
|
||||||
|
z = e.entityLiving.posZ.toInt(),
|
||||||
|
dimension = e.entityLiving.dimension
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) = runBlocking {
|
||||||
JoinLeaveHandler.handleJoin(e.player.displayName)
|
JoinLeaveHandler.handleJoin(
|
||||||
|
player = e.player.displayName,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) = runBlocking {
|
||||||
JoinLeaveHandler.handleLeave(e.player.displayName)
|
JoinLeaveHandler.handleLeave(
|
||||||
|
player = e.player.displayName,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
fun serverTickEvent(e: TickEvent.ServerTickEvent) = runBlocking {
|
||||||
if (e.phase == TickEvent.Phase.END)
|
if (e.phase == TickEvent.Phase.END)
|
||||||
TickHandler.handleTick()
|
TickHandler.handleTick()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile
|
||||||
import cpw.mods.fml.common.FMLCommonHandler
|
import cpw.mods.fml.common.FMLCommonHandler
|
||||||
import cpw.mods.fml.common.Mod
|
import cpw.mods.fml.common.Mod
|
||||||
import cpw.mods.fml.common.event.*
|
import cpw.mods.fml.common.event.FMLInitializationEvent
|
||||||
import matterlink.command.CommandMatterlink
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import cpw.mods.fml.common.event.FMLServerStartingEvent
|
||||||
|
import cpw.mods.fml.common.event.FMLServerStoppingEvent
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
|
import matterlink.command.AuthCommand
|
||||||
|
import matterlink.command.MatterLinkCommand
|
||||||
import matterlink.command.MatterLinkCommandSender
|
import matterlink.command.MatterLinkCommandSender
|
||||||
|
import matterlink.config.BaseConfig
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
import net.minecraft.util.ChatComponentText
|
import net.minecraft.util.ChatComponentText
|
||||||
import net.minecraftforge.common.ForgeVersion
|
import net.minecraftforge.common.ForgeVersion
|
||||||
import net.minecraftforge.common.MinecraftForge
|
import net.minecraftforge.common.MinecraftForge
|
||||||
import org.apache.logging.log4j.Level
|
import java.util.UUID
|
||||||
import org.apache.logging.log4j.Logger
|
|
||||||
|
|
||||||
lateinit var logger: Logger
|
|
||||||
|
|
||||||
@Mod(
|
@Mod(
|
||||||
modid = MODID,
|
modid = MODID,
|
||||||
|
@ -32,10 +37,19 @@ class MatterLink : IMatterLink() {
|
||||||
MinecraftForge.EVENT_BUS.register(EventHandler)
|
MinecraftForge.EVENT_BUS.register(EventHandler)
|
||||||
FMLCommonHandler.instance().bus().register(EventHandler)
|
FMLCommonHandler.instance().bus().register(EventHandler)
|
||||||
|
|
||||||
logger = event.modLog
|
logger = with(event.modLog) {
|
||||||
|
object : Logger {
|
||||||
|
override fun info(message: String) = this@with.info(message)
|
||||||
|
override fun debug(message: String) = this@with.debug(message)
|
||||||
|
override fun error(message: String) = this@with.error(message)
|
||||||
|
override fun warn(message: String) = this@with.warn(message)
|
||||||
|
override fun trace(message: String) = this@with.trace(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Building bridge!")
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
@ -44,14 +58,15 @@ class MatterLink : IMatterLink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) = runBlocking {
|
||||||
logger.debug("Registering server commands")
|
logger.debug("Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(MatterLinkCommand)
|
||||||
|
event.registerServerCommand(AuthCommand)
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun serverStopping(event: FMLServerStoppingEvent) {
|
fun serverStopping(event: FMLServerStoppingEvent) = runBlocking {
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +75,74 @@ class MatterLink : IMatterLink() {
|
||||||
MinecraftServer.getServer().configurationManager.sendChatMsg(ChatComponentText(msg))
|
MinecraftServer.getServer().configurationManager.sendChatMsg(ChatComponentText(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log(level: String, formatString: String, vararg data: Any) =
|
override fun wrappedSendToPlayer(username: String, msg: String) {
|
||||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
val profile = profileByName(username) ?: run {
|
||||||
|
logger.error("cannot find player by name $username")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
logger.error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.addChatMessage(ChatComponentText(msg))
|
||||||
|
}
|
||||||
|
|
||||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
|
||||||
|
val profile = profileByUUID(uuid) ?: run {
|
||||||
|
logger.error("cannot find player by uuid $uuid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
logger.error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.addChatMessage(ChatComponentText(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isOnline(username: String) = (FMLCommonHandler.instance()
|
||||||
|
.minecraftServerInstance.configurationManager.getPlayerByUsername(username) ?: null) != null
|
||||||
|
|
||||||
|
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? {
|
||||||
|
return FMLCommonHandler.instance()
|
||||||
|
.minecraftServerInstance.configurationManager.getPlayerByUsername(gameProfile.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun profileByUUID(uuid: UUID): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(uuid)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by uuid $uuid")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun profileByName(username: String): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by username $username")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun collectPlayers(area: Area): Set<UUID> {
|
||||||
|
val players = MinecraftServer.getServer().configurationManager.playerEntityList
|
||||||
|
.map { it as EntityPlayerMP }
|
||||||
|
.filter {
|
||||||
|
(area.allDimensions || area.dimensions.contains(it.dimension))
|
||||||
|
&& area.testInBounds(it.posX.toInt(), it.posY.toInt(), it.posZ.toInt())
|
||||||
|
}
|
||||||
|
return players.map { it.uniqueID }.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
|
||||||
|
|
||||||
|
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
|
||||||
|
|
||||||
|
override fun commandSenderFor(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
) = MatterLinkCommandSender(user, env, op)
|
||||||
|
|
||||||
override val mcVersion: String = MCVERSION
|
override val mcVersion: String = MCVERSION
|
||||||
override val modVersion: String = MODVERSION
|
override val modVersion: String = MODVERSION
|
||||||
|
override val buildNumber = BUILD_NUMBER
|
||||||
override val forgeVersion = ForgeVersion.getVersion()
|
override val forgeVersion = ForgeVersion.getVersion()
|
||||||
}
|
}
|
|
@ -1,24 +0,0 @@
|
||||||
package matterlink
|
|
||||||
|
|
||||||
import matterlink.config.BaseConfig
|
|
||||||
import net.minecraftforge.common.config.Configuration
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
|
||||||
init {
|
|
||||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
|
||||||
val config = Configuration(mainCfgFile)
|
|
||||||
|
|
||||||
load(
|
|
||||||
getBoolean = config::getBoolean,
|
|
||||||
getString = config::getString,
|
|
||||||
getStringValidated = config::getString,
|
|
||||||
getStringValidValues = config::getString,
|
|
||||||
getStringList = config::getStringList,
|
|
||||||
addCustomCategoryComment = config::addCustomCategoryComment
|
|
||||||
)
|
|
||||||
if (config.hasChanged()) config.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
|
||||||
}
|
|
|
@ -3,31 +3,33 @@ package matterlink.command
|
||||||
import net.minecraft.command.CommandBase
|
import net.minecraft.command.CommandBase
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.command.WrongUsageException
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.util.ChatComponentText
|
import net.minecraft.util.ChatComponentText
|
||||||
|
|
||||||
|
|
||||||
class CommandMatterlink : CommandBase() {
|
object AuthCommand : CommandBase() {
|
||||||
|
override fun getCommandName(): String {
|
||||||
|
return CommandCoreAuth.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandUsage(sender: ICommandSender): String {
|
||||||
|
return CommandCoreAuth.usage
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandAliases(): List<String> {
|
||||||
|
return CommandCoreAuth.aliases
|
||||||
|
}
|
||||||
|
|
||||||
override fun processCommand(sender: ICommandSender, args: Array<String>) {
|
override fun processCommand(sender: ICommandSender, args: Array<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
throw WrongUsageException("Invalid command! Valid uses: ${this.getCommandUsage(sender)}")
|
throw WrongUsageException("Invalid command! Valid uses: ${this.getCommandUsage(sender)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val reply = CommandCore.execute(args)
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreAuth.execute(args, sender.commandSenderName, uuid)
|
||||||
|
|
||||||
if (reply.isNotEmpty()) {
|
if (reply.isNotEmpty()) {
|
||||||
sender.addChatMessage(ChatComponentText(reply))
|
sender.addChatMessage(ChatComponentText(reply))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCommandName(): String {
|
|
||||||
return CommandCore.getName()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCommandUsage(sender: ICommandSender): String {
|
|
||||||
return CommandCore.getUsage()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCommandAliases(): List<String> {
|
|
||||||
return CommandCore.getAliases()
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package matterlink.command
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import net.minecraft.command.CommandBase
|
||||||
|
import net.minecraft.command.ICommandSender
|
||||||
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.util.ChatComponentText
|
||||||
|
|
||||||
|
|
||||||
|
object MatterLinkCommand : CommandBase() {
|
||||||
|
override fun getCommandName(): String {
|
||||||
|
return CommandCoreML.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandUsage(sender: ICommandSender): String {
|
||||||
|
return CommandCoreML.usage
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandAliases(): List<String> {
|
||||||
|
return CommandCoreML.aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processCommand(sender: ICommandSender, args: Array<String>) = runBlocking {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
throw WrongUsageException("Invalid command! Valid uses: ${getCommandUsage(sender)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreML.execute(args, sender.commandSenderName, uuid)
|
||||||
|
|
||||||
|
if (reply.isNotEmpty()) {
|
||||||
|
sender.addChatMessage(ChatComponentText(reply))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
package matterlink.command
|
package matterlink.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import kotlinx.coroutines.runBlocking
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import matterlink.bridge.command.IMinecraftCommandSender
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
import net.minecraft.util.ChatComponentText
|
import net.minecraft.util.ChatComponentText
|
||||||
|
@ -11,19 +10,23 @@ import net.minecraft.util.ChunkCoordinates
|
||||||
import net.minecraft.util.IChatComponent
|
import net.minecraft.util.IChatComponent
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
|
|
||||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
class MatterLinkCommandSender(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
) : IMinecraftCommandSender(user, env, op), ICommandSender {
|
||||||
|
|
||||||
private var level: Int = 0
|
override fun execute(cmdString: String): Boolean = runBlocking {
|
||||||
|
return@runBlocking 0 < MinecraftServer.getServer().commandManager.executeCommand(
|
||||||
override fun execute(cmdString: String): Boolean {
|
this@MatterLinkCommandSender,
|
||||||
return 0 < MinecraftServer.getServer().commandManager.executeCommand(
|
|
||||||
this,
|
|
||||||
cmdString
|
cmdString
|
||||||
)
|
).apply {
|
||||||
|
sendReply(cmdString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFormattedCommandSenderName(): IChatComponent {
|
override fun getFormattedCommandSenderName(): IChatComponent {
|
||||||
return ChatComponentText(user)
|
return ChatComponentText(displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCommandSenderName() = accountName
|
override fun getCommandSenderName() = accountName
|
||||||
|
@ -38,7 +41,7 @@ class MatterLinkCommandSender(user: String, userId: String, server: String) : IM
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addChatMessage(component: IChatComponent) {
|
override fun addChatMessage(component: IChatComponent) {
|
||||||
sendReply(component.unformattedText)
|
appendReply(component.unformattedText)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCommandSenderPosition(): ChunkCoordinates = ChunkCoordinates(0, 0, 0)
|
override fun getCommandSenderPosition(): ChunkCoordinates = ChunkCoordinates(0, 0, 0)
|
||||||
|
|
|
@ -4,4 +4,4 @@ const val MODID = "matterlink"
|
||||||
const val NAME = "MatterLink"
|
const val NAME = "MatterLink"
|
||||||
const val MODVERSION = "@MODVERSION@"
|
const val MODVERSION = "@MODVERSION@"
|
||||||
const val MCVERSION = "@MCVERSION@"
|
const val MCVERSION = "@MCVERSION@"
|
||||||
|
const val BUILD_NUMBER = @BUILD_NUMBER@
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url = 'http://files.minecraftforge.net/maven'
|
||||||
|
}
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url 'https://plugins.gradle.org/m2/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '2.2-SNAPSHOT'
|
||||||
|
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: shadowVersion
|
||||||
|
classpath group: 'gradle.plugin.com.matthewprenger', name: 'CurseGradle', version: cursegradleVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
apply plugin: 'com.matthewprenger.cursegradle'
|
||||||
|
|
||||||
|
version = project.mc_version + '-' + project.modVersion
|
||||||
|
|
||||||
|
archivesBaseName = project.modName
|
||||||
|
|
||||||
|
sourceCompatibility = targetCompatibility = '1.8'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':core')
|
||||||
|
shadow (project(path: ':core', configuration: 'shadow')) { transitive = false }
|
||||||
|
|
||||||
|
compile group: 'net.shadowfacts', name: 'Forgelin', version: project.forgelinVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
classifier = ''
|
||||||
|
|
||||||
|
exclude 'dummyThing'
|
||||||
|
configurations = [project.configurations.shadow]
|
||||||
|
}
|
||||||
|
|
||||||
|
import net.minecraftforge.gradle.user.TaskSourceCopy
|
||||||
|
|
||||||
|
// Mad hacks to make source replacements work for Kotlin
|
||||||
|
// source: https://github.com/PaleoCrafter/VanillaImmersion/blob/ee82ecafb76659cf7d7822a722c8f63f43f41d01/build.gradle#L119
|
||||||
|
for (set in sourceSets) {
|
||||||
|
def taskName = "source${set.name.capitalize()}Kotlin"
|
||||||
|
def dir = new File(project.getBuildDir(), "sources/${set.name}/kotlin")
|
||||||
|
task(taskName, type: TaskSourceCopy) {
|
||||||
|
source = set.getKotlin()
|
||||||
|
output = dir
|
||||||
|
}
|
||||||
|
def compileTask = tasks[set.getCompileTaskName('kotlin')]
|
||||||
|
compileTask.source = dir
|
||||||
|
compileTask.dependsOn taskName
|
||||||
|
def dirPath = dir.toPath()
|
||||||
|
compileKotlin.include {
|
||||||
|
return it.file.toPath().startsWith(dirPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sourceJar.from sourceSets.main.kotlin
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
version = project.mc_version + '-' + project.forge_version
|
||||||
|
runDir = 'run'
|
||||||
|
|
||||||
|
mappings = project.mcp_mappings
|
||||||
|
|
||||||
|
replaceIn 'Constants.kt'
|
||||||
|
replace '@MODVERSION@', project.modVersion
|
||||||
|
replace '@MCVERSION@', project.mc_version
|
||||||
|
replace '@FORGELIN-VERSION@', project.forgelinVersion
|
||||||
|
replace '@FORGE-VERSION@', project.forge_version
|
||||||
|
replace '-1//@BUILD_NUMBER@', System.env.BUILD_NUMBER ?: -1
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
// this will ensure that this task is redone when the versions change.
|
||||||
|
inputs.property 'version', project.modVersion
|
||||||
|
inputs.property 'mcversion', project.minecraft.version
|
||||||
|
|
||||||
|
// replace stuff in mcmod.info, nothing else
|
||||||
|
from(project(':core').sourceSets.main.resources.srcDirs) {
|
||||||
|
include 'mcmod.info'
|
||||||
|
|
||||||
|
// replace version and mcversion
|
||||||
|
expand 'version': project.modVersion, 'mcversion': project.minecraft.version
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy everything else except the mcmod.info
|
||||||
|
from(project(':core').sourceSets.main.resources.srcDirs) {
|
||||||
|
exclude 'mcmod.info'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceJar {
|
||||||
|
classifier 'sources'
|
||||||
|
// copy all the minecraftforge specific classes
|
||||||
|
from sourceSets.main.allSource
|
||||||
|
|
||||||
|
// copy everything else except the mcmod.info
|
||||||
|
from(project(':core').sourceSets.main.allSource) {
|
||||||
|
exclude 'mcmod.info'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
reobf {
|
||||||
|
shadowJar { mappingType = 'SEARGE' }
|
||||||
|
}
|
||||||
|
tasks.shadowJar.finalizedBy reobfShadowJar
|
||||||
|
|
||||||
|
curseforge {
|
||||||
|
if (project.hasProperty('CURSEFORGE_API_TOKEN') && project.hasProperty('release')) {
|
||||||
|
apiKey = CURSEFORGE_API_TOKEN
|
||||||
|
}
|
||||||
|
project {
|
||||||
|
id = project.curseId
|
||||||
|
releaseType = project.curseReleaseType
|
||||||
|
addGameVersion '1.10'
|
||||||
|
if (project.hasProperty('changelog_file')) {
|
||||||
|
println("changelog = $changelog_file")
|
||||||
|
changelogType = 'markdown'
|
||||||
|
changelog = file(changelog_file)
|
||||||
|
}
|
||||||
|
relations {
|
||||||
|
requiredLibrary 'shadowfacts-forgelin'
|
||||||
|
}
|
||||||
|
mainArtifact(shadowJar) {
|
||||||
|
displayName = "MatterLink $version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
mc_version = 1.9.4
|
||||||
|
mcp_mappings = stable_26
|
||||||
|
forge_version = 12.17.0.2051
|
|
@ -5,3 +5,4 @@ const val NAME = "MatterLink"
|
||||||
const val MODVERSION = "@MODVERSION@"
|
const val MODVERSION = "@MODVERSION@"
|
||||||
const val MCVERSION = "@MCVERSION@"
|
const val MCVERSION = "@MCVERSION@"
|
||||||
const val DEPENDENCIES = "required-after:forgelin@[@FORGELIN-VERSION@,);"
|
const val DEPENDENCIES = "required-after:forgelin@[@FORGELIN-VERSION@,);"
|
||||||
|
const val BUILD_NUMBER = -1//@BUILD_NUMBER@
|
|
@ -0,0 +1,139 @@
|
||||||
|
package matterlink
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.handlers.ChatEvent
|
||||||
|
import matterlink.handlers.ChatProcessor
|
||||||
|
import matterlink.handlers.DeathHandler
|
||||||
|
import matterlink.handlers.JoinLeaveHandler
|
||||||
|
import matterlink.handlers.ProgressHandler
|
||||||
|
import matterlink.handlers.TickHandler
|
||||||
|
import net.minecraft.command.server.CommandBroadcast
|
||||||
|
import net.minecraft.command.server.CommandEmote
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
|
import net.minecraft.server.dedicated.DedicatedServer
|
||||||
|
import net.minecraftforge.event.CommandEvent
|
||||||
|
import net.minecraftforge.event.ServerChatEvent
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
||||||
|
import net.minecraftforge.event.entity.player.AchievementEvent
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
||||||
|
import net.minecraftforge.fml.common.gameevent.PlayerEvent
|
||||||
|
import net.minecraftforge.fml.common.gameevent.TickEvent
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
object EventHandler {
|
||||||
|
|
||||||
|
//MC-VERSION & FORGE DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun progressEvent(e: AchievementEvent) = runBlocking {
|
||||||
|
val achievement = e.achievement
|
||||||
|
val entityPlayer = e.entityPlayer as? EntityPlayerMP ?: return@runBlocking
|
||||||
|
val statFile = entityPlayer.statFile
|
||||||
|
|
||||||
|
if (!statFile.canUnlockAchievement(achievement) || statFile.hasAchievementUnlocked(achievement)) {
|
||||||
|
return@runBlocking
|
||||||
|
}
|
||||||
|
ProgressHandler.handleProgress(
|
||||||
|
name = e.entityPlayer.displayName.unformattedText,
|
||||||
|
message = "has earned the achievement",
|
||||||
|
display = e.achievement.statName.unformattedText,
|
||||||
|
x = e.entityPlayer.posX.toInt(),
|
||||||
|
y = e.entityPlayer.posY.toInt(),
|
||||||
|
z = e.entityPlayer.posZ.toInt(),
|
||||||
|
dimension = e.entityPlayer.dimension
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun chatEvent(e: ServerChatEvent) = runBlocking {
|
||||||
|
if (e.isCanceled) return@runBlocking
|
||||||
|
e.isCanceled = ChatProcessor.sendToBridge(
|
||||||
|
user = e.player.displayName.unformattedText,
|
||||||
|
msg = e.message,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension,
|
||||||
|
event = ChatEvent.PLAIN,
|
||||||
|
uuid = e.player.gameProfile.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun commandEvent(e: CommandEvent) = runBlocking {
|
||||||
|
val sender = when {
|
||||||
|
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
||||||
|
else -> e.sender.displayName.unformattedText
|
||||||
|
}
|
||||||
|
val args = e.parameters.joinToString(" ")
|
||||||
|
val type = with(e.command) {
|
||||||
|
when {
|
||||||
|
this is CommandEmote || commandName.equals("me", true) -> ChatEvent.ACTION
|
||||||
|
this is CommandBroadcast || commandName.equals("say", true) -> ChatEvent.BROADCAST
|
||||||
|
else -> return@runBlocking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ChatProcessor.sendToBridge(
|
||||||
|
user = sender,
|
||||||
|
msg = args,
|
||||||
|
event = type,
|
||||||
|
x = e.sender.position.x,
|
||||||
|
y = e.sender.position.y,
|
||||||
|
z = e.sender.position.z,
|
||||||
|
dimension = when {
|
||||||
|
e.sender is DedicatedServer -> null
|
||||||
|
else -> e.sender.commandSenderEntity?.dimension ?: e.sender.entityWorld.provider.dimension
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun deathEvent(e: LivingDeathEvent) = runBlocking {
|
||||||
|
if (e.entityLiving is EntityPlayer) {
|
||||||
|
DeathHandler.handleDeath(
|
||||||
|
player = e.entityLiving.displayName.unformattedText,
|
||||||
|
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
||||||
|
damageType = e.source.damageType,
|
||||||
|
x = e.entityLiving.posX.toInt(),
|
||||||
|
y = e.entityLiving.posY.toInt(),
|
||||||
|
z = e.entityLiving.posZ.toInt(),
|
||||||
|
dimension = e.entityLiving.dimension
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) = runBlocking {
|
||||||
|
JoinLeaveHandler.handleJoin(
|
||||||
|
player = e.player.displayName.unformattedText,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) = runBlocking {
|
||||||
|
JoinLeaveHandler.handleLeave(
|
||||||
|
player = e.player.displayName.unformattedText,
|
||||||
|
x = e.player.posX.toInt(),
|
||||||
|
y = e.player.posY.toInt(),
|
||||||
|
z = e.player.posZ.toInt(),
|
||||||
|
dimension = e.player.dimension
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
fun serverTickEvent(e: TickEvent.ServerTickEvent) = runBlocking {
|
||||||
|
if (e.phase == TickEvent.Phase.END)
|
||||||
|
TickHandler.handleTick()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,148 @@
|
||||||
|
package matterlink
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
|
import matterlink.command.AuthCommand
|
||||||
|
import matterlink.command.MatterLinkCommand
|
||||||
|
import matterlink.command.MatterLinkCommandSender
|
||||||
|
import matterlink.config.BaseConfig
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
|
import net.minecraft.util.text.TextComponentString
|
||||||
|
import net.minecraftforge.common.ForgeVersion
|
||||||
|
import net.minecraftforge.common.MinecraftForge
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
|
import net.minecraftforge.fml.common.Mod
|
||||||
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
@Mod(
|
||||||
|
modid = MODID,
|
||||||
|
name = NAME, version = MODVERSION,
|
||||||
|
serverSideOnly = true,
|
||||||
|
useMetadata = true,
|
||||||
|
acceptableRemoteVersions = "*",
|
||||||
|
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter",
|
||||||
|
dependencies = DEPENDENCIES
|
||||||
|
)
|
||||||
|
object MatterLink : IMatterLink() {
|
||||||
|
init {
|
||||||
|
instance = this
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
fun preInit(event: FMLPreInitializationEvent) {
|
||||||
|
MinecraftForge.EVENT_BUS.register(EventHandler)
|
||||||
|
logger = with(event.modLog) {
|
||||||
|
object : Logger {
|
||||||
|
override fun info(message: String) = this@with.info(message)
|
||||||
|
override fun debug(message: String) = this@with.debug(message)
|
||||||
|
override fun error(message: String) = this@with.error(message)
|
||||||
|
override fun warn(message: String) = this@with.warn(message)
|
||||||
|
override fun trace(message: String) = this@with.trace(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
|
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
fun init(event: FMLInitializationEvent) {
|
||||||
|
this.registerBridgeCommands()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
fun serverStarting(event: FMLServerStartingEvent) = runBlocking {
|
||||||
|
logger.debug("Registering server commands")
|
||||||
|
event.registerServerCommand(MatterLinkCommand)
|
||||||
|
event.registerServerCommand(AuthCommand)
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
fun serverStopping(event: FMLServerStoppingEvent) = runBlocking {
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
override fun wrappedSendToPlayers(msg: String) {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendChatMsg(TextComponentString(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun wrappedSendToPlayer(username: String, msg: String) {
|
||||||
|
val profile = profileByName(username) ?: run {
|
||||||
|
error("cannot find player by name $username")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.addChatMessage(TextComponentString(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
|
||||||
|
val profile = profileByUUID(uuid) ?: run {
|
||||||
|
logger.error("cannot find player by uuid $uuid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val player = playerByProfile(profile) ?: run {
|
||||||
|
logger.error("${profile.name} is not online")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
player.addChatMessage(TextComponentString(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isOnline(username: String) =
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerList.allUsernames.contains(username)
|
||||||
|
|
||||||
|
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? =
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
|
||||||
|
|
||||||
|
|
||||||
|
private fun profileByUUID(uuid: UUID): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by uuid $uuid")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun profileByName(username: String): GameProfile? = try {
|
||||||
|
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.warn("cannot find profile by username $username")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun collectPlayers(area: Area): Set<UUID> {
|
||||||
|
val playerList = FMLCommonHandler.instance().minecraftServerInstance.playerList
|
||||||
|
val players = playerList.allProfiles
|
||||||
|
.map { playerList.getPlayerByUUID(it.id) }
|
||||||
|
.filter {
|
||||||
|
(area.allDimensions || area.dimensions.contains(it.dimension))
|
||||||
|
&& area.testInBounds(it.posX.toInt(), it.posY.toInt(), it.posZ.toInt())
|
||||||
|
}
|
||||||
|
return players.map { it.uniqueID }.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
|
||||||
|
|
||||||
|
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
|
||||||
|
|
||||||
|
override fun commandSenderFor(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
) = MatterLinkCommandSender(user, env, op)
|
||||||
|
|
||||||
|
override val mcVersion: String = MCVERSION
|
||||||
|
override val modVersion: String = MODVERSION
|
||||||
|
override val buildNumber = BUILD_NUMBER
|
||||||
|
override val forgeVersion = ForgeVersion.getVersion()
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package matterlink.command
|
||||||
|
|
||||||
|
import net.minecraft.command.CommandBase
|
||||||
|
import net.minecraft.command.ICommandSender
|
||||||
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.text.TextComponentString
|
||||||
|
|
||||||
|
|
||||||
|
object AuthCommand : CommandBase() {
|
||||||
|
override fun getCommandName(): String {
|
||||||
|
return CommandCoreAuth.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandUsage(sender: ICommandSender): String {
|
||||||
|
return CommandCoreAuth.usage
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandAliases(): List<String> {
|
||||||
|
return CommandCoreAuth.aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getRequiredPermissionLevel(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
throw WrongUsageException("Invalid command! Valid uses: ${this.getCommandUsage(sender)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreAuth.execute(args, sender.name, uuid)
|
||||||
|
|
||||||
|
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
||||||
|
sender.addChatMessage(TextComponentString(reply))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package matterlink.command
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import net.minecraft.command.CommandBase
|
||||||
|
import net.minecraft.command.ICommandSender
|
||||||
|
import net.minecraft.command.WrongUsageException
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.text.TextComponentString
|
||||||
|
|
||||||
|
|
||||||
|
object MatterLinkCommand : CommandBase() {
|
||||||
|
override fun getCommandName(): String {
|
||||||
|
return CommandCoreML.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandUsage(sender: ICommandSender): String {
|
||||||
|
return CommandCoreML.usage
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCommandAliases(): List<String> {
|
||||||
|
return CommandCoreML.aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) = runBlocking {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
throw WrongUsageException("Invalid command! Valid uses: ${getCommandUsage(sender)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
|
||||||
|
val reply = CommandCoreML.execute(args, sender.name, uuid)
|
||||||
|
|
||||||
|
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
|
||||||
|
sender.addChatMessage(TextComponentString(reply))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
package matterlink.command
|
package matterlink.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import kotlinx.coroutines.runBlocking
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import matterlink.bridge.command.IMinecraftCommandSender
|
||||||
import matterlink.config.cfg
|
|
||||||
import net.minecraft.command.CommandResultStats
|
import net.minecraft.command.CommandResultStats
|
||||||
import net.minecraft.command.ICommandSender
|
import net.minecraft.command.ICommandSender
|
||||||
import net.minecraft.entity.Entity
|
import net.minecraft.entity.Entity
|
||||||
|
@ -16,18 +15,22 @@ import net.minecraft.world.World
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
class MatterLinkCommandSender(
|
||||||
private var level: Int = 0
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
override fun execute(cmdString: String): Boolean {
|
op: Boolean
|
||||||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
) : IMinecraftCommandSender(user, env, op), ICommandSender {
|
||||||
this,
|
override fun execute(cmdString: String): Boolean = runBlocking {
|
||||||
|
return@runBlocking 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||||
|
this@MatterLinkCommandSender,
|
||||||
cmdString
|
cmdString
|
||||||
)
|
).apply {
|
||||||
|
sendReply(cmdString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDisplayName(): ITextComponent {
|
override fun getDisplayName(): ITextComponent {
|
||||||
return TextComponentString(user)
|
return TextComponentString(displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName() = accountName
|
override fun getName() = accountName
|
||||||
|
@ -36,7 +39,7 @@ class MatterLinkCommandSender(user: String, userId: String, server: String) : IM
|
||||||
return FMLCommonHandler.instance().minecraftServerInstance.worldServerForDimension(0)
|
return FMLCommonHandler.instance().minecraftServerInstance.worldServerForDimension(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canUseCommand(permLevel: Int, commandName: String): Boolean {
|
override fun canCommandSenderUseCommand(permLevel: Int, commandName: String): Boolean {
|
||||||
//we check user on our end
|
//we check user on our end
|
||||||
return canExecute(commandName)
|
return canExecute(commandName)
|
||||||
}
|
}
|
||||||
|
@ -45,9 +48,8 @@ class MatterLinkCommandSender(user: String, userId: String, server: String) : IM
|
||||||
return FMLCommonHandler.instance().minecraftServerInstance
|
return FMLCommonHandler.instance().minecraftServerInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
override fun addChatMessage(@Nonnull component: ITextComponent?) {
|
||||||
sendReply(component!!.unformattedComponentText)
|
appendReply(component!!.unformattedComponentText)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendCommandFeedback(): Boolean {
|
override fun sendCommandFeedback(): Boolean {
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7d27c28784bacba17450faa9e723ca6b6eb39602
|
|
@ -1,28 +1,25 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
stages {
|
stages {
|
||||||
|
stage("init") {
|
||||||
|
steps {
|
||||||
|
sh 'git submodule update --init --recursive'
|
||||||
|
}
|
||||||
|
}
|
||||||
stage("1.7.10") {
|
stage("1.7.10") {
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew :1.7.10:setupCiWorkspace'
|
sh './gradlew :1.7.10:setupCiWorkspace'
|
||||||
sh './gradlew :1.7.10:clean'
|
sh './gradlew :1.7.10:clean'
|
||||||
sh './gradlew :1.7.10:build'
|
sh './gradlew :1.7.10:build'
|
||||||
archive '1.7.10/build/libs/*jar'
|
archiveArtifacts artifacts: '1.7.10/build/libs/*jar'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage("1.10.2") {
|
stage("1.9.4") {
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew :1.10.2:setupCiWorkspace'
|
sh './gradlew :1.9.4:setupCiWorkspace'
|
||||||
sh './gradlew :1.10.2:clean'
|
sh './gradlew :1.9.4:clean'
|
||||||
sh './gradlew :1.10.2:build'
|
sh './gradlew :1.9.4:build'
|
||||||
archive '1.10.2/build/libs/*jar'
|
archiveArtifacts artifacts: '1.9.4/build/libs/*jar'
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("1.11.2") {
|
|
||||||
steps {
|
|
||||||
sh './gradlew :1.11.2:setupCiWorkspace'
|
|
||||||
sh './gradlew :1.11.2:clean'
|
|
||||||
sh './gradlew :1.11.2:build'
|
|
||||||
archive '1.11.2/build/libs/*jar'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage("1.12.2") {
|
stage("1.12.2") {
|
||||||
|
@ -30,7 +27,7 @@ pipeline {
|
||||||
sh './gradlew :1.12.2:setupCiWorkspace'
|
sh './gradlew :1.12.2:setupCiWorkspace'
|
||||||
sh './gradlew :1.12.2:clean'
|
sh './gradlew :1.12.2:clean'
|
||||||
sh './gradlew :1.12.2:build'
|
sh './gradlew :1.12.2:build'
|
||||||
archive '1.12.2/build/libs/*jar'
|
archiveArtifacts artifacts: '1.12.2/build/libs/*jar'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
208
README.md
208
README.md
|
@ -1,18 +1,145 @@
|
||||||
|
[](http://discord.gg/Fm5EST)
|
||||||
|
[](https://discord.gg/hXqNgq5)
|
||||||
|
[](https://curse.nikky.moe/api/url/287323?version=1.12.2)
|
||||||
|
[](https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/lastSuccessfulBuild/artifact/)
|
||||||
|
[](https://www.patreon.com/NikkyAi)
|
||||||
|
|
||||||
# MatterLink
|
# MatterLink
|
||||||
|
|
||||||
A MatterBridge endpoint for MC servers!
|
- [Downloads](#downloads)
|
||||||
|
- [Dependencies](#dependencies)
|
||||||
|
- [Features](#features)
|
||||||
|
- [Setup](#setup)
|
||||||
|
|
||||||
|
A Matterbridge endpoint for MC servers!
|
||||||
|
|
||||||
THIS MOD REQUIRES YOU TO ALSO RUN A MATTERBRIDGE RELAY
|
THIS MOD REQUIRES YOU TO ALSO RUN A MATTERBRIDGE RELAY
|
||||||
https://github.com/42wim/matterbridge
|
https://github.com/42wim/matterbridge
|
||||||
|
|
||||||
Chat with us on IRC: [#matterbridge @ irc.esper.net](irc://irc.esper.net/matterbridge)
|
Chat with us on IRC: [#matterlink @ irc.esper.net](irc://irc.esper.net/matterlink)
|
||||||
|
|
||||||
|
## Downloads
|
||||||
|
|
||||||
|
[](https://github.com/elytra/MatterLink/releases)
|
||||||
|
|
||||||
|
[](https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/lastSuccessfulBuild/artifact/)
|
||||||
|
|
||||||
|
[](https://minecraft.curseforge.com/projects/287323/files)
|
||||||
|
|
||||||
|
[](https://curse.nikky.moe/api/url/287323?version=1.12.2)
|
||||||
|
|
||||||
|
[](https://curse.nikky.moe/api/url/287323?version=1.9.4)
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
[](https://minecraft.curseforge.com/projects/248453/files)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### Custom bridge commands
|
||||||
|
|
||||||
|
includes pass-through to Minecraft commands!
|
||||||
|
Default commands: `help, tps, list, seed, uptime`
|
||||||
|
|
||||||
|
Commands are specified in JSON format as follows:
|
||||||
|
|
||||||
|
Passthrough command (executes the configured command from the MC server console)
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"tps": {
|
||||||
|
"type": "PASSTHROUGH",
|
||||||
|
"execute": "forge tps",
|
||||||
|
"permLevel": 0,
|
||||||
|
"help": "Print server tps",
|
||||||
|
"allowArgs": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Response command
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"uptime": {
|
||||||
|
"type": "RESPONSE",
|
||||||
|
"response": "{uptime}",
|
||||||
|
"permLevel": 1,
|
||||||
|
"help": "Print server uptime",
|
||||||
|
"allowArgs": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Acount Linking
|
||||||
|
|
||||||
|
To link your chat account to your minecraft uuid
|
||||||
|
execute `!auth Username`
|
||||||
|
make sure to use the proper username and command prefix, the system will then guide you through
|
||||||
|
|
||||||
|
internally the identity links are stored like so:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
/* username: NikkyAi */
|
||||||
|
"edd31c45-b095-49c5-a9f5-59cec4cfed8c": {
|
||||||
|
/* discord id */
|
||||||
|
"discord.game": [
|
||||||
|
"112228624366575616"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command permissions
|
||||||
|
|
||||||
|
Higher numbers mean more permissions. Configured per uuid.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"edd31c45-b095-49c5-a9f5-59cec4cfed8c": 9000
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reload
|
||||||
|
|
||||||
|
Edit and reload the config file without restarting the server!
|
||||||
|
```
|
||||||
|
/ml <connect|disconnect|reload>
|
||||||
|
connect: Connects the MC chat to the MatterBridge server
|
||||||
|
disconnect: Disconnects the chat from the MatterBridge server
|
||||||
|
reload: Disconnects, reloads the config and custom command files,
|
||||||
|
then reconnects.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
Requires the matterbridge config api section to be setup along these lines:
|
Requires the matterbridge config api section to be setup along these lines:
|
||||||
|
|
||||||
|
### Local
|
||||||
|
|
||||||
|
If ou know the matterbridge will run on the same machine as the Minecraft Server
|
||||||
|
```
|
||||||
|
[api]
|
||||||
|
[api.local]
|
||||||
|
BindAddress="127.0.0.1:4242" // Listens only for localhost
|
||||||
|
#OPTIONAL (no authorization if token is empty)
|
||||||
|
Token="" # Token left empty
|
||||||
|
Buffer=1000
|
||||||
|
RemoteNickFormat="{NICK}"
|
||||||
|
ShowJoinPart = true
|
||||||
|
```
|
||||||
|
|
||||||
|
With this you need no extra configuration steps.. just run matterbridge and then start the minecraft server (or reload matterlink with command if it runs already)
|
||||||
|
|
||||||
|
### Remote
|
||||||
|
|
||||||
|
If the matterbridge runs on a different machine
|
||||||
|
|
||||||
```
|
```
|
||||||
[api]
|
[api]
|
||||||
[api.local]
|
[api.local]
|
||||||
BindAddress="0.0.0.0:4242" # or listen only to localhost: 127.0.0.1:4242
|
BindAddress="0.0.0.0:4242"
|
||||||
#OPTIONAL (no authorization if token is empty)
|
#OPTIONAL (no authorization if token is empty)
|
||||||
Token="mytoken"
|
Token="mytoken"
|
||||||
Buffer=1000
|
Buffer=1000
|
||||||
|
@ -20,68 +147,11 @@ Requires the matterbridge config api section to be setup along these lines:
|
||||||
ShowJoinPart = true
|
ShowJoinPart = true
|
||||||
```
|
```
|
||||||
|
|
||||||
## Features
|
you need to know the ip / domain of the matterbridge and the token used,
|
||||||
|
enter them in the ´connection' section in the config and reload matterlink
|
||||||
|
|
||||||
* Custom bridge commands, including passthrough to MC!
|
|
||||||
Default commands: `help, tps, list, seed, uptime`
|
|
||||||
|
|
||||||
Commands are specified in JSON format as follows:
|
### Sample
|
||||||
Passthrough command (executes the configured command as if from the MC server console)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"alias": "tps",
|
|
||||||
"type": "PASSTHROUGH",
|
|
||||||
"execute": "forge tps",
|
|
||||||
"permLevel": 0,
|
|
||||||
"help": "Print server tps",
|
|
||||||
"allowArgs": false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Response command
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"alias": "uptime",
|
|
||||||
"type": "RESPONSE",
|
|
||||||
"response": "{uptime}",
|
|
||||||
"permLevel": 1,
|
|
||||||
"help": "Print server uptime",
|
|
||||||
"allowArgs": false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
* Command permissions!
|
|
||||||
Higher numbers mean more permissions. Configured on a network-by-network basis.
|
|
||||||
For IRC, this is your hostmask.
|
|
||||||
For Discord, this is your userid (NOT the four-digit number.)
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"irc.esper": {
|
|
||||||
"~DaMachina@hostname.com":1000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
* Edit and reload the config file without restarting the server!
|
|
||||||
```
|
|
||||||
/config <connect|disconnect|reload>
|
|
||||||
connect: Connects the MC chat to the MatterBridge server
|
|
||||||
disconnect: Disconnects the chat from the MatterBridge server
|
|
||||||
reload: Disconnects, reloads the config and custom command files,
|
|
||||||
then reconnects.
|
|
||||||
```
|
|
||||||
|
|
||||||
## Downloads
|
|
||||||
|
|
||||||
https://github.com/elytra/MatterLink/releases
|
|
||||||
|
|
||||||
https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/lastSuccessfulBuild/ - may be unstable
|
|
||||||
|
|
||||||
https://minecraft.curseforge.com/projects/matterlink
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
- forgelin: https://minecraft.curseforge.com/projects/shadowfacts-forgelin
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
Now you just need to run MatterBridge on the server, the default configuration works with the provided sample.
|
|
||||||
|
|
||||||
Install matterbridge and try out the basic sample:
|
Install matterbridge and try out the basic sample:
|
||||||
|
|
||||||
|
@ -91,9 +161,15 @@ mv matterbridge-sample.toml matterbridge.toml
|
||||||
matterbridge
|
matterbridge
|
||||||
```
|
```
|
||||||
|
|
||||||
now start the server with matterlink (and forgelin )in the mods folder
|
now start the server with matterlink (and forgelin) in the mods folder
|
||||||
|
|
||||||
|
and then [configure](https://github.com/42wim/matterbridge#configuration) all your needed gateways, endpoints etc
|
||||||
|
|
||||||
and then [RTFM!!!](https://github.com/42wim/matterbridge#configuration) and configure all your needed gateways, endpoints etc
|
### Building
|
||||||
|
|
||||||
powered by wishful thinking
|
```bash
|
||||||
|
git clone --recursive https://git.lain.faith/sorceress/MatterLink.git
|
||||||
|
cd MatterLink/
|
||||||
|
./gradlew setupDecompWorkspace
|
||||||
|
./gradlew build
|
||||||
|
```
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Replacement for guava
|
||||||
|
|
||||||
|
# using Fuel everywhere to simplify code
|
||||||
|
|
||||||
|
|
||||||
|
# Adittional player values
|
||||||
|
|
||||||
|
|
||||||
|
add optional feature:
|
||||||
|
GET json dictionary of player values like TEAM, NICK, TOWN
|
||||||
|
from url based on uuid / playername
|
||||||
|
|
||||||
|
config input: `http://rest.wurmcraft.com/user/find/{UUID}`
|
||||||
|
url: `http://rest.wurmcraft.com/user/find/148cf139-dd14-4bf4-97a2-08305dfef0a9`
|
53
build.gradle
53
build.gradle
|
@ -1,16 +1,28 @@
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath group: "org.jetbrains.kotlin", name: "kotlin-gradle-plugin", version: kotlinVersion
|
||||||
|
classpath group: "org.jetbrains.kotlin", name: "kotlin-serialization", version: kotlinVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.jvm" version '1.2.21'
|
|
||||||
id 'idea'
|
id 'idea'
|
||||||
|
id "org.sonarqube" version "2.6.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
apply plugin: "kotlin"
|
apply plugin: "kotlin"
|
||||||
|
apply plugin: "kotlinx-serialization"
|
||||||
apply plugin: "idea"
|
apply plugin: "idea"
|
||||||
|
|
||||||
if (System.env.BUILD_NUMBER) {
|
if (System.env.BUILD_NUMBER) {
|
||||||
mod_version += "-${System.env.BUILD_NUMBER}"
|
modVersion += "-${System.env.BUILD_NUMBER}"
|
||||||
} else if (!project.hasProperty('release')) {
|
} else if (!project.hasProperty('release')) {
|
||||||
mod_version += "-dev"
|
// modVersion += "-dev"
|
||||||
|
modVersion += "-dev"
|
||||||
}
|
}
|
||||||
|
|
||||||
idea {
|
idea {
|
||||||
|
@ -18,19 +30,44 @@ subprojects {
|
||||||
excludeDirs += [file("run")]
|
excludeDirs += [file("run")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (name == 'Jankson') {
|
||||||
if (name != "core") {
|
sonarqube {
|
||||||
|
skipProject = true
|
||||||
|
}
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
name = "unascribed"
|
name = "bintray"
|
||||||
url = 'http://unascribed.com/maven/releases'
|
url = "http://jcenter.bintray.com"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
name = "jitpack"
|
||||||
|
url = "https://jitpack.io"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = "kotlinx"
|
||||||
|
url = "https://kotlin.bintray.com/kotlinx/"
|
||||||
|
}
|
||||||
|
// maven {
|
||||||
|
// name = "elytradev"
|
||||||
|
// // url = 'http://unascribed.com/maven/releases'
|
||||||
|
// url = "https://repo.elytradev.com"
|
||||||
|
// }
|
||||||
maven {
|
maven {
|
||||||
name = "shadowfacts"
|
name = "shadowfacts"
|
||||||
url = "http://maven.shadowfacts.net/"
|
url = "http://maven.shadowfacts.net/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileTestKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
object MatterLink {
|
||||||
|
const val version = "1.6.5"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Kotlin {
|
||||||
|
const val version = "1.3.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Forgelin {
|
||||||
|
const val version = "1.8.0"
|
||||||
|
}
|
|
@ -1,28 +1,43 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.2.21'
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath group: "org.jetbrains.kotlin", name: "kotlin-gradle-plugin", version: kotlinVersion
|
||||||
|
classpath group: "com.github.jengelman.gradle.plugins", name: "shadow", version: shadowVersion
|
||||||
|
classpath group: 'com.vanniktech', name: 'gradle-dependency-graph-generator-plugin', version: '0.5.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
|
apply plugin: "com.vanniktech.dependency.graph.generator"
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
|
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
|
||||||
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3'
|
compile project(":Jankson")
|
||||||
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'
|
shadow(project(':Jankson')) { transitive = false }
|
||||||
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: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: project.kotlin_version
|
compile group: 'com.google.guava', name: 'guava', version: '+'
|
||||||
|
|
||||||
|
compile(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion)
|
||||||
|
shadow(group: "com.github.kittinunf.Fuel", name: "fuel", version: fuelVersion) { transitive = true }
|
||||||
|
compile(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion)
|
||||||
|
shadow(group: "com.github.kittinunf.Fuel", name: "fuel-coroutines", version: fuelVersion) { transitive = true }
|
||||||
|
compile(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion)
|
||||||
|
shadow(group: "com.github.kittinunf.Fuel", name: "fuel-kotlinx-serialization", version: fuelVersion) { transitive = true }
|
||||||
|
// compile(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion)
|
||||||
|
// shadow(group: 'com.github.kittinunf.result', name: 'result', version: resultVersion) { transitive = false }
|
||||||
|
|
||||||
|
// compile(group: "org.jetbrains.kotlinx", name: "kotlinx-coroutines-core", version: coroutinesVersion)
|
||||||
|
// shadow(group: "org.jetbrains.kotlinx", name: "kotlinx-coroutines-core", version: coroutinesVersion) { transitive = false }
|
||||||
|
|
||||||
|
compile(group: "org.jetbrains.kotlinx", name: "kotlinx-serialization-runtime", version: serializationVersion)
|
||||||
|
shadow(group: "org.jetbrains.kotlinx", name: "kotlinx-serialization-runtime", version: serializationVersion) { transitive = false }
|
||||||
|
|
||||||
|
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlinVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
@ -30,3 +45,14 @@ compileKotlin {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
classifier = ''
|
||||||
|
|
||||||
|
relocate 'blue.endless', 'matterlink.repack.blue.endless'
|
||||||
|
relocate 'com.github', 'matterlink.repack.com.github'
|
||||||
|
relocate 'kotlinx', 'matterlink.repack.kotlinx'
|
||||||
|
configurations = [project.configurations.shadow]
|
||||||
|
}
|
||||||
|
|
||||||
|
//tasks.build.dependsOn shadowJar
|
|
@ -0,0 +1,185 @@
|
||||||
|
package matterlink
|
||||||
|
|
||||||
|
import blue.endless.jankson.JsonObject
|
||||||
|
import blue.endless.jankson.impl.SyntaxError
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
fun JsonObject.parseDimensions(): List<Int> = getOrPutList("dimensions", emptyList(), "list of dimension ids")
|
||||||
|
fun JsonObject.parseAllDimensions(): Boolean = getOrDefault("allDimensions", false, "ignores dimension list")
|
||||||
|
|
||||||
|
sealed class Area {
|
||||||
|
abstract val type: String
|
||||||
|
abstract val dimensions: List<Int>
|
||||||
|
abstract val allDimensions: Boolean
|
||||||
|
|
||||||
|
abstract fun testInBounds(x: Int, y: Int, z: Int): Boolean
|
||||||
|
|
||||||
|
fun testForDim(dimension: Int?): Boolean {
|
||||||
|
if (allDimensions) return true
|
||||||
|
if (dimension == null) return false
|
||||||
|
return dimensions.contains(dimension)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
val type: String = jsonObj.getOrDefault("type", "INFINITE", "Area type identifier")
|
||||||
|
return when (type.toUpperCase()) {
|
||||||
|
"INFINITE" -> Infinite.parse(jsonObj)
|
||||||
|
"RADIUS" -> Radius.parse(jsonObj)
|
||||||
|
"SPHERE" -> Sphere.parse(jsonObj)
|
||||||
|
"BOX" -> Box.parse(jsonObj)
|
||||||
|
"SQUARE" -> Square.parse(jsonObj)
|
||||||
|
else -> throw SyntaxError("no Area type '$type' found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Infinite(
|
||||||
|
override val dimensions: List<Int> = listOf(),
|
||||||
|
override val allDimensions: Boolean = false
|
||||||
|
) : Area() {
|
||||||
|
override val type = "INFINITE"
|
||||||
|
|
||||||
|
override fun testInBounds(x: Int, y: Int, z: Int): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
return Infinite(
|
||||||
|
dimensions = jsonObj.parseDimensions(),
|
||||||
|
allDimensions = jsonObj.parseAllDimensions()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Radius(
|
||||||
|
override val dimensions: List<Int> = listOf(),
|
||||||
|
override val allDimensions: Boolean = false,
|
||||||
|
val x: Int,
|
||||||
|
val z: Int,
|
||||||
|
val radius: Int?
|
||||||
|
) : Area() {
|
||||||
|
override val type = "RADIUS"
|
||||||
|
|
||||||
|
override fun testInBounds(x: Int, y: Int, z: Int): Boolean {
|
||||||
|
if (radius == null) return true
|
||||||
|
return sqrt(((this.x - x) * (this.x - x)) + ((this.z - z) * (this.z - z)).toFloat()) < this.radius
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
|
||||||
|
return Radius(
|
||||||
|
dimensions = jsonObj.parseDimensions(),
|
||||||
|
allDimensions = jsonObj.parseAllDimensions(),
|
||||||
|
x = jsonObj.getOrDefault("x", 0),
|
||||||
|
z = jsonObj.getOrDefault("z", 0),
|
||||||
|
radius = jsonObj.getReified("radius")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sphere(
|
||||||
|
override val dimensions: List<Int> = listOf(),
|
||||||
|
override val allDimensions: Boolean = false,
|
||||||
|
val x: Int,
|
||||||
|
val y: Int,
|
||||||
|
val z: Int,
|
||||||
|
val radius: Int? = null
|
||||||
|
) : Area() {
|
||||||
|
override val type = "SPHERE"
|
||||||
|
|
||||||
|
override fun testInBounds(x: Int, y: Int, z: Int): Boolean {
|
||||||
|
if (radius == null) return true
|
||||||
|
return sqrt(((this.x - x) * (this.x - x)) + ((this.y - y) * (this.y - y)) + ((this.z - z) * (this.z - z)).toFloat()) < this.radius
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
|
||||||
|
return Sphere(
|
||||||
|
dimensions = jsonObj.parseDimensions(),
|
||||||
|
allDimensions = jsonObj.parseAllDimensions(),
|
||||||
|
x = jsonObj.getOrDefault("x", 0),
|
||||||
|
y = jsonObj.getOrDefault("y", 0),
|
||||||
|
z = jsonObj.getOrDefault("z", 0),
|
||||||
|
radius = jsonObj.getReified("radius")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Box(
|
||||||
|
override val dimensions: List<Int> = listOf(),
|
||||||
|
override val allDimensions: Boolean = false,
|
||||||
|
val x1: Int,
|
||||||
|
val x2: Int,
|
||||||
|
val y1: Int,
|
||||||
|
val y2: Int,
|
||||||
|
val z1: Int,
|
||||||
|
val z2: Int
|
||||||
|
) : Area() {
|
||||||
|
override val type = "BOX"
|
||||||
|
|
||||||
|
override fun testInBounds(x: Int, y: Int, z: Int): Boolean {
|
||||||
|
return x in x1..x2 && y in y1..y2 && z in z1..z2
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
|
||||||
|
return Box(
|
||||||
|
dimensions = jsonObj.parseDimensions(),
|
||||||
|
allDimensions = jsonObj.parseAllDimensions(),
|
||||||
|
x1 = jsonObj.getOrDefault("x1", 0),
|
||||||
|
x2 = jsonObj.getOrDefault("x2", 0),
|
||||||
|
y1 = jsonObj.getOrDefault("y1", 0),
|
||||||
|
y2 = jsonObj.getOrDefault("y2", 0),
|
||||||
|
z1 = jsonObj.getOrDefault("z1", 0),
|
||||||
|
z2 = jsonObj.getOrDefault("z2", 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Square(
|
||||||
|
override val dimensions: List<Int> = listOf(),
|
||||||
|
override val allDimensions: Boolean = false,
|
||||||
|
val x1: Int,
|
||||||
|
val x2: Int,
|
||||||
|
val z1: Int,
|
||||||
|
val z2: Int
|
||||||
|
) : Area() {
|
||||||
|
override val type = "SQUARE"
|
||||||
|
|
||||||
|
override fun testInBounds(x: Int, y: Int, z: Int): Boolean {
|
||||||
|
return x in x1..x2 && z in z1..z2
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun parse(jsonObj: JsonObject): Area {
|
||||||
|
|
||||||
|
return Square(
|
||||||
|
dimensions = jsonObj.parseDimensions(),
|
||||||
|
allDimensions = jsonObj.parseAllDimensions(),
|
||||||
|
x1 = jsonObj.getOrDefault("x1", 0),
|
||||||
|
x2 = jsonObj.getOrDefault("x2", 0),
|
||||||
|
z1 = jsonObj.getOrDefault("z1", 0),
|
||||||
|
z2 = jsonObj.getOrDefault("z2", 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// class FakePlayer (
|
||||||
|
// val x: Int,
|
||||||
|
// val y: Int,
|
||||||
|
// val z: Int,
|
||||||
|
// val name: String
|
||||||
|
// ): Area()
|
||||||
|
}
|
|
@ -1,46 +1,48 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandlerInst
|
||||||
import matterlink.bridge.command.BridgeCommandRegistry
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
|
import matterlink.bridge.command.IBridgeCommand
|
||||||
import matterlink.bridge.command.IMinecraftCommandSender
|
import matterlink.bridge.command.IMinecraftCommandSender
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.update.UpdateChecker
|
import matterlink.update.UpdateChecker
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
lateinit var logger: Logger
|
||||||
|
|
||||||
lateinit var instance: IMatterLink
|
lateinit var instance: IMatterLink
|
||||||
|
|
||||||
abstract class IMatterLink {
|
abstract class IMatterLink {
|
||||||
abstract val mcVersion: String
|
abstract val mcVersion: String
|
||||||
abstract val modVersion: String
|
abstract val modVersion: String
|
||||||
|
abstract val buildNumber: Int
|
||||||
abstract val forgeVersion: String
|
abstract val forgeVersion: String
|
||||||
|
|
||||||
abstract fun commandSenderFor(user: String, userId: String, server: String): IMinecraftCommandSender
|
abstract fun commandSenderFor(
|
||||||
|
user: String,
|
||||||
|
env: IBridgeCommand.CommandEnvironment,
|
||||||
|
op: Boolean
|
||||||
|
): IMinecraftCommandSender
|
||||||
|
|
||||||
abstract fun wrappedSendToPlayers(msg: String)
|
abstract fun wrappedSendToPlayers(msg: String)
|
||||||
|
|
||||||
|
abstract fun wrappedSendToPlayer(username: String, msg: String)
|
||||||
|
abstract fun wrappedSendToPlayer(uuid: UUID, msg: String)
|
||||||
|
abstract fun isOnline(username: String): Boolean
|
||||||
|
abstract fun nameToUUID(username: String): UUID?
|
||||||
|
abstract fun uuidToName(uuid: UUID): String?
|
||||||
|
|
||||||
fun start() {
|
suspend fun start() {
|
||||||
|
MessageHandlerInst.logger = logger
|
||||||
serverStartTime = System.currentTimeMillis()
|
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.check()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
suspend 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 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun trace(formatString: String, vararg data: Any) {
|
|
||||||
if (cfg.debug.logLevel == "TRACE")
|
|
||||||
log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,4 +74,7 @@ abstract class IMatterLink {
|
||||||
fun registerBridgeCommands() {
|
fun registerBridgeCommands() {
|
||||||
BridgeCommandRegistry.reloadCommands()
|
BridgeCommandRegistry.reloadCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract fun collectPlayers(area: Area): Set<UUID>
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package matterlink
|
||||||
|
|
||||||
|
interface Logger {
|
||||||
|
fun info(message: String)
|
||||||
|
fun debug(message: String)
|
||||||
|
fun error(message: String)
|
||||||
|
fun warn(message: String)
|
||||||
|
fun trace(message: String)
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
package matterlink
|
||||||
|
|
||||||
|
import blue.endless.jankson.Jankson
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 09/07/18.
|
||||||
|
* @author Nikky
|
||||||
|
*/
|
||||||
|
|
||||||
|
data class Paste(
|
||||||
|
val encrypted: Boolean = false,
|
||||||
|
val description: String,
|
||||||
|
val sections: List<PasteSection>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PasteSection(
|
||||||
|
val name: String,
|
||||||
|
val syntax: String = "text",
|
||||||
|
val contents: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PasteResponse(
|
||||||
|
val id: String,
|
||||||
|
val link: String
|
||||||
|
)
|
||||||
|
|
||||||
|
object PasteUtil {
|
||||||
|
private const val DEFAULT_KEY = "uKJoyicVJFnmpnrIZMklOURWxrCKXYaiBWOzPmvon"
|
||||||
|
|
||||||
|
private val jankson = Jankson.builder()
|
||||||
|
.registerTypeAdapter {
|
||||||
|
PasteResponse(
|
||||||
|
id = it.getReified("id") ?: "",
|
||||||
|
link = it.getReified<String>("link")
|
||||||
|
?.replace("\\/", "/")
|
||||||
|
?: "invalid"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// .registerSerializer { paste: Paste, marshaller: Marshaller ->
|
||||||
|
// JsonObject().apply {
|
||||||
|
// with(paste) {
|
||||||
|
// if (description.isNotBlank())
|
||||||
|
// this@apply["description"] = marshaller.serialize(description)
|
||||||
|
// if (encrypted)
|
||||||
|
// this@apply["encrypted"] = marshaller.serialize(encrypted)
|
||||||
|
// this@apply["sections"] = marshaller.serialize(sections)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .registerSerializer { section: PasteSection, marshaller: Marshaller ->
|
||||||
|
// JsonObject().apply {
|
||||||
|
// with(section) {
|
||||||
|
// if (name.isNotBlank())
|
||||||
|
// this@apply["name"] = marshaller.serialize(name)
|
||||||
|
// this@apply["syntax"] = marshaller.serialize(syntax)
|
||||||
|
// this@apply["contents"] = marshaller.serialize(contents.replace("\n", "\\n"))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
.build()
|
||||||
|
|
||||||
|
fun paste(paste: Paste, key: String = ""): PasteResponse {
|
||||||
|
val apiKey = key.takeIf { it.isNotBlank() } ?: DEFAULT_KEY
|
||||||
|
|
||||||
|
val url = URL("https://api.paste.ee/v1/pastes")
|
||||||
|
val http = url.openConnection() as HttpURLConnection
|
||||||
|
http.requestMethod = "POST"
|
||||||
|
http.doOutput = true
|
||||||
|
|
||||||
|
val out = jankson.toJson(paste)
|
||||||
|
.toJson(false, false)
|
||||||
|
.toByteArray()
|
||||||
|
|
||||||
|
http.setFixedLengthStreamingMode(out.size)
|
||||||
|
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
http.setRequestProperty("X-Auth-Token", apiKey)
|
||||||
|
http.connect()
|
||||||
|
http.outputStream.use { os ->
|
||||||
|
os.write(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
val textResponse = http.inputStream.bufferedReader().use { it.readText() }
|
||||||
|
logger.debug("response: $textResponse")
|
||||||
|
// val jsonObject = jankson.load(http.inputStream)
|
||||||
|
return jankson.fromJson(textResponse)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,14 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
|
import blue.endless.jankson.Jankson
|
||||||
|
import blue.endless.jankson.JsonArray
|
||||||
|
import blue.endless.jankson.JsonElement
|
||||||
|
import blue.endless.jankson.JsonObject
|
||||||
|
import blue.endless.jankson.impl.Marshaller
|
||||||
|
import matterlink.config.cfg
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.io.StringWriter
|
import java.io.StringWriter
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
private const val ZWSP: Char = '\u200b'
|
private const val ZWSP: Char = '\u200b'
|
||||||
|
|
||||||
|
@ -22,19 +29,121 @@ fun String.mapFormat(env: Map<String, String>): String {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.lazyFormat(env: Map<String, () -> String>): String {
|
fun String.lazyFormat(env: Map<String, () -> String?>): String {
|
||||||
var result = this
|
var result = this
|
||||||
env.forEach { key, value ->
|
env.forEach { key, value ->
|
||||||
if (result.contains(key)) {
|
if (result.contains(key)) {
|
||||||
result = result.replace(key, value())
|
result = result.replace(key, value().toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val String.stripColorOut: String
|
||||||
|
get() =
|
||||||
|
if (cfg.outgoing.stripColors)
|
||||||
|
this.replace("[&§][0-9A-FK-OR]".toRegex(RegexOption.IGNORE_CASE), "")
|
||||||
|
else
|
||||||
|
this
|
||||||
|
|
||||||
|
|
||||||
|
val String.stripColorIn: String
|
||||||
|
get() = if (cfg.incoming.stripColors)
|
||||||
|
this.replace("§.?".toRegex(), "")
|
||||||
|
else
|
||||||
|
this
|
||||||
|
|
||||||
|
|
||||||
val Exception.stackTraceString: String
|
val Exception.stackTraceString: String
|
||||||
get() {
|
get() {
|
||||||
val sw = StringWriter()
|
val sw = StringWriter()
|
||||||
this.printStackTrace(PrintWriter(sw))
|
this.printStackTrace(PrintWriter(sw))
|
||||||
return sw.toString()
|
return sw.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun randomString(length: Int = 6): String =
|
||||||
|
java.util.UUID.randomUUID().toString().replace("-", "").take(length)
|
||||||
|
|
||||||
|
fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T {
|
||||||
|
logger.trace("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default")
|
||||||
|
return putDefault(key, default, comment)!!.also {
|
||||||
|
setComment(key, comment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Jankson.fromJson(obj: JsonObject): T = this.fromJson(obj, T::class.java)
|
||||||
|
inline fun <reified T : Any> Jankson.fromJson(json: String): T = this.fromJson(json, T::class.java)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Jankson.Builder.registerTypeAdapter(noinline adapter: (JsonObject) -> T) =
|
||||||
|
this.registerTypeAdapter(T::class.java, adapter)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Jankson.Builder.registerPrimitiveTypeAdapter(noinline adapter: (Any) -> T) =
|
||||||
|
this.registerPrimitiveTypeAdapter(T::class.java, adapter)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Jankson.Builder.registerSerializer(noinline serializer: (T, Marshaller) -> JsonElement) =
|
||||||
|
this.registerSerializer(T::class.java, serializer)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Marshaller.registerSerializer(noinline serializer: (T) -> JsonElement) =
|
||||||
|
this.registerSerializer(T::class.java, serializer)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Marshaller.registerSerializer(noinline serializer: (T, Marshaller) -> JsonElement) =
|
||||||
|
this.registerSerializer(T::class.java, serializer)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> JsonObject.getReified(key: String, comment: String? = null): T? =
|
||||||
|
this.get(T::class.java, key)
|
||||||
|
?.also { setComment(key, comment) }
|
||||||
|
|
||||||
|
inline fun <reified T : Any> JsonObject.getReifiedOrDelete(key: String, comment: String? = null): T? =
|
||||||
|
this.get(T::class.java, key)
|
||||||
|
?.also { setComment(key, comment) }
|
||||||
|
?: run {
|
||||||
|
this.remove(key)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : Any> JsonObject.getList(key: String): List<T>? {
|
||||||
|
return this[key]?.let { array ->
|
||||||
|
when (array) {
|
||||||
|
is JsonArray -> {
|
||||||
|
array.indices.map { i ->
|
||||||
|
array.get(T::class.java, i) ?: throw NullPointerException("cannot parse ${array.get(i)}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : Any> JsonObject.getOrPutList(key: String, default: List<T>, comment: String?): List<T> {
|
||||||
|
return this[key]?.let { array ->
|
||||||
|
when (array) {
|
||||||
|
is JsonArray -> {
|
||||||
|
array.indices.map { i ->
|
||||||
|
array.get(T::class.java, i) ?: throw NullPointerException("cannot parse ${array.get(i)}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}.also {
|
||||||
|
setComment(key, comment)
|
||||||
|
} ?: this.putDefault(key, default, comment) ?: default
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : Any> JsonObject.getOrPutMap(
|
||||||
|
key: String,
|
||||||
|
default: Map<String, T>,
|
||||||
|
comment: String?
|
||||||
|
): Map<String, T> {
|
||||||
|
return this[key]?.let { map ->
|
||||||
|
when (map) {
|
||||||
|
is JsonObject -> {
|
||||||
|
map.mapValues { (key, element) ->
|
||||||
|
map.get(T::class.java, key) ?: throw NullPointerException("cannot parse $element")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}.also {
|
||||||
|
setComment(key, comment)
|
||||||
|
} ?: this.putDefault(key, default, comment) ?: default
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
package matterlink.api
|
||||||
|
|
||||||
|
import kotlinx.serialization.Encoder
|
||||||
|
import kotlinx.serialization.Optional
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Serializer
|
||||||
|
import kotlinx.serialization.json.JSON
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 07/05/18.
|
||||||
|
*
|
||||||
|
* @author Nikky
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Serializable
|
||||||
|
data class ApiMessage(
|
||||||
|
@Optional var username: String = "",
|
||||||
|
@Optional var text: String = "",
|
||||||
|
@Optional var gateway: String = "",
|
||||||
|
@Optional var timestamp: String = "",
|
||||||
|
@Optional var channel: String = "",
|
||||||
|
@Optional var userid: String = "",
|
||||||
|
@Optional var avatar: String = "",
|
||||||
|
@Optional var account: String = "",
|
||||||
|
@Optional var protocol: String = "",
|
||||||
|
@Optional var event: String = "",
|
||||||
|
@Optional var id: String = "",
|
||||||
|
@Optional var Extra: Map<String, String>? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun encode(): String {
|
||||||
|
return JSON.nonstrict.stringify(ApiMessage.serializer(), this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun toString(): String = encode()
|
||||||
|
|
||||||
|
@Serializer(forClass = ApiMessage::class)
|
||||||
|
companion object {
|
||||||
|
val USER_ACTION = "user_action"
|
||||||
|
val JOIN_LEAVE = "join_leave"
|
||||||
|
|
||||||
|
override fun serialize(output: Encoder, obj: ApiMessage) {
|
||||||
|
val elemOutput = output.beginStructure(descriptor)
|
||||||
|
obj.username.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 0, it)
|
||||||
|
}
|
||||||
|
obj.text.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 1, it)
|
||||||
|
}
|
||||||
|
obj.gateway.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 2, it)
|
||||||
|
}
|
||||||
|
obj.timestamp.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 3, it)
|
||||||
|
}
|
||||||
|
obj.channel.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 4, it)
|
||||||
|
}
|
||||||
|
obj.userid.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 5, it)
|
||||||
|
}
|
||||||
|
obj.avatar.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 6, it)
|
||||||
|
}
|
||||||
|
obj.account.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 7, it)
|
||||||
|
}
|
||||||
|
obj.protocol.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 8, it)
|
||||||
|
}
|
||||||
|
obj.event.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 9, it)
|
||||||
|
}
|
||||||
|
obj.id.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
elemOutput.encodeStringElement(descriptor, 10, it)
|
||||||
|
}
|
||||||
|
// obj.Extra.takeIf { ! it.isNullOrEmpty() }?.let {
|
||||||
|
// elemOutput.encodeStringElement(descriptor, 11, it)
|
||||||
|
// }
|
||||||
|
elemOutput.endStructure(descriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decode(input: String): ApiMessage {
|
||||||
|
return JSON.nonstrict.parse(ApiMessage.serializer(), input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package matterlink.api
|
||||||
|
|
||||||
|
data class Config(
|
||||||
|
var url: String = "",
|
||||||
|
var token: String = "",
|
||||||
|
var announceConnect: Boolean = true,
|
||||||
|
var announceDisconnect: Boolean = true,
|
||||||
|
var reconnectWait: Long = 500,
|
||||||
|
var systemUser: String = "Server"
|
||||||
|
)
|
|
@ -0,0 +1,240 @@
|
||||||
|
package matterlink.api
|
||||||
|
|
||||||
|
import com.github.kittinunf.fuel.core.FuelManager
|
||||||
|
import com.github.kittinunf.fuel.core.Method
|
||||||
|
import com.github.kittinunf.fuel.core.ResponseDeserializable
|
||||||
|
import com.github.kittinunf.fuel.core.extensions.cUrlString
|
||||||
|
import com.github.kittinunf.fuel.core.extensions.jsonBody
|
||||||
|
import com.github.kittinunf.fuel.coroutines.awaitStringResponseResult
|
||||||
|
import com.github.kittinunf.fuel.httpGet
|
||||||
|
import com.github.kittinunf.fuel.httpPost
|
||||||
|
import com.github.kittinunf.result.Result
|
||||||
|
import kotlinx.coroutines.CoroutineName
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.channels.SendChannel
|
||||||
|
import kotlinx.coroutines.channels.actor
|
||||||
|
import kotlinx.coroutines.channels.broadcast
|
||||||
|
import kotlinx.coroutines.channels.consumeEach
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.serialization.json.JSON
|
||||||
|
import kotlinx.serialization.list
|
||||||
|
import matterlink.Logger
|
||||||
|
import java.io.Reader
|
||||||
|
import java.net.ConnectException
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 07/05/18.
|
||||||
|
*
|
||||||
|
* @author Nikky
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
open class MessageHandler : CoroutineScope {
|
||||||
|
override val coroutineContext: CoroutineContext = Job()
|
||||||
|
private var enabled = false
|
||||||
|
|
||||||
|
private var connectErrors = 0
|
||||||
|
private var reconnectCooldown = 0L
|
||||||
|
private var sendErrors = 0
|
||||||
|
|
||||||
|
private var sendChannel: SendChannel<ApiMessage> = senderActor()
|
||||||
|
|
||||||
|
private val messageStream = Channel<ApiMessage>(Channel.UNLIMITED)
|
||||||
|
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||||
|
var broadcast: BroadcastChannel<ApiMessage> = broadcast {
|
||||||
|
while (true) {
|
||||||
|
val msg = messageStream.receive()
|
||||||
|
send(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
private val keepOpenManager = FuelManager().apply {
|
||||||
|
timeoutInMillisecond = 0
|
||||||
|
timeoutReadInMillisecond = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var config: Config = Config()
|
||||||
|
|
||||||
|
var logger = object : Logger {
|
||||||
|
override fun info(message: String) = println("INFO: $message")
|
||||||
|
override fun debug(message: String) = println("DEBUG: $message")
|
||||||
|
override fun error(message: String) = println("ERROR: $message")
|
||||||
|
override fun warn(message: String) = println("WARN: $message")
|
||||||
|
override fun trace(message: String) = println("TRACE: $message")
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun stop(message: String? = null) {
|
||||||
|
if (message != null && config.announceDisconnect) {
|
||||||
|
sendStatusUpdate(message)
|
||||||
|
}
|
||||||
|
enabled = false
|
||||||
|
rcvJob?.cancel()
|
||||||
|
rcvJob = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private var rcvJob: Job? = null
|
||||||
|
|
||||||
|
suspend fun start(message: String?, clear: Boolean) {
|
||||||
|
logger.debug("starting connection")
|
||||||
|
if (clear) {
|
||||||
|
clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
rcvJob = messageBroadcast()
|
||||||
|
|
||||||
|
if (message != null && config.announceConnect) {
|
||||||
|
sendStatusUpdate(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun clear() {
|
||||||
|
val url = "${config.url}/api/messages"
|
||||||
|
val (request, response, result) = url.httpGet()
|
||||||
|
.apply {
|
||||||
|
if (config.token.isNotEmpty()) {
|
||||||
|
headers["Authorization"] = "Bearer ${config.token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.awaitStringResponseResult()
|
||||||
|
|
||||||
|
when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
val messages: List<ApiMessage> = JSON.nonstrict.parse(ApiMessage.list, result.value)
|
||||||
|
messages.forEach { msg ->
|
||||||
|
logger.trace("skipping $msg")
|
||||||
|
}
|
||||||
|
logger.debug("skipped ${messages.count()} messages")
|
||||||
|
}
|
||||||
|
is Result.Failure -> {
|
||||||
|
logger.error("failed to clear messages")
|
||||||
|
logger.error("url: $url")
|
||||||
|
logger.error("cUrl: ${request.cUrlString()}")
|
||||||
|
logger.error("response: $response")
|
||||||
|
logger.error(result.error.exception.localizedMessage)
|
||||||
|
result.error.exception.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open suspend fun sendStatusUpdate(message: String) {
|
||||||
|
transmit(ApiMessage(text = message))
|
||||||
|
}
|
||||||
|
|
||||||
|
open suspend fun transmit(msg: ApiMessage) {
|
||||||
|
// if (streamConnection.isConnected || streamConnection.isConnecting) {
|
||||||
|
if (msg.username.isEmpty())
|
||||||
|
msg.username = config.systemUser
|
||||||
|
if (msg.gateway.isEmpty()) {
|
||||||
|
logger.error("missing gateway on message: $msg")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.debug("Transmitting: $msg")
|
||||||
|
sendChannel.send(msg)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("use coroutine api", level = DeprecationLevel.ERROR)
|
||||||
|
fun checkConnection() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseExperimental(ObsoleteCoroutinesApi::class)
|
||||||
|
private fun CoroutineScope.senderActor() = actor<ApiMessage>(context = Dispatchers.IO) {
|
||||||
|
consumeEach {
|
||||||
|
try {
|
||||||
|
logger.debug("sending $it")
|
||||||
|
val url = "${config.url}/api/message"
|
||||||
|
val (request, response, result) = url.httpPost()
|
||||||
|
.apply {
|
||||||
|
if (config.token.isNotEmpty()) {
|
||||||
|
headers["Authorization"] = "Bearer ${config.token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.jsonBody(it.encode())
|
||||||
|
.responseString()
|
||||||
|
when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
logger.debug("sent $it")
|
||||||
|
sendErrors = 0
|
||||||
|
}
|
||||||
|
is Result.Failure -> {
|
||||||
|
sendErrors++
|
||||||
|
logger.error("failed to deliver: $it")
|
||||||
|
logger.error("url: $url")
|
||||||
|
logger.error("cUrl: ${request.cUrlString()}")
|
||||||
|
logger.error("response: $response")
|
||||||
|
logger.error(result.error.exception.localizedMessage)
|
||||||
|
result.error.exception.printStackTrace()
|
||||||
|
// close()
|
||||||
|
throw result.error.exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (connectError: ConnectException) {
|
||||||
|
connectError.printStackTrace()
|
||||||
|
sendErrors++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CoroutineScope.messageBroadcast() = launch(context = Dispatchers.IO + CoroutineName("msgBroadcaster")) {
|
||||||
|
loop@ while (isActive) {
|
||||||
|
logger.info("opening connection")
|
||||||
|
val url = "${config.url}/api/stream"
|
||||||
|
val (request, response, result) = keepOpenManager.request(Method.GET, url)
|
||||||
|
.apply {
|
||||||
|
if (config.token.isNotEmpty()) {
|
||||||
|
headers["Authorization"] = "Bearer ${config.token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.responseObject(object : ResponseDeserializable<Unit> {
|
||||||
|
override fun deserialize(reader: Reader) =
|
||||||
|
runBlocking(Dispatchers.IO + CoroutineName("msgReceiver")) {
|
||||||
|
logger.info("connected successfully")
|
||||||
|
connectErrors = 0
|
||||||
|
reconnectCooldown = 0
|
||||||
|
|
||||||
|
reader.useLines { lines ->
|
||||||
|
lines.forEach { line ->
|
||||||
|
val msg = ApiMessage.decode(line)
|
||||||
|
logger.debug("received: $msg")
|
||||||
|
if (msg.event != "api_connect") {
|
||||||
|
messageStream.send(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
logger.info("connection closed")
|
||||||
|
}
|
||||||
|
is Result.Failure -> {
|
||||||
|
connectErrors++
|
||||||
|
reconnectCooldown = connectErrors * 1000L
|
||||||
|
logger.error("connectErrors: $connectErrors")
|
||||||
|
logger.error("connection error")
|
||||||
|
logger.error("curl: ${request.cUrlString()}")
|
||||||
|
logger.error(result.error.localizedMessage)
|
||||||
|
result.error.exception.printStackTrace()
|
||||||
|
if (connectErrors >= 10) {
|
||||||
|
logger.error("Caught too many errors, closing bridge")
|
||||||
|
stop("Interrupting connection to matterbridge API due to accumulated connection errors")
|
||||||
|
break@loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delay(reconnectCooldown) // reconnect delay in ms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
package matterlink.bridge
|
||||||
|
|
||||||
|
import matterlink.Paste
|
||||||
|
import matterlink.PasteSection
|
||||||
|
import matterlink.PasteUtil
|
||||||
|
import matterlink.antiping
|
||||||
|
import matterlink.api.ApiMessage
|
||||||
|
import matterlink.api.MessageHandler
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.handlers.ChatEvent
|
||||||
|
import matterlink.handlers.LocationHandler
|
||||||
|
import matterlink.mapFormat
|
||||||
|
import matterlink.stackTraceString
|
||||||
|
|
||||||
|
object MessageHandlerInst : MessageHandler() {
|
||||||
|
override suspend fun transmit(msg: ApiMessage) {
|
||||||
|
transmit(msg, cause = "")
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun sendStatusUpdate(message: String) {
|
||||||
|
LocationHandler.sendToLocations(
|
||||||
|
msg = message,
|
||||||
|
x = 0, y = 0, z = 0, dimension = null,
|
||||||
|
systemuser = true,
|
||||||
|
event = ChatEvent.STATUS,
|
||||||
|
cause = "status update message"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun transmit(msg: ApiMessage, cause: String, maxLines: Int = cfg.outgoing.inlineLimit) {
|
||||||
|
if (msg.username.isEmpty()) {
|
||||||
|
msg.username = cfg.outgoing.systemUser
|
||||||
|
|
||||||
|
if (msg.avatar.isEmpty() && cfg.outgoing.avatar.enable) {
|
||||||
|
msg.avatar = cfg.outgoing.avatar.systemUserAvatar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (msg.gateway.isEmpty()) {
|
||||||
|
logger.error("dropped message '$msg' due to missing gateway")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.text.lines().count() >= maxLines) {
|
||||||
|
try {
|
||||||
|
val response = PasteUtil.paste(
|
||||||
|
Paste(
|
||||||
|
description = cause,
|
||||||
|
sections = listOf(
|
||||||
|
PasteSection(
|
||||||
|
name = "log.txt",
|
||||||
|
syntax = "text",
|
||||||
|
contents = msg.text
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
msg.text = msg.text.substringBefore('\n')
|
||||||
|
.take(25) + "... " + response.link
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.error(cause)
|
||||||
|
logger.error(e.stackTraceString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.transmit(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,43 +0,0 @@
|
||||||
package matterlink.bridge
|
|
||||||
|
|
||||||
import matterlink.bridge.command.BridgeCommandRegistry
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import matterlink.instance
|
|
||||||
|
|
||||||
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 (nextMessage != null && nextMessage.gateway == cfg.connect.gateway) {
|
|
||||||
if (!nextMessage.text.isBlank()) {
|
|
||||||
val message = when (nextMessage.event) {
|
|
||||||
"user_action" -> nextMessage.format(cfg.incoming.action)
|
|
||||||
"" -> {
|
|
||||||
// try to handle command and do not handle as a chat message
|
|
||||||
if (BridgeCommandRegistry.handleCommand(nextMessage)) return
|
|
||||||
nextMessage.format(cfg.incoming.chat)
|
|
||||||
}
|
|
||||||
"join_leave" -> nextMessage.format(cfg.incoming.joinPart)
|
|
||||||
else -> {
|
|
||||||
val user = nextMessage.username
|
|
||||||
val text = nextMessage.text
|
|
||||||
val json = nextMessage.encode()
|
|
||||||
instance.debug("Threw out message with unhandled event: ${nextMessage.event}")
|
|
||||||
instance.debug(" Message contents:")
|
|
||||||
instance.debug(" User: $user")
|
|
||||||
instance.debug(" Text: $text")
|
|
||||||
instance.debug(" JSON: $json")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instance.wrappedSendToPlayers(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package matterlink.bridge.command
|
||||||
|
|
||||||
|
import matterlink.config.AuthRequest
|
||||||
|
import matterlink.config.IdentitiesConfig
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.instance
|
||||||
|
import matterlink.randomString
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
object AuthBridgeCommand : IBridgeCommand() {
|
||||||
|
val syntax = "Syntax: auth [username]"
|
||||||
|
override val help: String = "Requests authentication on the bridge. $syntax"
|
||||||
|
override val permLevel: Double
|
||||||
|
get() = cfg.command.defaultPermUnauthenticated
|
||||||
|
|
||||||
|
override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
|
||||||
|
if (env !is CommandEnvironment.BridgeEnv) {
|
||||||
|
env.respond("please initiate authentication from linked external chat")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val uuid = env.uuid
|
||||||
|
if (uuid != null) {
|
||||||
|
val name = instance.uuidToName(uuid)
|
||||||
|
env.respond("you are already authenticated as name: $name uuid: $uuid")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val argList = args.split(' ', limit = 2)
|
||||||
|
val target = argList.getOrNull(0) ?: run {
|
||||||
|
env.respond(
|
||||||
|
"no username/uuid provided\n" +
|
||||||
|
syntax
|
||||||
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetUserName = target
|
||||||
|
|
||||||
|
val targetUUid: String = instance.nameToUUID(target)?.toString() ?: run {
|
||||||
|
try {
|
||||||
|
targetUserName = instance.uuidToName(UUID.fromString(target)) ?: run {
|
||||||
|
env.respond("cannot find player by username/uuid $target")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
env.respond("invalid username/uuid $target")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
target
|
||||||
|
}
|
||||||
|
|
||||||
|
val online = instance.isOnline(targetUserName)
|
||||||
|
if (!online) {
|
||||||
|
env.respond("$targetUserName is not online, please log in and try again to send instructions")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val nonce = randomString(length = 3).toUpperCase()
|
||||||
|
|
||||||
|
val requestId = user.toLowerCase()
|
||||||
|
instance.wrappedSendToPlayer(targetUserName, "have you requested authentication with the MatterLink system?")
|
||||||
|
instance.wrappedSendToPlayer(targetUserName, "if yes please execute /auth accept $user $nonce")
|
||||||
|
instance.wrappedSendToPlayer(targetUserName, "otherwise you may ignore this message")
|
||||||
|
|
||||||
|
|
||||||
|
IdentitiesConfig.authRequests.put(
|
||||||
|
requestId,
|
||||||
|
AuthRequest(
|
||||||
|
username = targetUserName,
|
||||||
|
uuid = targetUUid,
|
||||||
|
nonce = nonce,
|
||||||
|
platform = env.platform,
|
||||||
|
userid = env.userId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
env.respond("please accept the authentication request ingame, do not share the code")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,33 +1,89 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import matterlink.api.ApiMessage
|
||||||
import matterlink.config.CommandConfig
|
import matterlink.config.CommandConfig
|
||||||
|
import matterlink.config.IdentitiesConfig
|
||||||
import matterlink.config.PermissionConfig
|
import matterlink.config.PermissionConfig
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.instance
|
import matterlink.logger
|
||||||
import java.util.*
|
import java.util.HashMap
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
object BridgeCommandRegistry {
|
object BridgeCommandRegistry {
|
||||||
|
|
||||||
private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
|
private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
|
||||||
|
|
||||||
fun handleCommand(input: ApiMessage): Boolean {
|
/**
|
||||||
if (!cfg.command.enable) return false
|
*
|
||||||
if (input.text[0] != cfg.command.prefix[0] || input.text.length < 2) return false
|
* @return consume message flag
|
||||||
|
*/
|
||||||
|
suspend fun handleCommand(input: ApiMessage): Boolean {
|
||||||
|
if (!cfg.command.enable || input.text.isBlank()) return false
|
||||||
|
|
||||||
|
if (input.text[0] != cfg.command.prefix || input.text.length < 2) return false
|
||||||
|
|
||||||
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
||||||
val args = if (cmd.size == 2) cmd[1] else ""
|
val args = if (cmd.size == 2) cmd[1] else ""
|
||||||
|
|
||||||
return commandMap[cmd[0]]?.execute(cmd[0], input.username, input.userid, input.account, args) ?: false
|
val uuid = IdentitiesConfig.getUUID(input.account, input.userid)
|
||||||
|
|
||||||
|
val env = IBridgeCommand.CommandEnvironment.BridgeEnv(
|
||||||
|
input.username,
|
||||||
|
input.userid,
|
||||||
|
input.account,
|
||||||
|
input.gateway,
|
||||||
|
uuid
|
||||||
|
)
|
||||||
|
return commandMap[cmd[0]]?.let {
|
||||||
|
if (!it.reachedTimeout()) {
|
||||||
|
logger.debug("dropped command ${it.alias}")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.preExecute() // resets the tickCounter
|
||||||
|
if (!it.canExecute(uuid)) {
|
||||||
|
env.respond(
|
||||||
|
text = "${input.username} is not permitted to perform command: ${cmd[0]}"
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.execute(cmd[0], input.username, env, args)
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun handleCommand(text: String, username: String, uuid: UUID): Boolean {
|
||||||
|
if (!cfg.command.enable || text.isBlank()) return false
|
||||||
|
|
||||||
|
if (text[0] != cfg.command.prefix || text.length < 2) return false
|
||||||
|
|
||||||
|
val cmd = text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
||||||
|
val args = if (cmd.size == 2) cmd[1] else ""
|
||||||
|
|
||||||
|
val env = IBridgeCommand.CommandEnvironment.GameEnv(username, uuid)
|
||||||
|
|
||||||
|
return commandMap[cmd[0]]?.let {
|
||||||
|
if (!it.reachedTimeout()) {
|
||||||
|
logger.debug("dropped command ${it.alias}")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
it.preExecute() // resets the tickCounter
|
||||||
|
if (!it.canExecute(uuid)) {
|
||||||
|
env.respond(
|
||||||
|
text = "$username is not permitted to perform command: ${cmd[0]}"
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
it.execute(cmd[0], username, env, args)
|
||||||
|
} ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun register(alias: String, cmd: IBridgeCommand): Boolean {
|
fun register(alias: String, cmd: IBridgeCommand): Boolean {
|
||||||
if (alias.isBlank() || commandMap.containsKey(alias)) {
|
if (alias.isBlank() || commandMap.containsKey(alias)) {
|
||||||
instance.error("Failed to register command: '${alias}'")
|
logger.error("Failed to register command: '$alias'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!cmd.validate()) {
|
if (!cmd.validate()) {
|
||||||
instance.error("Failed to validate command: '${alias}'")
|
logger.error("Failed to validate command: '$alias'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//TODO: maybe write alias to command here ?
|
//TODO: maybe write alias to command here ?
|
||||||
|
@ -44,7 +100,7 @@ object BridgeCommandRegistry {
|
||||||
return if (help.isNotBlank()) help else "No help for '$cmd'"
|
return if (help.isNotBlank()) help else "No help for '$cmd'"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCommandList(permLvl: Int): String {
|
fun getCommandList(permLvl: Double): String {
|
||||||
return commandMap
|
return commandMap
|
||||||
.filterValues {
|
.filterValues {
|
||||||
it.permLevel <= permLvl
|
it.permLevel <= permLvl
|
||||||
|
@ -55,9 +111,15 @@ object BridgeCommandRegistry {
|
||||||
|
|
||||||
fun reloadCommands() {
|
fun reloadCommands() {
|
||||||
commandMap.clear()
|
commandMap.clear()
|
||||||
val permStatus = PermissionConfig.loadPermFile()
|
|
||||||
register("help", HelpCommand)
|
register("help", HelpCommand)
|
||||||
val cmdStatus = CommandConfig.readConfig()
|
if (cfg.command.authRequests)
|
||||||
|
register("auth", AuthBridgeCommand)
|
||||||
|
if (cfg.command.permisionRequests)
|
||||||
|
register("request", RequestPermissionsCommand)
|
||||||
|
PermissionConfig.loadFile()
|
||||||
|
CommandConfig.loadFile()
|
||||||
|
IdentitiesConfig.loadFile()
|
||||||
|
|
||||||
CommandConfig.commands.forEach { (alias, command) ->
|
CommandConfig.commands.forEach { (alias, command) ->
|
||||||
register(alias, command)
|
register(alias, command)
|
||||||
}
|
}
|
||||||
|
@ -66,9 +128,10 @@ object BridgeCommandRegistry {
|
||||||
operator fun get(command: String) = commandMap[command]
|
operator fun get(command: String) = commandMap[command]
|
||||||
|
|
||||||
fun getName(command: IBridgeCommand): String? {
|
fun getName(command: IBridgeCommand): String? {
|
||||||
commandMap.forEach{(alias, cmd) ->
|
commandMap.forEach { (alias, cmd) ->
|
||||||
if(command == cmd) return alias
|
if (command == cmd) return alias
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,49 +1,45 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.handlers.TickHandler
|
|
||||||
import matterlink.instance
|
import matterlink.instance
|
||||||
import matterlink.lazyFormat
|
import matterlink.lazyFormat
|
||||||
|
import matterlink.logger
|
||||||
|
import matterlink.stripColorIn
|
||||||
|
|
||||||
data class CustomCommand(
|
data class CustomCommand(
|
||||||
val type: CommandType = CommandType.RESPONSE,
|
val type: CommandType = CommandType.RESPONSE,
|
||||||
val execute: String = "",
|
val execute: String? = null,
|
||||||
val response: String = "",
|
val response: String? = null,
|
||||||
override val permLevel: Int = 0,
|
override val permLevel: Double = 0.0,
|
||||||
override val help: String = "",
|
override val help: String = "",
|
||||||
val allowArgs: Boolean = true,
|
override val timeout: Int = 20,
|
||||||
val timeout: Int = 20
|
val defaultCommand: Boolean? = null,
|
||||||
) : IBridgeCommand {
|
val execOp: Boolean? = null,
|
||||||
val alias: String
|
val argumentsRegex: Regex? = null
|
||||||
get() = BridgeCommandRegistry.getName(this)!!
|
) : IBridgeCommand() {
|
||||||
|
|
||||||
var lastUsed: Int = 0
|
override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
|
||||||
override fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean {
|
if (argumentsRegex != null) {
|
||||||
if (!allowArgs && args.isNotBlank()) return false
|
logger.debug("testing '$args' against '${argumentsRegex.pattern}'")
|
||||||
|
if (!argumentsRegex.matches(args)) {
|
||||||
if (TickHandler.tickCounter - lastUsed < timeout)
|
env.respond("$user sent invalid input to command $alias")
|
||||||
{
|
|
||||||
instance.debug("dropped command $alias")
|
|
||||||
return true //eat command silently
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!canExecute(userId, server)) {
|
|
||||||
MessageHandler.transmit(ApiMessage(text = "$user is not permitted to perform command: $alias"))
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lastUsed = TickHandler.tickCounter
|
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
CommandType.EXECUTE -> {
|
CommandType.EXECUTE -> {
|
||||||
//uses a new commandsender for each user
|
// uses a new commandsender for each use
|
||||||
// TODO: cache CommandSenders
|
val commandSender = instance.commandSenderFor(user, env, execOp ?: false)
|
||||||
val commandSender = instance.commandSenderFor(user, userId, server)
|
val cmd = execute?.lazyFormat(getReplacements(user, env, args))?.stripColorIn
|
||||||
commandSender.execute("$execute $args") || commandSender.reply.isNotBlank()
|
?: return false
|
||||||
|
commandSender.execute(cmd) || commandSender.reply.isNotEmpty()
|
||||||
}
|
}
|
||||||
CommandType.RESPONSE -> {
|
CommandType.RESPONSE -> {
|
||||||
MessageHandler.transmit(ApiMessage(text = response.lazyFormat(getReplacements(user, userId, server, args))))
|
env.respond(
|
||||||
|
response?.lazyFormat(getReplacements(user, env, args))
|
||||||
|
?: "", cause = "response to command: $alias"
|
||||||
|
)
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,8 +50,8 @@ data class CustomCommand(
|
||||||
*/
|
*/
|
||||||
override fun validate(): Boolean {
|
override fun validate(): Boolean {
|
||||||
val typeCheck = when (type) {
|
val typeCheck = when (type) {
|
||||||
CommandType.EXECUTE -> execute.isNotBlank()
|
CommandType.EXECUTE -> execute?.isNotBlank() ?: false
|
||||||
CommandType.RESPONSE -> response.isNotBlank()
|
CommandType.RESPONSE -> response?.isNotBlank() ?: false
|
||||||
}
|
}
|
||||||
if (!typeCheck) return false
|
if (!typeCheck) return false
|
||||||
|
|
||||||
|
@ -63,13 +59,37 @@ data class CustomCommand(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val DEFAULT = CustomCommand()
|
||||||
|
|
||||||
fun getReplacements(user: String, userId: String, server: String, args: String): Map<String, () -> String> = mapOf(
|
fun getReplacements(user: String, env: CommandEnvironment, args: String): Map<String, () -> String?> = mapOf(
|
||||||
"{uptime}" to instance::getUptimeAsString,
|
"{uptime}" to instance::getUptimeAsString,
|
||||||
"{user}" to { user },
|
"{user}" to { user },
|
||||||
"{userid}" to { userId },
|
"{userid}" to {
|
||||||
"{server}" to { server },
|
when (env) {
|
||||||
"{args}" to { args }
|
is CommandEnvironment.BridgeEnv -> env.userId
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"{uuid}" to {
|
||||||
|
when (env) {
|
||||||
|
is CommandEnvironment.BridgeEnv -> env.uuid.toString()
|
||||||
|
is CommandEnvironment.GameEnv -> env.uuid.toString()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"{username}" to {
|
||||||
|
when (env) {
|
||||||
|
is CommandEnvironment.BridgeEnv -> env.uuid
|
||||||
|
is CommandEnvironment.GameEnv -> env.uuid
|
||||||
|
}?.let { instance.uuidToName(it) }
|
||||||
|
},
|
||||||
|
"{platform}" to {
|
||||||
|
when (env) {
|
||||||
|
is CommandEnvironment.BridgeEnv -> env.platform
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"{args}" to { args },
|
||||||
|
"{version}" to { instance.modVersion }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
|
||||||
object HelpCommand : IBridgeCommand {
|
object HelpCommand : IBridgeCommand() {
|
||||||
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
|
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
|
||||||
override val permLevel = 0
|
override val permLevel: Double
|
||||||
override fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean {
|
get() = cfg.command.defaultPermUnauthenticated
|
||||||
|
|
||||||
|
override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
|
||||||
val msg: String = when {
|
val msg: String = when {
|
||||||
args.isEmpty() ->
|
args.isEmpty() ->
|
||||||
"Available commands: ${BridgeCommandRegistry.getCommandList(IBridgeCommand.getPermLevel(userId, server))}"
|
"Available commands: ${BridgeCommandRegistry.getCommandList(IBridgeCommand.getPermLevel(env.uuid))}"
|
||||||
else -> args.split(" ", ignoreCase = false)
|
else -> args.split(" ", ignoreCase = false)
|
||||||
.joinToString(separator = "\n") {
|
.joinToString(separator = "\n") {
|
||||||
"$it: ${BridgeCommandRegistry.getHelpString(it)}"
|
"$it: ${BridgeCommandRegistry.getHelpString(it)}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessageHandler.transmit(ApiMessage(text = msg))
|
env.respond(
|
||||||
|
text = msg,
|
||||||
|
cause = "Help Requested $args"
|
||||||
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,92 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
|
import matterlink.api.ApiMessage
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
import matterlink.config.PermissionConfig
|
import matterlink.config.PermissionConfig
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.handlers.TickHandler
|
||||||
|
import matterlink.instance
|
||||||
|
import matterlink.logger
|
||||||
|
import matterlink.stripColorOut
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
interface IBridgeCommand {
|
abstract class IBridgeCommand {
|
||||||
val help: String
|
abstract val help: String
|
||||||
val permLevel: Int
|
abstract val permLevel: Double
|
||||||
|
open val timeout: Int = 20
|
||||||
|
|
||||||
fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean
|
sealed class CommandEnvironment {
|
||||||
|
abstract val uuid: UUID?
|
||||||
|
abstract val username: String?
|
||||||
|
|
||||||
fun canExecute(userId: String, server: String): Boolean {
|
data class BridgeEnv(
|
||||||
return getPermLevel(userId, server) >= permLevel
|
val name: String,
|
||||||
|
val userId: String,
|
||||||
|
val platform: String,
|
||||||
|
val gateway: String,
|
||||||
|
override val uuid: UUID?
|
||||||
|
) : CommandEnvironment() {
|
||||||
|
override val username: String?
|
||||||
|
get() = uuid?.let { instance.uuidToName(uuid) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validate() = true
|
data class GameEnv(
|
||||||
|
override val username: String,
|
||||||
|
override val uuid: UUID
|
||||||
|
) : CommandEnvironment()
|
||||||
|
|
||||||
|
suspend fun respond(text: String, cause: String = "") {
|
||||||
|
when (this) {
|
||||||
|
is BridgeEnv -> {
|
||||||
|
MessageHandlerInst.transmit(
|
||||||
|
ApiMessage(
|
||||||
|
gateway = this.gateway,
|
||||||
|
text = text.stripColorOut
|
||||||
|
),
|
||||||
|
cause = cause
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is GameEnv -> {
|
||||||
|
instance.wrappedSendToPlayer(uuid, text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private var lastUsed: Int = 0
|
||||||
|
|
||||||
|
val alias: String
|
||||||
|
get() = BridgeCommandRegistry.getName(this)!!
|
||||||
|
|
||||||
|
fun reachedTimeout(): Boolean {
|
||||||
|
return (TickHandler.tickCounter - lastUsed > timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun preExecute() {
|
||||||
|
lastUsed = TickHandler.tickCounter
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return consume message flag
|
||||||
|
*/
|
||||||
|
abstract suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean
|
||||||
|
|
||||||
|
fun canExecute(uuid: UUID?): Boolean {
|
||||||
|
logger.trace("canExecute this: $this uuid: $uuid permLevel: $permLevel")
|
||||||
|
val canExec = getPermLevel(uuid) >= permLevel
|
||||||
|
logger.trace("canExecute return $canExec")
|
||||||
|
return canExec
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun validate() = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getPermLevel(userId: String, server: String): Int {
|
fun getPermLevel(uuid: UUID?): Double {
|
||||||
if (PermissionConfig.perms[server] == null) return 0
|
if (uuid == null) return cfg.command.defaultPermUnauthenticated
|
||||||
return PermissionConfig.perms[server]?.get(userId) ?: 0
|
return PermissionConfig.perms[uuid.toString()] ?: cfg.command.defaultPermAuthenticated
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,6 @@
|
||||||
package matterlink.bridge.command
|
package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
abstract class IMinecraftCommandSender(val user: String, val env: IBridgeCommand.CommandEnvironment, val op: Boolean) {
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import matterlink.instance
|
|
||||||
|
|
||||||
abstract class IMinecraftCommandSender(val user: String, val userId: String, val server: String) {
|
|
||||||
/**
|
/**
|
||||||
* @param cmdString The command to execute with its arguments
|
* @param cmdString The command to execute with its arguments
|
||||||
*
|
*
|
||||||
|
@ -13,20 +8,38 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
|
||||||
*/
|
*/
|
||||||
abstract fun execute(cmdString: String): Boolean
|
abstract fun execute(cmdString: String): Boolean
|
||||||
|
|
||||||
val accountName = "$user (id=$userId server=$server)"
|
val displayName = env.username ?: user
|
||||||
|
val accountName = when (env) {
|
||||||
|
is IBridgeCommand.CommandEnvironment.BridgeEnv -> "$user (id=${env.userId} platform=${env.platform}${env.uuid?.let { " uuid=$it" }
|
||||||
|
?: ""}${env.username?.let { " username=$it" } ?: ""})"
|
||||||
|
is IBridgeCommand.CommandEnvironment.GameEnv -> "$user (username=${env.username} uuid=${env.uuid})"
|
||||||
|
}
|
||||||
|
|
||||||
fun canExecute(commandName: String): Boolean {
|
fun canExecute(commandName: String): Boolean {
|
||||||
|
if (op) return true
|
||||||
val command = BridgeCommandRegistry[commandName] ?: return false
|
val command = BridgeCommandRegistry[commandName] ?: return false
|
||||||
|
return command.canExecute(env.uuid)
|
||||||
return command.canExecute(userId, server)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var reply: String = ""
|
private var finished = true
|
||||||
|
val reply = mutableListOf<String>()
|
||||||
|
|
||||||
fun sendReply(text: String) {
|
/**
|
||||||
reply = text
|
* accumulates response
|
||||||
MessageHandler.transmit(ApiMessage(
|
*/
|
||||||
text = text
|
fun appendReply(text: String) {
|
||||||
))
|
if (finished) {
|
||||||
|
reply.clear()
|
||||||
|
finished = false
|
||||||
|
}
|
||||||
|
reply += text
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun sendReply(cmdString: String) {
|
||||||
|
env.respond(
|
||||||
|
text = reply.joinToString("\n"),
|
||||||
|
cause = "executed command: $cmdString"
|
||||||
|
)
|
||||||
|
finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package matterlink.bridge.command
|
||||||
|
|
||||||
|
import matterlink.config.PermissionConfig
|
||||||
|
import matterlink.config.PermissionRequest
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.randomString
|
||||||
|
|
||||||
|
object RequestPermissionsCommand : IBridgeCommand() {
|
||||||
|
val syntax = " Syntax: request [permissionLevel]"
|
||||||
|
override val help: String = "Requests permissions on the bridge. $syntax"
|
||||||
|
override val permLevel: Double
|
||||||
|
get() = cfg.command.defaultPermAuthenticated
|
||||||
|
|
||||||
|
override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
|
||||||
|
|
||||||
|
val uuid = env.uuid
|
||||||
|
if (uuid == null) {
|
||||||
|
env.respond("$user is not authenticated ($env)")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val argList = args.split(' ', limit = 2)
|
||||||
|
val requestedLevelArg = argList.getOrNull(0)
|
||||||
|
val requestedLevel = requestedLevelArg?.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
it.toDoubleOrNull() ?: run {
|
||||||
|
env.respond(
|
||||||
|
"cannot parse permlevel '$requestedLevelArg'\n" +
|
||||||
|
syntax
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val nonce = randomString(length = 3).toUpperCase()
|
||||||
|
|
||||||
|
val requestId = user.toLowerCase()
|
||||||
|
|
||||||
|
PermissionConfig.permissionRequests.put(
|
||||||
|
requestId,
|
||||||
|
PermissionRequest(uuid = uuid, user = user, nonce = nonce, powerlevel = requestedLevel)
|
||||||
|
)
|
||||||
|
env.respond("please ask a op to accept your permission elevation with `/ml permAccept $requestId $nonce [permLevel]`")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,41 +0,0 @@
|
||||||
package matterlink.command
|
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.bridge.command.BridgeCommandRegistry
|
|
||||||
import matterlink.config.cfg
|
|
||||||
import matterlink.instance
|
|
||||||
|
|
||||||
object CommandCore {
|
|
||||||
fun getName() = "bridge"
|
|
||||||
|
|
||||||
fun getAliases() = listOf("BRIDGE", "bridge")
|
|
||||||
|
|
||||||
fun getUsage() = "bridge <connect|disconnect|reload>"
|
|
||||||
|
|
||||||
fun execute(args: Array<String>): String {
|
|
||||||
val cmd = args[0].toLowerCase()
|
|
||||||
|
|
||||||
return when (cmd) {
|
|
||||||
"connect" -> {
|
|
||||||
MessageHandler.start(message = "Bridge connected by console")
|
|
||||||
"Attempting bridge connection!"
|
|
||||||
}
|
|
||||||
"disconnect" -> {
|
|
||||||
MessageHandler.stop(message = "Bridge disconnected by console")
|
|
||||||
"Bridge disconnected!"
|
|
||||||
}
|
|
||||||
"reload" -> {
|
|
||||||
if (MessageHandler.connected) MessageHandler.stop(message = "Bridge restarting (reload command issued by console)")
|
|
||||||
cfg = cfg.load()
|
|
||||||
BridgeCommandRegistry.reloadCommands()
|
|
||||||
if (!MessageHandler.connected) MessageHandler.start(message = "Bridge reconnected")
|
|
||||||
"Bridge config reloaded!"
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
"Invalid arguments for command!"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package matterlink.command
|
||||||
|
|
||||||
|
import matterlink.config.IdentitiesConfig
|
||||||
|
|
||||||
|
object CommandCoreAuth {
|
||||||
|
val name = "auth"
|
||||||
|
|
||||||
|
val aliases = listOf("authenticate")
|
||||||
|
|
||||||
|
val usage = "auth <accept|reject> <id> <code>"
|
||||||
|
|
||||||
|
fun execute(args: Array<String>, user: String, uuid: String?): String {
|
||||||
|
val cmd = args[0].toLowerCase()
|
||||||
|
|
||||||
|
return when (cmd) {
|
||||||
|
"accept" -> {
|
||||||
|
val requestId = args.getOrNull(1)?.toLowerCase() ?: run {
|
||||||
|
return "no requestId passed"
|
||||||
|
}
|
||||||
|
val request = IdentitiesConfig.authRequests.getIfPresent(requestId.toLowerCase()) ?: run {
|
||||||
|
return "No request available"
|
||||||
|
}
|
||||||
|
val nonce = args.getOrNull(2)?.toUpperCase() ?: run {
|
||||||
|
return "no code passed"
|
||||||
|
}
|
||||||
|
if (request.nonce != nonce) {
|
||||||
|
return "nonce in request does not match"
|
||||||
|
}
|
||||||
|
if (request.username != user) {
|
||||||
|
return "username in request does not match ${request.username} != $user"
|
||||||
|
}
|
||||||
|
if (request.uuid != uuid) {
|
||||||
|
return "uuid in request does not match ${request.uuid} != $uuid"
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentitiesConfig.add(
|
||||||
|
request.uuid,
|
||||||
|
request.username,
|
||||||
|
request.platform,
|
||||||
|
request.userid,
|
||||||
|
"Accepted by $user"
|
||||||
|
)
|
||||||
|
|
||||||
|
IdentitiesConfig.authRequests.invalidate(requestId)
|
||||||
|
"${request.userid} on ${request.platform} is now identified as $user"
|
||||||
|
}
|
||||||
|
"reject" -> {
|
||||||
|
|
||||||
|
val requestId = args.getOrNull(1)?.toLowerCase() ?: run {
|
||||||
|
return "no requestId passed"
|
||||||
|
}
|
||||||
|
val request = IdentitiesConfig.authRequests.getIfPresent(requestId.toLowerCase()) ?: run {
|
||||||
|
return "No request available"
|
||||||
|
}
|
||||||
|
val nonce = args.getOrNull(2)?.toUpperCase() ?: run {
|
||||||
|
return "no code passed"
|
||||||
|
}
|
||||||
|
if (request.nonce != nonce) {
|
||||||
|
return "nonce in request does not match"
|
||||||
|
}
|
||||||
|
if (request.username != user) {
|
||||||
|
return "username in request does not match ${request.username} != $user"
|
||||||
|
}
|
||||||
|
if (request.uuid != uuid) {
|
||||||
|
return "uuid in request does not match ${request.uuid} != $uuid"
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentitiesConfig.authRequests.invalidate(requestId)
|
||||||
|
"request $nonce for ${request.userid} on ${request.platform} was invalidated"
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
"Invalid arguments for command! \n" +
|
||||||
|
"usage: $usage"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package matterlink.command
|
||||||
|
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
|
import matterlink.config.PermissionConfig
|
||||||
|
import matterlink.config.baseCfg
|
||||||
|
import matterlink.config.cfg
|
||||||
|
|
||||||
|
object CommandCoreML {
|
||||||
|
val name = "ml"
|
||||||
|
|
||||||
|
val aliases = listOf("matterlink")
|
||||||
|
|
||||||
|
val usage = "ml <connect|disconnect|reload|permAccept>"
|
||||||
|
|
||||||
|
suspend fun execute(args: Array<String>, user: String, uuid: String?): String {
|
||||||
|
val cmd = args[0].toLowerCase()
|
||||||
|
|
||||||
|
return when (cmd) {
|
||||||
|
"connect" -> {
|
||||||
|
MessageHandlerInst.start("Bridge connected by console", true)
|
||||||
|
"Attempting bridge connection!"
|
||||||
|
}
|
||||||
|
"disconnect" -> {
|
||||||
|
MessageHandlerInst.stop("Bridge disconnected by console")
|
||||||
|
"Bridge disconnected!"
|
||||||
|
}
|
||||||
|
"reload" -> {
|
||||||
|
// if (MessageHandlerInst.connected)
|
||||||
|
MessageHandlerInst.stop("Bridge restarting (reload command issued by console)")
|
||||||
|
cfg = baseCfg.load()
|
||||||
|
BridgeCommandRegistry.reloadCommands()
|
||||||
|
// if (!MessageHandlerInst.connected)
|
||||||
|
MessageHandlerInst.start("Bridge reconnected", false)
|
||||||
|
"Bridge config reloaded!"
|
||||||
|
}
|
||||||
|
"permaccept" -> {
|
||||||
|
val requestId = args.getOrNull(1)?.toLowerCase() ?: run {
|
||||||
|
return "no requestId passed"
|
||||||
|
}
|
||||||
|
val request = PermissionConfig.permissionRequests.getIfPresent(requestId.toLowerCase()) ?: run {
|
||||||
|
return "No request available"
|
||||||
|
}
|
||||||
|
val nonce = args.getOrNull(2)?.toUpperCase() ?: run {
|
||||||
|
return "no code passed"
|
||||||
|
}
|
||||||
|
if (request.nonce != nonce) {
|
||||||
|
return "nonce in request does not match with $nonce"
|
||||||
|
}
|
||||||
|
val powerLevelArg = args.getOrNull(3)?.toDoubleOrNull()
|
||||||
|
val powerLevel = powerLevelArg ?: run { return "permLevel cannot be parsed: ${args.getOrNull(3)}" }
|
||||||
|
?: request.powerlevel
|
||||||
|
?: return "no permLevel provided"
|
||||||
|
PermissionConfig.add(request.uuid, powerLevel, "${request.user} Authorized by $user")
|
||||||
|
PermissionConfig.permissionRequests.invalidate(requestId)
|
||||||
|
"added ${request.user} (uuid: ${request.uuid}) with power level: $powerLevel"
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
"Invalid arguments for command! \n" +
|
||||||
|
"usage: ${CommandCoreAuth.usage}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,92 +1,202 @@
|
||||||
package matterlink.config
|
package matterlink.config
|
||||||
|
|
||||||
|
import blue.endless.jankson.Jankson
|
||||||
|
import blue.endless.jankson.JsonObject
|
||||||
|
import blue.endless.jankson.impl.Marshaller
|
||||||
|
import blue.endless.jankson.impl.SyntaxError
|
||||||
|
import matterlink.Area
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
|
import matterlink.getOrDefault
|
||||||
|
import matterlink.getOrPutList
|
||||||
|
import matterlink.getReifiedOrDelete
|
||||||
|
import matterlink.logger
|
||||||
|
import matterlink.registerSerializer
|
||||||
|
import matterlink.registerTypeAdapter
|
||||||
|
import matterlink.stackTraceString
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.regex.Pattern
|
import java.io.FileNotFoundException
|
||||||
|
|
||||||
lateinit var cfg: BaseConfig
|
lateinit var cfg: BaseConfig.MatterLinkConfig
|
||||||
|
lateinit var baseCfg: BaseConfig
|
||||||
|
|
||||||
abstract class BaseConfig(rootDir: File) {
|
data class BaseConfig(val rootDir: File) {
|
||||||
val cfgDirectory: File = rootDir.resolve("matterlink")
|
val cfgDirectory: File = rootDir.resolve("matterlink")
|
||||||
val mainCfgFile: File = cfgDirectory.resolve("matterlink.cfg")
|
val configFile: File = cfgDirectory.resolve("matterlink.hjson")
|
||||||
|
|
||||||
|
init {
|
||||||
|
logger.info("Reading bridge blueprints... from $rootDir")
|
||||||
|
baseCfg = this
|
||||||
|
}
|
||||||
|
|
||||||
var connect = ConnectOptions()
|
data class MatterLinkConfig(
|
||||||
var debug = DebugOptions()
|
val connect: ConnectOptions = ConnectOptions(),
|
||||||
var incoming = IncomingOption()
|
val outgoingDefaults: DefaultSettingsOutgoing = DefaultSettingsOutgoing(),
|
||||||
var outgoing = OutgoingOptions()
|
val incomingDefaults: DefaultSettingsIncoming = DefaultSettingsIncoming(),
|
||||||
var command = CommandOptions()
|
val locations: List<Location> = listOf(
|
||||||
var update = UpdateOptions()
|
Location(
|
||||||
|
label = "default",
|
||||||
|
gateway = "minecraft",
|
||||||
|
area = Area.Infinite(dimensions = listOf(-1, 0, 1), allDimensions = true),
|
||||||
|
outgoing = SettingsOutgoing(
|
||||||
|
plain = true,
|
||||||
|
action = true,
|
||||||
|
join = true,
|
||||||
|
leave = true,
|
||||||
|
advancement = true,
|
||||||
|
death = true,
|
||||||
|
broadcast = true,
|
||||||
|
status = true
|
||||||
|
),
|
||||||
|
incoming = SettingsIncoming(
|
||||||
|
plain = true,
|
||||||
|
action = true,
|
||||||
|
join_leave = true,
|
||||||
|
commands = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
val incoming: IncomingOptions = IncomingOptions(),
|
||||||
|
val outgoing: OutgoingOptions = OutgoingOptions(),
|
||||||
|
val command: CommandOptions = CommandOptions(),
|
||||||
|
val update: UpdateOptions = UpdateOptions()
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DefaultSettingsOutgoing(
|
||||||
|
val plain: Boolean = true,
|
||||||
|
val action: Boolean = true,
|
||||||
|
val join: Boolean = false,
|
||||||
|
val leave: Boolean = false,
|
||||||
|
val advancement: Boolean = false,
|
||||||
|
val death: Boolean = false,
|
||||||
|
val broadcast: Boolean = false,
|
||||||
|
val status: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SettingsOutgoing(
|
||||||
|
val plain: Boolean? = null,
|
||||||
|
val action: Boolean? = null,
|
||||||
|
val join: Boolean? = null,
|
||||||
|
val leave: Boolean? = null,
|
||||||
|
val advancement: Boolean? = null,
|
||||||
|
val death: Boolean? = null,
|
||||||
|
val broadcast: Boolean? = null,
|
||||||
|
val status: Boolean? = null,
|
||||||
|
val skip: List<String> = listOf()
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DefaultSettingsIncoming(
|
||||||
|
val plain: Boolean = true,
|
||||||
|
val action: Boolean = true,
|
||||||
|
val join_leave: Boolean = true,
|
||||||
|
val commands: Boolean = true
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SettingsIncoming(
|
||||||
|
val plain: Boolean? = null,
|
||||||
|
val action: Boolean? = null,
|
||||||
|
val join_leave: Boolean? = null,
|
||||||
|
val commands: Boolean? = null,
|
||||||
|
val skip: List<String> = listOf()
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Location(
|
||||||
|
val label: String = "unlabeled",
|
||||||
|
val gateway: String = "",
|
||||||
|
val area: Area = Area.Infinite(),
|
||||||
|
val outgoing: SettingsOutgoing = SettingsOutgoing(),
|
||||||
|
val incoming: SettingsIncoming = SettingsIncoming()
|
||||||
|
)
|
||||||
|
|
||||||
data class CommandOptions(
|
data class CommandOptions(
|
||||||
val prefix: String = "$",
|
val prefix: Char = '!',
|
||||||
val enable: Boolean = true
|
val enable: Boolean = true,
|
||||||
|
val authRequests: Boolean = true,
|
||||||
|
val permisionRequests: Boolean = true,
|
||||||
|
val defaultPermUnauthenticated: Double = 0.0,
|
||||||
|
val defaultPermAuthenticated: Double = 1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ConnectOptions(
|
data class ConnectOptions(
|
||||||
val url: String = "http://localhost:4242",
|
val url: String = "http://localhost:4242",
|
||||||
val authToken: String = "",
|
val authToken: String = "",
|
||||||
val gateway: String = "minecraft",
|
val autoConnect: Boolean = true,
|
||||||
val autoConnect: Boolean = true
|
val reconnectWait: Long = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
data class DebugOptions(
|
data class IncomingOptions(
|
||||||
var logLevel: String = "INFO"
|
|
||||||
)
|
|
||||||
|
|
||||||
data class IncomingOption(
|
|
||||||
val chat: String = "<{username}> {text}",
|
val chat: String = "<{username}> {text}",
|
||||||
val joinPart: String = "§6-- {username} {text}",
|
val joinPart: String = "§6-- {username} {text}",
|
||||||
val action: String = "§5* {username} {text}"
|
val action: String = "§5* {username} {text}",
|
||||||
|
val stripColors: Boolean = true
|
||||||
)
|
)
|
||||||
|
|
||||||
data class OutgoingOptions(
|
data class OutgoingOptions(
|
||||||
val systemUser: String = "Server",
|
val systemUser: String = "Server",
|
||||||
//outgoing toggles
|
//outgoing toggles
|
||||||
var announceConnect: Boolean = true,
|
val announceConnect: Boolean = true,
|
||||||
var announceDisconnect: Boolean = true,
|
val announceDisconnect: Boolean = true,
|
||||||
val advancements: Boolean = true,
|
val advancements: Boolean = true,
|
||||||
var death: DeathOptions = DeathOptions(),
|
val stripColors: Boolean = true,
|
||||||
|
val pasteEEKey: String = "",
|
||||||
|
val inlineLimit: Int = 5,
|
||||||
|
|
||||||
var joinPart: JoinPartOptions = JoinPartOptions()
|
val joinPart: JoinPartOptions = JoinPartOptions(),
|
||||||
|
var avatar: AvatarOptions = AvatarOptions(),
|
||||||
|
val death: DeathOptions = DeathOptions()
|
||||||
)
|
)
|
||||||
|
|
||||||
data class DeathOptions(
|
data class DeathOptions(
|
||||||
val enable: Boolean = true,
|
val enable: Boolean = true,
|
||||||
val damageType: Boolean = true,
|
val damageType: Boolean = true,
|
||||||
val damageTypeMapping: Map<String, String> = mapOf(
|
val damageTypeMapping: Map<String, Array<String>> = mapOf(
|
||||||
"inFire" to "\uD83D\uDD25", //🔥
|
"inFire" to arrayOf("\uD83D\uDD25"), //🔥
|
||||||
"lightningBolt" to "\uD83C\uDF29", //🌩
|
"lightningBolt" to arrayOf("\uD83C\uDF29"), //🌩
|
||||||
"onFire" to "\uD83D\uDD25", //🔥
|
"onFire" to arrayOf("\uD83D\uDD25"), //🔥
|
||||||
"lava" to "\uD83D\uDD25", //🔥
|
"lava" to arrayOf("\uD83D\uDD25"), //🔥
|
||||||
"hotFloor" to "♨️",
|
"hotFloor" to arrayOf("♨️"),
|
||||||
"inWall" to "",
|
"inWall" to arrayOf(),
|
||||||
"cramming" to "",
|
"cramming" to arrayOf(),
|
||||||
"drown" to "\uD83C\uDF0A", //🌊
|
"drown" to arrayOf("\uD83C\uDF0A"), //🌊
|
||||||
"starve" to "\uD83D\uDC80", //💀
|
"starve" to arrayOf("\uD83D\uDC80"), //💀
|
||||||
"cactus" to "\uD83C\uDF35", //🌵
|
"cactus" to arrayOf("\uD83C\uDF35"), //🌵
|
||||||
"fall" to "\u2BEF️", //⯯️
|
"fall" to arrayOf("\u2BEF️"), //⯯️
|
||||||
"flyIntoWall" to "\uD83D\uDCA8", //💨
|
"flyIntoWall" to arrayOf("\uD83D\uDCA8"), //💨
|
||||||
"outOfWorld" to "\u2734", //✴
|
"outOfWorld" to arrayOf("\u2734"), //✴
|
||||||
"generic" to "\uD83D\uDC7B", //👻
|
"generic" to arrayOf("\uD83D\uDC7B"), //👻
|
||||||
"magic" to "✨ ⚚",
|
"magic" to arrayOf("✨", "⚚"),
|
||||||
"indirectMagic" to "✨ ⚚",
|
"indirectMagic" to arrayOf("✨", "⚚"),
|
||||||
"wither" to "\uD83D\uDD71", //🕱
|
"wither" to arrayOf("\uD83D\uDD71"), //🕱
|
||||||
"anvil" to "",
|
"anvil" to arrayOf(),
|
||||||
"fallingBlock" to "",
|
"fallingBlock" to arrayOf(),
|
||||||
"dragonBreath" to "\uD83D\uDC32", //🐲
|
"dragonBreath" to arrayOf("\uD83D\uDC32"), //🐲
|
||||||
"fireworks" to "\uD83C\uDF86", //🎆
|
"fireworks" to arrayOf("\uD83C\uDF86"), //🎆
|
||||||
|
|
||||||
"mob" to "\uD83D\uDC80", //💀
|
"mob" to arrayOf("\uD83D\uDC80"), //💀
|
||||||
"player" to "\uD83D\uDDE1", //🗡
|
"player" to arrayOf("\uD83D\uDDE1"), //🗡
|
||||||
"arrow" to "\uD83C\uDFF9", //🏹
|
"arrow" to arrayOf("\uD83C\uDFF9"), //🏹
|
||||||
"thrown" to "彡°",
|
"thrown" to arrayOf("彡°"),
|
||||||
"thorns" to "\uD83C\uDF39", //🌹
|
"thorns" to arrayOf("\uD83C\uDF39"), //🌹
|
||||||
"explosion" to "\uD83D\uDCA3 \uD83D\uDCA5", //💣 💥
|
"explosion" to arrayOf("\uD83D\uDCA3", "\uD83D\uDCA5"), //💣 💥
|
||||||
"explosion.player" to "\uD83D\uDCA3 \uD83D\uDCA5" //💣 💥
|
"explosion.player" to arrayOf("\uD83D\uDCA3", "\uD83D\uDCA5"), //💣 💥
|
||||||
|
"ieWireShock" to arrayOf("\uD83D\uDD0C", "\u26A1"), //🔌 ⚡
|
||||||
|
"immersiverailroading:hitByTrain" to arrayOf(
|
||||||
|
"\uD83D\uDE82",
|
||||||
|
"\uD83D\uDE83",
|
||||||
|
"\uD83D\uDE84",
|
||||||
|
"\uD83D\uDE85",
|
||||||
|
"\uD83D\uDE87",
|
||||||
|
"\uD83D\uDE88",
|
||||||
|
"\uD83D\uDE8A"
|
||||||
|
) //🚂 🚃 🚄 🚅 🚇 🚈 🚊
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class AvatarOptions(
|
||||||
|
val enable: Boolean = true,
|
||||||
|
val urlTemplate: String = "https://mc-heads.net/head/{uuid}",
|
||||||
|
val systemUserAvatar: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
data class JoinPartOptions(
|
data class JoinPartOptions(
|
||||||
val enable: Boolean = true,
|
val enable: Boolean = true,
|
||||||
val joinServer: String = "{username:antiping} has connected to the server",
|
val joinServer: String = "{username:antiping} has connected to the server",
|
||||||
|
@ -97,206 +207,508 @@ abstract class BaseConfig(rootDir: File) {
|
||||||
val enable: Boolean = true
|
val enable: Boolean = true
|
||||||
)
|
)
|
||||||
|
|
||||||
protected fun load(
|
companion object {
|
||||||
getBoolean: (key: String, category: String, default: Boolean, comment: String) -> Boolean,
|
val jankson = Jankson
|
||||||
getString: (key: String, category: String, default: String, comment: String) -> String,
|
.builder()
|
||||||
getStringValidated: (key: String, category: String, default: String, comment: String, pattern: Pattern) -> String,
|
.registerTypeAdapter {
|
||||||
getStringValidValues: (key: String, category: String, default: String, comment: String, validValues: Array<String>) -> String,
|
with(MatterLinkConfig()) {
|
||||||
getStringList: (name: String, category: String, defaultValues: Array<String>, comment: String) -> Array<String>,
|
MatterLinkConfig(
|
||||||
addCustomCategoryComment: (key: String, comment: String) -> Unit
|
command = it.getOrDefault(
|
||||||
) {
|
"command",
|
||||||
|
command,
|
||||||
|
"User commands"
|
||||||
|
),
|
||||||
|
outgoingDefaults = it.getOrDefault(
|
||||||
|
"outgoingDefaults",
|
||||||
|
outgoingDefaults,
|
||||||
|
"default settings for outgoing"
|
||||||
|
),
|
||||||
|
incomingDefaults = it.getOrDefault(
|
||||||
|
"incomingDefaults",
|
||||||
|
incomingDefaults,
|
||||||
|
"default settings for incoming"
|
||||||
|
),
|
||||||
|
locations = it.getOrPutList(
|
||||||
|
"locations",
|
||||||
|
locations,
|
||||||
|
"list of fixed chat locations"
|
||||||
|
),
|
||||||
|
connect = it.getOrDefault(
|
||||||
|
"connect",
|
||||||
|
connect,
|
||||||
|
"Connection Settings"
|
||||||
|
),
|
||||||
|
incoming = it.getOrDefault(
|
||||||
|
"incoming",
|
||||||
|
incoming,
|
||||||
|
"""
|
||||||
|
Gateway -> Server
|
||||||
|
Options all about receiving messages from the API
|
||||||
|
Formatting options:
|
||||||
|
Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}
|
||||||
|
""".trimIndent()
|
||||||
|
),
|
||||||
|
outgoing = it.getOrDefault(
|
||||||
|
"outgoing",
|
||||||
|
outgoing,
|
||||||
|
"""
|
||||||
|
Server -> Gateway
|
||||||
|
Options all about sending messages to the API
|
||||||
|
""".trimIndent()
|
||||||
|
),
|
||||||
|
update = it.getOrDefault(
|
||||||
|
"update",
|
||||||
|
update,
|
||||||
|
"Update Settings"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(DefaultSettingsOutgoing()) {
|
||||||
|
DefaultSettingsOutgoing(
|
||||||
|
plain = it.getOrDefault(
|
||||||
|
"plain",
|
||||||
|
plain,
|
||||||
|
"plain text messages"
|
||||||
|
),
|
||||||
|
action = it.getOrDefault(
|
||||||
|
"action",
|
||||||
|
action,
|
||||||
|
"action messages"
|
||||||
|
),
|
||||||
|
join = it.getOrDefault(
|
||||||
|
"join",
|
||||||
|
join,
|
||||||
|
"handle join event"
|
||||||
|
),
|
||||||
|
leave = it.getOrDefault(
|
||||||
|
"leave",
|
||||||
|
leave,
|
||||||
|
"handle leave events"
|
||||||
|
),
|
||||||
|
advancement = it.getOrDefault(
|
||||||
|
"advancement",
|
||||||
|
advancement,
|
||||||
|
"handle advancement events"
|
||||||
|
),
|
||||||
|
death = it.getOrDefault(
|
||||||
|
"death",
|
||||||
|
death,
|
||||||
|
"handle death events"
|
||||||
|
),
|
||||||
|
broadcast = it.getOrDefault(
|
||||||
|
"broadcast",
|
||||||
|
broadcast,
|
||||||
|
"handle broadcast command"
|
||||||
|
),
|
||||||
|
status = it.getOrDefault(
|
||||||
|
"status",
|
||||||
|
status,
|
||||||
|
"handles tatus updates"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(SettingsOutgoing()) {
|
||||||
|
SettingsOutgoing(
|
||||||
|
plain = it.getReifiedOrDelete("plain", "transmit join events"),
|
||||||
|
action = it.getReifiedOrDelete("action", "transmit join events"),
|
||||||
|
join = it.getReifiedOrDelete("join", "transmit join events"),
|
||||||
|
leave = it.getReifiedOrDelete("leave", "transmit leave events"),
|
||||||
|
advancement = it.getReifiedOrDelete("advancement", "transmit advancements"),
|
||||||
|
death = it.getReifiedOrDelete("death", "transmit death messages"),
|
||||||
|
broadcast = it.getReifiedOrDelete("say", "transmit broadcasts"),
|
||||||
|
status = it.getReifiedOrDelete("status", "transmit status updates"),
|
||||||
|
skip = it.getOrPutList(
|
||||||
|
"skip",
|
||||||
|
skip,
|
||||||
|
"list of other locations to ignore after handling this"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var category = "commands"
|
.registerTypeAdapter {
|
||||||
|
with(DefaultSettingsIncoming()) {
|
||||||
addCustomCategoryComment(category, "User commands")
|
DefaultSettingsIncoming(
|
||||||
command = CommandOptions(
|
plain = it.getOrDefault(
|
||||||
enable = getBoolean(
|
"plain",
|
||||||
|
plain,
|
||||||
|
"plain text messages"
|
||||||
|
),
|
||||||
|
action = it.getOrDefault(
|
||||||
|
"action",
|
||||||
|
action,
|
||||||
|
"action messages"
|
||||||
|
),
|
||||||
|
join_leave = it.getOrDefault(
|
||||||
|
"join_leave",
|
||||||
|
join_leave,
|
||||||
|
"handle join/leave event"
|
||||||
|
),
|
||||||
|
commands = it.getOrDefault(
|
||||||
|
"commands",
|
||||||
|
join_leave,
|
||||||
|
"receive commands"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(SettingsIncoming()) {
|
||||||
|
SettingsIncoming(
|
||||||
|
plain = it.getReifiedOrDelete("plain", "transmit join events"),
|
||||||
|
action = it.getReifiedOrDelete("action", "transmit join events"),
|
||||||
|
join_leave = it.getReifiedOrDelete("join_leave", "transmit join_leave events"),
|
||||||
|
commands = it.getReifiedOrDelete("commands", "receive commands"),
|
||||||
|
skip = it.getOrPutList(
|
||||||
|
"skip",
|
||||||
|
skip,
|
||||||
|
"list of other locations to ignore after handling this"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(Location()) {
|
||||||
|
Location(
|
||||||
|
label = it.getOrDefault(
|
||||||
|
"label",
|
||||||
|
label,
|
||||||
|
"location label for identification"
|
||||||
|
),
|
||||||
|
gateway = it.getOrDefault(
|
||||||
|
"gateway",
|
||||||
|
gateway,
|
||||||
|
"matterbridge gateway identifier"
|
||||||
|
),
|
||||||
|
area = Area.parse(it.getObject("area") ?: JsonObject()),
|
||||||
|
outgoing = it.getOrDefault(
|
||||||
|
"outgoing",
|
||||||
|
outgoing,
|
||||||
|
"Location outgoing settings"
|
||||||
|
),
|
||||||
|
incoming = it.getOrDefault(
|
||||||
|
"incoming",
|
||||||
|
incoming,
|
||||||
|
"incoming settings"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(CommandOptions()) {
|
||||||
|
CommandOptions(
|
||||||
|
enable = it.getOrDefault(
|
||||||
"enable",
|
"enable",
|
||||||
category,
|
enable,
|
||||||
command.enable,
|
|
||||||
"Enable MC bridge commands"
|
"Enable MC bridge commands"
|
||||||
),
|
),
|
||||||
prefix = getStringValidated(
|
prefix = it.getOrDefault(
|
||||||
"prefix",
|
"prefix",
|
||||||
category,
|
prefix,
|
||||||
command.prefix,
|
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)"
|
||||||
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)",
|
|
||||||
Pattern.compile("^[^0-9A-Za-z/]$")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
category = "connection"
|
|
||||||
addCustomCategoryComment(category, "Connection settings")
|
|
||||||
connect = ConnectOptions(
|
|
||||||
url = getString(
|
|
||||||
"connectURL",
|
|
||||||
category,
|
|
||||||
connect.url,
|
|
||||||
"The URL or IP address of the bridge server"
|
|
||||||
),
|
),
|
||||||
authToken = getString(
|
authRequests = it.getOrDefault(
|
||||||
|
"authRequests",
|
||||||
|
authRequests,
|
||||||
|
"Enable the 'auth' command for linking chat accounts to uuid / ingame account"
|
||||||
|
),
|
||||||
|
permisionRequests = it.getOrDefault(
|
||||||
|
"permisionRequests",
|
||||||
|
authRequests,
|
||||||
|
"Enable the 'request' command for requestion permissions from chat"
|
||||||
|
),
|
||||||
|
defaultPermUnauthenticated = it.getOrDefault(
|
||||||
|
"defaultPermUnauthenticated",
|
||||||
|
defaultPermUnauthenticated,
|
||||||
|
"default permission level for unauthenticated players"
|
||||||
|
),
|
||||||
|
defaultPermAuthenticated = it.getOrDefault(
|
||||||
|
"defaultPermAuthenticated",
|
||||||
|
defaultPermAuthenticated,
|
||||||
|
"default permission level for players that hve linked their accounts"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(ConnectOptions()) {
|
||||||
|
ConnectOptions(
|
||||||
|
url = it.getOrDefault(
|
||||||
|
"url",
|
||||||
|
url,
|
||||||
|
"The URL or IP address of the bridge platform"
|
||||||
|
),
|
||||||
|
authToken = it.getOrDefault(
|
||||||
"authToken",
|
"authToken",
|
||||||
category,
|
authToken,
|
||||||
connect.authToken,
|
"Auth token used to connect to the bridge platform"
|
||||||
"Auth token used to connect to the bridge server"
|
|
||||||
),
|
),
|
||||||
gateway = getString(
|
autoConnect = it.getOrDefault(
|
||||||
"gateway",
|
|
||||||
category,
|
|
||||||
connect.gateway,
|
|
||||||
"MatterBridge gateway"
|
|
||||||
),
|
|
||||||
autoConnect = getBoolean(
|
|
||||||
"autoConnect",
|
"autoConnect",
|
||||||
category,
|
autoConnect,
|
||||||
connect.autoConnect,
|
|
||||||
"Connect the relay on startup"
|
"Connect the relay on startup"
|
||||||
|
),
|
||||||
|
reconnectWait = it.getOrDefault(
|
||||||
|
"reconnectWait",
|
||||||
|
reconnectWait,
|
||||||
|
"base delay in milliseconds between attempting reconnects"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
category = "debug"
|
}
|
||||||
addCustomCategoryComment(category, "Options to help you figure out what happens and why, because computers can be silly")
|
.registerTypeAdapter {
|
||||||
debug = DebugOptions(
|
with(IncomingOptions()) {
|
||||||
logLevel = getStringValidValues(
|
IncomingOptions(
|
||||||
"logLevel",
|
chat = it.getOrDefault(
|
||||||
category,
|
|
||||||
debug.logLevel,
|
|
||||||
"MatterLink log level",
|
|
||||||
arrayOf("INFO", "DEBUG", "TRACE")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
category = "incoming"
|
|
||||||
addCustomCategoryComment(category, "Gateway -> Server" +
|
|
||||||
"\nOptions all about receiving messages from the API" +
|
|
||||||
"\nFormatting options: " +
|
|
||||||
"\nAvailable variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
|
|
||||||
incoming = IncomingOption(
|
|
||||||
chat = getString(
|
|
||||||
"chat",
|
"chat",
|
||||||
category,
|
chat,
|
||||||
incoming.chat,
|
|
||||||
"Generic chat event, just talking"
|
"Generic chat event, just talking"
|
||||||
),
|
),
|
||||||
joinPart = getString(
|
joinPart = it.getOrDefault(
|
||||||
"joinPart",
|
"joinPart",
|
||||||
category,
|
joinPart,
|
||||||
incoming.joinPart,
|
|
||||||
"Join and part events from other gateways"
|
"Join and part events from other gateways"
|
||||||
),
|
),
|
||||||
action = getString(
|
action = it.getOrDefault(
|
||||||
"action",
|
"action",
|
||||||
category,
|
action,
|
||||||
incoming.action,
|
|
||||||
"User actions (/me) sent by users from other gateways"
|
"User actions (/me) sent by users from other gateways"
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
category = "outgoing"
|
|
||||||
addCustomCategoryComment(category, "Server -> Gateway" +
|
|
||||||
"\nOptions all about sending messages to the API")
|
|
||||||
|
|
||||||
outgoing = OutgoingOptions(
|
|
||||||
systemUser = getString(
|
|
||||||
"systemUser",
|
|
||||||
category,
|
|
||||||
outgoing.systemUser,
|
|
||||||
"Name of the server user (used by death and advancement messages and the /say command)"
|
|
||||||
),
|
),
|
||||||
//outgoing events toggle
|
stripColors = it.getOrDefault(
|
||||||
advancements = getBoolean(
|
"stripColors",
|
||||||
|
stripColors,
|
||||||
|
"strip colors from incoming text"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(OutgoingOptions()) {
|
||||||
|
OutgoingOptions(
|
||||||
|
systemUser = it.getOrDefault(
|
||||||
|
"systemUser",
|
||||||
|
systemUser,
|
||||||
|
"Name of the platform user (used by death and advancement messages and the /say command)"
|
||||||
|
),
|
||||||
|
advancements = it.getOrDefault(
|
||||||
"advancements",
|
"advancements",
|
||||||
category,
|
advancements,
|
||||||
outgoing.advancements,
|
|
||||||
"Relay player achievements / advancements"
|
"Relay player achievements / advancements"
|
||||||
),
|
),
|
||||||
announceConnect = getBoolean(
|
announceConnect = it.getOrDefault(
|
||||||
"announceConnect",
|
"announceConnect",
|
||||||
category,
|
announceConnect,
|
||||||
outgoing.announceConnect,
|
|
||||||
"announce successful connection to the gateway"
|
"announce successful connection to the gateway"
|
||||||
),
|
),
|
||||||
announceDisconnect = getBoolean(
|
announceDisconnect = it.getOrDefault(
|
||||||
"announceDisconnect",
|
"announceDisconnect",
|
||||||
category,
|
announceConnect,
|
||||||
outgoing.announceConnect,
|
|
||||||
"announce intention to disconnect / reconnect"
|
"announce intention to disconnect / reconnect"
|
||||||
|
),
|
||||||
|
stripColors = it.getOrDefault(
|
||||||
|
"stripColors",
|
||||||
|
stripColors,
|
||||||
|
"strip colors from nicknames and messages"
|
||||||
|
),
|
||||||
|
pasteEEKey = it.getOrDefault(
|
||||||
|
"pasteEEKey",
|
||||||
|
pasteEEKey,
|
||||||
|
"paste.ee api key, leave empty to use application default"
|
||||||
|
),
|
||||||
|
inlineLimit = it.getOrDefault(
|
||||||
|
"inlineLimit",
|
||||||
|
inlineLimit,
|
||||||
|
"messages with more lines than this will get shortened via paste.ee"
|
||||||
|
),
|
||||||
|
death = it.getOrDefault(
|
||||||
|
"death",
|
||||||
|
DeathOptions(),
|
||||||
|
"Death messages settings"
|
||||||
|
),
|
||||||
|
avatar = it.getOrDefault(
|
||||||
|
"avatar",
|
||||||
|
AvatarOptions(),
|
||||||
|
"Avatar options"
|
||||||
|
),
|
||||||
|
joinPart = it.getOrDefault(
|
||||||
|
"joinPart",
|
||||||
|
JoinPartOptions(),
|
||||||
|
"relay join and part messages to the gatway"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
category = "outgoing.death"
|
}
|
||||||
addCustomCategoryComment(category, "Death messages settings")
|
.registerTypeAdapter { jsonObj ->
|
||||||
outgoing.death = DeathOptions(
|
with(DeathOptions()) {
|
||||||
|
DeathOptions(
|
||||||
enable = getBoolean(
|
enable = jsonObj.getOrDefault(
|
||||||
"enable",
|
"enable",
|
||||||
category,
|
enable,
|
||||||
outgoing.death.enable,
|
|
||||||
"Relay player death messages"
|
"Relay player death messages"
|
||||||
),
|
),
|
||||||
damageType = getBoolean(
|
damageType = jsonObj.getOrDefault(
|
||||||
"damageType",
|
"damageType",
|
||||||
category,
|
damageType,
|
||||||
outgoing.death.damageType,
|
|
||||||
"Enable Damage type symbols on death messages"
|
"Enable Damage type symbols on death messages"
|
||||||
),
|
),
|
||||||
damageTypeMapping = getStringList(
|
damageTypeMapping = (jsonObj.getObject("damageTypeMapping")
|
||||||
"damageTypeMapping",
|
?: Marshaller.getFallback().serialize(damageTypeMapping) as JsonObject)
|
||||||
category,
|
.let {
|
||||||
outgoing.death.damageTypeMapping.map { entry ->
|
jsonObj.setComment(
|
||||||
"${entry.key}=${entry.value}"
|
"damageTypMapping",
|
||||||
|
"Damage type mapping for death cause"
|
||||||
|
)
|
||||||
|
it.mapValues { (key, _) ->
|
||||||
|
it.getOrDefault(key, damageTypeMapping[key] ?: emptyArray(), key)
|
||||||
|
.apply { it[key] }.apply {
|
||||||
|
jsonObj["damageTypeMapping"] = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.toTypedArray(),
|
|
||||||
"Damage type mapping for death cause, " +
|
|
||||||
"\nseparate value and key with '=', " +
|
|
||||||
"\nseparate multiple values with spaces\n"
|
|
||||||
).associate {
|
|
||||||
val key = it.substringBefore('=')
|
|
||||||
val value = it.substringAfter('=')
|
|
||||||
Pair(key, value)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
category = "outgoing.join&part"
|
}
|
||||||
addCustomCategoryComment(category, "relay join and part messages to the gatway" +
|
.registerTypeAdapter {
|
||||||
"\nFormatting options: " +
|
with(AvatarOptions()) {
|
||||||
"\nAvailable variables: {username}, {username:antiping}")
|
AvatarOptions(
|
||||||
outgoing.joinPart = JoinPartOptions(
|
enable = it.getOrDefault(
|
||||||
enable = getBoolean(
|
|
||||||
"enable",
|
"enable",
|
||||||
category,
|
enable,
|
||||||
outgoing.joinPart.enable,
|
"enable ingame avatar"
|
||||||
|
),
|
||||||
|
urlTemplate = it.getOrDefault(
|
||||||
|
"urlTemplate",
|
||||||
|
urlTemplate,
|
||||||
|
"template for constructing the user avatar url using the uuid"
|
||||||
|
),
|
||||||
|
systemUserAvatar = it.getOrDefault(
|
||||||
|
"systemUserAvatar",
|
||||||
|
systemUserAvatar,
|
||||||
|
"avatar url for the system user"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
|
with(JoinPartOptions()) {
|
||||||
|
JoinPartOptions(
|
||||||
|
enable = it.getOrDefault(
|
||||||
|
"enable",
|
||||||
|
enable,
|
||||||
"Relay when a player joins / parts the game" +
|
"Relay when a player joins / parts the game" +
|
||||||
"\nany receiving end still needs to be configured with showJoinPart = true" +
|
"\nany receiving end still needs to be configured with showJoinPart = true" +
|
||||||
"\nto display the messages"
|
"\nto display the messages"
|
||||||
),
|
),
|
||||||
joinServer = getString(
|
joinServer = it.getOrDefault(
|
||||||
"joinServer",
|
"joinServer",
|
||||||
category,
|
joinServer,
|
||||||
outgoing.joinPart.joinServer,
|
|
||||||
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
),
|
),
|
||||||
partServer = getString(
|
partServer = it.getOrDefault(
|
||||||
"partServer",
|
"partServer",
|
||||||
category,
|
partServer,
|
||||||
outgoing.joinPart.partServer,
|
|
||||||
"user part message sent to other gateways, available variables: {username}, {username:antiping}"
|
"user part message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerTypeAdapter {
|
||||||
category = "update"
|
with(UpdateOptions()) {
|
||||||
addCustomCategoryComment(category, "Update Settings")
|
UpdateOptions(
|
||||||
update = UpdateOptions(
|
enable = it.getOrDefault(
|
||||||
enable = getBoolean(
|
|
||||||
"enable",
|
"enable",
|
||||||
category,
|
enable,
|
||||||
update.enable,
|
|
||||||
"Enable Update checking"
|
"Enable Update checking"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.registerSerializer { locationSettings: SettingsOutgoing, marshaller: Marshaller ->
|
||||||
|
val jsonObject = JsonObject()
|
||||||
|
locationSettings.plain?.let {
|
||||||
|
jsonObject["plain"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.action?.let {
|
||||||
|
jsonObject["action"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.join?.let {
|
||||||
|
jsonObject["join"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.leave?.let {
|
||||||
|
jsonObject["leave"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.advancement?.let {
|
||||||
|
jsonObject["advancement"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.death?.let {
|
||||||
|
jsonObject["death"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.broadcast?.let {
|
||||||
|
jsonObject["broadcast"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.status?.let {
|
||||||
|
jsonObject["status"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
locationSettings.skip.let {
|
||||||
|
jsonObject["skip"] = marshaller.serialize(it)
|
||||||
|
}
|
||||||
|
jsonObject
|
||||||
|
}
|
||||||
|
.build()!!
|
||||||
|
}
|
||||||
|
|
||||||
abstract fun load(): BaseConfig
|
fun load(): MatterLinkConfig {
|
||||||
|
val jsonObject = try {
|
||||||
|
jankson.load(configFile)
|
||||||
|
} catch (e: SyntaxError) {
|
||||||
|
logger.error("error loading config: ${e.completeMessage}")
|
||||||
|
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
|
logger.error("creating config file $configFile")
|
||||||
|
configFile.absoluteFile.parentFile.mkdirs()
|
||||||
|
configFile.createNewFile()
|
||||||
|
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
|
||||||
|
}
|
||||||
|
logger.info("finished loading base config")
|
||||||
|
|
||||||
|
val tmpCfg = try {
|
||||||
|
//cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||||
|
jankson.fromJson(jsonObject, MatterLinkConfig::class.java).apply {
|
||||||
|
configFile.writeText(jsonObject.toJson(true, true))
|
||||||
|
logger.info("loaded config: Main config")
|
||||||
|
logger.debug("loaded config: $this")
|
||||||
|
}
|
||||||
|
} catch (e: SyntaxError) {
|
||||||
|
logger.error("error parsing config: ${e.completeMessage} ")
|
||||||
|
logger.error(e.stackTraceString)
|
||||||
|
cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||||
|
if (::cfg.isInitialized) cfg else MatterLinkConfig()
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
logger.error(e.stackTraceString)
|
||||||
|
cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||||
|
if (::cfg.isInitialized) cfg else MatterLinkConfig()
|
||||||
|
} catch (e: NullPointerException) {
|
||||||
|
logger.error("error loading config: ${e.stackTraceString}")
|
||||||
|
cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||||
|
if (::cfg.isInitialized) cfg else MatterLinkConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// val defaultJsonObject = jankson.load("{}")
|
||||||
|
// jankson.fromJson(defaultJsonObject, MatterLinkConfig::class.java)
|
||||||
|
// val nonDefault = jsonObject.getDelta(defaultJsonObject)
|
||||||
|
|
||||||
|
MessageHandlerInst.config.url = tmpCfg.connect.url
|
||||||
|
MessageHandlerInst.config.token = tmpCfg.connect.authToken
|
||||||
|
MessageHandlerInst.config.reconnectWait = tmpCfg.connect.reconnectWait
|
||||||
|
|
||||||
|
MessageHandlerInst.config.systemUser = tmpCfg.outgoing.systemUser
|
||||||
|
MessageHandlerInst.config.announceConnect = tmpCfg.outgoing.announceConnect
|
||||||
|
MessageHandlerInst.config.announceDisconnect = tmpCfg.outgoing.announceDisconnect
|
||||||
|
|
||||||
|
return tmpCfg
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,69 +1,154 @@
|
||||||
package matterlink.config
|
package matterlink.config
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import blue.endless.jankson.Jankson
|
||||||
import com.google.gson.GsonBuilder
|
import blue.endless.jankson.JsonObject
|
||||||
import com.google.gson.JsonSyntaxException
|
import blue.endless.jankson.JsonPrimitive
|
||||||
import com.google.gson.reflect.TypeToken
|
import blue.endless.jankson.impl.SyntaxError
|
||||||
import matterlink.bridge.command.CommandType
|
import matterlink.bridge.command.CommandType
|
||||||
import matterlink.bridge.command.CustomCommand
|
import matterlink.bridge.command.CustomCommand
|
||||||
import matterlink.instance
|
import matterlink.getOrDefault
|
||||||
import matterlink.stackTraceString
|
import matterlink.logger
|
||||||
|
import matterlink.registerPrimitiveTypeAdapter
|
||||||
|
import matterlink.registerTypeAdapter
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
|
||||||
typealias CommandMap = Map<String, CustomCommand>
|
typealias CommandMap = MutableMap<String, CustomCommand>
|
||||||
|
typealias DefaultCommands = Map<String, Pair<String, CustomCommand>>
|
||||||
|
|
||||||
object CommandConfig {
|
object CommandConfig {
|
||||||
private val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
private val configFile: File = baseCfg.cfgDirectory.resolve("commands.hjson")
|
||||||
private val configFile: File = cfg.cfgDirectory.resolve("commands.json")
|
|
||||||
|
|
||||||
private val default = hashMapOf(
|
private val default: DefaultCommands = mapOf(
|
||||||
"tps" to CustomCommand(
|
"tps" to ("""Your run off the mill tps commands, change it to /sampler tps or /cofh tps if you like
|
||||||
|
|make sure to disable defaultCommand if you want your edits to have any effect
|
||||||
|
""".trimMargin()
|
||||||
|
to CustomCommand(
|
||||||
type = CommandType.EXECUTE,
|
type = CommandType.EXECUTE,
|
||||||
execute = "forge tps",
|
execute = "forge tps",
|
||||||
help = "Print server tps",
|
help = "Print platform tps",
|
||||||
allowArgs = false
|
timeout = 200,
|
||||||
),
|
defaultCommand = true
|
||||||
"list" to CustomCommand(
|
)),
|
||||||
|
"list" to ("lists all the players, this is just a straight pass-through"
|
||||||
|
to CustomCommand(
|
||||||
type = CommandType.EXECUTE,
|
type = CommandType.EXECUTE,
|
||||||
execute = "list",
|
execute = "list",
|
||||||
help = "List online players",
|
help = "List online players",
|
||||||
allowArgs = false
|
defaultCommand = true
|
||||||
),
|
)),
|
||||||
"seed" to CustomCommand(
|
"seed" to ("another straight pass-through"
|
||||||
|
to CustomCommand(
|
||||||
type = CommandType.EXECUTE,
|
type = CommandType.EXECUTE,
|
||||||
execute = "seed",
|
execute = "seed",
|
||||||
help = "Print server world seed",
|
help = "Print platform world seed",
|
||||||
allowArgs = false
|
defaultCommand = true
|
||||||
),
|
)),
|
||||||
"uptime" to CustomCommand(
|
"uptime" to ("this is a reponse command, it uses the uptime function, time since the mod was first loaded"
|
||||||
|
to CustomCommand(
|
||||||
type = CommandType.RESPONSE,
|
type = CommandType.RESPONSE,
|
||||||
permLevel = 1,
|
|
||||||
response = "{uptime}",
|
response = "{uptime}",
|
||||||
help = "Print server uptime",
|
help = "Print platform uptime",
|
||||||
allowArgs = false
|
defaultCommand = true
|
||||||
)
|
)),
|
||||||
|
"whoami" to ("this shows you some of the other response macros"
|
||||||
|
to CustomCommand(
|
||||||
|
type = CommandType.RESPONSE,
|
||||||
|
response = "name: `{user}` userid: `{userid}` platform: `{platform}` username: `{username}` uuid: `{uuid}`",
|
||||||
|
help = "Print debug user data",
|
||||||
|
timeout = 200,
|
||||||
|
defaultCommand = true
|
||||||
|
)),
|
||||||
|
"version" to ("are you out of date huh ?"
|
||||||
|
to CustomCommand(
|
||||||
|
type = CommandType.RESPONSE,
|
||||||
|
response = "{version}",
|
||||||
|
help = "are you out of date huh ?",
|
||||||
|
timeout = 200,
|
||||||
|
defaultCommand = true
|
||||||
|
)),
|
||||||
|
"exec" to ("this uses arguments in a passed-through command, you could restrict the arguments with a regex"
|
||||||
|
to CustomCommand(
|
||||||
|
type = CommandType.EXECUTE,
|
||||||
|
execute = "{args}",
|
||||||
|
argumentsRegex = ".*".toRegex(),
|
||||||
|
permLevel = 50.0,
|
||||||
|
help = "Execute any command as OP, be careful with this one",
|
||||||
|
execOp = true,
|
||||||
|
defaultCommand = true
|
||||||
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
var commands: CommandMap = default
|
val commands: CommandMap = hashMapOf()
|
||||||
private set
|
|
||||||
|
|
||||||
fun readConfig(): Boolean {
|
fun loadFile() {
|
||||||
if (!configFile.exists() || configFile.readText().isBlank()) {
|
val jankson = Jankson
|
||||||
|
.builder()
|
||||||
|
.registerTypeAdapter { jsonObj ->
|
||||||
|
with(CustomCommand.DEFAULT) {
|
||||||
|
CustomCommand(
|
||||||
|
type = jsonObj.get(CommandType::class.java, "type") ?: type,
|
||||||
|
execute = jsonObj.get(String::class.java, "execute") ?: execute,
|
||||||
|
response = jsonObj.get(String::class.java, "response") ?: response,
|
||||||
|
permLevel = jsonObj.get(Double::class.java, "permLevel") ?: permLevel,
|
||||||
|
help = jsonObj.get(String::class.java, "help") ?: help,
|
||||||
|
timeout = jsonObj.get(Int::class.java, "timeout") ?: timeout,
|
||||||
|
defaultCommand = jsonObj.get(Boolean::class.java, "defaultCommand") ?: defaultCommand,
|
||||||
|
execOp = jsonObj.get(Boolean::class.java, "execOp") ?: execOp,
|
||||||
|
argumentsRegex = jsonObj.get(Regex::class.java, "argumentsRegex") ?: argumentsRegex
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.registerPrimitiveTypeAdapter {
|
||||||
|
it.toString().toRegex()
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
|
||||||
|
jankson.marshaller.registerSerializer(Regex::class.java) { regex, _ ->
|
||||||
|
JsonPrimitive(regex.pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
val jsonObject = try {
|
||||||
|
jankson.load(configFile)
|
||||||
|
} catch (e: SyntaxError) {
|
||||||
|
logger.error("error parsing config: ${e.completeMessage}")
|
||||||
|
JsonObject()
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
configFile.createNewFile()
|
configFile.createNewFile()
|
||||||
configFile.writeText(gson.toJson(default))
|
JsonObject()
|
||||||
return true
|
}
|
||||||
|
// clear commands
|
||||||
|
commands.clear()
|
||||||
|
jsonObject.forEach { key, element ->
|
||||||
|
logger.trace("loading command '$key'")
|
||||||
|
val command = jsonObject.get(CustomCommand::class.java, key)
|
||||||
|
if (command != null)
|
||||||
|
commands[key] = command
|
||||||
|
else {
|
||||||
|
logger.error("could not parse key: $key, value: '$element' as CustomCommand")
|
||||||
|
logger.error("skipping $key")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
//apply defaults
|
||||||
commands = gson.fromJson(configFile.readText(), object : TypeToken<CommandMap>() {}.type)
|
default.forEach { k, (comment, defCommand) ->
|
||||||
} catch (e: JsonSyntaxException) {
|
val command = commands[k]
|
||||||
instance.fatal(e.stackTraceString)
|
if (command == null || command.defaultCommand == true) {
|
||||||
instance.fatal("failed to parse $configFile using last good values as fallback")
|
commands[k] = defCommand
|
||||||
|
jsonObject.getOrDefault(k, defCommand, comment)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("loaded jsonObj: $jsonObject")
|
||||||
|
logger.debug("loaded commandMap: $commands")
|
||||||
|
|
||||||
|
val defaultJsonObject = jankson.marshaller.serialize(CustomCommand.DEFAULT) as JsonObject
|
||||||
|
val nonDefaultJsonObj = jsonObject.clone()
|
||||||
|
jsonObject.forEach { key, element ->
|
||||||
|
if (element is JsonObject) {
|
||||||
|
nonDefaultJsonObj[key] = element.getDelta(defaultJsonObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configFile.writeText(nonDefaultJsonObj.toJson(true, true))
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
package matterlink.config
|
||||||
|
|
||||||
|
import blue.endless.jankson.Jankson
|
||||||
|
import blue.endless.jankson.JsonObject
|
||||||
|
import blue.endless.jankson.impl.Marshaller
|
||||||
|
import blue.endless.jankson.impl.SyntaxError
|
||||||
|
import com.google.common.cache.Cache
|
||||||
|
import com.google.common.cache.CacheBuilder
|
||||||
|
import matterlink.getList
|
||||||
|
import matterlink.logger
|
||||||
|
import matterlink.stackTraceString
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
typealias IdentMap = Map<String, Map<String, List<String>>>
|
||||||
|
|
||||||
|
data class AuthRequest(
|
||||||
|
val username: String,
|
||||||
|
val uuid: String,
|
||||||
|
val nonce: String,
|
||||||
|
val platform: String,
|
||||||
|
val userid: String
|
||||||
|
)
|
||||||
|
|
||||||
|
object IdentitiesConfig {
|
||||||
|
val authRequests: Cache<String, AuthRequest> = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private val jankson = Jankson
|
||||||
|
.builder()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private val configFile: File = baseCfg.cfgDirectory.resolve("identities.hjson")
|
||||||
|
|
||||||
|
private val default = mapOf(
|
||||||
|
("edd31c45-b095-49c5-a9f5-59cec4cfed8c" to mapOf(
|
||||||
|
"discord.game" to (listOf("112228624366575616") to "discord id")
|
||||||
|
) to "username: NikkyAi")
|
||||||
|
)
|
||||||
|
|
||||||
|
var idents: IdentMap = mapOf()
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var jsonObject: JsonObject = JsonObject()
|
||||||
|
|
||||||
|
fun loadFile() {
|
||||||
|
|
||||||
|
val defaultJsonObject = JsonObject().apply {
|
||||||
|
default.forEach { (uuid, userMap), uuidComment ->
|
||||||
|
val jsonUserMap = this.putDefault(uuid, JsonObject(), uuidComment)
|
||||||
|
if (jsonUserMap is JsonObject) {
|
||||||
|
userMap.forEach { platform, (user, comment) ->
|
||||||
|
logger.trace("loading uuid: $uuid platform: $platform user: $user")
|
||||||
|
val element = Marshaller.getFallback().serialize(user)
|
||||||
|
jsonUserMap.putDefault(platform, element, comment.takeUnless { it.isBlank() })
|
||||||
|
}
|
||||||
|
this[uuid] = jsonUserMap
|
||||||
|
} else {
|
||||||
|
logger.error("cannot parse uuid: $uuid , value: '$jsonUserMap' as Map, skipping")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var save = true
|
||||||
|
jsonObject = try {
|
||||||
|
jankson.load(configFile)
|
||||||
|
} catch (e: SyntaxError) {
|
||||||
|
logger.error("error parsing config: ${e.completeMessage}")
|
||||||
|
save = false
|
||||||
|
defaultJsonObject
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
|
logger.error("cannot find config: $configFile .. creating sample permissions mapping")
|
||||||
|
configFile.createNewFile()
|
||||||
|
defaultJsonObject
|
||||||
|
}
|
||||||
|
|
||||||
|
load(save)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun load(save: Boolean = true) {
|
||||||
|
val tmpIdents: MutableMap<String, Map<String, List<String>>> = mutableMapOf()
|
||||||
|
jsonObject.forEach { uuid, jsonIdentifier ->
|
||||||
|
val identMap: MutableMap<String, List<String>> = tmpIdents[uuid]?.toMutableMap() ?: mutableMapOf()
|
||||||
|
if (jsonIdentifier is JsonObject) {
|
||||||
|
jsonIdentifier.forEach { platform, user ->
|
||||||
|
logger.info("$uuid $platform $user")
|
||||||
|
identMap[platform] = jsonIdentifier.getList(platform) ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmpIdents[uuid] = identMap.toMap()
|
||||||
|
}
|
||||||
|
idents = tmpIdents.toMap()
|
||||||
|
|
||||||
|
logger.info("Identities loaded")
|
||||||
|
|
||||||
|
if (save)
|
||||||
|
configFile.writeText(jsonObject.toJson(true, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(uuid: String, username: String, platform: String, userid: String, comment: String? = null) {
|
||||||
|
val platformObject = jsonObject.getObject(uuid) ?: JsonObject()
|
||||||
|
platformObject.putDefault(platform, userid, comment)
|
||||||
|
val userIdList = platformObject.getList<String>(platform) ?: emptyList()
|
||||||
|
platformObject[platform] = platformObject.marshaller.serialize(userIdList + userid)
|
||||||
|
jsonObject[uuid] = platformObject
|
||||||
|
|
||||||
|
if (jsonObject.getComment(uuid) == null) {
|
||||||
|
jsonObject.setComment(uuid, "Username: $username")
|
||||||
|
}
|
||||||
|
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: rewrite, store ident map differently in memory
|
||||||
|
fun getUUID(platform: String, userid: String): UUID? {
|
||||||
|
return idents.entries.firstOrNull { (uuid, usermap) ->
|
||||||
|
usermap.entries.any { (_platform, userids) ->
|
||||||
|
if (platform.equals(_platform, true))
|
||||||
|
logger.info("platform: $_platform userids: $userids")
|
||||||
|
platform.equals(_platform, true) && userids.contains(userid)
|
||||||
|
}
|
||||||
|
}?.key?.let {
|
||||||
|
try {
|
||||||
|
UUID.fromString(it)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
logger.error("cannot parse UUID: $it")
|
||||||
|
logger.error(e.stackTraceString)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,46 +1,85 @@
|
||||||
package matterlink.config
|
package matterlink.config
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import blue.endless.jankson.Jankson
|
||||||
import com.google.gson.GsonBuilder
|
import blue.endless.jankson.JsonObject
|
||||||
import com.google.gson.JsonSyntaxException
|
import blue.endless.jankson.impl.SyntaxError
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.common.cache.Cache
|
||||||
import matterlink.instance
|
import com.google.common.cache.CacheBuilder
|
||||||
import matterlink.stackTraceString
|
import matterlink.getReified
|
||||||
|
import matterlink.logger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
typealias PermissionMap = Map<String, Map<String, Int>>
|
typealias PermissionMap = Map<String, Double>
|
||||||
|
|
||||||
|
data class PermissionRequest(
|
||||||
|
val uuid: UUID,
|
||||||
|
val user: String,
|
||||||
|
val nonce: String,
|
||||||
|
val powerlevel: Double? = null
|
||||||
|
)
|
||||||
|
|
||||||
object PermissionConfig {
|
object PermissionConfig {
|
||||||
private val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
val permissionRequests: Cache<String, PermissionRequest> = CacheBuilder.newBuilder()
|
||||||
private val configFile: File = cfg.cfgDirectory.resolve("permissions.json")
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
|
.build()
|
||||||
|
private val jankson = Jankson
|
||||||
|
.builder()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private val configFile: File = baseCfg.cfgDirectory.resolve("permissions.hjson")
|
||||||
|
|
||||||
private val default = mapOf(
|
private val default = mapOf(
|
||||||
"irc.esper" to mapOf(
|
"edd31c45-b095-49c5-a9f5-59cec4cfed8c" to 9000.0 to "Superuser"
|
||||||
"~nikky@nikky.moe" to 0,
|
|
||||||
"user@example." to 0
|
|
||||||
),
|
|
||||||
"discord.game" to mapOf(
|
|
||||||
"112228624366575616" to 0
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var perms: PermissionMap = default
|
val perms: PermissionMap = mutableMapOf()
|
||||||
|
private var jsonObject: JsonObject = JsonObject()
|
||||||
|
|
||||||
fun loadPermFile(): Boolean {
|
fun loadFile() {
|
||||||
if (!configFile.exists() || configFile.readText().isBlank()) {
|
val defaultJsonObject = JsonObject().apply {
|
||||||
|
default.forEach { (uuid, level), comment ->
|
||||||
|
jsonObject.putDefault(uuid, level, comment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var save = true
|
||||||
|
jsonObject = try {
|
||||||
|
jankson.load(configFile)
|
||||||
|
} catch (e: SyntaxError) {
|
||||||
|
logger.error("error parsing config: ${e.completeMessage}")
|
||||||
|
save = false
|
||||||
|
defaultJsonObject
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
|
logger.error("cannot find config: $configFile .. creating sample permissions mapping")
|
||||||
configFile.createNewFile()
|
configFile.createNewFile()
|
||||||
configFile.writeText(gson.toJson(default))
|
defaultJsonObject
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
load(save)
|
||||||
perms =gson.fromJson(configFile.readText(), object : TypeToken<PermissionMap>() {}.type)
|
|
||||||
} catch (e: JsonSyntaxException) {
|
|
||||||
instance.fatal(e.stackTraceString)
|
|
||||||
instance.fatal("failed to parse $configFile using last good values as fallback")
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
|
private fun load(save: Boolean = true) {
|
||||||
|
val tmpPerms = mutableMapOf<String, Double>()
|
||||||
|
for ((uuid, powerlevel) in jsonObject) {
|
||||||
|
val tmpLevel = jsonObject.getReified<Double>(uuid)
|
||||||
|
if (tmpLevel == null) {
|
||||||
|
logger.warn("cannot parse permission uuid: $uuid level: $powerlevel")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tmpPerms[uuid] = tmpLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Permissions reloaded")
|
||||||
|
|
||||||
|
if (save)
|
||||||
|
configFile.writeText(jsonObject.toJson(true, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(uuid: UUID, powerlevel: Double, comment: String? = null) {
|
||||||
|
jsonObject.putDefault(uuid.toString(), powerlevel, comment)
|
||||||
|
load()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,19 +1,40 @@
|
||||||
package matterlink.handlers
|
package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.logger
|
||||||
import matterlink.instance
|
import java.util.UUID
|
||||||
|
|
||||||
object ChatProcessor {
|
object ChatProcessor {
|
||||||
fun sendToBridge(user: String, msg: String, event: String) {
|
/**
|
||||||
|
* @return cancel message flag
|
||||||
|
*/
|
||||||
|
suspend fun sendToBridge(
|
||||||
|
user: String,
|
||||||
|
msg: String,
|
||||||
|
x: Int,
|
||||||
|
y: Int,
|
||||||
|
z: Int,
|
||||||
|
dimension: Int?,
|
||||||
|
event: ChatEvent,
|
||||||
|
uuid: UUID? = null
|
||||||
|
): Boolean {
|
||||||
|
//TODO: pass message to Locations
|
||||||
|
logger.info("position: $x $y $z dimension: $dimension")
|
||||||
val message = msg.trim()
|
val message = msg.trim()
|
||||||
|
if (uuid != null && BridgeCommandRegistry.handleCommand(message, user, uuid)) return true
|
||||||
when {
|
when {
|
||||||
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
|
message.isNotBlank() -> LocationHandler.sendToLocations(
|
||||||
username = user,
|
user = user,
|
||||||
text = message,
|
msg = message,
|
||||||
event = event
|
x = x, y = y, z = z, dimension = dimension,
|
||||||
))
|
event = event,
|
||||||
else -> instance.warn("WARN: dropped blank message by '$user'")
|
cause = "Message from $user",
|
||||||
|
uuid = uuid
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
else -> logger.warn("WARN: dropped blank message by '$user'")
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,35 @@
|
||||||
package matterlink.handlers
|
package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.antiping
|
import matterlink.antiping
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import java.util.*
|
import matterlink.stripColorOut
|
||||||
|
import java.util.Random
|
||||||
|
|
||||||
object DeathHandler {
|
object DeathHandler {
|
||||||
private val random = Random()
|
private val random = Random()
|
||||||
|
|
||||||
fun handleDeath(
|
suspend fun handleDeath(
|
||||||
player: String,
|
player: String,
|
||||||
deathMessage: String,
|
deathMessage: String,
|
||||||
damageType: String
|
damageType: String,
|
||||||
|
x: Int, y: Int, z: Int,
|
||||||
|
dimension: Int
|
||||||
) {
|
) {
|
||||||
if (cfg.outgoing.death.enable) {
|
if (cfg.outgoing.death.enable) {
|
||||||
var msg = deathMessage.replace(player, player.antiping)
|
var msg = deathMessage.stripColorOut.replace(player, player.stripColorOut.antiping)
|
||||||
if (cfg.outgoing.death.damageType) {
|
if (cfg.outgoing.death.damageType) {
|
||||||
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]?.split(' ')
|
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]
|
||||||
?: listOf("\uD83D\uDC7B unknown type '$damageType'")
|
?: arrayOf("\uD83D\uDC7B unknown type '$damageType'")
|
||||||
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
||||||
msg += " " + damageEmoji
|
msg += " $damageEmoji"
|
||||||
}
|
}
|
||||||
MessageHandler.transmit(ApiMessage(
|
LocationHandler.sendToLocations(
|
||||||
text = msg
|
msg = msg,
|
||||||
))
|
x = x, y = y, z = z, dimension = dimension,
|
||||||
|
event = ChatEvent.DEATH,
|
||||||
|
cause = "Death Event of $player",
|
||||||
|
systemuser = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +1,52 @@
|
||||||
package matterlink.handlers
|
package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.antiping
|
import matterlink.antiping
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.JOIN_LEAVE
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.mapFormat
|
import matterlink.mapFormat
|
||||||
|
import matterlink.stripColorOut
|
||||||
|
|
||||||
object JoinLeaveHandler {
|
object JoinLeaveHandler {
|
||||||
fun handleJoin(player: String) {
|
suspend fun handleJoin(
|
||||||
|
player: String,
|
||||||
|
x: Int, y: Int, z: Int,
|
||||||
|
dimension: Int
|
||||||
|
) {
|
||||||
if (cfg.outgoing.joinPart.enable) {
|
if (cfg.outgoing.joinPart.enable) {
|
||||||
val msg = cfg.outgoing.joinPart.joinServer.mapFormat(
|
val msg = cfg.outgoing.joinPart.joinServer.mapFormat(
|
||||||
mapOf(
|
mapOf(
|
||||||
"{username}" to player,
|
"{username}" to player.stripColorOut,
|
||||||
"{username:antiping}" to player.antiping
|
"{username:antiping}" to player.stripColorOut.antiping
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
MessageHandler.transmit(ApiMessage(
|
LocationHandler.sendToLocations(
|
||||||
text = msg,
|
msg = msg,
|
||||||
event = JOIN_LEAVE
|
x = x, y = y, z = z, dimension = dimension,
|
||||||
))
|
event = ChatEvent.JOIN,
|
||||||
|
systemuser = true,
|
||||||
|
cause = "$player joined"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleLeave(player: String) {
|
suspend fun handleLeave(
|
||||||
|
player: String,
|
||||||
|
x: Int, y: Int, z: Int,
|
||||||
|
dimension: Int
|
||||||
|
) {
|
||||||
if (cfg.outgoing.joinPart.enable) {
|
if (cfg.outgoing.joinPart.enable) {
|
||||||
val msg = cfg.outgoing.joinPart.partServer.mapFormat(
|
val msg = cfg.outgoing.joinPart.partServer.mapFormat(
|
||||||
mapOf(
|
mapOf(
|
||||||
"{username}" to player,
|
"{username}" to player.stripColorOut,
|
||||||
"{username:antiping}" to player.antiping
|
"{username:antiping}" to player.stripColorOut.antiping
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
MessageHandler.transmit(ApiMessage(
|
LocationHandler.sendToLocations(
|
||||||
text = msg,
|
msg = msg,
|
||||||
event = JOIN_LEAVE
|
x = x, y = y, z = z, dimension = dimension,
|
||||||
))
|
event = ChatEvent.JOIN,
|
||||||
|
systemuser = true,
|
||||||
|
cause = "$player left"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
package matterlink.handlers
|
||||||
|
|
||||||
|
import matterlink.api.ApiMessage
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.logger
|
||||||
|
import matterlink.stripColorOut
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
|
||||||
|
enum class ChatEvent {
|
||||||
|
PLAIN, ACTION, DEATH, JOIN, LEAVE, ADVANCEMENT, BROADCAST, STATUS
|
||||||
|
}
|
||||||
|
|
||||||
|
object LocationHandler {
|
||||||
|
|
||||||
|
suspend fun sendToLocations(
|
||||||
|
user: String = cfg.outgoing.systemUser,
|
||||||
|
msg: String,
|
||||||
|
x: Int, y: Int, z: Int,
|
||||||
|
dimension: Int?,
|
||||||
|
event: ChatEvent,
|
||||||
|
systemuser: Boolean = false,
|
||||||
|
uuid: UUID? = null,
|
||||||
|
cause: String
|
||||||
|
): Boolean {
|
||||||
|
val defaults = cfg.outgoingDefaults
|
||||||
|
var handled = false
|
||||||
|
val skips = mutableSetOf<String>()
|
||||||
|
logger.debug("locations: ${cfg.locations.map { it.label }}")
|
||||||
|
for (location in cfg.locations) {
|
||||||
|
val label = location.label
|
||||||
|
if (skips.contains(label)) {
|
||||||
|
logger.debug("skipping $label (contained in in $skips)")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!location.area.testForDim(dimension)) {
|
||||||
|
logger.debug("location: $label dropped message '$msg' from $user due to mismatched dimension")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!location.area.testInBounds(x, y, z)) {
|
||||||
|
logger.debug("location: $label dropped message '$msg' from $user out of coordinate bounds")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val matchesEvent = when (event) {
|
||||||
|
ChatEvent.PLAIN -> location.outgoing.plain ?: defaults.plain
|
||||||
|
ChatEvent.ACTION -> location.outgoing.action ?: defaults.action
|
||||||
|
ChatEvent.DEATH -> location.outgoing.death ?: defaults.death
|
||||||
|
ChatEvent.JOIN -> location.outgoing.join ?: defaults.join
|
||||||
|
ChatEvent.LEAVE -> location.outgoing.leave ?: defaults.leave
|
||||||
|
ChatEvent.ADVANCEMENT -> location.outgoing.advancement ?: defaults.advancement
|
||||||
|
ChatEvent.BROADCAST -> location.outgoing.broadcast ?: defaults.broadcast
|
||||||
|
ChatEvent.STATUS -> location.outgoing.status ?: defaults.status
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchesEvent) {
|
||||||
|
logger.debug("location: $label dropped message '$msg' from user: '$user', event not enabled")
|
||||||
|
logger.debug("event: $event")
|
||||||
|
logger.debug("location.outgoing: ${location.outgoing}")
|
||||||
|
logger.debug("defaults: $defaults")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
skips.addAll(location.outgoing.skip)
|
||||||
|
|
||||||
|
val eventStr = when (event) {
|
||||||
|
ChatEvent.PLAIN -> ""
|
||||||
|
ChatEvent.ACTION -> ApiMessage.USER_ACTION
|
||||||
|
ChatEvent.DEATH -> ""
|
||||||
|
ChatEvent.JOIN -> ApiMessage.JOIN_LEAVE
|
||||||
|
ChatEvent.LEAVE -> ApiMessage.JOIN_LEAVE
|
||||||
|
ChatEvent.ADVANCEMENT -> ""
|
||||||
|
ChatEvent.BROADCAST -> ""
|
||||||
|
ChatEvent.STATUS -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val username = when {
|
||||||
|
systemuser -> cfg.outgoing.systemUser
|
||||||
|
else -> user
|
||||||
|
}
|
||||||
|
val avatar = when {
|
||||||
|
systemuser ->
|
||||||
|
cfg.outgoing.avatar.systemUserAvatar
|
||||||
|
cfg.outgoing.avatar.enable && uuid != null ->
|
||||||
|
cfg.outgoing.avatar.urlTemplate.replace("{uuid}", uuid.toString())
|
||||||
|
else ->
|
||||||
|
null
|
||||||
|
}
|
||||||
|
when {
|
||||||
|
msg.isNotBlank() -> MessageHandlerInst.transmit(
|
||||||
|
ApiMessage(
|
||||||
|
username = username.stripColorOut,
|
||||||
|
text = msg.stripColorOut,
|
||||||
|
event = eventStr,
|
||||||
|
gateway = location.gateway
|
||||||
|
).apply {
|
||||||
|
avatar?.let {
|
||||||
|
this.avatar = it
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cause = cause
|
||||||
|
)
|
||||||
|
else -> logger.warn("WARN: dropped blank message by '$user'")
|
||||||
|
}
|
||||||
|
logger.debug("sent message through location: $label, cause: $cause")
|
||||||
|
handled = true
|
||||||
|
}
|
||||||
|
return handled
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,24 @@
|
||||||
package matterlink.handlers
|
package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.antiping
|
import matterlink.antiping
|
||||||
import matterlink.bridge.ApiMessage
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
import matterlink.stripColorOut
|
||||||
|
|
||||||
object ProgressHandler {
|
object ProgressHandler {
|
||||||
|
|
||||||
fun handleProgress(name: String, message: String, display: String) {
|
suspend fun handleProgress(
|
||||||
|
name: String, message: String, display: String,
|
||||||
|
x: Int, y: Int, z: Int,
|
||||||
|
dimension: Int
|
||||||
|
) {
|
||||||
if (!cfg.outgoing.advancements) return
|
if (!cfg.outgoing.advancements) return
|
||||||
val usr = name.antiping
|
val usr = name.stripColorOut.antiping
|
||||||
MessageHandler.transmit(ApiMessage(
|
LocationHandler.sendToLocations(
|
||||||
text = "$usr $message $display"
|
msg = "$usr $message $display".stripColorOut,
|
||||||
))
|
x = x, y = y, z = z, dimension = dimension,
|
||||||
|
event = ChatEvent.ADVANCEMENT,
|
||||||
|
cause = "Progress Event by $usr",
|
||||||
|
systemuser = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package matterlink.handlers
|
||||||
|
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import matterlink.api.ApiMessage
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
|
import matterlink.bridge.format
|
||||||
|
import matterlink.config.cfg
|
||||||
|
import matterlink.instance
|
||||||
|
import matterlink.logger
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
object ServerChatHandler {
|
||||||
|
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||||
|
val rcvChannel = MessageHandlerInst.broadcast.openSubscription()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method must be called every server tick with no arguments.
|
||||||
|
*/
|
||||||
|
suspend fun writeIncomingToChat() {
|
||||||
|
val nextMessage = rcvChannel.poll() ?: return
|
||||||
|
|
||||||
|
val defaults = cfg.incomingDefaults
|
||||||
|
|
||||||
|
val sourceGateway = nextMessage.gateway
|
||||||
|
|
||||||
|
// find all areas to send to
|
||||||
|
|
||||||
|
val targetUUIDs = mutableSetOf<UUID>()
|
||||||
|
val skips = mutableSetOf<String>()
|
||||||
|
|
||||||
|
val locations = cfg.locations.filter {
|
||||||
|
it.gateway == sourceGateway
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextMessage.event.isEmpty()) {
|
||||||
|
// filter command handlers
|
||||||
|
val commandLocations = locations.filter {
|
||||||
|
it.incoming.commands ?: cfg.incomingDefaults.commands
|
||||||
|
}
|
||||||
|
|
||||||
|
// process potential command
|
||||||
|
for ((label, location) in commandLocations) {
|
||||||
|
if (BridgeCommandRegistry.handleCommand(nextMessage)) return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (location in locations) {
|
||||||
|
val label = location.label
|
||||||
|
if (skips.contains(label)) {
|
||||||
|
logger.debug("skipping $label")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val matchesEvent = when (nextMessage.event) {
|
||||||
|
"" -> {
|
||||||
|
// if (location.incoming.commands ?: defaults.commands
|
||||||
|
// && BridgeCommandRegistry.handleCommand(nextMessage)) return
|
||||||
|
location.incoming.plain ?: defaults.plain
|
||||||
|
}
|
||||||
|
ApiMessage.JOIN_LEAVE -> location.incoming.join_leave ?: defaults.join_leave
|
||||||
|
ApiMessage.USER_ACTION -> location.incoming.action ?: defaults.action
|
||||||
|
else -> {
|
||||||
|
logger.error("unknown event type '${nextMessage.event}' on incoming message")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchesEvent) {
|
||||||
|
logger.info("location: $label dropped message '$nextMessage' event not enabled")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
targetUUIDs.addAll(instance.collectPlayers(location.area))
|
||||||
|
}
|
||||||
|
|
||||||
|
val message = when (nextMessage.event) {
|
||||||
|
"user_action" -> nextMessage.format(cfg.incoming.action)
|
||||||
|
"" -> {
|
||||||
|
// try to handle command and do not handle as a chat message
|
||||||
|
if (BridgeCommandRegistry.handleCommand(nextMessage)) return
|
||||||
|
nextMessage.format(cfg.incoming.chat)
|
||||||
|
}
|
||||||
|
"join_leave" -> nextMessage.format(cfg.incoming.joinPart)
|
||||||
|
else -> {
|
||||||
|
val user = nextMessage.username
|
||||||
|
val text = nextMessage.text
|
||||||
|
val json = nextMessage.encode()
|
||||||
|
logger.debug("Threw out message with unhandled event: ${nextMessage.event}")
|
||||||
|
logger.debug(" Message contents:")
|
||||||
|
logger.debug(" User: $user")
|
||||||
|
logger.debug(" Text: $text")
|
||||||
|
logger.debug(" JSON: $json")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targetUUIDs.forEach {
|
||||||
|
//TODO: optimize send to all at once
|
||||||
|
instance.wrappedSendToPlayer(it, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (nextMessage?.gateway == cfg.connect.gateway) {
|
||||||
|
// if (!nextMessage.text.isBlank()) {
|
||||||
|
// nextMessage.text = nextMessage.text.stripColorIn
|
||||||
|
// val message = when (nextMessage.event) {
|
||||||
|
// "user_action" -> nextMessage.format(cfg.incoming.action)
|
||||||
|
// "" -> {
|
||||||
|
// // try to handle command and do not handle as a chat message
|
||||||
|
// if (BridgeCommandRegistry.handleCommand(nextMessage)) return
|
||||||
|
// nextMessage.format(cfg.incoming.chat)
|
||||||
|
// }
|
||||||
|
// "join_leave" -> nextMessage.format(cfg.incoming.joinPart)
|
||||||
|
// else -> {
|
||||||
|
// val user = nextMessage.username
|
||||||
|
// val text = nextMessage.text
|
||||||
|
// val json = nextMessage.encode()
|
||||||
|
// logger.debug("Threw out message with unhandled event: ${nextMessage.event}")
|
||||||
|
// logger.debug(" Message contents:")
|
||||||
|
// logger.debug(" User: $user")
|
||||||
|
// logger.debug(" Text: $text")
|
||||||
|
// logger.debug(" JSON: $json")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// instance.wrappedSendToPlayers(message)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package matterlink.handlers
|
package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.bridge.ServerChatHandler
|
|
||||||
import matterlink.update.UpdateChecker
|
import matterlink.update.UpdateChecker
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,17 +12,17 @@ object TickHandler {
|
||||||
private set
|
private set
|
||||||
private var accumulator = 0
|
private var accumulator = 0
|
||||||
private const val updateInterval = 12 * 60 * 60 * 20
|
private const val updateInterval = 12 * 60 * 60 * 20
|
||||||
fun handleTick() {
|
suspend fun handleTick() {
|
||||||
tickCounter++
|
tickCounter++
|
||||||
if (tickCounter % 100 == 0) {
|
// if (tickCounter % 100 == 0) {
|
||||||
MessageHandler.checkConnection()
|
// MessageHandlerInst.checkConnection()
|
||||||
}
|
// }
|
||||||
|
|
||||||
ServerChatHandler.writeIncomingToChat()
|
ServerChatHandler.writeIncomingToChat()
|
||||||
|
|
||||||
if(accumulator++ > updateInterval) {
|
if (accumulator++ > updateInterval) {
|
||||||
accumulator -= updateInterval
|
accumulator -= updateInterval
|
||||||
UpdateChecker.run()
|
UpdateChecker.check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package matterlink.jenkins
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 03/02/18.
|
||||||
|
* @author Nikky
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Artifact(
|
||||||
|
val displayPath: String,
|
||||||
|
val fileName: String,
|
||||||
|
val relativePath: String
|
||||||
|
)
|
|
@ -0,0 +1,36 @@
|
||||||
|
package matterlink.jenkins
|
||||||
|
|
||||||
|
import com.github.kittinunf.fuel.httpGet
|
||||||
|
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
|
||||||
|
import com.github.kittinunf.result.Result
|
||||||
|
import kotlinx.serialization.json.JSON
|
||||||
|
import matterlink.logger
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 03/02/18.
|
||||||
|
* @author Nikky
|
||||||
|
*/
|
||||||
|
|
||||||
|
//@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
data class Build(
|
||||||
|
val number: Int,
|
||||||
|
val url: String
|
||||||
|
) {
|
||||||
|
fun details(userAgent: String): BuildWithDetails? {
|
||||||
|
val (request, response, result) = "$url/api/json"
|
||||||
|
.httpGet()
|
||||||
|
.header("User-Agent" to userAgent)
|
||||||
|
.responseObject(kotlinxDeserializerOf(loader = BuildWithDetails.serializer(), json = JSON.nonstrict))
|
||||||
|
return when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
result.value
|
||||||
|
}
|
||||||
|
is Result.Failure -> {
|
||||||
|
logger.error(result.error.toString())
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package matterlink.jenkins
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BuildWithDetails(
|
||||||
|
val number: Int,
|
||||||
|
val url: String,
|
||||||
|
val artifacts: List<Artifact>,
|
||||||
|
val timestamp: Date
|
||||||
|
)
|
|
@ -0,0 +1,37 @@
|
||||||
|
package matterlink.jenkins
|
||||||
|
|
||||||
|
|
||||||
|
import com.github.kittinunf.fuel.httpGet
|
||||||
|
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
|
||||||
|
import com.github.kittinunf.result.Result
|
||||||
|
import kotlinx.serialization.json.JSON
|
||||||
|
import matterlink.logger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 03/02/18.
|
||||||
|
* @author Nikky
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class JenkinsServer(val url: String) {
|
||||||
|
|
||||||
|
fun getUrl(job: String) = url + "/job/" + job.replace("/", "/job/")
|
||||||
|
|
||||||
|
fun getJob(job: String, userAgent: String): Job? {
|
||||||
|
val requestURL = getUrl(job) + "/api/json"
|
||||||
|
val (_, _, result) = requestURL
|
||||||
|
.httpGet()
|
||||||
|
.header("User-Agent" to userAgent)
|
||||||
|
.responseObject(kotlinxDeserializerOf(loader = Job.serializer(), json = JSON.nonstrict))
|
||||||
|
return when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
result.value
|
||||||
|
}
|
||||||
|
is Result.Failure -> {
|
||||||
|
logger.error(result.error.toString())
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package matterlink.jenkins
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nikky on 03/02/18.
|
||||||
|
* @author Nikky
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Job(
|
||||||
|
val url: String,
|
||||||
|
val name: String,
|
||||||
|
val fullName: String,
|
||||||
|
val displayName: String,
|
||||||
|
val fullDisplayName: String,
|
||||||
|
val builds: List<Build>?,
|
||||||
|
val lastSuccessfulBuild: Build?,
|
||||||
|
val lastStableBuild: Build?
|
||||||
|
) {
|
||||||
|
fun getBuildByNumber(build: Int, userAgent: String): BuildWithDetails? {
|
||||||
|
return builds?.find { it.number == build }?.details(userAgent)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,13 @@
|
||||||
package matterlink.update
|
package matterlink.update
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class CurseFile(
|
data class CurseFile(
|
||||||
val downloadURL: String,
|
val downloadUrl: String,
|
||||||
val fileName: String,
|
val fileName: String,
|
||||||
|
val fileNameOnDisk: String,
|
||||||
val gameVersion: List<String>,
|
val gameVersion: List<String>,
|
||||||
val releaseType: String,
|
val releaseType: String,
|
||||||
val fileStatus: String
|
val fileStatus: String
|
||||||
) {
|
)
|
||||||
companion object {
|
|
||||||
val gson = Gson()
|
|
||||||
|
|
||||||
fun decode(json: String): CurseFile {
|
|
||||||
return gson.fromJson(json, CurseFile::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +1,92 @@
|
||||||
package matterlink.update
|
package matterlink.update
|
||||||
|
|
||||||
import com.google.gson.FieldNamingPolicy
|
import com.github.kittinunf.fuel.core.extensions.cUrlString
|
||||||
import com.google.gson.GsonBuilder
|
import com.github.kittinunf.fuel.httpGet
|
||||||
import matterlink.bridge.ApiMessage
|
import kotlinx.coroutines.CoroutineName
|
||||||
import matterlink.bridge.MessageHandler
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.serialization.list
|
||||||
|
import matterlink.api.ApiMessage
|
||||||
|
import matterlink.bridge.MessageHandlerInst
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
import matterlink.handlers.ChatEvent
|
||||||
|
import matterlink.handlers.LocationHandler
|
||||||
import matterlink.instance
|
import matterlink.instance
|
||||||
import org.apache.http.HttpResponse
|
import matterlink.jenkins.JenkinsServer
|
||||||
import org.apache.http.client.HttpClient
|
import matterlink.logger
|
||||||
import org.apache.http.client.methods.HttpGet
|
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
|
||||||
import org.apache.http.impl.client.CloseableHttpClient
|
import com.github.kittinunf.result.Result
|
||||||
import org.apache.http.impl.client.HttpClients
|
import kotlinx.serialization.json.JSON
|
||||||
import java.io.BufferedReader
|
|
||||||
|
|
||||||
class UpdateChecker : Thread() {
|
object UpdateChecker : CoroutineScope {
|
||||||
companion object {
|
override val coroutineContext = Job() + CoroutineName("UpdateChacker")
|
||||||
fun run() {
|
|
||||||
|
suspend fun check() {
|
||||||
if (cfg.update.enable) {
|
if (cfg.update.enable) {
|
||||||
UpdateChecker().start()
|
run()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
private suspend fun run() {
|
||||||
name = "UpdateCheckerThread"
|
if (instance.buildNumber > 0) {
|
||||||
|
val server = JenkinsServer("https://ci.elytradev.com")
|
||||||
|
val job = server.getJob("elytra/MatterLink/master", "MatterLink/${instance.modVersion}")
|
||||||
|
?: run {
|
||||||
|
logger.error("failed obtaining job: elytra/MatterLink/master")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//TODO: add job name to constants at build time
|
||||||
|
val build = job.lastSuccessfulBuild ?: run {
|
||||||
|
logger.error("no successful build found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
with(build) {
|
||||||
|
when {
|
||||||
|
number > instance.buildNumber -> {
|
||||||
|
logger.warn("Mod out of date! New build $number available at $url")
|
||||||
|
val difference = number - instance.buildNumber
|
||||||
|
LocationHandler.sendToLocations(
|
||||||
|
msg = "MatterLink out of date! You are $difference builds behind! Please download new version from $url",
|
||||||
|
x = 0, y = 0, z = 0, dimension = null,
|
||||||
|
event = ChatEvent.STATUS,
|
||||||
|
cause = "MatterLink update notice"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
number < instance.buildNumber -> logger.error("lastSuccessfulBuild: $number is older than installed build: ${instance.buildNumber}")
|
||||||
|
else -> logger.info("you are up to date")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run() {
|
|
||||||
if (instance.modVersion.contains("-build")) {
|
|
||||||
instance.debug("Not checking updates on Jenkins build")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (instance.modVersion.contains("-dev")) {
|
if (instance.modVersion.contains("-dev")) {
|
||||||
instance.debug("Not checking updates on developer build")
|
logger.debug("Not checking updates on developer build")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val gson = GsonBuilder()
|
logger.info("Checking for new versions...")
|
||||||
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
|
val (request, response, result) = with(instance) {
|
||||||
.create()
|
val useragent =
|
||||||
|
"MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)"
|
||||||
|
logger.debug("setting User-Agent: '$useragent'")
|
||||||
|
|
||||||
instance.info("Checking for new versions...")
|
"https://curse.nikky.moe/api/addon/287323/files".httpGet()
|
||||||
|
.header("User-Agent" to useragent)
|
||||||
val client = HttpClients.createDefault()
|
.responseObject(kotlinxDeserializerOf(loader = CurseFile.serializer().list, json = JSON.nonstrict))
|
||||||
val request = HttpGet("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323")
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val response: HttpResponse = client.execute(request)
|
val apiUpdateList = when(result) {
|
||||||
val apiUpdateList = if (200 == response.statusLine.statusCode) { //HTTP 200 OK
|
is Result.Success -> {
|
||||||
val buffer: BufferedReader = response.entity.content.bufferedReader()
|
result.value
|
||||||
|
|
||||||
//put all of the buffer content onto the string
|
|
||||||
val content = buffer.readText()
|
|
||||||
instance.trace("updateData: $content")
|
|
||||||
|
|
||||||
gson.fromJson(content, Array<CurseFile>::class.java)
|
|
||||||
.filter {
|
|
||||||
it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion)
|
|
||||||
}
|
}
|
||||||
.sortedByDescending { it.fileName.substringAfterLast(" ") }
|
is Result.Failure -> {
|
||||||
|
logger.error("Could not check for updates!")
|
||||||
} else {
|
logger.error("cUrl: ${request.cUrlString()}")
|
||||||
instance.error("Could not check for updates!")
|
logger.error("request: $request")
|
||||||
|
logger.error("response: $response")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.filter { it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion) }
|
||||||
|
|
||||||
val modVersionChunks = instance.modVersion
|
val modVersionChunks = instance.modVersion
|
||||||
.substringBefore("-dev")
|
.substringBefore("-dev")
|
||||||
|
@ -80,13 +98,13 @@ class UpdateChecker : Thread() {
|
||||||
|
|
||||||
val possibleUpdates = mutableListOf<CurseFile>()
|
val possibleUpdates = mutableListOf<CurseFile>()
|
||||||
apiUpdateList.forEach {
|
apiUpdateList.forEach {
|
||||||
instance.debug(it.toString())
|
logger.debug(it.toString())
|
||||||
val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() }
|
val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() }
|
||||||
var bigger = false
|
var bigger = false
|
||||||
version.forEachIndexed { index, chunk ->
|
version.forEachIndexed { index, chunk ->
|
||||||
if (!bigger) {
|
if (!bigger) {
|
||||||
val currentChunk = modVersionChunks.getOrNull(index) ?: 0
|
val currentChunk = modVersionChunks.getOrNull(index) ?: 0
|
||||||
instance.debug("$chunk > $currentChunk")
|
logger.debug("$chunk > $currentChunk")
|
||||||
if (chunk < currentChunk)
|
if (chunk < currentChunk)
|
||||||
return@forEach
|
return@forEach
|
||||||
|
|
||||||
|
@ -104,15 +122,16 @@ class UpdateChecker : Thread() {
|
||||||
val count = possibleUpdates.count()
|
val count = possibleUpdates.count()
|
||||||
val version = if (count == 1) "version" else "versions"
|
val version = if (count == 1) "version" else "versions"
|
||||||
|
|
||||||
instance.info("Matterlink out of date! You are $count $version behind")
|
logger.info("Matterlink out of date! You are $count $version behind")
|
||||||
possibleUpdates.forEach {
|
possibleUpdates.forEach {
|
||||||
instance.info("version: {} download: {}", it.fileName, it.downloadURL)
|
logger.info("version: ${it.fileName} download: ${it.downloadUrl}")
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
|
logger.warn("Mod out of date! New $version available at ${latest.downloadUrl}")
|
||||||
MessageHandler.transmit(ApiMessage(
|
MessageHandlerInst.transmit(
|
||||||
username = cfg.outgoing.systemUser,
|
ApiMessage(
|
||||||
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
|
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadUrl}"
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
[{
|
[{
|
||||||
"modid": "matterlink",
|
"modid": "matterlink",
|
||||||
"name": "MatterLink",
|
"name": "MatterLink",
|
||||||
"description": "Minecraft Server Matterbridge link",
|
"description": "Minecraft Server Matterbridge link, Multi-Platform chat",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
"mcversion": "${mcversion}",
|
"mcversion": "${mcversion}",
|
||||||
"url": "https://github.com/elytra/MatterLink",
|
"url": "https://github.com/elytra/MatterLink",
|
||||||
"authorList":["Arcanitor", "NikkyAi"],
|
"authorList":["NikkyAi", "Arcanitor"],
|
||||||
"credits": "Blame Nikky for talking me into this.",
|
"credits": "Blame Nikky for talking me into this. \n42wim for creating matterbridge \nUna, Falkreon and capitalthree's patience",
|
||||||
"dependencies": ["forgelin"]
|
"dependencies": ["forgelin"]
|
||||||
}]
|
}]
|
|
@ -1,5 +1,12 @@
|
||||||
mod_name = MatterLink
|
modName = MatterLink
|
||||||
mod_version = 1.5.4
|
modVersion = 1.6.4
|
||||||
forgelin_version = 1.6.0
|
forgelinVersion = 1.8.2
|
||||||
curse_id = 287323
|
kotlinVersion = 1.3.10
|
||||||
curse_release_type = beta
|
coroutinesVersion = 1.0.1
|
||||||
|
serializationVersion = 0.9.1
|
||||||
|
shadowVersion = 2.0.2
|
||||||
|
fuelVersion = 8690665998
|
||||||
|
resultVersion = 2.0.0
|
||||||
|
cursegradleVersion = 1.1.2
|
||||||
|
curseId = 287323
|
||||||
|
curseReleaseType = beta
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
java -jar forge-installer.jar --installServer
|
||||||
|
|
||||||
|
FORGE_FILE=`grep "The server installed successfully, you should now be able to run the file " forge-installer.jar.log | tail -1`
|
||||||
|
FORGE_FILE=${FORGE_FILE#"The server installed successfully, you should now be able to run the file "}
|
||||||
|
echo $FORGE_FILE
|
||||||
|
|
||||||
|
cp -f "$FORGE_FILE" forge.jar
|
||||||
|
if [ ! $? -eq 0 ]; then
|
||||||
|
echo "Error installing forge"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "installed forge"
|
||||||
|
|
||||||
|
cp ../eula.txt .
|
||||||
|
|
||||||
|
mkdir -p config
|
||||||
|
rm -rf config/matterlink
|
||||||
|
cp -r ../matterlink_config config/matterlink
|
||||||
|
|
||||||
|
java -jar forge.jar
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
|
||||||
|
|
||||||
|
RUN="$PWD/run/1.12.2"
|
||||||
|
|
||||||
|
rm -rf "$RUN/mods"
|
||||||
|
mkdir -p "$RUN/mods"
|
||||||
|
|
||||||
|
"$PWD/gradlew" :1.12.2:clean :1.12.2:build && cp -f 1.12.2/build/libs/MatterLink-1.12.2-*-dev.jar "$RUN/mods"
|
||||||
|
if [ ! $? -eq 0 ]; then
|
||||||
|
echo "Error compiling matterlink"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$RUN"
|
||||||
|
|
||||||
|
curl -o forge-installer.jar "https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.12.2-14.23.5.2768/forge-1.12.2-14.23.5.2768-installer.jar"
|
||||||
|
curl -L -o "$RUN/mods/Forgelin.jar" "https://minecraft.curseforge.com/projects/shadowfacts-forgelin/files/2640952/download"
|
||||||
|
|
||||||
|
$DIR/scripts/start.sh
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
|
||||||
|
|
||||||
|
RUN="$PWD/run/1.7.10"
|
||||||
|
|
||||||
|
rm -rf "$RUN/mods"
|
||||||
|
mkdir -p "$RUN/mods"
|
||||||
|
|
||||||
|
"$PWD/gradlew" :1.7.10:clean :1.7.10:build && cp -f $DIR/1.7.10/build/libs/MatterLink-1.7.10-*-dev.jar "$RUN/mods"
|
||||||
|
if [ ! $? -eq 0 ]; then
|
||||||
|
echo "Error compiling matterlink"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$RUN"
|
||||||
|
|
||||||
|
curl -o forge-installer.jar "https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forge-1.7.10-10.13.4.1614-1.7.10-installer.jar"
|
||||||
|
|
||||||
|
$DIR/scripts/start.sh
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
|
||||||
|
|
||||||
|
RUN="$PWD/run/1.9.4"
|
||||||
|
|
||||||
|
rm -rf "$RUN/mods"
|
||||||
|
mkdir -p "$RUN/mods"
|
||||||
|
|
||||||
|
"$PWD/gradlew" :1.9.4:clean :1.9.4:build && cp -f 1.9.4/build/libs/MatterLink-1.9.4-*-dev.jar "$RUN/mods"
|
||||||
|
if [ ! $? -eq 0 ]; then
|
||||||
|
echo "Error compiling matterlink"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$RUN"
|
||||||
|
|
||||||
|
curl -o forge-installer.jar "https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.9.4-12.17.0.2051/forge-1.9.4-12.17.0.2051-installer.jar"
|
||||||
|
curl -L -o "$RUN/mods/Forgelin.jar" "https://minecraft.curseforge.com/projects/shadowfacts-forgelin/files/2640952/download" # "https://minecraft.curseforge.com/projects/shadowfacts-forgelin/files/2573311/download"
|
||||||
|
|
||||||
|
$DIR/scripts/start.sh
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
rootProject.name = 'MatterLink'
|
rootProject.name = 'MatterLink'
|
||||||
include 'core', '1.12.2', '1.11.2', '1.10.2', '1.7.10'
|
include 'core'
|
||||||
|
include 'Jankson'
|
||||||
|
include '1.12.2', '1.9.4', '1.7.10'
|
Loading…
Reference in New Issue