Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Socket Nickname #16

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
feat: added nickname to socket
Yatt0Ikigai committed Jul 24, 2024
commit 8e4ea6ea3582c5e40e07cd7ba3a019fb29fd1394
9 changes: 9 additions & 0 deletions src/PuuClocks.API/internal/server/sockets.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,15 @@ func (s socketServer) JoinLobby(c *gin.Context) {
}
defer conn.Close()
id := c.Param("id")
nickname := c.Query("nickname")
if nickname == "" {
if err = conn.WriteJSON(map[string]string{
"message": "User not passed nickname",
}); err != nil {
log.Log.Errorln(err)
}
return
}

parsedID, err = uuid.Parse(id)
if err != nil {
10 changes: 8 additions & 2 deletions src/PuuClocks.API/internal/sockets/client.go
Original file line number Diff line number Diff line change
@@ -10,12 +10,14 @@ import (
type Client interface {
SendMessage([]byte)
GetID() uuid.UUID
GetNickname() string
Close()
}

type client struct {
ID uuid.UUID
Socket *websocket.Conn
ID uuid.UUID
Nickname string
Socket *websocket.Conn

Receive chan []byte

@@ -85,3 +87,7 @@ func (c *client) Close() {
func (c *client) GetID() uuid.UUID {
return c.ID
}

func (c *client) GetNickname() string {
return c.Nickname
}