18 type TransactionType struct {
19 Access int // Specifies access privilege required to perform the transaction
20 DenyMsg string // The error reply message when user does not have access
21 Handler func(*ClientConn, *Transaction) ([]Transaction, error) // function for handling the transaction type
22 Name string // Name of transaction as it will appear in logging
23 RequiredFields []requiredField
26 var TransactionHandlers = map[uint16]TransactionType{
32 tranNotifyChangeUser: {
33 Name: "tranNotifyChangeUser",
39 Name: "tranShowAgreement",
42 Name: "tranUserAccess",
44 tranNotifyDeleteUser: {
45 Name: "tranNotifyDeleteUser",
48 Access: accessAlwaysAllow,
50 Handler: HandleTranAgreed,
53 Access: accessAlwaysAllow,
54 Handler: HandleChatSend,
56 RequiredFields: []requiredField{
64 Access: accessNewsDeleteArt,
65 DenyMsg: "You are not allowed to delete news articles.",
66 Name: "tranDelNewsArt",
67 Handler: HandleDelNewsArt,
70 Access: accessAlwaysAllow, // Granular access enforced inside the handler
71 // Has multiple access flags: News Delete Folder (37) or News Delete Category (35)
72 // TODO: Implement inside the handler
73 Name: "tranDelNewsItem",
74 Handler: HandleDelNewsItem,
77 Access: accessAlwaysAllow, // Granular access enforced inside the handler
78 Name: "tranDeleteFile",
79 Handler: HandleDeleteFile,
82 Access: accessAlwaysAllow,
83 Name: "tranDeleteUser",
84 Handler: HandleDeleteUser,
87 Access: accessDisconUser,
88 DenyMsg: "You are not allowed to disconnect users.",
89 Name: "tranDisconnectUser",
90 Handler: HandleDisconnectUser,
93 Access: accessAlwaysAllow,
94 Name: "tranDownloadFile",
95 Handler: HandleDownloadFile,
98 Access: accessDownloadFile, // There is no specific access flag for folder vs file download
99 DenyMsg: "You are not allowed to download files.",
100 Name: "tranDownloadFldr",
101 Handler: HandleDownloadFolder,
103 tranGetClientInfoText: {
104 Access: accessGetClientInfo,
105 DenyMsg: "You are not allowed to get client info",
106 Name: "tranGetClientInfoText",
107 Handler: HandleGetClientConnInfoText,
110 Access: accessAlwaysAllow,
111 Name: "tranGetFileInfo",
112 Handler: HandleGetFileInfo,
114 tranGetFileNameList: {
115 Access: accessAlwaysAllow,
116 Name: "tranGetFileNameList",
117 Handler: HandleGetFileNameList,
120 Access: accessAlwaysAllow,
122 Handler: HandleGetMsgs,
124 tranGetNewsArtData: {
125 Access: accessNewsReadArt,
126 DenyMsg: "You are not allowed to read news.",
127 Name: "tranGetNewsArtData",
128 Handler: HandleGetNewsArtData,
130 tranGetNewsArtNameList: {
131 Access: accessNewsReadArt,
132 DenyMsg: "You are not allowed to read news.",
133 Name: "tranGetNewsArtNameList",
134 Handler: HandleGetNewsArtNameList,
136 tranGetNewsCatNameList: {
137 Access: accessNewsReadArt,
138 DenyMsg: "You are not allowed to read news.",
139 Name: "tranGetNewsCatNameList",
140 Handler: HandleGetNewsCatNameList,
143 Access: accessAlwaysAllow,
145 Handler: HandleGetUser,
147 tranGetUserNameList: {
148 Access: accessAlwaysAllow,
149 Name: "tranHandleGetUserNameList",
150 Handler: HandleGetUserNameList,
153 Access: accessOpenChat,
154 DenyMsg: "You are not allowed to request private chat.",
155 Name: "tranInviteNewChat",
156 Handler: HandleInviteNewChat,
159 Access: accessOpenChat,
160 DenyMsg: "You are not allowed to request private chat.",
161 Name: "tranInviteToChat",
162 Handler: HandleInviteToChat,
165 Access: accessAlwaysAllow,
166 Name: "tranJoinChat",
167 Handler: HandleJoinChat,
170 Access: accessAlwaysAllow,
171 Name: "tranKeepAlive",
172 Handler: HandleKeepAlive,
175 Access: accessAlwaysAllow,
176 Name: "tranJoinChat",
177 Handler: HandleLeaveChat,
180 Access: accessAlwaysAllow,
181 Name: "tranListUsers",
182 Handler: HandleListUsers,
185 Access: accessMoveFile,
186 DenyMsg: "You are not allowed to move files.",
187 Name: "tranMoveFile",
188 Handler: HandleMoveFile,
191 Access: accessCreateFolder,
192 DenyMsg: "You are not allow to create folders.",
193 Name: "tranNewFolder",
194 Handler: HandleNewFolder,
197 Access: accessNewsCreateCat,
198 DenyMsg: "You are not allowed to create news categories.",
199 Name: "tranNewNewsCat",
200 Handler: HandleNewNewsCat,
203 Access: accessNewsCreateFldr,
204 DenyMsg: "You are not allowed to create news folders.",
205 Name: "tranNewNewsFldr",
206 Handler: HandleNewNewsFldr,
209 Access: accessAlwaysAllow,
211 Handler: HandleNewUser,
214 Access: accessNewsPostArt,
215 DenyMsg: "You are not allowed to post news.",
216 Name: "tranOldPostNews",
217 Handler: HandleTranOldPostNews,
220 Access: accessNewsPostArt,
221 DenyMsg: "You are not allowed to post news articles.",
222 Name: "tranPostNewsArt",
223 Handler: HandlePostNewsArt,
225 tranRejectChatInvite: {
226 Access: accessAlwaysAllow,
227 Name: "tranRejectChatInvite",
228 Handler: HandleRejectChatInvite,
230 tranSendInstantMsg: {
231 Access: accessAlwaysAllow,
232 // Access: accessSendPrivMsg,
233 // DenyMsg: "You are not allowed to send private messages",
234 Name: "tranSendInstantMsg",
235 Handler: HandleSendInstantMsg,
236 RequiredFields: []requiredField{
246 tranSetChatSubject: {
247 Access: accessAlwaysAllow,
248 Name: "tranSetChatSubject",
249 Handler: HandleSetChatSubject,
252 Access: accessAlwaysAllow,
253 Name: "tranMakeFileAlias",
254 Handler: HandleMakeAlias,
255 RequiredFields: []requiredField{
256 {ID: fieldFileName, minLen: 1},
257 {ID: fieldFilePath, minLen: 1},
258 {ID: fieldFileNewPath, minLen: 1},
261 tranSetClientUserInfo: {
262 Access: accessAlwaysAllow,
263 Name: "tranSetClientUserInfo",
264 Handler: HandleSetClientUserInfo,
267 Access: accessAlwaysAllow,
268 Name: "tranSetFileInfo",
269 Handler: HandleSetFileInfo,
272 Access: accessModifyUser,
273 DenyMsg: "You are not allowed to modify accounts.",
275 Handler: HandleSetUser,
278 Access: accessAlwaysAllow,
279 Name: "tranUploadFile",
280 Handler: HandleUploadFile,
283 Access: accessAlwaysAllow,
284 Name: "tranUploadFldr",
285 Handler: HandleUploadFolder,
288 Access: accessBroadcast,
289 DenyMsg: "You are not allowed to send broadcast messages.",
290 Name: "tranUserBroadcast",
291 Handler: HandleUserBroadcast,
295 func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
296 if !authorize(cc.Account.Access, accessSendChat) {
297 res = append(res, cc.NewErrReply(t, "You are not allowed to participate in chat."))
301 // Truncate long usernames
302 trunc := fmt.Sprintf("%13s", cc.UserName)
303 formattedMsg := fmt.Sprintf("\r%.14s: %s", trunc, t.GetField(fieldData).Data)
305 // By holding the option key, Hotline chat allows users to send /me formatted messages like:
306 // *** Halcyon does stuff
307 // This is indicated by the presence of the optional field fieldChatOptions in the transaction payload
308 if t.GetField(fieldChatOptions).Data != nil {
309 formattedMsg = fmt.Sprintf("\r*** %s %s", cc.UserName, t.GetField(fieldData).Data)
312 if bytes.Equal(t.GetField(fieldData).Data, []byte("/stats")) {
313 formattedMsg = strings.Replace(cc.Server.Stats.String(), "\n", "\r", -1)
316 chatID := t.GetField(fieldChatID).Data
317 // a non-nil chatID indicates the message belongs to a private chat
319 chatInt := binary.BigEndian.Uint32(chatID)
320 privChat := cc.Server.PrivateChats[chatInt]
322 clients := sortedClients(privChat.ClientConn)
324 // send the message to all connected clients of the private chat
325 for _, c := range clients {
326 res = append(res, *NewTransaction(
329 NewField(fieldChatID, chatID),
330 NewField(fieldData, []byte(formattedMsg)),
336 for _, c := range sortedClients(cc.Server.Clients) {
337 // Filter out clients that do not have the read chat permission
338 if authorize(c.Account.Access, accessReadChat) {
339 res = append(res, *NewTransaction(tranChatMsg, c.ID, NewField(fieldData, []byte(formattedMsg))))
346 // HandleSendInstantMsg sends instant message to the user on the current server.
347 // Fields used in the request:
350 // One of the following values:
351 // - User message (myOpt_UserMessage = 1)
352 // - Refuse message (myOpt_RefuseMessage = 2)
353 // - Refuse chat (myOpt_RefuseChat = 3)
354 // - Automatic response (myOpt_AutomaticResponse = 4)"
356 // 214 Quoting message Optional
358 // Fields used in the reply:
360 func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
361 msg := t.GetField(fieldData)
362 ID := t.GetField(fieldUserID)
364 reply := *NewTransaction(
367 NewField(fieldData, msg.Data),
368 NewField(fieldUserName, cc.UserName),
369 NewField(fieldUserID, *cc.ID),
370 NewField(fieldOptions, []byte{0, 1}),
373 // Later versions of Hotline include the original message in the fieldQuotingMsg field so
374 // the receiving client can display both the received message and what it is in reply to
375 if t.GetField(fieldQuotingMsg).Data != nil {
376 reply.Fields = append(reply.Fields, NewField(fieldQuotingMsg, t.GetField(fieldQuotingMsg).Data))
379 res = append(res, reply)
381 id, _ := byteToInt(ID.Data)
382 otherClient := cc.Server.Clients[uint16(id)]
383 if otherClient == nil {
384 return res, errors.New("ohno")
387 // Respond with auto reply if other client has it enabled
388 if len(otherClient.AutoReply) > 0 {
393 NewField(fieldData, otherClient.AutoReply),
394 NewField(fieldUserName, otherClient.UserName),
395 NewField(fieldUserID, *otherClient.ID),
396 NewField(fieldOptions, []byte{0, 1}),
401 res = append(res, cc.NewReply(t))
406 func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
407 fileName := t.GetField(fieldFileName).Data
408 filePath := t.GetField(fieldFilePath).Data
410 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName, 0)
415 res = append(res, cc.NewReply(t,
416 NewField(fieldFileName, fileName),
417 NewField(fieldFileTypeString, ffo.FlatFileInformationFork.TypeSignature),
418 NewField(fieldFileCreatorString, ffo.FlatFileInformationFork.CreatorSignature),
419 NewField(fieldFileComment, ffo.FlatFileInformationFork.Comment),
420 NewField(fieldFileType, ffo.FlatFileInformationFork.TypeSignature),
421 NewField(fieldFileCreateDate, ffo.FlatFileInformationFork.CreateDate),
422 NewField(fieldFileModifyDate, ffo.FlatFileInformationFork.ModifyDate),
423 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
428 // HandleSetFileInfo updates a file or folder name and/or comment from the Get Info window
429 // TODO: Implement support for comments
430 // Fields used in the request:
432 // * 202 File path Optional
433 // * 211 File new name Optional
434 // * 210 File comment Optional
435 // Fields used in the reply: None
436 func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
437 fileName := t.GetField(fieldFileName).Data
438 filePath := t.GetField(fieldFilePath).Data
440 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
445 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, t.GetField(fieldFileNewName).Data)
450 // fileComment := t.GetField(fieldFileComment).Data
451 fileNewName := t.GetField(fieldFileNewName).Data
453 if fileNewName != nil {
454 fi, err := FS.Stat(fullFilePath)
458 switch mode := fi.Mode(); {
460 if !authorize(cc.Account.Access, accessRenameFolder) {
461 res = append(res, cc.NewErrReply(t, "You are not allowed to rename folders."))
464 case mode.IsRegular():
465 if !authorize(cc.Account.Access, accessRenameFile) {
466 res = append(res, cc.NewErrReply(t, "You are not allowed to rename files."))
471 err = os.Rename(fullFilePath, fullNewFilePath)
472 if os.IsNotExist(err) {
473 res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
478 res = append(res, cc.NewReply(t))
482 // HandleDeleteFile deletes a file or folder
483 // Fields used in the request:
486 // Fields used in the reply: none
487 func HandleDeleteFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
488 fileName := t.GetField(fieldFileName).Data
489 filePath := t.GetField(fieldFilePath).Data
491 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
496 cc.Server.Logger.Debugw("Delete file", "src", fullFilePath)
498 fi, err := os.Stat(fullFilePath)
500 res = append(res, cc.NewErrReply(t, "Cannot delete file "+string(fileName)+" because it does not exist or cannot be found."))
503 switch mode := fi.Mode(); {
505 if !authorize(cc.Account.Access, accessDeleteFolder) {
506 res = append(res, cc.NewErrReply(t, "You are not allowed to delete folders."))
509 case mode.IsRegular():
510 if !authorize(cc.Account.Access, accessDeleteFile) {
511 res = append(res, cc.NewErrReply(t, "You are not allowed to delete files."))
516 if err := os.RemoveAll(fullFilePath); err != nil {
520 res = append(res, cc.NewReply(t))
524 // HandleMoveFile moves files or folders. Note: seemingly not documented
525 func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
526 fileName := string(t.GetField(fieldFileName).Data)
527 filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
528 fileNewPath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFileNewPath).Data)
530 cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName)
532 fp := filePath + "/" + fileName
533 fi, err := os.Stat(fp)
537 switch mode := fi.Mode(); {
539 if !authorize(cc.Account.Access, accessMoveFolder) {
540 res = append(res, cc.NewErrReply(t, "You are not allowed to move folders."))
543 case mode.IsRegular():
544 if !authorize(cc.Account.Access, accessMoveFile) {
545 res = append(res, cc.NewErrReply(t, "You are not allowed to move files."))
550 err = os.Rename(filePath+"/"+fileName, fileNewPath+"/"+fileName)
551 if os.IsNotExist(err) {
552 res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
556 return []Transaction{}, err
558 // TODO: handle other possible errors; e.g. file delete fails due to file permission issue
560 res = append(res, cc.NewReply(t))
564 func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
565 newFolderPath := cc.Server.Config.FileRoot
566 folderName := string(t.GetField(fieldFileName).Data)
568 folderName = path.Join("/", folderName)
570 // fieldFilePath is only present for nested paths
571 if t.GetField(fieldFilePath).Data != nil {
573 err := newFp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
577 newFolderPath += newFp.String()
579 newFolderPath = path.Join(newFolderPath, folderName)
581 // TODO: check path and folder name lengths
583 if _, err := FS.Stat(newFolderPath); !os.IsNotExist(err) {
584 msg := fmt.Sprintf("Cannot create folder \"%s\" because there is already a file or folder with that name.", folderName)
585 return []Transaction{cc.NewErrReply(t, msg)}, nil
588 // TODO: check for disallowed characters to maintain compatibility for original client
590 if err := FS.Mkdir(newFolderPath, 0777); err != nil {
591 msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
592 return []Transaction{cc.NewErrReply(t, msg)}, nil
595 res = append(res, cc.NewReply(t))
599 func HandleSetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
600 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
601 userName := string(t.GetField(fieldUserName).Data)
603 newAccessLvl := t.GetField(fieldUserAccess).Data
605 account := cc.Server.Accounts[login]
606 account.Access = &newAccessLvl
607 account.Name = userName
609 // If the password field is cleared in the Hotline edit user UI, the SetUser transaction does
610 // not include fieldUserPassword
611 if t.GetField(fieldUserPassword).Data == nil {
612 account.Password = hashAndSalt([]byte(""))
614 if len(t.GetField(fieldUserPassword).Data) > 1 {
615 account.Password = hashAndSalt(t.GetField(fieldUserPassword).Data)
618 file := cc.Server.ConfigDir + "Users/" + login + ".yaml"
619 out, err := yaml.Marshal(&account)
623 if err := ioutil.WriteFile(file, out, 0666); err != nil {
627 // Notify connected clients logged in as the user of the new access level
628 for _, c := range cc.Server.Clients {
629 if c.Account.Login == login {
630 // Note: comment out these two lines to test server-side deny messages
631 newT := NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, newAccessLvl))
632 res = append(res, *newT)
634 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
635 if authorize(c.Account.Access, accessDisconUser) {
636 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 1)
638 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 0)
640 binary.BigEndian.PutUint16(*c.Flags, uint16(flagBitmap.Int64()))
642 c.Account.Access = account.Access
645 tranNotifyChangeUser,
646 NewField(fieldUserID, *c.ID),
647 NewField(fieldUserFlags, *c.Flags),
648 NewField(fieldUserName, c.UserName),
649 NewField(fieldUserIconID, *c.Icon),
654 res = append(res, cc.NewReply(t))
658 func HandleGetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
659 if !authorize(cc.Account.Access, accessOpenUser) {
660 res = append(res, cc.NewErrReply(t, "You are not allowed to view accounts."))
664 account := cc.Server.Accounts[string(t.GetField(fieldUserLogin).Data)]
666 res = append(res, cc.NewErrReply(t, "Account does not exist."))
670 res = append(res, cc.NewReply(t,
671 NewField(fieldUserName, []byte(account.Name)),
672 NewField(fieldUserLogin, negateString(t.GetField(fieldUserLogin).Data)),
673 NewField(fieldUserPassword, []byte(account.Password)),
674 NewField(fieldUserAccess, *account.Access),
679 func HandleListUsers(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
680 if !authorize(cc.Account.Access, accessOpenUser) {
681 res = append(res, cc.NewErrReply(t, "You are not allowed to view accounts."))
685 var userFields []Field
686 // TODO: make order deterministic
687 for _, acc := range cc.Server.Accounts {
688 userField := acc.MarshalBinary()
689 userFields = append(userFields, NewField(fieldData, userField))
692 res = append(res, cc.NewReply(t, userFields...))
696 // HandleNewUser creates a new user account
697 func HandleNewUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
698 if !authorize(cc.Account.Access, accessCreateUser) {
699 res = append(res, cc.NewErrReply(t, "You are not allowed to create new accounts."))
703 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
705 // If the account already exists, reply with an error
706 if _, ok := cc.Server.Accounts[login]; ok {
707 res = append(res, cc.NewErrReply(t, "Cannot create account "+login+" because there is already an account with that login."))
711 if err := cc.Server.NewUser(
713 string(t.GetField(fieldUserName).Data),
714 string(t.GetField(fieldUserPassword).Data),
715 t.GetField(fieldUserAccess).Data,
717 return []Transaction{}, err
720 res = append(res, cc.NewReply(t))
724 func HandleDeleteUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
725 if !authorize(cc.Account.Access, accessDeleteUser) {
726 res = append(res, cc.NewErrReply(t, "You are not allowed to delete accounts."))
730 // TODO: Handle case where account doesn't exist; e.g. delete race condition
731 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
733 if err := cc.Server.DeleteUser(login); err != nil {
737 res = append(res, cc.NewReply(t))
741 // HandleUserBroadcast sends an Administrator Message to all connected clients of the server
742 func HandleUserBroadcast(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
745 NewField(fieldData, t.GetField(tranGetMsgs).Data),
746 NewField(fieldChatOptions, []byte{0}),
749 res = append(res, cc.NewReply(t))
753 func byteToInt(bytes []byte) (int, error) {
756 return int(binary.BigEndian.Uint16(bytes)), nil
758 return int(binary.BigEndian.Uint32(bytes)), nil
761 return 0, errors.New("unknown byte length")
764 func HandleGetClientConnInfoText(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
765 clientID, _ := byteToInt(t.GetField(fieldUserID).Data)
767 clientConn := cc.Server.Clients[uint16(clientID)]
768 if clientConn == nil {
769 return res, errors.New("invalid client")
772 // TODO: Implement non-hardcoded values
773 template := `Nickname: %s
778 -------- File Downloads ---------
782 ------- Folder Downloads --------
786 --------- File Uploads ----------
790 -------- Folder Uploads ---------
794 ------- Waiting Downloads -------
800 activeDownloads := clientConn.Transfers[FileDownload]
801 activeDownloadList := "None."
802 for _, dl := range activeDownloads {
803 activeDownloadList += dl.String() + "\n"
806 template = fmt.Sprintf(
809 clientConn.Account.Name,
810 clientConn.Account.Login,
811 clientConn.Connection.RemoteAddr().String(),
814 template = strings.Replace(template, "\n", "\r", -1)
816 res = append(res, cc.NewReply(t,
817 NewField(fieldData, []byte(template)),
818 NewField(fieldUserName, clientConn.UserName),
823 func HandleGetUserNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
824 res = append(res, cc.NewReply(t, cc.Server.connectedUsers()...))
829 func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
831 cc.UserName = t.GetField(fieldUserName).Data
832 *cc.Icon = t.GetField(fieldUserIconID).Data
834 options := t.GetField(fieldOptions).Data
835 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
837 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
839 // Check refuse private PM option
840 if optBitmap.Bit(refusePM) == 1 {
841 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, 1)
842 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
845 // Check refuse private chat option
846 if optBitmap.Bit(refuseChat) == 1 {
847 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, 1)
848 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
851 // Check auto response
852 if optBitmap.Bit(autoResponse) == 1 {
853 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
855 cc.AutoReply = []byte{}
860 tranNotifyChangeUser, nil,
861 NewField(fieldUserName, cc.UserName),
862 NewField(fieldUserID, *cc.ID),
863 NewField(fieldUserIconID, *cc.Icon),
864 NewField(fieldUserFlags, *cc.Flags),
868 res = append(res, cc.NewReply(t))
873 const defaultNewsDateFormat = "Jan02 15:04" // Jun23 20:49
874 // "Mon, 02 Jan 2006 15:04:05 MST"
876 const defaultNewsTemplate = `From %s (%s):
880 __________________________________________________________`
882 // HandleTranOldPostNews updates the flat news
883 // Fields used in this request:
885 func HandleTranOldPostNews(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
886 cc.Server.flatNewsMux.Lock()
887 defer cc.Server.flatNewsMux.Unlock()
889 newsDateTemplate := defaultNewsDateFormat
890 if cc.Server.Config.NewsDateFormat != "" {
891 newsDateTemplate = cc.Server.Config.NewsDateFormat
894 newsTemplate := defaultNewsTemplate
895 if cc.Server.Config.NewsDelimiter != "" {
896 newsTemplate = cc.Server.Config.NewsDelimiter
899 newsPost := fmt.Sprintf(newsTemplate+"\r", cc.UserName, time.Now().Format(newsDateTemplate), t.GetField(fieldData).Data)
900 newsPost = strings.Replace(newsPost, "\n", "\r", -1)
902 // update news in memory
903 cc.Server.FlatNews = append([]byte(newsPost), cc.Server.FlatNews...)
905 // update news on disk
906 if err := ioutil.WriteFile(cc.Server.ConfigDir+"MessageBoard.txt", cc.Server.FlatNews, 0644); err != nil {
910 // Notify all clients of updated news
913 NewField(fieldData, []byte(newsPost)),
916 res = append(res, cc.NewReply(t))
920 func HandleDisconnectUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
921 clientConn := cc.Server.Clients[binary.BigEndian.Uint16(t.GetField(fieldUserID).Data)]
923 if authorize(clientConn.Account.Access, accessCannotBeDiscon) {
924 res = append(res, cc.NewErrReply(t, clientConn.Account.Login+" is not allowed to be disconnected."))
928 if err := clientConn.Connection.Close(); err != nil {
932 res = append(res, cc.NewReply(t))
936 func HandleGetNewsCatNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
937 // Fields used in the request:
938 // 325 News path (Optional)
940 newsPath := t.GetField(fieldNewsPath).Data
941 cc.Server.Logger.Infow("NewsPath: ", "np", string(newsPath))
943 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
944 cats := cc.Server.GetNewsCatByPath(pathStrs)
946 // To store the keys in slice in sorted order
947 keys := make([]string, len(cats))
949 for k := range cats {
955 var fieldData []Field
956 for _, k := range keys {
958 b, _ := cat.MarshalBinary()
959 fieldData = append(fieldData, NewField(
960 fieldNewsCatListData15,
965 res = append(res, cc.NewReply(t, fieldData...))
969 func HandleNewNewsCat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
970 name := string(t.GetField(fieldNewsCatName).Data)
971 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
973 cats := cc.Server.GetNewsCatByPath(pathStrs)
974 cats[name] = NewsCategoryListData15{
977 Articles: map[uint32]*NewsArtData{},
978 SubCats: make(map[string]NewsCategoryListData15),
981 if err := cc.Server.writeThreadedNews(); err != nil {
984 res = append(res, cc.NewReply(t))
988 func HandleNewNewsFldr(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
989 // Fields used in the request:
990 // 322 News category name
992 name := string(t.GetField(fieldFileName).Data)
993 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
995 cc.Server.Logger.Infof("Creating new news folder %s", name)
997 cats := cc.Server.GetNewsCatByPath(pathStrs)
998 cats[name] = NewsCategoryListData15{
1001 Articles: map[uint32]*NewsArtData{},
1002 SubCats: make(map[string]NewsCategoryListData15),
1004 if err := cc.Server.writeThreadedNews(); err != nil {
1007 res = append(res, cc.NewReply(t))
1011 // Fields used in the request:
1012 // 325 News path Optional
1015 // 321 News article list data Optional
1016 func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1017 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1019 var cat NewsCategoryListData15
1020 cats := cc.Server.ThreadedNews.Categories
1022 for _, fp := range pathStrs {
1024 cats = cats[fp].SubCats
1027 nald := cat.GetNewsArtListData()
1029 res = append(res, cc.NewReply(t, NewField(fieldNewsArtListData, nald.Payload())))
1033 func HandleGetNewsArtData(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1036 // 326 News article ID
1037 // 327 News article data flavor
1039 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1041 var cat NewsCategoryListData15
1042 cats := cc.Server.ThreadedNews.Categories
1044 for _, fp := range pathStrs {
1046 cats = cats[fp].SubCats
1048 newsArtID := t.GetField(fieldNewsArtID).Data
1050 convertedArtID := binary.BigEndian.Uint16(newsArtID)
1052 art := cat.Articles[uint32(convertedArtID)]
1054 res = append(res, cc.NewReply(t))
1059 // 328 News article title
1060 // 329 News article poster
1061 // 330 News article date
1062 // 331 Previous article ID
1063 // 332 Next article ID
1064 // 335 Parent article ID
1065 // 336 First child article ID
1066 // 327 News article data flavor "Should be “text/plain”
1067 // 333 News article data Optional (if data flavor is “text/plain”)
1069 res = append(res, cc.NewReply(t,
1070 NewField(fieldNewsArtTitle, []byte(art.Title)),
1071 NewField(fieldNewsArtPoster, []byte(art.Poster)),
1072 NewField(fieldNewsArtDate, art.Date),
1073 NewField(fieldNewsArtPrevArt, art.PrevArt),
1074 NewField(fieldNewsArtNextArt, art.NextArt),
1075 NewField(fieldNewsArtParentArt, art.ParentArt),
1076 NewField(fieldNewsArt1stChildArt, art.FirstChildArt),
1077 NewField(fieldNewsArtDataFlav, []byte("text/plain")),
1078 NewField(fieldNewsArtData, []byte(art.Data)),
1083 func HandleDelNewsItem(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1084 // Access: News Delete Folder (37) or News Delete Category (35)
1086 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1088 // TODO: determine if path is a Folder (Bundle) or Category and check for permission
1090 cc.Server.Logger.Infof("DelNewsItem %v", pathStrs)
1092 cats := cc.Server.ThreadedNews.Categories
1094 delName := pathStrs[len(pathStrs)-1]
1095 if len(pathStrs) > 1 {
1096 for _, fp := range pathStrs[0 : len(pathStrs)-1] {
1097 cats = cats[fp].SubCats
1101 delete(cats, delName)
1103 err = cc.Server.writeThreadedNews()
1108 // Reply params: none
1109 res = append(res, cc.NewReply(t))
1114 func HandleDelNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1117 // 326 News article ID
1118 // 337 News article – recursive delete Delete child articles (1) or not (0)
1119 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1120 ID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1122 // TODO: Delete recursive
1123 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1125 catName := pathStrs[len(pathStrs)-1]
1126 cat := cats[catName]
1128 delete(cat.Articles, uint32(ID))
1131 if err := cc.Server.writeThreadedNews(); err != nil {
1135 res = append(res, cc.NewReply(t))
1139 func HandlePostNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1142 // 326 News article ID ID of the parent article?
1143 // 328 News article title
1144 // 334 News article flags
1145 // 327 News article data flavor Currently “text/plain”
1146 // 333 News article data
1148 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1149 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1151 catName := pathStrs[len(pathStrs)-1]
1152 cat := cats[catName]
1154 newArt := NewsArtData{
1155 Title: string(t.GetField(fieldNewsArtTitle).Data),
1156 Poster: string(cc.UserName),
1157 Date: toHotlineTime(time.Now()),
1158 PrevArt: []byte{0, 0, 0, 0},
1159 NextArt: []byte{0, 0, 0, 0},
1160 ParentArt: append([]byte{0, 0}, t.GetField(fieldNewsArtID).Data...),
1161 FirstChildArt: []byte{0, 0, 0, 0},
1162 DataFlav: []byte("text/plain"),
1163 Data: string(t.GetField(fieldNewsArtData).Data),
1167 for k := range cat.Articles {
1168 keys = append(keys, int(k))
1174 prevID := uint32(keys[len(keys)-1])
1177 binary.BigEndian.PutUint32(newArt.PrevArt, prevID)
1179 // Set next article ID
1180 binary.BigEndian.PutUint32(cat.Articles[prevID].NextArt, nextID)
1183 // Update parent article with first child reply
1184 parentID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1186 parentArt := cat.Articles[uint32(parentID)]
1188 if bytes.Equal(parentArt.FirstChildArt, []byte{0, 0, 0, 0}) {
1189 binary.BigEndian.PutUint32(parentArt.FirstChildArt, nextID)
1193 cat.Articles[nextID] = &newArt
1196 if err := cc.Server.writeThreadedNews(); err != nil {
1200 res = append(res, cc.NewReply(t))
1204 // HandleGetMsgs returns the flat news data
1205 func HandleGetMsgs(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1206 if !authorize(cc.Account.Access, accessNewsReadArt) {
1207 res = append(res, cc.NewErrReply(t, "You are not allowed to read news."))
1211 res = append(res, cc.NewReply(t, NewField(fieldData, cc.Server.FlatNews)))
1216 func HandleDownloadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1217 if !authorize(cc.Account.Access, accessDownloadFile) {
1218 res = append(res, cc.NewErrReply(t, "You are not allowed to download files."))
1222 fileName := t.GetField(fieldFileName).Data
1223 filePath := t.GetField(fieldFilePath).Data
1226 // transferOptions := t.GetField(fieldFileTransferOptions).Data
1227 resumeData := t.GetField(fieldFileResumeData).Data
1229 var dataOffset int64
1230 var frd FileResumeData
1231 if resumeData != nil {
1232 if err := frd.UnmarshalBinary(t.GetField(fieldFileResumeData).Data); err != nil {
1235 dataOffset = int64(binary.BigEndian.Uint32(frd.ForkInfoList[0].DataSize[:]))
1239 err = fp.UnmarshalBinary(filePath)
1244 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName, dataOffset)
1249 transactionRef := cc.Server.NewTransactionRef()
1250 data := binary.BigEndian.Uint32(transactionRef)
1252 ft := &FileTransfer{
1255 ReferenceNumber: transactionRef,
1259 if resumeData != nil {
1260 var frd FileResumeData
1261 frd.UnmarshalBinary(t.GetField(fieldFileResumeData).Data)
1262 ft.fileResumeData = &frd
1265 cc.Server.FileTransfers[data] = ft
1266 cc.Transfers[FileDownload] = append(cc.Transfers[FileDownload], ft)
1268 res = append(res, cc.NewReply(t,
1269 NewField(fieldRefNum, transactionRef),
1270 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1271 NewField(fieldTransferSize, ffo.TransferSize()),
1272 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
1278 // Download all files from the specified folder and sub-folders
1291 // 00 6c // transfer size
1295 // 00 dc // field Folder item count
1299 // 00 6b // ref number
1302 func HandleDownloadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1303 transactionRef := cc.Server.NewTransactionRef()
1304 data := binary.BigEndian.Uint32(transactionRef)
1306 fileTransfer := &FileTransfer{
1307 FileName: t.GetField(fieldFileName).Data,
1308 FilePath: t.GetField(fieldFilePath).Data,
1309 ReferenceNumber: transactionRef,
1310 Type: FolderDownload,
1312 cc.Server.FileTransfers[data] = fileTransfer
1313 cc.Transfers[FolderDownload] = append(cc.Transfers[FolderDownload], fileTransfer)
1316 err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
1321 fullFilePath, err := readPath(cc.Server.Config.FileRoot, t.GetField(fieldFilePath).Data, t.GetField(fieldFileName).Data)
1326 transferSize, err := CalcTotalSize(fullFilePath)
1330 itemCount, err := CalcItemCount(fullFilePath)
1334 res = append(res, cc.NewReply(t,
1335 NewField(fieldRefNum, transactionRef),
1336 NewField(fieldTransferSize, transferSize),
1337 NewField(fieldFolderItemCount, itemCount),
1338 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1343 // Upload all files from the local folder and its subfolders to the specified path on the server
1344 // Fields used in the request
1347 // 108 transfer size Total size of all items in the folder
1348 // 220 Folder item count
1349 // 204 File transfer options "Optional Currently set to 1" (TODO: ??)
1350 func HandleUploadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1351 transactionRef := cc.Server.NewTransactionRef()
1352 data := binary.BigEndian.Uint32(transactionRef)
1355 if t.GetField(fieldFilePath).Data != nil {
1356 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1361 // Handle special cases for Upload and Drop Box folders
1362 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1363 if !fp.IsUploadDir() && !fp.IsDropbox() {
1364 res = append(res, cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload of the folder \"%v\" because you are only allowed to upload to the \"Uploads\" folder.", string(t.GetField(fieldFileName).Data))))
1369 fileTransfer := &FileTransfer{
1370 FileName: t.GetField(fieldFileName).Data,
1371 FilePath: t.GetField(fieldFilePath).Data,
1372 ReferenceNumber: transactionRef,
1374 FolderItemCount: t.GetField(fieldFolderItemCount).Data,
1375 TransferSize: t.GetField(fieldTransferSize).Data,
1377 cc.Server.FileTransfers[data] = fileTransfer
1379 res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
1384 // Fields used in the request:
1387 // 204 File transfer options "Optional
1388 // Used only to resume download, currently has value 2"
1389 // 108 File transfer size "Optional used if download is not resumed"
1390 func HandleUploadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1391 if !authorize(cc.Account.Access, accessUploadFile) {
1392 res = append(res, cc.NewErrReply(t, "You are not allowed to upload files."))
1396 fileName := t.GetField(fieldFileName).Data
1397 filePath := t.GetField(fieldFilePath).Data
1399 transferOptions := t.GetField(fieldFileTransferOptions).Data
1401 // TODO: is this field useful for anything?
1402 // transferSize := t.GetField(fieldTransferSize).Data
1405 if filePath != nil {
1406 if err = fp.UnmarshalBinary(filePath); err != nil {
1411 // Handle special cases for Upload and Drop Box folders
1412 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1413 if !fp.IsUploadDir() && !fp.IsDropbox() {
1414 res = append(res, cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload of the file \"%v\" because you are only allowed to upload to the \"Uploads\" folder.", string(fileName))))
1419 transactionRef := cc.Server.NewTransactionRef()
1420 data := binary.BigEndian.Uint32(transactionRef)
1422 cc.Server.FileTransfers[data] = &FileTransfer{
1425 ReferenceNumber: transactionRef,
1429 replyT := cc.NewReply(t, NewField(fieldRefNum, transactionRef))
1431 // client has requested to resume a partially transfered file
1432 if transferOptions != nil {
1433 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
1438 fileInfo, err := FS.Stat(fullFilePath + incompleteFileSuffix)
1443 offset := make([]byte, 4)
1444 binary.BigEndian.PutUint32(offset, uint32(fileInfo.Size()))
1446 fileResumeData := NewFileResumeData([]ForkInfoList{
1447 *NewForkInfoList(offset),
1450 b, _ := fileResumeData.BinaryMarshal()
1452 replyT.Fields = append(replyT.Fields, NewField(fieldFileResumeData, b))
1455 res = append(res, replyT)
1459 func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1461 if len(t.GetField(fieldUserIconID).Data) == 4 {
1462 icon = t.GetField(fieldUserIconID).Data[2:]
1464 icon = t.GetField(fieldUserIconID).Data
1467 cc.UserName = t.GetField(fieldUserName).Data
1469 // the options field is only passed by the client versions > 1.2.3.
1470 options := t.GetField(fieldOptions).Data
1473 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
1474 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
1476 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, optBitmap.Bit(refusePM))
1477 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1479 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, optBitmap.Bit(refuseChat))
1480 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1482 // Check auto response
1483 if optBitmap.Bit(autoResponse) == 1 {
1484 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
1486 cc.AutoReply = []byte{}
1490 // Notify all clients of updated user info
1492 tranNotifyChangeUser,
1493 NewField(fieldUserID, *cc.ID),
1494 NewField(fieldUserIconID, *cc.Icon),
1495 NewField(fieldUserFlags, *cc.Flags),
1496 NewField(fieldUserName, cc.UserName),
1502 // HandleKeepAlive responds to keepalive transactions with an empty reply
1503 // * HL 1.9.2 Client sends keepalive msg every 3 minutes
1504 // * HL 1.2.3 Client doesn't send keepalives
1505 func HandleKeepAlive(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1506 res = append(res, cc.NewReply(t))
1511 func HandleGetFileNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1512 fullPath, err := readPath(
1513 cc.Server.Config.FileRoot,
1514 t.GetField(fieldFilePath).Data,
1522 if t.GetField(fieldFilePath).Data != nil {
1523 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1528 // Handle special case for drop box folders
1529 if fp.IsDropbox() && !authorize(cc.Account.Access, accessViewDropBoxes) {
1530 res = append(res, cc.NewReply(t))
1534 fileNames, err := getFileNameList(fullPath)
1539 res = append(res, cc.NewReply(t, fileNames...))
1544 // =================================
1545 // Hotline private chat flow
1546 // =================================
1547 // 1. ClientA sends tranInviteNewChat to server with user ID to invite
1548 // 2. Server creates new ChatID
1549 // 3. Server sends tranInviteToChat to invitee
1550 // 4. Server replies to ClientA with new Chat ID
1552 // A dialog box pops up in the invitee client with options to accept or decline the invitation.
1553 // If Accepted is clicked:
1554 // 1. ClientB sends tranJoinChat with fieldChatID
1556 // HandleInviteNewChat invites users to new private chat
1557 func HandleInviteNewChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1559 targetID := t.GetField(fieldUserID).Data
1560 newChatID := cc.Server.NewPrivateChat(cc)
1566 NewField(fieldChatID, newChatID),
1567 NewField(fieldUserName, cc.UserName),
1568 NewField(fieldUserID, *cc.ID),
1574 NewField(fieldChatID, newChatID),
1575 NewField(fieldUserName, cc.UserName),
1576 NewField(fieldUserID, *cc.ID),
1577 NewField(fieldUserIconID, *cc.Icon),
1578 NewField(fieldUserFlags, *cc.Flags),
1585 func HandleInviteToChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1587 targetID := t.GetField(fieldUserID).Data
1588 chatID := t.GetField(fieldChatID).Data
1594 NewField(fieldChatID, chatID),
1595 NewField(fieldUserName, cc.UserName),
1596 NewField(fieldUserID, *cc.ID),
1602 NewField(fieldChatID, chatID),
1603 NewField(fieldUserName, cc.UserName),
1604 NewField(fieldUserID, *cc.ID),
1605 NewField(fieldUserIconID, *cc.Icon),
1606 NewField(fieldUserFlags, *cc.Flags),
1613 func HandleRejectChatInvite(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1614 chatID := t.GetField(fieldChatID).Data
1615 chatInt := binary.BigEndian.Uint32(chatID)
1617 privChat := cc.Server.PrivateChats[chatInt]
1619 resMsg := append(cc.UserName, []byte(" declined invitation to chat")...)
1621 for _, c := range sortedClients(privChat.ClientConn) {
1626 NewField(fieldChatID, chatID),
1627 NewField(fieldData, resMsg),
1635 // HandleJoinChat is sent from a v1.8+ Hotline client when the joins a private chat
1636 // Fields used in the reply:
1637 // * 115 Chat subject
1638 // * 300 User name with info (Optional)
1639 // * 300 (more user names with info)
1640 func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1641 chatID := t.GetField(fieldChatID).Data
1642 chatInt := binary.BigEndian.Uint32(chatID)
1644 privChat := cc.Server.PrivateChats[chatInt]
1646 // Send tranNotifyChatChangeUser to current members of the chat to inform of new user
1647 for _, c := range sortedClients(privChat.ClientConn) {
1650 tranNotifyChatChangeUser,
1652 NewField(fieldChatID, chatID),
1653 NewField(fieldUserName, cc.UserName),
1654 NewField(fieldUserID, *cc.ID),
1655 NewField(fieldUserIconID, *cc.Icon),
1656 NewField(fieldUserFlags, *cc.Flags),
1661 privChat.ClientConn[cc.uint16ID()] = cc
1663 replyFields := []Field{NewField(fieldChatSubject, []byte(privChat.Subject))}
1664 for _, c := range sortedClients(privChat.ClientConn) {
1669 Name: string(c.UserName),
1672 replyFields = append(replyFields, NewField(fieldUsernameWithInfo, user.Payload()))
1675 res = append(res, cc.NewReply(t, replyFields...))
1679 // HandleLeaveChat is sent from a v1.8+ Hotline client when the user exits a private chat
1680 // Fields used in the request:
1681 // * 114 fieldChatID
1682 // Reply is not expected.
1683 func HandleLeaveChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1684 chatID := t.GetField(fieldChatID).Data
1685 chatInt := binary.BigEndian.Uint32(chatID)
1687 privChat := cc.Server.PrivateChats[chatInt]
1689 delete(privChat.ClientConn, cc.uint16ID())
1691 // Notify members of the private chat that the user has left
1692 for _, c := range sortedClients(privChat.ClientConn) {
1695 tranNotifyChatDeleteUser,
1697 NewField(fieldChatID, chatID),
1698 NewField(fieldUserID, *cc.ID),
1706 // HandleSetChatSubject is sent from a v1.8+ Hotline client when the user sets a private chat subject
1707 // Fields used in the request:
1709 // * 115 Chat subject Chat subject string
1710 // Reply is not expected.
1711 func HandleSetChatSubject(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1712 chatID := t.GetField(fieldChatID).Data
1713 chatInt := binary.BigEndian.Uint32(chatID)
1715 privChat := cc.Server.PrivateChats[chatInt]
1716 privChat.Subject = string(t.GetField(fieldChatSubject).Data)
1718 for _, c := range sortedClients(privChat.ClientConn) {
1721 tranNotifyChatSubject,
1723 NewField(fieldChatID, chatID),
1724 NewField(fieldChatSubject, t.GetField(fieldChatSubject).Data),
1732 // HandleMakeAlias makes a file alias using the specified path.
1733 // Fields used in the request:
1736 // 212 File new path Destination path
1738 // Fields used in the reply:
1740 func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1741 if !authorize(cc.Account.Access, accessMakeAlias) {
1742 res = append(res, cc.NewErrReply(t, "You are not allowed to make aliases."))
1745 fileName := t.GetField(fieldFileName).Data
1746 filePath := t.GetField(fieldFilePath).Data
1747 fileNewPath := t.GetField(fieldFileNewPath).Data
1749 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
1754 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
1759 cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
1761 if err := FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
1762 res = append(res, cc.NewErrReply(t, "Error creating alias"))
1766 res = append(res, cc.NewReply(t))