Compare commits

...

158 Commits

Author SHA1 Message Date
Agatha Lovelace dd0626b8e9
make default avatar template actually work in discord 2021-08-27 21:31:54 +03:00
Agatha Lovelace eda95f3dfe
fix system user avatar not being registered 2021-08-27 21:26:26 +03:00
Agatha Lovelace 8df4024320
update readme, fix build errors (hopefully) 2021-08-27 17:38:20 +03:00
NikkyAI e561423884 update cursegradle 2019-04-04 01:11:30 +02:00
NikkyAI b12704d507 remove gson dependency, update dependency checks 2018-12-11 15:02:28 +13:00
NikkyAI 43ce9491b9 fix update check for CI builds 2018-11-28 21:53:20 +01:00
NikkyAI e506f14f76 update gitignore 2018-11-28 20:01:49 +01:00
NikkyAI e410515e05 make location logging also debug instead of info 2018-11-28 18:23:59 +01:00
NikkyAI 4392b442da reduce info logging 2018-11-28 17:57:35 +01:00
NikkyAI ecbb95391f accept older forge versions 2018-11-28 16:24:58 +01:00
NikkyAI 05ed3b4a9b do not use the same arguments as nonce and perm level 2018-11-28 15:23:47 +01:00
NikkyAI fe9cb31d72 little bit of debugging help 2018-11-28 15:15:39 +01:00
NikkyAI ef66087044 fix potential library mismatch.. again 2018-11-25 23:37:07 +01:00
NikkyAI 4ce29f0eb6 bumping forgelin, kotlin and libraries version 2018-11-25 00:34:03 +01:00
NikkyAI a0b0e3d24d fix strict json parsing 2018-11-24 23:39:54 +01:00
NikkyAI 04bc439880 make sure debug logging is actually debug 2018-11-23 19:38:18 +01:00
NikkyAI d4802d372f fix idiotic errors in config 2018-11-23 04:00:38 +01:00
NikkyAI a12a9ae74f make json parsing nonstrict 2018-11-18 02:19:41 +01:00
NikkyAI 4d854e5af8 update coroutines 2018-11-18 02:04:19 +01:00
NikkyAI 1bcafb47e1 fix dependency mismatch with Forgelin 2018-11-18 01:59:47 +01:00
NikkyAI 16c66782c6 forgot to shadow kotlinx-serialization-runtime 2018-11-18 00:05:21 +01:00
NikkyAI a2a24c6ed9 bump Fuel version 2018-11-17 14:57:36 +01:00
NikkyAI 2091d59219 fix async mess 2018-11-17 13:21:12 +01:00
NikkyAI f1cc1349ef version bump 2018-11-17 11:33:00 +01:00
NikkyAI 34887a833c update to kotlin 1.3
[1.7.10] fixed send to player NPE
2018-11-02 04:22:56 +01:00
nikky 3082d3e592 update Jankson 2018-08-26 18:47:35 +02:00
nikky 79c9ac1572 revert dropping 1.7.10, adding 1.9.4 instead of 1.10/1.11 2018-08-16 23:54:50 +02:00
nikky 7818afc920 move api into core 2018-08-15 18:42:43 +02:00
nikky e30e8132ca update 1.12.2 with locations 2018-08-15 00:20:21 +02:00
nikky 6cdd7ade7c drop 1.7.10 support 2018-08-08 20:44:42 +02:00
nikky 910d2fc12b release 1.6.3 2018-08-08 20:06:18 +02:00
nikky ac9066225d improve color stripping 2018-08-06 17:38:58 +02:00
nikky 8115bada4f ignore Jankson in sonarqube 2018-07-19 16:48:47 +02:00
nikky e73255c8fc add sonarqube 2018-07-19 16:25:11 +02:00
nikky a9838339d6 add IllegalArgument checks, because parsing UUID can throw 2018-07-19 15:06:17 +02:00
nikky ad3862f14a fix curse update check 2018-07-15 17:28:33 +02:00
nikky 43d6589572 add update checks to jenkins builds 2018-07-15 17:18:06 +02:00
nikky 619e0541d7 add avatars for players and server user 2018-07-15 01:31:20 +02:00
nikky 75a64e49ad adding version command for simplified debugging of user issues 2018-07-14 23:01:10 +02:00
nikky 58ff1a3d8f cleanup gradle stuff 2018-07-11 23:29:02 +02:00
nikky 93c86463c4 improve logging 2018-07-11 20:56:07 +02:00
nikky 83501c867f fixed crash due to runtime constraints 2018-07-11 00:30:09 +02:00
nikky 4627a60c9d execute bridge commands ingame 2018-07-10 05:54:51 +02:00
nikky 42dcd2c543 paste long output 2018-07-10 02:54:21 +02:00
nikky 13a607fcd1 update README 2018-07-08 02:46:15 +02:00
nikky 0057b3037b add linking chat accounts to uuid
implement global timeouts for all commands
improved permission requests
2018-07-08 02:02:38 +02:00
nikky 254c990d76 remove attempts at cleanup 2018-07-07 14:42:40 +02:00
nikky edbac3dfaf clean git mess, loads of jenkins experimentation 2018-07-07 14:41:02 +02:00
nikky c326ca2b48 update jankson 2018-07-03 23:49:25 +02:00
nikky 510123b6f5 buildscript cleanup for 1.10 and 1.11 2018-07-03 14:02:32 +02:00
nikky 66229f4308 reduce INFO spam from messages 2018-06-30 22:49:59 +02:00
nikky 0ebb89cfa8 add more extensions for Jankson 2018-06-28 07:21:05 +02:00
nikky 19e4136d88 add badges to top of readme 2018-06-28 06:16:44 +02:00
nikky 35d5865e5d fix defaults for incomingOptions and remnants of space-seperated emoji 2018-06-28 01:09:07 +02:00
nikky 1356e3682f fix NPE in Jankson and finetune hjson loading 2018-06-26 19:08:36 +02:00
nikky 88bee22010 this really should not break 2018-06-26 03:51:17 +02:00
nikky 602762f371 add option to disable req command globally 2018-06-25 14:25:57 +02:00
nikky 33c94a589c raise permission requirement for exec 2018-06-25 14:17:31 +02:00
nikky 3a79834e4c added permisssion request commands 2018-06-25 14:12:14 +02:00
nikky 5eb79935ba switch main config to hjson 2018-06-25 02:28:30 +02:00
nikky 6af52cc58e improve type adapters for CustomCommand 2018-06-24 14:57:42 +02:00
nikky f24ba763ac implemented jankson loading for commands and permissions 2018-06-24 13:58:38 +02:00
nikky 240bff1677 add jankson dependency 2018-06-22 11:58:51 +02:00
nikky e84f616d9b lower permission requirement for uptime 2018-06-17 13:35:47 +02:00
nikky 166fa8a6e1 fix small typo 2018-05-29 00:44:39 +02:00
nikky ff36de2446 changing allowArgs to regex check 2018-05-29 00:37:09 +02:00
nikky 6cab3c9838 fix colorcodes in death message 2018-05-26 00:05:32 +02:00
nikky 451de594cd small cleanup 2018-05-24 23:46:23 +02:00
nikky 9c52df1f98 fix actions not sending / receiving properly 2018-05-24 23:10:06 +02:00
nikky fcd1a148a2 actually stripping colors attempt 3 and counting 2018-05-24 21:10:20 +02:00
nikky 0429407547 actually stripping colors attempt 2 2018-05-24 20:07:32 +02:00
nikky cee1673728 add color stripping to incoming chat 2018-05-24 19:56:47 +02:00
nikky e652a27a06 fix NPE in kotlin.. and several smaller issues 2018-05-24 19:51:06 +02:00
nikky dd07bdd386 fix dangling import 2018-05-24 03:48:37 +02:00
nikky 68144ae512 add colorcode stripping
fix potential infinite crash loop
2018-05-24 03:45:17 +02:00
nikky 25627c138a fix readme 2018-05-23 23:43:36 +02:00
nikky 41454b533d add exec command to the defaults 2018-05-23 22:52:44 +02:00
nikky 07bc1736e6 allow `execute` commands to run as op 2018-05-21 13:54:23 +02:00
nikky 1400627187 keep track of default commands for updating
use nullable variables because gson is stupid
2018-05-21 12:00:55 +02:00
nikky fd7fd69306 hotfix, blame past me 2018-05-10 00:56:28 +02:00
nikky c3b6459738 version bump 2018-05-08 08:10:24 +02:00
nikky 1522269e44 Added submodule api 2018-05-08 01:09:50 +02:00
nikky 10ac3bf92b updated defaults, added whoami 2018-05-07 08:51:43 +02:00
nikky 3de56755be Badges on all the README's and code formatting 2018-05-05 16:44:10 +02:00
nikky 928576c64b fix gson type confusion bug 2018-04-22 18:56:42 +02:00
NikkyAI f367690789 bump version to 1.5.4 2018-04-15 20:03:52 +02:00
NikkyAI 6f9da8f2e3 support displayname changing mods like ConventionalChat 2018-04-15 19:57:19 +02:00
NikkyAI ada8a3ac89 oops 2018-03-08 16:06:57 +01:00
NikkyAI 02c9cb076d fix 1.7.10 relations, update license 2018-03-08 16:01:20 +01:00
Nikky Ai 08affaf9ec update update checker 2018-03-07 23:04:06 +01:00
NikkyAI 4e8fba5725
improve command aliases (#4)
* redo alias in commands and use hocon for commands and permission

* fix packaging issue on 1.1x.2 builds

* revert attempts at hocon
2018-02-26 05:15:43 +01:00
Nikky Ai c5fd53a00c add timeous to commands 2018-02-25 00:51:56 +01:00
Nikky Ai 53e84afc6d add more know properties to the RESPONSE template 2018-02-24 21:03:02 +01:00
NikkyAI 3591044368 how did i miss this.. ? 2018-02-22 18:28:24 +01:00
NikkyAI c7146ce7df improve docs and reconnection handling 2018-02-21 22:34:16 +01:00
Nikky Ai e5cd059313 remove offending tickCounter 2018-02-21 06:00:38 +01:00
Nikky Ai d5fd7328c7 improve update check and add handleTick 2018-02-21 05:52:01 +01:00
Nikky Ai f6b48085b0 add custom command: uptime to the defaults 2018-02-21 05:23:01 +01:00
Nikky Ai 172305482d refactor config and add connect / disconnect announcements as debug option 2018-02-21 03:13:49 +01:00
NikkyAI bce5cd871e wtf gradle 2018-02-19 22:33:19 +01:00
NikkyAI 1ac7bee4cc more curseGradle fixes 2018-02-19 21:06:08 +01:00
NikkyAI c42f91c966 curseforge uploaded recompiled the wrong files and everything broke 2018-02-19 20:42:12 +01:00
NikkyAI 83d7028280 MatterLink actually works now, no promises though 2018-02-19 20:31:02 +01:00
NikkyAI 846ebecc44 FUCK YOU GRADLE 2018-02-19 20:04:40 +01:00
NikkyAI 894b6d78bd fix 1.7.10 receive and send messaes to chat 2018-02-19 18:49:11 +01:00
NikkyAI 0f3ebeb67d skip update check for jenkins and dev builds, add default users (power 0) to permissions as examples 2018-02-19 16:25:52 +01:00
NikkyAI 82c550f37f experimental 1.7.10 fixes, improved version comparison in update checker 2018-02-19 16:03:37 +01:00
NikkyAI 6a77fbc3f3 fix some invalid commands being passed through 2018-02-19 01:04:05 +01:00
NikkyAI 41c8776993 format all the things 2018-02-19 00:19:13 +01:00
DaMachinator 6c5a381903 finished loading custom commands and permissions from file 2018-02-18 23:58:34 +01:00
DaMachinator 968ff1aacc WIP custom commands and permissions loading from json 2018-02-18 20:22:27 +01:00
NikkyAI 4d51894628 fix duplicate achievment display 2018-02-18 06:05:06 +01:00
NikkyAI 7d05aa51f5 version bump to 1.4 2018-02-18 04:52:35 +01:00
NikkyAI 7fd8b31474 restructure configuration, fix connection errors, register events properly on 1.7.10 2018-02-18 04:50:58 +01:00
NikkyAI 23c65bd4e1 add 1.7.10 to jenkins 2018-02-17 23:53:45 +01:00
NikkyAI 67d0aab64e add 1.7.10 2018-02-17 23:52:29 +01:00
NikkyAI cfc677868a refactor message stream 2018-02-17 22:45:48 +01:00
NikkyAI e495e588da fix achievment/advancement string 2018-02-17 18:30:02 +01:00
NikkyAI 00b1969754 refactorio 2018-02-17 18:16:06 +01:00
DaMachinator cdcc79fcaf Merge branch 'master' of https://github.com/elytra/MatterLink 2018-02-17 11:41:20 -05:00
DaMachinator 4c19b26ce3 Begin refactor 2018-02-17 11:39:05 -05:00
NikkyAI 4545b7d38a fix update checker output format 2018-02-17 17:26:02 +01:00
NikkyAI aad5365d19 finalize Update checker 2018-02-17 17:18:23 +01:00
Nikky Ai 19d7017336 add Update Check, simplify config access 2018-02-17 04:07:22 +01:00
DaMachinator 7ea258fdc4 Update checker 2018-02-16 15:09:47 -05:00
DaMachinator d93e0249b2 Update README.MD 2018-02-15 18:00:56 -05:00
DaMachinator 740e967a90 Update README.MD 2018-02-15 17:56:54 -05:00
DaMachinator 901e5378c1 Wrong variable.... 2018-02-15 17:32:10 -05:00
NikkyAI 62ce5423a3 fixed oversight in refactor 2018-02-15 23:20:01 +01:00
NikkyAI dc702b2445 because ForgeGradle sucks.. at least before 2.3-SNAPSHOT 2018-02-15 23:03:52 +01:00
DaMachinator 5f180f0dbf Should *actually* work now 2018-02-15 11:45:47 -05:00
DaMachinator f36e77ed31 Should work now 2018-02-15 11:43:11 -05:00
DaMachinator 3a9889ead7 Ability to access above-mentioned commandsender 2018-02-15 11:31:57 -05:00
DaMachinator ae0cf58abf Implement new custom ICommandSenders 2018-02-15 11:25:24 -05:00
DaMachinator f63e03dd5c WIP command passthrough 2018-02-15 11:09:42 -05:00
NikkyAI 445bf425c2 add proper required-after forgelin and forge version, improves to the build.gradle 2018-02-15 16:51:30 +01:00
DaMachinator 160681489b Added command pass-through config 2018-02-15 10:15:55 -05:00
DaMachinator 56dd6556bd Added $uptime command, abstracted command registration into core 2018-02-15 08:30:36 -05:00
DaMachinator 1032ed1619 Merge remote-tracking branch 'origin/master' 2018-02-15 08:19:44 -05:00
DaMachinator 74f7c9ec65 implement getUptime 2018-02-15 08:19:34 -05:00
NikkyAI 7c60477f53 refactor config loading and reloading more 2018-02-14 19:22:24 +01:00
DaMachinator 0b5abf8a1e delet todo 2018-02-14 12:46:53 -05:00
DaMachinator cf2e514843 Refactor BaseConfig.reload() 2018-02-14 12:18:57 -05:00
NikkyAI 7b20616e0b make sure /bridge reload works 2018-02-14 18:04:04 +01:00
DaMachinator 51b184266b Implement /reload 2018-02-14 11:54:01 -05:00
DaMachinator 06957f07fb Abstracted commands into core 2018-02-14 11:11:54 -05:00
NikkyAI acaca1a04e add fake debug and trace loggers 2018-02-14 16:29:59 +01:00
NikkyAI c426e625d3 restructure config 2018-02-14 06:52:27 +01:00
NikkyAI 572c326f4c adding changelog to cursegradle config 2018-02-14 06:26:12 +01:00
NikkyAI f45cd7c9f7 fix CurseGradle displaynames 2018-02-14 06:04:33 +01:00
NikkyAI 22c75e3856 try to fix cursegradel changelog 2018-02-14 05:51:07 +01:00
NikkyAI bcc53a090e add damage type emoji to death message
modify gradle build to inlcude changelogs
2018-02-14 05:34:45 +01:00
NikkyAI 6a117af7ca update .gitignore 2018-02-13 23:27:22 +01:00
NikkyAI 382b3dd3f0 release 1.2.3 2018-02-12 21:44:03 +01:00
NikkyAI 39c835d8e3 add sample and update README 2018-02-12 17:41:07 +01:00
NikkyAI 09c8465fe3 remove unecessary Enum 2018-02-11 21:23:54 +01:00
NikkyAI f69eac719c deduplicate configuration code 2018-02-11 21:12:56 +01:00
NikkyAI 440ab5ac9f versioning scheme change 2018-02-11 17:23:52 +01:00
104 changed files with 5637 additions and 2588 deletions

117
.gitignore vendored
View File

@ -1,31 +1,102 @@
#Courtesy of Buildcraft # Created by https://www.gitignore.io/api/gradle,kotlin,intellij+iml
#idea ### Intellij ###
*.iml # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
*.ipr # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
## File-based project format:
*.iws *.iws
.idea
out
build
classes
#eclipse ## Plugin-specific files:
.project
.classpath
.settings/
.metadata
*.launch
org.*
bin
#gradle # IntelliJ
out/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij+all Patch ###
# Ignores the whole idea folder
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
### Kotlin ###
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Gradle ###
.gradle .gradle
**/build/
#runtime # Ignore Gradle GUI config
run gradle-app.setting
run_server
#mac # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
.DS_Store !gradle-wrapper.jar
*.hprof # Cache of project
.gradletasknamecache
# End of https://www.gitignore.io/api/gradle,kotlin,intellij+iml
### MatterLink ###
classes/
run/
*.tmp
**/gen/
\.floo
\.flooignore
bugreport/

3
.gitmodules vendored Normal file
View File

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

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.home": "/usr/lib/jvm/java-8-openjdk/"
}

