]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/transaction_handlers_test.go
Use fixed size array types in Transaction fields
[rbdr/mobius] / hotline / transaction_handlers_test.go
index cb9e21f301a117faf12188fd9e24b99b226c8baa..9ea4a0a11f72afe28c31a74e6fb35de567445a1d 100644 (file)
@@ -5,8 +5,8 @@ import (
        "fmt"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/mock"
+       "io"
        "io/fs"
-       "math/rand"
        "os"
        "path/filepath"
        "strings"
@@ -67,40 +67,29 @@ func TestHandleSetChatSubject(t *testing.T) {
                                        },
                                },
                                t: &Transaction{
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0, 0, 0, 1},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Type: [2]byte{0, 0x6a},
+                                       ID:   [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldChatSubject, []byte("Test Subject")),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldChatSubject, []byte("Test Subject")),
                                        },
                                },
                        },
                        want: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x77},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x77},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldChatSubject, []byte("Test Subject")),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldChatSubject, []byte("Test Subject")),
                                        },
                                },
                                {
-                                       clientID:  &[]byte{0, 2},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x77},
-                                       ID:        []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 2},
+                                       Type:     [2]byte{0, 0x77},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldChatSubject, []byte("Test Subject")),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldChatSubject, []byte("Test Subject")),
                                        },
                                },
                        },
@@ -108,15 +97,13 @@ func TestHandleSetChatSubject(t *testing.T) {
                },
        }
        for _, tt := range tests {
-               rand.Seed(1) // reset seed between tests to make transaction IDs predictable
-
                t.Run(tt.name, func(t *testing.T) {
                        got, err := HandleSetChatSubject(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleSetChatSubject() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
-                       if !assert.Equal(t, tt.want, got) {
+                       if !tranAssertEqual(t, tt.want, got) {
                                t.Errorf("HandleSetChatSubject() got = %v, want %v", got, tt.want)
                        }
                })
@@ -174,19 +161,17 @@ func TestHandleLeaveChat(t *testing.T) {
                                                },
                                        },
                                },
-                               t: NewTransaction(tranDeleteUser, nil, NewField(fieldChatID, []byte{0, 0, 0, 1})),
+                               t: NewTransaction(TranDeleteUser, nil, NewField(FieldChatID, []byte{0, 0, 0, 1})),
                        },
                        want: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x76},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Flags:    0x00,
+                                       IsReply:  0x00,
+                                       Type:     [2]byte{0, 0x76},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldUserID, []byte{0, 2}),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldUserID, []byte{0, 2}),
                                        },
                                },
                        },
@@ -194,14 +179,13 @@ func TestHandleLeaveChat(t *testing.T) {
                },
        }
        for _, tt := range tests {
-               rand.Seed(1)
                t.Run(tt.name, func(t *testing.T) {
                        got, err := HandleLeaveChat(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleLeaveChat() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
-                       if !assert.Equal(t, tt.want, got) {
+                       if !tranAssertEqual(t, tt.want, got) {
                                t.Errorf("HandleLeaveChat() got = %v, want %v", got, tt.want)
                        }
                })
@@ -232,45 +216,29 @@ func TestHandleGetUserNameList(t *testing.T) {
                                                                Icon:     []byte{0, 2},
                                                                Flags:    []byte{0, 3},
                                                                UserName: []byte{0, 4},
-                                                               Agreed:   true,
                                                        },
                                                        uint16(2): {
                                                                ID:       &[]byte{0, 2},
                                                                Icon:     []byte{0, 2},
                                                                Flags:    []byte{0, 3},
                                                                UserName: []byte{0, 4},
-                                                               Agreed:   true,
-                                                       },
-                                                       uint16(3): {
-                                                               ID:       &[]byte{0, 3},
-                                                               Icon:     []byte{0, 2},
-                                                               Flags:    []byte{0, 3},
-                                                               UserName: []byte{0, 4},
-                                                               Agreed:   false,
                                                        },
                                                },
                                        },
                                },
-                               t: &Transaction{
-                                       ID:   []byte{0, 0, 0, 1},
-                                       Type: []byte{0, 1},
-                               },
+                               t: &Transaction{},
                        },
                        want: []Transaction{
                                {
-                                       clientID:  &[]byte{1, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 1},
-                                       ID:        []byte{0, 0, 0, 1},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{1, 1},
+                                       IsReply:  0x01,
                                        Fields: []Field{
                                                NewField(
-                                                       fieldUsernameWithInfo,
+                                                       FieldUsernameWithInfo,
                                                        []byte{00, 01, 00, 02, 00, 03, 00, 02, 00, 04},
                                                ),
                                                NewField(
-                                                       fieldUsernameWithInfo,
+                                                       FieldUsernameWithInfo,
                                                        []byte{00, 02, 00, 02, 00, 03, 00, 02, 00, 04},
                                                ),
                                        },
@@ -333,31 +301,81 @@ func TestHandleChatSend(t *testing.T) {
                                },
                                t: &Transaction{
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("hai")),
+                                               NewField(FieldData, []byte("hai")),
                                        },
                                },
                        },
                        want: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Flags:    0x00,
+                                       IsReply:  0x00,
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
                                        },
                                },
                                {
-                                       clientID:  &[]byte{0, 2},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 2},
+                                       Flags:    0x00,
+                                       IsReply:  0x00,
+                                       Type:     [2]byte{0, 0x6a},
+                                       Fields: []Field{
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
+               {
+                       name: "treats Chat ID 00 00 00 00 as a public chat message",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendChat)
+                                                       return bits
+                                               }(),
+                                       },
+                                       UserName: []byte{0x00, 0x01},
+                                       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("hai")),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 0}),
+                                       },
+                               },
+                       },
+                       want: []Transaction{
+                               {
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x6a},
+                                       Fields: []Field{
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                       },
+                               },
+                               {
+                                       clientID: &[]byte{0, 2},
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
                                        },
                                },
                        },
@@ -378,26 +396,23 @@ func TestHandleChatSend(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranChatSend, &[]byte{0, 1},
-                                       NewField(fieldData, []byte("hai")),
+                                       TranChatSend, &[]byte{0, 1},
+                                       NewField(FieldData, []byte("hai")),
                                ),
                        },
                        want: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to participate in chat.")),
+                                               NewField(FieldError, []byte("You are not allowed to participate in chat.")),
                                        },
                                },
                        },
                        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{
@@ -427,32 +442,82 @@ func TestHandleChatSend(t *testing.T) {
                                },
                                t: &Transaction{
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("performed action")),
-                                               NewField(fieldChatOptions, []byte{0x00, 0x01}),
+                                               NewField(FieldData, []byte("performed action")),
+                                               NewField(FieldChatOptions, []byte{0x00, 0x01}),
                                        },
                                },
                        },
                        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},
