mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	Initial work on multi-server bridge from a while back.
This commit is contained in:
		@ -1,6 +1,6 @@
 | 
			
		||||
plugins {
 | 
			
		||||
  `kotlin-dsl`
 | 
			
		||||
  kotlin("plugin.serialization") version "1.5.31"
 | 
			
		||||
  kotlin("plugin.serialization") version "1.6.21"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
repositories {
 | 
			
		||||
@ -8,10 +8,10 @@ repositories {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
  implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
 | 
			
		||||
  implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.10")
 | 
			
		||||
  implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.1")
 | 
			
		||||
  implementation("com.google.code.gson:gson:2.8.9")
 | 
			
		||||
  implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
 | 
			
		||||
  implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.21")
 | 
			
		||||
  implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
 | 
			
		||||
  implementation("com.google.code.gson:gson:2.9.0")
 | 
			
		||||
  implementation("org.bouncycastle:bcprov-jdk15on:1.70")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ dependencies {
 | 
			
		||||
  implementation("net.dv8tion:JDA:5.0.0-alpha.2") {
 | 
			
		||||
    exclude(module = "opus-java")
 | 
			
		||||
  }
 | 
			
		||||
  implementation("com.rabbitmq:amqp-client:5.14.2")
 | 
			
		||||
 | 
			
		||||
  compileOnly(project(":foundation-core"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,11 @@
 | 
			
		||||
package cloud.kubelet.foundation.bifrost
 | 
			
		||||
 | 
			
		||||
import io.papermc.paper.event.player.AsyncChatEvent
 | 
			
		||||
import org.bukkit.event.player.PlayerJoinEvent
 | 
			
		||||
import org.bukkit.event.player.PlayerQuitEvent
 | 
			
		||||
 | 
			
		||||
interface EventHandler {
 | 
			
		||||
  fun onPlayerJoin(e: PlayerJoinEvent)
 | 
			
		||||
  fun onPlayerQuit(e: PlayerQuitEvent)
 | 
			
		||||
  fun onChat(e: AsyncChatEvent)
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,26 @@
 | 
			
		||||
package cloud.kubelet.foundation.bifrost
 | 
			
		||||
 | 
			
		||||
import cloud.kubelet.foundation.bifrost.model.BifrostMessageQueueConfig
 | 
			
		||||
import cloud.kubelet.foundation.bifrost.model.BifrostMultiConfig
 | 
			
		||||
import com.rabbitmq.client.Connection
 | 
			
		||||
import com.rabbitmq.client.ConnectionFactory
 | 
			
		||||
import io.papermc.paper.event.player.AsyncChatEvent
 | 
			
		||||
 | 
			
		||||
class MultiServerEventHandler(config: BifrostMultiConfig) : EventHandler {
 | 
			
		||||
  private val bus = buildConnection(config.messageQueue)
 | 
			
		||||
  private val channel = bus.createChannel()
 | 
			
		||||
 | 
			
		||||
  init {
 | 
			
		||||
    channel.queueDeclare(config.messageQueue.queueName, false, false, false, emptyMap())
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun onChat(e: AsyncChatEvent) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private companion object {
 | 
			
		||||
    fun buildConnection(config: BifrostMessageQueueConfig): Connection = ConnectionFactory().apply {
 | 
			
		||||
      host = config.host
 | 
			
		||||
      port = config.port
 | 
			
		||||
    }.newConnection()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,19 @@
 | 
			
		||||
package cloud.kubelet.foundation.bifrost.model
 | 
			
		||||
 | 
			
		||||
import kotlinx.serialization.Serializable
 | 
			
		||||
 | 
			
		||||
@Serializable
 | 
			
		||||
data class BifrostMultiConfig(
 | 
			
		||||
  val messageQueue: BifrostMessageQueueConfig,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@Serializable
 | 
			
		||||
data class BifrostMessageQueueConfig(
 | 
			
		||||
  val host: String = "localhost",
 | 
			
		||||
  val port: Int = 5672,
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Name of the RabbitMQ queue
 | 
			
		||||
   */
 | 
			
		||||
  val queueName: String = "bifrost",
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										5
									
								
								foundation-bifrost/src/main/resources/bifrost-multi.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								foundation-bifrost/src/main/resources/bifrost-multi.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
# Configuration for the Bifrost multi-server chat bridge.
 | 
			
		||||
 | 
			
		||||
messageQueue:
 | 
			
		||||
  host: localhost
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@ -1,5 +1,5 @@
 | 
			
		||||
distributionBase=GRADLE_USER_HOME
 | 
			
		||||
distributionPath=wrapper/dists
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
 | 
			
		||||
zipStoreBase=GRADLE_USER_HOME
 | 
			
		||||
zipStorePath=wrapper/dists
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user