View File

@ -1,92 +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"
}
apply plugin: 'net.minecraftforge.gradle.forge'
version = mc_version + "-" + mod_version
archivesBaseName = "MatterLink"
sourceCompatibility = targetCompatibility = '1.8'
dependencies {
compile project(':core')
compile group: "net.shadowfacts", name: "Forgelin", version: "1.6.0"
}
shadowJar {
classifier ''
// configurations = [project.configurations.shadow]
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("org.apache.httpcomponents:httpclient:4.3.3"))
include(dependency("org.apache.httpcomponents:httpcore:4.3.2"))
include(dependency('commons-logging:commons-logging:1.1.3'))
}
exclude 'dummyThing'
}
minecraft {
version = mc_version + "-" + forge_version
runDir = "run"
mappings = mcp_mappings
replaceIn 'MatterLink.kt'
replace '@VERSION@', mod_version
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.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.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.reobfShadowJar.mustRunAfter shadowJar

View File

@ -1,3 +0,0 @@
mc_version = 1.10.2
mcp_mappings = stable_29
forge_version = 12.18.3.2185

View File

@ -1,97 +0,0 @@
package matterlink
import matterlink.bridge.ServerChatHandler
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.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.FMLCommonHandler
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 EventWrapper {
//MC-VERSION & FORGE DEPENDENT
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AchievementEvent) {
val name = e.entityPlayer.name
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
ProgressHandler.handleProgress(name, text)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatHandler.handleChat(user, msg)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun commandEvent(e: CommandEvent) {
val sender =
when {
e.sender is EntityPlayer -> e.sender.name
e.sender is DedicatedServer -> cfg!!.relay.systemUser
e.sender is TileEntityCommandBlock -> "CommandBlock"
else -> return
}
val args = e.parameters.joinToString(" ")
val type = when {
e.command is CommandEmote -> USER_ACTION
e.command is CommandBroadcast -> ""
else -> return
}
CommandHandler.handleCommand(sender, args, type)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText
)
}
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
JoinLeaveHandler.handleJoin(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
JoinLeaveHandler.handleLeave(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
ServerChatHandler.writeIncomingToChat(FMLCommonHandler.instance().minecraftServerInstance.tickCounter)
}
}

View File

@ -1,78 +0,0 @@
package matterlink
import jline.internal.Log
import matterlink.bridge.MessageHandler
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.HelpCommand
import matterlink.bridge.command.PlayerListCommand
import matterlink.command.CommandMatterlink
import net.minecraft.util.text.TextComponentString
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
const val MODID = "matterlink"
const val NAME = "MatterLink"
const val VERSION = "@VERSION@"
lateinit var logger: Logger
@Mod(
modid = MODID,
name = NAME, version = VERSION,
serverSideOnly = true,
useMetadata = true,
acceptableRemoteVersions = "*",
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter"
)
object MatterLink : IMatterLink() {
init {
instance = this
}
@Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) {
logger = event.modLog
logger.info("Building bridge!")
MatterLinkConfig(event.suggestedConfigurationFile)
}
@Mod.EventHandler
fun init(event: FMLInitializationEvent) {
BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand)
}
@Mod.EventHandler
fun serverAboutToStart(event: FMLServerAboutToStartEvent) {
// MessageHandler.start(clear = true)
}
@Mod.EventHandler
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
event.registerServerCommand(CommandMatterlink())
connect()
}
@Mod.EventHandler
fun serverStopping(event: FMLServerStoppingEvent) {
disconnect()
}
//FORGE-DEPENDENT
override fun wrappedSendToPlayers(msg: String) {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendChatMsg(TextComponentString(msg))
}
//FORGE-DEPENDENT
override fun wrappedPlayerList(): Array<String> {
return FMLCommonHandler.instance().minecraftServerInstance.playerList.onlinePlayerNames
}
override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO),formatString, *data)
}

View File

@ -1,128 +0,0 @@
package matterlink
import matterlink.config.IMatterLinkConfig
import matterlink.config.cfg
import net.minecraftforge.common.config.Configuration
import java.io.File
import java.util.regex.Pattern
class MatterLinkConfig(file: File) : IMatterLinkConfig() {
init {
logger.info("Reading bridge blueprints... from {}", file)
val config = Configuration(file)
config.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS, "Relay options")
relay = RelayOptions(
systemUser = config.getString(
"systemUser",
CATEGORY_RELAY_OPTIONS,
relay.systemUser,
"Name of the server user (used by death and advancement messages and the /say command)"
),
deathEvents = config.getBoolean(
"deathEvents",
CATEGORY_RELAY_OPTIONS,
relay.deathEvents,
"Relay player death messages"
),
advancements = config.getBoolean(
"advancements",
CATEGORY_RELAY_OPTIONS,
relay.advancements,
"Relay player advancements"
),
joinLeave = config.getBoolean(
"joinLeave",
CATEGORY_RELAY_OPTIONS,
relay.joinLeave,
"Relay when a player joins or leaves the game"
)
)
config.addCustomCategoryComment(CATEGORY_COMMAND, "User commands")
command = CommandOptions(
enable = config.getBoolean(
"enable",
CATEGORY_COMMAND,
command.enable,
"Enable MC bridge commands"
),
prefix = config.getString(
"prefix",
CATEGORY_COMMAND,
command.prefix,
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)",
Pattern.compile("^[^0-9A-Za-z/]$")
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_INCOMING, "Gateway -> Server" +
"Formatting options: " +
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
formatting = FormattingOptions(
chat = config.getString(
"chat",
CATEGORY_FORMATTING_INCOMING,
formatting.chat,
"Generic chat event, just talking"
),
joinLeave = config.getString(
"joinLeave",
CATEGORY_FORMATTING_INCOMING,
formatting.joinLeave,
"Join and leave events from other gateways"
),
action = config.getString(
"action",
CATEGORY_FORMATTING_INCOMING,
formatting.action,
"User actions (/me) sent by users from other gateways"
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_JOIN_LEAVE, "Server -> Gateway" +
"Formatting options: " +
"Available variables: {username}, {username:antiping}")
formattingJoinLeave = FormattingJoinLeave(
joinServer = config.getString(
"joinServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.joinServer,
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
),
leaveServer = config.getString(
"leaveServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.leaveServer,
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
)
)
config.addCustomCategoryComment(CATEGORY_CONNECTION, "Connection settings")
connect = ConnectOptions(
url = config.getString(
"connectURL",
CATEGORY_CONNECTION,
connect.url,
"The URL or IP address of the bridge server"
),
authToken = config.getString(
"authToken",
CATEGORY_CONNECTION,
connect.authToken,
"Auth token used to connect to the bridge server"
),
gateway = config.getString(
"gateway",
CATEGORY_CONNECTION,
connect.gateway,
"MatterBridge gateway"
)
)
if (config.hasChanged()) config.save()
cfg = this
}
}

View File

@ -1,53 +0,0 @@
package matterlink.command
import com.google.common.collect.Lists
import matterlink.MODID
import matterlink.bridge.MessageHandler
import matterlink.bridge.ServerChatHandler
import matterlink.instance
import matterlink.logger
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.server.MinecraftServer
class CommandMatterlink : CommandBase() {
private val aliases: List<String>
init {
aliases = Lists.newArrayList(MODID, "bridge", "BRIDGE")
}
override fun getName(): String {
return "bridge"
}
override fun getUsage(sender: ICommandSender): String {
return "bridge <connect|disconnect>"
}
override fun getAliases(): List<String> {
return aliases
}
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) /*throws CommandException*/ {
if (args.isEmpty()) {
//throw new WrongUsageException("")
return
}
//TODO: check if sender is OP or test if normal users cannot send this
val cmd = args[0].toLowerCase()
when (cmd) {
"connect" -> {
instance.connect()
}
"disconnect" -> {
instance.disconnect()
}
}
}
}

View File

