]> git.r.bdr.sh - rbdr/mobius/blame_incremental - hotline/field.go
patch: v0.10.20
[rbdr/mobius] / hotline / field.go
... / ...
CommitLineData
1package hotline
2
3import (
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
9const (
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
68type Field struct {
69 ID []byte // Type of field
70 FieldSize []byte // Size of the data part
71 Data []byte // Actual field content
72}
73
74type requiredField struct {
75 ID int
76 minLen int
77 maxLen int
78}
79
80func NewField(id uint16, data []byte) Field {
81 idBytes := make([]byte, 2)
82 binary.BigEndian.PutUint16(idBytes, id)
83
84 bs := make([]byte, 2)
85 binary.BigEndian.PutUint16(bs, uint16(len(data)))
86
87 return Field{
88 ID: idBytes,
89 FieldSize: bs,
90 Data: data,
91 }
92}
93
94func (f Field) Payload() []byte {
95 return concat.Slices(f.ID, f.FieldSize, f.Data)
96}
97
98func getField(id int, fields *[]Field) *Field {
99 for _, field := range *fields {
100 if id == int(binary.BigEndian.Uint16(field.ID)) {
101 return &field
102 }
103 }
104 return nil
105}