aboutsummaryrefslogtreecommitdiff
path: root/hotline/client_conn.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-06 19:41:07 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-06 19:41:07 -0700
commitd4c152a4dba0eec7c8ecd13732900909f51b1c97 (patch)
treecf1653bad283565ad3fe3f63c763e700f04ee363 /hotline/client_conn.go
parentc26c20e3539233a6cde9e64aa9d9a89b2017a772 (diff)
Refactor and cleanup to improve testability
Diffstat (limited to 'hotline/client_conn.go')
-rw-r--r--hotline/client_conn.go43
1 files changed, 31 insertions, 12 deletions
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index 65e18ee..c1ae4e3 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -3,8 +3,8 @@ package hotline
import (
"encoding/binary"
"golang.org/x/crypto/bcrypt"
+ "io"
"math/big"
- "net"
)
type byClientID []*ClientConn
@@ -21,9 +21,37 @@ func (s byClientID) Less(i, j int) bool {
return s[i].uint16ID() < s[j].uint16ID()
}
+const template = `Nickname: %s
+Name: %s
+Account: %s
+Address: %s
+
+-------- File Downloads ---------
+
+%s
+
+------- Folder Downloads --------
+
+None.
+
+--------- File Uploads ----------
+
+None.
+
+-------- Folder Uploads ---------
+
+None.
+
+------- Waiting Downloads -------
+
+None.
+
+ `
+
// ClientConn represents a client connected to a Server
type ClientConn struct {
- Connection net.Conn
+ Connection io.ReadWriteCloser
+ RemoteAddr string
ID *[]byte
Icon *[]byte
Flags *[]byte
@@ -67,15 +95,6 @@ func (cc *ClientConn) handleTransaction(transaction *Transaction) error {
return nil
}
}
- if !authorize(cc.Account.Access, handler.Access) {
- cc.Server.Logger.Infow(
- "Unauthorized Action",
- "Account", cc.Account.Login, "UserName", string(cc.UserName), "RequestType", handler.Name,
- )
- cc.Server.outbox <- cc.NewErrReply(transaction, handler.DenyMsg)
-
- return nil
- }
cc.Server.Logger.Infow(
"Received Transaction",
@@ -160,7 +179,7 @@ func (cc *ClientConn) Disconnect() {
cc.notifyOthers(*NewTransaction(tranNotifyDeleteUser, nil, NewField(fieldUserID, *cc.ID)))
if err := cc.Connection.Close(); err != nil {
- cc.Server.Logger.Errorw("error closing client connection", "RemoteAddr", cc.Connection.RemoteAddr())
+ cc.Server.Logger.Errorw("error closing client connection", "RemoteAddr", cc.RemoteAddr)
}
}