@ -1,92 +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"
}
apply plugin: 'net.minecraftforge.gradle.forge'
version = mc_version + "-" + mod_version
archivesBaseName = "MatterLink"
sourceCompatibility = targetCompatibility = '1.8'
dependencies {
compile project(':core')
compile group: "net.shadowfacts", name: "Forgelin", version: "1.6.0"
}
shadowJar {
classifier ''
// configurations = [project.configurations.shadow]
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("org.apache.httpcomponents:httpclient:4.3.3"))
include(dependency("org.apache.httpcomponents:httpcore:4.3.2"))
include(dependency('commons-logging:commons-logging:1.1.3'))
}
exclude 'dummyThing'
}
minecraft {
version = mc_version + "-" + forge_version
runDir = "run"
mappings = mcp_mappings
replaceIn 'MatterLink.kt'
replace '@VERSION@', mod_version
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.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.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.reobfShadowJar.mustRunAfter shadowJar

View File

@ -1,3 +0,0 @@
mc_version = 1.11.2
mcp_mappings = stable_32
forge_version = 13.20.1.2386

View File

@ -1,97 +0,0 @@
package matterlink
import matterlink.bridge.ServerChatHandler
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.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.FMLCommonHandler
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 EventWrapper {
//MC-VERSION & FORGE DEPENDENT
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AchievementEvent) {
val name = e.entityPlayer.name
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
ProgressHandler.handleProgress(name, text)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatHandler.handleChat(user, msg)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun commandEvent(e: CommandEvent) {
val sender =
when {
e.sender is EntityPlayer -> e.sender.name
e.sender is DedicatedServer -> cfg!!.relay.systemUser
e.sender is TileEntityCommandBlock -> "CommandBlock"
else -> return
}
val args = e.parameters.joinToString(" ")
val type = when {
e.command is CommandEmote -> USER_ACTION
e.command is CommandBroadcast -> ""
else -> return
}
CommandHandler.handleCommand(sender, args, type)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText
)
}
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
JoinLeaveHandler.handleJoin(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
JoinLeaveHandler.handleLeave(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
ServerChatHandler.writeIncomingToChat(FMLCommonHandler.instance().minecraftServerInstance.tickCounter)
}
}

View File

@ -1,78 +0,0 @@
package matterlink
import jline.internal.Log
import matterlink.bridge.MessageHandler
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.HelpCommand
import matterlink.bridge.command.PlayerListCommand
import matterlink.command.CommandMatterlink
import net.minecraft.util.text.TextComponentString
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
const val MODID = "matterlink"
const val NAME = "MatterLink"
const val VERSION = "@VERSION@"
lateinit var logger: Logger
@Mod(
modid = MODID,
name = NAME, version = VERSION,
serverSideOnly = true,
useMetadata = true,
acceptableRemoteVersions = "*",
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter"
)
object MatterLink : IMatterLink() {
init {
instance = this
}
@Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) {
logger = event.modLog
logger.info("Building bridge!")
MatterLinkConfig(event.suggestedConfigurationFile)
}
@Mod.EventHandler
fun init(event: FMLInitializationEvent) {
BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand)
}
@Mod.EventHandler
fun serverAboutToStart(event: FMLServerAboutToStartEvent) {
// MessageHandler.start(clear = true)
}
@Mod.EventHandler
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
event.registerServerCommand(CommandMatterlink())
connect()
}
@Mod.EventHandler
fun serverStopping(event: FMLServerStoppingEvent) {
disconnect()
}
//FORGE-DEPENDENT
override fun wrappedSendToPlayers(msg: String) {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
}
//FORGE-DEPENDENT
override fun wrappedPlayerList(): Array<String> {
return FMLCommonHandler.instance().minecraftServerInstance.playerList.onlinePlayerNames
}
override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO),formatString, *data)
}

View File

@ -1,128 +0,0 @@
package matterlink
import matterlink.config.IMatterLinkConfig
import matterlink.config.cfg
import net.minecraftforge.common.config.Configuration
import java.io.File
import java.util.regex.Pattern
class MatterLinkConfig(file: File) : IMatterLinkConfig() {
init {
logger.info("Reading bridge blueprints... from {}", file)
val config = Configuration(file)
config.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS, "Relay options")
relay = RelayOptions(
systemUser = config.getString(
"systemUser",
CATEGORY_RELAY_OPTIONS,
relay.systemUser,
"Name of the server user (used by death and advancement messages and the /say command)"
),
deathEvents = config.getBoolean(
"deathEvents",
CATEGORY_RELAY_OPTIONS,
relay.deathEvents,
"Relay player death messages"
),
advancements = config.getBoolean(
"advancements",
CATEGORY_RELAY_OPTIONS,
relay.advancements,
"Relay player advancements"
),
joinLeave = config.getBoolean(
"joinLeave",
CATEGORY_RELAY_OPTIONS,
relay.joinLeave,
"Relay when a player joins or leaves the game"
)
)
config.addCustomCategoryComment(CATEGORY_COMMAND, "User commands")
command = CommandOptions(
enable = config.getBoolean(
"enable",
CATEGORY_COMMAND,
command.enable,
"Enable MC bridge commands"
),
prefix = config.getString(
"prefix",
CATEGORY_COMMAND,
command.prefix,
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)",
Pattern.compile("^[^0-9A-Za-z/]$")
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_INCOMING, "Gateway -> Server" +
"Formatting options: " +
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
formatting = FormattingOptions(
chat = config.getString(
"chat",
CATEGORY_FORMATTING_INCOMING,
formatting.chat,
"Generic chat event, just talking"
),
joinLeave = config.getString(
"joinLeave",
CATEGORY_FORMATTING_INCOMING,
formatting.joinLeave,
"Join and leave events from other gateways"
),
action = config.getString(
"action",
CATEGORY_FORMATTING_INCOMING,
formatting.action,
"User actions (/me) sent by users from other gateways"
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_JOIN_LEAVE, "Server -> Gateway" +
"Formatting options: " +
"Available variables: {username}, {username:antiping}")
formattingJoinLeave = FormattingJoinLeave(
joinServer = config.getString(
"joinServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.joinServer,
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
),
leaveServer = config.getString(
"leaveServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.leaveServer,
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
)
)
config.addCustomCategoryComment(CATEGORY_CONNECTION, "Connection settings")
connect = ConnectOptions(
url = config.getString(
"connectURL",
CATEGORY_CONNECTION,
connect.url,
"The URL or IP address of the bridge server"
),
authToken = config.getString(
"authToken",
CATEGORY_CONNECTION,
connect.authToken,
"Auth token used to connect to the bridge server"
),
gateway = config.getString(
"gateway",
CATEGORY_CONNECTION,
connect.gateway,
"MatterBridge gateway"
)
)
if (config.hasChanged()) config.save()
cfg = this
}
}

View File

@ -1,53 +0,0 @@
package matterlink.command
import com.google.common.collect.Lists
import matterlink.MODID
import matterlink.bridge.MessageHandler
import matterlink.bridge.ServerChatHandler
import matterlink.instance
import matterlink.logger
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.server.MinecraftServer
class CommandMatterlink : CommandBase() {
private val aliases: List<String>
init {
aliases = Lists.newArrayList(MODID, "bridge", "BRIDGE")
}
override fun getName(): String {
return "bridge"
}
override fun getUsage(sender: ICommandSender): String {
return "bridge <connect|disconnect>"
}
override fun getAliases(): List<String> {
return aliases
}
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) /*throws CommandException*/ {
if (args.isEmpty()) {
//throw new WrongUsageException("")
return
}
//TODO: check if sender is OP or test if normal users cannot send this
val cmd = args[0].toLowerCase()
when (cmd) {
"connect" -> {
instance.connect()
}
"disconnect" -> {
instance.disconnect()
}
}
}
}

View File

@ -1,61 +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"
}
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 = mc_version + "-" + mod_version version = project.mc_version + '-' + project.modVersion
archivesBaseName = "MatterLink" 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: "1.6.0" shadow (project(path: ':core', configuration: 'shadow')) { transitive = false }
compile group: 'net.shadowfacts', name: 'Forgelin', version: project.forgelinVersion
} }
shadowJar { shadowJar {
classifier '' classifier = ''
// configurations = [project.configurations.shadow]
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("org.apache.httpcomponents:httpclient:4.3.3"))
include(dependency("org.apache.httpcomponents:httpcore:4.3.2"))
include(dependency('commons-logging:commons-logging:1.1.3'))
}
exclude 'dummyThing' exclude 'dummyThing'
configurations = [project.configurations.shadow]
} }
minecraft { minecraft {
version = mc_version + "-" + forge_version version = project.mc_version + '-' + project.forge_version
runDir = "run" runDir = 'run'
mappings = mcp_mappings mappings = project.mcp_mappings
replaceIn 'MatterLink.kt' replaceIn 'Constants.kt'
replace '@VERSION@', mod_version 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 { 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.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
@ -63,7 +69,7 @@ processResources {
include 'mcmod.info' include 'mcmod.info'
// replace version and mcversion // replace version and mcversion
expand 'version': project.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
@ -74,12 +80,12 @@ 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
// copy everything else except the mcmod.info // copy everything else except the mcmod.info
from (project(":core").sourceSets.main.allSource) { from(project(":core").sourceSets.main.allSource) {
exclude 'mcmod.info' exclude 'mcmod.info'
} }
} }
@ -87,5 +93,29 @@ sourceJar {
reobf { reobf {
shadowJar { mappingType = 'SEARGE' } shadowJar { mappingType = 'SEARGE' }
} }
tasks.shadowJar.finalizedBy reobfShadowJar
tasks.reobfShadowJar.mustRunAfter shadowJar curseforge {
if (project.hasProperty('CURSEFORGE_API_TOKEN') && project.hasProperty('release')) {
apiKey = CURSEFORGE_API_TOKEN
}
project {
id = project.curseId
releaseType = project.curseReleaseType
if (project.hasProperty('changelog_file')) {
println("changelog = $changelog_file")
changelogType = 'markdown'
changelog = file(changelog_file)
}
relations {
requiredLibrary 'shadowfacts-forgelin'
}
mainArtifact(shadowJar) {
displayName = "MatterLink $version"
}
}
}
runServer {
outputs.upToDateWhen { false }
}

View File

@ -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

View File

@ -0,0 +1,8 @@
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@,);"
const val BUILD_NUMBER = -1//@BUILD_NUMBER@

View File

@ -0,0 +1,143 @@
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.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.AdvancementEvent
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: AdvancementEvent) = runBlocking {
if (e.advancement.display == null) return@runBlocking
ProgressHandler.handleProgress(
name = e.entityPlayer.displayName.unformattedText,
message = "has made the advancement",
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
@SubscribeEvent
@JvmStatic
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
@JvmStatic
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 || name.equals("me", true) -> ChatEvent.ACTION
this is CommandBroadcast || name.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
@JvmStatic
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
@JvmStatic
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
@JvmStatic
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
@JvmStatic
fun serverTickEvent(e: TickEvent.ServerTickEvent) = runBlocking {
if (e.phase == TickEvent.Phase.END)
TickHandler.handleTick()
}
}

View File

@ -1,98 +0,0 @@
package matterlink
import matterlink.bridge.ServerChatHandler
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.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.AdvancementEvent
import net.minecraftforge.fml.common.FMLCommonHandler
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 EventWrapper {
//MC-VERSION & FORGE DEPENDENT
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AdvancementEvent) {
if (e.advancement.display == null) return
val name = e.entityPlayer.name
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
ProgressHandler.handleProgress(name, text)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatHandler.handleChat(user, msg)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun commandEvent(e: CommandEvent) {
val sender =
when {
e.sender is EntityPlayer -> e.sender.name
e.sender is DedicatedServer -> cfg!!.relay.systemUser
e.sender is TileEntityCommandBlock -> "CommandBlock"
else -> return
}
val args = e.parameters.joinToString(" ")
val type = when {
e.command is CommandEmote -> USER_ACTION
e.command is CommandBroadcast -> ""
else -> return
}
CommandHandler.handleCommand(sender, args, type)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText
)
}
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
JoinLeaveHandler.handleJoin(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
JoinLeaveHandler.handleLeave(e.player.name)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
ServerChatHandler.writeIncomingToChat(FMLCommonHandler.instance().minecraftServerInstance.tickCounter)
}
}

View File

@ -1,65 +1,79 @@
package matterlink package matterlink
import matterlink.bridge.MessageHandler import com.mojang.authlib.GameProfile
import matterlink.bridge.command.BridgeCommandRegistry import kotlinx.coroutines.runBlocking
import matterlink.bridge.command.HelpCommand import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.PlayerListCommand import matterlink.command.AuthCommand
import matterlink.command.CommandMatterlink 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.minecraft.util.text.TextComponentString
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
const val MODID = "matterlink"
const val NAME = "MatterLink"
const val VERSION = "@VERSION@"
lateinit var logger: Logger
@Mod( @Mod(
modid = MODID, modid = MODID,
name = NAME, version = VERSION, name = NAME, version = MODVERSION,
serverSideOnly = true, serverSideOnly = true,
useMetadata = true, useMetadata = true,
acceptableRemoteVersions = "*", acceptableRemoteVersions = "*",
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter" modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter",
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!")
MatterLinkConfig(event.suggestedConfigurationFile) cfg = BaseConfig(event.modConfigurationDirectory).load()
} }
@Mod.EventHandler @Mod.EventHandler
fun init(event: FMLInitializationEvent) { fun init(event: FMLInitializationEvent) {
BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand) logger.debug("Registering bridge commands")
} 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)
connect() runBlocking {
start()
}
} }
@Mod.EventHandler @Mod.EventHandler
fun serverStopping(event: FMLServerStoppingEvent) { fun serverStopping(event: FMLServerStoppingEvent) = runBlocking {
disconnect() stop()
} }
//FORGE-DEPENDENT //FORGE-DEPENDENT
@ -67,11 +81,70 @@ object MatterLink : IMatterLink() {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg)) FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
} }
//FORGE-DEPENDENT override fun wrappedSendToPlayer(username: String, msg: String) {
override fun wrappedPlayerList(): Array<String> { val profile = profileByName(username) ?: run {
return FMLCommonHandler.instance().minecraftServerInstance.playerList.onlinePlayerNames 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 log(level: String, formatString: String, vararg data: Any) = override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
logger.log(Level.toLevel(level, Level.INFO),formatString, *data) 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 modVersion: String = MODVERSION
override val buildNumber = BUILD_NUMBER
override val forgeVersion = ForgeVersion.getVersion()
} }

