Documentation ¶
Index ¶
- Constants
- Variables
- func GameName(name string) string
- func NetworkAndAddress(address string) (string, string)
- func Nickname(nick string) string
- type Command
- type Conn
- type ConnectingPlayer
- type Game
- func (g *Game) AddPlayer(p *Player)
- func (g *Game) AddPlayerL(p *Player)
- func (g *Game) HandleReadCommands(in chan GameCommandInterface)
- func (g *Game) Log(level int, a ...interface{})
- func (g *Game) Logf(level int, format string, a ...interface{})
- func (g *Game) ProcessAction(a event.GameAction)
- func (g *Game) ProcessActionL(a event.GameAction)
- func (g *Game) RemovePlayer(playerID int)
- func (g *Game) RemovePlayerL(playerID int)
- func (g *Game) Reset()
- func (g *Game) ResetL()
- func (g *Game) SetGarbageReceiver(receiver int)
- func (g *Game) Start(seed int64) int64
- func (g *Game) StartL(seed int64) int64
- func (g *Game) StopL()
- func (g *Game) WriteAll(gc GameCommandInterface)
- func (g *Game) WriteAllAndLogL(gc GameCommandInterface)
- func (g *Game) WriteAllL(gc GameCommandInterface)
- func (g *Game) WriteMessage(message string)
- type GameCommand
- type GameCommandDisconnect
- type GameCommandGameOver
- type GameCommandInterface
- type GameCommandJoinGame
- type GameCommandListGames
- type GameCommandMessage
- type GameCommandNickname
- type GameCommandPing
- type GameCommandPong
- type GameCommandQuitGame
- type GameCommandReceiveGarbage
- type GameCommandSendGarbage
- type GameCommandStartGame
- type GameCommandStats
- type GameCommandTransport
- type GameCommandUpdateGame
- type GameCommandUpdateMatrix
- type IncomingPlayer
- type ListedGame
- type Player
- type Server
- type ServerInterface
Constants ¶
View Source
const ( UpdateDuration = 100 * time.Millisecond IdleStart = 5 * time.Second IdleTimeout = 1 * time.Minute )
View Source
const ( LogStandard = iota LogDebug LogVerbose )
View Source
const ( CommandQueueSize = 10 LogQueueSize = 10 PlayerHost = -1 PlayerUnknown = 0 )
View Source
const ( DefaultPort = 1984 DefaultServer = "netris.rocketnine.space" )
View Source
const ConnTimeout = 30 * time.Second
Variables ¶
View Source
var Version = "0.0.0"
Functions ¶
func NetworkAndAddress ¶
Types ¶
type Command ¶
type Command int
const ( CommandUnknown Command = iota CommandDisconnect CommandPing CommandPong CommandNickname CommandMessage CommandNewGame CommandJoinGame CommandQuitGame CommandUpdateGame CommandStartGame CommandGameOver CommandUpdateMatrix CommandSendGarbage CommandReceiveGarbage CommandStats CommandListGames )
The order of these constants must be preserved
type Conn ¶
type Conn struct { LastTransfer time.Time Terminated bool Player int In chan GameCommandInterface *sync.WaitGroup // contains filtered or unexported fields }
func NewServerConn ¶
func NewServerConn(conn net.Conn, forwardOut chan GameCommandInterface) *Conn
func (*Conn) JoinGame ¶
func (s *Conn) JoinGame(name string, gameID int, newGame *ListedGame, logger chan string, draw chan event.DrawObject) (*Game, error)
When newGame is set to a ListedGame and gameID is 0, a new custom game is created
func (*Conn) Write ¶
func (s *Conn) Write(gc GameCommandInterface)
type ConnectingPlayer ¶
type ConnectingPlayer struct {
Name string
}
type Game ¶
type Game struct { ID int Name string Starting bool Started bool TimeStarted time.Time Eternal bool Terminated bool Local bool LocalPlayer int Players map[int]*Player MaxPlayers int GarbageReceiver int Event chan interface{} LogLevel int Rank int Minos []mino.Mino Seed int64 FallTime time.Duration SpeedLimit int *sync.Mutex // contains filtered or unexported fields }
func NewGame ¶
func NewGame(rank int, out func(GameCommandInterface), logger chan string, draw chan event.DrawObject) (*Game, error)
func (*Game) AddPlayerL ¶
func (*Game) HandleReadCommands ¶
func (g *Game) HandleReadCommands(in chan GameCommandInterface)
func (*Game) ProcessAction ¶
func (g *Game) ProcessAction(a event.GameAction)
func (*Game) ProcessActionL ¶
func (g *Game) ProcessActionL(a event.GameAction)
func (*Game) RemovePlayer ¶
func (*Game) RemovePlayerL ¶
func (*Game) SetGarbageReceiver ¶
func (*Game) WriteAll ¶
func (g *Game) WriteAll(gc GameCommandInterface)
func (*Game) WriteAllAndLogL ¶
func (g *Game) WriteAllAndLogL(gc GameCommandInterface)
func (*Game) WriteAllL ¶
func (g *Game) WriteAllL(gc GameCommandInterface)
func (*Game) WriteMessage ¶
type GameCommand ¶
type GameCommand struct {
SourcePlayer int `json:"sp,omitempty"`
}
func (*GameCommand) SetSource ¶
func (gc *GameCommand) SetSource(source int)
func (*GameCommand) Source ¶
func (gc *GameCommand) Source() int
type GameCommandDisconnect ¶
type GameCommandDisconnect struct { GameCommand Player int `json:"p,omitempty"` Message string `json:"m,omitempty"` }
func (GameCommandDisconnect) Command ¶
func (gc GameCommandDisconnect) Command() Command
type GameCommandGameOver ¶
type GameCommandGameOver struct { GameCommand Player int `json:"p,omitempty"` Winner string `json:"w,omitempty"` }
func (GameCommandGameOver) Command ¶
func (gc GameCommandGameOver) Command() Command
type GameCommandInterface ¶
type GameCommandJoinGame ¶
type GameCommandJoinGame struct { GameCommand Version int `json:"v,omitempty"` Name string `json:"n,omitempty"` GameID int `json:"g,omitempty"` PlayerID int `json:"p,omitempty"` Listing ListedGame `json:"l,omitempty"` }
func (GameCommandJoinGame) Command ¶
func (gc GameCommandJoinGame) Command() Command
type GameCommandListGames ¶
type GameCommandListGames struct { GameCommand Games []*ListedGame `json:"g,omitempty"` }
func (GameCommandListGames) Command ¶
func (gc GameCommandListGames) Command() Command
type GameCommandMessage ¶
type GameCommandMessage struct { GameCommand Player int `json:"p,omitempty"` Message string `json:"m,omitempty"` }
func (GameCommandMessage) Command ¶
func (gc GameCommandMessage) Command() Command
type GameCommandNickname ¶
type GameCommandNickname struct { GameCommand Player int `json:"p,omitempty"` Nickname string `json:"n,omitempty"` }
func (GameCommandNickname) Command ¶
func (gc GameCommandNickname) Command() Command
type GameCommandPing ¶
type GameCommandPing struct { GameCommand Message string `json:"m,omitempty"` }
func (GameCommandPing) Command ¶
func (gc GameCommandPing) Command() Command
type GameCommandPong ¶
type GameCommandPong struct { GameCommand Message string `json:"m,omitempty"` }
func (GameCommandPong) Command ¶
func (gc GameCommandPong) Command() Command
type GameCommandQuitGame ¶
type GameCommandQuitGame struct { GameCommand Player int `json:"p,omitempty"` }
func (GameCommandQuitGame) Command ¶
func (gc GameCommandQuitGame) Command() Command
type GameCommandReceiveGarbage ¶
type GameCommandReceiveGarbage struct { GameCommand Lines int `json:"l,omitempty"` }
func (GameCommandReceiveGarbage) Command ¶
func (gc GameCommandReceiveGarbage) Command() Command
type GameCommandSendGarbage ¶
type GameCommandSendGarbage struct { GameCommand Receiver int `json:"r,omitempty"` Lines int `json:"l,omitempty"` }
func (GameCommandSendGarbage) Command ¶
func (gc GameCommandSendGarbage) Command() Command
type GameCommandStartGame ¶
type GameCommandStartGame struct { GameCommand Seed int64 `json:"s,omitempty"` Started bool `json:"st,omitempty"` }
func (GameCommandStartGame) Command ¶
func (gc GameCommandStartGame) Command() Command
type GameCommandStats ¶
type GameCommandStats struct { GameCommand Created time.Time `json:"c,omitempty"` Players int `json:"p,omitempty"` Games int `json:"g,omitempty"` }
func (GameCommandStats) Command ¶
func (gc GameCommandStats) Command() Command
type GameCommandTransport ¶
type GameCommandTransport struct { Command Command `json:"cmd"` Data json.RawMessage }
type GameCommandUpdateGame ¶
type GameCommandUpdateGame struct { GameCommand Players map[int]string `json:"p,omitempty"` }
func (GameCommandUpdateGame) Command ¶
func (gc GameCommandUpdateGame) Command() Command
type GameCommandUpdateMatrix ¶
type GameCommandUpdateMatrix struct { GameCommand Matrixes map[int]*mino.Matrix `json:"m,omitempty"` }
func (GameCommandUpdateMatrix) Command ¶
func (gc GameCommandUpdateMatrix) Command() Command
type IncomingPlayer ¶
type ListedGame ¶
type Player ¶
type Server ¶
type Server struct { I []ServerInterface In chan GameCommandInterface Out chan GameCommandInterface Games map[int]*Game Logger chan string NewPlayers chan *IncomingPlayer sync.RWMutex // contains filtered or unexported fields }
func NewServer ¶
func NewServer(si []ServerInterface, logLevel int) *Server
func (*Server) FindGame ¶
func (s *Server) FindGame(p *Player, gameID int, newGame ListedGame) *Game
func (*Server) StopListening ¶
func (s *Server) StopListening()
type ServerInterface ¶
type ServerInterface interface { // Load config Host(newPlayers chan<- *IncomingPlayer) Shutdown(reason string) }
Click to show internal directories.
Click to hide internal directories.