func (s *Server) sendTransaction(t Transaction) error {
clientID, err := byteToInt(*t.clientID)
if err != nil {
- return err
+ return fmt.Errorf("invalid client ID: %v", err)
}
s.mux.Lock()
- client := s.Clients[uint16(clientID)]
+ client, ok := s.Clients[uint16(clientID)]
s.mux.Unlock()
- if client == nil {
+ if !ok || client == nil {
return fmt.Errorf("invalid client id %v", *t.clientID)
}
- b, err := t.MarshalBinary()
- if err != nil {
- return err
- }
-
- _, err = client.Connection.Write(b)
+ _, err = io.Copy(client.Connection, &t)
if err != nil {
- return err
+ return fmt.Errorf("failed to send transaction to client %v: %v", clientID, err)
}
return nil
NewField(FieldChatOptions, []byte{0, 0}),
)
- b, err := t.MarshalBinary()
- if err != nil {
- return err
- }
-
- _, err = rwc.Write(b)
+ _, err := io.Copy(rwc, t)
if err != nil {
return err
}
NewField(FieldData, []byte("You are temporarily banned on this server")),
NewField(FieldChatOptions, []byte{0, 0}),
)
- b, err := t.MarshalBinary()
- if err != nil {
- return err
- }
- _, err = rwc.Write(b)
+ _, err := io.Copy(rwc, t)
if err != nil {
return err
}
// If authentication fails, send error reply and close connection
if !c.Authenticate(login, encodedPassword) {
t := c.NewErrReply(&clientLogin, "Incorrect login.")
- b, err := t.MarshalBinary()
+
+ _, err := io.Copy(rwc, &t)
if err != nil {
return err
}
- if _, err := rwc.Write(b); err != nil {
- return err
- }
c.logger.Info("Login failed", "clientVersion", fmt.Sprintf("%x", c.Version))
if len(c.UserName) != 0 {
// Add the client username to the logger. For 1.5+ clients, we don't have this information yet as it comes as
// part of TranAgreed
- c.logger = c.logger.With("name", string(c.UserName))
+ c.logger = c.logger.With("Name", string(c.UserName))
c.logger.Info("Login successful", "clientVersion", "Not sent (probably 1.2.3)")
rLogger := s.Logger.With(
"remoteAddr", ctx.Value(contextKeyReq).(requestCtx).remoteAddr,
"login", fileTransfer.ClientConn.Account.Login,
- "name", string(fileTransfer.ClientConn.UserName),
+ "Name", string(fileTransfer.ClientConn.UserName),
)
fullPath, err := readPath(s.Config.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)