+                                       clientID: &[]byte{0, 1},
+                                       Flags:    0x00,
+                                       IsReply:  0x00,
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("\r*** Testy McTest performed action")),
+                                               NewField(FieldData, []byte("\r*** Testy McTest performed action")),
                                        },
                                },
                                {
-                                       clientID:  &[]byte{0, 2},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0xf0, 0xc5, 0x34, 0x1e},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 2},
+                                       Flags:    0x00,
+                                       IsReply:  0x00,
+                                       Type:     [2]byte{0, 0x6a},
+                                       Fields: []Field{
+                                               NewField(FieldData, []byte("\r*** Testy McTest performed action")),
+                                       },
+                               },
+                       },
+                       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},
+                                       Type:     [2]byte{0, 0x6a},
+                                       Fields: []Field{
+                                               NewField(FieldData, []byte("\r Testy McTest:  hello")),
+                                       },
+                               },
+                               {
+                                       clientID: &[]byte{0, 2},
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("\r*** Testy McTest performed action")),
+                                               NewField(FieldData, []byte("\r Testy McTest:  hello")),
                                        },
                                },
                        },
@@ -492,20 +557,16 @@ func TestHandleChatSend(t *testing.T) {
                                },
                                t: &Transaction{
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("hai")),
+                                               NewField(FieldData, []byte("hai")),
                                        },
                                },
                        },
                        want: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
                                        },
                                },
                        },
@@ -560,34 +621,26 @@ func TestHandleChatSend(t *testing.T) {
                                },
                                t: &Transaction{
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("hai")),
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldData, []byte("hai")),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
                                        },
                                },
                        },
                        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},
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
                                        },
                                },
                                {
-                                       clientID:  &[]byte{0, 2},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x6a},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 2},
+                                       Type:     [2]byte{0, 0x6a},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0, 0, 0, 1}),
-                                               NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
+                                               NewField(FieldChatID, []byte{0, 0, 0, 1}),
+                                               NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
                                        },
                                },
                        },
@@ -608,8 +661,6 @@ func TestHandleChatSend(t *testing.T) {
 }
 
 func TestHandleGetFileInfo(t *testing.T) {
-       rand.Seed(1) // reset seed between tests to make transaction IDs predictable
-
        type args struct {
                cc *ClientConn
                t  *Transaction
@@ -636,28 +687,24 @@ func TestHandleGetFileInfo(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetFileInfo, nil,
-                                       NewField(fieldFileName, []byte("testfile.txt")),
-                                       NewField(fieldFilePath, []byte{0x00, 0x00}),
+                                       TranGetFileInfo, nil,
+                                       NewField(FieldFileName, []byte("testfile.txt")),
+                                       NewField(FieldFilePath, []byte{0x00, 0x00}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xce},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Type:     [2]byte{0, 0},
                                        Fields: []Field{
-                                               NewField(fieldFileName, []byte("testfile.txt")),
-                                               NewField(fieldFileTypeString, []byte("Text File")),
-                                               NewField(fieldFileCreatorString, []byte("ttxt")),
-                                               NewField(fieldFileComment, []byte{}),
-                                               NewField(fieldFileType, []byte("TEXT")),
-                                               NewField(fieldFileCreateDate, make([]byte, 8)),
-                                               NewField(fieldFileModifyDate, make([]byte, 8)),
-                                               NewField(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
+                                               NewField(FieldFileName, []byte("testfile.txt")),
+                                               NewField(FieldFileTypeString, []byte("Text File")),
+                                               NewField(FieldFileCreatorString, []byte("ttxt")),
+                                               NewField(FieldFileType, []byte("TEXT")),
+                                               NewField(FieldFileCreateDate, make([]byte, 8)),
+                                               NewField(FieldFileModifyDate, make([]byte, 8)),
+                                               NewField(FieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
                                        },
                                },
                        },
@@ -666,8 +713,6 @@ func TestHandleGetFileInfo(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       rand.Seed(1) // reset seed between tests to make transaction IDs predictable
-
                        gotRes, err := HandleGetFileInfo(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr)
@@ -676,9 +721,10 @@ func TestHandleGetFileInfo(t *testing.T) {
 
                        // Clear the fileWrapper timestamp fields to work around problems running the tests in multiple timezones
                        // TODO: revisit how to test this by mocking the stat calls
+                       gotRes[0].Fields[4].Data = make([]byte, 8)
                        gotRes[0].Fields[5].Data = make([]byte, 8)
-                       gotRes[0].Fields[6].Data = make([]byte, 8)
-                       if !assert.Equal(t, tt.wantRes, gotRes) {
+
+                       if !tranAssertEqual(t, tt.wantRes, gotRes) {
                                t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
                        }
                })
@@ -714,13 +760,10 @@ func TestHandleNewFolder(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to create folders.")),
+                                               NewField(FieldError, []byte("You are not allowed to create folders.")),
                                        },
                                },
                        },
@@ -751,9 +794,9 @@ func TestHandleNewFolder(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewFolder, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFolder")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranNewFolder, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFolder")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -763,12 +806,8 @@ func TestHandleNewFolder(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xcd},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
                                },
                        },
                        wantErr: false,
@@ -798,18 +837,14 @@ func TestHandleNewFolder(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewFolder, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFolder")),
+                                       TranNewFolder, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFolder")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xcd},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
                                },
                        },
                        wantErr: false,
@@ -839,9 +874,9 @@ func TestHandleNewFolder(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewFolder, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFolder")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranNewFolder, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFolder")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00,
                                        }),
                                ),
@@ -850,7 +885,7 @@ func TestHandleNewFolder(t *testing.T) {
                        wantErr: true,
                },
                {
-                       name: "fieldFileName does not allow directory traversal",
+                       name: "FieldFileName does not allow directory traversal",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -874,23 +909,19 @@ func TestHandleNewFolder(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewFolder, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("../../testFolder")),
+                                       TranNewFolder, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("../../testFolder")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xcd},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
                                },
                        }, wantErr: false,
                },
                {
-                       name: "fieldFilePath does not allow directory traversal",
+                       name: "FieldFilePath does not allow directory traversal",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -914,9 +945,9 @@ func TestHandleNewFolder(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewFolder, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFolder")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranNewFolder, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFolder")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x02,
                                                0x00, 0x00,
                                                0x03,
@@ -929,19 +960,14 @@ func TestHandleNewFolder(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xcd},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
                                },
                        }, wantErr: false,
                },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-
                        gotRes, err := HandleNewFolder(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleNewFolder() error = %v, wantErr %v", err, tt.wantErr)
@@ -989,9 +1015,9 @@ func TestHandleUploadFile(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranUploadFile, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFile")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranUploadFile, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFile")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -1001,13 +1027,9 @@ func TestHandleUploadFile(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xcb},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), // rand.Seed(1)
+                                               NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), // rand.Seed(1)
                                        },
                                },
                        },
@@ -1025,9 +1047,9 @@ func TestHandleUploadFile(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranUploadFile, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFile")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranUploadFile, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFile")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -1037,13 +1059,10 @@ func TestHandleUploadFile(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to upload files.")), // rand.Seed(1)
+                                               NewField(FieldError, []byte("You are not allowed to upload files.")), // rand.Seed(1)
                                        },
                                },
                        },
