Compare commits
No commits in common. "76f395429978bc46340dd081746b7065df0577ca" and "dd9490bb3b8e80b0b4b272ac67ecce896b8cdb9b" have entirely different histories.
76f3954299
...
dd9490bb3b
7 changed files with 8 additions and 18 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
"github.com/gorilla/handlers"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
@ -44,15 +43,14 @@ func Start() {
|
||||||
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
||||||
|
|
||||||
// start connection handler and broadcast
|
// start connection handler and broadcast
|
||||||
r := http.NewServeMux()
|
http.HandleFunc("/ws", websocket.HandleConnection)
|
||||||
r.HandleFunc("/ws", websocket.HandleConnection)
|
|
||||||
go websocket.SendPermanentBroadCastMessage()
|
go websocket.SendPermanentBroadCastMessage()
|
||||||
|
|
||||||
log.Info("GoTomato started", "version", metadata.GoTomatoVersion)
|
log.Info("GoTomato started", "version", metadata.GoTomatoVersion)
|
||||||
log.Info("Websocket listening", "address", listen)
|
log.Info("Websocket listening", "address", listen)
|
||||||
|
|
||||||
// start the listener
|
// start the listener
|
||||||
err := http.ListenAndServe(listen, handlers.ProxyHeaders(r))
|
err := http.ListenAndServe(listen, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error starting server:", "msg", err)
|
log.Fatal("Error starting server:", "msg", err)
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,14 +4,12 @@ go 1.23
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/charmbracelet/log v0.4.0
|
github.com/charmbracelet/log v0.4.0
|
||||||
github.com/gorilla/handlers v1.5.2
|
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/lipgloss v0.10.0 // indirect
|
github.com/charmbracelet/lipgloss v0.10.0 // indirect
|
||||||
github.com/felixge/httpsnoop v1.0.3 // indirect
|
|
||||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
github.com/mattn/go-isatty v0.0.18 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -6,12 +6,8 @@ github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8
|
||||||
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
|
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
|
|
||||||
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
|
||||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||||
github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE=
|
|
||||||
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
|
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
|
|
|
@ -2,5 +2,5 @@ package metadata
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
const GoTomatoVersion = "v0.0.7" // The GoTomato version
|
const GoTomatoVersion = "v0.0.6" // The GoTomato version
|
||||||
var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version
|
var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version
|
||||||
|
|
|
@ -21,8 +21,8 @@ func handleClientCommands(c models.WebsocketClient) {
|
||||||
|
|
||||||
_, message, err := ws.ReadMessage()
|
_, message, err := ws.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Info("Client disconnected:", "msg", err, "host", ws.RemoteAddr(), "clients", len(Clients)-1)
|
||||||
delete(Clients, ws.LocalAddr())
|
delete(Clients, ws.LocalAddr())
|
||||||
log.Info("Client disconnected:", "msg", err, "host", c.RealIP, "clients", len(Clients))
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,16 @@ func HandleConnection(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
|
||||||
|
log.Info("Client connected", "host", ws.RemoteAddr(), "clients", len(Clients)+1)
|
||||||
|
|
||||||
// Register the new client
|
// Register the new client
|
||||||
client := models.WebsocketClient{
|
client := models.WebsocketClient{
|
||||||
Conn: ws,
|
Conn: ws,
|
||||||
RealIP: r.RemoteAddr,
|
|
||||||
}
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
Clients[ws.LocalAddr()] = &client
|
Clients[ws.LocalAddr()] = &client
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
log.Info("Client connected", "host", client.RealIP, "clients", len(Clients))
|
|
||||||
|
|
||||||
// Listen for commands from the connected client
|
// Listen for commands from the connected client
|
||||||
handleClientCommands(client)
|
handleClientCommands(client)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,7 @@ type ClientCommand struct {
|
||||||
|
|
||||||
// Represents a single client
|
// Represents a single client
|
||||||
type WebsocketClient struct {
|
type WebsocketClient struct {
|
||||||
Conn *websocket.Conn
|
Conn *websocket.Conn
|
||||||
RealIP string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends a message to the websocket.
|
// Sends a message to the websocket.
|
||||||
|
|
Loading…
Reference in a new issue