Skip to content

Commit

Permalink
optional struct tag for SNAC(0x01,0x10) evil notif
Browse files Browse the repository at this point in the history
Instead of having two separate structs for the evil notification
struct, we now have just one struct that leverages the optional
field to indicate whether the warning is anonymous or not.
  • Loading branch information
mk6i committed Jul 12, 2024
1 parent ef3b784 commit 723e8cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
15 changes: 8 additions & 7 deletions foodgroup/icbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,20 @@ func (s ICBMService) EvilRequest(ctx context.Context, sess *state.Session, inFra
}
recipSess.IncrementWarning(increase)

var notif any
notif := wire.SNAC_0x01_0x10_OServiceEvilNotification{
NewEvil: recipSess.Warning(),
}

// append info about user who sent the warning
if inBody.SendAs == 0 {
notif = wire.SNAC_0x01_0x10_OServiceEvilNotification{
NewEvil: recipSess.Warning(),
notif.Snitcher = &struct {
wire.TLVUserInfo
}{
TLVUserInfo: wire.TLVUserInfo{
ScreenName: sess.DisplayScreenName().String(),
WarningLevel: sess.Warning(),
},
}
} else {
notif = wire.SNAC_0x01_0x10_OServiceEvilNotificationAnon{
NewEvil: recipSess.Warning(),
}
}

s.messageRelayer.RelayToScreenName(ctx, recipSess.IdentScreenName(), wire.SNACMessage{
Expand Down
12 changes: 8 additions & 4 deletions foodgroup/icbm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func TestICBMService_EvilRequest(t *testing.T) {
FoodGroup: wire.OService,
SubGroup: wire.OServiceEvilNotification,
},
Body: wire.SNAC_0x01_0x10_OServiceEvilNotificationAnon{
Body: wire.SNAC_0x01_0x10_OServiceEvilNotification{
NewEvil: evilDeltaAnon,
},
},
Expand Down Expand Up @@ -438,9 +438,13 @@ func TestICBMService_EvilRequest(t *testing.T) {
},
Body: wire.SNAC_0x01_0x10_OServiceEvilNotification{
NewEvil: evilDelta,
TLVUserInfo: wire.TLVUserInfo{
ScreenName: "sender-screen-name",
WarningLevel: 110,
Snitcher: &struct {
wire.TLVUserInfo
}{
wire.TLVUserInfo{
ScreenName: "sender-screen-name",
WarningLevel: 110,
},
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions wire/snacs.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ type SNAC_0x01_0x0F_OServiceUserInfoUpdate struct {

type SNAC_0x01_0x10_OServiceEvilNotification struct {
NewEvil uint16
TLVUserInfo
}

type SNAC_0x01_0x10_OServiceEvilNotificationAnon struct {
NewEvil uint16
// Snitcher specifies the user who sent the warning. Nil pointer indicates
// an anonymous warning.
Snitcher *struct {
TLVUserInfo
} `oscar:"optional"`
}

type SNAC_0x01_0x11_OServiceIdleNotification struct {
Expand Down

0 comments on commit 723e8cc

Please sign in to comment.