]> git.r.bdr.sh - rbdr/mobius/blob - hotline/field.go
Implement multi-account edit
[rbdr/mobius] / hotline / field.go
1 package hotline
2
3 import (
4 "encoding/binary"
5 "github.com/jhalter/mobius/concat"
6 )
7
8 const fieldError = 100
9 const fieldData = 101
10 const fieldUserName = 102
11 const fieldUserID = 103
12 const fieldUserIconID = 104
13 const fieldUserLogin = 105
14 const fieldUserPassword = 106
15 const fieldRefNum = 107
16 const fieldTransferSize = 108
17 const fieldChatOptions = 109
18 const fieldUserAccess = 110
19
20 // const fieldUserAlias = 111 TODO: implement
21 const fieldUserFlags = 112
22 const fieldOptions = 113
23 const fieldChatID = 114
24 const fieldChatSubject = 115
25 const fieldWaitingCount = 116
26 const fieldVersion = 160
27 const fieldCommunityBannerID = 161
28 const fieldServerName = 162
29 const fieldFileNameWithInfo = 200
30 const fieldFileName = 201
31 const fieldFilePath = 202
32 const fieldFileResumeData = 203
33 const fieldFileTransferOptions = 204
34 const fieldFileTypeString = 205
35 const fieldFileCreatorString = 206
36 const fieldFileSize = 207
37 const fieldFileCreateDate = 208
38 const fieldFileModifyDate = 209
39 const fieldFileComment = 210
40 const fieldFileNewName = 211
41 const fieldFileNewPath = 212
42 const fieldFileType = 213
43 const fieldQuotingMsg = 214
44 const fieldAutomaticResponse = 215
45 const fieldFolderItemCount = 220
46 const fieldUsernameWithInfo = 300
47 const fieldNewsArtListData = 321
48 const fieldNewsCatName = 322
49 const fieldNewsCatListData15 = 323
50 const fieldNewsPath = 325
51 const fieldNewsArtID = 326
52 const fieldNewsArtDataFlav = 327
53 const fieldNewsArtTitle = 328
54 const fieldNewsArtPoster = 329
55 const fieldNewsArtDate = 330
56 const fieldNewsArtPrevArt = 331
57 const fieldNewsArtNextArt = 332
58 const fieldNewsArtData = 333
59 const fieldNewsArtFlags = 334
60 const fieldNewsArtParentArt = 335
61 const fieldNewsArt1stChildArt = 336
62 const fieldNewsArtRecurseDel = 337
63
64 type Field struct {
65 ID []byte // Type of field
66 FieldSize []byte // Size of the data part
67 Data []byte // Actual field content
68 }
69
70 type requiredField struct {
71 ID int
72 minLen int
73 maxLen int
74 }
75
76 func NewField(id uint16, data []byte) Field {
77 idBytes := make([]byte, 2)
78 binary.BigEndian.PutUint16(idBytes, id)
79
80 bs := make([]byte, 2)
81 binary.BigEndian.PutUint16(bs, uint16(len(data)))
82
83 return Field{
84 ID: idBytes,
85 FieldSize: bs,
86 Data: data,
87 }
88 }
89
90 func (f Field) Payload() []byte {
91 return concat.Slices(f.ID, f.FieldSize, f.Data)
92 }
93
94 func getField(id int, fields *[]Field) *Field {
95 for _, field := range *fields {
96 if id == int(binary.BigEndian.Uint16(field.ID)) {
97 return &field
98 }
99 }
100 return nil
101 }