View File

@ -1,128 +0,0 @@
package matterlink
import matterlink.config.IMatterLinkConfig
import matterlink.config.cfg
import net.minecraftforge.common.config.Configuration
import java.io.File
import java.util.regex.Pattern
class MatterLinkConfig(file: File) : IMatterLinkConfig() {
init {
logger.info("Reading bridge blueprints... from {}", file)
val config = Configuration(file)
config.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS, "Relay options")
relay = RelayOptions(
systemUser = config.getString(
"systemUser",
CATEGORY_RELAY_OPTIONS,
relay.systemUser,
"Name of the server user (used by death and advancement messages and the /say command)"
),
deathEvents = config.getBoolean(
"deathEvents",
CATEGORY_RELAY_OPTIONS,
relay.deathEvents,
"Relay player death messages"
),
advancements = config.getBoolean(
"advancements",
CATEGORY_RELAY_OPTIONS,
relay.advancements,
"Relay player advancements"
),
joinLeave = config.getBoolean(
"joinLeave",
CATEGORY_RELAY_OPTIONS,
relay.joinLeave,
"Relay when a player joins or leaves the game"
)
)
config.addCustomCategoryComment(CATEGORY_COMMAND, "User commands")
command = CommandOptions(
enable = config.getBoolean(
"enable",
CATEGORY_COMMAND,
command.enable,
"Enable MC bridge commands"
),
prefix = config.getString(
"prefix",
CATEGORY_COMMAND,
command.prefix,
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)",
Pattern.compile("^[^0-9A-Za-z/]$")
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_INCOMING, "Gateway -> Server" +
"Formatting options: " +
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
formatting = FormattingOptions(
chat = config.getString(
"chat",
CATEGORY_FORMATTING_INCOMING,
formatting.chat,
"Generic chat event, just talking"
),
joinLeave = config.getString(
"joinLeave",
CATEGORY_FORMATTING_INCOMING,
formatting.joinLeave,
"Join and leave events from other gateways"
),
action = config.getString(
"action",
CATEGORY_FORMATTING_INCOMING,
formatting.action,
"User actions (/me) sent by users from other gateways"
)
)
config.addCustomCategoryComment(CATEGORY_FORMATTING_JOIN_LEAVE, "Server -> Gateway" +
"Formatting options: " +
"Available variables: {username}, {username:antiping}")
formattingJoinLeave = FormattingJoinLeave(
joinServer = config.getString(
"joinServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.joinServer,
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
),
leaveServer = config.getString(
"leaveServer",
CATEGORY_FORMATTING_JOIN_LEAVE,
formattingJoinLeave.leaveServer,
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
)
)
config.addCustomCategoryComment(CATEGORY_CONNECTION, "Connection settings")
connect = ConnectOptions(
url = config.getString(
"connectURL",
CATEGORY_CONNECTION,
connect.url,
"The URL or IP address of the bridge server"
),
authToken = config.getString(
"authToken",
CATEGORY_CONNECTION,
connect.authToken,
"Auth token used to connect to the bridge server"
),
gateway = config.getString(
"gateway",
CATEGORY_CONNECTION,
connect.gateway,
"MatterBridge gateway"
)
)
if (config.hasChanged()) config.save()
cfg = this
}
}

View File

@ -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 getName(): String {
return CommandCoreAuth.name
}
override fun getUsage(sender: ICommandSender): String {
return CommandCoreAuth.usage
}
override fun getAliases(): 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.getUsage(sender)}")
}
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
val reply = CommandCoreAuth.execute(args, sender.name, uuid)
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
sender.sendMessage(TextComponentString(reply))
}
}
}

View File

@ -1,53 +0,0 @@
package matterlink.command
import com.google.common.collect.Lists
import matterlink.MODID
import matterlink.bridge.MessageHandler
import matterlink.bridge.ServerChatHandler
import matterlink.instance
import matterlink.logger
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.server.MinecraftServer
class CommandMatterlink : CommandBase() {
private val aliases: List<String>
init {
aliases = Lists.newArrayList(MODID, "bridge", "BRIDGE")
}
override fun getName(): String {
return "bridge"
}
override fun getUsage(sender: ICommandSender): String {
return "bridge <connect|disconnect>"
}
override fun getAliases(): List<String> {
return aliases
}
override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<String>) /*throws CommandException*/ {
if (args.isEmpty()) {
//throw new WrongUsageException("")
return
}
//TODO: check if sender is OP or test if normal users cannot send this
val cmd = args[0].toLowerCase()
when (cmd) {
"connect" -> {
instance.connect()
}
"disconnect" -> {
instance.disconnect()
}
}
}
}

View File

@ -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 getName(): String {
return CommandCoreML.name
}
override fun getUsage(sender: ICommandSender): String {
return CommandCoreML.usage
}
override fun getAliases(): 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: ${getUsage(sender)}")
}
val uuid = (sender as? EntityPlayer)?.uniqueID?.toString()
val reply = CommandCoreML.execute(args, sender.name, uuid)
if (reply.isNotEmpty() && sender.sendCommandFeedback()) {
sender.sendMessage(TextComponentString(reply))
}
}
}

View File

@ -0,0 +1,55 @@
package matterlink.command
import kotlinx.coroutines.runBlocking
import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender
import net.minecraft.command.ICommandSender
import net.minecraft.server.MinecraftServer
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,
env: IBridgeCommand.CommandEnvironment,
op: Boolean
) : IMinecraftCommandSender(user, env, op), ICommandSender {
override fun execute(cmdString: String): Boolean = runBlocking {
0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
this@MatterLinkCommandSender,
cmdString
).apply {
sendReply(cmdString)
}
}
override fun getDisplayName(): ITextComponent {
return TextComponentString(displayName)
}
override fun getName() = accountName
override fun getEntityWorld(): World {
return FMLCommonHandler.instance().minecraftServerInstance.getWorld(0)
}
override fun canUseCommand(permLevel: Int, commandName: String): Boolean {
//permissions are checked on our end
return canExecute(commandName)
}
override fun getServer(): MinecraftServer? {
return FMLCommonHandler.instance().minecraftServerInstance
}
override fun sendMessage(@Nonnull component: ITextComponent?) {
appendReply(component!!.unformattedComponentText)
}
override fun sendCommandFeedback(): Boolean {
return true
}
}

130
1.7.10/build.gradle Normal file
View File

@ -0,0 +1,130 @@
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: '1.2-SNAPSHOT'
classpath group: 'gradle.plugin.com.matthewprenger', name: 'CurseGradle', version: cursegradleVersion
}
}
apply plugin: 'forge'
apply plugin: 'com.matthewprenger.cursegradle'
version = project.mc_version + '-' + project.modVersion
archivesBaseName = project.modName
sourceCompatibility = targetCompatibility = '1.8'
configurations {
shade
compile.extendsFrom shade
}
dependencies {
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 {
version = project.mc_version + '-' + project.forge_version + '-' + project.mc_version
runDir = 'run'
mappings = project.mcp_mappings
// srgExtra 'PK: kotlin matterlink/repack/kotlin'
// srgExtra 'PK: org/jetbrains/annotations matterlink/repack/org/jetbrains/annotations'
// srgExtra 'PK: org/intellij matterlink/repack/org/intellij'
// srgExtra 'PK: blue/endless/ matterlink/repack/blue/endless/'
}
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.modVersion, 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.forgelinVersion, 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')
}
ant.replaceregexp(match: '@BUILD_NUMBER@', replace: System.env.BUILD_NUMBER ?: -1, 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.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'
}
}
jar {
configurations.shade.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}
}
curseforge {
if (project.hasProperty('CURSEFORGE_API_TOKEN') && project.hasProperty('release')) {
apiKey = CURSEFORGE_API_TOKEN
}
project {
id = project.curseId
releaseType = project.curseReleaseType
if (project.hasProperty('changelog_file')) {
println("changelog = $changelog_file")
changelogType = 'markdown'
changelog = file(changelog_file)
}
mainArtifact(jar) {
displayName = "MatterLink $version"
}
}
}

3
1.7.10/gradle.properties Normal file
View File

@ -0,0 +1,3 @@
mc_version = 1.7.10
mcp_mappings = stable_12
forge_version = 10.13.4.1614

View File

@ -0,0 +1,148 @@
package matterlink
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.PlayerEvent
import cpw.mods.fml.common.gameevent.TickEvent
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.Entity
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
//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,
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,
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.commandSenderName
}
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
}
}
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
@SubscribeEvent
fun deathEvent(e: LivingDeathEvent) = runBlocking {
if (e.entityLiving is EntityPlayer) {
val player = e.entityLiving as EntityPlayer
DeathHandler.handleDeath(
player = player.displayName,
deathMessage = e.entityLiving.combatTracker.func_151521_b().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,
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,
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()
}
}

View File

@ -0,0 +1,148 @@
package matterlink
import com.mojang.authlib.GameProfile
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.event.FMLInitializationEvent
import cpw.mods.fml.common.event.FMLPreInitializationEvent
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.config.BaseConfig
import matterlink.config.cfg
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.server.MinecraftServer
import net.minecraft.util.ChatComponentText
import net.minecraftforge.common.ForgeVersion
import net.minecraftforge.common.MinecraftForge
import java.util.UUID
@Mod(
modid = MODID,
name = NAME, version = MODVERSION,
useMetadata = true,
acceptableRemoteVersions = "*"
)
class MatterLink : IMatterLink() {
init {
instance = this
}
@Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) {
MinecraftForge.EVENT_BUS.register(EventHandler)
FMLCommonHandler.instance().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) {
MinecraftServer.getServer().configurationManager.sendChatMsg(ChatComponentText(msg))
}
override fun wrappedSendToPlayer(username: String, msg: String) {
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 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 modVersion: String = MODVERSION
override val buildNumber = BUILD_NUMBER
override val forgeVersion = ForgeVersion.getVersion()
}

View File

@ -0,0 +1,35 @@
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.util.ChatComponentText
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>) {
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.commandSenderName, uuid)
if (reply.isNotEmpty()) {
sender.addChatMessage(ChatComponentText(reply))
}
}
}

View File

@ -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))
}
}
}

View File

@ -0,0 +1,48 @@
package matterlink.command
import kotlinx.coroutines.runBlocking
import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender
import net.minecraft.command.ICommandSender
import net.minecraft.server.MinecraftServer
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChunkCoordinates
import net.minecraft.util.IChatComponent
import net.minecraft.world.World
class MatterLinkCommandSender(
user: String,
env: IBridgeCommand.CommandEnvironment,
op: Boolean
) : IMinecraftCommandSender(user, env, op), ICommandSender {
override fun execute(cmdString: String): Boolean = runBlocking {
return@runBlocking 0 < MinecraftServer.getServer().commandManager.executeCommand(
this@MatterLinkCommandSender,
cmdString
).apply {
sendReply(cmdString)
}
}
override fun getFormattedCommandSenderName(): IChatComponent {
return ChatComponentText(displayName)
}
override fun getCommandSenderName() = accountName
override fun getEntityWorld(): World {
return MinecraftServer.getServer().worldServerForDimension(0)
}
override fun canCommandSenderUseCommand(permLevel: Int, commandName: String): Boolean {
//we do permission
return canExecute(commandName)
}
override fun addChatMessage(component: IChatComponent) {
appendReply(component.unformattedText)
}
override fun getCommandSenderPosition(): ChunkCoordinates = ChunkCoordinates(0, 0, 0)
}

View File

@ -0,0 +1,7 @@
package matterlink
const val MODID = "matterlink"
const val NAME = "MatterLink"
const val MODVERSION = "@MODVERSION@"
const val MCVERSION = "@MCVERSION@"
const val BUILD_NUMBER = @BUILD_NUMBER@

135
1.9.4/build.gradle Normal file
View File

@ -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"
}
}
}

3
1.9.4/gradle.properties Normal file
View File

@ -0,0 +1,3 @@
mc_version = 1.9.4
mcp_mappings = stable_26
forge_version = 12.17.0.2051

View File

@ -0,0 +1,8 @@
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@,);"
const val BUILD_NUMBER = -1//@BUILD_NUMBER@

View File

@ -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()
}
}

View File

@ -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()
}

View File

@ -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))
}
}
}

View File

@ -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))
}
}
}

View File

