diff --git a/0x17_authorization_registration_service.go b/0x17_authorization_registration_service.go index d9952f8..f63779f 100644 --- a/0x17_authorization_registration_service.go +++ b/0x17_authorization_registration_service.go @@ -50,7 +50,7 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi snac := NewSNAC(0x17, 0x03) snac.Data.WriteBinary(usernameTLV) snac.Data.WriteBinary(NewTLV(0x08, []byte{0, 4})) - resp := NewFLAP(session, 2) + resp := NewFLAP(2) resp.Data.WriteBinary(snac) return session.Send(resp) } @@ -65,7 +65,7 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi snac.Data.WriteUint16(uint16(len(user.Cipher))) snac.Data.WriteString(user.Cipher) - resp := NewFLAP(session, 2) + resp := NewFLAP(2) resp.Data.WriteBinary(snac) return session.Send(resp) @@ -90,7 +90,7 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi snac := NewSNAC(0x17, 0x03) snac.Data.WriteBinary(usernameTLV) snac.Data.WriteBinary(NewTLV(0x08, []byte{0, 4})) - resp := NewFLAP(session, 2) + resp := NewFLAP(2) resp.Data.WriteBinary(snac) return session.Send(resp) } @@ -111,12 +111,12 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi badPasswordSnac := NewSNAC(0x17, 0x03) badPasswordSnac.Data.WriteBinary(usernameTLV) badPasswordSnac.Data.WriteBinary(NewTLV(0x08, []byte{0, 4})) - badPasswordFlap := NewFLAP(session, 2) + badPasswordFlap := NewFLAP(2) badPasswordFlap.Data.WriteBinary(badPasswordSnac) session.Send(badPasswordFlap) // Tell tem to leave - discoFlap := NewFLAP(session, 4) + discoFlap := NewFLAP(4) return session.Send(discoFlap) } @@ -125,12 +125,12 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi authSnac.Data.WriteBinary(usernameTLV) authSnac.Data.WriteBinary(NewTLV(0x5, []byte("10.0.1.2:5191"))) authSnac.Data.WriteBinary(NewTLV(0x6, []byte(`{"hello": "uwu"}`))) - authFlap := NewFLAP(session, 2) + authFlap := NewFLAP(2) authFlap.Data.WriteBinary(authSnac) session.Send(authFlap) // Tell tem to leave - discoFlap := NewFLAP(session, 4) + discoFlap := NewFLAP(4) return session.Send(discoFlap) } diff --git a/flap.go b/flap.go index 1507779..ca42097 100644 --- a/flap.go +++ b/flap.go @@ -21,13 +21,12 @@ type FLAP struct { Data Buffer } -func NewFLAP(session *Session, channel uint8) *FLAP { - session.SequenceNumber += 1 - +func NewFLAP(channel uint8) *FLAP { return &FLAP{ Header: FLAPHeader{ Channel: channel, - SequenceNumber: uint16(session.SequenceNumber), + SequenceNumber: 0, + DataLength: 0, }, } } diff --git a/flap_test.go b/flap_test.go index 4826f23..ff7635f 100644 --- a/flap_test.go +++ b/flap_test.go @@ -6,8 +6,7 @@ import ( ) func TestFLAP(t *testing.T) { - session := Session{} - hello := NewFLAP(&session, 1) + hello := NewFLAP(1) hello.Data.Write([]byte{0, 0, 0, 1}) b, err := hello.MarshalBinary() diff --git a/main.go b/main.go index 1410253..bcd4f37 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,7 @@ func handleTCPConnection(db *bun.DB, session *Session, conn net.Conn) { for { if !session.GreetedClient { // send a hello - hello := NewFLAP(session, 1) + hello := NewFLAP(1) hello.Data.Write([]byte{0, 0, 0, 1}) err := session.Send(hello) panicIfError(err) diff --git a/session.go b/session.go index ff4f9ae..f60ca9f 100644 --- a/session.go +++ b/session.go @@ -2,7 +2,6 @@ package main import ( "context" - "encoding" "fmt" "net" @@ -46,8 +45,10 @@ func CurrentSession(ctx context.Context) (session *Session, err error) { return s.(*Session), nil } -func (s *Session) Send(m encoding.BinaryMarshaler) error { - bytes, err := m.MarshalBinary() +func (s *Session) Send(flap *FLAP) error { + s.SequenceNumber += 1 + flap.Header.SequenceNumber = s.SequenceNumber + bytes, err := flap.MarshalBinary() if err != nil { return errors.Wrap(err, "could not marshal message") } diff --git a/util.go b/util.go index 4053c1b..50a26e8 100644 --- a/util.go +++ b/util.go @@ -38,7 +38,7 @@ func prettyBytes(bytes []byte) string { if err != nil || (n < 32 || n > 126) { res += "." } else { - res += string(n) + res += string(rune(n)) } } res += "|\n"