@@ -1052,7 +1071,6 @@ func TestHandleUploadFile(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       rand.Seed(1)
                        gotRes, err := HandleUploadFile(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleUploadFile() error = %v, wantErr %v", err, tt.wantErr)
@@ -1060,7 +1078,6 @@ func TestHandleUploadFile(t *testing.T) {
                        }
 
                        tranAssertEqual(t, tt.wantRes, gotRes)
-
                })
        }
 }
@@ -1109,20 +1126,16 @@ func TestHandleMakeAlias(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranMakeFileAlias, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFile")),
-                                       NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
-                                       NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
+                                       TranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFile")),
+                                       NewField(FieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
+                                       NewField(FieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xd1},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field(nil),
+                                       IsReply: 0x01,
+                                       Fields:  []Field(nil),
                                },
                        },
                        wantErr: false,
@@ -1160,21 +1173,18 @@ func TestHandleMakeAlias(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranMakeFileAlias, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFile")),
-                                       NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
-                                       NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
+                                       TranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFile")),
+                                       NewField(FieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
+                                       NewField(FieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("Error creating alias")),
+                                               NewField(FieldError, []byte("Error creating alias")),
                                        },
                                },
                        },
@@ -1201,15 +1211,15 @@ func TestHandleMakeAlias(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranMakeFileAlias, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testFile")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFile")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
                                                0x2e, 0x2e, 0x2e,
                                        }),
-                                       NewField(fieldFileNewPath, []byte{
+                                       NewField(FieldFileNewPath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -1219,13 +1229,10 @@ func TestHandleMakeAlias(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to make aliases.")),
+                                               NewField(FieldError, []byte("You are not allowed to make aliases.")),
                                        },
                                },
                        },
@@ -1279,22 +1286,18 @@ func TestHandleGetUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetUser, &[]byte{0, 1},
-                                       NewField(fieldUserLogin, []byte("guest")),
+                                       TranGetUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, []byte("guest")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x01, 0x60},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldUserName, []byte("Guest")),
-                                               NewField(fieldUserLogin, negateString([]byte("guest"))),
-                                               NewField(fieldUserPassword, []byte("password")),
-                                               NewField(fieldUserAccess, []byte{0, 0, 0, 0, 0, 0, 0, 0}),
+                                               NewField(FieldUserName, []byte("Guest")),
+                                               NewField(FieldUserLogin, encodeString([]byte("guest"))),
+                                               NewField(FieldUserPassword, []byte("password")),
+                                               NewField(FieldUserAccess, []byte{0, 0, 0, 0, 0, 0, 0, 0}),
                                        },
                                },
                        },
@@ -1315,19 +1318,16 @@ func TestHandleGetUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetUser, &[]byte{0, 1},
-                                       NewField(fieldUserLogin, []byte("nonExistentUser")),
+                                       TranGetUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, []byte("nonExistentUser")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to view accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to view accounts.")),
                                        },
                                },
                        },
@@ -1349,19 +1349,18 @@ func TestHandleGetUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetUser, &[]byte{0, 1},
-                                       NewField(fieldUserLogin, []byte("nonExistentUser")),
+                                       TranGetUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, []byte("nonExistentUser")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
                                        Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Type:      [2]byte{0, 0},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("Account does not exist.")),
+                                               NewField(FieldError, []byte("Account does not exist.")),
                                        },
                                },
                        },
@@ -1419,18 +1418,16 @@ func TestHandleDeleteUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDeleteUser, &[]byte{0, 1},
-                                       NewField(fieldUserLogin, negateString([]byte("testuser"))),
+                                       TranDeleteUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, encodeString([]byte("testuser"))),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x1, 0x5f},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field(nil),
+                                       Flags:   0x00,
+                                       IsReply: 0x01,
+                                       Type:    [2]byte{0, 0},
+                                       Fields:  []Field(nil),
                                },
                        },
                        wantErr: assert.NoError,
@@ -1450,19 +1447,16 @@ func TestHandleDeleteUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDeleteUser, &[]byte{0, 1},
-                                       NewField(fieldUserLogin, negateString([]byte("testuser"))),
+                                       TranDeleteUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, encodeString([]byte("testuser"))),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete accounts.")),
                                        },
                                },
                        },
@@ -1508,18 +1502,14 @@ func TestHandleGetMsgs(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetMsgs, &[]byte{0, 1},
+                                       TranGetMsgs, &[]byte{0, 1},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x65},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("TEST")),
+                                               NewField(FieldData, []byte("TEST")),
                                        },
                                },
                        },
@@ -1540,18 +1530,15 @@ func TestHandleGetMsgs(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetMsgs, &[]byte{0, 1},
+                                       TranGetMsgs, &[]byte{0, 1},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to read news.")),
+                                               NewField(FieldError, []byte("You are not allowed to read news.")),
                                        },
                                },
                        },
@@ -1596,18 +1583,54 @@ func TestHandleNewUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewUser, &[]byte{0, 1},
+                                       TranNewUser, &[]byte{0, 1},
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       IsReply:   0x01,
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(FieldError, []byte("You are not allowed to create new accounts.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user attempts to create account with greater access",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessCreateUser)
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranNewUser, &[]byte{0, 1},
+                                       NewField(FieldUserLogin, []byte("userB")),
+                                       NewField(
+                                               FieldUserAccess,
+                                               func() []byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDisconUser)
+                                                       return bits[:]
+                                               }(),
+                                       ),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to create new accounts.")),
+                                               NewField(FieldError, []byte("Cannot create account with more access than yourself.")),
                                        },
                                },
                        },
@@ -1652,18 +1675,15 @@ func TestHandleListUsers(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranNewUser, &[]byte{0, 1},
+                                       TranNewUser, &[]byte{0, 1},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to view accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to view accounts.")),
                                        },
                                },
                        },
@@ -1692,19 +1712,15 @@ func TestHandleListUsers(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetClientInfoText, &[]byte{0, 1},
-                                       NewField(fieldUserID, []byte{0, 1}),
+                                       TranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(FieldUserID, []byte{0, 1}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x01, 0x2f},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldData, []byte{
+                                               NewField(FieldData, []byte{
                                                        0x00, 0x04, 0x00, 0x66, 0x00, 0x05, 0x67, 0x75, 0x65, 0x73, 0x74, 0x00, 0x69, 0x00, 0x05, 0x98,
                                                        0x8a, 0x9a, 0x8c, 0x8b, 0x00, 0x6e, 0x00, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                                                        0x00, 0x6a, 0x00, 0x01, 0x78,
@@ -1750,17 +1766,14 @@ func TestHandleDownloadFile(t *testing.T) {
                                        },
                                        Server: &Server{},
                                },
-                               t: NewTransaction(tranDownloadFile, &[]byte{0, 1}),
+                               t: NewTransaction(TranDownloadFile, &[]byte{0, 1}),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to download files.")),
+                                               NewField(FieldError, []byte("You are not allowed to download files.")),
                                        },
                                },
                        },
