Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions server/game/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package game

import (
"crypto/hmac"
"crypto/sha1"
"hash"
"sync"
"time"

Expand Down Expand Up @@ -44,7 +41,7 @@ type Client struct {
received bool

authKey string
hmac hash.Hash
macKey string

logger log.Logger

Expand Down Expand Up @@ -85,7 +82,7 @@ func newClient(info *pb.ClientInfo, macKey string, room IRoom, isPlayer bool) (*
renewPeer: make(chan struct{}, 1),

authKey: RandomHex(room.ClientConf().AuthKeyLen),
hmac: hmac.New(sha1.New, []byte(macKey)),
macKey: macKey,

logger: room.Logger().With(log.KeyClient, info.Id),

Expand Down
7 changes: 6 additions & 1 deletion server/game/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package game

import (
"context"
"crypto/hmac"
"crypto/sha1"
"errors"
"hash"
"net"
"sync"
"time"
Expand Down Expand Up @@ -30,6 +33,7 @@ type Peer struct {
client *Client
conn *websocket.Conn
msgCh chan binary.Msg
hmac hash.Hash

done chan struct{}
detached chan struct{}
Expand All @@ -45,6 +49,7 @@ func NewPeer(ctx context.Context, cli *Client, conn *websocket.Conn, lastEvSeq i
client: cli,
conn: conn,
msgCh: make(chan binary.Msg),
hmac: hmac.New(sha1.New, []byte(cli.macKey)),

done: make(chan struct{}),
detached: make(chan struct{}),
Expand Down Expand Up @@ -223,7 +228,7 @@ loop:
}
metrics.MessageRecv.Add(1)

msg, err := binary.UnmarshalMsg(p.client.hmac, data)
msg, err := binary.UnmarshalMsg(p.hmac, data)
if err != nil {
p.client.logger.Errorf("peer UnmarshalMsg (%v, %p): %+v", p.client.Id, p, err)
p.closeWithMessage(websocket.CloseInvalidFramePayloadData, err.Error())
Expand Down
Loading