},
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",
// 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)
// 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()
}
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 {
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
}
+
+// 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
+}