},
tranSendInstantMsg: {
Access: accessAlwaysAllow,
- //Access: accessSendPrivMsg,
- //DenyMsg: "You are not allowed to send private messages",
+ // Access: accessSendPrivMsg,
+ // DenyMsg: "You are not allowed to send private messages",
Name: "tranSendInstantMsg",
Handler: HandleSendInstantMsg,
RequiredFields: []requiredField{
Name: "tranSetChatSubject",
Handler: HandleSetChatSubject,
},
+ tranMakeFileAlias: {
+ Access: accessAlwaysAllow,
+ Name: "tranMakeFileAlias",
+ Handler: HandleMakeAlias,
+ RequiredFields: []requiredField{
+ {ID: fieldFileName, minLen: 1},
+ {ID: fieldFilePath, minLen: 1},
+ {ID: fieldFileNewPath, minLen: 1},
+ },
+ },
tranSetClientUserInfo: {
Access: accessAlwaysAllow,
Name: "tranSetClientUserInfo",
Handler: HandleSetUser,
},
tranUploadFile: {
- Access: accessUploadFile,
+ Access: accessAlwaysAllow,
DenyMsg: "You are not allowed to upload files.",
Name: "tranUploadFile",
Handler: HandleUploadFile,
// 101 Data Optional
// 214 Quoting message Optional
//
-//Fields used in the reply:
+// Fields used in the reply:
// None
func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
msg := t.GetField(fieldData)
ID := t.GetField(fieldUserID)
// TODO: Implement reply quoting
- //options := transaction.GetField(hotline.fieldOptions)
+ // options := transaction.GetField(hotline.fieldOptions)
res = append(res,
*NewTransaction(
)
id, _ := byteToInt(ID.Data)
- //keys := make([]uint16, 0, len(cc.Server.Clients))
- //for k := range cc.Server.Clients {
- // keys = append(keys, k)
- //}
-
otherClient := cc.Server.Clients[uint16(id)]
if otherClient == nil {
return res, errors.New("ohno")
}
// Respond with auto reply if other client has it enabled
- if len(*otherClient.AutoReply) > 0 {
+ if len(otherClient.AutoReply) > 0 {
res = append(res,
*NewTransaction(
tranServerMsg,
cc.ID,
- NewField(fieldData, *otherClient.AutoReply),
+ NewField(fieldData, otherClient.AutoReply),
NewField(fieldUserName, otherClient.UserName),
NewField(fieldUserID, *otherClient.ID),
NewField(fieldOptions, []byte{0, 1}),
return nil, err
}
- //fileComment := t.GetField(fieldFileComment).Data
+ // fileComment := t.GetField(fieldFileComment).Data
fileNewName := t.GetField(fieldFileNewName).Data
if fileNewName != nil {
}
func HandleGetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
- userLogin := string(t.GetField(fieldUserLogin).Data)
- account := cc.Server.Accounts[userLogin]
+ // userLogin := string(t.GetField(fieldUserLogin).Data)
+ account := cc.Server.Accounts[string(t.GetField(fieldUserLogin).Data)]
if account == nil {
errorT := cc.NewErrReply(t, "Account does not exist.")
res = append(res, errorT)
}
func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
- bs := make([]byte, 2)
- binary.BigEndian.PutUint16(bs, *cc.Server.NextGuestID)
-
+ cc.Agreed = true
cc.UserName = t.GetField(fieldUserName).Data
- *cc.ID = bs
*cc.Icon = t.GetField(fieldUserIconID).Data
options := t.GetField(fieldOptions).Data
// Check auto response
if optBitmap.Bit(autoResponse) == 1 {
- *cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
+ cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
} else {
- *cc.AutoReply = []byte{}
+ cc.AutoReply = []byte{}
}
_, _ = cc.notifyNewUserHasJoined()
newArt := NewsArtData{
Title: string(t.GetField(fieldNewsArtTitle).Data),
Poster: string(cc.UserName),
- Date: NewsDate(),
+ Date: toHotlineTime(time.Now()),
PrevArt: []byte{0, 0, 0, 0},
NextArt: []byte{0, 0, 0, 0},
ParentArt: append([]byte{0, 0}, t.GetField(fieldNewsArtID).Data...),
}
fullFilePath, err := readPath(cc.Server.Config.FileRoot, t.GetField(fieldFilePath).Data, t.GetField(fieldFileName).Data)
+ if err != nil {
+ return res, err
+ }
transferSize, err := CalcTotalSize(fullFilePath)
if err != nil {
}
func HandleUploadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
+ // TODO: add permission handing for upload folders and drop boxes
+ if !authorize(cc.Account.Access, accessUploadFile) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to upload files."))
+ return res, err
+ }
+
fileName := t.GetField(fieldFileName).Data
filePath := t.GetField(fieldFilePath).Data
transactionRef := cc.Server.NewTransactionRef()
data := binary.BigEndian.Uint32(transactionRef)
- fileTransfer := &FileTransfer{
+ cc.Server.FileTransfers[data] = &FileTransfer{
FileName: fileName,
FilePath: filePath,
ReferenceNumber: transactionRef,
Type: FileUpload,
}
- cc.Server.FileTransfers[data] = fileTransfer
-
res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
return res, err
}
optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
- // Check refuse private PM option
- if optBitmap.Bit(refusePM) == 1 {
- flagBitmap.SetBit(flagBitmap, userFlagRefusePM, 1)
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
- }
+ flagBitmap.SetBit(flagBitmap, userFlagRefusePM, optBitmap.Bit(refusePM))
+ binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
- // Check refuse private chat option
- if optBitmap.Bit(refuseChat) == 1 {
- flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, 1)
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
- }
+ flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, optBitmap.Bit(refuseChat))
+ binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
// Check auto response
if optBitmap.Bit(autoResponse) == 1 {
- *cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
+ cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
} else {
- *cc.AutoReply = []byte{}
+ cc.AutoReply = []byte{}
}
}
return res, err
}
-// HandleKeepAlive response to keepalive transactions with an empty reply
-// HL 1.9.2 Client sends keepalive msg every 3 minutes
-// HL 1.2.3 Client doesn't send keepalives
+// HandleKeepAlive responds to keepalive transactions with an empty reply
+// * HL 1.9.2 Client sends keepalive msg every 3 minutes
+// * HL 1.2.3 Client doesn't send keepalives
func HandleKeepAlive(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
res = append(res, cc.NewReply(t))
return res, err
}
+
+// HandleMakeAlias makes a file alias using the specified path.
+// Fields used in the request:
+// 201 File name
+// 202 File path
+// 212 File new path Destination path
+//
+// Fields used in the reply:
+// None
+func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
+ if !authorize(cc.Account.Access, accessMakeAlias) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to make aliases."))
+ return res, err
+ }
+ fileName := t.GetField(fieldFileName).Data
+ filePath := t.GetField(fieldFilePath).Data
+ fileNewPath := t.GetField(fieldFileNewPath).Data
+
+ fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
+ if err != nil {
+ return res, err
+ }
+
+ fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
+ if err != nil {
+ return res, err
+ }
+
+ cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
+
+ if err := FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
+ res = append(res, cc.NewErrReply(t, "Error creating alias"))
+ return res, nil
+ }
+
+ res = append(res, cc.NewReply(t))
+ return res, err
+}