@@ -1792,22 +1805,18 @@ func TestHandleDownloadFile(t *testing.T) {
                                t: NewTransaction(
                                        accessDownloadFile,
                                        &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testfile.txt")),
-                                       NewField(fieldFilePath, []byte{0x0, 0x00}),
+                                       NewField(FieldFileName, []byte("testfile.txt")),
+                                       NewField(FieldFilePath, []byte{0x0, 0x00}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x2},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}),
-                                               NewField(fieldWaitingCount, []byte{0x00, 0x00}),
-                                               NewField(fieldTransferSize, []byte{0x00, 0x00, 0x00, 0xa5}),
-                                               NewField(fieldFileSize, []byte{0x00, 0x00, 0x00, 0x17}),
+                                               NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(FieldWaitingCount, []byte{0x00, 0x00}),
+                                               NewField(FieldTransferSize, []byte{0x00, 0x00, 0x00, 0xa5}),
+                                               NewField(FieldFileSize, []byte{0x00, 0x00, 0x00, 0x17}),
                                        },
                                },
                        },
@@ -1856,10 +1865,10 @@ func TestHandleDownloadFile(t *testing.T) {
                                t: NewTransaction(
                                        accessDownloadFile,
                                        &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testfile-1k")),
-                                       NewField(fieldFilePath, []byte{0x00, 0x00}),
+                                       NewField(FieldFileName, []byte("testfile-1k")),
+                                       NewField(FieldFilePath, []byte{0x00, 0x00}),
                                        NewField(
-                                               fieldFileResumeData,
+                                               FieldFileResumeData,
                                                func() []byte {
                                                        frd := FileResumeData{
                                                                Format:    [4]byte{},
@@ -1889,16 +1898,12 @@ func TestHandleDownloadFile(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x2},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}),
-                                               NewField(fieldWaitingCount, []byte{0x00, 0x00}),
-                                               NewField(fieldTransferSize, []byte{0x00, 0x00, 0x03, 0x8d}),
-                                               NewField(fieldFileSize, []byte{0x00, 0x00, 0x03, 0x00}),
+                                               NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(FieldWaitingCount, []byte{0x00, 0x00}),
+                                               NewField(FieldTransferSize, []byte{0x00, 0x00, 0x03, 0x8d}),
+                                               NewField(FieldFileSize, []byte{0x00, 0x00, 0x03, 0x00}),
                                        },
                                },
                        },
@@ -1944,24 +1949,24 @@ func TestHandleUpdateUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranUpdateUser,
+                                       TranUpdateUser,
                                        &[]byte{0, 0},
-                                       NewField(fieldData, []byte{
+                                       NewField(FieldData, []byte{
                                                0x00, 0x04, // field count
 
-                                               0x00, 0x69, // fieldUserLogin = 105
+                                               0x00, 0x69, // FieldUserLogin = 105
                                                0x00, 0x03,
                                                0x9d, 0x9d, 0x9d,
 
-                                               0x00, 0x6a, // fieldUserPassword = 106
+                                               0x00, 0x6a, // FieldUserPassword = 106
                                                0x00, 0x03,
                                                0x9c, 0x9c, 0x9c,
 
-                                               0x00, 0x66, // fieldUserName = 102
+                                               0x00, 0x66, // FieldUserName = 102
                                                0x00, 0x03,
                                                0x61, 0x61, 0x61,
 
-                                               0x00, 0x6e, // fieldUserAccess = 110
+                                               0x00, 0x6e, // FieldUserAccess = 110
                                                0x00, 0x08,
                                                0x60, 0x70, 0x0c, 0x20, 0x03, 0x80, 0x00, 0x00,
                                        }),
@@ -1969,13 +1974,10 @@ func TestHandleUpdateUser(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to create new accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to create new accounts.")),
                                        },
                                },
                        },
@@ -2000,24 +2002,24 @@ func TestHandleUpdateUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranUpdateUser,
+                                       TranUpdateUser,
                                        &[]byte{0, 0},
-                                       NewField(fieldData, []byte{
+                                       NewField(FieldData, []byte{
                                                0x00, 0x04, // field count
 
-                                               0x00, 0x69, // fieldUserLogin = 105
+                                               0x00, 0x69, // FieldUserLogin = 105
                                                0x00, 0x03,
                                                0x9d, 0x9d, 0x9d,
 
-                                               0x00, 0x6a, // fieldUserPassword = 106
+                                               0x00, 0x6a, // FieldUserPassword = 106
                                                0x00, 0x03,
                                                0x9c, 0x9c, 0x9c,
 
-                                               0x00, 0x66, // fieldUserName = 102
+                                               0x00, 0x66, // FieldUserName = 102
                                                0x00, 0x03,
                                                0x61, 0x61, 0x61,
 
-                                               0x00, 0x6e, // fieldUserAccess = 110
+                                               0x00, 0x6e, // FieldUserAccess = 110
                                                0x00, 0x08,
                                                0x60, 0x70, 0x0c, 0x20, 0x03, 0x80, 0x00, 0x00,
                                        }),
@@ -2025,13 +2027,10 @@ func TestHandleUpdateUser(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to modify accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to modify accounts.")),
                                        },
                                },
                        },
@@ -2055,9 +2054,9 @@ func TestHandleUpdateUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranUpdateUser,
+                                       TranUpdateUser,
                                        &[]byte{0, 0},
-                                       NewField(fieldData, []byte{
+                                       NewField(FieldData, []byte{
                                                0x00, 0x01,
                                                0x00, 0x65,
                                                0x00, 0x03,
@@ -2067,13 +2066,10 @@ func TestHandleUpdateUser(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete accounts.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete accounts.")),
                                        },
                                },
                        },
@@ -2115,19 +2111,16 @@ func TestHandleDelNewsArt(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsArt,
+                                       TranDelNewsArt,
                                        &[]byte{0, 0},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete news articles.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete news articles.")),
                                        },
                                },
                        },
@@ -2168,19 +2161,16 @@ func TestHandleDisconnectUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsArt,
+                                       TranDelNewsArt,
                                        &[]byte{0, 0},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to disconnect users.")),
+                                               NewField(FieldError, []byte("You are not allowed to disconnect users.")),
                                        },
                                },
                        },
@@ -2213,20 +2203,17 @@ func TestHandleDisconnectUser(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsArt,
+                                       TranDelNewsArt,
                                        &[]byte{0, 0},
-                                       NewField(fieldUserID, []byte{0, 1}),
+                                       NewField(FieldUserID, []byte{0, 1}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("unnamed is not allowed to be disconnected.")),
+                                               NewField(FieldError, []byte("unnamed is not allowed to be disconnected.")),
                                        },
                                },
                        },
@@ -2267,23 +2254,20 @@ func TestHandleSendInstantMsg(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsArt,
+                                       TranDelNewsArt,
                                        &[]byte{0, 0},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to send private messages.")),
+                                               NewField(FieldError, []byte("You are not allowed to send private messages.")),
                                        },
                                },
                        },
