You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Labels.kt 634B

123456789101112131415161718
  1. package com.dmdirc.ktirc.util
  2. import com.dmdirc.ktirc.IrcClient
  3. import com.dmdirc.ktirc.sasl.toBase64
  4. import java.time.ZoneOffset
  5. internal var generateLabel: (IrcClient) -> String = ::defaultGenerateLabel
  6. internal fun defaultGenerateLabel(ircClient: IrcClient): String {
  7. val time = currentTimeProvider().toEpochSecond(ZoneOffset.UTC)
  8. val counter = ircClient.serverState.asyncResponseState.labelCounter.incrementAndGet()
  9. return ByteArray(6) {
  10. when {
  11. it < 3 -> (time shr it and 0xff).toByte()
  12. else -> (counter shr (it - 3) and 0xff).toByte()
  13. }
  14. }.toBase64()
  15. }