Skip to content

Commit

Permalink
extract netplay client name from user
Browse files Browse the repository at this point in the history
  • Loading branch information
n-at committed May 6, 2024
1 parent 52bf16c commit e6ba8f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions web/gamesession/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type Client struct {
lock sync.RWMutex
}

func NewClient(id string, ws *websocket.Conn) *Client {
func NewClient(id, name string, ws *websocket.Conn) *Client {
return &Client{
id: id,
name: storage.GenerateRandomName(),
name: name,
clientKey: storage.NewId(),
player: PlayerSpectator,
heartbeat: true,
Expand Down
8 changes: 7 additions & 1 deletion web/handlers_netplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *Server) netplayWS(c echo.Context) error {
isHost := false
hostId := game.UserId
clientId := storage.NewId()
clientName := storage.GenerateRandomName()
sessionId := game.NetplaySessionId

if pctx.session != nil && len(pctx.session.UserId) != 0 {
Expand All @@ -76,7 +77,12 @@ func (s *Server) netplayWS(c echo.Context) error {
}
}()

client := gamesession.NewClient(clientId, ws)
user, _ := s.findContextSessionUser(pctx)
if user != nil && len(user.Login) != 0 {
clientName = user.Login
}

client := gamesession.NewClient(clientId, clientName, ws)

s.gameSessionsMu.Lock() /////////////////////

Expand Down

0 comments on commit e6ba8f9

Please sign in to comment.