Skip to content

Commit

Permalink
Merge pull request #80 from RediCloud/dev
Browse files Browse the repository at this point in the history
improved server versions
  • Loading branch information
Suqatri authored Jun 13, 2024
2 parents 0590db6 + ba99b2c commit 505d9fc
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 42 deletions.
2 changes: 1 addition & 1 deletion api-files/defaultFiles/bukkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ settings:
permissions-file: permissions.yml
update-folder: update
plugin-profiling: false
connection-throttle: 4000
connection-throttle: 0
query-plugins: true
deprecated-verbose: default
shutdown-message: Server closed
Expand Down
2 changes: 1 addition & 1 deletion api-files/defaultFiles/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ listeners:
max_players: 1
tab_size: 60
force_default_server: false
ip_forward: false
ip_forward: true
remote_ping_timeout: 5000
prevent_proxy_connections: false
groups:
Expand Down
2 changes: 1 addition & 1 deletion api-files/defaultFiles/paper-global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ proxies:
proxy-protocol: false
velocity:
enabled: false
online-mode: false
online-mode: true
secret: ''
scoreboards:
save-empty-scoreboard-teams: false
Expand Down
2 changes: 1 addition & 1 deletion api-files/defaultFiles/server.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ max-tick-time=60000
require-resource-pack=false
use-native-transport=true
max-players=20
online-mode=true
online-mode=false
enable-status=true
allow-flight=false
initial-disabled-packs=
Expand Down
2 changes: 1 addition & 1 deletion api-files/defaultFiles/spigot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
settings:
debug: false
sample-count: 12
bungeecord: false
bungeecord: true
save-user-cache-on-stop-only: false
timeout-time: 60
restart-on-crash: true
Expand Down
19 changes: 1 addition & 18 deletions api-files/server-version-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@
"server.properties": {
"server-ip": "%HOSTNAME%",
"server-port": "%PORT%",
"online-mode": "false",
"max-players": "%MAX_PLAYERS%"
},
"bukkit.yml": {
"connection-throttle": "0"
},
"spigot.yml": {
"bungeecord": "true"
},
"config/paper-global.yml": {
"secret": "'%PROXY_SECRET%'",
"online-mode": "true"
"secret": "'%PROXY_SECRET%'"
}
},
"connectorPluginName": "redicloud-bukkit-connector-%cloud_version%-%branch%-%build%.jar",
Expand Down Expand Up @@ -65,14 +57,7 @@
"server.properties": {
"server-ip": "%HOSTNAME%",
"server-port": "%PORT%",
"online-mode": "false",
"max-players": "%MAX_PLAYERS%"
},
"bukkit.yml": {
"connection-throttle": "0"
},
"spigot.yml": {
"bungeecord": "true"
}
},
"connectorPluginName": "redicloud-bukkit-connector-%cloud_version%-%branch%-%build%.jar",
Expand Down Expand Up @@ -122,7 +107,6 @@
"fileEdits": {
"config.yml": {
"host": "%HOSTNAME%",
"ip_forward": "true",
"player_limit": "%MAX_PLAYERS%"
}
},
Expand All @@ -145,7 +129,6 @@
"fileEdits": {
"config.yml": {
"host": "%HOSTNAME%",
"ip_forward": "true",
"player_limit": "%MAX_PLAYERS%"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dev.redicloud.api.java.ICloudJavaVersion
import dev.redicloud.logging.LogManager
import dev.redicloud.api.utils.MINECRAFT_VERSIONS_FOLDER
import java.io.File
import java.util.concurrent.locks.ReentrantLock
import dev.redicloud.utils.SimpleLock

interface IServerVersionHandler {

Expand Down Expand Up @@ -41,7 +41,7 @@ interface IServerVersionHandler {

fun register() = registerHandler(this)

fun getLock(version: ICloudServerVersion): ReentrantLock
fun getLock(version: ICloudServerVersion): SimpleLock

suspend fun shutdown(force: Boolean, serverVersionRepository: ICloudServerVersionRepository) {
serverVersionRepository.getVersions().forEach {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildDependencies.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object BuildDependencies {
const val CLOUD_VERSION = "2.3.3-RELEASE"
const val CLOUD_VERSION = "2.3.4-SNAPSHOT"
const val CLOUD_LIBLOADER_VERSION = "1.7.0"
const val CLOUD_LIBLOADER_BOOTSTRAP = "dev.redicloud.libloader:libloader-bootstrap:1.7.0"

Expand Down
2 changes: 1 addition & 1 deletion connectors/bukkit-connector/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: redicloud-connector
version: 2.3.3-RELEASE
version: 2.3.4-SNAPSHOT
main: dev.redicloud.connector.bukkit.bootstrap.BukkitConnectorBootstrap
author: RediCloud
description: RediCloud Connector Bukkit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: redicloud-connector
version: 2.3.3-RELEASE
version: 2.3.4-SNAPSHOT
url: https://redicloud.dev
author: RediCloud
main: dev.redicloud.connector.bungeecord.bootstrap.BungeeCordConnectorBootstrap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"entrypoint": "dev.redicloud.connector.minestom.bootstrap.MinestomConnectorBootstrap",
"name": "redicloud_connector",
"version": "2.3.3-RELEASE",
"version": "2.3.4-SNAPSHOT",
"dependencies": [],
"externalDependencies": {
"repositories": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlin.system.exitProcess
@Plugin(
id = "redicloud-connector",
name = "redicloud-connector-velocity",
version = "2.3.3-RELEASE",
version = "2.3.4-SNAPSHOT",
url = "https://redicloud.dev",
authors = ["RediCloud"]
)
Expand Down
2 changes: 1 addition & 1 deletion deploy.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream

val version = "2.3.3-RELEASE"
val version = "2.3.4-SNAPSHOT"
val build = System.getenv("build_number") ?: "local"
val git = System.getenv("build_vcs_number") ?: "unknown"
val branch = System.getenv("branch")?.replace("refs/heads/", "") ?: "local"
Expand Down
2 changes: 1 addition & 1 deletion examples/example-module/src/main/resources/module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example-module",
"id": "example-module",
"version": "2.3.3-RELEASE",
"version": "2.3.4-SNAPSHOT",
"description": "An example module for redicloud",
"website": "https://redocloud.dev/",
"authors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class PaperMcServerVersionHandler(
return IServerVersionHandler.getDefaultHandler().patchCommand(type, javaVersion, jarToExecute)
}

override fun getLock(version: ICloudServerVersion): ReentrantLock {
override fun getLock(version: ICloudServerVersion): SimpleLock {
return IServerVersionHandler.getDefaultHandler().getLock(version)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/papermc-updater/src/main/resources/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "papermc-updater",
"name": "PaperMC Updater",
"description": "A simple module to automatically update software (Velocity, Paper, Folia, Waterfall) to the latest version.",
"version": "2.3.3-RELEASE",
"version": "2.3.4-SNAPSHOT",
"website": "https://docs.redicloud.dev/modules/papermc-updater",
"authors": [
"Suqatri"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class CloudServerVersionType(
result = 31 * result + (connectorDownloadUrl?.hashCode() ?: 0)
result = 31 * result + connectorFolder.hashCode()
result = 31 * result + (libPattern?.hashCode() ?: 0)
result = 31 * result + jvmArguments.hashCode()
result = 31 * result + environmentVariables.hashCode()
result = 31 * result + programParameters.hashCode()
result = 31 * result + defaultFiles.hashCode()
result = 31 * result + fileEdits.hashCode()
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CloudServerVersionTypeRepository(
if (onlineType.isUnknown()) return@forEach
if (existsType(onlineType.uniqueId)) {
val current = getType(onlineType.uniqueId)!!
if (current == onlineType) return@forEach
if (current.hashCode() == onlineType.hashCode()) return@forEach
if (!silent) LOGGER.info("Pulled server version type ${toConsoleValue(onlineType.name)} from web!")
updateType(onlineType)
serverVersionRepository.getVersions().forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.ktor.http.*
import java.io.File
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
import java.util.regex.Pattern
import kotlin.time.Duration.Companion.minutes
Expand All @@ -38,10 +39,10 @@ open class URLServerVersionHandler(
private val logger = LogManager.logger(URLServerVersionHandler::class)
}

protected val locks = mutableMapOf<UUID, ReentrantLock>()
protected val locks = mutableMapOf<UUID, SimpleLock>()

override fun getLock(version: ICloudServerVersion): ReentrantLock {
return locks.getOrPut(version.uniqueId) { ReentrantLock() }
override fun getLock(version: ICloudServerVersion): SimpleLock {
return locks.getOrPut(version.uniqueId) { SimpleLock() }
}

override suspend fun download(version: ICloudServerVersion, force: Boolean, lock: Boolean): File {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class FileCopier(
versionHandler.getLock(snapshot.version).withLock {
runBlocking {
if (!versionHandler.isPatched(snapshot.version) && versionHandler.isPatchVersion(snapshot.version)) {
versionHandler.patch(snapshot.version)
versionHandler.patch(snapshot.version, lock = false)
}else if(!versionHandler.isDownloaded(snapshot.version)) {
versionHandler.download(snapshot.version)
versionHandler.download(snapshot.version, lock = false)
}
if (force && configurationTemplate.static || !configurationTemplate.static) {
versionHandler.getFolder(snapshot.version).copyRecursively(workDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class VersionCommand(
}
val updateInfo = Updater.updateAvailable()
if (updateInfo.first && updateInfo.second != null) {
actor.sendMessage("An update is available: %hc%${updateInfo.second}")
actor.sendMessage("An update is available: %hc%${updateInfo.second!!.branch}§8#%tc%${updateInfo.second!!.build} §8(%tc%${updateInfo.second!!.version}§8)")
actor.sendMessage("You can download the update with the command: %hc%version download $BRANCH ${updateInfo.second}")
actor.sendMessage("And switch the update with the command: %hc%version switch $BRANCH ${updateInfo.second}")
actor.sendMessage("And switch the update with the command: %hc%version switch $BRANCH ${updateInfo.second!!.build}")
} else {
actor.sendMessage("You are running the latest version!")
}
Expand Down
81 changes: 81 additions & 0 deletions utils/src/main/kotlin/dev/redicloud/utils/SimpleLock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package dev.redicloud.utils

import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.Condition
import java.util.concurrent.locks.Lock

class SimpleLock : Lock {

private val state = AtomicBoolean(false)
private val lockThreadId = ThreadLocal<Long>()
val isLocked: Boolean
get() = state.get()

override fun lock() {
if (lockThreadId.get() == Thread.currentThread().id) {
return
}
while (!state.compareAndSet(false, true)) {
try {
Thread.sleep(2)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}
lockThreadId.set(Thread.currentThread().id)
}

override fun lockInterruptibly() {
if (lockThreadId.get() == Thread.currentThread().id) {
return
}
while (!state.compareAndSet(false, true)) {
if (Thread.interrupted()) {
throw InterruptedException()
}
try {
Thread.sleep(2)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}
lockThreadId.set(Thread.currentThread().id)
}

override fun tryLock(): Boolean {
val result = state.compareAndSet(false, true)
if (result) {
lockThreadId.set(Thread.currentThread().id)
}
return result
}

override fun tryLock(time: Long, unit: TimeUnit): Boolean {
if (lockThreadId.get() == Thread.currentThread().id) {
return true
}
val end = System.currentTimeMillis() + unit.toMillis(time)
while (!state.compareAndSet(false, true)) {
if (System.currentTimeMillis() >= end) {
return false
}
try {
Thread.sleep(2)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}
lockThreadId.set(Thread.currentThread().id)
return true
}

override fun unlock() {
state.set(false)
lockThreadId.set(null)
}

override fun newCondition(): Condition {
throw UnsupportedOperationException()
}
}

0 comments on commit 505d9fc

Please sign in to comment.