Created
July 29, 2018 09:51
-
-
Save Hc747/7fb24323d32aaf742fceaf364966e660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DiscordRichPresenceUpdate(private val details: String?, private val state: String?, private val key: String?) { | |
fun encode(): PacketBuilder { | |
val buffer = PacketBuilder(PACKET_ID, PacketType.BYTE) | |
val builder = PacketBuilder() | |
var mask: Byte = 0 | |
if (details != null) { | |
mask = mask xor DETAILS_MASK | |
builder.putString(details) | |
} | |
if (state != null) { | |
mask = mask xor STATE_MASK | |
builder.putString(state) | |
} | |
if (key != null) { | |
mask = mask xor KEY_MASK | |
builder.putString(key) | |
} | |
buffer.putByte(mask) | |
builder.writeTo(buffer) | |
return buffer | |
} | |
companion object { | |
const val PACKET_ID = 131 | |
const val DETAILS_MASK: Byte = 0x1 | |
const val STATE_MASK: Byte = 0x2 | |
const val KEY_MASK: Byte = 0x4 | |
//leaves 5 bits reserved for later usage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment