├── test ├── run │ └── .gitkeep └── build.gradle.kts ├── .github ├── .editorconfig └── workflows │ ├── build.yaml │ └── publish.yaml ├── gradlew ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── characters └── build.gradle.kts ├── proxy └── src │ ├── main │ ├── resources │ │ ├── log4j2_prod.component.properties │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── kotlinx.coroutines.internal.MainDispatcherFactory │ │ ├── data │ │ │ ├── npc_catchable.json │ │ │ └── tile_frame_important.json │ │ ├── log4j2_prod.xml │ │ └── log4j2.xml │ └── kotlin │ │ └── org │ │ └── lanternpowered │ │ └── terre │ │ ├── catalog │ │ ├── CatalogType.kt │ │ ├── NamedCatalogType.kt │ │ ├── NumericCatalogType.kt │ │ ├── CatalogTypeRegistry.kt │ │ ├── NumericCatalogTypeRegistry.kt │ │ └── NamedCatalogTypeRegistry.kt │ │ ├── impl │ │ ├── network │ │ │ ├── Packet.kt │ │ │ ├── buffer │ │ │ │ ├── ItemId.kt │ │ │ │ ├── NpcType.kt │ │ │ │ ├── NpcId.kt │ │ │ │ ├── Projectile.kt │ │ │ │ ├── ProjectileId.kt │ │ │ │ ├── PlayerId.kt │ │ │ │ ├── UpOrDown.kt │ │ │ │ └── LeftOrRight.kt │ │ │ ├── NetworkContext.kt │ │ │ ├── ProtocolTranslation.kt │ │ │ ├── pipeline │ │ │ │ ├── ProtocolConstants.kt │ │ │ │ ├── FrameEncoder.kt │ │ │ │ └── FrameDecoder.kt │ │ │ ├── PacketDecoderRegistration.kt │ │ │ ├── PacketEncoderRegistration.kt │ │ │ ├── VersionedProtocol.kt │ │ │ ├── PacketEncoderRegistrationImpl.kt │ │ │ ├── PacketDecoderRegistrationImpl.kt │ │ │ ├── PacketDirection.kt │ │ │ ├── ChannelFutureListener.kt │ │ │ ├── PacketRegistration.kt │ │ │ ├── packet │ │ │ │ ├── RealIPPacket.kt │ │ │ │ ├── PasswordRequestPacket.kt │ │ │ │ ├── tmodloader │ │ │ │ │ ├── SyncModsDonePacket.kt │ │ │ │ │ ├── ModDataPacket.kt │ │ │ │ │ └── ModFileRequestPacket.kt │ │ │ │ ├── CompleteConnectionPacket.kt │ │ │ │ ├── EssentialTilesRequestPacket.kt │ │ │ │ ├── WorldInfoRequestPacket.kt │ │ │ │ ├── DisconnectPacket.kt │ │ │ │ ├── v238 │ │ │ │ │ ├── ConnectionApproved238.kt │ │ │ │ │ └── PlayerSpawn238.kt │ │ │ │ ├── ConnectionRequestPacket.kt │ │ │ │ ├── PasswordResponsePacket.kt │ │ │ │ ├── NebulaLevelUpRequestPacket.kt │ │ │ │ ├── PlayerCommandPacket.kt │ │ │ │ ├── PlayerPvPPacket.kt │ │ │ │ ├── PlayerActivePacket.kt │ │ │ │ ├── ClientUniqueIdPacket.kt │ │ │ │ ├── CustomPayloadPacket.kt │ │ │ │ ├── PlayerManaPacket.kt │ │ │ │ ├── PlayerHealthPacket.kt │ │ │ │ ├── AddPlayerBuffPacket.kt │ │ │ │ ├── ConnectionApprovedPacket.kt │ │ │ │ ├── ItemUpdateOwnerPacket.kt │ │ │ │ ├── PlayerBuffsPacket.kt │ │ │ │ ├── ItemRemoveOwnerPacket.kt │ │ │ │ ├── TeleportPylonPacket.kt │ │ │ │ ├── v230 │ │ │ │ │ └── TileSquare230.kt │ │ │ │ ├── ProjectileDestroyPacket.kt │ │ │ │ └── PlayerTeamPacket.kt │ │ │ ├── NettyThreadFactory.kt │ │ │ ├── UnknownPacket.kt │ │ │ ├── client │ │ │ │ ├── InitialInboundConnection.kt │ │ │ │ └── ClientInitProtocol.kt │ │ │ ├── PacketDecoder.kt │ │ │ ├── backend │ │ │ │ └── ServerInitConnectionResult.kt │ │ │ ├── ForwardingReferenceCounted.kt │ │ │ ├── tracking │ │ │ │ ├── TrackedPlayers.kt │ │ │ │ ├── TrackedNpcs.kt │ │ │ │ ├── TrackedProjectiles.kt │ │ │ │ └── TrackedItems.kt │ │ │ ├── PacketCodecContext.kt │ │ │ ├── PacketEncoder.kt │ │ │ └── PacketLengthBuilder.kt │ │ ├── ProjectileType.kt │ │ ├── event │ │ │ ├── EventHandler.kt │ │ │ ├── RegisteredHandler.kt │ │ │ ├── UntargetedEventHandler.kt │ │ │ └── EventExecutor.kt │ │ ├── plugin │ │ │ ├── PluginCandidate.kt │ │ │ ├── PluginClassLoader.kt │ │ │ └── asm │ │ │ │ ├── PluginClassVisitor.kt │ │ │ │ └── WarningAnnotationVisitor.kt │ │ ├── AchievementImpl.kt │ │ ├── text │ │ │ ├── ColorableTextImpl.kt │ │ │ ├── GlyphImpl.kt │ │ │ ├── TaggedTextSerializerImpl.kt │ │ │ ├── GlyphTextImpl.kt │ │ │ ├── AchievementTextImpl.kt │ │ │ ├── ItemTextImpl.kt │ │ │ ├── MessageReceiverImpl.kt │ │ │ └── LiteralTextImpl.kt │ │ ├── ProjectileTypes.kt │ │ ├── item │ │ │ ├── ItemTypeImpl.kt │ │ │ ├── ItemModifierImpl.kt │ │ │ ├── InventoryImpl.kt │ │ │ └── ItemStackImpl.kt │ │ ├── util │ │ │ ├── InetAddress.kt │ │ │ ├── LazyReadOnlyProperty.kt │ │ │ └── TerreThread.kt │ │ ├── ProjectileIdAllocator.kt │ │ ├── logger │ │ │ └── LoggerImpl.kt │ │ ├── coroutines │ │ │ └── Coroutines.kt │ │ ├── TileInfo.kt │ │ ├── NpcInfo.kt │ │ ├── config │ │ │ └── ConfigDirectoryImpl.kt │ │ ├── Terre.kt │ │ └── player │ │ │ └── TeamImpl.kt │ │ ├── event │ │ ├── Event.kt │ │ ├── Order.kt │ │ ├── proxy │ │ │ ├── ProxyShutdownEvent.kt │ │ │ └── ProxyInitializeEvent.kt │ │ ├── EventSubscription.kt │ │ ├── ListenerRegistration.kt │ │ ├── player │ │ │ ├── PlayerDeathEvent.kt │ │ │ ├── PlayerRespawnEvent.kt │ │ │ ├── PlayerChangePvPEnabledEvent.kt │ │ │ └── PlayerChangeTeamEvent.kt │ │ ├── server │ │ │ ├── ServerUnregisterEvent.kt │ │ │ ├── ServerRegisterEvent.kt │ │ │ ├── PlayerLeaveServerEvent.kt │ │ │ └── PlayerJoinServerEvent.kt │ │ ├── Subscribe.kt │ │ ├── connection │ │ │ ├── PlayerPostLoginEvent.kt │ │ │ ├── ClientConnectEvent.kt │ │ │ └── PlayerLoginEvent.kt │ │ ├── permission │ │ │ └── InitPermissionSubjectEvent.kt │ │ └── chat │ │ │ └── ServerChatEvent.kt │ │ ├── plugin │ │ ├── InvalidPluginException.kt │ │ ├── Plugin.kt │ │ ├── PluginManager.kt │ │ └── PluginContainer.kt │ │ ├── command │ │ ├── CommandSource.kt │ │ ├── CommandManager.kt │ │ └── CommandExecutor.kt │ │ ├── Named.kt │ │ ├── text │ │ ├── TextLike.kt │ │ ├── MessageSender.kt │ │ ├── TextSerializer.kt │ │ ├── LiteralText.kt │ │ ├── PlainTextSerializer.kt │ │ ├── StatusTextAware.kt │ │ ├── GroupedText.kt │ │ ├── GlyphText.kt │ │ ├── Achievement.kt │ │ ├── ItemText.kt │ │ ├── TaggedTextSerializer.kt │ │ ├── AchievementText.kt │ │ ├── Glyph.kt │ │ ├── CombatTextAware.kt │ │ ├── ColorableText.kt │ │ ├── FormattableText.kt │ │ └── LocalizedText.kt │ │ ├── logger │ │ └── Logger.kt │ │ ├── util │ │ ├── collection │ │ │ └── Maps.kt │ │ └── text │ │ │ └── CharSequence.kt │ │ ├── permission │ │ └── PermissionSubject.kt │ │ ├── sql │ │ └── SqlManager.kt │ │ ├── ServerConnection.kt │ │ ├── config │ │ ├── RootConfigDirectory.kt │ │ ├── ConfigFormat.kt │ │ ├── ConfigFormats.kt │ │ ├── ConfigDirectory.kt │ │ ├── ConfigDirectoryBase.kt │ │ └── ReloadableConfig.kt │ │ ├── Console.kt │ │ ├── item │ │ ├── Inventory.kt │ │ ├── ItemModifier.kt │ │ └── ItemType.kt │ │ ├── portal │ │ ├── PortalAware.kt │ │ └── PortalType.kt │ │ ├── InboundConnection.kt │ │ ├── MaxPlayers.kt │ │ ├── character │ │ └── CharacterStorage.kt │ │ ├── ServerCollection.kt │ │ ├── coroutines │ │ └── Coroutines.kt │ │ ├── ServerInfo.kt │ │ ├── PlayerCollection.kt │ │ └── Team.kt │ └── test │ └── kotlin │ └── org │ └── lanternpowered │ └── terre │ └── impl │ ├── math │ ├── Vec2iTest.kt │ └── Vec2fTest.kt │ └── util │ ├── VersionTest.kt │ └── GenerateReadyRequestPacket.kt ├── HEADER.txt ├── k8s-server-finder └── build.gradle.kts ├── settings.gradle.kts ├── .gitattributes ├── tshock-users └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── lanternpowered │ │ └── terre │ │ └── tshock │ │ ├── group │ │ ├── Group.kt │ │ ├── SuperAdminGroup.kt │ │ └── Groups.kt │ │ ├── user │ │ └── User.kt │ │ ├── TShockPlayer.kt │ │ └── TShockUsersConfigSpec.kt │ └── test │ └── kotlin │ └── org │ └── lanternpowered │ └── terre │ └── tshock │ └── group │ └── TShockMessagesTest.kt ├── .idea └── runConfigurations │ └── Terre_Test.xml ├── .gitignore ├── LICENSE.txt ├── image └── build.gradle.kts └── portals └── src └── main └── kotlin └── org └── lanternpowered └── terre └── portals └── PortalData.kt /test/run/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.yaml] 2 | ij_wrap_on_typing = false 3 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LanternPowered/Terre/HEAD/gradlew -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LanternPowered/Terre/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /characters/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | } 4 | 5 | dependencies { 6 | implementation(project(":terre-proxy")) 7 | } 8 | -------------------------------------------------------------------------------- /proxy/src/main/resources/log4j2_prod.component.properties: -------------------------------------------------------------------------------- 1 | Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector 2 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory: -------------------------------------------------------------------------------- 1 | org.lanternpowered.terre.impl.TerreMainDispatcherFactory 2 | -------------------------------------------------------------------------------- /HEADER.txt: -------------------------------------------------------------------------------- 1 | ${name} 2 | 3 | Copyright (c) ${organization} <${url}> 4 | Copyright (c) contributors 5 | 6 | This work is licensed under the terms of the MIT License (MIT). For 7 | a copy, see 'LICENSE.txt' or . -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /k8s-server-finder/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | kotlin("plugin.serialization") 4 | } 5 | 6 | dependencies { 7 | api(project(":terre-proxy")) 8 | implementation(group = "io.kubernetes", name = "client-java", version = "18.0.0") 9 | } 10 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "Terre" 2 | 3 | listOf( 4 | "proxy", 5 | "image", 6 | "standalone", 7 | "k8s-server-finder", 8 | "portals", 9 | "characters", 10 | "test", 11 | "tshock-users", 12 | ).forEach { 13 | include(it) 14 | project(":$it").name = "terre-$it" 15 | } 16 | -------------------------------------------------------------------------------- /test/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | kotlin("plugin.serialization") 4 | } 5 | 6 | dependencies { 7 | implementation(project(":terre-proxy")) 8 | implementation(project(":terre-portals")) 9 | implementation(project(":terre-characters")) 10 | // implementation(project(":terre-tshock-users")) 11 | } 12 | -------------------------------------------------------------------------------- /proxy/src/main/resources/data/npc_catchable.json: -------------------------------------------------------------------------------- 1 | [46,55,74,148,149,297,298,299,300,355,356,357,358,359,360,361,362,363,364,365,366,367,374,377,442,443,444,445,446,447,448,484,485,486,487,538,539,583,584,585,592,593,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,616,617,626,627,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,661,669,677] 2 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/CatalogType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | interface CatalogType 13 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/Packet.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal interface Packet 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize as LF in the repository, OS native locally 2 | * text=auto 3 | 4 | *.bat text eol=crlf 5 | gradlew text eol=lf 6 | *.sh text eol=lf 7 | 8 | *.java text 9 | *.java diff=java 10 | 11 | # Binary files that should not be modified 12 | *.dat binary 13 | *.db binary 14 | *.icns binary 15 | *.ico binary 16 | *.jar binary 17 | *.jks binary 18 | *.jpg binary 19 | *.key binary 20 | *.png binary 21 | *.ttf binary 22 | *.wav binary 23 | JavaApplicationStub binary -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/Event.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event 11 | 12 | /** 13 | * The base interface for all events. 14 | */ 15 | interface Event 16 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/plugin/InvalidPluginException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.plugin 11 | 12 | class InvalidPluginException(message: String) : Exception(message) 13 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/ItemId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | @JvmInline 13 | internal value class ItemId(val value: Int) 14 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/NpcType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | @JvmInline 13 | internal value class NpcType(val value: Int) 14 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/NetworkContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal interface NetworkContext { 13 | 14 | val connection: Connection 15 | } 16 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/NamedCatalogType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | import org.lanternpowered.terre.Named 13 | 14 | interface NamedCatalogType : Named, CatalogType 15 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/command/CommandSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.command 11 | 12 | import org.lanternpowered.terre.permission.PermissionSubject 13 | 14 | interface CommandSource : PermissionSubject 15 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/group/Group.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock.group 11 | 12 | interface Group { 13 | 14 | val name: String 15 | 16 | fun hasPermission(permission: String): Boolean 17 | } 18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/Named.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | /** 13 | * Something that has a name. 14 | */ 15 | interface Named { 16 | 17 | /** 18 | * The name. 19 | */ 20 | val name: String 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/ProjectileType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | /** 13 | * Represents the id of a projectile. 14 | */ 15 | @JvmInline 16 | internal value class ProjectileType(inline val value: Int) 17 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/event/EventHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.event 11 | 12 | import org.lanternpowered.terre.event.Event 13 | 14 | interface EventHandler { 15 | 16 | suspend fun handle(event: Event) 17 | } 18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/NpcId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | /** 13 | * Represents the id of a npc. 14 | */ 15 | @JvmInline 16 | internal value class NpcId(inline val value: Int) 17 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/plugin/PluginCandidate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.plugin 11 | 12 | import java.nio.file.Path 13 | 14 | internal data class PluginCandidate( 15 | val className: String, 16 | val id: String, 17 | val source: Path? 18 | ) 19 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches-ignore: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v3 15 | - name: Setup JDK 17 16 | uses: actions/setup-java@v3 17 | with: 18 | distribution: adopt 19 | java-version: 17 20 | - name: Validate Gradle wrapper 21 | uses: gradle/wrapper-validation-action@v1 22 | - name: Build 23 | run: "./gradlew build" 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/Order.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event 11 | 12 | object Order { 13 | 14 | const val First = -100 15 | 16 | const val Early = -50 17 | 18 | const val Normal = 0 19 | 20 | const val Late = 50 21 | 22 | const val Last = 100 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/proxy/ProxyShutdownEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.proxy 11 | 12 | import org.lanternpowered.terre.event.Event 13 | 14 | /** 15 | * This event is thrown when the proxy is shutting down. 16 | */ 17 | class ProxyShutdownEvent : Event 18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/Projectile.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | import org.lanternpowered.terre.impl.ProjectileType 13 | 14 | internal data class Projectile( 15 | val id: ProjectileId, 16 | val type: ProjectileType 17 | ) 18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/TextLike.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | /** 13 | * Something that can be represented as [Text]. 14 | */ 15 | interface TextLike { 16 | 17 | /** 18 | * Converts this text like to [Text]. 19 | */ 20 | fun text(): Text 21 | } 22 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/group/SuperAdminGroup.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock.group 11 | 12 | object SuperAdminGroup : Group { 13 | 14 | override val name: String 15 | get() = "superadmin" 16 | 17 | override fun hasPermission(permission: String) = true 18 | } 19 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/EventSubscription.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event 11 | 12 | /** 13 | * Represents an event subscription. 14 | */ 15 | interface EventSubscription { 16 | 17 | /** 18 | * Unregisters the event subscription. 19 | */ 20 | fun unsubscribe() 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/MessageSender.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | /** 13 | * Represents a sender of messages. 14 | */ 15 | interface MessageSender { 16 | 17 | /** 18 | * Represents an unknown message sender. 19 | */ 20 | object Unknown : MessageSender 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/ProtocolTranslation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | /** 13 | * Represents an allowed translation between two protocol versions. 14 | */ 15 | internal class ProtocolTranslation( 16 | val from: Protocol, 17 | val to: Protocol 18 | ) 19 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/ListenerRegistration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event 11 | 12 | /** 13 | * Represents a listener registration. 14 | */ 15 | interface ListenerRegistration { 16 | 17 | /** 18 | * Unregisters the listener registration. 19 | */ 20 | fun unregister() 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/NumericCatalogType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | /** 13 | * Represents a catalog type that holds a numeric id. 14 | */ 15 | interface NumericCatalogType : CatalogType { 16 | 17 | /** 18 | * The numeric id. 19 | */ 20 | val numericId: Int 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/logger/Logger.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.logger 11 | 12 | import org.apache.logging.log4j.Logger 13 | 14 | interface Logger : Logger { 15 | 16 | fun info(message: () -> String) 17 | 18 | fun debug(message: () -> String) 19 | 20 | fun warn(message: () -> String) 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/util/collection/Maps.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("NOTHING_TO_INLINE") 11 | 12 | package org.lanternpowered.terre.util.collection 13 | 14 | import com.google.common.collect.ImmutableMap 15 | 16 | inline fun Map.toImmutableMap(): ImmutableMap = 17 | ImmutableMap.copyOf(this) 18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/proxy/ProxyInitializeEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.proxy 11 | 12 | import org.lanternpowered.terre.event.Event 13 | 14 | /** 15 | * This event is thrown after the plugins are loaded and the proxy is starting to accept 16 | * connections. 17 | */ 18 | class ProxyInitializeEvent : Event 19 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/pipeline/ProtocolConstants.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.pipeline 11 | 12 | /** 13 | * The id of the module packets. 14 | */ 15 | internal const val ModulePacketId = 0x52 16 | 17 | internal const val ModuleIdOffset = 8 18 | internal const val ModuleIdMask = (1 shl ModuleIdOffset) - 1 19 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/ProjectileId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | /** 13 | * Represents the id of a projectile. 14 | */ 15 | @JvmInline 16 | internal value class ProjectileId(inline val value: Int) { 17 | 18 | companion object { 19 | 20 | val None = ProjectileId(-1) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/player/PlayerDeathEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.player 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | 15 | /** 16 | * An event that is thrown when a player dies. 17 | */ 18 | data class PlayerDeathEvent( 19 | val player: Player, 20 | ) : Event 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/server/ServerUnregisterEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.server 11 | 12 | import org.lanternpowered.terre.Server 13 | import org.lanternpowered.terre.event.Event 14 | 15 | /** 16 | * This event is thrown when a server got unregistered. 17 | */ 18 | class ServerUnregisterEvent(val server: Server) : Event 19 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/player/PlayerRespawnEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.player 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | 15 | /** 16 | * An event that is thrown when a player respawns. 17 | */ 18 | data class PlayerRespawnEvent( 19 | val player: Player, 20 | ) : Event 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/AchievementImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | import org.lanternpowered.terre.text.Achievement 13 | 14 | internal data class AchievementImpl( 15 | override val name: String 16 | ) : Achievement 17 | 18 | internal val AchievementRegistryImpl = 19 | buildNamedCatalogTypeRegistryOf(::AchievementImpl) 20 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/event/RegisteredHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.event 11 | 12 | import org.lanternpowered.terre.plugin.PluginContainer 13 | 14 | internal class RegisteredHandler( 15 | val plugin: PluginContainer?, 16 | val order: Int, 17 | val eventType: Class<*>, 18 | val instance: Any, 19 | val handler: EventHandler 20 | ) 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketDecoderRegistration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | /** 13 | * Represents a registered packet codec. 14 | */ 15 | internal interface PacketDecoderRegistration

: PacketRegistration

{ 16 | 17 | /** 18 | * The decoder. 19 | */ 20 | val decoder: PacketDecoder 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketEncoderRegistration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | /** 13 | * Represents a registered packet codec. 14 | */ 15 | internal interface PacketEncoderRegistration

: PacketRegistration

{ 16 | 17 | /** 18 | * The encoder. 19 | */ 20 | val encoder: PacketEncoder 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/permission/PermissionSubject.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.permission 11 | 12 | /** 13 | * Represents an object that has a set of permissions. 14 | */ 15 | interface PermissionSubject { 16 | 17 | /** 18 | * Returns if this subject has the specified [permission]. 19 | */ 20 | fun hasPermission(permission: String): Boolean 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/plugin/Plugin.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.plugin 11 | 12 | /** 13 | * An annotation to mark plugin classes or objects. 14 | * 15 | * @property id The id, can only contain a-z, 0-9, - and _ 16 | */ 17 | @Target(AnnotationTarget.CLASS) 18 | @Retention(AnnotationRetention.RUNTIME) 19 | annotation class Plugin( 20 | val id: String 21 | ) 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/VersionedProtocol.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import org.lanternpowered.terre.ProtocolVersion 13 | 14 | /** 15 | * Represents a [Protocol] bound to a specific [ProtocolVersion]. 16 | */ 17 | internal data class VersionedProtocol( 18 | val version: ProtocolVersion, 19 | val protocol: Protocol, 20 | ) 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/ColorableTextImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.text.ColorableText 13 | import org.lanternpowered.terre.util.Color 14 | 15 | internal abstract class ColorableTextImpl : TextImpl(), ColorableText { 16 | 17 | final override val color: Color? 18 | get() = optionalColor.orNull() 19 | } 20 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/TextSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | interface TextSerializer { 13 | 14 | /** 15 | * Serializes the [Text] object into a string. 16 | */ 17 | fun serialize(text: Text): String 18 | 19 | /** 20 | * Deserializes the [Text] object from a string. 21 | */ 22 | fun deserialize(string: String): Text 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/PlayerId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | /** 13 | * Represents the id of a player. 14 | */ 15 | @JvmInline 16 | internal value class PlayerId(inline val value: Int) { 17 | 18 | companion object { 19 | 20 | /** 21 | * Represents no player. 22 | */ 23 | val None = PlayerId(255) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketEncoderRegistrationImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal class PacketEncoderRegistrationImpl

( 13 | override val packetType: Class

, 14 | override val opcode: Int, 15 | override val encoder: PacketEncoder, 16 | override val directions: Set 17 | ) : PacketEncoderRegistration

18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/LiteralText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.util.Color 13 | 14 | /** 15 | * A component backed by literal text. 16 | */ 17 | interface LiteralText : ColorableText { 18 | 19 | /** 20 | * The literal text. 21 | */ 22 | val literal: String 23 | 24 | override fun color(color: Color?): LiteralText 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketDecoderRegistrationImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal class PacketDecoderRegistrationImpl

( 13 | override val packetType: Class

, 14 | override val opcode: Int, 15 | override val decoder: PacketDecoder, 16 | override val directions: Set, 17 | ) : PacketDecoderRegistration

18 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/GlyphImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.impl.buildNumericCatalogTypeRegistryOf 13 | import org.lanternpowered.terre.text.Glyph 14 | 15 | internal data class GlyphImpl( 16 | override val numericId: Int 17 | ) : Glyph 18 | 19 | internal val GlyphRegistryImpl = buildNumericCatalogTypeRegistryOf(::GlyphImpl) 20 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/PlainTextSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | /** 13 | * Represents the [TextSerializer] who converts between 14 | * plain strings and text objects. 15 | */ 16 | object PlainTextSerializer : TextSerializer { 17 | 18 | override fun serialize(text: Text) = text.toPlain() 19 | 20 | override fun deserialize(string: String) = string.text() 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketDirection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | /** 13 | * Represents the direction in which the 14 | * packet is being sent. 15 | */ 16 | enum class PacketDirection { 17 | /** 18 | * From the client to the server. 19 | */ 20 | ClientToServer, 21 | /** 22 | * From the server to the client. 23 | */ 24 | ServerToClient, 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/sql/SqlManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.sql 11 | 12 | import org.lanternpowered.terre.impl.sql.SqlManagerImpl 13 | import javax.sql.DataSource 14 | 15 | interface SqlManager { 16 | 17 | fun dataSource(url: String): DataSource 18 | 19 | fun dataSource(url: String, user: String, password: String): DataSource 20 | 21 | companion object : SqlManager by SqlManagerImpl 22 | } 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/Subscribe.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event 11 | 12 | /** 13 | * An annotation to mark a method as a listener for events. 14 | * 15 | * @property order The order (also known as priority) that the listener should be executed 16 | */ 17 | @Target(AnnotationTarget.FUNCTION) 18 | @Retention(AnnotationRetention.RUNTIME) 19 | annotation class Subscribe(val order: Int = Order.Normal) 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Terre_Test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/ServerConnection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | /** 13 | * Represents a connection between the proxy and a server for a specific [Player]. 14 | */ 15 | interface ServerConnection { 16 | 17 | /** 18 | * The server this connection is connected to. 19 | */ 20 | val server: Server 21 | 22 | /** 23 | * The player that this connection is used by. 24 | */ 25 | val player: Player 26 | } 27 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/ChannelFutureListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import io.netty.channel.ChannelFuture 13 | import io.netty.channel.ChannelFutureListener 14 | 15 | internal inline fun ChannelFuture.addChannelFutureListener( 16 | crossinline block: (future: ChannelFuture) -> Unit 17 | ): ChannelFuture { 18 | return this.addListener(ChannelFutureListener { 19 | block(it) 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/StatusTextAware.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | interface StatusTextAware { 13 | 14 | /** 15 | * Shows status text on the right side of the HUD. This will override any status text sent by 16 | * the server until reset. 17 | */ 18 | fun showStatusText(text: Text, showShadows: Boolean = false) 19 | 20 | /** 21 | * Resets the status text. 22 | */ 23 | fun resetStatusText() 24 | } 25 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/RootConfigDirectory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import org.lanternpowered.terre.impl.ProxyImpl 13 | 14 | /** 15 | * Represents the root configuration directory. 16 | */ 17 | interface RootConfigDirectory : ConfigDirectoryBase { 18 | 19 | /** 20 | * The singleton instance of the root config directory. 21 | */ 22 | companion object : RootConfigDirectory by ProxyImpl.configDirectory 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/plugin/PluginClassLoader.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.plugin 11 | 12 | import java.net.URL 13 | import java.net.URLClassLoader 14 | 15 | internal class PluginClassLoader( 16 | urls: Array = emptyArray(), 17 | parent: ClassLoader? = Thread.currentThread().contextClassLoader 18 | ) : URLClassLoader(urls, parent) { 19 | 20 | public override fun addURL(url: URL) { 21 | super.addURL(url) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/command/CommandManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.command 11 | 12 | import org.lanternpowered.terre.impl.command.CommandManagerImpl 13 | 14 | interface CommandManager { 15 | 16 | // TODO: Replace with kommando 17 | 18 | fun register(name: String, executor: RawCommandExecutor) 19 | 20 | fun register(name: String, executor: SimpleCommandExecutor) 21 | 22 | companion object : CommandManager by CommandManagerImpl 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/ProjectileTypes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | internal object ProjectileTypes { 13 | 14 | val NebulaArcanum = ProjectileType(617) 15 | val LunarPortal = ProjectileType(641) 16 | val MagnetSphereBall = ProjectileType(254) 17 | val ElectroSphereMissile = ProjectileType(443) 18 | val Fireball = ProjectileType(467) 19 | val ShadowFireball = ProjectileType(468) 20 | val VoidBag = ProjectileType(734) 21 | } 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketRegistration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal interface PacketRegistration

{ 13 | 14 | /** 15 | * The directions applicable to the registration. 16 | */ 17 | val directions: Set 18 | 19 | /** 20 | * The type of the packet. 21 | */ 22 | val packetType: Class

23 | 24 | /** 25 | * The opcode of the registration. 26 | */ 27 | val opcode: Int 28 | } 29 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/GroupedText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.util.Color 13 | 14 | /** 15 | * Represents a text component that is a combination of multiple child text components. 16 | */ 17 | interface GroupedText : ColorableText { 18 | 19 | /** 20 | * Represents the children of this grouped text component. 21 | */ 22 | val children: List 23 | 24 | override fun color(color: Color?): GroupedText 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/Console.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | import org.lanternpowered.terre.command.CommandSource 13 | import org.lanternpowered.terre.impl.ProxyImpl 14 | import org.lanternpowered.terre.text.MessageReceiver 15 | 16 | /** 17 | * Represents the console. 18 | */ 19 | interface Console : MessageReceiver, CommandSource { 20 | 21 | /** 22 | * The singleton instance of the console. 23 | */ 24 | companion object : Console by ProxyImpl.console 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/event/UntargetedEventHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.event 11 | 12 | import org.lanternpowered.terre.event.Event 13 | 14 | interface UntargetedEventHandler { 15 | 16 | suspend fun handle(target: Any, event: Event) 17 | 18 | interface NoSuspend : UntargetedEventHandler { 19 | 20 | override suspend fun handle(target: Any, event: Event) = handleDirect(target, event) 21 | 22 | fun handleDirect(target: Any, event: Event) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/GlyphText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.GlyphTextImpl 13 | 14 | /** 15 | * Creates a new [GlyphText] from the given [Glyph]. 16 | */ 17 | fun textOf(glyph: Glyph): GlyphText = 18 | GlyphTextImpl(glyph) 19 | 20 | /** 21 | * Represents a glyph text component. 22 | */ 23 | interface GlyphText : Text { 24 | 25 | /** 26 | * The glyph of the text component. 27 | */ 28 | val glyph: Glyph 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/item/Inventory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.item 11 | 12 | interface Inventory : Iterable> { 13 | 14 | /** 15 | * Clears the inventory. 16 | */ 17 | fun clear() 18 | 19 | /** 20 | * Gets the [ItemStack] at the specified [index]. 21 | */ 22 | operator fun get(index: Int): ItemStack 23 | 24 | /** 25 | * Sets the [ItemStack] at the specified [index]. 26 | */ 27 | operator fun set(index: Int, itemStack: ItemStack) 28 | } 29 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/group/Groups.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock.group 11 | 12 | import org.jetbrains.exposed.sql.Database 13 | import java.util.concurrent.ConcurrentHashMap 14 | 15 | object Groups { 16 | 17 | private val groups = ConcurrentHashMap() 18 | 19 | suspend fun load(db: Database) { 20 | GroupTable.loadGroups(db) 21 | .associateByTo(groups) { it.name } 22 | } 23 | 24 | operator fun get(name: String): Group? = groups[name] 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/item/ItemTypeImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.item 11 | 12 | import org.lanternpowered.terre.impl.buildNumericCatalogTypeRegistryOf 13 | import org.lanternpowered.terre.item.ItemType 14 | 15 | internal class ItemTypeImpl( 16 | override val numericId: Int 17 | ) : ItemType { 18 | override fun toString(): String = "ItemType(numericId=$numericId)" 19 | } 20 | 21 | internal val ItemTypeRegistryImpl = 22 | buildNumericCatalogTypeRegistryOf(::ItemTypeImpl) 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/Achievement.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.catalog.NamedCatalogType 13 | import org.lanternpowered.terre.catalog.NamedCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.AchievementRegistryImpl 15 | 16 | interface Achievement : NamedCatalogType, TextLike { 17 | 18 | override fun text(): AchievementText = textOf(this) 19 | } 20 | 21 | object AchievementRegistry : NamedCatalogTypeRegistry by AchievementRegistryImpl 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/portal/PortalAware.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.portal 11 | 12 | import org.lanternpowered.terre.math.Vec2f 13 | 14 | /** 15 | * Represents something that is aware of portals. 16 | */ 17 | interface PortalAware { 18 | 19 | /** 20 | * Opens a new portal at the given position. When the portal is no longer desired, it must be 21 | * cleaned up through [Portal.close]. 22 | */ 23 | fun openPortal(type: PortalType, position: Vec2f, builder: PortalBuilder.() -> Unit = {}): Portal 24 | } 25 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/UpOrDown.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | /** 13 | * Left or right. Usually used for up or down directions. 14 | * 15 | * @property isUp Whether it's up 16 | * @property isDown Whether it's down 17 | */ 18 | @JvmInline 19 | internal value class UpOrDown(val isUp: Boolean) { 20 | 21 | val isDown: Boolean 22 | get() = !isUp 23 | 24 | companion object { 25 | 26 | val Up = UpOrDown(true) 27 | 28 | val Down = UpOrDown(false) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/RealIPPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketEncoder 14 | import org.lanternpowered.terre.impl.network.buffer.writeString 15 | 16 | internal data class RealIPPacket( 17 | val ip: String 18 | ) : Packet 19 | 20 | internal val RealIPEncoder = PacketEncoder { buf, packet -> 21 | buf.writeShortLE(0) 22 | buf.writeString(packet.ip) 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/item/ItemModifierImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.item 11 | 12 | import org.lanternpowered.terre.impl.buildNumericCatalogTypeRegistryOf 13 | import org.lanternpowered.terre.item.ItemModifier 14 | 15 | internal class ItemModifierImpl( 16 | override val numericId: Int 17 | ) : ItemModifier { 18 | override fun toString(): String = "ItemModifier(numericId=$numericId)" 19 | } 20 | 21 | internal val ItemModifierRegistryImpl = 22 | buildNumericCatalogTypeRegistryOf(::ItemModifierImpl) 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/NettyThreadFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import org.lanternpowered.terre.impl.util.TerreThread 13 | import java.util.concurrent.ThreadFactory 14 | import java.util.concurrent.atomic.AtomicInteger 15 | 16 | internal class NettyThreadFactory(private val group: String) : ThreadFactory { 17 | 18 | private val counter = AtomicInteger() 19 | 20 | override fun newThread(r: Runnable): Thread = 21 | TerreThread(r, "netty-$group-${counter.incrementAndGet()}") 22 | } 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/InboundConnection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | import java.net.SocketAddress 13 | 14 | /** 15 | * Represents the inbound connection of a [Player] from the client to the proxy server. 16 | */ 17 | interface InboundConnection { 18 | 19 | /** 20 | * The remote address that was used to connect with the proxy server. 21 | */ 22 | val remoteAddress: SocketAddress 23 | 24 | /** 25 | * The protocol version used by the inbound connection. 26 | */ 27 | val protocolVersion: ProtocolVersion 28 | } 29 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/connection/PlayerPostLoginEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.connection 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | 15 | /** 16 | * An event that is thrown when a player has logged in successfully. This event is thrown after 17 | * [PlayerLoginEvent] if the result is not [PlayerLoginEvent.Result.Denied]. 18 | * 19 | * @property player The player that logged in 20 | */ 21 | data class PlayerPostLoginEvent( 22 | val player: Player 23 | ) : Event 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PasswordRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | 16 | internal object PasswordRequestPacket : Packet 17 | 18 | internal val PasswordRequestEncoder = PacketEncoder { _, _ -> } 19 | 20 | internal val PasswordRequestDecoder = PacketDecoder { PasswordRequestPacket } 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/tmodloader/SyncModsDonePacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.tmodloader 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | 16 | internal object SyncModsDonePacket : Packet 17 | 18 | internal val SyncModsDoneEncoder = PacketEncoder { _, _ -> } 19 | 20 | internal val SyncModsDoneDecoder = PacketDecoder { SyncModsDonePacket } 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/ItemText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.ItemTextImpl 13 | import org.lanternpowered.terre.item.ItemStack 14 | 15 | /** 16 | * Creates a new [ItemText] from the given stack. 17 | */ 18 | fun textOf(itemStack: ItemStack): ItemText = 19 | ItemTextImpl(itemStack) 20 | 21 | /** 22 | * A text component that represents an item. 23 | */ 24 | interface ItemText : Text { 25 | 26 | /** 27 | * The item of this text. 28 | */ 29 | val itemStack: ItemStack 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/buffer/LeftOrRight.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.buffer 11 | 12 | /** 13 | * Left or right. Usually used for left or right directions. 14 | * 15 | * @property isRight Whether it's right 16 | * @property isLeft Whether it's left 17 | */ 18 | @JvmInline 19 | internal value class LeftOrRight(val isRight: Boolean) { 20 | 21 | val isLeft: Boolean 22 | get() = !isRight 23 | 24 | companion object { 25 | 26 | val Right = LeftOrRight(true) 27 | 28 | val Left = LeftOrRight(false) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/CompleteConnectionPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | 16 | internal object CompleteConnectionPacket : Packet 17 | 18 | internal val CompleteConnectionEncoder = PacketEncoder { _, _ -> } 19 | 20 | internal val CompleteConnectionDecoder = PacketDecoder { CompleteConnectionPacket } 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/util/InetAddress.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.util 11 | 12 | import java.net.InetSocketAddress 13 | import java.net.URI 14 | 15 | internal fun parseInetAddress(address: String): InetSocketAddress { 16 | val uri = URI.create("tcp://$address") 17 | check(uri.port != -1) { "Port couldn't be parsed from: $address" } 18 | return InetSocketAddress.createUnresolved(uri.host, uri.port) 19 | } 20 | 21 | internal fun InetSocketAddress.resolve(): InetSocketAddress { 22 | return InetSocketAddress(this.hostName, this.port) 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/TaggedTextSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.TaggedTextSerializerImpl 13 | 14 | /** 15 | * Represents the [TextSerializer] who converts between tagged strings and text objects. 16 | * 17 | * Tagged strings are strings where the tags are used to define items, glyphs, achievements, 18 | * colors, etc. 19 | * 20 | * See [Terraria Chat Tags](https://terraria.gamepedia.com/Chat#Tags) 21 | */ 22 | object TaggedTextSerializer : TextSerializer by TaggedTextSerializerImpl 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/TaggedTextSerializerImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.text.Text 13 | import org.lanternpowered.terre.text.TextSerializer 14 | import org.lanternpowered.terre.text.text 15 | 16 | internal object TaggedTextSerializerImpl : TextSerializer { 17 | 18 | override fun serialize(text: Text): String = 19 | (text as TextImpl).toTaggedVanillaText().toPlain() 20 | 21 | override fun deserialize(string: String): Text = 22 | (string.text() as TextImpl).fromTaggedVanillaText() 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/CatalogTypeRegistry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | /** 13 | * Represents a registry for catalog types. 14 | */ 15 | interface CatalogTypeRegistry { 16 | 17 | /** 18 | * A collection with all the registered types. 19 | */ 20 | val all: Collection 21 | } 22 | 23 | /** 24 | * Represents a builder for catalog registries. 25 | */ 26 | interface CatalogTypeRegistryBuilder { 27 | 28 | /** 29 | * Registers a catalog type. 30 | */ 31 | fun register(catalogType: T) 32 | } 33 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/AchievementText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.AchievementTextImpl 13 | 14 | /** 15 | * Creates a new [AchievementText] from the given [Achievement]. 16 | */ 17 | fun textOf(achievement: Achievement): AchievementText = 18 | AchievementTextImpl(achievement) 19 | 20 | /** 21 | * Represents a achievement text component. 22 | */ 23 | interface AchievementText : Text { 24 | 25 | /** 26 | * The achievement of the text component. 27 | */ 28 | val achievement: Achievement 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/UnknownPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import io.netty.buffer.ByteBuf 13 | import org.lanternpowered.terre.util.toString 14 | 15 | /** 16 | * A packet mainly used for debugging purposes. 17 | */ 18 | internal class UnknownPacket( 19 | val opcode: Int, 20 | val data: ByteBuf 21 | ) : Packet, ForwardingReferenceCounted(data) { 22 | 23 | val length: Int 24 | get() = data.readableBytes() 25 | 26 | override fun toString() = toString { 27 | "opcode" to opcode 28 | "contentLength" to length 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/server/ServerRegisterEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.server 11 | 12 | import org.lanternpowered.terre.Server 13 | import org.lanternpowered.terre.event.Event 14 | import org.lanternpowered.terre.event.proxy.ProxyInitializeEvent 15 | 16 | /** 17 | * This event is thrown when a server got registered. This event is only thrown for servers that 18 | * got registered after the proxy was initialized. All other servers will already be available 19 | * when the [ProxyInitializeEvent] gets thrown. 20 | */ 21 | class ServerRegisterEvent(val server: Server) : Event 22 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/GlyphTextImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.text.Glyph 13 | import org.lanternpowered.terre.text.GlyphText 14 | import org.lanternpowered.terre.util.ToStringHelper 15 | 16 | internal data class GlyphTextImpl(override val glyph: Glyph) : TextImpl(), GlyphText { 17 | 18 | override val isEmpty: Boolean 19 | get() = false 20 | 21 | override fun toPlain(): String = "[Glyph: ${glyph.numericId}]" 22 | 23 | override fun toString() = ToStringHelper(GlyphText::class) 24 | .add("glyph", glyph) 25 | .toString() 26 | } 27 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/EssentialTilesRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.math.Vec2i 13 | import org.lanternpowered.terre.impl.network.Packet 14 | import org.lanternpowered.terre.impl.network.buffer.writeVec2i 15 | import org.lanternpowered.terre.impl.network.PacketEncoder 16 | 17 | internal data class EssentialTilesRequestPacket( 18 | val position: Vec2i 19 | ) : Packet 20 | 21 | internal val EssentialTilesRequestEncoder = PacketEncoder { buf, packet -> 22 | buf.writeVec2i(packet.position) 23 | } 24 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/Glyph.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.catalog.NumericCatalogType 13 | import org.lanternpowered.terre.catalog.NumericCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.text.GlyphRegistryImpl 15 | 16 | /** 17 | * Represents a glyph that can be displayed in chat. 18 | */ 19 | interface Glyph : NumericCatalogType, TextLike { 20 | 21 | override fun text(): GlyphText = textOf(this) 22 | } 23 | 24 | /** 25 | * A registry of all the [Glyph]s. 26 | */ 27 | object GlyphRegistry : NumericCatalogTypeRegistry by GlyphRegistryImpl 28 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/CombatTextAware.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.math.Vec2f 13 | 14 | interface CombatTextAware { 15 | 16 | /** 17 | * Shows combat [text] at the given [position]. Text [color] is only supported at the root 18 | * element. 19 | */ 20 | fun showCombatText(text: TextLike, position: Vec2f) = 21 | showCombatText(text.text(), position) 22 | 23 | /** 24 | * Shows combat [text] at the given [position]. Text [color] is only supported at the root 25 | * element. 26 | */ 27 | fun showCombatText(text: Text, position: Vec2f) 28 | } 29 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/MaxPlayers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | /** 13 | * Represents the number of players that are allowed to join the proxy. 14 | */ 15 | sealed interface MaxPlayers { 16 | 17 | /** 18 | * A limited number of players is allowed. 19 | * 20 | * This doesn't allow players to join if the backing servers have less space than the specified 21 | * [amount]. 22 | */ 23 | data class Limited(val amount: Int) : MaxPlayers 24 | 25 | /** 26 | * Players are allowed to join as long that there's space on one of the backing servers. 27 | */ 28 | object Unlimited : MaxPlayers 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/player/PlayerChangePvPEnabledEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.player 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | 15 | /** 16 | * An even that is thrown when a [Player] tries to enable or disable PvP. Can be 17 | * cancelled to prevent a player from switching. The backing server can still prevent the player 18 | * from switching even if this event is not cancelled. 19 | */ 20 | data class PlayerChangePvPEnabledEvent( 21 | val player: Player, 22 | val pvpEnabled: Boolean, 23 | var cancelled: Boolean = false, 24 | ) : Event 25 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/client/InitialInboundConnection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.client 11 | 12 | import org.lanternpowered.terre.InboundConnection 13 | import org.lanternpowered.terre.ProtocolVersion 14 | import org.lanternpowered.terre.util.ToStringHelper 15 | import java.net.SocketAddress 16 | 17 | internal class InitialInboundConnection( 18 | override val remoteAddress: SocketAddress, 19 | override val protocolVersion: ProtocolVersion 20 | ) : InboundConnection { 21 | 22 | override fun toString() = ToStringHelper() 23 | .add("remoteAddress", remoteAddress) 24 | .toString() 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/client/ClientInitProtocol.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.client 11 | 12 | import org.lanternpowered.terre.impl.network.PacketDirection 13 | import org.lanternpowered.terre.impl.network.protocol 14 | import org.lanternpowered.terre.impl.network.packet.ConnectionRequestDecoder 15 | import org.lanternpowered.terre.impl.network.packet.init.InitDisconnectClientEncoder 16 | 17 | internal val ClientInitProtocol = protocol("client-init") { 18 | bind(0x01, ConnectionRequestDecoder, PacketDirection.ClientToServer) 19 | bind(0x02, InitDisconnectClientEncoder, PacketDirection.ServerToClient) 20 | } 21 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/character/CharacterStorage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.character 11 | 12 | import org.lanternpowered.terre.item.Inventory 13 | import org.lanternpowered.terre.item.ItemStack 14 | 15 | interface CharacterStorage { 16 | 17 | /** 18 | * Loads all the inventory of the character. 19 | */ 20 | suspend fun loadInventory(inventory: Inventory) 21 | 22 | /** 23 | * Saves the inventory of the character. 24 | */ 25 | suspend fun saveInventory(inventory: Inventory) 26 | 27 | /** 28 | * Saves the inventory item at a specific [index]. 29 | */ 30 | suspend fun saveItem(index: Int, itemStack: ItemStack) 31 | } 32 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/player/PlayerChangeTeamEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.player 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.Team 14 | import org.lanternpowered.terre.event.Event 15 | 16 | /** 17 | * An even that is thrown when a [Player] tries to switch to the specified [Team]. Can be 18 | * cancelled to prevent a player from switching. The backing server can still prevent the player 19 | * from switching even if this event is not cancelled. 20 | */ 21 | data class PlayerChangeTeamEvent( 22 | val player: Player, 23 | val team: Team, 24 | var cancelled: Boolean = false, 25 | ) : Event 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/WorldInfoRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.util.toString 16 | 17 | internal object WorldInfoRequestPacket : Packet { 18 | 19 | override fun toString() = toString {} 20 | } 21 | 22 | internal val RequestWorldInfoDecoder = PacketDecoder { WorldInfoRequestPacket } 23 | 24 | internal val RequestWorldInfoEncoder = PacketEncoder { _, _ -> } 25 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/ConfigFormat.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import com.uchuhimo.konf.Config 13 | import com.uchuhimo.konf.source.Writer 14 | import com.uchuhimo.konf.source.Loader as Reader 15 | 16 | /** 17 | * Represents a configuration format. 18 | */ 19 | interface ConfigFormat { 20 | 21 | /** 22 | * The default extension name. 23 | */ 24 | val extension: String 25 | 26 | /** 27 | * Constructs a reader for the given [Config]. 28 | */ 29 | fun readerFor(config: Config): Reader 30 | 31 | /** 32 | * Constructs a writer for the given [Config]. 33 | */ 34 | fun writerFor(config: Config): Writer 35 | } 36 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/ProjectileIdAllocator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | import it.unimi.dsi.fastutil.ints.IntOpenHashSet 13 | import org.lanternpowered.terre.impl.network.buffer.ProjectileId 14 | 15 | internal class ProjectileIdAllocator { 16 | 17 | private val allocated = IntOpenHashSet() 18 | 19 | fun allocate(): ProjectileId { 20 | for (i in 1000 downTo 0) { 21 | if (allocated.contains(i)) 22 | continue 23 | allocated.add(i) 24 | return ProjectileId(i) 25 | } 26 | return ProjectileId.None 27 | } 28 | 29 | fun release(id: ProjectileId) { 30 | allocated.remove(id.value) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /proxy/src/test/kotlin/org/lanternpowered/terre/impl/math/Vec2iTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.math 11 | 12 | import org.junit.jupiter.api.Test 13 | import org.lanternpowered.terre.math.Vec2i 14 | import kotlin.test.assertEquals 15 | 16 | class Vec2iTest { 17 | 18 | @Test fun `test vec2i construction`() { 19 | val x = 15148 20 | val y = 91234 21 | val vec = Vec2i(x, y) 22 | assertEquals(x, vec.x) 23 | assertEquals(y, vec.y) 24 | } 25 | 26 | @Test fun `test vec2i construction with negative values`() { 27 | val x = 158914 28 | val y = -86534 29 | val vec = Vec2i(x, y) 30 | assertEquals(x, vec.x) 31 | assertEquals(y, vec.y) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/server/PlayerLeaveServerEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.server 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.Server 14 | import org.lanternpowered.terre.event.Event 15 | 16 | /** 17 | * An event that is thrown when a [Player] leaves the specific [Server]. When switching [Server]s, 18 | * this event is thrown before the new [PlayerJoinServerEvent]. 19 | * 20 | * @property player The player that is joining the server. 21 | * @property server The server the player is joining. 22 | */ 23 | data class PlayerLeaveServerEvent( 24 | val player: Player, 25 | val server: Server, 26 | ) : Event 27 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketDecoder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("FunctionName") 11 | 12 | package org.lanternpowered.terre.impl.network 13 | 14 | import io.netty.buffer.ByteBuf 15 | 16 | internal inline fun

PacketDecoder( 17 | crossinline fn: PacketCodecContext.(buf: ByteBuf) -> P? 18 | ): PacketDecoder

{ 19 | return object : PacketDecoder

{ 20 | override fun decode(ctx: PacketCodecContext, buf: ByteBuf): P? { 21 | return fn(ctx, buf) 22 | } 23 | } 24 | } 25 | 26 | internal interface PacketDecoder

{ 27 | 28 | /** 29 | * Decodes a packet from the [ByteBuf]. 30 | */ 31 | fun decode(ctx: PacketCodecContext, buf: ByteBuf): P? 32 | } 33 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/AchievementTextImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.text.Achievement 13 | import org.lanternpowered.terre.text.AchievementText 14 | import org.lanternpowered.terre.util.ToStringHelper 15 | 16 | internal data class AchievementTextImpl( 17 | override val achievement: Achievement 18 | ) : TextImpl(), AchievementText { 19 | 20 | override val isEmpty: Boolean 21 | get() = false 22 | 23 | override fun toPlain(): String = 24 | '[' + achievement.name + ']' 25 | 26 | override fun toString() = ToStringHelper(AchievementText::class) 27 | .add("achievement", achievement) 28 | .toString() 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/ItemTextImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.item.ItemStack 13 | import org.lanternpowered.terre.text.ItemText 14 | import org.lanternpowered.terre.util.ToStringHelper 15 | 16 | internal data class ItemTextImpl( 17 | override val itemStack: ItemStack 18 | ) : TextImpl(), ItemText { 19 | 20 | override val isEmpty: Boolean 21 | get() = this.itemStack.isEmpty 22 | 23 | override fun toPlain(): String = 24 | "[Item: Type=${itemStack.type.numericId} Modifier=${itemStack.modifier.numericId}]" 25 | 26 | override fun toString() = ToStringHelper(ItemText::class) 27 | .add("itemStack", itemStack) 28 | .toString() 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/backend/ServerInitConnectionResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.backend 11 | 12 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 13 | import org.lanternpowered.terre.text.Text 14 | 15 | /** 16 | * Represents the result of a [ServerInitConnectionHandler]. 17 | */ 18 | internal sealed class ServerInitConnectionResult { 19 | 20 | data class Success(val playerId: PlayerId) : ServerInitConnectionResult() 21 | 22 | data class Disconnected(val reason: Text?) : ServerInitConnectionResult() 23 | 24 | data class UnsupportedProtocol(val reason: Text?) : ServerInitConnectionResult() 25 | 26 | data class NotModded(val reason: Text?) : ServerInitConnectionResult() 27 | } 28 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/logger/LoggerImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.logger 11 | 12 | import org.apache.logging.log4j.spi.ExtendedLogger 13 | import org.apache.logging.log4j.Logger as Log4jLogger 14 | import org.lanternpowered.terre.logger.Logger 15 | 16 | internal class LoggerImpl(logger: Log4jLogger) : 17 | Logger, ExtendedLogger by (logger as ExtendedLogger) { 18 | 19 | override fun info(message: () -> String) { 20 | if (isInfoEnabled) 21 | info(message()) 22 | } 23 | 24 | override fun debug(message: () -> String) { 25 | if (isDebugEnabled) 26 | debug(message()) 27 | } 28 | 29 | override fun warn(message: () -> String) { 30 | if (isWarnEnabled) 31 | warn(message()) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/item/ItemModifier.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.item 11 | 12 | import org.lanternpowered.terre.catalog.NumericCatalogType 13 | import org.lanternpowered.terre.catalog.NumericCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.item.ItemModifierRegistryImpl 15 | 16 | /** 17 | * Represents a modifier of an item stack. 18 | */ 19 | interface ItemModifier : NumericCatalogType { 20 | 21 | companion object { 22 | 23 | /** 24 | * The default item modifier. 25 | */ 26 | val Default = ItemModifierRegistry.require(0) 27 | } 28 | } 29 | 30 | /** 31 | * A registry for all the [ItemModifier]s. 32 | */ 33 | object ItemModifierRegistry : NumericCatalogTypeRegistry by ItemModifierRegistryImpl 34 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/util/text/CharSequence.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.util.text 11 | 12 | /** 13 | * Returns the index within this string of the first occurrence of the specified character, starting 14 | * from the specified [startIndex] and ending at the specified [endIndex]. 15 | * 16 | * @param ignoreCase `true` to ignore character case when matching a character. By default, `false`. 17 | * @return An index of the first occurrence of [char] or -1 if none is found. 18 | */ 19 | fun CharSequence.indexOf( 20 | char: Char, startIndex: Int = 0, endIndex: Int = length, ignoreCase: Boolean = false 21 | ): Int { 22 | val index = indexOf(char, startIndex, ignoreCase) 23 | if (index >= endIndex) 24 | return -1 25 | return index 26 | } 27 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/server/PlayerJoinServerEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.server 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.Server 14 | import org.lanternpowered.terre.event.Event 15 | import java.util.UUID 16 | 17 | /** 18 | * An event that is thrown when a [Player] joins or switches to a specific [Server]. 19 | * 20 | * @property player The player that is joining the server. 21 | * @property server The server the player is joining. 22 | * @property clientUniqueId The unique id that server will know the [player] as. 23 | */ 24 | data class PlayerJoinServerEvent( 25 | val player: Player, 26 | val server: Server, 27 | var clientUniqueId: UUID = player.clientUniqueId, 28 | ) : Event 29 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/pipeline/FrameEncoder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.pipeline 11 | 12 | import io.netty.buffer.ByteBuf 13 | import io.netty.channel.ChannelHandlerContext 14 | import io.netty.handler.codec.MessageToMessageEncoder 15 | 16 | internal class FrameEncoder : MessageToMessageEncoder() { 17 | 18 | override fun encode(ctx: ChannelHandlerContext, input: ByteBuf, output: MutableList) { 19 | // Allocate buffer just for the packet length 20 | val lengthBuf = ctx.alloc().buffer(Short.SIZE_BYTES) 21 | // Content length + length header 22 | lengthBuf.writeShortLE(input.readableBytes() + Short.SIZE_BYTES) 23 | 24 | output.add(lengthBuf) 25 | output.add(input.retain()) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/ConfigFormats.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import com.uchuhimo.konf.Config 13 | import com.uchuhimo.konf.source.json.toJson 14 | import com.uchuhimo.konf.source.yaml 15 | import com.uchuhimo.konf.source.yaml.toYaml 16 | 17 | object ConfigFormats { 18 | 19 | val Json = object : ConfigFormat { 20 | override val extension get() = "json" 21 | override fun readerFor(config: Config) = config.from.json 22 | override fun writerFor(config: Config) = config.toJson 23 | } 24 | 25 | val Yaml = object : ConfigFormat { 26 | override val extension get() = "yaml" 27 | override fun readerFor(config: Config) = config.from.yaml 28 | override fun writerFor(config: Config) = config.toYaml 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/ConfigDirectory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import com.uchuhimo.konf.Config 13 | 14 | /** 15 | * Represents a configuration directory. 16 | */ 17 | interface ConfigDirectory : ConfigDirectoryBase { 18 | 19 | /** 20 | * Initializes a new config with the default name. 21 | * 22 | * @param format The format used to write and read the file 23 | * @param extension The extension of the file, defaults to the extension of the config format 24 | * @param initializer Function to initialize the config 25 | */ 26 | fun config( 27 | format: ConfigFormat = ConfigFormats.Yaml, 28 | extension: String = format.extension, 29 | initializer: Config.() -> Unit 30 | ) = config("config", format, extension, initializer) 31 | } 32 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/coroutines/Coroutines.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.coroutines 11 | 12 | import kotlinx.coroutines.CoroutineScope 13 | import kotlinx.coroutines.TimeoutCancellationException 14 | import kotlinx.coroutines.withTimeout 15 | import kotlin.time.Duration 16 | 17 | internal suspend fun tryWithTimeout( 18 | timeMillis: Long, block: suspend CoroutineScope.() -> T 19 | ): Result { 20 | return try { 21 | Result.success(withTimeout(timeMillis, block)) 22 | } catch (ex: TimeoutCancellationException) { 23 | Result.failure(ex) 24 | } 25 | } 26 | 27 | internal suspend fun tryWithTimeout( 28 | duration: Duration, block: suspend CoroutineScope.() -> T 29 | ): Result { 30 | return tryWithTimeout(duration.inWholeMilliseconds, block) 31 | } 32 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/MessageReceiverImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.impl.player.PlayerImpl 13 | import org.lanternpowered.terre.text.MessageReceiver 14 | import org.lanternpowered.terre.text.MessageSender 15 | import org.lanternpowered.terre.text.Text 16 | import org.lanternpowered.terre.text.color 17 | import org.lanternpowered.terre.text.text 18 | 19 | interface MessageReceiverImpl : MessageReceiver { 20 | 21 | override fun sendMessageAs(message: Text, sender: MessageSender) { 22 | if (sender !is PlayerImpl) { 23 | sendMessage(message) 24 | return 25 | } 26 | val color = sender.team.color 27 | val name = sender.name 28 | sendMessage(("<$name> ".text() + message).color(color)) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/ForwardingReferenceCounted.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import io.netty.util.ReferenceCounted 13 | 14 | internal abstract class ForwardingReferenceCounted( 15 | private val referenceCounted: ReferenceCounted 16 | ) : ReferenceCounted { 17 | 18 | override fun refCnt() = referenceCounted.refCnt() 19 | override fun release() = referenceCounted.release() 20 | override fun release(decrement: Int) = referenceCounted.release(decrement) 21 | override fun retain() = apply { referenceCounted.retain() } 22 | override fun retain(increment: Int) = apply { referenceCounted.retain(increment) } 23 | override fun touch() = apply { referenceCounted.touch() } 24 | override fun touch(hint: Any?) = apply { referenceCounted.touch(hint) } 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/DisconnectPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.readPlainText 14 | import org.lanternpowered.terre.impl.network.buffer.writePlainText 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | import org.lanternpowered.terre.text.Text 18 | 19 | internal data class DisconnectPacket(val reason: Text) : Packet 20 | 21 | internal val DisconnectEncoder = PacketEncoder { buf, packet -> 22 | buf.writePlainText(packet.reason) 23 | } 24 | 25 | internal val DisconnectDecoder = PacketDecoder { buf -> DisconnectPacket(buf.readPlainText()) } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/v238/ConnectionApproved238.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.v238 11 | 12 | import org.lanternpowered.terre.impl.network.PacketDecoder 13 | import org.lanternpowered.terre.impl.network.PacketEncoder 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.packet.ConnectionApprovedPacket 17 | 18 | internal val ConnectionApproved238Encoder = PacketEncoder { buf, packet -> 19 | buf.writePlayerId(packet.playerId) 20 | } 21 | 22 | internal val ConnectionApproved238Decoder = PacketDecoder { buf -> 23 | val playerId = buf.readPlayerId() 24 | ConnectionApprovedPacket(playerId) 25 | } 26 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/plugin/PluginManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.plugin 11 | 12 | import org.lanternpowered.terre.impl.ProxyImpl 13 | 14 | /** 15 | * The plugin manager. 16 | */ 17 | interface PluginManager { 18 | 19 | /** 20 | * A list with all the registered [PluginContainer]s. 21 | */ 22 | val all: List 23 | 24 | /** 25 | * Attempts to get a [PluginContainer] for the given id. 26 | */ 27 | operator fun get(id: String): PluginContainer? 28 | 29 | /** 30 | * Attempts to get a [PluginContainer] for the given instance. 31 | */ 32 | fun getByInstance(instance: Any): PluginContainer? 33 | 34 | /** 35 | * The singleton instance of the [PluginManager]. 36 | */ 37 | companion object : PluginManager by ProxyImpl.pluginManager 38 | } 39 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ConnectionRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.impl.network.buffer.readString 16 | import org.lanternpowered.terre.impl.network.buffer.writeString 17 | 18 | internal data class ConnectionRequestPacket(val version: String) : Packet 19 | 20 | 21 | internal val ConnectionRequestDecoder = PacketDecoder { buf -> 22 | ConnectionRequestPacket(buf.readString()) 23 | } 24 | 25 | internal val ConnectionRequestEncoder = PacketEncoder { buf, packet -> 26 | buf.writeString(packet.version) 27 | } 28 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PasswordResponsePacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.readString 14 | import org.lanternpowered.terre.impl.network.buffer.writeString 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | 18 | internal data class PasswordResponsePacket(val password: String) : Packet 19 | 20 | internal val PasswordResponseEncoder = PacketEncoder { buf, packet -> 21 | buf.writeString(packet.password) 22 | } 23 | 24 | internal val PasswordResponseDecoder = PacketDecoder { buf -> 25 | PasswordResponsePacket(buf.readString()) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tshock-users/src/test/kotlin/org/lanternpowered/terre/tshock/group/TShockMessagesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock.group 11 | 12 | import org.lanternpowered.terre.tshock.TShockMessages 13 | import kotlin.test.Test 14 | import kotlin.test.assertEquals 15 | import kotlin.test.assertNull 16 | 17 | class TShockMessagesTest { 18 | 19 | @Test 20 | fun authenticatedMessage() { 21 | val user = "User" 22 | var extracted = TShockMessages.findAuthenticatedUser("Authenticated as $user successfully.") 23 | assertEquals(user, extracted) 24 | extracted = TShockMessages.findAuthenticatedUser("El jugador $user ya está conectado.") 25 | assertEquals(user, extracted) 26 | extracted = TShockMessages.findAuthenticatedUser("Authenticated as $user successfully. More.") 27 | assertNull(extracted) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/ServerCollection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | /** 13 | * Represents a collection of [Server] instances. 14 | */ 15 | interface ServerCollection : Collection { 16 | 17 | /** 18 | * Attempts to get a [Server] from the given [name]. Retrieving by name is case-insensitive. 19 | */ 20 | operator fun get(name: String): Server? 21 | 22 | /** 23 | * Attempts to register a new [Server] with the given [ServerInfo]. If a server with the same 24 | * name is already registered (case-insensitive), this will result in an 25 | * [IllegalArgumentException]. 26 | * 27 | * If a [ProtocolVersion] is provided, and it is not supported by the proxy, an 28 | * [IllegalArgumentException] is expected. 29 | */ 30 | fun register(serverInfo: ServerInfo): Server 31 | } 32 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/ColorableText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("UNCHECKED_CAST") 11 | 12 | package org.lanternpowered.terre.text 13 | 14 | import org.lanternpowered.terre.util.Color 15 | 16 | /** 17 | * Gets a copy of this text object but with the given color, if coloring is supported. 18 | */ 19 | fun T.color(color: Color?): T = 20 | if (this is ColorableText) color(color) as T else this 21 | 22 | /** 23 | * Represents a text component that can be colored. Doesn't work within localized components. 24 | */ 25 | interface ColorableText : Text { 26 | 27 | /** 28 | * The color of the text. If null, it will inherit the color of the parent. 29 | */ 30 | val color: Color? 31 | 32 | /** 33 | * Gets a copy of this text object but with the given color. 34 | */ 35 | fun color(color: Color?): ColorableText 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/command/CommandExecutor.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.command 11 | 12 | fun interface RawCommandExecutor { 13 | 14 | /** 15 | * Executes the raw command. 16 | * 17 | * @param source The source which triggered the command 18 | * @param alias The alias of the command that was executed 19 | * @param args The arguments of the command 20 | */ 21 | suspend fun execute(source: CommandSource, alias: String, args: String) 22 | } 23 | 24 | fun interface SimpleCommandExecutor { 25 | 26 | /** 27 | * Executes the raw command. 28 | * 29 | * @param source The source which triggered the command 30 | * @param alias The alias of the command that was executed 31 | * @param args The arguments of the command 32 | */ 33 | suspend fun execute(source: CommandSource, alias: String, args: List) 34 | } 35 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/permission/InitPermissionSubjectEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.permission 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | import org.lanternpowered.terre.event.connection.PlayerPreLoginEvent 15 | import org.lanternpowered.terre.permission.PermissionSubject 16 | 17 | /** 18 | * An event that is thrown when setting up the permission function of a specific [subject]. 19 | * 20 | * For [Player]s, this event is thrown before [PlayerPreLoginEvent]. 21 | * 22 | * @property subject The subject that is being setup. 23 | * @property permissionChecker A function that checks permissions. 24 | */ 25 | data class InitPermissionSubjectEvent( 26 | val subject: PermissionSubject, 27 | var permissionChecker: (permission: String) -> Boolean = { true }, 28 | ) : Event 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build # 2 | ######### 3 | MANIFEST.MF 4 | dependency-reduced-pom.xml 5 | .checkstyle 6 | 7 | # Compiled # 8 | ############ 9 | classes 10 | bin 11 | build 12 | dist 13 | lib 14 | out 15 | target 16 | *.com 17 | *.class 18 | *.dll 19 | *.exe 20 | *.o 21 | *.so 22 | 23 | # Databases # 24 | ############# 25 | *.db 26 | *.sql 27 | *.sqlite 28 | 29 | # Packages # 30 | ############ 31 | *.7z 32 | *.dmg 33 | *.gz 34 | *.iso 35 | *.rar 36 | *.tar 37 | *.zip 38 | 39 | # Repository # 40 | ############## 41 | .git 42 | 43 | # Logging # 44 | ########### 45 | /logs 46 | *.log 47 | 48 | # Misc # 49 | ######## 50 | *.bak 51 | 52 | # System # 53 | ########## 54 | .DS_Store 55 | ehthumbs.db 56 | Thumbs.db 57 | 58 | # Project # 59 | ########### 60 | .classpath 61 | .externalToolBuilders 62 | .gradle 63 | .nb-gradle 64 | .idea/* 65 | !.idea/runConfigurations/ 66 | !.idea/runConfigurations/* 67 | .project 68 | .settings 69 | nbproject 70 | atlassian-ide-plugin.xml 71 | build.xml 72 | nb-configuration.xml 73 | *.iml 74 | *.ipr 75 | *.iws 76 | 77 | # Other Files # 78 | ############### 79 | !/test/ 80 | /test/run/ 81 | !/test/run/.gitkeep 82 | !.gitkeep 83 | config.yaml 84 | *.launch 85 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/tracking/TrackedPlayers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.tracking 11 | 12 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 13 | 14 | internal class TrackedPlayers : Iterable { 15 | 16 | private val players = Array(capacity) { TrackedPlayer(PlayerId(it)) } 17 | 18 | operator fun get(id: PlayerId) = players[id.value] 19 | 20 | override fun iterator(): Iterator = players.iterator() 21 | 22 | fun reset() { 23 | players.forEach(TrackedPlayer::reset) 24 | } 25 | 26 | companion object { 27 | 28 | private const val capacity = 255 29 | } 30 | } 31 | 32 | internal class TrackedPlayer( 33 | val id: PlayerId 34 | ) { 35 | var name: String? = null 36 | var active = false 37 | 38 | fun reset() { 39 | name = null 40 | active = false 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /proxy/src/test/kotlin/org/lanternpowered/terre/impl/util/VersionTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.util 11 | 12 | import org.junit.jupiter.api.Test 13 | import org.lanternpowered.terre.util.Version 14 | import kotlin.test.assertEquals 15 | 16 | class VersionTest { 17 | 18 | @Test fun `test-version-equality`() { 19 | val a = Version(0, 10, 5, 3) 20 | val b = Version(0, 10, 5, 3) 21 | 22 | assertEquals(a, b) 23 | assertEquals(0, a.compareTo(b)) 24 | } 25 | 26 | @Test fun `test-version-comparison`() { 27 | val a = Version(0, 10, 5, 3) 28 | val b = Version(0, 11, 5, 3) 29 | val c = Version(0, 11, 5, 7) 30 | 31 | assert(a < b) 32 | assert(c > b) 33 | } 34 | 35 | @Test fun `test-version-comparison-unequal-length`() { 36 | val a = Version(0, 11, 5, 3) 37 | val b = Version(0, 11, 5, 3, 10) 38 | 39 | assert(b > a) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/NebulaLevelUpRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.math.Vec2f 13 | import org.lanternpowered.terre.impl.network.Packet 14 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.writeVec2f 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | 19 | internal data class NebulaLevelUpRequestPacket( 20 | val playerId: PlayerId, 21 | val type: Int, 22 | val origin: Vec2f 23 | ) : Packet 24 | 25 | internal val NebulaLevelUpRequestEncoder = PacketEncoder { buf, packet -> 26 | buf.writePlayerId(packet.playerId) 27 | buf.writeByte(packet.type) 28 | buf.writeVec2f(packet.origin) 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/tmodloader/ModDataPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.tmodloader 11 | 12 | import io.netty.buffer.ByteBuf 13 | import org.lanternpowered.terre.impl.network.ForwardingReferenceCounted 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | 18 | internal data class ModDataPacket(val data: ByteBuf) : Packet, ForwardingReferenceCounted(data) 19 | 20 | internal val ModDataEncoder = PacketEncoder { buf, packet -> 21 | val data = packet.data 22 | buf.writeBytes(data, data.readerIndex(), data.readableBytes()) 23 | } 24 | 25 | internal val ModDataDecoder = PacketDecoder { buf -> 26 | val data = buf.readBytes(buf.readableBytes()) 27 | ModDataPacket(data) 28 | } 29 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/item/ItemType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.item 11 | 12 | import org.lanternpowered.terre.catalog.NumericCatalogType 13 | import org.lanternpowered.terre.catalog.NumericCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.item.ItemTypeRegistryImpl 15 | import org.lanternpowered.terre.text.ItemText 16 | import org.lanternpowered.terre.text.TextLike 17 | 18 | /** 19 | * Represents the type of item. 20 | */ 21 | interface ItemType : NumericCatalogType, TextLike { 22 | 23 | override fun text(): ItemText = ItemStack(this).text() 24 | 25 | companion object { 26 | 27 | /** 28 | * Represents an empty item. 29 | */ 30 | val None: ItemType = ItemTypeRegistryImpl.require(0) 31 | } 32 | } 33 | 34 | /** 35 | * A registry for all the [ItemType]s. 36 | */ 37 | object ItemTypeRegistry : NumericCatalogTypeRegistry by ItemTypeRegistryImpl 38 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) LanternPowered 4 | Copyright (c) contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/tmodloader/ModFileRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.tmodloader 11 | 12 | import io.netty.buffer.ByteBuf 13 | import org.lanternpowered.terre.impl.network.ForwardingReferenceCounted 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | 18 | internal data class ModFileRequestPacket(val data: ByteBuf) : 19 | Packet, ForwardingReferenceCounted(data) 20 | 21 | internal val ModFileRequestEncoder = PacketEncoder { buf, packet -> 22 | val data = packet.data 23 | buf.writeBytes(data, data.readerIndex(), data.readableBytes()) 24 | } 25 | 26 | internal val ModFileRequestDecoder = PacketDecoder { buf -> 27 | val data = buf.readBytes(buf.readableBytes()) 28 | ModFileRequestPacket(data) 29 | } 30 | -------------------------------------------------------------------------------- /image/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | kotlin("plugin.serialization") 4 | id("com.google.cloud.tools.jib") version "3.4.0" 5 | } 6 | 7 | dependencies { 8 | api(project(":terre-proxy")) 9 | api(project(":terre-portals")) 10 | api(project(":terre-k8s-server-finder")) 11 | } 12 | 13 | jib { 14 | val dockerUsername: String? by project 15 | val dockerPassword: String? by project 16 | from { 17 | image = "azul/zulu-openjdk-alpine:17-jre" 18 | if (!dockerUsername.isNullOrBlank() && !dockerPassword.isNullOrBlank()) { 19 | platforms { 20 | listOf("amd64", "arm64").forEach { arch -> 21 | platform { 22 | os = "linux" 23 | architecture = arch 24 | } 25 | } 26 | } 27 | } 28 | } 29 | to { 30 | image = "cybermaxke/terre" 31 | tags = setOf("latest") 32 | if (!dockerUsername.isNullOrBlank() && !dockerPassword.isNullOrBlank()) { 33 | auth { 34 | username = dockerUsername 35 | password = dockerPassword 36 | } 37 | } 38 | } 39 | container { 40 | mainClass = "org.lanternpowered.terre.impl.TerreMainKt" 41 | ports = listOf("7777") 42 | creationTime.set("USE_CURRENT_TIMESTAMP") 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/tracking/TrackedNpcs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.tracking 11 | 12 | import org.lanternpowered.terre.impl.network.buffer.NpcId 13 | import org.lanternpowered.terre.impl.network.buffer.NpcType 14 | 15 | internal class TrackedNpcs : Iterable { 16 | 17 | private val npcs = Array(capacity) { TrackedNpc(NpcId(it)) } 18 | 19 | operator fun get(id: NpcId) = npcs[id.value] 20 | 21 | override fun iterator(): Iterator = npcs.iterator() 22 | 23 | fun reset() { 24 | npcs.forEach(TrackedNpc::reset) 25 | } 26 | 27 | companion object { 28 | 29 | private const val capacity = 201 30 | } 31 | } 32 | 33 | internal class TrackedNpc( 34 | val id: NpcId 35 | ) { 36 | var type = NpcType(0) 37 | var life: Int = 0 38 | 39 | val active: Boolean 40 | get() = life > 0 41 | 42 | fun reset() { 43 | type = NpcType(0) 44 | life = 0 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerCommandPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.readString 14 | import org.lanternpowered.terre.impl.network.buffer.writeString 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | 18 | internal data class PlayerCommandPacket( 19 | val commandId: String, 20 | val arguments: String 21 | ) : Packet 22 | 23 | internal val PlayerCommandEncoder = PacketEncoder { buf, packet -> 24 | buf.writeString(packet.commandId) 25 | buf.writeString(packet.arguments) 26 | } 27 | 28 | internal val PlayerCommandDecoder = PacketDecoder { buf -> 29 | val commandId = buf.readString() 30 | val arguments = buf.readString() 31 | PlayerCommandPacket(commandId, arguments) 32 | } 33 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/ConfigDirectoryBase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import com.uchuhimo.konf.Config 13 | import java.nio.file.Path 14 | 15 | /** 16 | * Represents a configuration directory. 17 | */ 18 | interface ConfigDirectoryBase { 19 | 20 | /** 21 | * The root path of the configuration directory. 22 | */ 23 | val path: Path 24 | 25 | /** 26 | * Initializes a new config. 27 | * 28 | * @param name The name of the configuration file, without the extension 29 | * @param format The format used to write and read the file 30 | * @param extension The extension of the file, defaults to the extension of the config format 31 | * @param initializer Function to initialize the config 32 | */ 33 | fun config( 34 | name: String, 35 | format: ConfigFormat = ConfigFormats.Yaml, 36 | extension: String = format.extension, 37 | initializer: Config.() -> Unit 38 | ): ReloadableConfig 39 | } 40 | -------------------------------------------------------------------------------- /proxy/src/main/resources/log4j2_prod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/TileInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | import com.google.gson.Gson 13 | import com.google.gson.JsonArray 14 | import com.google.gson.stream.JsonReader 15 | import it.unimi.dsi.fastutil.ints.IntOpenHashSet 16 | import it.unimi.dsi.fastutil.ints.IntSet 17 | import java.io.InputStreamReader 18 | 19 | internal object TileInfo { 20 | 21 | private val frameImportant: IntSet 22 | 23 | init { 24 | val input = TileInfo::class.java 25 | .getResourceAsStream("/data/tile_frame_important.json") 26 | ?: error("Failed to find tile frame important data.") 27 | val reader = JsonReader(InputStreamReader(input)) 28 | reader.use { 29 | frameImportant = Gson().fromJson(reader, JsonArray::class.java) 30 | .map { element -> element.asInt } 31 | .toCollection(IntOpenHashSet()) 32 | } 33 | } 34 | 35 | fun isFrameImportantFor(tileId: Int): Boolean = 36 | frameImportant.contains(tileId) 37 | } 38 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerPvPPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 17 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 18 | 19 | internal data class PlayerPvPPacket( 20 | val playerId: PlayerId, 21 | val enabled: Boolean, 22 | ) : Packet 23 | 24 | internal val PlayerPvPEncoder = PacketEncoder { buf, packet -> 25 | buf.writePlayerId(packet.playerId) 26 | buf.writeBoolean(packet.enabled) 27 | } 28 | 29 | internal val PlayerPvPDecoder = PacketDecoder { buf -> 30 | val playerId = buf.readPlayerId() 31 | val enabled = buf.readBoolean() 32 | PlayerPvPPacket(playerId, enabled) 33 | } 34 | -------------------------------------------------------------------------------- /proxy/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerActivePacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.PacketDecoder 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | 19 | internal data class PlayerActivePacket( 20 | val playerId: PlayerId, 21 | val active: Boolean 22 | ) : Packet 23 | 24 | internal val PlayerActiveEncoder = PacketEncoder { buf, packet -> 25 | buf.writePlayerId(packet.playerId) 26 | buf.writeBoolean(packet.active) 27 | } 28 | 29 | internal val PlayerActiveDecoder = PacketDecoder { buf -> 30 | val playerId = buf.readPlayerId() 31 | val active = buf.readBoolean() 32 | PlayerActivePacket(playerId, active) 33 | } 34 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/chat/ServerChatEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.chat 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.Server 14 | import org.lanternpowered.terre.event.Event 15 | import org.lanternpowered.terre.text.MessageSender 16 | import org.lanternpowered.terre.text.Text 17 | 18 | /** 19 | * An event that is thrown when the server sends a chat message to the [Player]. 20 | * 21 | * @property player The player that is receiving the chat message. 22 | * @property server The server that is sending the chat message. 23 | * @property message The chat message. 24 | * @property sender The sender the chat message is being sent as. 25 | * @property cancelled If the event is cancelled, this will prevent the message from being sent. 26 | */ 27 | data class ServerChatEvent( 28 | val player: Player, 29 | val server: Server, 30 | val message: Text, 31 | val sender: MessageSender? = null, 32 | var cancelled: Boolean = false, 33 | ) : Event 34 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/item/InventoryImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.item 11 | 12 | import org.lanternpowered.terre.item.Inventory 13 | import org.lanternpowered.terre.item.ItemStack 14 | import java.util.concurrent.ConcurrentHashMap 15 | import kotlin.math.max 16 | 17 | internal class InventoryImpl : Inventory { 18 | 19 | private val items = ConcurrentHashMap() 20 | 21 | var maxSize: Int = 0 22 | 23 | override fun clear() { 24 | items.clear() 25 | } 26 | 27 | override fun get(index: Int): ItemStack = items.getOrElse(index) { ItemStack.Empty } 28 | 29 | override fun set(index: Int, itemStack: ItemStack) { 30 | if (itemStack.isEmpty) { 31 | items.remove(index) 32 | } else { 33 | items[index] = itemStack 34 | maxSize = max(maxSize, index + 1) 35 | } 36 | } 37 | 38 | override fun iterator(): Iterator> = 39 | items.asSequence().map { (index, value) -> IndexedValue(index, value) }.iterator() 40 | } 41 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/tracking/TrackedProjectiles.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.tracking 11 | 12 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 13 | import org.lanternpowered.terre.impl.network.buffer.ProjectileId 14 | 15 | internal class TrackedProjectiles : Iterable { 16 | 17 | private val projectiles = Array(capacity) { TrackedProjectile(ProjectileId(it)) } 18 | 19 | operator fun get(id: ProjectileId) = projectiles[id.value] 20 | 21 | override fun iterator(): Iterator = projectiles.iterator() 22 | 23 | fun reset() { 24 | projectiles.forEach(TrackedProjectile::reset) 25 | } 26 | 27 | companion object { 28 | 29 | private const val capacity = 1001 30 | } 31 | } 32 | 33 | internal class TrackedProjectile( 34 | val id: ProjectileId 35 | ) { 36 | var owner = PlayerId.None 37 | var active = false 38 | 39 | fun reset() { 40 | owner = PlayerId.None 41 | active = false 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/user/User.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock.user 11 | 12 | import java.security.MessageDigest 13 | import java.time.LocalDateTime 14 | import java.util.UUID 15 | 16 | data class User( 17 | val id: Int, 18 | val name: String, 19 | val password: String, 20 | val clientIdentifier: String, 21 | val group: String, 22 | val registered: LocalDateTime, 23 | val lastAccessed: LocalDateTime, 24 | val knownIPs: String, 25 | ) { 26 | 27 | companion object { 28 | 29 | /** 30 | * Generates a user identifier from the given [clientUniqueId]. 31 | */ 32 | fun generateIdentifier(clientUniqueId: UUID): String { 33 | val digest = MessageDigest.getInstance("SHA-512") 34 | digest.reset() 35 | digest.update(clientUniqueId.toString().toByteArray(Charsets.UTF_8)) 36 | return digest.digest().joinToString(separator = "") { 37 | it.toUByte().toString(radix = 16).padStart(2, '0').uppercase() 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/NpcInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | import com.google.gson.Gson 13 | import com.google.gson.JsonArray 14 | import com.google.gson.stream.JsonReader 15 | import it.unimi.dsi.fastutil.ints.IntOpenHashSet 16 | import it.unimi.dsi.fastutil.ints.IntSet 17 | import org.lanternpowered.terre.impl.network.buffer.NpcType 18 | import java.io.InputStreamReader 19 | 20 | internal object NpcInfo { 21 | 22 | private val catchable: IntSet 23 | 24 | init { 25 | val input = NpcInfo::class.java 26 | .getResourceAsStream("/data/npc_catchable.json") 27 | ?: error("Failed to find catchable npc data.") 28 | val reader = JsonReader(InputStreamReader(input)) 29 | reader.use { 30 | catchable = Gson().fromJson(reader, JsonArray::class.java) 31 | .map { element -> element.asInt } 32 | .toCollection(IntOpenHashSet()) 33 | } 34 | } 35 | 36 | fun isCatchable(npcType: NpcType): Boolean = 37 | catchable.contains(npcType.value) 38 | } 39 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/tracking/TrackedItems.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.tracking 11 | 12 | import org.lanternpowered.terre.impl.network.buffer.ItemId 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.item.ItemStack 15 | 16 | internal class TrackedItems : Iterable { 17 | 18 | private val items = Array(capacity) { TrackedItem(ItemId(it)) } 19 | 20 | operator fun get(id: ItemId) = items[id.value] 21 | 22 | override fun iterator(): Iterator = items.iterator() 23 | 24 | fun reset() { 25 | items.forEach(TrackedItem::reset) 26 | } 27 | 28 | companion object { 29 | 30 | private const val capacity = 401 31 | } 32 | } 33 | 34 | internal class TrackedItem( 35 | val id: ItemId 36 | ) { 37 | var itemStack = ItemStack.Empty 38 | var owner = PlayerId.None 39 | 40 | val active: Boolean 41 | get() = !itemStack.isEmpty 42 | 43 | fun reset() { 44 | itemStack = ItemStack.Empty 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ClientUniqueIdPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import io.netty.handler.codec.DecoderException 13 | import org.lanternpowered.terre.impl.network.Packet 14 | import org.lanternpowered.terre.impl.network.buffer.readString 15 | import org.lanternpowered.terre.impl.network.buffer.writeString 16 | import org.lanternpowered.terre.impl.network.PacketDecoder 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | import java.util.* 19 | 20 | internal data class ClientUniqueIdPacket( 21 | val uniqueId: UUID 22 | ) : Packet 23 | 24 | internal val ClientUniqueIdDecoder = PacketDecoder { buf -> 25 | val uniqueId = try { 26 | UUID.fromString(buf.readString()) 27 | } catch (ex: IllegalArgumentException) { 28 | throw DecoderException(ex) 29 | } 30 | ClientUniqueIdPacket(uniqueId) 31 | } 32 | 33 | internal val ClientUniqueIdEncoder = PacketEncoder { buf, packet -> 34 | buf.writeString(packet.uniqueId.toString()) 35 | } 36 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/util/LazyReadOnlyProperty.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("UNCHECKED_CAST") 11 | 12 | package org.lanternpowered.terre.impl.util 13 | 14 | import kotlin.properties.ReadOnlyProperty 15 | import kotlin.reflect.KProperty 16 | 17 | @PublishedApi 18 | internal class LazyReadOnlyProperty(initializer: R.() -> T) : ReadOnlyProperty { 19 | 20 | private object Uninitialized 21 | 22 | private val lock = Any() 23 | private var initializer: (R.() -> T)? = initializer 24 | @Volatile private var value: Any? = Uninitialized 25 | 26 | override fun getValue(thisRef: R, property: KProperty<*>): T { 27 | var cached = this.value 28 | if (cached !== Uninitialized) { 29 | return cached as T 30 | } 31 | synchronized(this.lock) { 32 | cached = this.value 33 | if (cached !== Uninitialized) { 34 | return cached as T 35 | } 36 | cached = this.initializer!!(thisRef) 37 | this.initializer = null 38 | this.value = cached 39 | return cached as T 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/TShockPlayer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock 11 | 12 | import kotlinx.coroutines.CompletableDeferred 13 | import org.lanternpowered.terre.tshock.group.Group 14 | import org.lanternpowered.terre.tshock.group.Groups 15 | import org.lanternpowered.terre.tshock.user.User 16 | import java.util.UUID 17 | 18 | class TShockPlayer( 19 | var clientUniqueId: UUID, 20 | ) { 21 | 22 | val clientIdentifier = User.generateIdentifier(clientUniqueId) 23 | var name: String = "" 24 | var loggedIn: Boolean = false 25 | var blockLoggedOutSSCEnabledMessage = false 26 | var groupName: String? = null 27 | var logoutDone: CompletableDeferred? = null 28 | 29 | val group: Group? 30 | get() { 31 | val groupName = groupName 32 | return if (groupName != null) Groups[groupName] else null 33 | } 34 | 35 | fun hasPermission(permission: String): Boolean { 36 | val group = group 37 | if (group != null) 38 | return group.hasPermission(permission) 39 | return false 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/coroutines/Coroutines.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.coroutines 11 | 12 | import kotlinx.coroutines.CoroutineDispatcher 13 | import kotlinx.coroutines.CoroutineScope 14 | import kotlinx.coroutines.withTimeout 15 | import org.lanternpowered.terre.dispatcher.dispatch 16 | import kotlin.coroutines.resume 17 | import kotlin.coroutines.suspendCoroutine 18 | import kotlin.time.Duration 19 | 20 | suspend inline fun withTimeout( 21 | timeMillis: Long, 22 | noinline block: suspend CoroutineScope.() -> T 23 | ): T { 24 | return withTimeout(timeMillis, block) 25 | } 26 | 27 | suspend fun withTimeout(duration: Duration, block: suspend CoroutineScope.() -> T): T { 28 | return withTimeout(duration.inWholeMilliseconds, block) 29 | } 30 | 31 | /** 32 | * Continues the current coroutine with the given coroutine dispatcher. 33 | */ 34 | suspend fun continueWith(dispatcher: CoroutineDispatcher) { 35 | suspendCoroutine { continuation -> 36 | dispatcher.dispatch { 37 | continuation.resume(Unit) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketCodecContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | import io.netty.buffer.ByteBufAllocator 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | 15 | internal interface PacketCodecContext : NetworkContext { 16 | 17 | /** 18 | * The byte buf allocator. 19 | */ 20 | val byteBufAllocator: ByteBufAllocator 21 | get() = connection.byteBufAlloc 22 | 23 | /** 24 | * The protocol used during the encoding or decoding. 25 | * 26 | * May throw an [IllegalStateException] if the protocol is not yet known. 27 | */ 28 | val protocol: Protocol 29 | get() = connection.protocol 30 | 31 | val nonePlayerId: PlayerId 32 | get() = connection.nonePlayerId 33 | 34 | /** 35 | * The direction for which the packet is being encoded or decoded. 36 | */ 37 | val direction: PacketDirection 38 | } 39 | 40 | internal class PacketCodecContextImpl( 41 | override val connection: Connection, 42 | override val direction: PacketDirection, 43 | ) : PacketCodecContext 44 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/pipeline/FrameDecoder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.pipeline 11 | 12 | import io.netty.buffer.ByteBuf 13 | import io.netty.channel.ChannelHandlerContext 14 | import io.netty.handler.codec.ByteToMessageDecoder 15 | import io.netty.handler.codec.DecoderException 16 | 17 | internal class FrameDecoder : ByteToMessageDecoder() { 18 | 19 | override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, output: MutableList) { 20 | if (!input.isReadable || input.readableBytes() < Short.SIZE_BYTES) 21 | return 22 | 23 | val index = input.readerIndex() 24 | val length = input.readUnsignedShortLE() - Short.SIZE_BYTES // Includes the header length 25 | 26 | if (length < 0) 27 | throw DecoderException("Invalid packet length: $length") 28 | 29 | // Check if all the bytes of the packet are available 30 | if (input.readableBytes() < length) { 31 | input.readerIndex(index) 32 | return 33 | } 34 | 35 | output.add(input.readRetainedSlice(length)) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Build and publish 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | - name: Add short commit SHA 15 | run: echo "GITHUB_SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV 16 | - name: Setup JDK 17 17 | uses: actions/setup-java@v3 18 | with: 19 | distribution: adopt 20 | java-version: 17 21 | - name: Validate Gradle wrapper 22 | uses: gradle/wrapper-validation-action@v1 23 | - name: Build and push image 24 | run: "./gradlew jib" 25 | env: 26 | ORG_GRADLE_PROJECT_dockerUsername: "${{ secrets.DOCKER_USERNAME }}" 27 | ORG_GRADLE_PROJECT_dockerPassword: "${{ secrets.DOCKER_PASSWORD }}" 28 | - name: Build and push standalone jar 29 | run: "./gradlew publish" 30 | env: 31 | ORG_GRADLE_PROJECT_repoUsername: "${{ github.actor }}" 32 | ORG_GRADLE_PROJECT_repoPassword: "${{ github.token }}" 33 | ORG_GRADLE_PROJECT_repoUrl: "https://maven.pkg.github.com/${{ github.repository }}" 34 | ORG_GRADLE_PROJECT_projectUrl: "https://github.com/${{ github.repository }}" 35 | ORG_GRADLE_PROJECT_projectSha: "${{ env.GITHUB_SHORT_SHA }}" 36 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/item/ItemStackImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.item 11 | 12 | import org.lanternpowered.terre.item.ItemModifier 13 | import org.lanternpowered.terre.item.ItemStack 14 | import org.lanternpowered.terre.item.ItemType 15 | import kotlin.math.max 16 | 17 | internal class ItemStackImpl( 18 | override val type: ItemType, 19 | override var modifier: ItemModifier, 20 | quantity: Int 21 | ) : ItemStack { 22 | 23 | override val isEmpty get() = quantity <= 0 || type == ItemType.None 24 | 25 | override var quantity: Int = if (type == ItemType.None) 0 else quantity 26 | set(value) { 27 | check(value >= 0) { "quantity cannot be negative" } 28 | field = max(value, 0) 29 | } 30 | 31 | override fun similarTo(other: ItemStack): Boolean = 32 | other.type == type && other.modifier == modifier 33 | 34 | override fun copy(): ItemStack { 35 | return ItemStackImpl(type, modifier, quantity) 36 | } 37 | 38 | override fun toString(): String = "ItemStack(type=$type,modifier=$modifier,quantity=$quantity)" 39 | } 40 | -------------------------------------------------------------------------------- /tshock-users/src/main/kotlin/org/lanternpowered/terre/tshock/TShockUsersConfigSpec.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.tshock 11 | 12 | import com.uchuhimo.konf.ConfigSpec 13 | 14 | object TShockUsersConfigSpec : ConfigSpec("tShockUsers") { 15 | 16 | val uuidLogin by optional( 17 | default = true, 18 | description = "Allows players to join automatically by using their client UUID." 19 | ) 20 | 21 | object Database : ConfigSpec("database") { 22 | 23 | val host by optional( 24 | default = "localhost", 25 | description = "The database host." 26 | ) 27 | 28 | val port by optional( 29 | default = 3306, 30 | description = "The database port." 31 | ) 32 | 33 | val database by optional( 34 | default = "", 35 | description = "The database name. Defaults to user name." 36 | ) 37 | 38 | val user by optional( 39 | default = "", 40 | description = "The database user." 41 | ) 42 | 43 | val password by optional( 44 | default = "", 45 | description = "The database user password." 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/plugin/asm/PluginClassVisitor.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.plugin.asm 11 | 12 | import org.lanternpowered.terre.plugin.Plugin 13 | import org.objectweb.asm.AnnotationVisitor 14 | import org.objectweb.asm.ClassVisitor 15 | import org.objectweb.asm.Opcodes.ASM9 16 | import org.objectweb.asm.Type 17 | 18 | internal class PluginClassVisitor : ClassVisitor(ASM9) { 19 | 20 | lateinit var className: String 21 | private set 22 | 23 | var pluginId: String? = null 24 | 25 | override fun visit( 26 | version: Int, 27 | access: Int, 28 | name: String, 29 | signature: String?, 30 | superName: String?, 31 | interfaces: Array? 32 | ) { 33 | className = name 34 | } 35 | 36 | override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? = 37 | if (visible && desc == pluginDescriptor) { 38 | PluginAnnotationVisitor(this, className) 39 | } else null 40 | 41 | companion object { 42 | 43 | private val pluginDescriptor = Type.getDescriptor(Plugin::class.java) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/plugin/PluginContainer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.plugin 11 | 12 | import org.lanternpowered.terre.impl.plugin.activePlugin 13 | 14 | /** 15 | * Represents a plugin. 16 | */ 17 | interface PluginContainer { 18 | 19 | /** 20 | * The id of the plugin. 21 | */ 22 | val id: String 23 | 24 | /** 25 | * The name of the plugin. 26 | */ 27 | val name: String 28 | 29 | /** 30 | * The version of the plugin. 31 | */ 32 | val version: String? 33 | 34 | /** 35 | * The description of the plugin, if there's one. 36 | */ 37 | val description: String? 38 | 39 | /** 40 | * The authors of the plugin. 41 | */ 42 | val authors: List 43 | 44 | /** 45 | * The url of the project page of the plugin. 46 | */ 47 | val url: String? 48 | 49 | /** 50 | * The instance of the plugin. 51 | */ 52 | val instance: Any 53 | 54 | companion object { 55 | 56 | /** 57 | * The current plugin that is executing code. 58 | */ 59 | val Active: PluginContainer? 60 | get() = activePlugin 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/util/TerreThread.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.util 11 | 12 | import io.netty.util.concurrent.FastThreadLocalThread 13 | import org.lanternpowered.terre.plugin.PluginContainer 14 | 15 | /** 16 | * Represents a custom thread to store thread local variables. 17 | * 18 | * Storing thread local values as fields instead of using 19 | * ThreadLocal objects has better performance. 20 | */ 21 | internal class TerreThread : FastThreadLocalThread { 22 | 23 | /** 24 | * The plugin that's currently active. 25 | */ 26 | var activePlugin: PluginContainer? = null 27 | 28 | constructor() : super() 29 | 30 | constructor(target: Runnable) : super(target) 31 | 32 | constructor(group: ThreadGroup?, target: Runnable) : super(group, target) 33 | 34 | constructor(name: String) : super(name) 35 | 36 | constructor(group: ThreadGroup?, name: String) : super(group, name) 37 | 38 | constructor(target: Runnable, name: String) : super(target, name) 39 | 40 | constructor(group: ThreadGroup?, target: Runnable, name: String) : super(group, target, name) 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/config/ReloadableConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.config 11 | 12 | import com.uchuhimo.konf.Config 13 | import kotlinx.coroutines.Job 14 | import java.nio.file.Path 15 | 16 | /** 17 | * Represents a [Config] which is more convenient to work with. 18 | */ 19 | interface ReloadableConfig : Config { 20 | 21 | /** 22 | * Whether the configuration file exists. 23 | */ 24 | val exists: Boolean 25 | 26 | /** 27 | * The path to the configuration file. 28 | */ 29 | val path: Path 30 | 31 | /** 32 | * The configuration format. 33 | */ 34 | val format: ConfigFormat 35 | 36 | /** 37 | * Loads or reloads the config file. 38 | */ 39 | suspend fun load() 40 | 41 | /** 42 | * Loads, reloads or creates the config file. 43 | */ 44 | suspend fun loadOrCreate() 45 | 46 | /** 47 | * Loads or reloads the config file. 48 | */ 49 | fun loadAsync(): Job 50 | 51 | /** 52 | * Saves the config file. 53 | */ 54 | suspend fun save() 55 | 56 | /** 57 | * Saves the config file. 58 | */ 59 | fun saveAsync(): Job 60 | } 61 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketEncoder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("FunctionName") 11 | 12 | package org.lanternpowered.terre.impl.network 13 | 14 | import io.netty.buffer.ByteBuf 15 | 16 | internal inline fun

PacketEncoder( 17 | crossinline fn: PacketCodecContext.(buf: ByteBuf, packet: P) -> Unit 18 | ): PacketEncoder

{ 19 | return object : PacketEncoder

{ 20 | override fun encode(ctx: PacketCodecContext, packet: P): ByteBuf { 21 | val buf = ctx.byteBufAllocator.buffer() 22 | fn(ctx, buf, packet) 23 | return buf 24 | } 25 | } 26 | } 27 | 28 | internal inline fun

PacketEncoder( 29 | crossinline fn: PacketCodecContext.(packet: P) -> ByteBuf 30 | ): PacketEncoder

{ 31 | return object : PacketEncoder

{ 32 | override fun encode(ctx: PacketCodecContext, packet: P): ByteBuf { 33 | return fn(ctx, packet) 34 | } 35 | } 36 | } 37 | 38 | internal interface PacketEncoder

{ 39 | 40 | /** 41 | * Encodes the packet into a [ByteBuf]. 42 | */ 43 | fun encode(ctx: PacketCodecContext, packet: P): ByteBuf 44 | } 45 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/CustomPayloadPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import io.netty.buffer.ByteBuf 13 | import org.lanternpowered.terre.impl.network.ForwardingReferenceCounted 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | 18 | /** 19 | * A packet reserved for custom communication between client and servers. This will be used for 20 | * custom communication between the proxy and backend servers. 21 | */ 22 | internal class CustomPayloadPacket( 23 | val content: ByteBuf 24 | ) : Packet, ForwardingReferenceCounted(content) 25 | 26 | internal val CustomPayloadEncoder = PacketEncoder { buf, packet -> 27 | val content = packet.content 28 | buf.writeBytes(content, content.readerIndex(), content.readableBytes()) 29 | } 30 | 31 | internal val CustomPayloadDecoder = PacketDecoder { buf -> 32 | val content = buf.readBytes(buf.readableBytes()) 33 | CustomPayloadPacket(content) 34 | } 35 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerManaPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.PacketDecoder 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | 19 | internal data class PlayerManaPacket( 20 | val playerId: PlayerId, 21 | val current: Int, 22 | val max: Int 23 | ) : Packet 24 | 25 | internal val PlayerManaDecoder = PacketDecoder { buf -> 26 | val playerId = buf.readPlayerId() 27 | val current = buf.readShortLE().toInt() 28 | val max = buf.readShortLE().toInt() 29 | PlayerManaPacket(playerId, current, max) 30 | } 31 | 32 | internal val PlayerManaEncoder = PacketEncoder { buf, packet -> 33 | buf.writePlayerId(packet.playerId) 34 | buf.writeShortLE(packet.current) 35 | buf.writeShortLE(packet.max) 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/portal/PortalType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.portal 11 | 12 | import org.lanternpowered.terre.catalog.NamedCatalogType 13 | import org.lanternpowered.terre.catalog.NamedCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.portal.PortalTypeImpl 15 | import org.lanternpowered.terre.impl.portal.PortalTypeRegistryImpl 16 | 17 | /** 18 | * Represents a type of portal. 19 | */ 20 | interface PortalType : NamedCatalogType 21 | 22 | /** 23 | * All the supported portal types. 24 | */ 25 | object PortalTypes { 26 | val Lunar: PortalType = PortalTypeImpl.Lunar 27 | val Nebula: PortalType = PortalTypeImpl.Nebula 28 | val Magnetosphere: PortalType = PortalTypeImpl.Magnetosphere 29 | val Electrosphere: PortalType = PortalTypeImpl.Electrosphere 30 | val Fireball: PortalType = PortalTypeImpl.Fireball 31 | val Shadowball: PortalType = PortalTypeImpl.Shadowball 32 | val Void: PortalType = PortalTypeImpl.Void 33 | val Invisible: PortalType = PortalTypeImpl.Invisible 34 | } 35 | 36 | object PortalTypeRegistry : NamedCatalogTypeRegistry by PortalTypeRegistryImpl 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerHealthPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 17 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 18 | 19 | internal data class PlayerHealthPacket( 20 | val playerId: PlayerId, 21 | val current: Int, 22 | val max: Int 23 | ) : Packet 24 | 25 | internal val PlayerHealthDecoder = PacketDecoder { buf -> 26 | val playerId = buf.readPlayerId() 27 | val current = buf.readShortLE().toInt() 28 | val max = buf.readShortLE().toInt() 29 | PlayerHealthPacket(playerId, current, max) 30 | } 31 | 32 | internal val PlayerHealthEncoder = PacketEncoder { buf, packet -> 33 | buf.writePlayerId(packet.playerId) 34 | buf.writeShortLE(packet.current) 35 | buf.writeShortLE(packet.max) 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/connection/ClientConnectEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.connection 11 | 12 | import org.lanternpowered.terre.InboundConnection 13 | import org.lanternpowered.terre.event.Event 14 | import org.lanternpowered.terre.text.Text 15 | 16 | /** 17 | * An event that is thrown when a client establishes a new connection with the proxy. 18 | * 19 | * @property inboundConnection The inbound connection 20 | * @property result The result of the event 21 | */ 22 | data class ClientConnectEvent( 23 | val inboundConnection: InboundConnection, 24 | var result: Result = Result.Allowed 25 | ) : Event { 26 | 27 | /** 28 | * Represents the result of a [ClientConnectEvent]. 29 | */ 30 | sealed interface Result { 31 | 32 | /** 33 | * The client is allowed to proceed connecting to the proxy. 34 | */ 35 | object Allowed : Result 36 | 37 | /** 38 | * The client is denied to proceed connecting to the proxy. The client will be disconnected 39 | * with the specified [reason]. 40 | */ 41 | data class Denied(val reason: Text) : Result 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /proxy/src/test/kotlin/org/lanternpowered/terre/impl/math/Vec2fTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.math 11 | 12 | import org.junit.jupiter.api.Test 13 | import org.lanternpowered.terre.math.Vec2f 14 | import kotlin.test.assertEquals 15 | 16 | class Vec2fTest { 17 | 18 | @Test fun `test vec2f construction`() { 19 | val x = 15148.2134f 20 | val y = 91234.96478f 21 | val vec = Vec2f(x, y) 22 | assertEquals(x, vec.x) 23 | assertEquals(y, vec.y) 24 | } 25 | 26 | @Test fun `test vec2f construction with negative values`() { 27 | val x = 987.3647f 28 | val y = -9532.36578f 29 | val vec = Vec2f(x, y) 30 | assertEquals(x, vec.x) 31 | assertEquals(y, vec.y) 32 | } 33 | 34 | @Test fun `test vec2f construction with NaN value`() { 35 | val x = 15148f 36 | val y = Float.NaN 37 | val vec = Vec2f(x, y) 38 | assertEquals(x, vec.x) 39 | assertEquals(y, vec.y) 40 | } 41 | 42 | @Test fun `test vec2f equality`() { 43 | val x = 15148.2134f 44 | val y = 91234.96478f 45 | val vec1 = Vec2f(x, y) 46 | val vec2 = Vec2f(x, y) 47 | assertEquals(vec1, vec2) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /proxy/src/test/kotlin/org/lanternpowered/terre/impl/util/GenerateReadyRequestPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.util 11 | 12 | import io.netty.buffer.Unpooled 13 | import io.netty.handler.codec.base64.Base64 14 | import org.junit.jupiter.api.Test 15 | import org.lanternpowered.terre.impl.network.buffer.writeString 16 | 17 | class GenerateReadyRequestPacket { 18 | 19 | /** 20 | * Generates a base64 encoded packet content that can be used to check if Terraria is running 21 | * and accepting connections. The server should respond with a version mismatch. 22 | */ 23 | @Test fun generate() { 24 | val content = Unpooled.buffer() 25 | val framed = Unpooled.buffer() 26 | 27 | try { 28 | content.writeByte(0x01) // Connection request packet id 29 | content.writeString("Liveness") // Version string 30 | 31 | framed.writeShortLE(content.readableBytes() + Short.SIZE_BYTES) 32 | framed.writeBytes(content) 33 | 34 | println("Liveness: " + Base64.encode(framed).toString(Charsets.UTF_8)) 35 | } finally { 36 | content.release() 37 | framed.release() 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/text/LiteralTextImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.text 11 | 12 | import org.lanternpowered.terre.impl.util.OptionalColor 13 | import org.lanternpowered.terre.impl.util.optionalFromNullable 14 | import org.lanternpowered.terre.text.LiteralText 15 | import org.lanternpowered.terre.util.Color 16 | import org.lanternpowered.terre.util.ToStringHelper 17 | 18 | internal data class LiteralTextImpl( 19 | override val literal: String, 20 | override val optionalColor: OptionalColor = OptionalColor.empty() 21 | ) : ColorableTextImpl(), LiteralText { 22 | 23 | override fun toPlain() = literal 24 | 25 | override val isEmpty get() = literal.isEmpty() 26 | 27 | override fun color(color: Color?): LiteralTextImpl = 28 | color(color.optionalFromNullable()) 29 | 30 | fun color(color: OptionalColor): LiteralTextImpl = 31 | if (optionalColor == color) this 32 | else LiteralTextImpl(literal, color) 33 | 34 | override fun toString() = ToStringHelper(LiteralText::class) 35 | .omitNullValues() 36 | .add("literal", literal) 37 | .add("color", color) 38 | .toString() 39 | } 40 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/AddPlayerBuffPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | @file:Suppress("FunctionName") 11 | 12 | package org.lanternpowered.terre.impl.network.packet 13 | 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 17 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 18 | import org.lanternpowered.terre.impl.network.PacketDecoder 19 | import org.lanternpowered.terre.impl.network.PacketEncoder 20 | 21 | internal data class AddPlayerBuffPacket( 22 | val playerId: PlayerId, 23 | val buff: Int, 24 | val time: Int 25 | ) : Packet 26 | 27 | internal val AddPlayerBuffEncoder = PacketEncoder { buf, packet -> 28 | buf.writePlayerId(packet.playerId) 29 | buf.writeShortLE(packet.buff) 30 | buf.writeIntLE(packet.time) 31 | } 32 | 33 | internal val AddPlayerBuffDecoder = PacketDecoder { buf -> 34 | val playerId = buf.readPlayerId() 35 | val buff = buf.readUnsignedShortLE() 36 | val time = buf.readIntLE() 37 | AddPlayerBuffPacket(playerId, buff, time) 38 | } 39 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/event/EventExecutor.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.event 11 | 12 | import com.google.common.util.concurrent.ThreadFactoryBuilder 13 | import kotlinx.coroutines.asCoroutineDispatcher 14 | import org.lanternpowered.terre.impl.dispatcher.PluginContextCoroutineDispatcher 15 | import org.lanternpowered.terre.impl.util.TerreThread 16 | import java.util.concurrent.ExecutorService 17 | import java.util.concurrent.Executors 18 | 19 | internal object EventExecutor { 20 | 21 | val executor: ExecutorService = 22 | Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), 23 | ThreadFactoryBuilder() 24 | .setNameFormat("event-executor-%d") 25 | .setDaemon(true) 26 | .setThreadFactory(::TerreThread) 27 | .build()) 28 | 29 | /** 30 | * The internal coroutine dispatcher. 31 | */ 32 | val dispatcher = executor.asCoroutineDispatcher() 33 | 34 | /** 35 | * A coroutine dispatcher that makes sure that the context of the plugin that's submitting a 36 | * task is known. 37 | */ 38 | val pluginAwareDispatcher = PluginContextCoroutineDispatcher(dispatcher) 39 | } 40 | -------------------------------------------------------------------------------- /proxy/src/main/resources/data/tile_frame_important.json: -------------------------------------------------------------------------------- 1 | [3,4,5,10,11,12,13,14,15,16,17,18,19,20,21,24,26,27,28,29,31,33,34,35,36,42,49,50,55,61,71,72,73,74,77,78,79,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,110,113,114,125,126,128,129,132,133,134,135,136,137,138,139,141,142,143,144,149,165,171,172,173,174,178,184,185,186,187,201,207,209,210,212,215,216,217,218,219,220,227,228,231,233,235,236,237,238,239,240,241,242,243,244,245,246,247,254,269,270,271,275,276,277,278,279,280,281,282,283,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,314,316,317,318,319,320,323,324,334,335,337,338,339,349,354,355,356,358,359,360,361,362,363,364,372,373,374,375,376,377,378,380,386,387,388,389,390,391,392,393,394,395,405,406,410,411,412,413,414,419,420,423,424,425,427,428,429,435,436,437,438,439,440,441,442,443,444,445,452,453,454,455,456,457,461,462,463,464,465,466,467,468,469,470,471,475,476,480,484,485,486,487,488,489,490,491,493,494,497,499,505,506,509,510,511,518,519,520,520,521,522,523,524,525,526,527,529,530,531,532,533,538,542,543,544,545,547,548,549,550,551,552,553,554,555,556,558,559,560,564,565,567,568,568,569,569,570,570,571,572,573,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,619,620,621,622,623,624,629,630,631,632,634,634,637,639,640,642,643,644,645,646,653,654,656,657,658,660,663,664,665] 2 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ConnectionApprovedPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.PacketDecoder 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | 19 | internal data class ConnectionApprovedPacket(val playerId: PlayerId) : Packet 20 | 21 | internal val ConnectionApprovedEncoder = PacketEncoder { buf, packet -> 22 | buf.writePlayerId(packet.playerId) 23 | buf.writeBoolean(false) // serverWantsToRunCheckBytesInClientLoopThread -> disable 24 | } 25 | 26 | internal val ConnectionApprovedDecoder = PacketDecoder { buf -> 27 | val playerId = buf.readPlayerId() 28 | // if condition for server-init protocol 29 | if (buf.readableBytes() > 0) 30 | buf.readBoolean() // serverWantsToRunCheckBytesInClientLoopThread -> ignore 31 | ConnectionApprovedPacket(playerId) 32 | } 33 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/NumericCatalogTypeRegistry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | import org.lanternpowered.terre.impl.buildNumericCatalogTypeRegistryOf 13 | import kotlin.reflect.KClass 14 | 15 | /** 16 | * Constructs a new [CatalogTypeRegistry]. 17 | */ 18 | inline fun numericCatalogTypeRegistry( 19 | noinline fn: CatalogTypeRegistryBuilder.() -> Unit 20 | ): NumericCatalogTypeRegistry = numericCatalogTypeRegistry(T::class, fn) 21 | 22 | /** 23 | * Constructs a new [CatalogTypeRegistry]. 24 | */ 25 | fun numericCatalogTypeRegistry( 26 | type: KClass, fn: CatalogTypeRegistryBuilder.() -> Unit 27 | ): NumericCatalogTypeRegistry = buildNumericCatalogTypeRegistryOf(type, fn) 28 | 29 | interface NumericCatalogTypeRegistry : CatalogTypeRegistry { 30 | 31 | /** 32 | * Gets a catalog type of type [T] from the registry, if present. 33 | */ 34 | operator fun get(numericId: Int): T? 35 | 36 | /** 37 | * Requires that a catalog type of the given numeric id exists and returns it. 38 | */ 39 | fun require(numericId: Int): T 40 | } 41 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/config/ConfigDirectoryImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.config 11 | 12 | import com.uchuhimo.konf.Config 13 | import org.lanternpowered.terre.config.ConfigDirectory 14 | import org.lanternpowered.terre.config.ConfigDirectoryBase 15 | import org.lanternpowered.terre.config.ConfigFormat 16 | import org.lanternpowered.terre.config.ReloadableConfig 17 | import org.lanternpowered.terre.config.RootConfigDirectory 18 | import java.nio.file.Path 19 | 20 | internal open class ConfigDirectoryBaseImpl(override val path: Path) : ConfigDirectoryBase { 21 | 22 | override fun config( 23 | name: String, format: ConfigFormat, extension: String, initializer: Config.() -> Unit 24 | ): ReloadableConfig { 25 | val config = Config().also(initializer) 26 | val path = path.resolve(name + if (extension.isNotBlank()) ".$extension" else "") 27 | return ReloadableConfigImpl(config, path, format) 28 | } 29 | } 30 | 31 | internal class RootConfigDirectoryImpl(path: Path) : 32 | ConfigDirectoryBaseImpl(path), RootConfigDirectory 33 | 34 | internal class ConfigDirectoryImpl(path: Path) : 35 | ConfigDirectoryBaseImpl(path), ConfigDirectory 36 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/ServerInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | import java.net.InetSocketAddress 13 | 14 | /** 15 | * Represents a server that a player can connect to. 16 | * 17 | * If [protocolVersion] is null, the proxy will attempt to connect with multiple versions. This 18 | * has the benefit that you can swap the server without having to modify the info, but the first 19 | * time someone connects to the server can take a bit longer. After the server has discovered the 20 | * version there shouldn't be a difference in connecting time. 21 | * 22 | * @property name The name of the server, which should be human-readable 23 | * @property address The address of the server where the proxy should connect to 24 | * @property password The password of the server, if required 25 | * @property protocolVersion The protocol version that is used by the server, or null if unknown 26 | */ 27 | data class ServerInfo( 28 | val name: String, 29 | val address: InetSocketAddress, 30 | val password: String = "", 31 | val protocolVersion: ProtocolVersion? = null 32 | ) { 33 | 34 | init { 35 | check(name.isNotBlank()) { "The server name cannot be blank" } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/plugin/asm/WarningAnnotationVisitor.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.plugin.asm 11 | 12 | import org.lanternpowered.terre.impl.Terre 13 | import org.objectweb.asm.AnnotationVisitor 14 | 15 | internal abstract class WarningAnnotationVisitor(api: Int, private val className: String) : AnnotationVisitor(api) { 16 | 17 | internal abstract val annotation: String 18 | 19 | override fun visit(name: String?, value: Any) { 20 | Terre.logger.warn("Found unknown $annotation annotation element in $className: $name = $value") 21 | } 22 | 23 | override fun visitEnum(name: String?, desc: String, value: String) { 24 | Terre.logger.warn("Found unknown $annotation annotation element in $className: $name ($desc) = $value") 25 | } 26 | 27 | override fun visitAnnotation(name: String?, desc: String): AnnotationVisitor? { 28 | Terre.logger.warn("Found unknown $annotation annotation element in $className: $name ($desc)") 29 | return null 30 | } 31 | 32 | override fun visitArray(name: String?): AnnotationVisitor? { 33 | Terre.logger.warn("Found unknown $annotation annotation element in $className: $name") 34 | return null 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ItemUpdateOwnerPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 16 | import org.lanternpowered.terre.impl.network.PacketDecoder 17 | import org.lanternpowered.terre.impl.network.PacketEncoder 18 | import org.lanternpowered.terre.impl.network.buffer.ItemId 19 | import org.lanternpowered.terre.impl.network.buffer.readItemId 20 | import org.lanternpowered.terre.impl.network.buffer.writeItemId 21 | 22 | internal data class ItemUpdateOwnerPacket( 23 | val id: ItemId, 24 | val ownerId: PlayerId 25 | ) : Packet 26 | 27 | internal val ItemUpdateOwnerEncoder = PacketEncoder { buf, packet -> 28 | buf.writeItemId(packet.id) 29 | buf.writePlayerId(packet.ownerId) 30 | } 31 | 32 | internal val ItemUpdateOwnerDecoder = PacketDecoder { buf -> 33 | val itemId = buf.readItemId() 34 | val ownerId = buf.readPlayerId() 35 | ItemUpdateOwnerPacket(itemId, ownerId) 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/PlayerCollection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | import kotlinx.coroutines.Job 13 | import org.lanternpowered.terre.dispatcher.launchAsync 14 | import org.lanternpowered.terre.text.Text 15 | import java.util.UUID 16 | 17 | /** 18 | * Represents a collection of players. 19 | */ 20 | interface PlayerCollection : Collection { 21 | 22 | /** 23 | * Attempts to get the player for the given [UUID]. 24 | */ 25 | operator fun get(uniqueId: UUID): Player? 26 | 27 | /** 28 | * Gets whether a player with the given [UUID] exists in this collection. 29 | */ 30 | operator fun contains(uniqueId: UUID): Boolean 31 | } 32 | 33 | /** 34 | * Disconnects all the [Player]s in the [PlayerCollection]. 35 | */ 36 | suspend fun Collection.disconnectAll(reason: Text = DefaultDisconnectReason) { 37 | toList().asSequence() 38 | .map { it.disconnectAsync(reason) } 39 | .forEach { it.join() } 40 | } 41 | 42 | /** 43 | * Disconnects all the [Player]s in the [PlayerCollection]. 44 | */ 45 | fun Collection.disconnectAllAsync(reason: Text = DefaultDisconnectReason): Job { 46 | return launchAsync { 47 | disconnectAll(reason) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/Team.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre 11 | 12 | import org.lanternpowered.terre.catalog.NamedCatalogType 13 | import org.lanternpowered.terre.catalog.NamedCatalogTypeRegistry 14 | import org.lanternpowered.terre.impl.player.TeamImpl 15 | import org.lanternpowered.terre.impl.player.TeamRegistryImpl 16 | import org.lanternpowered.terre.util.Color 17 | 18 | interface Team : NamedCatalogType { 19 | 20 | val color: Color 21 | 22 | companion object { 23 | 24 | /** 25 | * No team. 26 | */ 27 | val None: Team = TeamImpl.None 28 | 29 | /** 30 | * The red team. 31 | */ 32 | val Red: Team = TeamImpl.Red 33 | 34 | /** 35 | * The green team. 36 | */ 37 | val Green: Team = TeamImpl.Green 38 | 39 | /** 40 | * The blue team. 41 | */ 42 | val Blue: Team = TeamImpl.Blue 43 | 44 | /** 45 | * The yellow team. 46 | */ 47 | val Yellow: Team = TeamImpl.Yellow 48 | 49 | /** 50 | * The pink team. 51 | */ 52 | val Pink: Team = TeamImpl.Pink 53 | } 54 | } 55 | 56 | /** 57 | * A registry for all the [Team]s. 58 | */ 59 | object TeamRegistry : NamedCatalogTypeRegistry by TeamRegistryImpl 60 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerBuffsPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import io.netty.buffer.ByteBuf 13 | import org.lanternpowered.terre.impl.network.ForwardingReferenceCounted 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 17 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 18 | import org.lanternpowered.terre.impl.network.PacketDecoder 19 | import org.lanternpowered.terre.impl.network.PacketEncoder 20 | 21 | internal data class PlayerBuffsPacket( 22 | val playerId: PlayerId, 23 | val data: ByteBuf 24 | ) : Packet, ForwardingReferenceCounted(data) 25 | 26 | internal val PlayerBuffsEncoder = PacketEncoder { buf, packet -> 27 | val content = packet.data 28 | buf.writePlayerId(packet.playerId) 29 | buf.writeBytes(content, 0, content.readableBytes()) 30 | } 31 | 32 | internal val PlayerBuffsDecoder = PacketDecoder { buf -> 33 | val playerId = buf.readPlayerId() 34 | val content = buf.readBytes(buf.readableBytes()) 35 | PlayerBuffsPacket(playerId, content) 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/catalog/NamedCatalogTypeRegistry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.catalog 11 | 12 | import org.lanternpowered.terre.impl.buildNamedCatalogTypeRegistryOf 13 | import kotlin.reflect.KClass 14 | 15 | /** 16 | * Constructs a new [CatalogTypeRegistry]. 17 | */ 18 | inline fun namedCatalogTypeRegistry( 19 | noinline fn: CatalogTypeRegistryBuilder.() -> Unit 20 | ): NamedCatalogTypeRegistry = namedCatalogTypeRegistry(T::class, fn) 21 | 22 | /** 23 | * Constructs a new [CatalogTypeRegistry]. 24 | */ 25 | fun namedCatalogTypeRegistry( 26 | type: KClass, fn: CatalogTypeRegistryBuilder.() -> Unit 27 | ): NamedCatalogTypeRegistry = buildNamedCatalogTypeRegistryOf(type, fn) 28 | 29 | /** 30 | * Represents a registry for named catalog types. 31 | */ 32 | interface NamedCatalogTypeRegistry : CatalogTypeRegistry { 33 | 34 | /** 35 | * Gets a catalog type of type [T] from the registry, if present. 36 | */ 37 | operator fun get(name: String): T? 38 | 39 | /** 40 | * Requires that a catalog type of the 41 | * given name exists and returns it. 42 | */ 43 | fun require(name: String): T 44 | } 45 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/Terre.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl 11 | 12 | import org.apache.logging.log4j.LogManager 13 | import org.lanternpowered.terre.impl.logger.LoggerImpl 14 | import org.lanternpowered.terre.logger.Logger 15 | import org.lanternpowered.terre.text.Text 16 | import org.lanternpowered.terre.text.text 17 | import org.lanternpowered.terre.util.Color 18 | 19 | internal object Terre { 20 | 21 | /** 22 | * The name of the implementation. 23 | */ 24 | val name = ProxyImpl::class.java.`package`.implementationTitle ?: "Terre" 25 | 26 | /** 27 | * The version of the implementation. 28 | */ 29 | val version = ProxyImpl::class.java.`package`.implementationVersion ?: "" 30 | 31 | /** 32 | * The color used for chat messages from terre. 33 | */ 34 | val color = Color(61, 105, 95) 35 | 36 | /** 37 | * The prefix used in from of terre messages. 38 | */ 39 | private val messagePrefix = "[$name] ".text().color(color) 40 | 41 | fun message(text: Text) = messagePrefix + text 42 | 43 | fun message(text: String) = message(text.text()) 44 | 45 | /** 46 | * The logger of the platform. 47 | */ 48 | val logger: Logger = LoggerImpl(LogManager.getLogger(name)) 49 | } 50 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/player/TeamImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.player 11 | 12 | import org.lanternpowered.terre.Team 13 | import org.lanternpowered.terre.catalog.NumericCatalogType 14 | import org.lanternpowered.terre.impl.buildNamedCatalogTypeRegistryOf 15 | import org.lanternpowered.terre.util.Color 16 | import org.lanternpowered.terre.util.Colors 17 | 18 | internal data class TeamImpl( 19 | override val name: String, 20 | override val numericId: Int, 21 | override val color: Color, 22 | ) : Team, NumericCatalogType { 23 | 24 | companion object { 25 | val None = TeamImpl("none", 0, Colors.White) 26 | val Red = TeamImpl("red", 1, Color(218, 59, 59)) 27 | val Green = TeamImpl("green", 2, Color(59, 218, 85)) 28 | val Blue = TeamImpl("blue", 3, Color(59, 149, 218)) 29 | val Yellow = TeamImpl("yellow", 4, Color(242, 221, 100)) 30 | val Pink = TeamImpl("pink", 5, Color(224, 100, 242)) 31 | } 32 | } 33 | 34 | internal val TeamRegistryImpl = buildNamedCatalogTypeRegistryOf({ null }) { 35 | register(TeamImpl.None) 36 | register(TeamImpl.Red) 37 | register(TeamImpl.Green) 38 | register(TeamImpl.Blue) 39 | register(TeamImpl.Yellow) 40 | register(TeamImpl.Pink) 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/FormattableText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.FormattableTextImpl 13 | import org.lanternpowered.terre.util.collection.toImmutableList 14 | 15 | /** 16 | * Constructs a formatted text component with the given substitutions. 17 | */ 18 | fun formattedTextOf(format: String, vararg substitutions: Any): FormattableText = 19 | formattedTextOf(format, substitutions.asList()) 20 | 21 | /** 22 | * Constructs a formatted text component with the given substitutions. 23 | */ 24 | fun formattedTextOf(format: String, substitutions: Iterable): FormattableText { 25 | val textSubstitutions = substitutions.asSequence() 26 | .map { substitution -> 27 | if (substitution is TextLike) substitution.text() 28 | else substitution.toString().text() 29 | } 30 | .toImmutableList() 31 | return FormattableTextImpl(format, textSubstitutions) 32 | } 33 | 34 | interface FormattableText : ColorableText { 35 | 36 | /** 37 | * The format that will be formatted using the substitutions. 38 | */ 39 | val format: String 40 | 41 | /** 42 | * The substitutions of the text. 43 | */ 44 | val substitutions: List 45 | } 46 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ItemRemoveOwnerPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.impl.network.buffer.ItemId 16 | import org.lanternpowered.terre.impl.network.buffer.readItemId 17 | import org.lanternpowered.terre.impl.network.buffer.writeItemId 18 | 19 | internal data class ItemRemoveOwnerPacket( 20 | val id: ItemId 21 | ) : Packet { 22 | 23 | companion object { 24 | 25 | /** 26 | * An item id that is not used by vanilla so can be used as a ping pong between the client 27 | * and server. The client will always respond with a [ItemUpdateOwnerPacket] when sending 28 | * a [ItemRemoveOwnerPacket]. 29 | */ 30 | val PingPongItemId = ItemId(400) 31 | } 32 | } 33 | 34 | internal val ItemRemoveOwnerEncoder = PacketEncoder { buf, packet -> 35 | buf.writeItemId(packet.id) 36 | } 37 | 38 | internal val ItemRemoveOwnerDecoder = PacketDecoder { buf -> 39 | val itemId = buf.readItemId() 40 | ItemRemoveOwnerPacket(itemId) 41 | } 42 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/text/LocalizedText.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.text 11 | 12 | import org.lanternpowered.terre.impl.text.LocalizedTextImpl 13 | import org.lanternpowered.terre.util.Color 14 | import org.lanternpowered.terre.util.collection.toImmutableList 15 | 16 | /** 17 | * Constructs a localized text component with the given substitutions. 18 | */ 19 | fun localizedTextOf(key: String, vararg substitutions: Any): LocalizedText = 20 | localizedTextOf(key, substitutions.asList()) 21 | 22 | /** 23 | * Constructs a localized text component with the given substitutions. 24 | */ 25 | fun localizedTextOf(key: String, substitutions: Iterable): LocalizedText { 26 | val textSubstitutions = substitutions.asSequence() 27 | .map { it as? Text ?: it.toString().text() } 28 | .toImmutableList() 29 | return LocalizedTextImpl(key, textSubstitutions) 30 | } 31 | 32 | /** 33 | * Represents localized text. 34 | */ 35 | interface LocalizedText : ColorableText { 36 | 37 | /** 38 | * The key of the localized text. 39 | */ 40 | val key: String 41 | 42 | /** 43 | * The substitutions of the text. 44 | */ 45 | val substitutions: List 46 | 47 | override fun color(color: Color?): LocalizedText 48 | } 49 | -------------------------------------------------------------------------------- /portals/src/main/kotlin/org/lanternpowered/terre/portals/PortalData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.portals 11 | 12 | import kotlinx.serialization.SerialName 13 | import kotlinx.serialization.Serializable 14 | import org.lanternpowered.terre.math.Vec2f 15 | import org.lanternpowered.terre.portal.PortalType 16 | import org.lanternpowered.terre.portal.PortalTypeRegistry 17 | 18 | /** 19 | * Represents a portal that is persisted. 20 | * 21 | * @property name The name of the portal, used to identify it. 22 | * @property position The position where the portal is located. 23 | * @property destination The target server the portal should bring us to. 24 | */ 25 | @Serializable 26 | class PortalData( 27 | val name: String, 28 | @SerialName("type") private val typeName: String, 29 | @SerialName("pos") private val positionArray: FloatArray, 30 | val origin: String, 31 | val destination: String 32 | ) { 33 | 34 | val position: Vec2f 35 | get() = Vec2f(positionArray[0], positionArray[1]) 36 | 37 | val type: PortalType 38 | get() = PortalTypeRegistry[typeName]!! 39 | 40 | constructor(name: String, type: PortalType, position: Vec2f, origin: String, target: String) : 41 | this(name, type.name, floatArrayOf(position.x, position.y), origin, target) 42 | } 43 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/TeleportPylonPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.PacketDecoder 14 | import org.lanternpowered.terre.impl.network.PacketEncoder 15 | import org.lanternpowered.terre.impl.network.buffer.readShortVec2i 16 | import org.lanternpowered.terre.impl.network.buffer.writeShortVec2i 17 | import org.lanternpowered.terre.math.Vec2i 18 | 19 | internal data class TeleportPylonPacket( 20 | val action: Action, 21 | val type: Int, 22 | val position: Vec2i, 23 | ) : Packet { 24 | 25 | enum class Action { 26 | Added, 27 | Removed, 28 | RequestTeleport, 29 | } 30 | } 31 | 32 | internal val TeleportPylonEncoder = PacketEncoder { buf, packet -> 33 | buf.writeByte(packet.action.ordinal) 34 | buf.writeShortVec2i(packet.position) 35 | buf.writeByte(packet.type) 36 | } 37 | 38 | internal val TeleportPylonDecoder = PacketDecoder { buf -> 39 | val action = TeleportPylonPacket.Action.entries[buf.readByte().toInt()] 40 | val position = buf.readShortVec2i() 41 | val type = buf.readByte().toInt() 42 | TeleportPylonPacket(action, type, position) 43 | } 44 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/v230/TileSquare230.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.v230 11 | 12 | import org.lanternpowered.terre.impl.network.PacketDecoder 13 | import org.lanternpowered.terre.impl.network.PacketEncoder 14 | import org.lanternpowered.terre.impl.network.packet.TileSquarePacket 15 | 16 | internal val TileSquare230Encoder = PacketEncoder { buf, packet -> 17 | check(packet.width == packet.height) { "Width and height must be the same" } 18 | var size = packet.width 19 | if (packet.changeType != 0) 20 | size += 0x8000 21 | buf.writeShortLE(size) 22 | if (packet.changeType != 0) 23 | buf.writeByte(packet.changeType) 24 | buf.writeShortLE(packet.x) 25 | buf.writeShortLE(packet.y) 26 | buf.writeBytes(packet.tiles) 27 | } 28 | 29 | internal val TileSquare230Decoder = PacketDecoder { buf -> 30 | val sizeAndFlag = buf.readUnsignedShortLE() 31 | val size = sizeAndFlag and 0x7fff 32 | val changeType = if (sizeAndFlag and 0x8000 != 0) { 33 | buf.readByte().toInt() 34 | } else 0 35 | val x = buf.readShortLE().toInt() 36 | val y = buf.readShortLE().toInt() 37 | val tiles = buf.retainedSlice() 38 | TileSquarePacket(x, y, size, size, changeType, tiles) 39 | } 40 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/ProjectileDestroyPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.impl.network.Packet 13 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 14 | import org.lanternpowered.terre.impl.network.buffer.ProjectileId 15 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 16 | import org.lanternpowered.terre.impl.network.buffer.readProjectileId 17 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 18 | import org.lanternpowered.terre.impl.network.buffer.writeProjectileId 19 | import org.lanternpowered.terre.impl.network.PacketDecoder 20 | import org.lanternpowered.terre.impl.network.PacketEncoder 21 | 22 | internal data class ProjectileDestroyPacket( 23 | val id: ProjectileId, 24 | val owner: PlayerId 25 | ) : Packet 26 | 27 | internal val ProjectileDestroyEncoder = PacketEncoder { buf, packet -> 28 | buf.writeProjectileId(packet.id) 29 | buf.writePlayerId(packet.owner) 30 | } 31 | 32 | internal val ProjectileDestroyDecoder = PacketDecoder { buf -> 33 | val projectileId = buf.readProjectileId() 34 | val owner = buf.readPlayerId() 35 | ProjectileDestroyPacket(projectileId, owner) 36 | } 37 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/v238/PlayerSpawn238.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet.v238 11 | 12 | import org.lanternpowered.terre.impl.network.PacketDecoder 13 | import org.lanternpowered.terre.impl.network.PacketEncoder 14 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 15 | import org.lanternpowered.terre.impl.network.buffer.readShortVec2i 16 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 17 | import org.lanternpowered.terre.impl.network.buffer.writeShortVec2i 18 | import org.lanternpowered.terre.impl.network.packet.PlayerSpawnPacket 19 | 20 | internal val PlayerSpawn238Encoder = PacketEncoder { buf, packet -> 21 | buf.writePlayerId(packet.playerId) 22 | buf.writeShortVec2i(packet.position) 23 | buf.writeIntLE(packet.respawnTimeRemaining) 24 | buf.writeByte(packet.context.ordinal) 25 | } 26 | 27 | internal val PlayerSpawn238Decoder = PacketDecoder { buf -> 28 | val playerId = buf.readPlayerId() 29 | val position = buf.readShortVec2i() 30 | val respawnTimeRemaining = buf.readIntLE() 31 | val respawnContext = PlayerSpawnPacket.Context.entries[buf.readUnsignedByte().toInt()] 32 | PlayerSpawnPacket(playerId, position, respawnTimeRemaining, 0, 0, 33 | respawnContext) 34 | } 35 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/event/connection/PlayerLoginEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.event.connection 11 | 12 | import org.lanternpowered.terre.Player 13 | import org.lanternpowered.terre.event.Event 14 | import org.lanternpowered.terre.text.Text 15 | 16 | /** 17 | * An event that is thrown when a player has been authenticated, but before they connect to a 18 | * server through a proxy. 19 | * 20 | * A [PlayerLoginEvent] can have a result [Result.Denied] if the player failed to provide a valid 21 | * password as result of [PlayerPreLoginEvent.Result.RequestPassword]. 22 | * 23 | * @property player The player that is attempting to log in 24 | * @property result The result of the login 25 | */ 26 | data class PlayerLoginEvent( 27 | val player: Player, 28 | var result: Result = Result.Allowed 29 | ) : Event { 30 | 31 | /** 32 | * Represents the result of a [PlayerLoginEvent]. 33 | */ 34 | sealed interface Result { 35 | 36 | /** 37 | * The player is allowed to proceed connecting to the proxy. 38 | */ 39 | object Allowed : Result 40 | 41 | /** 42 | * The player is denied to proceed connecting to the proxy. The player will be disconnected 43 | * with the specified [reason]. 44 | */ 45 | data class Denied(val reason: Text) : Result 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/PacketLengthBuilder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network 11 | 12 | internal fun calculateLength(fn: PacketLengthBuilder.() -> Unit): Int { 13 | return PacketLengthBuilderImpl().also(fn).length 14 | } 15 | 16 | internal interface PacketLengthBuilder { 17 | fun int() 18 | fun byte() 19 | fun playerId() 20 | fun short() 21 | fun long() 22 | fun double() 23 | fun float() 24 | fun vec2f() 25 | fun vec2i() 26 | fun shortVec2i() 27 | } 28 | 29 | private class PacketLengthBuilderImpl : PacketLengthBuilder { 30 | 31 | var length = 0 32 | 33 | override fun int() { 34 | length += Int.SIZE_BYTES 35 | } 36 | 37 | override fun byte() { 38 | length += Byte.SIZE_BYTES 39 | } 40 | 41 | override fun playerId() { 42 | byte() 43 | } 44 | 45 | override fun short() { 46 | length += Short.SIZE_BYTES 47 | } 48 | 49 | override fun long() { 50 | length += Long.SIZE_BYTES 51 | } 52 | 53 | override fun double() { 54 | long() 55 | } 56 | 57 | override fun float() { 58 | int() 59 | } 60 | 61 | override fun vec2f() { 62 | long() // 2 Floats 63 | } 64 | 65 | override fun vec2i() { 66 | long() // 2 Ints 67 | } 68 | 69 | override fun shortVec2i() { 70 | int() // 2 Shorts 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /proxy/src/main/kotlin/org/lanternpowered/terre/impl/network/packet/PlayerTeamPacket.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Terre 3 | * 4 | * Copyright (c) LanternPowered 5 | * Copyright (c) contributors 6 | * 7 | * This work is licensed under the terms of the MIT License (MIT). For 8 | * a copy, see 'LICENSE.txt' or . 9 | */ 10 | package org.lanternpowered.terre.impl.network.packet 11 | 12 | import org.lanternpowered.terre.Team 13 | import org.lanternpowered.terre.TeamRegistry 14 | import org.lanternpowered.terre.impl.network.Packet 15 | import org.lanternpowered.terre.impl.network.PacketDecoder 16 | import org.lanternpowered.terre.impl.network.PacketEncoder 17 | import org.lanternpowered.terre.impl.network.buffer.PlayerId 18 | import org.lanternpowered.terre.impl.network.buffer.readPlayerId 19 | import org.lanternpowered.terre.impl.network.buffer.writePlayerId 20 | import org.lanternpowered.terre.impl.player.TeamImpl 21 | 22 | internal data class PlayerTeamPacket( 23 | val playerId: PlayerId, 24 | val team: Team 25 | ) : Packet 26 | 27 | internal val PlayerTeamEncoder = PacketEncoder { buf, packet -> 28 | buf.writePlayerId(packet.playerId) 29 | buf.writeByte((packet.team as TeamImpl).numericId) 30 | } 31 | 32 | private val teamById = TeamRegistry.all.associateBy { (it as TeamImpl).numericId } 33 | 34 | internal val PlayerTeamDecoder = PacketDecoder { buf -> 35 | val playerId = buf.readPlayerId() 36 | val teamId = buf.readByte().toInt() 37 | val team = teamById[teamId] ?: error("Unknown team id: $teamId") 38 | PlayerTeamPacket(playerId, team) 39 | } 40 | --------------------------------------------------------------------------------