-                       wantErr: assert.NoError,
+                       wantErr: assert.Error,
                },
                {
                        name: "when client 1 sends a message to client 2",
@@ -2302,34 +2286,31 @@ func TestHandleSendInstantMsg(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(2): {
                                                                AutoReply: []byte(nil),
+                                                               Flags:     []byte{0, 0},
                                                        },
                                                },
                                        },
                                },
                                t: NewTransaction(
-                                       tranSendInstantMsg,
+                                       TranSendInstantMsg,
                                        &[]byte{0, 1},
-                                       NewField(fieldData, []byte("hai")),
-                                       NewField(fieldUserID, []byte{0, 2}),
+                                       NewField(FieldData, []byte("hai")),
+                                       NewField(FieldUserID, []byte{0, 2}),
                                ),
                        },
                        wantRes: []Transaction{
                                *NewTransaction(
-                                       tranServerMsg,
+                                       TranServerMsg,
                                        &[]byte{0, 2},
-                                       NewField(fieldData, []byte("hai")),
-                                       NewField(fieldUserName, []byte("User1")),
-                                       NewField(fieldUserID, []byte{0, 1}),
-                                       NewField(fieldOptions, []byte{0, 1}),
+                                       NewField(FieldData, []byte("hai")),
+                                       NewField(FieldUserName, []byte("User1")),
+                                       NewField(FieldUserID, []byte{0, 1}),
+                                       NewField(FieldOptions, []byte{0, 1}),
                                ),
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x0, 0x6c},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field(nil),
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field(nil),
                                },
                        },
                        wantErr: assert.NoError,
@@ -2350,6 +2331,7 @@ func TestHandleSendInstantMsg(t *testing.T) {
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(2): {
+                                                               Flags:     []byte{0, 0},
                                                                ID:        &[]byte{0, 2},
                                                                UserName:  []byte("User2"),
                                                                AutoReply: []byte("autohai"),
@@ -2358,37 +2340,80 @@ func TestHandleSendInstantMsg(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranSendInstantMsg,
+                                       TranSendInstantMsg,
                                        &[]byte{0, 1},
-                                       NewField(fieldData, []byte("hai")),
-                                       NewField(fieldUserID, []byte{0, 2}),
+                                       NewField(FieldData, []byte("hai")),
+                                       NewField(FieldUserID, []byte{0, 2}),
                                ),
                        },
                        wantRes: []Transaction{
                                *NewTransaction(
-                                       tranServerMsg,
+                                       TranServerMsg,
                                        &[]byte{0, 2},
-                                       NewField(fieldData, []byte("hai")),
-                                       NewField(fieldUserName, []byte("User1")),
-                                       NewField(fieldUserID, []byte{0, 1}),
-                                       NewField(fieldOptions, []byte{0, 1}),
+                                       NewField(FieldData, []byte("hai")),
+                                       NewField(FieldUserName, []byte("User1")),
+                                       NewField(FieldUserID, []byte{0, 1}),
+                                       NewField(FieldOptions, []byte{0, 1}),
                                ),
                                *NewTransaction(
-                                       tranServerMsg,
+                                       TranServerMsg,
                                        &[]byte{0, 1},
-                                       NewField(fieldData, []byte("autohai")),
-                                       NewField(fieldUserName, []byte("User2")),
-                                       NewField(fieldUserID, []byte{0, 2}),
-                                       NewField(fieldOptions, []byte{0, 1}),
+                                       NewField(FieldData, []byte("autohai")),
+                                       NewField(FieldUserName, []byte("User2")),
+                                       NewField(FieldUserID, []byte{0, 2}),
+                                       NewField(FieldOptions, []byte{0, 1}),
                                ),
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x0, 0x6c},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field(nil),
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field(nil),
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when client 2 has refuse private messages enabled",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendPrivMsg)
+                                                       return bits
+                                               }(),
+                                       },
+                                       ID:       &[]byte{0, 1},
+                                       UserName: []byte("User1"),
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(2): {
+                                                               Flags:    []byte{255, 255},
+                                                               ID:       &[]byte{0, 2},
+                                                               UserName: []byte("User2"),
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranSendInstantMsg,
+                                       &[]byte{0, 1},
+                                       NewField(FieldData, []byte("hai")),
+                                       NewField(FieldUserID, []byte{0, 2}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               *NewTransaction(
+                                       TranServerMsg,
+                                       &[]byte{0, 1},
+                                       NewField(FieldData, []byte("User2 does not accept private messages.")),
+                                       NewField(FieldUserName, []byte("User2")),
+                                       NewField(FieldUserID, []byte{0, 2}),
+                                       NewField(FieldOptions, []byte{0, 2}),
+                               ),
+                               {
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field(nil),
                                },
                        },
                        wantErr: assert.NoError,
@@ -2452,9 +2477,9 @@ func TestHandleDeleteFile(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDeleteFile, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testfile")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranDeleteFile, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testfile")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -2464,13 +2489,10 @@ func TestHandleDeleteFile(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete files.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete files.")),
                                        },
                                },
                        },
