Files
ForkWar/WebsiteBackend/src/de/steamwar/data/VelocitySync.kt
T

49 lines
1.7 KiB
Kotlin

/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.data
import de.steamwar.sql.SteamwarUser
import java.io.File
import java.nio.file.Files
object VelocitySync {
private const val SYNC_PATH = "/run/sync"
private val SYNC_FILE = File(SYNC_PATH)
private val isWindows = System.getProperty("os.name").lowercase().contains("win")
private val lastSendMap = mutableMapOf<String, Long>()
private fun sendCommand(command: String, vararg args: String) {
if (isWindows) { return }
val name = command + if (args.isNotEmpty()) "." + args.joinToString(".") else ""
if (lastSendMap[name] != null || lastSendMap[name]!! > System.currentTimeMillis() - 1000) {
return
}
lastSendMap[name] = System.currentTimeMillis()
Files.createFile(File(SYNC_FILE, name).toPath())
}
fun reloadEvent() = sendCommand(SyncCommands.RELOAD_EVENT)
fun reloadPlayer(user: SteamwarUser) = sendCommand(SyncCommands.RELOAD_PLAYER, user.id.toString())
}