)
type Server struct {
- Interface string
Port int
Accounts map[string]*Account
Agreement []byte
if client == nil {
return errors.New("invalid client")
}
- userName := string(*client.UserName)
+ userName := string(client.UserName)
login := client.Account.Login
handler := TransactionHandlers[requestNum]
+ b, err := t.MarshalBinary()
+ if err != nil {
+ return err
+ }
var n int
- if n, err = client.Connection.Write(t.Payload()); err != nil {
+ if n, err = client.Connection.Write(b); err != nil {
return err
}
s.Logger.Debugw("Sent Transaction",
const (
agreementFile = "Agreement.txt"
- messageBoardFile = "MessageBoard.txt"
- threadedNewsFile = "ThreadedNews.yaml"
)
// NewServer constructs a new Server from a config dir
tranNotifyChangeUser,
NewField(fieldUserID, *c.ID),
NewField(fieldUserFlags, *c.Flags),
- NewField(fieldUserName, *c.UserName),
+ NewField(fieldUserName, c.UserName),
NewField(fieldUserIconID, *c.Icon),
)
}
ID: &[]byte{0, 0},
Icon: &[]byte{0, 0},
Flags: &[]byte{0, 0},
- UserName: &[]byte{},
+ UserName: []byte{},
Connection: conn,
Server: s,
Version: &[]byte{},
ID: *c.ID,
Icon: *c.Icon,
Flags: *c.Flags,
- Name: string(*c.UserName),
+ Name: string(c.UserName),
}
connectedUsers = append(connectedUsers, NewField(fieldUsernameWithInfo, user.Payload()))
}
// If authentication fails, send error reply and close connection
if !c.Authenticate(login, encodedPassword) {
- rep := c.NewErrReply(clientLogin, "Incorrect login.")
- if _, err := conn.Write(rep.Payload()); err != nil {
+ t := c.NewErrReply(clientLogin, "Incorrect login.")
+ b, err := t.MarshalBinary()
+ if err != nil {
+ return err
+ }
+ if _, err := conn.Write(b); err != nil {
return err
}
return fmt.Errorf("incorrect login")
}
if clientLogin.GetField(fieldUserName).Data != nil {
- *c.UserName = clientLogin.GetField(fieldUserName).Data
+ c.UserName = clientLogin.GetField(fieldUserName).Data
}
if clientLogin.GetField(fieldUserIconID).Data != nil {
//
// This notifies the server to send the next item header
- fh := NewFilePath(fileTransfer.FilePath)
+ var fh FilePath
+ _ = fh.UnmarshalBinary(fileTransfer.FilePath)
fullFilePath := fmt.Sprintf("%v/%v", s.Config.FileRoot+fh.String(), string(fileTransfer.FileName))
basePathLen := len(fullFilePath)
i := 0
_ = filepath.Walk(fullFilePath+"/", func(path string, info os.FileInfo, _ error) error {
i += 1
- subPath := path[basePathLen-2:]
+ subPath := path[basePathLen:]
s.Logger.Infow("Sending fileheader", "i", i, "path", path, "fullFilePath", fullFilePath, "subPath", subPath, "IsDir", info.IsDir())
fileHeader := NewFileHeader(subPath, info.IsDir())