-
Notifications
You must be signed in to change notification settings - Fork 9
Server Encodings
Rawky comes with a peer-to-peer server to allow painting with friends. When a server is started, a notification will open showing a password. With this password, anyone can connect to your server
Warning This kind of server provides no protection. Do not give this code to those you don't trust
To aid in mild masking of this password, not all passwords are encoded the same. Instead the server owner specifies a encoder and the users must also select the same decoder. These encoders and decoders are provided by different plugins. Many are provided but they by far do not cover all methods of encoding and decoding data
First, we'll need a plugin to work with. If you already have one, keep going. If not, define a plugin. After we have one, we'll either need to extend the Encoder class with our plugin object or create a secondary object that implements it
@Plugin(...)
object MyEncoder : Encoder("MyEncoder")
Now we need to register our encoder to the encoder registry so that it'll be picked up by the program
@Plugin(...)
object MyEncoder : Encoder("MyEncoder") {
init {
Encoder.registry[name] = this
}
}
We then need to override the encode
and decode
methods of the Encoder class to use the functions of the encoding library we're implementing
@Plugin(...)
object MyEncoder : Encoder("MyEncoder") {
override fun encode(text: ByteArray): String = Library.encode(text)
override fun decode(text: String): ByteArray = Library.decode(text)
init {
Encoder.registry[name] = this
}
}
After doing this, the encoder will now show as an option and can be used by those who have the your plugin