@@ -2517,9 +2539,9 @@ func TestHandleDeleteFile(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranDeleteFile, &[]byte{0, 1},
-                                       NewField(fieldFileName, []byte("testfile")),
-                                       NewField(fieldFilePath, []byte{
+                                       TranDeleteFile, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testfile")),
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x03,
@@ -2529,12 +2551,8 @@ func TestHandleDeleteFile(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x0, 0xcc},
-                                       ID:        []byte{0x0, 0x0, 0x0, 0x0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field(nil),
+                                       IsReply: 0x01,
+                                       Fields:  []Field(nil),
                                },
                        },
                        wantErr: assert.NoError,
@@ -2566,7 +2584,7 @@ func TestHandleGetFileNameList(t *testing.T) {
                wantErr assert.ErrorAssertionFunc
        }{
                {
-                       name: "when fieldFilePath is a drop box, but user does not have accessViewDropBoxes ",
+                       name: "when FieldFilePath is a drop box, but user does not have accessViewDropBoxes ",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -2586,8 +2604,8 @@ func TestHandleGetFileNameList(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetFileNameList, &[]byte{0, 1},
-                                       NewField(fieldFilePath, []byte{
+                                       TranGetFileNameList, &[]byte{0, 1},
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x01,
                                                0x00, 0x00,
                                                0x08,
@@ -2597,13 +2615,10 @@ func TestHandleGetFileNameList(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to view drop boxes.")),
+                                               NewField(FieldError, []byte("You are not allowed to view drop boxes.")),
                                        },
                                },
                        },
@@ -2623,8 +2638,8 @@ func TestHandleGetFileNameList(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetFileNameList, &[]byte{0, 1},
-                                       NewField(fieldFilePath, []byte{
+                                       TranGetFileNameList, &[]byte{0, 1},
+                                       NewField(FieldFilePath, []byte{
                                                0x00, 0x00,
                                                0x00, 0x00,
                                        }),
@@ -2632,14 +2647,10 @@ func TestHandleGetFileNameList(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0xc8},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
                                                NewField(
-                                                       fieldFileNameWithInfo,
+                                                       FieldFileNameWithInfo,
                                                        func() []byte {
                                                                fnwi := FileNameWithInfo{
                                                                        fileNameWithInfoHeader: fileNameWithInfoHeader{
@@ -2650,9 +2661,9 @@ func TestHandleGetFileNameList(t *testing.T) {
                                                                                NameScript: [2]byte{},
                                                                                NameSize:   [2]byte{0, 0x0b},
                                                                        },
-                                                                       name: []byte("testfile-1k"),
+                                                                       Name: []byte("testfile-1k"),
                                                                }
-                                                               b, _ := fnwi.MarshalBinary()
+                                                               b, _ := io.ReadAll(&fnwi)
                                                                return b
                                                        }(),
                                                ),
@@ -2700,19 +2711,16 @@ func TestHandleGetClientInfoText(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetClientInfoText, &[]byte{0, 1},
-                                       NewField(fieldUserID, []byte{0, 1}),
+                                       TranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(FieldUserID, []byte{0, 1}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to get client info.")),
+                                               NewField(FieldError, []byte("You are not allowed to get client info.")),
                                        },
                                },
                        },
@@ -2759,20 +2767,16 @@ func TestHandleGetClientInfoText(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranGetClientInfoText, &[]byte{0, 1},
-                                       NewField(fieldUserID, []byte{0, 1}),
+                                       TranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(FieldUserID, []byte{0, 1}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x1, 0x2f},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                        Fields: []Field{
-                                               NewField(fieldData, []byte(
-                                                       strings.Replace(`Nickname:   Testy McTest
+                                               NewField(FieldData, []byte(
+                                                       strings.ReplaceAll(`Nickname:   Testy McTest
 Name:       test
 Account:    test
 Address:    1.2.3.4:12345
@@ -2797,9 +2801,9 @@ None.
 
 None.
 
-`, "\n", "\r", -1)),
+`, "\n", "\r")),
                                                ),
-                                               NewField(fieldUserName, []byte("Testy McTest")),
+                                               NewField(FieldUserName, []byte("Testy McTest")),
                                        },
                                },
                        },
@@ -2851,32 +2855,24 @@ func TestHandleTranAgreed(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranAgreed, nil,
-                                       NewField(fieldUserName, []byte("username")),
-                                       NewField(fieldUserIconID, []byte{0, 1}),
-                                       NewField(fieldOptions, []byte{0, 0}),
+                                       TranAgreed, nil,
+                                       NewField(FieldUserName, []byte("username")),
+                                       NewField(FieldUserIconID, []byte{0, 1}),
+                                       NewField(FieldOptions, []byte{0, 0}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x7a},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x7a},
                                        Fields: []Field{
-                                               NewField(fieldBannerType, []byte("JPEG")),
+                                               NewField(FieldBannerType, []byte("JPEG")),
                                        },
                                },
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x79},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field{},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field{},
                                },
                        },
                        wantErr: assert.NoError,
@@ -2926,24 +2922,20 @@ func TestHandleSetClientUserInfo(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranSetClientUserInfo, nil,
-                                       NewField(fieldUserIconID, []byte{0, 1}),
-                                       NewField(fieldUserName, []byte("NOPE")),
+                                       TranSetClientUserInfo, nil,
+                                       NewField(FieldUserIconID, []byte{0, 1}),
+                                       NewField(FieldUserName, []byte("NOPE")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0x01, 0x2d},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0x01, 0x2d},
                                        Fields: []Field{
-                                               NewField(fieldUserID, []byte{0, 1}),
-                                               NewField(fieldUserIconID, []byte{0, 1}),
-                                               NewField(fieldUserFlags, []byte{0, 1}),
-                                               NewField(fieldUserName, []byte("Guest"))},
+                                               NewField(FieldUserID, []byte{0, 1}),
+                                               NewField(FieldUserIconID, []byte{0, 1}),
+                                               NewField(FieldUserFlags, []byte{0, 1}),
+                                               NewField(FieldUserName, []byte("Guest"))},
                                },
                        },
                        wantErr: assert.NoError,
@@ -2983,17 +2975,15 @@ func TestHandleDelNewsItem(t *testing.T) {
                                        Server: &Server{
                                                ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
                                                        "test": {
-                                                               Type:     []byte{0, 3},
-                                                               Count:    nil,
-                                                               NameSize: 0,
-                                                               Name:     "zz",
+                                                               Type: [2]byte{0, 3},
+                                                               Name: "zz",
                                                        },
                                                }},
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsItem, nil,
-                                       NewField(fieldNewsPath,
+                                       TranDelNewsItem, nil,
+                                       NewField(FieldNewsPath,
                                                []byte{
                                                        0, 1,
                                                        0, 0,
@@ -3006,13 +2996,10 @@ func TestHandleDelNewsItem(t *testing.T) {
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete news categories.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete news categories.")),
                                        },
                                },
                        },
@@ -3029,17 +3016,15 @@ func TestHandleDelNewsItem(t *testing.T) {
                                        Server: &Server{
                                                ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
                                                        "testcat": {
-                                                               Type:     []byte{0, 2},
-                                                               Count:    nil,
-                                                               NameSize: 0,
-                                                               Name:     "test",
+                                                               Type: [2]byte{0, 2},
+                                                               Name: "test",
                                                        },
                                                }},
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsItem, nil,
-                                       NewField(fieldNewsPath,
+                                       TranDelNewsItem, nil,
+                                       NewField(FieldNewsPath,
                                                []byte{
                                                        0, 1,
                                                        0, 0,
@@ -3052,13 +3037,10 @@ func TestHandleDelNewsItem(t *testing.T) {
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to delete news folders.")),
+                                               NewField(FieldError, []byte("You are not allowed to delete news folders.")),
                                        },
                                },
                        },
@@ -3085,17 +3067,15 @@ func TestHandleDelNewsItem(t *testing.T) {
                                                }(),
                                                ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
                                                        "testcat": {
-                                                               Type:     []byte{0, 2},
-                                                               Count:    nil,
-                                                               NameSize: 0,
-                                                               Name:     "test",
+                                                               Type: [2]byte{0, 2},
+                                                               Name: "test",
                                                        },
                                                }},
                                        },
                                },
                                t: NewTransaction(
-                                       tranDelNewsItem, nil,
-                                       NewField(fieldNewsPath,
+                                       TranDelNewsItem, nil,
+                                       NewField(FieldNewsPath,
                                                []byte{
                                                        0, 1,
                                                        0, 0,
@@ -3107,13 +3087,9 @@ func TestHandleDelNewsItem(t *testing.T) {
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x01, 0x7c},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields:    []Field{},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field{},
                                },
                        },
                        wantErr: assert.NoError,
@@ -3130,72 +3106,6 @@ func TestHandleDelNewsItem(t *testing.T) {
        }
 }
 
-func TestHandleDownloadBanner(t *testing.T) {
-       type args struct {
-               cc *ClientConn
-               t  *Transaction
-       }
-       tests := []struct {
-               name    string
-               args    args
-               wantRes []Transaction
-               wantErr assert.ErrorAssertionFunc
-       }{
-               {
-                       name: "returns expected response",
-                       args: args{
-                               cc: &ClientConn{
-                                       ID: &[]byte{0, 1},
-                                       transfers: map[int]map[[4]byte]*FileTransfer{
-                                               bannerDownload: {},
-                                       },
-                                       Server: &Server{
-                                               ConfigDir: "/config",
-                                               Config: &Config{
-                                                       BannerFile: "banner.jpg",
-                                               },
-                                               fileTransfers: map[[4]byte]*FileTransfer{},
-                                               FS: func() *MockFileStore {
-                                                       mfi := &MockFileInfo{}
-                                                       mfi.On("Size").Return(int64(100))
-
-                                                       mfs := &MockFileStore{}
-                                                       mfs.On("Stat", "/config/banner.jpg").Return(mfi, nil)
-                                                       return mfs
-                                               }(),
-                                       },
-                               },
-                               t: NewTransaction(tranDownloadBanner, nil),
-                       },
-                       wantRes: []Transaction{
-                               {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0x00, 0xd4},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
-                                       Fields: []Field{
-                                               NewField(fieldRefNum, []byte{1, 2, 3, 4}),
-                                               NewField(fieldTransferSize, []byte{0, 0, 0, 0x64}),
-                                       },
-                               },
-                       },
-                       wantErr: assert.NoError,
-               },
-       }
-       for _, tt := range tests {
-               t.Run(tt.name, func(t *testing.T) {
-                       gotRes, err := HandleDownloadBanner(tt.args.cc, tt.args.t)
-                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t)) {
-                               return
-                       }
-
-                       tranAssertEqual(t, tt.wantRes, gotRes)
-               })
-       }
-}
-
 func TestHandleTranOldPostNews(t *testing.T) {
        type args struct {
                cc *ClientConn
@@ -3219,19 +3129,16 @@ func TestHandleTranOldPostNews(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranOldPostNews, &[]byte{0, 1},
-                                       NewField(fieldData, []byte("hai")),
+                                       TranOldPostNews, &[]byte{0, 1},
+                                       NewField(FieldData, []byte("hai")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to post news.")),
+                                               NewField(FieldError, []byte("You are not allowed to post news.")),
                                        },
                                },
                        },
@@ -3259,17 +3166,13 @@ func TestHandleTranOldPostNews(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranOldPostNews, &[]byte{0, 1},
-                                       NewField(fieldData, []byte("hai")),
+                                       TranOldPostNews, &[]byte{0, 1},
+                                       NewField(FieldData, []byte("hai")),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x67},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply: 0x01,
                                },
                        },
                        wantErr: assert.NoError,
