"encoding/binary"
"errors"
"fmt"
- "github.com/davecgh/go-spew/spew"
"gopkg.in/yaml.v2"
"io/ioutil"
"math/big"
func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
// Truncate long usernames
- trunc := fmt.Sprintf("%13s", *cc.UserName)
+ trunc := fmt.Sprintf("%13s", cc.UserName)
formattedMsg := fmt.Sprintf("\r%.14s: %s", trunc, t.GetField(fieldData).Data)
// By holding the option key, Hotline chat allows users to send /me formatted messages like:
// *** Halcyon does stuff
// This is indicated by the presence of the optional field fieldChatOptions in the transaction payload
if t.GetField(fieldChatOptions).Data != nil {
- formattedMsg = fmt.Sprintf("\r*** %s %s", *cc.UserName, t.GetField(fieldData).Data)
+ formattedMsg = fmt.Sprintf("\r*** %s %s", cc.UserName, t.GetField(fieldData).Data)
}
if bytes.Equal(t.GetField(fieldData).Data, []byte("/stats")) {
tranServerMsg,
&ID.Data,
NewField(fieldData, msg.Data),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
NewField(fieldOptions, []byte{0, 1}),
),
tranServerMsg,
cc.ID,
NewField(fieldData, *otherClient.AutoReply),
- NewField(fieldUserName, *otherClient.UserName),
+ NewField(fieldUserName, otherClient.UserName),
NewField(fieldUserID, *otherClient.ID),
NewField(fieldOptions, []byte{0, 1}),
),
func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
fileName := string(t.GetField(fieldFileName).Data)
filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
- spew.Dump(cc.Server.Config.FileRoot)
ffo, err := NewFlattenedFileObject(filePath, fileName)
if err != nil {
fileName := string(t.GetField(fieldFileName).Data)
filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
- path := "./" + filePath + "/" + fileName
+ path := filePath + fileName
- cc.Server.Logger.Debugw("Delete file", "src", filePath+"/"+fileName)
+ cc.Server.Logger.Debugw("Delete file", "src", path)
fi, err := os.Stat(path)
if err != nil {
// HandleMoveFile moves files or folders. Note: seemingly not documented
func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
fileName := string(t.GetField(fieldFileName).Data)
- filePath := "./" + cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
- fileNewPath := "./" + cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFileNewPath).Data)
+ filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
+ fileNewPath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFileNewPath).Data)
cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName)
// fieldFilePath is only present for nested paths
if t.GetField(fieldFilePath).Data != nil {
- newFp := NewFilePath(t.GetField(fieldFilePath).Data)
+ var newFp FilePath
+ newFp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
newFolderPath += newFp.String()
}
newFolderPath += "/" + string(t.GetField(fieldFileName).Data)
tranNotifyChangeUser,
NewField(fieldUserID, *c.ID),
NewField(fieldUserFlags, *c.Flags),
- NewField(fieldUserName, *c.UserName),
+ NewField(fieldUserName, c.UserName),
NewField(fieldUserIconID, *c.Icon),
)
}
var userFields []Field
// TODO: make order deterministic
for _, acc := range cc.Server.Accounts {
- userField := acc.Payload()
+ userField := acc.MarshalBinary()
userFields = append(userFields, NewField(fieldData, userField))
}
template = fmt.Sprintf(
template,
- *clientConn.UserName,
+ clientConn.UserName,
clientConn.Account.Name,
clientConn.Account.Login,
clientConn.Connection.RemoteAddr().String(),
res = append(res, cc.NewReply(t,
NewField(fieldData, []byte(template)),
- NewField(fieldUserName, *clientConn.UserName),
+ NewField(fieldUserName, clientConn.UserName),
))
return res, err
}
cc.NotifyOthers(
*NewTransaction(
tranNotifyChangeUser, nil,
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
bs := make([]byte, 2)
binary.BigEndian.PutUint16(bs, *cc.Server.NextGuestID)
- *cc.UserName = t.GetField(fieldUserName).Data
+ cc.UserName = t.GetField(fieldUserName).Data
*cc.ID = bs
*cc.Icon = t.GetField(fieldUserIconID).Data
newsTemplate = cc.Server.Config.NewsDelimiter
}
- newsPost := fmt.Sprintf(newsTemplate+"\r", *cc.UserName, time.Now().Format(newsDateTemplate), t.GetField(fieldData).Data)
+ newsPost := fmt.Sprintf(newsTemplate+"\r", cc.UserName, time.Now().Format(newsDateTemplate), t.GetField(fieldData).Data)
newsPost = strings.Replace(newsPost, "\n", "\r", -1)
// update news in memory
var fieldData []Field
for _, k := range keys {
cat := cats[k]
+ b, _ := cat.MarshalBinary()
fieldData = append(fieldData, NewField(
fieldNewsCatListData15,
- cat.Payload(),
+ b,
))
}
newArt := NewsArtData{
Title: string(t.GetField(fieldNewsArtTitle).Data),
- Poster: string(*cc.UserName),
+ Poster: string(cc.UserName),
Date: NewsDate(),
PrevArt: []byte{0, 0, 0, 0},
NextArt: []byte{0, 0, 0, 0},
cc.Server.FileTransfers[data] = fileTransfer
cc.Transfers[FolderDownload] = append(cc.Transfers[FolderDownload], fileTransfer)
- fp := NewFilePath(t.GetField(fieldFilePath).Data)
+ var fp FilePath
+ err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
+ if err != nil {
+ return res, err
+ }
- fullFilePath := fmt.Sprintf("./%v/%v", cc.Server.Config.FileRoot+fp.String(), string(fileTransfer.FileName))
+ fullFilePath := fmt.Sprintf("%v%v", cc.Server.Config.FileRoot+fp.String(), string(fileTransfer.FileName))
transferSize, err := CalcTotalSize(fullFilePath)
if err != nil {
return res, err
icon = t.GetField(fieldUserIconID).Data
}
*cc.Icon = icon
- *cc.UserName = t.GetField(fieldUserName).Data
+ cc.UserName = t.GetField(fieldUserName).Data
// the options field is only passed by the client versions > 1.2.3.
options := t.GetField(fieldOptions).Data
NewField(fieldUserID, *cc.ID),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
)
return res, err
tranInviteToChat,
&targetID,
NewField(fieldChatID, newChatID),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
),
)
res = append(res,
cc.NewReply(t,
NewField(fieldChatID, newChatID),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
tranInviteToChat,
&targetID,
NewField(fieldChatID, chatID),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
),
)
cc.NewReply(
t,
NewField(fieldChatID, chatID),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
privChat := cc.Server.PrivateChats[chatInt]
- resMsg := append(*cc.UserName, []byte(" declined invitation to chat")...)
+ resMsg := append(cc.UserName, []byte(" declined invitation to chat")...)
for _, c := range sortedClients(privChat.ClientConn) {
res = append(res,
tranNotifyChatChangeUser,
c.ID,
NewField(fieldChatID, chatID),
- NewField(fieldUserName, *cc.UserName),
+ NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
ID: *c.ID,
Icon: *c.Icon,
Flags: *c.Flags,
- Name: string(*c.UserName),
+ Name: string(c.UserName),
}
replyFields = append(replyFields, NewField(fieldUsernameWithInfo, user.Payload()))