mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-09-28 04:37:40 +02:00
parent
91f31e2353
commit
d66a31908f
@ -37,7 +37,7 @@ compileKotlin.kotlinOptions.jvmTarget = "11"
|
||||
val gitVersion: groovy.lang.Closure<String> by extra
|
||||
|
||||
group = "com.github.creeper123123321.viaaas"
|
||||
version = "0.4.9+" + try {
|
||||
version = "0.4.10+" + try {
|
||||
gitVersion()
|
||||
} catch (e: Exception) {
|
||||
"unknown"
|
||||
@ -138,9 +138,7 @@ class HtmlMinifyFilter(reader: java.io.Reader) : java.io.FilterReader("".reader(
|
||||
tasks.named<ProcessResources>("processResources") {
|
||||
filesMatching("viaaas_info.json") {
|
||||
filter<org.apache.tools.ant.filters.ReplaceTokens>(
|
||||
"tokens" to mapOf(
|
||||
"version" to project.property("version")
|
||||
)
|
||||
"tokens" to mapOf("version" to project.version)
|
||||
)
|
||||
}
|
||||
filesMatching("**/*.js") {
|
||||
|
27
src/main/java/com/viaversion/aas/command/VersionCommand.java
Normal file
27
src/main/java/com/viaversion/aas/command/VersionCommand.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.viaversion.aas.command;
|
||||
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum VersionCommand implements Command {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "Alias of 'viaver viaaas'";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> suggest(@NotNull ViaCommandSender sender, @NotNull String alias, @NotNull List<String> args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull ViaCommandSender sender, @NotNull String alias, @NotNull List<String> args) {
|
||||
ViaAspirinCommand.INSTANCE.execute(sender, alias, List.of("viaaas"));
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.aas
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import com.velocitypowered.natives.util.Natives
|
||||
import com.viaversion.aas.config.VIAaaSConfig
|
||||
@ -10,10 +11,12 @@ import com.viaversion.aas.web.WebDashboardServer
|
||||
import com.viaversion.viaversion.ViaManagerImpl
|
||||
import com.viaversion.viaversion.api.Via
|
||||
import com.viaversion.viaversion.api.protocol.packet.State
|
||||
import com.viaversion.viaversion.update.Version
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.java.*
|
||||
import io.ktor.client.features.*
|
||||
import io.ktor.client.features.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.network.tls.certificates.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
@ -36,6 +39,7 @@ object AspirinServer {
|
||||
.reader(Charsets.UTF_8)
|
||||
.readText()
|
||||
).asJsonObject.get("version").asString
|
||||
val cleanedVer get() = version.substringBefore("+")
|
||||
var viaWebServer = WebDashboardServer()
|
||||
private var serverFinishing = CompletableFuture<Unit>()
|
||||
private var finishedFuture = CompletableFuture<Unit>()
|
||||
@ -56,7 +60,7 @@ object AspirinServer {
|
||||
.build()
|
||||
val httpClient = HttpClient(Java) {
|
||||
install(UserAgent) {
|
||||
agent = "VIAaaS/${version.substringBefore("+")}"
|
||||
agent = "VIAaaS/$cleanedVer"
|
||||
}
|
||||
install(JsonFeature) {
|
||||
serializer = GsonSerializer()
|
||||
@ -91,7 +95,7 @@ object AspirinServer {
|
||||
|
||||
fun stopSignal() = serverFinishing.complete(Unit)
|
||||
fun mainFinishSignal() = finishedFuture.complete(Unit)
|
||||
fun mainStartSigal() = initFuture.complete(Unit)
|
||||
fun mainStartSignal() = initFuture.complete(Unit)
|
||||
|
||||
fun listenPorts(args: Array<String>) {
|
||||
chFuture = ServerBootstrap()
|
||||
@ -126,4 +130,20 @@ object AspirinServer {
|
||||
fun currentPlayers(): Int {
|
||||
return Via.getManager().connectionManager.connections.filter { it.protocolInfo.state == State.PLAY }.count()
|
||||
}
|
||||
|
||||
suspend fun updaterCheckMessage(): String {
|
||||
return try {
|
||||
val latestData =
|
||||
httpClient.get<JsonObject>("https://api.github.com/repos/viaversion/viaaas/releases/latest")
|
||||
val latest = Version(latestData.get("tag_name")!!.asString.removePrefix("v"))
|
||||
val current = Version(cleanedVer)
|
||||
when {
|
||||
latest > current -> "This build is outdated."
|
||||
latest < current -> "This build is newer than released."
|
||||
else -> "VIAaaS seems up to date."
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
"Failed to fetch latest release info. $e"
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,9 @@ import com.viaversion.viaversion.api.data.MappingDataLoader
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
|
||||
import de.gerrygames.viarewind.api.ViaRewindConfigImpl
|
||||
import io.ktor.application.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.io.IoBuilder
|
||||
import java.io.File
|
||||
@ -20,11 +23,12 @@ fun main(args: Array<String>) {
|
||||
try {
|
||||
setupSystem()
|
||||
printSplash()
|
||||
CoroutineScope(Dispatchers.IO).launch { viaaasLogger.info(AspirinServer.updaterCheckMessage()) }
|
||||
AspirinServer.generateCert()
|
||||
initVia()
|
||||
AspirinServer.listenPorts(args)
|
||||
|
||||
AspirinServer.mainStartSigal()
|
||||
AspirinServer.mainStartSignal()
|
||||
AspirinServer.addShutdownHook()
|
||||
|
||||
Thread { VIAaaSConsole.start() }.start()
|
||||
@ -61,7 +65,6 @@ private fun printSplash() {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun initVia() {
|
||||
Via.init(
|
||||
ViaManagerImpl.builder()
|
||||
|
@ -26,6 +26,8 @@ object VIAaaSConsole : SimpleTerminalConsole(), ViaCommandSender {
|
||||
commands["end"] = EndCommand
|
||||
commands["reload"] = ReloadCommand
|
||||
commands["list"] = ListCommand
|
||||
commands["ver"] = VersionCommand.INSTANCE
|
||||
commands["version"] = VersionCommand.INSTANCE
|
||||
}
|
||||
|
||||
override fun buildReader(builder: LineReaderBuilder): LineReader {
|
||||
|
@ -3,12 +3,16 @@ package com.viaversion.aas.command.sub
|
||||
import com.viaversion.aas.AspirinServer
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender
|
||||
import com.viaversion.viaversion.api.command.ViaSubCommand
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object VIAaaSSubCommand : ViaSubCommand() {
|
||||
override fun name(): String = "viaaas"
|
||||
override fun description(): String = "Info about VIAaaS"
|
||||
override fun execute(p0: ViaCommandSender, p1: Array<out String>): Boolean {
|
||||
p0.sendMessage("VIAaaS version ${AspirinServer.version}")
|
||||
CoroutineScope(Dispatchers.IO).launch { p0.sendMessage(AspirinServer.updaterCheckMessage()) }
|
||||
return true
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ class WebLogin : WebState {
|
||||
when (obj.getAsJsonPrimitive("action").asString) {
|
||||
"offline_login" -> {
|
||||
if (!sha512Hex(msg.toByteArray(Charsets.UTF_8)).startsWith("00000")) throw StacklessException("PoW failed")
|
||||
if ((obj.getAsJsonPrimitive("date").asLong - System.currentTimeMillis()).absoluteValue
|
||||
> Duration.ofMinutes(2).toMillis()
|
||||
if ((obj.getAsJsonPrimitive("date").asLong - System.currentTimeMillis())
|
||||
.absoluteValue > Duration.ofSeconds(20).toMillis()
|
||||
) {
|
||||
throw StacklessException("Invalid PoW date")
|
||||
}
|
||||
|
@ -195,6 +195,13 @@ function resetHtml() {
|
||||
|
||||
function ohNo() {
|
||||
try {
|
||||
icanhazepoch().then(sec => {
|
||||
if (Math.abs(Date.now() / 1000 - sec) > 15) {
|
||||
addToast("Time isn't synchronized", "Please synchronize your computer time to NTP servers");
|
||||
} else {
|
||||
console.log("time seems synchronized");
|
||||
}
|
||||
})
|
||||
new Date().getDay() == 3 && console.log("it's snapshot day 🐸 my dudes"); new Date().getDate() == 1 && new Date().getMonth() == 3 && addToast("WARNING", "Your ViaVersion has expired, please renew it at https://viaversion.com/ for $99");
|
||||
} catch (e) { console.log(e); }
|
||||
}
|
||||
|
@ -15,3 +15,10 @@ function icanhazip(cors) {
|
||||
.then(r => r.text())
|
||||
.then(it => it.trim());
|
||||
}
|
||||
|
||||
function icanhazepoch() {
|
||||
return fetch("https://icanhazepoch.com")
|
||||
.then(checkFetchSuccess("code"))
|
||||
.then(r => r.text())
|
||||
.then(it => parseInt(it.trim()))
|
||||
}
|
Loading…
Reference in New Issue
Block a user