@ -0,0 +1,66 @@
package matterlink.command
import kotlinx.coroutines.runBlocking
import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender
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,
env: IBridgeCommand.CommandEnvironment,
op: Boolean
) : IMinecraftCommandSender(user, env, op), ICommandSender {
override fun execute(cmdString: String): Boolean = runBlocking {
return@runBlocking 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
this@MatterLinkCommandSender,
cmdString
).apply {
sendReply(cmdString)
}
}
override fun getDisplayName(): ITextComponent {
return TextComponentString(displayName)
}
override fun getName() = accountName
override fun getEntityWorld(): World {
return FMLCommonHandler.instance().minecraftServerInstance.worldServerForDimension(0)
}
override fun canCommandSenderUseCommand(permLevel: Int, commandName: String): Boolean {
//we check user on our end
return canExecute(commandName)
}
override fun getServer(): MinecraftServer? {
return FMLCommonHandler.instance().minecraftServerInstance
}
override fun addChatMessage(@Nonnull component: ITextComponent?) {
appendReply(component!!.unformattedComponentText)
}
override fun sendCommandFeedback(): Boolean {
return true
}
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
Jankson Submodule

@ -0,0 +1 @@
Subproject commit 7d27c28784bacba17450faa9e723ca6b6eb39602

27
Jenkinsfile vendored
View File

@ -1,20 +1,25 @@
pipeline { pipeline {
agent any agent any
stages { stages {
stage("1.10.2") { stage("init") {
steps { steps {
sh './gradlew :1.10.2:setupCiWorkspace' sh 'git submodule update --init --recursive'
sh './gradlew :1.10.2:clean'
sh './gradlew :1.10.2:build'
archive '1.10.2/build/libs/*jar'
} }
} }
stage("1.11.2") { stage("1.7.10") {
steps { steps {
sh './gradlew :1.11.2:setupCiWorkspace' sh './gradlew :1.7.10:setupCiWorkspace'
sh './gradlew :1.11.2:clean' sh './gradlew :1.7.10:clean'
sh './gradlew :1.11.2:build' sh './gradlew :1.7.10:build'
archive '1.11.2/build/libs/*jar' archiveArtifacts artifacts: '1.7.10/build/libs/*jar'
}
}
stage("1.9.4") {
steps {
sh './gradlew :1.9.4:setupCiWorkspace'
sh './gradlew :1.9.4:clean'
sh './gradlew :1.9.4:build'
archiveArtifacts artifacts: '1.9.4/build/libs/*jar'
} }
} }
stage("1.12.2") { stage("1.12.2") {
@ -22,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'
} }
} }
} }

695
LICENSE
View File

@ -1,674 +1,21 @@
GNU GENERAL PUBLIC LICENSE MIT License
Version 3, 29 June 2007
Copyright (c) 2018 NikkyAi & Arcan
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies Permission is hereby granted, free of charge, to any person obtaining a copy
of this license document, but changing it is not allowed. of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Preamble to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
The GNU General Public License is a free, copyleft license for furnished to do so, subject to the following conditions:
software and other kinds of works.
The above copyright notice and this permission notice shall be included in all
The licenses for most software and other practical works are designed copies or substantial portions of the Software.
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
share and change all versions of a program--to make sure it remains free IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
software for all its users. We, the Free Software Foundation, use the FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
GNU General Public License for most of our software; it applies also to AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
any other work released this way by its authors. You can apply it to LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
your programs, too. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

173
README.md
View File