@@ -3309,17 +3212,14 @@ func TestHandleInviteNewChat(t *testing.T) {
                                                }(),
                                        },
                                },
-                               t: NewTransaction(tranInviteNewChat, &[]byte{0, 1}),
+                               t: NewTransaction(TranInviteNewChat, &[]byte{0, 1}),
                        },
                        wantRes: []Transaction{
                                {
-                                       Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x00},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldError, []byte("You are not allowed to request private chat.")),
+                                               NewField(FieldError, []byte("You are not allowed to request private chat.")),
                                        },
                                },
                        },
@@ -3352,38 +3252,30 @@ func TestHandleInviteNewChat(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranInviteNewChat, &[]byte{0, 1},
-                                       NewField(fieldUserID, []byte{0, 2}),
+                                       TranInviteNewChat, &[]byte{0, 1},
+                                       NewField(FieldUserID, []byte{0, 2}),
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 2},
-                                       Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x71},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 2},
+                                       Type:     [2]byte{0, 0x71},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
-                                               NewField(fieldUserName, []byte("UserA")),
-                                               NewField(fieldUserID, []byte{0, 1}),
+                                               NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(FieldUserName, []byte("UserA")),
+                                               NewField(FieldUserID, []byte{0, 1}),
                                        },
                                },
 
                                {
-                                       clientID:  &[]byte{0, 1},
-                                       Flags:     0x00,
-                                       IsReply:   0x01,
-                                       Type:      []byte{0, 0x70},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
-                                               NewField(fieldUserName, []byte("UserA")),
-                                               NewField(fieldUserID, []byte{0, 1}),
-                                               NewField(fieldUserIconID, []byte{0, 1}),
-                                               NewField(fieldUserFlags, []byte{0, 0}),
+                                               NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(FieldUserName, []byte("UserA")),
+                                               NewField(FieldUserID, []byte{0, 1}),
+                                               NewField(FieldUserIconID, []byte{0, 1}),
+                                               NewField(FieldUserFlags, []byte{0, 0}),
                                        },
                                },
                        },
