feat: netty server default port (#2822)

* use port 15000 by default for netty server

* fix detekt issue

* update theme readme
This commit is contained in:
Senk Ju
2024-04-15 22:14:22 +02:00
committed by GitHub
parent 9e2e66d62c
commit 38b8ce9f90
2 changed files with 16 additions and 4 deletions

View File

@@ -9,8 +9,7 @@ This directory contains the source code of LiquidBounce's default theme made wit
1. Install [Node.js](https://nodejs.org/en) on your computer (either latest or stable should be fine).
2. Install required dependencies using `npm install`.
3. Set `IN_DEV` in [host.ts](https://github.com/CCBlueX/LiquidBounce/blob/nextgen/src-theme/src/integration/host.ts) to `true`.
4. Change `PORT` to `15000` in [NettyServer.kt](https://github.com/CCBlueX/LiquidBounce/blob/nextgen/src/main/kotlin/net/ccbluex/liquidbounce/web/socket/netty/NettyServer.kt).
5. Launch the client.
6. Run `npm run dev` to start a development server.
4. Launch the client.
5. Run `npm run dev` to start a development server.
Make sure not to push the changes made to `host.ts` and `NettyServer.kt`!

View File

@@ -30,15 +30,28 @@ import io.netty.handler.logging.LogLevel
import io.netty.handler.logging.LoggingHandler
import net.ccbluex.liquidbounce.utils.client.ErrorHandler
import net.ccbluex.liquidbounce.utils.client.logger
import java.net.Socket
internal class NettyServer {
companion object {
val PORT = (15000..17000).random()
private const val DEFAULT_PORT = 15000
val PORT = findAvailablePort()
val NETTY_ROOT = "http://127.0.0.1:$PORT"
@Suppress("SwallowedException")
private fun findAvailablePort() = try {
Socket("localhost", DEFAULT_PORT).use {
logger.info("Default port unavailable. Falling back to random port.")
(15001..17000).random()
}
} catch (e: Exception) {
logger.info("Default port $DEFAULT_PORT available.")
DEFAULT_PORT
}
}
fun startServer(port: Int = PORT) {