]>
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 | |
eabc4b6c | 19 | //const fieldUserAlias = 111 TODO: implement |
6988a057 JH |
20 | const fieldUserFlags = 112 |
21 | const fieldOptions = 113 | |
22 | const fieldChatID = 114 | |
23 | const fieldChatSubject = 115 | |
24 | const fieldWaitingCount = 116 | |
25 | const fieldVersion = 160 | |
26 | const fieldCommunityBannerID = 161 | |
27 | const fieldServerName = 162 | |
28 | const fieldFileNameWithInfo = 200 | |
29 | const fieldFileName = 201 | |
30 | const fieldFilePath = 202 | |
31 | const fieldFileTypeString = 205 | |
32 | const fieldFileCreatorString = 206 | |
33 | const fieldFileSize = 207 | |
34 | const fieldFileCreateDate = 208 | |
35 | const fieldFileModifyDate = 209 | |
36 | const fieldFileComment = 210 | |
37 | const fieldFileNewName = 211 | |
38 | const fieldFileNewPath = 212 | |
39 | const fieldFileType = 213 | |
40 | const fieldQuotingMsg = 214 // Defined but unused in the Hotline Protocol spec | |
41 | const fieldAutomaticResponse = 215 | |
42 | const fieldFolderItemCount = 220 | |
43 | const fieldUsernameWithInfo = 300 | |
44 | const fieldNewsArtListData = 321 | |
45 | const fieldNewsCatName = 322 | |
46 | const fieldNewsCatListData15 = 323 | |
47 | const fieldNewsPath = 325 | |
48 | const fieldNewsArtID = 326 | |
49 | const fieldNewsArtDataFlav = 327 | |
50 | const fieldNewsArtTitle = 328 | |
51 | const fieldNewsArtPoster = 329 | |
52 | const fieldNewsArtDate = 330 | |
53 | const fieldNewsArtPrevArt = 331 | |
54 | const fieldNewsArtNextArt = 332 | |
55 | const fieldNewsArtData = 333 | |
56 | const fieldNewsArtFlags = 334 | |
57 | const fieldNewsArtParentArt = 335 | |
58 | const fieldNewsArt1stChildArt = 336 | |
59 | const fieldNewsArtRecurseDel = 337 | |
60 | ||
61 | type Field struct { | |
62 | ID []byte // Type of field | |
63 | FieldSize []byte // Size of the data part | |
64 | Data []byte // Actual field content | |
65 | } | |
66 | ||
67 | type requiredField struct { | |
68 | ID int | |
69 | minLen int | |
70 | maxLen int | |
71 | } | |
72 | ||
73 | func NewField(id uint16, data []byte) Field { | |
74 | idBytes := make([]byte, 2) | |
75 | binary.BigEndian.PutUint16(idBytes, id) | |
76 | ||
77 | bs := make([]byte, 2) | |
78 | binary.BigEndian.PutUint16(bs, uint16(len(data))) | |
79 | ||
80 | return Field{ | |
81 | ID: idBytes, | |
82 | FieldSize: bs, | |
83 | Data: data, | |
84 | } | |
85 | } | |
86 | ||
87 | func (f Field) Payload() []byte { | |
88 | return concat.Slices(f.ID, f.FieldSize, f.Data) | |
89 | } |