@ -1,32 +1,175 @@
[![Discord](https://img.shields.io/discord/176780432371744769.svg?style=for-the-badge&label=%23ai-dev&logo=discord)](http://discord.gg/Fm5EST)
[![Discord](https://img.shields.io/discord/342696338556977153.svg?style=for-the-badge&logo=discord)](https://discord.gg/hXqNgq5)
[![Download 1.12.2](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.12.2)](https://curse.nikky.moe/api/url/287323?version=1.12.2)
[![Jenkins](https://img.shields.io/jenkins/s/https/ci.elytradev.com/job/elytra/job/MatterLink/job/master.svg?style=for-the-badge&label=Jenkins%20Build)](https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/lastSuccessfulBuild/artifact/)
[![Patreon](https://img.shields.io/badge/Patreon-Nikkyai-red.svg?style=for-the-badge)](https://www.patreon.com/NikkyAi)
# MatterLink # MatterLink
matterbridge 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
https://github.com/42wim/matterbridge https://github.com/42wim/matterbridge
requires api section to be setup along these lines Chat with us on IRC: [#matterlink @ irc.esper.net](irc://irc.esper.net/matterlink)
## Downloads
[![Github All Releases](https://img.shields.io/github/downloads/elytra/MatterLink/total.svg?style=for-the-badge&label=Github%20Releases&logo=github)](https://github.com/elytra/MatterLink/releases)
[![Jenkins](https://img.shields.io/jenkins/s/https/ci.elytradev.com/job/elytra/job/MatterLink/job/master.svg?style=for-the-badge&label=Jenkins%20Build)](https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/lastSuccessfulBuild/artifact/)
[![Files](https://curse.nikky.moe/api/img/287323/files?logo&style=for-the-badge&version=1.12.2)](https://minecraft.curseforge.com/projects/287323/files)
[![Download 1.12.2](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.12.2)](https://curse.nikky.moe/api/url/287323?version=1.12.2)
[![Download 1.9.4](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.9.4)](https://curse.nikky.moe/api/url/287323?version=1.9.4)
## Dependencies
[![Forgelin Files](https://curse.nikky.moe/api/img/248453/files?logo&style=for-the-badge)](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:
### 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:4343" # or listen only to localhost BindAddress="0.0.0.0:4242"
#Bearer token used for authentication
#curl -H "Authorization: Bearer testtoken" http://localhost:4343/api/messages
#OPTIONAL (no authorization if token is empty) #OPTIONAL (no authorization if token is empty)
Token="testtoken" Token="mytoken"
Buffer=1000 Buffer=1000
RemoteNickFormat="{NICK}" RemoteNickFormat="{NICK}"
ShowJoinPart = true ShowJoinPart = true
``` ```
values you need to remember are obviously the IP, port and token you need to know the ip / domain of the matterbridge and the token used,
MatterLInk will need them in the configuration enter them in the ´connection' section in the config and reload matterlink
## Downloads
https://ci.elytradev.com/job/elytra/job/MatterLink/job/master/ ### Sample
Install matterbridge and try out the basic sample:
```
go get github.com/42wim/matterbridge
mv matterbridge-sample.toml matterbridge.toml
matterbridge
```
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
### Building
```bash
git clone --recursive https://git.lain.faith/sorceress/MatterLink.git
cd MatterLink/
./gradlew setupDecompWorkspace
./gradlew build
```

14
TODO.MD Normal file
View File

@ -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`

View File

@ -1,31 +1,73 @@
plugins { buildscript {
id "org.jetbrains.kotlin.jvm" version '1.2.21' repositories {
id 'idea' jcenter()
}
dependencies {
classpath group: "org.jetbrains.kotlin", name: "kotlin-gradle-plugin", version: kotlinVersion
classpath group: "org.jetbrains.kotlin", name: "kotlin-serialization", version: kotlinVersion
}
} }
plugins {
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) {
modVersion += "-${System.env.BUILD_NUMBER}"
} else if (!project.hasProperty('release')) {
// modVersion += "-dev"
modVersion += "-dev"
}
idea { idea {
module { module {
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"
}
} }
} }

View File

@ -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"
}

View File

@ -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 'org.apache.httpcomponents:httpclient:4.3.3' compile project(":Jankson")
compile 'commons-logging:commons-logging:1.1.3' shadow(project(':Jankson')) { transitive = false }
// compile group: "org.apache.logging.log4j", name: "log4j-api", version: '2.8.1'
compile 'com.google.code.gson:gson:2.8.0' compile group: 'com.google.guava', name: 'guava', version: '+'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_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

View File

@ -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()
}

View File

@ -1,31 +1,80 @@
package matterlink package matterlink
import matterlink.bridge.MessageHandler import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender
import matterlink.config.cfg
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 {
// var interrupted: Boolean = false abstract val mcVersion: String
abstract val modVersion: String
abstract val buildNumber: Int
abstract val forgeVersion: String
abstract fun commandSenderFor(
user: String,
env: IBridgeCommand.CommandEnvironment,
op: Boolean
): IMinecraftCommandSender
abstract fun wrappedSendToPlayers(msg: String) abstract fun wrappedSendToPlayers(msg: String)
abstract fun wrappedPlayerList(): Array<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 connect() { suspend fun start() {
MessageHandler.start(clear = true) MessageHandlerInst.logger = logger
serverStartTime = System.currentTimeMillis()
if (cfg.connect.autoConnect)
MessageHandlerInst.start("Server started, connecting to matterbridge API", true)
UpdateChecker.check()
} }
fun disconnect() { suspend fun stop() {
MessageHandler.stop() MessageHandlerInst.stop("Server shutting down, disconnecting from matterbridge API")
} }
abstract fun log(level: String, formatString: String, vararg data: Any) /**
* in milliseconds
*/
var serverStartTime: Long = System.currentTimeMillis()
fun fatal(formatString: String, vararg data: Any) = log(Level.FATAL.name, formatString, *data) fun getUptimeAsString(): String {
fun error(formatString: String, vararg data: Any) = log(Level.ERROR.name, formatString, *data) val total = (System.currentTimeMillis() - serverStartTime) / 1000
fun warn(formatString: String, vararg data: Any) = log(Level.WARN.name, formatString, *data) val s = total % 60
fun info(formatString: String, vararg data: Any) = log(Level.INFO.name, formatString, *data) val m = (total / 60) % 60
fun debug(formatString: String, vararg data: Any) = log(Level.DEBUG.name, formatString, *data) val h = (total / 3600) % 24
fun trace(formatString: String, vararg data: Any) = log(Level.TRACE.name, formatString, *data) val d = total / 86400
fun timeFormat(unit: Long, name: String) = when {
unit > 1L -> "$unit ${name}s "
unit == 1L -> "$unit $name "
else -> ""
}
var result = ""
result += timeFormat(d, "Day")
result += timeFormat(h, "Hour")
result += timeFormat(m, "Minute")
result += timeFormat(s, "Second")
return result
}
fun registerBridgeCommands() {
BridgeCommandRegistry.reloadCommands()
}
abstract fun collectPlayers(area: Area): Set<UUID>
} }

View File

@ -1,38 +0,0 @@
package matterlink
enum class Level(val level: Int) {
/**
* No events will be logged.
*/
OFF(0),
/**
* A severe error that will prevent the application from continuing.
*/
FATAL(1),
/**
* An error in the application, possibly recoverable.
*/
ERROR(2),
/**
* An event that might possible lead to an error.
*/
WARN(3),
/**
* An event for informational purposes.
*/
INFO(4),
/**
* A general debugging event.
*/
DEBUG(5),
/**
* A fine-grained debug message, typically capturing the flow through the application.
*/
TRACE(6),
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -1,12 +1,23 @@
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.StringWriter
import java.util.*
private const val ZWSP: Char = '\u200b' private const val ZWSP: Char = '\u200b'
//Inserts a zero-width space at index 1 in the string' //Inserts a zero-width space at index 1 in the string'
fun String.antiping(): String { val String.antiping: String
get() {
return this[0].toString() + ZWSP + this.substring(1) return this[0].toString() + ZWSP + this.substring(1)
} }
fun String.mapFormat(env: Map<String, String>): String { fun String.mapFormat(env: Map<String, String>): String {
var result = this var result = this
@ -17,3 +28,122 @@ fun String.mapFormat(env: Map<String, String>): String {
} }
return result return result
} }
fun String.lazyFormat(env: Map<String, () -> String?>): String {
var result = this
env.forEach { key, value ->
if (result.contains(key)) {
result = result.replace(key, value().toString())
}
}
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
get() {
val sw = StringWriter()
this.printStackTrace(PrintWriter(sw))
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
}

View File

@ -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)
}
}
}

View File

@ -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"
)

View File

@ -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
}
}
}

View File

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

View File

@ -1,89 +0,0 @@
package matterlink.bridge;
import matterlink.instance
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClients
import java.io.InputStream
import java.net.SocketException
val BUFFER_SIZE = 1000
class HttpStreamConnection(getClosure: () -> HttpGet,
clearClosure: () -> HttpGet,
private val mhandler: (String) -> Unit,
private val onClose: () -> Unit,
private val setSuccess: (Boolean) -> Unit,
private val clear: Boolean = true
) : Thread() {
private val client = HttpClients.createDefault()
private var stream: InputStream? = null
val get = getClosure()
private val clearGet = clearClosure()
var cancelled: Boolean = false
private set
override fun run() {
if (clear) {
val r = client.execute(clearGet)
r.entity.content.bufferedReader().forEachLine {
instance.debug("skipping $it")
}
}
try {
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()
return
} else {
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.debug(buffer)
while (buffer.contains("\n")) {
val line = buffer.substringBefore("\n")
buffer = buffer.substringAfter("\n")
mhandler(line)
}
} else if (chars < 0) {
break
}
}
instance.debug("closing stream")
content.close()
} catch (e: SocketException) {
instance.info("error {}", e)
if (!cancelled) {
instance.error("Bridge Connection interrupted...")
setSuccess(false)
}
} finally {
instance.debug("thread finished")
onClose()
}
return
}
fun close() {
cancelled = true
get.abort()
join()
}
}

View File

@ -1,153 +0,0 @@
package matterlink.bridge
import matterlink.config.cfg
import matterlink.instance
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpPost
import org.apache.http.client.methods.HttpRequestBase
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.net.SocketException
import java.util.concurrent.ConcurrentLinkedQueue
object MessageHandler {
var connected = false
private var connecting = false
private var enabled = true
private var connectErrors = 0
private var sendErrors = 0
private var streamConnection: HttpStreamConnection
var rcvQueue = ConcurrentLinkedQueue<ApiMessage>()
init {
streamConnection = createThread()
streamConnection.start()
connected = true
}
private fun HttpRequestBase.authorize() {
if (cfg!!.connect.authToken.isNotEmpty() && getHeaders("Authorization").isEmpty())
setHeader("Authorization", "Bearer " + cfg!!.connect.authToken)
}
private fun createThread(clear: Boolean = true): HttpStreamConnection {
instance.info("Attempting to open bridge connection.")
return HttpStreamConnection(
{
HttpGet(cfg!!.connect.url + "/api/stream").apply {
authorize()
}
},
{
HttpGet(cfg!!.connect.url + "/api/messages").apply {
authorize()
}
},
{
rcvQueue.add(
ApiMessage.decode(it)
)
instance.debug("Received: " + it)
},
{
instance.warn("Bridge connection closed!")
connected = false
connecting = false
},
{ success ->
connecting = false
if (success) {
instance.info("connected successfully")
connectErrors = 0
connected = true
} else {
connectErrors++
connected = false
}
},
clear
)
}
fun transmit(msg: ApiMessage) {
if (connected && streamConnection.isAlive) {
instance.debug("Transmitting: " + msg)
transmitMessage(msg)
}
}
fun stop() {
enabled = false
instance.info("Closing bridge connection...")
// MessageHandler.transmit(ApiMessage(text="bridge closing", username="Server"))
try {
streamConnection.close()
} catch (e: SocketException) {
instance.error("exception: $e")
}
}
fun start(clear: Boolean = true) {
enabled = true
if (!connected)
streamConnection = createThread(clear)
if (!streamConnection.isAlive) {
connecting = true
streamConnection.start()
// MessageHandler.transmit(ApiMessage(text="bridge connected", username="Server"))
}
if (streamConnection.isAlive) {
instance.info("Bridge Connection opened")
}
}
private fun transmitMessage(message: ApiMessage) {
try {
//open a connection
val client = HttpClients.createDefault()
val post = HttpPost(cfg!!.connect.url + "/api/message")
post.entity = StringEntity(message.encode(), 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()
}
}
sendErrors = 0
} catch (e: IOException) {
instance.error("sending message caused $e")
sendErrors++
if (sendErrors > 5) {
instance.error("caught too many errors, closing bridge")
stop()
}
}
}
fun checkConnection(tick: Int) {
if (enabled && tick % 20 == 0 && !MessageHandler.connected && !connecting) {
if (connectErrors > 5) {
instance.fatal("caught too many errors, closing bridge")
stop()
return
}
instance.info("Trying to reconnect")
MessageHandler.start(clear = false)
}
}
}

View File

@ -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
)
)
}

View File

@ -1,43 +0,0 @@
package matterlink.bridge
import matterlink.instance
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.config.cfg
object ServerChatHandler {
/**
* This method must be called every server tick with no arguments.
*/
fun writeIncomingToChat(tick: Int) {
MessageHandler.checkConnection(tick)
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!!.formatting.action)
"" -> {
if (BridgeCommandRegistry.handleCommand(nextMessage.text)) return
nextMessage.format(cfg!!.formatting.chat)
}
"join_leave" -> nextMessage.format(cfg!!.formatting.joinLeave)
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)
}
}
}
}

View File

@ -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
}
}

View File

@ -1,37 +1,95 @@
package matterlink.bridge.command package matterlink.bridge.command
import matterlink.api.ApiMessage
import matterlink.config.CommandConfig
import matterlink.config.IdentitiesConfig
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> = HashMap() private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
fun handleCommand(input: String): Boolean { /**
if (!cfg!!.command.enable) return false *
if (input[0] != cfg!!.command.prefix[0] || input.length < 2) return false * @return consume message flag
*/
suspend fun handleCommand(input: ApiMessage): Boolean {
if (!cfg.command.enable || input.text.isBlank()) return false
val cmd = input.substring(1).split(' ', ignoreCase = false, limit = 2) if (input.text[0] != cfg.command.prefix || input.text.length < 2) return false
val args = if (cmd.size == 2)
cmd[1]
else
""
return if (commandMap.containsKey(cmd[0])) (commandMap[cmd[0]]!!.call(args)) else false val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
} val args = if (cmd.size == 2) cmd[1] else ""
fun register(cmd: IBridgeCommand): Boolean { val uuid = IdentitiesConfig.getUUID(input.account, input.userid)
if (cmd.name.isBlank() || commandMap.containsKey(cmd.name)) {
instance.info("Failed to register command: '${cmd.name}'") 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 return false
} }
commandMap[cmd.name] = cmd it.preExecute() // resets the tickCounter
return true 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
} }
fun registerAll(vararg commands: IBridgeCommand) { suspend fun handleCommand(text: String, username: String, uuid: UUID): Boolean {
commands.forEach { register(it) } 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 {
if (alias.isBlank() || commandMap.containsKey(alias)) {
logger.error("Failed to register command: '$alias'")
return false
}
if (!cmd.validate()) {
logger.error("Failed to validate command: '$alias'")
return false
}
//TODO: maybe write alias to command here ?
// could avoid searching for the command in the registry
commandMap[alias] = cmd
return true
} }
fun getHelpString(cmd: String): String { fun getHelpString(cmd: String): String {
@ -42,6 +100,38 @@ object BridgeCommandRegistry {
return if (help.isNotBlank()) help else "No help for '$cmd'" return if (help.isNotBlank()) help else "No help for '$cmd'"
} }
val commandList: String fun getCommandList(permLvl: Double): String {
get() = commandMap.keys.joinToString(separator = ", ") return commandMap
.filterValues {
it.permLevel <= permLvl
}
.keys
.joinToString(" ")
}
fun reloadCommands() {
commandMap.clear()
register("help", HelpCommand)
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) ->
register(alias, command)
}
}
operator fun get(command: String) = commandMap[command]
fun getName(command: IBridgeCommand): String? {
commandMap.forEach { (alias, cmd) ->
if (command == cmd) return alias
}
return null
}
} }

View File

@ -0,0 +1,99 @@
package matterlink.bridge.command
import matterlink.instance
import matterlink.lazyFormat
import matterlink.logger
import matterlink.stripColorIn
data class CustomCommand(
val type: CommandType = CommandType.RESPONSE,
val execute: String? = null,
val response: String? = null,
override val permLevel: Double = 0.0,
override val help: String = "",
override val timeout: Int = 20,
val defaultCommand: Boolean? = null,
val execOp: Boolean? = null,
val argumentsRegex: Regex? = null
) : IBridgeCommand() {
override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
if (argumentsRegex != null) {
logger.debug("testing '$args' against '${argumentsRegex.pattern}'")
if (!argumentsRegex.matches(args)) {
env.respond("$user sent invalid input to command $alias")
return false
}
}
return when (type) {
CommandType.EXECUTE -> {
// uses a new commandsender for each use
val commandSender = instance.commandSenderFor(user, env, execOp ?: false)
val cmd = execute?.lazyFormat(getReplacements(user, env, args))?.stripColorIn
?: return false
commandSender.execute(cmd) || commandSender.reply.isNotEmpty()
}
CommandType.RESPONSE -> {
env.respond(
response?.lazyFormat(getReplacements(user, env, args))
?: "", cause = "response to command: $alias"
)
true
}
}
}
/**
*
*/
override fun validate(): Boolean {
val typeCheck = when (type) {
CommandType.EXECUTE -> execute?.isNotBlank() ?: false
CommandType.RESPONSE -> response?.isNotBlank() ?: false
}
if (!typeCheck) return false
return true
}
companion object {
val DEFAULT = CustomCommand()
fun getReplacements(user: String, env: CommandEnvironment, args: String): Map<String, () -> String?> = mapOf(
"{uptime}" to instance::getUptimeAsString,
"{user}" to { user },
"{userid}" to {
when (env) {
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 }
)
}
}
enum class CommandType {
EXECUTE, RESPONSE
}

View File

@ -1,23 +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 name: String = "help"
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 fun call(args: String): Boolean { override val permLevel: Double
val msg: String = if (args.isEmpty()) { get() = cfg.command.defaultPermUnauthenticated
"Available commands: ${ BridgeCommandRegistry.commandList}"
} else { override suspend fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
args.split(" ", ignoreCase = false) val msg: String = when {
.joinToString(separator = "\n") { "$it: ${ BridgeCommandRegistry.getHelpString(it) }" } args.isEmpty() ->
"Available commands: ${BridgeCommandRegistry.getCommandList(IBridgeCommand.getPermLevel(env.uuid))}"
else -> args.split(" ", ignoreCase = false)
.joinToString(separator = "\n") {
"$it: ${BridgeCommandRegistry.getHelpString(it)}"
} }
MessageHandler.transmit(ApiMessage( }
username = cfg!!.relay.systemUser, env.respond(
text = msg text = msg,
)) cause = "Help Requested $args"
)
return true return true
} }

View File

@ -1,7 +1,92 @@
package matterlink.bridge.command package matterlink.bridge.command
interface IBridgeCommand { import matterlink.api.ApiMessage
val name: String import matterlink.bridge.MessageHandlerInst
fun call(args: String): Boolean import matterlink.config.PermissionConfig
val help: String import matterlink.config.cfg
import matterlink.handlers.TickHandler
import matterlink.instance
import matterlink.logger
import matterlink.stripColorOut
import java.util.UUID
abstract class IBridgeCommand {
abstract val help: String
abstract val permLevel: Double
open val timeout: Int = 20
sealed class CommandEnvironment {
abstract val uuid: UUID?
abstract val username: String?
data class BridgeEnv(
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) }
}
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 {
fun getPermLevel(uuid: UUID?): Double {
if (uuid == null) return cfg.command.defaultPermUnauthenticated
return PermissionConfig.perms[uuid.toString()] ?: cfg.command.defaultPermAuthenticated
}
}
} }

View File

@ -0,0 +1,45 @@
package matterlink.bridge.command
abstract class IMinecraftCommandSender(val user: String, val env: IBridgeCommand.CommandEnvironment, val op: Boolean) {
/**
* @param cmdString The command to execute with its arguments
*
* @return True for success, or false for failure
*/
abstract fun execute(cmdString: String): Boolean
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 {
if (op) return true
val command = BridgeCommandRegistry[commandName] ?: return false
return command.canExecute(env.uuid)
}
private var finished = true
val reply = mutableListOf<String>()
/**
* accumulates response
*/
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
}
}

View File

@ -1,26 +0,0 @@
package matterlink.bridge.command
import matterlink.instance
import matterlink.antiping
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.config.cfg
object PlayerListCommand : IBridgeCommand {
override val name: String = "players"
override val help: String = "Lists online players."
override fun call(args: String): Boolean {
if (args.isNotBlank()) return false
val playerList = instance.wrappedPlayerList()
MessageHandler.transmit(ApiMessage(
username = cfg!!.relay.systemUser,
text = when {
playerList.isNotEmpty() -> "players: " + playerList.joinToString(" ") { it.antiping() }
else -> "No Players online"
}
))
return true
}
}

View File

@ -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
}
}

View File

@ -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"
}
}
}
}

View File

@ -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}"
}
}
}
}

View File

@ -0,0 +1,714 @@
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.FileNotFoundException
lateinit var cfg: BaseConfig.MatterLinkConfig
lateinit var baseCfg: BaseConfig
data class BaseConfig(val rootDir: File) {
val cfgDirectory: File = rootDir.resolve("matterlink")
val configFile: File = cfgDirectory.resolve("matterlink.hjson")
init {
logger.info("Reading bridge blueprints... from $rootDir")
baseCfg = this
}
data class MatterLinkConfig(
val connect: ConnectOptions = ConnectOptions(),
val outgoingDefaults: DefaultSettingsOutgoing = DefaultSettingsOutgoing(),
val incomingDefaults: DefaultSettingsIncoming = DefaultSettingsIncoming(),
val locations: List<Location> = listOf(
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(
val prefix: Char = '!',
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(
val url: String = "http://localhost:4242",
val authToken: String = "",
val autoConnect: Boolean = true,
val reconnectWait: Long = 500
)
data class IncomingOptions(
val chat: String = "<{username}> {text}",
val joinPart: String = "§6-- {username} {text}",
val action: String = "§5* {username} {text}",
val stripColors: Boolean = true
)
data class OutgoingOptions(
val systemUser: String = "Server",
//outgoing toggles
val announceConnect: Boolean = true,
val announceDisconnect: Boolean = true,
val advancements: Boolean = true,
val stripColors: Boolean = true,
val pasteEEKey: String = "",
val inlineLimit: Int = 5,
val joinPart: JoinPartOptions = JoinPartOptions(),
var avatar: AvatarOptions = AvatarOptions(),
val death: DeathOptions = DeathOptions()
)
data class DeathOptions(
val enable: Boolean = true,
val damageType: Boolean = true,
val damageTypeMapping: Map<String, Array<String>> = mapOf(
"inFire" to arrayOf("\uD83D\uDD25"), //🔥
"lightningBolt" to arrayOf("\uD83C\uDF29"), //🌩
"onFire" to arrayOf("\uD83D\uDD25"), //🔥
"lava" to arrayOf("\uD83D\uDD25"), //🔥
"hotFloor" to arrayOf("♨️"),
"inWall" to arrayOf(),
"cramming" to arrayOf(),
"drown" to arrayOf("\uD83C\uDF0A"), //🌊
"starve" to arrayOf("\uD83D\uDC80"), //💀
"cactus" to arrayOf("\uD83C\uDF35"), //🌵
"fall" to arrayOf("\u2BEF"), //⯯️
"flyIntoWall" to arrayOf("\uD83D\uDCA8"), //💨
"outOfWorld" to arrayOf("\u2734"), //✴
"generic" to arrayOf("\uD83D\uDC7B"), //👻
"magic" to arrayOf("", ""),
"indirectMagic" to arrayOf("", ""),
"wither" to arrayOf("\uD83D\uDD71"), //🕱
"anvil" to arrayOf(),
"fallingBlock" to arrayOf(),
"dragonBreath" to arrayOf("\uD83D\uDC32"), //🐲
"fireworks" to arrayOf("\uD83C\uDF86"), //🎆
"mob" to arrayOf("\uD83D\uDC80"), //💀
"player" to arrayOf("\uD83D\uDDE1"), //🗡
"arrow" to arrayOf("\uD83C\uDFF9"), //🏹
"thrown" to arrayOf("彡°"),
"thorns" to arrayOf("\uD83C\uDF39"), //🌹
"explosion" to arrayOf("\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(
val enable: Boolean = true,
val joinServer: String = "{username:antiping} has connected to the server",
val partServer: String = "{username:antiping} has disconnected from the server"
)
data class UpdateOptions(
val enable: Boolean = true
)
companion object {
val jankson = Jankson
.builder()
.registerTypeAdapter {
with(MatterLinkConfig()) {
MatterLinkConfig(
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"
)
)
}
}
.registerTypeAdapter {
with(DefaultSettingsIncoming()) {
DefaultSettingsIncoming(
plain = it.getOrDefault(
"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,
"Enable MC bridge commands"
),
prefix = it.getOrDefault(
"prefix",
prefix,
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)"
),
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,
"Auth token used to connect to the bridge platform"
),
autoConnect = it.getOrDefault(
"autoConnect",
autoConnect,
"Connect the relay on startup"
),
reconnectWait = it.getOrDefault(
"reconnectWait",
reconnectWait,
"base delay in milliseconds between attempting reconnects"
)
)
}
}
.registerTypeAdapter {
with(IncomingOptions()) {
IncomingOptions(
chat = it.getOrDefault(
"chat",
chat,
"Generic chat event, just talking"
),
joinPart = it.getOrDefault(
"joinPart",
joinPart,
"Join and part events from other gateways"
),
action = it.getOrDefault(
"action",
action,
"User actions (/me) sent by users from other gateways"
),
stripColors = it.getOrDefault(
"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,
"Relay player achievements / advancements"
),
announceConnect = it.getOrDefault(
"announceConnect",
announceConnect,
"announce successful connection to the gateway"
),
announceDisconnect = it.getOrDefault(
"announceDisconnect",
announceConnect,
"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"
)
)
}
}
.registerTypeAdapter { jsonObj ->
with(DeathOptions()) {
DeathOptions(
enable = jsonObj.getOrDefault(
"enable",
enable,
"Relay player death messages"
),
damageType = jsonObj.getOrDefault(
"damageType",
damageType,
"Enable Damage type symbols on death messages"
),
damageTypeMapping = (jsonObj.getObject("damageTypeMapping")
?: Marshaller.getFallback().serialize(damageTypeMapping) as JsonObject)
.let {
jsonObj.setComment(
"damageTypMapping",
"Damage type mapping for death cause"
)
it.mapValues { (key, _) ->
it.getOrDefault(key, damageTypeMapping[key] ?: emptyArray(), key)
.apply { it[key] }.apply {
jsonObj["damageTypeMapping"] = it
}
}
}
)
}
}
.registerTypeAdapter {
with(AvatarOptions()) {
AvatarOptions(
enable = it.getOrDefault(
"enable",
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" +
"\nany receiving end still needs to be configured with showJoinPart = true" +
"\nto display the messages"
),
joinServer = it.getOrDefault(
"joinServer",
joinServer,
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
),
partServer = it.getOrDefault(
"partServer",
partServer,
"user part message sent to other gateways, available variables: {username}, {username:antiping}"
)
)
}
}
.registerTypeAdapter {
with(UpdateOptions()) {
UpdateOptions(
enable = it.getOrDefault(
"enable",
enable,
"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()!!
}
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
}
}

View File

@ -0,0 +1,154 @@
package matterlink.config
import blue.endless.jankson.Jankson
import blue.endless.jankson.JsonObject
import blue.endless.jankson.JsonPrimitive
import blue.endless.jankson.impl.SyntaxError
import matterlink.bridge.command.CommandType
import matterlink.bridge.command.CustomCommand
import matterlink.getOrDefault
import matterlink.logger
import matterlink.registerPrimitiveTypeAdapter
import matterlink.registerTypeAdapter
import java.io.File
import java.io.FileNotFoundException
typealias CommandMap = MutableMap<String, CustomCommand>
typealias DefaultCommands = Map<String, Pair<String, CustomCommand>>
object CommandConfig {
private val configFile: File = baseCfg.cfgDirectory.resolve("commands.hjson")
private val default: DefaultCommands = mapOf(
"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,
execute = "forge tps",
help = "Print platform tps",
timeout = 200,
defaultCommand = true
)),
"list" to ("lists all the players, this is just a straight pass-through"
to CustomCommand(
type = CommandType.EXECUTE,
execute = "list",
help = "List online players",
defaultCommand = true
)),
"seed" to ("another straight pass-through"
to CustomCommand(
type = CommandType.EXECUTE,
execute = "seed",
help = "Print platform world seed",
defaultCommand = true
)),
"uptime" to ("this is a reponse command, it uses the uptime function, time since the mod was first loaded"
to CustomCommand(
type = CommandType.RESPONSE,
response = "{uptime}",
help = "Print platform uptime",
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
))
)
val commands: CommandMap = hashMapOf()
fun loadFile() {
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()
JsonObject()
}
// 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")
}
}
//apply defaults
default.forEach { k, (comment, defCommand) ->
val command = commands[k]
if (command == null || command.defaultCommand == true) {
commands[k] = defCommand
jsonObject.getOrDefault(k, defCommand, comment)
}
}
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))
}
}

View File

@ -1,46 +0,0 @@
package matterlink.config
var cfg: IMatterLinkConfig? = null
abstract class IMatterLinkConfig {
protected val CATEGORY_RELAY_OPTIONS = "relay"
protected val CATEGORY_FORMATTING_INCOMING = "formatting"
protected val CATEGORY_FORMATTING_JOIN_LEAVE = "formatting_join_leave"
protected val CATEGORY_CONNECTION = "connection"
protected val CATEGORY_COMMAND = "command"
var relay: RelayOptions = RelayOptions()
var connect: ConnectOptions = ConnectOptions()
var formatting: FormattingOptions = FormattingOptions()
var formattingJoinLeave: FormattingJoinLeave = FormattingJoinLeave()
var command: CommandOptions = CommandOptions()
data class RelayOptions(
val systemUser: String = "Server",
val deathEvents: Boolean = true,
val advancements: Boolean = true,
val joinLeave: Boolean = true
)
data class FormattingOptions(
val chat: String = "<{username}> {text}",
val joinLeave: String = "§6-- {username} {text}",
val action: String = "§5* {username} {text}"
)
data class FormattingJoinLeave(
val joinServer: String = "{username:antiping} has connected to the server",
val leaveServer: String = "{username:antiping} has disconnected from the server"
)
data class ConnectOptions(
val url: String = "http://localhost:4242",
val authToken: String = "",
val gateway: String = "minecraft"
)
data class CommandOptions(
val prefix: String = "$",
val enable: Boolean = true
)
}

View File

@ -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
}
}
}
}

View File

@ -0,0 +1,85 @@
package matterlink.config
import blue.endless.jankson.Jankson
import blue.endless.jankson.JsonObject
import blue.endless.jankson.impl.SyntaxError
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import matterlink.getReified
import matterlink.logger
import java.io.File
import java.io.FileNotFoundException
import java.util.UUID
import java.util.concurrent.TimeUnit
typealias PermissionMap = Map<String, Double>
data class PermissionRequest(
val uuid: UUID,
val user: String,
val nonce: String,
val powerlevel: Double? = null
)
object PermissionConfig {
val permissionRequests: Cache<String, PermissionRequest> = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.build()
private val jankson = Jankson
.builder()
.build()
private val configFile: File = baseCfg.cfgDirectory.resolve("permissions.hjson")
private val default = mapOf(
"edd31c45-b095-49c5-a9f5-59cec4cfed8c" to 9000.0 to "Superuser"
)
val perms: PermissionMap = mutableMapOf()
private var jsonObject: JsonObject = JsonObject()
fun loadFile() {
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()
defaultJsonObject
}
load(save)
}
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()
}
}

View File

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

View File

@ -0,0 +1,40 @@
package matterlink.handlers
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.logger
import java.util.UUID
object ChatProcessor {
/**
* @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()
if (uuid != null && BridgeCommandRegistry.handleCommand(message, user, uuid)) return true
when {
message.isNotBlank() -> LocationHandler.sendToLocations(
user = user,
msg = message,
x = x, y = y, z = z, dimension = dimension,
event = event,
cause = "Message from $user",
uuid = uuid
)
else -> logger.warn("WARN: dropped blank message by '$user'")
}
return false
}
}

View File

@ -1,14 +0,0 @@
package matterlink.handlers
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
object CommandHandler {
fun handleCommand(sender: String, args: String, type: String) {
MessageHandler.transmit(ApiMessage(
username = sender,
text = args,
event = type
))
}
}

View File

@ -1,18 +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 matterlink.stripColorOut
import java.util.Random
object DeathHandler { object DeathHandler {
fun handleDeath(player: String, deathMessage: String) { private val random = Random()
if (cfg!!.relay.deathEvents) {
val msg = deathMessage.replace(player, player.antiping()) suspend fun handleDeath(
MessageHandler.transmit(ApiMessage( player: String,
username = cfg!!.relay.systemUser, deathMessage: String,
text = msg damageType: String,
)) x: Int, y: Int, z: Int,
dimension: Int
) {
if (cfg.outgoing.death.enable) {
var msg = deathMessage.stripColorOut.replace(player, player.stripColorOut.antiping)
if (cfg.outgoing.death.damageType) {
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]
?: arrayOf("\uD83D\uDC7B unknown type '$damageType'")
val damageEmoji = emojis[random.nextInt(emojis.size)]
msg += " $damageEmoji"
}
LocationHandler.sendToLocations(
msg = msg,
x = x, y = y, z = z, dimension = dimension,
event = ChatEvent.DEATH,
cause = "Death Event of $player",
systemuser = true
)
} }
} }
} }

View File

@ -1,42 +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(
if (cfg!!.relay.joinLeave) { player: String,
val msg = cfg!!.formattingJoinLeave.joinServer.mapFormat( x: Int, y: Int, z: Int,
dimension: Int
) {
if (cfg.outgoing.joinPart.enable) {
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(
username = cfg!!.relay.systemUser, msg = msg,
text = msg, x = x, y = y, z = z, dimension = dimension,
event = JOIN_LEAVE event = ChatEvent.JOIN,
)) systemuser = true,
cause = "$player joined"
)
} }
} }
fun handleLeave(player: String) { suspend fun handleLeave(
if (cfg!!.relay.joinLeave) { player: String,
val msg = cfg!!.formattingJoinLeave.leaveServer.mapFormat( x: Int, y: Int, z: Int,
dimension: Int
) {
if (cfg.outgoing.joinPart.enable) {
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(
username = cfg!!.relay.systemUser, msg = msg,
text = msg, x = x, y = y, z = z, dimension = dimension,
event = JOIN_LEAVE event = ChatEvent.JOIN,
)) systemuser = true,
cause = "$player left"
)
} }
} }
} }

View File

@ -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
}
}

View File

@ -1,18 +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, text: String) { suspend fun handleProgress(
if (!cfg!!.relay.advancements) return name: String, message: String, display: String,
val usr = name.antiping() x: Int, y: Int, z: Int,
MessageHandler.transmit(ApiMessage( dimension: Int
username = cfg!!.relay.systemUser, ) {
text = "$usr $text" if (!cfg.outgoing.advancements) return
)) val usr = name.stripColorOut.antiping
LocationHandler.sendToLocations(
msg = "$usr $message $display".stripColorOut,
x = x, y = y, z = z, dimension = dimension,
event = ChatEvent.ADVANCEMENT,
cause = "Progress Event by $usr",
systemuser = true
)
} }
} }

View File

@ -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)
// }
// }
}
}

View File

@ -0,0 +1,28 @@
package matterlink.handlers
import matterlink.update.UpdateChecker
/**
* Created by nikky on 21/02/18.
* @author Nikky
* @version 1.0
*/
object TickHandler {
var tickCounter = 0
private set
private var accumulator = 0
private const val updateInterval = 12 * 60 * 60 * 20
suspend fun handleTick() {
tickCounter++
// if (tickCounter % 100 == 0) {
// MessageHandlerInst.checkConnection()
// }
ServerChatHandler.writeIncomingToChat()
if (accumulator++ > updateInterval) {
accumulator -= updateInterval
UpdateChecker.check()
}
}
}

View File

@ -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
)

View File

@ -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
}
}
}
}

View File

@ -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
)

View File

@ -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
}
}
}
}

View File

@ -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)
}
}

View File

@ -0,0 +1,13 @@
package matterlink.update
import kotlinx.serialization.Serializable
@Serializable
data class CurseFile(
val downloadUrl: String,
val fileName: String,
val fileNameOnDisk: String,
val gameVersion: List<String>,
val releaseType: String,
val fileStatus: String
)

View File

@ -0,0 +1,137 @@
package matterlink.update
import com.github.kittinunf.fuel.core.extensions.cUrlString
import com.github.kittinunf.fuel.httpGet
import kotlinx.coroutines.CoroutineName
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.handlers.ChatEvent
import matterlink.handlers.LocationHandler
import matterlink.instance
import matterlink.jenkins.JenkinsServer
import matterlink.logger
import com.github.kittinunf.fuel.serialization.kotlinxDeserializerOf
import com.github.kittinunf.result.Result
import kotlinx.serialization.json.JSON
object UpdateChecker : CoroutineScope {
override val coroutineContext = Job() + CoroutineName("UpdateChacker")
suspend fun check() {
if (cfg.update.enable) {
run()
}
}
private suspend fun run() {
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")
}
}
return
}
if (instance.modVersion.contains("-dev")) {
logger.debug("Not checking updates on developer build")
return
}
logger.info("Checking for new versions...")
val (request, response, result) = with(instance) {
val useragent =
"MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)"
logger.debug("setting User-Agent: '$useragent'")
"https://curse.nikky.moe/api/addon/287323/files".httpGet()
.header("User-Agent" to useragent)
.responseObject(kotlinxDeserializerOf(loader = CurseFile.serializer().list, json = JSON.nonstrict))
}
val apiUpdateList = when(result) {
is Result.Success -> {
result.value
}
is Result.Failure -> {
logger.error("Could not check for updates!")
logger.error("cUrl: ${request.cUrlString()}")
logger.error("request: $request")
logger.error("response: $response")
return
}
}
.filter { it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion) }
val modVersionChunks = instance.modVersion
.substringBefore("-dev")
.substringBefore("-build")
.split('.')
.map {
it.toInt()
}
val possibleUpdates = mutableListOf<CurseFile>()
apiUpdateList.forEach {
logger.debug(it.toString())
val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() }
var bigger = false
version.forEachIndexed { index, chunk ->
if (!bigger) {
val currentChunk = modVersionChunks.getOrNull(index) ?: 0
logger.debug("$chunk > $currentChunk")
if (chunk < currentChunk)
return@forEach
bigger = chunk > currentChunk
}
}
if (bigger) {
possibleUpdates += it
}
}
if (possibleUpdates.isEmpty()) return
val latest = possibleUpdates[0]
possibleUpdates.sortByDescending { it.fileName.substringAfter(" ") }
val count = possibleUpdates.count()
val version = if (count == 1) "version" else "versions"
logger.info("Matterlink out of date! You are $count $version behind")
possibleUpdates.forEach {
logger.info("version: ${it.fileName} download: ${it.downloadUrl}")
}
logger.warn("Mod out of date! New $version available at ${latest.downloadUrl}")
MessageHandlerInst.transmit(
ApiMessage(
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadUrl}"
)
)
}
}

View File

@ -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"]
}] }]

View File

@ -1 +1,12 @@
mod_version = 1.2.2 modName = MatterLink
modVersion = 1.6.4
forgelinVersion = 1.8.2
kotlinVersion = 1.3.10
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

View File

@ -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

248
matterbridge-sample.toml Normal file
View File

@ -0,0 +1,248 @@
#This is configuration for matterbridge.
#WARNING: as this file contains credentials, be sure to set correct file permissions
###################################################################
#IRC section
###################################################################
#REQUIRED to start IRC section
[irc]
#You can configure multiple servers "[irc.name]" or "[irc.name2]"
#In this example we use [irc.freenode]
#REQUIRED
[irc.esper]
#irc server to connect to.
#REQUIRED
Server="irc.esper.net:6697"
#Password for irc server (if necessary)
#OPTIONAL (default "")
Password=""
#Enable to use TLS connection to your irc server.
#OPTIONAL (default false)
UseTLS=true
#Enable SASL (PLAIN) authentication. (freenode requires this from eg AWS hosts)
#It uses NickServNick and NickServPassword as login and password
#OPTIONAL (default false)
UseSASL=false
#Enable to not verify the certificate on your irc server. i
#e.g. when using selfsigned certificates
#OPTIONAL (default false)
SkipTLSVerify=true
#If you know your charset, you can specify it manually.
#Otherwise it tries to detect this automatically. Select one below
# "iso-8859-2:1987", "iso-8859-9:1989", "866", "latin9", "iso-8859-10:1992", "iso-ir-109", "hebrew",
# "cp932", "iso-8859-15", "cp437", "utf-16be", "iso-8859-3:1988", "windows-1251", "utf16", "latin6",
# "latin3", "iso-8859-1:1987", "iso-8859-9", "utf-16le", "big5", "cp819", "asmo-708", "utf-8",
# "ibm437", "iso-ir-157", "iso-ir-144", "latin4", "850", "iso-8859-5", "iso-8859-5:1988", "l3",
# "windows-31j", "utf8", "iso-8859-3", "437", "greek", "iso-8859-8", "l6", "l9-iso-8859-15",
# "iso-8859-2", "latin2", "iso-ir-100", "iso-8859-6", "arabic", "iso-ir-148", "us-ascii", "x-sjis",
# "utf16be", "iso-8859-8:1988", "utf16le", "l4", "utf-16", "iso-ir-138", "iso-8859-7", "iso-8859-7:1987",
# "windows-1252", "l2", "koi8-r", "iso8859-1", "latin1", "ecma-114", "iso-ir-110", "elot-928",
# "iso-ir-126", "iso-8859-1", "iso-ir-127", "cp850", "cyrillic", "greek8", "windows-1250", "iso-latin-1",
# "l5", "ibm866", "cp866", "ms-kanji", "ibm850", "ecma-118", "iso-ir-101", "ibm819", "l1", "iso-8859-6:1987",
# "latin5", "ascii", "sjis", "iso-8859-10", "iso-8859-4", "iso-8859-4:1988", "shift-jis
# The select charset will be converted to utf-8 when sent to other bridges.
#OPTIONAL (default "")
Charset=""
#Your nick on irc.
#REQUIRED
Nick="matterbot"
#If you registered your bot with a service like Nickserv on freenode.
#Also being used when UseSASL=true
#
#Note: if you want do to quakenet auth, set NickServNick="Q@CServe.quakenet.org"
#OPTIONAL
NickServNick="nickserv"
NickServPassword="secret"
#OPTIONAL only used for quakenet auth
NickServUsername="username"
#Flood control
#Delay in milliseconds between each message send to the IRC server
#OPTIONAL (default 1300)
MessageDelay=1300
#Maximum amount of messages to hold in queue. If queue is full
#messages will be dropped.
#<message clipped> will be add to the message that fills the queue.
#OPTIONAL (default 30)
MessageQueue=30
#Maximum length of message sent to irc server. If it exceeds
#<message clipped> will be add to the message.
#OPTIONAL (default 400)
MessageLength=400
#Split messages on MessageLength instead of showing the <message clipped>
#WARNING: this could lead to flooding
#OPTIONAL (default false)
MessageSplit=false
#Delay in seconds to rejoin a channel when kicked
#OPTIONAL (default 0)
RejoinDelay=0
#Nicks you want to ignore.
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
#Messages you want to ignore.
#Messages matching these regexp will be ignored and not sent to other bridges
#See https://regex-golang.appspot.com/assets/html/index.html for more regex info
#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword
IgnoreMessages="^~~ badword"
#messages you want to replace.
#it replaces outgoing messages from the bridge.
#so you need to place it by the sending bridge definition.
#regular expressions supported
#some examples:
#this replaces cat => dog and sleep => awake
#replacemessages=[ ["cat","dog"], ["sleep","awake"] ]
#this replaces every number with number. 123 => numbernumbernumber
#replacemessages=[ ["[0-9]","number"] ]
#optional (default empty)
ReplaceMessages=[ ["cat","dog"] ]
#nicks you want to replace.
#see replacemessages for syntaxa
#optional (default empty)
ReplaceNicks=[ ["user--","user"] ]
#extra label that can be used in the RemoteNickFormat
#optional (default empty)
Label=""
#RemoteNickFormat defines how remote users appear on this bridge
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge
#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge
#The string "{NOPINGNICK}" (case sensitive) will be replaced by the actual nick / username, but with a ZWSP inside the nick, so the irc user with the same nick won't get pinged. See https://github.com/42wim/matterbridge/issues/175 for more information
#OPTIONAL (default empty)
RemoteNickFormat="[{PROTOCOL}.{BRIDGE}] <{NOPINGNICK}> "
#Enable to show users joins/parts from other bridges
#Currently works for messages from the following bridges: irc, mattermost, slack
#OPTIONAL (default false)
ShowJoinPart=true
#StripNick only allows alphanumerical nicks. See https://github.com/42wim/matterbridge/issues/285
#It will strip other characters from the nick
#OPTIONAL (default false)
StripNick=false
#Enable to show topic changes from other bridges
#Only works hiding/show topic changes from slack bridge for now
#OPTIONAL (default false)
ShowTopicChange=false
###################################################################
#API
###################################################################
[api]
#You can configure multiple API hooks
#In this example we use [api.minecraft]
#REQUIRED
[api.minecraft]
#Address to listen on for API
#REQUIRED
BindAddress="127.0.0.1:4242"
#Amount of messages to keep in memory
Buffer=1000
#Bearer token used for authentication
#curl -H "Authorization: Bearer token" http://localhost:4242/api/messages
#OPTIONAL (no authorization if token is empty)
Token=""
#extra label that can be used in the RemoteNickFormat
#optional (default empty)
Label="minecraft"
#RemoteNickFormat defines how remote users appear on this bridge
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge
#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge
#OPTIONAL (default empty)
RemoteNickFormat="{NICK}"
###################################################################
#General configuration
###################################################################
# Settings here are defaults that each protocol can override
[general]
#RemoteNickFormat defines how remote users appear on this bridge
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
#The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge
#The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge
#OPTIONAL (default empty)
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
#StripNick only allows alphanumerical nicks. See https://github.com/42wim/matterbridge/issues/285
#It will strip other characters from the nick
#OPTIONAL (default false)
StripNick=false
#MediaServerUpload and MediaServerDownload are used for uploading images/files/video to
#a remote "mediaserver" (a webserver like caddy for example).
#When configured images/files uploaded on bridges like mattermost,slack, telegram will be downloaded
#and uploaded again to MediaServerUpload URL
#The MediaServerDownload will be used so that bridges without native uploading support:
#gitter, irc and xmpp will be shown links to the files on MediaServerDownload
#
#More information https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-%5Badvanced%5D
#OPTIONAL (default empty)
MediaServerUpload="https://user:pass@yourserver.com/upload"
#OPTIONAL (default empty)
MediaServerDownload="https://youserver.com/download"
#MediaDownloadSize is the maximum size of attachments, videos, images
#matterbridge will download and upload this file to bridges that also support uploading files.
#eg downloading from slack to upload it to mattermost
#
#It will only download from bridges that don't have public links available, which are for the moment
#slack, telegram, matrix and mattermost
#
#Optional (default 1000000 (1 megabyte))
MediaDownloadSize=1000000
###################################################################
#Gateway configuration
###################################################################
#You can specify multiple gateways using [[gateway]]
#Each gateway has a [[gateway.in]] and a [[gateway.out]]
#[[gateway.in]] specifies the account and channels we will receive messages from.
#[[gateway.out]] specifies the account and channels we will send the messages
#from [[gateway.in]] to.
#
#Most of the time [[gateway.in]] and [[gateway.out]] are the same if you
#want bidirectional bridging. You can then use [[gateway.inout]]
#
[[gateway]]
#REQUIRED and UNIQUE
name="minecraft"
#Enable enables this gateway
##OPTIONAL (default false)
enable=true
# API
[[gateway.inout]]
account="api.minecraft"
channel="api"
[[gateway.inout]]
account="irc.esper"
channel="#matterlink"

23
scripts/start.sh Executable file
View File

@ -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

Some files were not shown because too many files have changed in this diff Show More