]> git.r.bdr.sh - rbdr/mobius/commitdiff
Improve Gtkhx compatability
authorJeff Halter <redacted>
Sat, 19 Nov 2022 20:36:57 +0000 (12:36 -0800)
committerJeff Halter <redacted>
Sat, 19 Nov 2022 20:36:57 +0000 (12:36 -0800)
hotline/transaction_handlers.go
hotline/transaction_handlers_test.go

index 6816456805f39ac414539226c843a8277e4fd510..7f8cbef4e99a6afc3e269875418432c40b1e1470 100644 (file)
@@ -248,8 +248,9 @@ func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err erro
 
        // By holding the option key, Hotline chat allows users to send /me formatted messages like:
        // *** Halcyon does stuff
-       // This is indicated by the presence of the optional field fieldChatOptions in the transaction payload
-       if t.GetField(fieldChatOptions).Data != nil {
+       // This is indicated by the presence of the optional field fieldChatOptions set to a value of 1.
+       // Most clients do not send this option for normal chat messages.
+       if t.GetField(fieldChatOptions).Data != nil && bytes.Equal(t.GetField(fieldChatOptions).Data, []byte{0, 1}) {
                formattedMsg = fmt.Sprintf("\r*** %s %s", cc.UserName, t.GetField(fieldData).Data)
        }
 
index 889859492ece04e93c81ee7bce5d71f2a11cef4e..663c622d393afdd0c398f1d45dcd4290df89224e 100644 (file)
@@ -459,7 +459,7 @@ func TestHandleChatSend(t *testing.T) {
                        wantErr: false,
                },
                {
-                       name: "sends chat msg as emote if fieldChatOptions is set",
+                       name: "sends chat msg as emote if fieldChatOptions is set to 1",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -520,6 +520,68 @@ func TestHandleChatSend(t *testing.T) {
                        },
                        wantErr: false,
                },
+               {
+                       name: "does not send chat msg as emote if fieldChatOptions is set to 0",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendChat)
+                                                       return bits
+                                               }(),
+                                       },
+                                       UserName: []byte("Testy McTest"),
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(1): {
+                                                               Account: &Account{
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
+                                                               },
+                                                               ID: &[]byte{0, 1},
+                                                       },
+                                                       uint16(2): {
+                                                               Account: &Account{
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
+                                                               },
+                                                               ID: &[]byte{0, 2},
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: &Transaction{
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte("hello")),
+                                               NewField(fieldChatOptions, []byte{0x00, 0x00}),
+                                       },
+                               },
+                       },
+                       want: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0, 0x6a},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte("\r Testy McTest:  hello")),
+                                       },
+                               },
+                               {
+                                       clientID:  &[]byte{0, 2},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0, 0x6a},
+                                       ID:        []byte{0xf0, 0xc5, 0x34, 0x1e},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte("\r Testy McTest:  hello")),
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
                {
                        name: "only sends chat msg to clients with accessReadChat permission",
                        args: args{