die less often

This commit is contained in:
Artem Titoulenko 2022-01-18 16:20:51 -05:00
parent 56c355b147
commit 3f59eb0056
3 changed files with 26 additions and 4 deletions

View file

@ -230,7 +230,12 @@ func main() {
if service, ok := serviceManager.GetService(snac.Header.Family); ok { if service, ok := serviceManager.GetService(snac.Header.Family); ok {
newCtx, err := service.HandleSNAC(ctx, db, snac) newCtx, err := service.HandleSNAC(ctx, db, snac)
util.PanicIfError(err) if err != nil {
log.Printf("encountered error: %s", err)
session.Disconnect()
handleCloseFn(ctx, session)
}
return newCtx return newCtx
} }
} else if flap.Header.Channel == 4 { } else if flap.Header.Channel == 4 {

View file

@ -52,7 +52,6 @@ func (s *LocationServices) HandleSNAC(ctx context.Context, db *bun.DB, snac *osc
} }
user.AwayMessage = string(awayMessageTLV.Data) user.AwayMessage = string(awayMessageTLV.Data)
user.AwayMessageEncoding = string(awayMessageMimeTLV.Data) user.AwayMessageEncoding = string(awayMessageMimeTLV.Data)
} }
profileTLV := oscar.FindTLV(tlvs, 0x2) profileTLV := oscar.FindTLV(tlvs, 0x2)
@ -95,6 +94,14 @@ func (s *LocationServices) HandleSNAC(ctx context.Context, db *bun.DB, snac *osc
if err != nil { if err != nil {
return ctx, aimerror.FetchingUser(err, requestedScreenName) return ctx, aimerror.FetchingUser(err, requestedScreenName)
} }
if requestedUser == nil {
noMatchSnac := oscar.NewSNAC(0x2, 1)
noMatchSnac.Data.WriteUint16(0x14) // error code 0x14: No Match
noMatchFlap := oscar.NewFLAP(2)
noMatchFlap.Data.WriteBinary(noMatchSnac)
session.Send(noMatchFlap)
return ctx, nil
}
respSnac := oscar.NewSNAC(2, 6) respSnac := oscar.NewSNAC(2, 6)
respSnac.Data.WriteLPString(requestedUser.ScreenName) respSnac.Data.WriteLPString(requestedUser.ScreenName)

View file

@ -48,7 +48,12 @@ func (b *BuddyListManagement) HandleSNAC(ctx context.Context, db *bun.DB, snac *
return ctx, errors.Wrap(err, "error looking for User") return ctx, errors.Wrap(err, "error looking for User")
} }
if buddy == nil { if buddy == nil {
return ctx, aimerror.UserNotFound(buddyScreename) noMatchSnac := oscar.NewSNAC(0x3, 1)
noMatchSnac.Data.WriteUint16(0x14) // error code 0x14: No Match
noMatchFlap := oscar.NewFLAP(2)
noMatchFlap.Data.WriteBinary(noMatchSnac)
session.Send(noMatchFlap)
return ctx, nil
} }
rel := &models.Buddy{ rel := &models.Buddy{
@ -84,7 +89,12 @@ func (b *BuddyListManagement) HandleSNAC(ctx context.Context, db *bun.DB, snac *
return ctx, errors.Wrap(err, "error looking for User") return ctx, errors.Wrap(err, "error looking for User")
} }
if buddy == nil { if buddy == nil {
return ctx, aimerror.UserNotFound(buddyScreename) noMatchSnac := oscar.NewSNAC(0x3, 1)
noMatchSnac.Data.WriteUint16(0x14) // error code 0x14: No Match
noMatchFlap := oscar.NewFLAP(2)
noMatchFlap.Data.WriteBinary(noMatchSnac)
session.Send(noMatchFlap)
return ctx, nil
} }
_, err = db.NewDelete().Model((*models.Buddy)(nil)).Where("source_uin = ?", user.UIN).Where("with_uin = ?", buddy.UIN).Exec(ctx) _, err = db.NewDelete().Model((*models.Buddy)(nil)).Where("source_uin = ?", user.UIN).Where("with_uin = ?", buddy.UIN).Exec(ctx)