]>
Commit | Line | Data |
---|---|---|
6988a057 JH |
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 | |
aebc4d36 JH |
19 | |
20 | // const fieldUserAlias = 111 TODO: implement | |
6988a057 | 21 | const fieldUserFlags = 112 |
ea5d8c51 | 22 | const fieldOptions = 113 |
6988a057 JH |
23 | const fieldChatID = 114 |
24 | const fieldChatSubject = 115 | |
25 | const fieldWaitingCount = 116 | |
9067f234 | 26 | const fieldBannerType = 152 |
688c86d2 | 27 | const fieldNoServerAgreement = 152 |
6988a057 JH |
28 | const fieldVersion = 160 |
29 | const fieldCommunityBannerID = 161 | |
30 | const fieldServerName = 162 | |
31 | const fieldFileNameWithInfo = 200 | |
32 | const fieldFileName = 201 | |
33 | const fieldFilePath = 202 | |
16a4ad70 JH |
34 | const fieldFileResumeData = 203 |
35 | const fieldFileTransferOptions = 204 | |
6988a057 JH |
36 | const fieldFileTypeString = 205 |
37 | const fieldFileCreatorString = 206 | |
38 | const fieldFileSize = 207 | |
39 | const fieldFileCreateDate = 208 | |
40 | const fieldFileModifyDate = 209 | |
41 | const fieldFileComment = 210 | |
42 | const fieldFileNewName = 211 | |
43 | const fieldFileNewPath = 212 | |
44 | const fieldFileType = 213 | |
5ae50876 | 45 | const fieldQuotingMsg = 214 |
6988a057 JH |
46 | const fieldAutomaticResponse = 215 |
47 | const fieldFolderItemCount = 220 | |
48 | const fieldUsernameWithInfo = 300 | |
49 | const fieldNewsArtListData = 321 | |
50 | const fieldNewsCatName = 322 | |
51 | const fieldNewsCatListData15 = 323 | |
52 | const fieldNewsPath = 325 | |
53 | const fieldNewsArtID = 326 | |
54 | const fieldNewsArtDataFlav = 327 | |
55 | const fieldNewsArtTitle = 328 | |
56 | const fieldNewsArtPoster = 329 | |
57 | const fieldNewsArtDate = 330 | |
58 | const fieldNewsArtPrevArt = 331 | |
59 | const fieldNewsArtNextArt = 332 | |
60 | const fieldNewsArtData = 333 | |
043c00da JH |
61 | |
62 | // const fieldNewsArtFlags = 334 | |
6988a057 JH |
63 | const fieldNewsArtParentArt = 335 |
64 | const fieldNewsArt1stChildArt = 336 | |
043c00da JH |
65 | |
66 | // const fieldNewsArtRecurseDel = 337 | |
6988a057 JH |
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 | maxLen int | |
78 | } | |
79 | ||
80 | func 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 | ||
94 | func (f Field) Payload() []byte { | |
95 | return concat.Slices(f.ID, f.FieldSize, f.Data) | |
96 | } | |
d2810ae9 JH |
97 | |
98 | func 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 | } |