Change default port to 1984

This commit is contained in:
Trevor Slocum 2019-10-14 16:00:25 -07:00
parent df42979b16
commit 31d7971372
6 changed files with 21 additions and 20 deletions

View File

@ -39,7 +39,7 @@ var (
logMessages []string
renderLogMessages bool
logMutex = new(sync.Mutex)
showLogLines = 7
showLogLines = 7 // TODO Set in resize func?
)
const (
@ -163,7 +163,7 @@ func main() {
}()
}
localListenAddress := "localhost:19840"
localListenAddress := fmt.Sprintf("localhost:%d", game.DefaultPort)
go server.Listen(localListenAddress)

View File

@ -20,6 +20,8 @@ const (
LogVerbose
)
const DefaultPort = 1984
type Game struct {
Rank int
Minos []mino.Mino

View File

@ -298,11 +298,7 @@ func (s *Server) handleGameCommands(pl *Player, g *Game) {
func (s *Server) Listen(address string) {
var network string
if strings.ContainsRune(address, ':') {
network = "tcp"
} else {
network = "unix"
}
network, address = NetworkAndAddress(address)
listener, err := net.Listen(network, address)
if err != nil {
@ -342,3 +338,18 @@ func (s *Server) Logf(format string, a ...interface{}) {
s.Logger <- fmt.Sprintf(format, a...)
}
func NetworkAndAddress(address string) (string, string) {
var network string
if strings.ContainsAny(address, `\/`) {
network = "unix"
} else {
network = "tcp"
if !strings.Contains(address, `:`) {
address = fmt.Sprintf("%s:%d", address, DefaultPort)
}
}
return network, address
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"log"
"net"
"strings"
"sync"
"time"
@ -63,11 +62,7 @@ func Connect(address string) *ServerConn {
err error
tries int
)
if strings.ContainsRune(address, ':') {
network = "tcp"
} else {
network = "unix"
}
network, address = NetworkAndAddress(address)
for {
conn, err = net.DialTimeout(network, address, ConnTimeout)

View File

@ -253,7 +253,6 @@ func (m Mino) Flatten() Mino {
rotateFunc = Point.Rotate180
}
if right > flattest {
flattest = right
rotateFunc = Point.Rotate90
}
if rotateFunc != nil {

View File

@ -166,12 +166,6 @@ func (p *Piece) Rotate(rotations int, direction int) Mino {
newMino := make(Mino, len(p.Mino))
copy(newMino, p.Mino.Origin())
w, h := newMino.Size()
maxSize := w
if h > maxSize {
maxSize = h
}
var rotationPivot int
for j := 0; j < rotations; j++ {
if direction == 0 {