]> git.r.bdr.sh - rbdr/mobius/blame - hotline/field.go
Move code to hotline dir
[rbdr/mobius] / hotline / field.go
CommitLineData
6988a057
JH
1package hotline
2
3import (
4 "encoding/binary"
5 "github.com/jhalter/mobius/concat"
6)
7
8const fieldError = 100
9const fieldData = 101
10const fieldUserName = 102
11const fieldUserID = 103
12const fieldUserIconID = 104
13const fieldUserLogin = 105
14const fieldUserPassword = 106
15const fieldRefNum = 107
16const fieldTransferSize = 108
17const fieldChatOptions = 109
18const fieldUserAccess = 110
19const fieldUserAlias = 111
20const fieldUserFlags = 112
21const fieldOptions = 113
22const fieldChatID = 114
23const fieldChatSubject = 115
24const fieldWaitingCount = 116
25const fieldVersion = 160
26const fieldCommunityBannerID = 161
27const fieldServerName = 162
28const fieldFileNameWithInfo = 200
29const fieldFileName = 201
30const fieldFilePath = 202
31const fieldFileTypeString = 205
32const fieldFileCreatorString = 206
33const fieldFileSize = 207
34const fieldFileCreateDate = 208
35const fieldFileModifyDate = 209
36const fieldFileComment = 210
37const fieldFileNewName = 211
38const fieldFileNewPath = 212
39const fieldFileType = 213
40const fieldQuotingMsg = 214 // Defined but unused in the Hotline Protocol spec
41const fieldAutomaticResponse = 215
42const fieldFolderItemCount = 220
43const fieldUsernameWithInfo = 300
44const fieldNewsArtListData = 321
45const fieldNewsCatName = 322
46const fieldNewsCatListData15 = 323
47const fieldNewsPath = 325
48const fieldNewsArtID = 326
49const fieldNewsArtDataFlav = 327
50const fieldNewsArtTitle = 328
51const fieldNewsArtPoster = 329
52const fieldNewsArtDate = 330
53const fieldNewsArtPrevArt = 331
54const fieldNewsArtNextArt = 332
55const fieldNewsArtData = 333
56const fieldNewsArtFlags = 334
57const fieldNewsArtParentArt = 335
58const fieldNewsArt1stChildArt = 336
59const fieldNewsArtRecurseDel = 337
60
61type Field struct {
62 ID []byte // Type of field
63 FieldSize []byte // Size of the data part
64 Data []byte // Actual field content
65}
66
67type requiredField struct {
68 ID int
69 minLen int
70 maxLen int
71}
72
73func 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
87func (f Field) Payload() []byte {
88 return concat.Slices(f.ID, f.FieldSize, f.Data)
89}
90
91type 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
100func (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}