mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2025-01-31 04:52:37 -05:00
separate FLAP from session
This commit is contained in:
parent
268cff0963
commit
d4d7f71c66
6 changed files with 17 additions and 18 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
7
flap.go
7
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
2
main.go
2
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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
2
util.go
2
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"
|
||||
|
|
Loading…
Reference in a new issue