summaryrefslogtreecommitdiff
path: root/pkg/ui/views
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-16 11:46:04 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-16 11:46:04 +0200
commitba4afeb4ee19c24b393ec21d374bdd752651c1a6 (patch)
tree2082deaddd348439605a7209fbffd4a355ff7b37 /pkg/ui/views
parent76f46e54175253d4b2ba61b9cb8f2525a48c15d8 (diff)
Remove topics on network
Diffstat (limited to 'pkg/ui/views')
-rw-r--r--pkg/ui/views/game.go18
-rw-r--r--pkg/ui/views/play.go16
2 files changed, 15 insertions, 19 deletions
diff --git a/pkg/ui/views/game.go b/pkg/ui/views/game.go
index 52d8459..5a0972c 100644
--- a/pkg/ui/views/game.go
+++ b/pkg/ui/views/game.go
@@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
- "strconv"
- "strings"
"github.com/boozec/rahanna/internal/api/database"
"github.com/boozec/rahanna/pkg/ui/multiplayer"
@@ -197,21 +195,13 @@ func (m *GameModel) getGame() tea.Cmd {
// Establish peer connection
if m.peer == "peer-1" {
if game.IP2 != "" {
- ipParts := strings.Split(game.IP2, ":")
- if len(ipParts) == 2 {
- remoteIP := ipParts[0]
- remotePortInt, _ := strconv.Atoi(ipParts[1])
- go m.network.Server.AddPeer("peer-2", remoteIP, remotePortInt)
- }
+ remote := game.IP2
+ go m.network.Server.AddPeer("peer-2", remote)
}
} else {
if game.IP1 != "" {
- ipParts := strings.Split(game.IP1, ":")
- if len(ipParts) == 2 {
- remoteIP := ipParts[0]
- remotePortInt, _ := strconv.Atoi(ipParts[1])
- go m.network.Server.AddPeer("peer-1", remoteIP, remotePortInt)
- }
+ remote := game.IP1
+ go m.network.Server.AddPeer("peer-1", remote)
}
}
diff --git a/pkg/ui/views/play.go b/pkg/ui/views/play.go
index 4801556..cf1f6ca 100644
--- a/pkg/ui/views/play.go
+++ b/pkg/ui/views/play.go
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/boozec/rahanna/internal/api/database"
+ "github.com/boozec/rahanna/internal/logger"
"github.com/boozec/rahanna/internal/network"
"github.com/boozec/rahanna/pkg/ui/multiplayer"
"github.com/charmbracelet/bubbles/key"
@@ -267,10 +268,11 @@ func (m *PlayModel) handlePlayResponse(msg playResponse) (tea.Model, tea.Cmd) {
} else {
m.playName = msg.Ok.Name
m.currentGameId = msg.Ok.GameID
-
- m.network = multiplayer.NewGameNetwork("peer-1", msg.Ok.IP, msg.Ok.Port, func() {
- close(start)
- })
+ logger, _ := logger.GetLogger()
+ m.network = multiplayer.NewGameNetwork("peer-1", fmt.Sprintf("%s:%d", msg.Ok.IP, msg.Ok.Port), func() error {
+ start <- 1
+ return nil
+ }, logger)
}
return m, nil
@@ -284,7 +286,11 @@ func (m *PlayModel) handleGameResponse(msg database.Game) (tea.Model, tea.Cmd) {
if len(ip) == 2 {
localIP := ip[0]
localPort, _ := strconv.ParseInt(ip[1], 10, 32)
- network := multiplayer.NewGameNetwork("peer-2", localIP, int(localPort), func() {})
+
+ logger, _ := logger.GetLogger()
+ network := multiplayer.NewGameNetwork("peer-2", fmt.Sprintf("%s:%d", localIP, localPort), func() error {
+ return nil
+ }, logger)
return m, SwitchModelCmd(NewGameModel(m.width, m.height+1, "peer-2", m.game.ID, network))
}