Files
2006Scape/2006Scape Server/plugins/plugin/integration/website/PlayersOnlineWebsite.kt
T
Dark98 e1efbb0fdf Website Integration Rewrite, Upgrades & Plugin Migration
- Remove synchronous website integration execution from the GameEngine 600ms tick loop
- Decouple website credentials and toggles from ConfigLoader, secrets.json, and Constants.WEBSITE_INTEGRATION
- Introduce modular "website" configuration group with independent toggles for players_online and registered_accounts
- Consolidate background tasks onto a single daemon ScheduledExecutorService with graceful lifecycle management via ServerStartupEvent and ServerShutdownEvent
- Optimize character directory counting with Java NIO streaming to prevent heap allocations
- Add UTF-8 URL encoding, User-Agent headers, safe stream handling, and network exception throttling
2026-11-13 01:12:15 +00:00

51 lines
1.3 KiB
Kotlin

package plugin.integration.website
import com.rs2.Constants
import com.rs2.game.players.PlayerHandler
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
object PlayersOnlineWebsite {
private var task: ScheduledFuture<*>? = null
fun start() {
if (!WebsiteConfig.playersOnline) {
return
}
if (WebsiteConfig.password.isEmpty()) {
WebsiteService.warnMissingPassword()
return
}
stop()
task = WebsiteService.getScheduler().scheduleAtFixedRate({
try {
update()
} catch (e: Exception) {
if (Constants.SERVER_DEBUG) {
e.printStackTrace()
} else {
System.err.println("[WebsiteIntegration] Error in PlayersOnlineWebsite task: ${e.message}")
}
}
}, 10, 30, TimeUnit.SECONDS)
}
fun stop() {
task?.cancel(true)
task = null
}
fun update() {
val pass = WebsiteConfig.password
if (pass.isEmpty()) return
WebsiteService.sendGetRequest("playersonline.php", mapOf(
"pass" to pass,
"amount" to PlayerHandler.getPlayerCount(),
"world" to Constants.WORLD
))
}
}