X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/22c599abc18895f73e96095f35b71cf3357d41b4..c8bfd6061f5079f6c6c0155a2de1e8cd32d8a39a:/hotline/field.go diff --git a/hotline/field.go b/hotline/field.go index 161a9b2..c5ae55b 100644 --- a/hotline/field.go +++ b/hotline/field.go @@ -5,58 +5,65 @@ import ( "github.com/jhalter/mobius/concat" ) -const fieldError = 100 -const fieldData = 101 -const fieldUserName = 102 -const fieldUserID = 103 -const fieldUserIconID = 104 -const fieldUserLogin = 105 -const fieldUserPassword = 106 -const fieldRefNum = 107 -const fieldTransferSize = 108 -const fieldChatOptions = 109 -const fieldUserAccess = 110 -const fieldUserAlias = 111 -const fieldUserFlags = 112 -const fieldOptions = 113 -const fieldChatID = 114 -const fieldChatSubject = 115 -const fieldWaitingCount = 116 -const fieldVersion = 160 -const fieldCommunityBannerID = 161 -const fieldServerName = 162 -const fieldFileNameWithInfo = 200 -const fieldFileName = 201 -const fieldFilePath = 202 -const fieldFileTypeString = 205 -const fieldFileCreatorString = 206 -const fieldFileSize = 207 -const fieldFileCreateDate = 208 -const fieldFileModifyDate = 209 -const fieldFileComment = 210 -const fieldFileNewName = 211 -const fieldFileNewPath = 212 -const fieldFileType = 213 -const fieldQuotingMsg = 214 // Defined but unused in the Hotline Protocol spec -const fieldAutomaticResponse = 215 -const fieldFolderItemCount = 220 -const fieldUsernameWithInfo = 300 -const fieldNewsArtListData = 321 -const fieldNewsCatName = 322 -const fieldNewsCatListData15 = 323 -const fieldNewsPath = 325 -const fieldNewsArtID = 326 -const fieldNewsArtDataFlav = 327 -const fieldNewsArtTitle = 328 -const fieldNewsArtPoster = 329 -const fieldNewsArtDate = 330 -const fieldNewsArtPrevArt = 331 -const fieldNewsArtNextArt = 332 -const fieldNewsArtData = 333 -const fieldNewsArtFlags = 334 -const fieldNewsArtParentArt = 335 -const fieldNewsArt1stChildArt = 336 -const fieldNewsArtRecurseDel = 337 +// List of Hotline protocol field types taken from the official 1.9 protocol document +const ( + FieldError = 100 + FieldData = 101 + FieldUserName = 102 + FieldUserID = 103 + FieldUserIconID = 104 + FieldUserLogin = 105 + FieldUserPassword = 106 + FieldRefNum = 107 + FieldTransferSize = 108 + FieldChatOptions = 109 + FieldUserAccess = 110 + FieldUserAlias = 111 // TODO: implement + FieldUserFlags = 112 + FieldOptions = 113 + FieldChatID = 114 + FieldChatSubject = 115 + FieldWaitingCount = 116 + FieldBannerType = 152 + FieldNoServerAgreement = 152 + FieldVersion = 160 + FieldCommunityBannerID = 161 + FieldServerName = 162 + FieldFileNameWithInfo = 200 + FieldFileName = 201 + FieldFilePath = 202 + FieldFileResumeData = 203 + FieldFileTransferOptions = 204 + FieldFileTypeString = 205 + FieldFileCreatorString = 206 + FieldFileSize = 207 + FieldFileCreateDate = 208 + FieldFileModifyDate = 209 + FieldFileComment = 210 + FieldFileNewName = 211 + FieldFileNewPath = 212 + FieldFileType = 213 + FieldQuotingMsg = 214 + FieldAutomaticResponse = 215 + FieldFolderItemCount = 220 + FieldUsernameWithInfo = 300 + FieldNewsArtListData = 321 + FieldNewsCatName = 322 + FieldNewsCatListData15 = 323 + FieldNewsPath = 325 + FieldNewsArtID = 326 + FieldNewsArtDataFlav = 327 + FieldNewsArtTitle = 328 + FieldNewsArtPoster = 329 + FieldNewsArtDate = 330 + FieldNewsArtPrevArt = 331 + FieldNewsArtNextArt = 332 + FieldNewsArtData = 333 + FieldNewsArtFlags = 334 // TODO: what is this used for? + FieldNewsArtParentArt = 335 + FieldNewsArt1stChildArt = 336 + FieldNewsArtRecurseDel = 337 // TODO: implement news article recusive deletion +) type Field struct { ID []byte // Type of field @@ -88,33 +95,11 @@ func (f Field) Payload() []byte { return concat.Slices(f.ID, f.FieldSize, f.Data) } -type FileNameWithInfo struct { - Type string // file type code - Creator []byte // File creator code - FileSize uint32 // File Size in bytes - NameScript []byte // TODO: What is this? - NameSize []byte // Length of name field - Name string // File name -} - -func (f FileNameWithInfo) Payload() []byte { - name := []byte(f.Name) - nameSize := make([]byte, 2) - binary.BigEndian.PutUint16(nameSize, uint16(len(name))) - - kb := f.FileSize - - fSize := make([]byte, 4) - binary.BigEndian.PutUint32(fSize, kb) - - return concat.Slices( - []byte(f.Type), - f.Creator, - fSize, - []byte{0, 0, 0, 0}, - f.NameScript, - nameSize, - []byte(f.Name), - ) - +func getField(id int, fields *[]Field) *Field { + for _, field := range *fields { + if id == int(binary.BigEndian.Uint16(field.ID)) { + return &field + } + } + return nil }