mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fix: targeted voucher code not working
This commit is contained in:
@@ -33,9 +33,11 @@ class ActorValue : KVHashMap {
|
||||
hashMap = newMap
|
||||
}
|
||||
|
||||
private fun isString(key: String) = (get(key) is String)
|
||||
|
||||
override fun set(key: String, value: Any) {
|
||||
// check if the key exists and is a blob
|
||||
if (getAsString(key.toLowerCase())?.startsWith(BLOB) == true) {
|
||||
if (isString(key.toLowerCase()) && getAsString(key.toLowerCase())?.startsWith(BLOB) == true) {
|
||||
throw IllegalStateException("Cannot write plain values to the blob object")
|
||||
}
|
||||
else
|
||||
|
||||
@@ -106,7 +106,7 @@ object RedeemCodeMachine {
|
||||
bytes[bytes.size - 1] = crc16.toByte()
|
||||
|
||||
|
||||
val basePwd = initialPassword.random()
|
||||
val basePwd = initialPassword.random().copyOf()
|
||||
val receiverPwd = receiver?.toByteArray() ?: ByteArray(16) // 128 bits of something
|
||||
|
||||
// xor basePWD with receiverPwd
|
||||
@@ -124,11 +124,19 @@ object RedeemCodeMachine {
|
||||
fun decode(codeStr: String, decoderUUID: UUID? = null): RedeemVoucher? {
|
||||
val receiverPwd = decoderUUID?.toByteArray() ?: ByteArray(16) // 128 bits of something
|
||||
|
||||
val passwords = initialPassword.map { basePwd ->
|
||||
// for decrypting targeted code
|
||||
val passwords1 = initialPassword.map { basePwd ->
|
||||
ByteArray(32) { i ->
|
||||
basePwd[i] xor receiverPwd[i % 16]
|
||||
}
|
||||
}
|
||||
// for decrypting generic code
|
||||
val passwords2 = initialPassword.map { basePwd ->
|
||||
ByteArray(32) { i ->
|
||||
basePwd[i]
|
||||
}
|
||||
}
|
||||
val passwords = passwords1 + passwords2
|
||||
|
||||
// try to decode the input string by just trying all 8 possible keys
|
||||
val decodeds = passwords.map {
|
||||
@@ -149,7 +157,7 @@ object RedeemCodeMachine {
|
||||
}
|
||||
|
||||
// if all CRC fails...
|
||||
if (crcResults.none()) {
|
||||
if (crcResults.indexOf(true) < 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,18 @@ class UIRedeemCodeMachine : UICanvas(
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
private val codeCols = 12
|
||||
|
||||
val title = UIItemTextLabel(this, { "Enter the Code" },
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(14)) / 2,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(codeCols)) / 2,
|
||||
App.scr.halfh - UIItemRedeemCodeArea.estimateHeight(4) - 48 - 48,
|
||||
UIItemRedeemCodeArea.estimateWidth(14)
|
||||
UIItemRedeemCodeArea.estimateWidth(codeCols)
|
||||
)
|
||||
|
||||
val inputPanel = UIItemRedeemCodeArea(this,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(14)) / 2,
|
||||
(Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(codeCols)) / 2,
|
||||
App.scr.halfh - UIItemRedeemCodeArea.estimateHeight(4) - 48,
|
||||
14, 4)
|
||||
codeCols, 4)
|
||||
|
||||
init {
|
||||
addUIitem(title)
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import net.torvald.terrarum.modulebasegame.redeemable.RedeemCodeMachine
|
||||
import java.util.*
|
||||
|
||||
fun main() {
|
||||
val uuid = UUID.randomUUID()
|
||||
|
||||
val code = RedeemCodeMachine.encode(
|
||||
"item@basegame:65511",
|
||||
6,
|
||||
true
|
||||
true,
|
||||
null
|
||||
)
|
||||
|
||||
println(code)
|
||||
|
||||
val voucher = RedeemCodeMachine.decode(code)
|
||||
val voucher = RedeemCodeMachine.decode(code, uuid)
|
||||
|
||||
println(voucher)
|
||||
}
|
||||
Reference in New Issue
Block a user