aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-23 15:35:45 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-23 15:35:45 -0700
commit0da28a1fe47ffc60e40aeca9dddd7ab37e52a999 (patch)
tree2e7f29ce2a78632ba263d9ea351d9750a31be622
parentc6a3fa2cdbf7eb78964a5df7622482cdd8782d74 (diff)
Improve logging readability
-rw-r--r--hotline/client.go5
-rw-r--r--hotline/client_conn.go2
-rw-r--r--hotline/server.go15
-rw-r--r--hotline/transaction_handlers.go1
4 files changed, 12 insertions, 11 deletions
diff --git a/hotline/client.go b/hotline/client.go
index 3a6584a..e5b396b 100644
--- a/hotline/client.go
+++ b/hotline/client.go
@@ -674,10 +674,7 @@ func (c *Client) HandleTransaction(t *Transaction) error {
}
requestNum := binary.BigEndian.Uint16(t.Type)
- c.Logger.Infow(
- "Received Transaction",
- "RequestType", requestNum,
- )
+ c.Logger.Debugw("Received Transaction", "RequestType", requestNum)
if handler, ok := c.Handlers[requestNum]; ok {
outT, _ := handler.Handle(c, t)
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index 6a27977..1186947 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -78,7 +78,7 @@ func (cc *ClientConn) handleTransaction(transaction *Transaction) error {
}
}
- cc.logger.Infow("Received Transaction", "RequestType", handler.Name)
+ cc.logger.Debugw("Received Transaction", "RequestType", handler.Name)
transactions, err := handler.Handler(cc, transaction)
if err != nil {
diff --git a/hotline/server.go b/hotline/server.go
index e685afd..0677a81 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -193,8 +193,9 @@ func (s *Server) Serve(ctx context.Context, ln net.Listener) error {
})
go func() {
+ s.Logger.Infow("Connection established", "RemoteAddr", conn.RemoteAddr())
+
if err := s.handleNewConnection(connCtx, conn, conn.RemoteAddr().String()); err != nil {
- s.Logger.Infow("New client connection established", "RemoteAddr", conn.RemoteAddr())
if err == io.EOF {
s.Logger.Infow("Client disconnected", "RemoteAddr", conn.RemoteAddr())
} else {
@@ -568,6 +569,8 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose
login = GuestAccount
}
+ c.logger = s.Logger.With("remoteAddr", remoteAddr, "login", login)
+
// If authentication fails, send error reply and close connection
if !c.Authenticate(login, encodedPassword) {
t := c.NewErrReply(clientLogin, "Incorrect login.")
@@ -578,7 +581,10 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose
if _, err := conn.Write(b); err != nil {
return err
}
- return fmt.Errorf("incorrect login")
+
+ c.logger.Infow("Login failed", "clientVersion", fmt.Sprintf("%x", *c.Version))
+
+ return nil
}
if clientLogin.GetField(fieldUserName).Data != nil {
@@ -595,10 +601,6 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose
*c.Flags = []byte{0, 2}
}
- c.logger = s.Logger.With("remoteAddr", remoteAddr, "login", login)
-
- c.logger.Infow("Client connection received", "version", fmt.Sprintf("%x", *c.Version))
-
s.outbox <- c.NewReply(clientLogin,
NewField(fieldVersion, []byte{0x00, 0xbe}),
NewField(fieldCommunityBannerID, []byte{0, 0}),
@@ -615,6 +617,7 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose
if *c.Version == nil || bytes.Equal(*c.Version, nostalgiaVersion) {
c.Agreed = true
c.logger = c.logger.With("name", string(c.UserName))
+ c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", *c.Version))
for _, t := range c.notifyOthers(
*NewTransaction(
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go
index 735e155..7f29d73 100644
--- a/hotline/transaction_handlers.go
+++ b/hotline/transaction_handlers.go
@@ -907,6 +907,7 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er
*cc.Icon = t.GetField(fieldUserIconID).Data
cc.logger = cc.logger.With("name", string(cc.UserName))
+ cc.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", *cc.Version))
options := t.GetField(fieldOptions).Data
optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))