]> git.r.bdr.sh - rbdr/mobius/blob - hotline/field.go
minor: v0.11.0
[rbdr/mobius] / hotline / field.go
1 package hotline
2
3 import (
4 "encoding/binary"
5 "github.com/jhalter/mobius/concat"
6 )
7
8 // List of Hotline protocol field types taken from the official 1.9 protocol document
9 const (
10 FieldError = 100
11 FieldData = 101
12 FieldUserName = 102
13 FieldUserID = 103
14 FieldUserIconID = 104
15 FieldUserLogin = 105
16 FieldUserPassword = 106
17 FieldRefNum = 107
18 FieldTransferSize = 108
19 FieldChatOptions = 109
20 FieldUserAccess = 110
21 FieldUserAlias = 111 // TODO: implement
22 FieldUserFlags = 112
23 FieldOptions = 113
24 FieldChatID = 114
25 FieldChatSubject = 115
26 FieldWaitingCount = 116
27 FieldBannerType = 152
28 FieldNoServerAgreement = 152
29 FieldVersion = 160
30 FieldCommunityBannerID = 161
31 FieldServerName = 162
32 FieldFileNameWithInfo = 200
33 FieldFileName = 201
34 FieldFilePath = 202
35 FieldFileResumeData = 203
36 FieldFileTransferOptions = 204
37 FieldFileTypeString = 205
38 FieldFileCreatorString = 206
39 FieldFileSize = 207
40 FieldFileCreateDate = 208
41 FieldFileModifyDate = 209
42 FieldFileComment = 210
43 FieldFileNewName = 211
44 FieldFileNewPath = 212
45 FieldFileType = 213
46 FieldQuotingMsg = 214
47 FieldAutomaticResponse = 215
48 FieldFolderItemCount = 220
49 FieldUsernameWithInfo = 300
50 FieldNewsArtListData = 321
51 FieldNewsCatName = 322
52 FieldNewsCatListData15 = 323
53 FieldNewsPath = 325
54 FieldNewsArtID = 326
55 FieldNewsArtDataFlav = 327
56 FieldNewsArtTitle = 328
57 FieldNewsArtPoster = 329
58 FieldNewsArtDate = 330
59 FieldNewsArtPrevArt = 331
60 FieldNewsArtNextArt = 332
61 FieldNewsArtData = 333
62 FieldNewsArtFlags = 334 // TODO: what is this used for?
63 FieldNewsArtParentArt = 335
64 FieldNewsArt1stChildArt = 336
65 FieldNewsArtRecurseDel = 337 // TODO: implement news article recusive deletion
66 )
67
68 type Field struct {
69 ID []byte // Type of field
70 FieldSize []byte // Size of the data part
71 Data []byte // Actual field content
72 }
73
74 type requiredField struct {
75 ID int
76 minLen int
77 }
78
79 func NewField(id uint16, data []byte) Field {
80 idBytes := make([]byte, 2)
81 binary.BigEndian.PutUint16(idBytes, id)
82
83 bs := make([]byte, 2)
84 binary.BigEndian.PutUint16(bs, uint16(len(data)))
85
86 return Field{
87 ID: idBytes,
88 FieldSize: bs,
89 Data: data,
90 }
91 }
92
93 func (f Field) Payload() []byte {
94 return concat.Slices(f.ID, f.FieldSize, f.Data)
95 }
96
97 func getField(id int, fields *[]Field) *Field {
98 for _, field := range *fields {
99 if id == int(binary.BigEndian.Uint16(field.ID)) {
100 return &field
101 }
102 }
103 return nil
104 }