Add settings for muting sounds
This commit is contained in:
parent
dd38c10f32
commit
3069f96568
10 changed files with 91 additions and 62 deletions
21
event.go
21
event.go
|
@ -115,14 +115,19 @@ type EventWin struct {
|
|||
|
||||
type EventSettings struct {
|
||||
Event
|
||||
AutoPlay bool
|
||||
Highlight bool
|
||||
Pips bool
|
||||
Moves bool
|
||||
Flip bool
|
||||
Traditional bool
|
||||
Advanced bool
|
||||
Speed int8
|
||||
AutoPlay bool
|
||||
Highlight bool
|
||||
Pips bool
|
||||
Moves bool
|
||||
Flip bool
|
||||
Traditional bool
|
||||
Advanced bool
|
||||
MuteJoinLeave bool
|
||||
MuteChat bool
|
||||
MuteRoll bool
|
||||
MuteMove bool
|
||||
MuteBearOff bool
|
||||
Speed int8
|
||||
}
|
||||
|
||||
type EventReplay struct {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -28,7 +28,7 @@ require (
|
|||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -60,8 +60,8 @@ github.com/matcornic/hermes/v2 v2.1.0 h1:9TDYFBPFv6mcXanaDmRDEp/RTWj0dTTi+LpFnnn
|
|||
github.com/matcornic/hermes/v2 v2.1.0/go.mod h1:2+ziJeoyRfaLiATIL8VZ7f9hpzH4oDHqTmn0bhrsgVI=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||
|
|
|
@ -6,14 +6,19 @@ type account struct {
|
|||
username []byte
|
||||
password []byte
|
||||
|
||||
autoplay bool
|
||||
highlight bool
|
||||
pips bool
|
||||
moves bool
|
||||
flip bool
|
||||
traditional bool
|
||||
advanced bool
|
||||
speed int8
|
||||
autoplay bool
|
||||
highlight bool
|
||||
pips bool
|
||||
moves bool
|
||||
flip bool
|
||||
traditional bool
|
||||
advanced bool
|
||||
muteJoinLeave bool
|
||||
muteChat bool
|
||||
muteRoll bool
|
||||
muteMove bool
|
||||
muteBearOff bool
|
||||
speed int8
|
||||
|
||||
casual *clientRating
|
||||
competitive *clientRating
|
||||
|
|
|
@ -54,6 +54,11 @@ CREATE TABLE account (
|
|||
flip smallint NOT NULL DEFAULT 0,
|
||||
traditional smallint NOT NULL DEFAULT 0,
|
||||
advanced smallint NOT NULL DEFAULT 0,
|
||||
mutejoinleave smallint NOT NULL DEFAULT 0,
|
||||
mutechat smallint NOT NULL DEFAULT 0,
|
||||
muteroll smallint NOT NULL DEFAULT 0,
|
||||
mutemove smallint NOT NULL DEFAULT 0,
|
||||
mutebearoff smallint NOT NULL DEFAULT 0,
|
||||
speed smallint NOT NULL DEFAULT 1
|
||||
);
|
||||
CREATE TABLE game (
|
||||
|
@ -344,8 +349,8 @@ func accountByID(id int) (*account, error) {
|
|||
casual: &clientRating{},
|
||||
competitive: &clientRating{},
|
||||
}
|
||||
var autoplay, highlight, pips, moves, flip, traditional, advanced int
|
||||
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, traditional, advanced, speed, casual_backgammon_single, casual_backgammon_multi, casual_acey_single, casual_acey_multi, casual_tabula_single, casual_tabula_multi, rated_backgammon_single, rated_backgammon_multi, rated_acey_single, rated_acey_multi, rated_tabula_single, rated_tabula_multi FROM account WHERE id = $1", id).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &traditional, &advanced, &a.speed, &a.casual.backgammonSingle, &a.casual.backgammonMulti, &a.casual.aceySingle, &a.casual.aceyMulti, &a.casual.tabulaSingle, &a.casual.tabulaMulti, &a.competitive.backgammonSingle, &a.competitive.backgammonMulti, &a.competitive.aceySingle, &a.competitive.aceyMulti, &a.competitive.tabulaSingle, &a.competitive.tabulaMulti)
|
||||
var autoplay, highlight, pips, moves, flip, traditional, advanced, muteJoinLeave, muteChat, muteRoll, muteMove, muteBearOff int
|
||||
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, traditional, advanced, mutejoinleave, mutechat, muteroll, mutemove, mutebearoff, speed, casual_backgammon_single, casual_backgammon_multi, casual_acey_single, casual_acey_multi, casual_tabula_single, casual_tabula_multi, rated_backgammon_single, rated_backgammon_multi, rated_acey_single, rated_acey_multi, rated_tabula_single, rated_tabula_multi FROM account WHERE id = $1", id).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &traditional, &advanced, &a.muteJoinLeave, &a.muteChat, &a.muteRoll, &a.muteMove, &a.muteBearOff, &a.speed, &a.casual.backgammonSingle, &a.casual.backgammonMulti, &a.casual.aceySingle, &a.casual.aceyMulti, &a.casual.tabulaSingle, &a.casual.tabulaMulti, &a.competitive.backgammonSingle, &a.competitive.backgammonMulti, &a.competitive.aceySingle, &a.competitive.aceyMulti, &a.competitive.tabulaSingle, &a.competitive.tabulaMulti)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -356,6 +361,11 @@ func accountByID(id int) (*account, error) {
|
|||
a.flip = flip == 1
|
||||
a.traditional = traditional == 1
|
||||
a.advanced = advanced == 1
|
||||
a.muteJoinLeave = muteJoinLeave == 1
|
||||
a.muteChat = muteChat == 1
|
||||
a.muteRoll = muteRoll == 1
|
||||
a.muteMove = muteMove == 1
|
||||
a.muteBearOff = muteBearOff == 1
|
||||
return a, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -216,31 +216,6 @@ func (s *server) handleLocal(conns chan net.Conn) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *server) Listen(network string, address string) {
|
||||
if strings.ToLower(network) == "ws" {
|
||||
go s.listenWebSocket(address)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Listening for %s connections on %s...", strings.ToUpper(network), address)
|
||||
listener, err := net.Listen(network, address)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen on %s: %s", address, err)
|
||||
}
|
||||
go s.handleListener(listener)
|
||||
s.listeners = append(s.listeners, listener)
|
||||
}
|
||||
|
||||
func (s *server) handleListener(listener net.Listener) {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to accept connection: %s", err)
|
||||
}
|
||||
go s.handleConnection(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) nameAllowed(username []byte) bool {
|
||||
return !guestName.Match(username)
|
||||
}
|
||||
|
|
|
@ -204,14 +204,19 @@ COMMANDS:
|
|||
if cmd.client.account != nil {
|
||||
a := cmd.client.account
|
||||
cmd.client.sendEvent(&bgammon.EventSettings{
|
||||
AutoPlay: a.autoplay,
|
||||
Highlight: a.highlight,
|
||||
Pips: a.pips,
|
||||
Moves: a.moves,
|
||||
Flip: a.flip,
|
||||
Traditional: a.traditional,
|
||||
Advanced: a.advanced,
|
||||
Speed: a.speed,
|
||||
AutoPlay: a.autoplay,
|
||||
Highlight: a.highlight,
|
||||
Pips: a.pips,
|
||||
Moves: a.moves,
|
||||
Flip: a.flip,
|
||||
Traditional: a.traditional,
|
||||
Advanced: a.advanced,
|
||||
MuteJoinLeave: a.muteJoinLeave,
|
||||
MuteChat: a.muteChat,
|
||||
MuteRoll: a.muteRoll,
|
||||
MuteMove: a.muteMove,
|
||||
MuteBearOff: a.muteBearOff,
|
||||
Speed: a.speed,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1147,7 @@ COMMANDS:
|
|||
}
|
||||
|
||||
name := string(bytes.ToLower(params[0]))
|
||||
settings := []string{"autoplay", "highlight", "pips", "moves", "flip", "traditional", "advanced", "speed"}
|
||||
settings := []string{"autoplay", "highlight", "pips", "moves", "flip", "traditional", "advanced", "mutejoinleave", "mutechat", "muteroll", "mutemove", "mutebearoff", "speed"}
|
||||
var found bool
|
||||
for i := range settings {
|
||||
if name == settings[i] {
|
||||
|
|
9
pkg/server/server_disabled.go
Normal file
9
pkg/server/server_disabled.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
//go:build !full
|
||||
|
||||
package server
|
||||
|
||||
import "log"
|
||||
|
||||
func (s *server) Listen(network string, address string) {
|
||||
log.Fatal("bgammon-server was built without the 'full' tag. Only local connections are possible.")
|
||||
}
|
|
@ -6,14 +6,41 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.rocket9labs.com/tslocum/bgammon"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (s *server) Listen(network string, address string) {
|
||||
if strings.ToLower(network) == "ws" {
|
||||
go s.listenWebSocket(address)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Listening for %s connections on %s...", strings.ToUpper(network), address)
|
||||
listener, err := net.Listen(network, address)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen on %s: %s", address, err)
|
||||
}
|
||||
go s.handleListener(listener)
|
||||
s.listeners = append(s.listeners, listener)
|
||||
}
|
||||
|
||||
func (s *server) handleListener(listener net.Listener) {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to accept connection: %s", err)
|
||||
}
|
||||
go s.handleConnection(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) listenWebSocket(address string) {
|
||||
log.Printf("Listening for WebSocket connections on %s...", address)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
//go:build !full
|
||||
|
||||
package server
|
||||
|
||||
func (s *server) listenWebSocket(address string) {
|
||||
// Do nothing.
|
||||
}
|
Loading…
Reference in a new issue