]> git.r.bdr.sh - rbdr/mobius/blob - hotline/field.go
Move code to hotline dir
[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 const fieldUserAlias = 111
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 }
90
91 type FileNameWithInfo struct {
92 Type string // file type code
93 Creator []byte // File creator code
94 FileSize uint32 // File Size in bytes
95 NameScript []byte // TODO: What is this?
96 NameSize []byte // Length of name field
97 Name string // File name
98 }
99
100 func (f FileNameWithInfo) Payload() []byte {
101 name := []byte(f.Name)
102 nameSize := make([]byte, 2)
103 binary.BigEndian.PutUint16(nameSize, uint16(len(name)))
104
105 kb := f.FileSize
106
107 fSize := make([]byte, 4)
108 binary.BigEndian.PutUint32(fSize, kb)
109
110 return concat.Slices(
111 []byte(f.Type),
112 f.Creator,
113 fSize,
114 []byte{0, 0, 0, 0},
115 f.NameScript,
116 nameSize,
117 []byte(f.Name),
118 )
119
120 }