aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-24 19:03:49 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-24 19:03:49 -0700
commita7216f677e7b02831328293224730f6f06f2d38a (patch)
tree0694960361d7723b7ab77e76fb1f4a1f6db9de9e
parent590974641fde819128297803a12cfd4c744283a8 (diff)
Remove unnecessary use of pointers
-rw-r--r--hotline/client_conn.go14
-rw-r--r--hotline/server.go34
-rw-r--r--hotline/transaction_handlers.go50
-rw-r--r--hotline/transaction_handlers_test.go18
4 files changed, 58 insertions, 58 deletions
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index 41810a8..076919f 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -31,13 +31,13 @@ type ClientConn struct {
Connection io.ReadWriteCloser
RemoteAddr string
ID *[]byte
- Icon *[]byte
- Flags *[]byte
+ Icon []byte
+ Flags []byte
UserName []byte
Account *Account
IdleTime int
Server *Server
- Version *[]byte
+ Version []byte
Idle bool
AutoReply []byte
@@ -102,17 +102,17 @@ func (cc *ClientConn) handleTransaction(transaction Transaction) error {
// if user was previously idle, mark as not idle and notify other connected clients that
// the user is no longer away
if cc.Idle {
- flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
+ flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(cc.Flags)))
flagBitmap.SetBit(flagBitmap, userFlagAway, 0)
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(cc.Flags, uint16(flagBitmap.Int64()))
cc.Idle = false
cc.sendAll(
tranNotifyChangeUser,
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserFlags, cc.Flags),
NewField(fieldUserName, cc.UserName),
- NewField(fieldUserIconID, *cc.Icon),
+ NewField(fieldUserIconID, cc.Icon),
)
}
}
diff --git a/hotline/server.go b/hotline/server.go
index fd8bda6..41b9a97 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -308,16 +308,16 @@ func (s *Server) keepaliveHandler() {
if c.IdleTime > userIdleSeconds && !c.Idle {
c.Idle = true
- flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
+ flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(c.Flags)))
flagBitmap.SetBit(flagBitmap, userFlagAway, 1)
- binary.BigEndian.PutUint16(*c.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(c.Flags, uint16(flagBitmap.Int64()))
c.sendAll(
tranNotifyChangeUser,
NewField(fieldUserID, *c.ID),
- NewField(fieldUserFlags, *c.Flags),
+ NewField(fieldUserFlags, c.Flags),
NewField(fieldUserName, c.UserName),
- NewField(fieldUserIconID, *c.Icon),
+ NewField(fieldUserIconID, c.Icon),
)
}
}
@@ -363,12 +363,12 @@ func (s *Server) NewClientConn(conn io.ReadWriteCloser, remoteAddr string) *Clie
clientConn := &ClientConn{
ID: &[]byte{0, 0},
- Icon: &[]byte{0, 0},
- Flags: &[]byte{0, 0},
+ Icon: []byte{0, 0},
+ Flags: []byte{0, 0},
UserName: []byte{},
Connection: conn,
Server: s,
- Version: &[]byte{},
+ Version: []byte{},
AutoReply: []byte{},
transfers: map[int]map[[4]byte]*FileTransfer{},
Agreed: false,
@@ -463,8 +463,8 @@ func (s *Server) connectedUsers() []Field {
}
user := User{
ID: *c.ID,
- Icon: *c.Icon,
- Flags: *c.Flags,
+ Icon: c.Icon,
+ Flags: c.Flags,
Name: string(c.UserName),
}
connectedUsers = append(connectedUsers, NewField(fieldUsernameWithInfo, user.Payload()))
@@ -598,7 +598,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
encodedLogin := clientLogin.GetField(fieldUserLogin).Data
encodedPassword := clientLogin.GetField(fieldUserPassword).Data
- *c.Version = clientLogin.GetField(fieldVersion).Data
+ c.Version = clientLogin.GetField(fieldVersion).Data
var login string
for _, char := range encodedLogin {
@@ -621,13 +621,13 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
return err
}
- c.logger.Infow("Login failed", "clientVersion", fmt.Sprintf("%x", *c.Version))
+ c.logger.Infow("Login failed", "clientVersion", fmt.Sprintf("%x", c.Version))
return nil
}
if clientLogin.GetField(fieldUserIconID).Data != nil {
- *c.Icon = clientLogin.GetField(fieldUserIconID).Data
+ c.Icon = clientLogin.GetField(fieldUserIconID).Data
}
c.Account = c.Server.Accounts[login]
@@ -641,7 +641,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
}
if c.Authorize(accessDisconUser) {
- *c.Flags = []byte{0, 2}
+ c.Flags = []byte{0, 2}
}
s.outbox <- c.NewReply(clientLogin,
@@ -657,18 +657,18 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
c.Server.outbox <- *NewTransaction(tranShowAgreement, c.ID, NewField(fieldData, s.Agreement))
// Used simplified hotline v1.2.3 login flow for clients that do not send login info in tranAgreed
- if *c.Version == nil || bytes.Equal(*c.Version, nostalgiaVersion) {
+ 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))
+ c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", c.Version))
for _, t := range c.notifyOthers(
*NewTransaction(
tranNotifyChangeUser, nil,
NewField(fieldUserName, c.UserName),
NewField(fieldUserID, *c.ID),
- NewField(fieldUserIconID, *c.Icon),
- NewField(fieldUserFlags, *c.Flags),
+ NewField(fieldUserIconID, c.Icon),
+ NewField(fieldUserFlags, c.Flags),
),
) {
c.Server.outbox <- t
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go
index 6389ed2..aa994b9 100644
--- a/hotline/transaction_handlers.go
+++ b/hotline/transaction_handlers.go
@@ -645,22 +645,22 @@ func HandleSetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error
newT := NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, newAccessLvl))
res = append(res, *newT)
- flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
+ flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(c.Flags)))
if authorize(c.Account.Access, accessDisconUser) {
flagBitmap.SetBit(flagBitmap, userFlagAdmin, 1)
} else {
flagBitmap.SetBit(flagBitmap, userFlagAdmin, 0)
}
- binary.BigEndian.PutUint16(*c.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(c.Flags, uint16(flagBitmap.Int64()))
c.Account.Access = account.Access
cc.sendAll(
tranNotifyChangeUser,
NewField(fieldUserID, *c.ID),
- NewField(fieldUserFlags, *c.Flags),
+ NewField(fieldUserFlags, c.Flags),
NewField(fieldUserName, c.UserName),
- NewField(fieldUserIconID, *c.Icon),
+ NewField(fieldUserIconID, c.Icon),
)
}
}
@@ -917,26 +917,26 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er
}
}
- *cc.Icon = t.GetField(fieldUserIconID).Data
+ 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))
+ cc.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", cc.Version))
options := t.GetField(fieldOptions).Data
optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
- flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
+ flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(cc.Flags)))
// Check refuse private PM option
if optBitmap.Bit(refusePM) == 1 {
flagBitmap.SetBit(flagBitmap, userFlagRefusePM, 1)
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(cc.Flags, uint16(flagBitmap.Int64()))
}
// Check refuse private chat option
if optBitmap.Bit(refuseChat) == 1 {
flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, 1)
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(cc.Flags, uint16(flagBitmap.Int64()))
}
// Check auto response
@@ -951,8 +951,8 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er
tranNotifyChangeUser, nil,
NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserIconID, cc.Icon),
+ NewField(fieldUserFlags, cc.Flags),
),
)
res = append(res, trans...)
@@ -1599,7 +1599,7 @@ func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction,
} else {
icon = t.GetField(fieldUserIconID).Data
}
- *cc.Icon = icon
+ cc.Icon = icon
cc.UserName = t.GetField(fieldUserName).Data
// the options field is only passed by the client versions > 1.2.3.
@@ -1607,13 +1607,13 @@ func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction,
if options != nil {
optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
- flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
+ flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(cc.Flags)))
flagBitmap.SetBit(flagBitmap, userFlagRefusePM, optBitmap.Bit(refusePM))
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(cc.Flags, uint16(flagBitmap.Int64()))
flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, optBitmap.Bit(refuseChat))
- binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
+ binary.BigEndian.PutUint16(cc.Flags, uint16(flagBitmap.Int64()))
// Check auto response
if optBitmap.Bit(autoResponse) == 1 {
@@ -1627,8 +1627,8 @@ func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction,
cc.sendAll(
tranNotifyChangeUser,
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserIconID, cc.Icon),
+ NewField(fieldUserFlags, cc.Flags),
NewField(fieldUserName, cc.UserName),
)
@@ -1715,8 +1715,8 @@ func HandleInviteNewChat(cc *ClientConn, t *Transaction) (res []Transaction, err
NewField(fieldChatID, newChatID),
NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserIconID, cc.Icon),
+ NewField(fieldUserFlags, cc.Flags),
),
)
@@ -1748,8 +1748,8 @@ func HandleInviteToChat(cc *ClientConn, t *Transaction) (res []Transaction, err
NewField(fieldChatID, chatID),
NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserIconID, cc.Icon),
+ NewField(fieldUserFlags, cc.Flags),
),
)
@@ -1798,8 +1798,8 @@ func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err erro
NewField(fieldChatID, chatID),
NewField(fieldUserName, cc.UserName),
NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
+ NewField(fieldUserIconID, cc.Icon),
+ NewField(fieldUserFlags, cc.Flags),
),
)
}
@@ -1810,8 +1810,8 @@ func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err erro
for _, c := range sortedClients(privChat.ClientConn) {
user := User{
ID: *c.ID,
- Icon: *c.Icon,
- Flags: *c.Flags,
+ Icon: c.Icon,
+ Flags: c.Flags,
Name: string(c.UserName),
}
diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go
index 5136c7d..f283112 100644
--- a/hotline/transaction_handlers_test.go
+++ b/hotline/transaction_handlers_test.go
@@ -228,22 +228,22 @@ func TestHandleGetUserNameList(t *testing.T) {
Clients: map[uint16]*ClientConn{
uint16(1): {
ID: &[]byte{0, 1},
- Icon: &[]byte{0, 2},
- Flags: &[]byte{0, 3},
+ Icon: []byte{0, 2},
+ Flags: []byte{0, 3},
UserName: []byte{0, 4},
Agreed: true,
},
uint16(2): {
ID: &[]byte{0, 2},
- Icon: &[]byte{0, 2},
- Flags: &[]byte{0, 3},
+ Icon: []byte{0, 2},
+ Flags: []byte{0, 3},
UserName: []byte{0, 4},
Agreed: true,
},
uint16(3): {
ID: &[]byte{0, 3},
- Icon: &[]byte{0, 2},
- Flags: &[]byte{0, 3},
+ Icon: []byte{0, 2},
+ Flags: []byte{0, 3},
UserName: []byte{0, 4},
Agreed: false,
},
@@ -2834,9 +2834,9 @@ func TestHandleTranAgreed(t *testing.T) {
access := bits[:]
return &access
}()},
- Icon: &[]byte{0, 1},
- Flags: &[]byte{0, 1},
- Version: &[]byte{0, 1},
+ Icon: []byte{0, 1},
+ Flags: []byte{0, 1},
+ Version: []byte{0, 1},
ID: &[]byte{0, 1},
logger: NewTestLogger(),
Server: &Server{