@@ -3416,52 +3308,405 @@ func TestHandleInviteNewChat(t *testing.T) {
                                        },
                                },
                                t: NewTransaction(
-                                       tranInviteNewChat, &[]byte{0, 1},
-                                       NewField(fieldUserID, []byte{0, 2}),
+                                       TranInviteNewChat, &[]byte{0, 1},
+                                       NewField(FieldUserID, []byte{0, 2}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID: &[]byte{0, 1},
+                                       Type:     [2]byte{0, 0x68},
+                                       Fields: []Field{
+                                               NewField(FieldData, []byte("UserB does not accept private chats.")),
+                                               NewField(FieldUserName, []byte("UserB")),
+                                               NewField(FieldUserID, []byte{0, 2}),
+                                               NewField(FieldOptions, []byte{0, 2}),
+                                       },
+                               },
+                               {
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields: []Field{
+                                               NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(FieldUserName, []byte("UserA")),
+                                               NewField(FieldUserID, []byte{0, 1}),
+                                               NewField(FieldUserIconID, []byte{0, 1}),
+                                               NewField(FieldUserFlags, []byte{0, 0}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleInviteNewChat(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleInviteNewChat(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleGetNewsArtData(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranGetNewsArtData, &[]byte{0, 1},
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       IsReply:   0x01,
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(FieldError, []byte("You are not allowed to read news.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleGetNewsArtData(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleGetNewsArtData(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleGetNewsArtNameList(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranGetNewsArtNameList, &[]byte{0, 1},
                                ),
                        },
                        wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
                                        Flags:     0x00,
-                                       IsReply:   0x00,
-                                       Type:      []byte{0, 0x68},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       IsReply:   0x01,
+                                       Type:      [2]byte{0, 0},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldData, []byte("UserB does not accept private messages.")),
-                                               NewField(fieldUserName, []byte("UserB")),
-                                               NewField(fieldUserID, []byte{0, 2}),
-                                               NewField(fieldOptions, []byte{0, 2}),
+                                               NewField(FieldError, []byte("You are not allowed to read news.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user has required access",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessNewsReadArt)
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               ThreadedNews: &ThreadedNews{
+                                                       Categories: map[string]NewsCategoryListData15{
+                                                               "Example Category": {
+                                                                       Type: [2]byte{0, 2},
+                                                                       Name: "",
+                                                                       Articles: map[uint32]*NewsArtData{
+                                                                               uint32(1): {
+                                                                                       Title:  "testTitle",
+                                                                                       Poster: "testPoster",
+                                                                                       Data:   "testBody",
+                                                                               },
+                                                                       },
+                                                                       SubCats:  nil,
+                                                                       GUID:     [16]byte{},
+                                                                       AddSN:    [4]byte{},
+                                                                       DeleteSN: [4]byte{},
+                                                               },
+                                                       },
+                                               },
+
+                                               //Accounts: map[string]*Account{
+                                               //      "guest": {
+                                               //              Name:     "guest",
+                                               //              Login:    "guest",
+                                               //              Password: "zz",
+                                               //              Access:   accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
+                                               //      },
+                                               //},
                                        },
                                },
+                               t: NewTransaction(
+                                       TranGetNewsArtNameList,
+                                       &[]byte{0, 1},
+                                       //  00000000  00 01 00 00 10 45 78 61  6d 70 6c 65 20 43 61 74  |.....Example Cat|
+                                       //  00000010  65 67 6f 72 79                                    |egory|
+                                       NewField(FieldNewsPath, []byte{
+                                               0x00, 0x01, 0x00, 0x00, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       IsReply: 0x01,
+                                       Fields: []Field{
+                                               NewField(FieldNewsArtListData, []byte{
+                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+                                                       0x09, 0x74, 0x65, 0x73, 0x74, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x50,
+                                                       0x6f, 0x73, 0x74, 0x65, 0x72, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, 0x61, 0x69, 0x6e,
+                                                       0x00, 0x08,
+                                               },
+                                               ),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleGetNewsArtNameList(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleGetNewsArtNameList(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleNewNewsFldr(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranGetNewsArtNameList, &[]byte{0, 1},
+                               ),
+                       },
+                       wantRes: []Transaction{
                                {
-                                       clientID:  &[]byte{0, 1},
                                        Flags:     0x00,
                                        IsReply:   0x01,
-                                       Type:      []byte{0, 0x70},
-                                       ID:        []byte{0, 0, 0, 0},
-                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Type:      [2]byte{0, 0},
+                                       ErrorCode: [4]byte{0, 0, 0, 1},
                                        Fields: []Field{
-                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
-                                               NewField(fieldUserName, []byte("UserA")),
-                                               NewField(fieldUserID, []byte{0, 1}),
-                                               NewField(fieldUserIconID, []byte{0, 1}),
-                                               NewField(fieldUserFlags, []byte{0, 0}),
+                                               NewField(FieldError, []byte("You are not allowed to create news folders.")),
                                        },
                                },
                        },
                        wantErr: assert.NoError,
                },
+               {
+                       name: "with a valid request",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessNewsCreateFldr)
+                                                       return bits
+                                               }(),
+                                       },
+                                       logger: NewTestLogger(),
+                                       ID:     &[]byte{0, 1},
+                                       Server: &Server{
+                                               ConfigDir: "/fakeConfigRoot",
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("WriteFile", "/fakeConfigRoot/ThreadedNews.yaml", mock.Anything, mock.Anything).Return(nil)
+                                                       return mfs
+                                               }(),
+                                               ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+                                                       "test": {
+                                                               Type:    [2]byte{0, 2},
+                                                               Name:    "test",
+                                                               SubCats: make(map[string]NewsCategoryListData15),
+                                                       },
+                                               }},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       TranGetNewsArtNameList, &[]byte{0, 1},
+                                       NewField(FieldFileName, []byte("testFolder")),
+                                       NewField(FieldNewsPath,
+                                               []byte{
+                                                       0, 1,
+                                                       0, 0,
+                                                       4,
+                                                       0x74, 0x65, 0x73, 0x74,
+                                               },
+                                       ),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID: &[]byte{0, 1},
+                                       IsReply:  0x01,
+                                       Fields:   []Field{},
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               //{
+               //      Name: "when there is an error writing the threaded news file",
+               //      args: args{
+               //              cc: &ClientConn{
+               //                      Account: &Account{
+               //                              Access: func() accessBitmap {
+               //                                      var bits accessBitmap
+               //                                      bits.Set(accessNewsCreateFldr)
+               //                                      return bits
+               //                              }(),
+               //                      },
+               //                      logger: NewTestLogger(),
+               //                      ID:     &[]byte{0, 1},
+               //                      Server: &Server{
+               //                              ConfigDir: "/fakeConfigRoot",
+               //                              FS: func() *MockFileStore {
+               //                                      mfs := &MockFileStore{}
+               //                                      mfs.On("WriteFile", "/fakeConfigRoot/ThreadedNews.yaml", mock.Anything, mock.Anything).Return(os.ErrNotExist)
+               //                                      return mfs
+               //                              }(),
+               //                              ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+               //                                      "test": {
+               //                                              Type:     []byte{0, 2},
+               //                                              Count:    nil,
+               //                                              NameSize: 0,
+               //                                              Name:     "test",
+               //                                              SubCats:  make(map[string]NewsCategoryListData15),
+               //                                      },
+               //                              }},
+               //                      },
+               //              },
+               //              t: NewTransaction(
+               //                      TranGetNewsArtNameList, &[]byte{0, 1},
+               //                      NewField(FieldFileName, []byte("testFolder")),
+               //                      NewField(FieldNewsPath,
+               //                              []byte{
+               //                                      0, 1,
+               //                                      0, 0,
+               //                                      4,
+               //                                      0x74, 0x65, 0x73, 0x74,
+               //                              },
+               //                      ),
+               //              ),
+               //      },
+               //      wantRes: []Transaction{
+               //              {
+               //                      clientID:  &[]byte{0, 1},
+               //                      Flags:     0x00,
+               //                      IsReply:   0x01,
+               //                      Type:      [2]byte{0, 0},
+               //                      ErrorCode: [4]byte{0, 0, 0, 1},
+               //                      Fields: []Field{
+               //                              NewField(FieldError, []byte("Error creating news folder.")),
+               //                      },
+               //              },
+               //      },
+               //      wantErr: assert.Error,
+               // },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       rand.Seed(1)
-                       gotRes, err := HandleInviteNewChat(tt.args.cc, tt.args.t)
-                       if !tt.wantErr(t, err, fmt.Sprintf("HandleInviteNewChat(%v, %v)", tt.args.cc, tt.args.t)) {
+                       gotRes, err := HandleNewNewsFldr(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleNewNewsFldr(%v, %v)", tt.args.cc, tt.args.t)) {
                                return
                        }
                        tranAssertEqual(t, tt.wantRes, gotRes)
                })
        }
 }
+
+func TestHandleDownloadBanner(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               // TODO: Add test cases.
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleDownloadBanner(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       assert.Equalf(t, tt.wantRes, gotRes, "HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t)
+               })
+       }
+}