Fix LoginMessage and ConnectToWorldReqMsg token

The decoding was wrong. ASCII was the wrong choice. We needed a cstring
and to add padding instead of assuming a fixed size.

Fixes and closes #2
This commit is contained in:
Chord 2016-05-19 03:11:15 -04:00
parent f1fae83548
commit 5ed40e73b3
3 changed files with 6 additions and 4 deletions

View file

@ -8,6 +8,7 @@ import scodec.codecs._
// NOTE: this packet has a ton of bytes left over at the end and is usually all zeros
// except for the server name and a 0x80 near the end
final case class ConnectToWorldRequestMessage(server : String,
token : String,
majorVersion : Long,
minorVersion : Long,
revision : Long,
@ -21,7 +22,7 @@ final case class ConnectToWorldRequestMessage(server : String,
object ConnectToWorldRequestMessage extends Marshallable[ConnectToWorldRequestMessage] {
implicit val codec : Codec[ConnectToWorldRequestMessage] = (
("server_name" | PacketHelpers.encodedString) ::
("unknown" | ignore(32*8)) ::
("token" | paddedFixedSizeBytes(32, cstring, ignore(8))) :: // must be an ignore 8 as the memory might not be 0x00
("major_version" | uint32L) ::
("minor_version" | uint32L) ::
("revision" | uint32L) ::

View file

@ -25,7 +25,7 @@ final case class LoginMessage(majorVersion : Long,
object LoginMessage extends Marshallable[LoginMessage] {
private def username = PacketHelpers.encodedStringAligned(7)
private def password = PacketHelpers.encodedString
private def tokenPath = fixedSizeBytes(32, ascii) :: username
private def tokenPath = paddedFixedSizeBytes(32, cstring, ignore(8)) :: username
private def passwordPath = username :: password
type Struct = String :: Option[String] :: Option[String] :: HNil