Documentation ¶
Index ¶
- Constants
- func NetworkAndAddress(address string) (string, string)
- func Nickname(nick string) string
- type ClientInterface
- type Command
- 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) RemovePlayer(playerID int)
- func (g *Game) RemovePlayerL(playerID int)
- func (g *Game) Reset()
- func (g *Game) ResetL()
- 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 GameCommandGameOver
- type GameCommandInterface
- type GameCommandJoinGame
- type GameCommandMessage
- type GameCommandNickname
- type GameCommandPing
- type GameCommandPong
- type GameCommandQuitGame
- type GameCommandReceiveGarbage
- type GameCommandSendGarbage
- type GameCommandStartGame
- type GameCommandTransport
- type GameCommandUpdateGame
- type GameCommandUpdateMatrix
- type IncomingPlayer
- type Player
- type Server
- type ServerConn
- type ServerInterface
Constants ¶
View Source
const ( LogStandard = iota LogDebug LogVerbose )
View Source
const ( DefaultPort = 1984 DefaultServer = "netris.rocketnine.space" )
View Source
const ( CommandQueueSize = 10 LogQueueSize = 10 PlayerHost = -1 PlayerUnknown = 0 )
View Source
const ConnTimeout = 30 * time.Second
View Source
const UpdateDuration = 850 * time.Millisecond
Variables ¶
This section is empty.
Functions ¶
func NetworkAndAddress ¶
Types ¶
type ClientInterface ¶
type ClientInterface interface { Attach(in chan<- GameCommandInterface, out <-chan GameCommandInterface) Detach(reason string) }
type Command ¶
type Command int
const ( CommandUnknown Command = iota CommandDisconnect CommandPing CommandPong CommandNickname CommandMessage CommandNewGame CommandJoinGame CommandQuitGame CommandUpdateGame CommandStartGame CommandGameOver CommandUpdateMatrix CommandSendGarbage CommandReceiveGarbage )
The order of these constants must be preserved
type ConnectingPlayer ¶
type ConnectingPlayer struct { Client ClientInterface Name string }
type Game ¶
type Game struct { Rank int Minos []mino.Mino Seed int64 Players map[int]*Player FallTime time.Duration Event chan interface{} Started bool Starting bool GameOver bool SentGameOverMatrix bool Terminated bool LocalPlayer int NextPlayer int LogLevel int Local bool *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) RemovePlayer ¶
func (*Game) RemovePlayerL ¶
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
}
func (*GameCommand) SetSource ¶
func (gc *GameCommand) SetSource(source int)
func (*GameCommand) Source ¶
func (gc *GameCommand) Source() int
type GameCommandGameOver ¶
type GameCommandGameOver struct { GameCommand Player int Winner string }
func (GameCommandGameOver) Command ¶
func (gc GameCommandGameOver) Command() Command
type GameCommandInterface ¶
type GameCommandJoinGame ¶
type GameCommandJoinGame struct { GameCommand Name string GameID int PlayerID int }
func (GameCommandJoinGame) Command ¶
func (gc GameCommandJoinGame) Command() Command
type GameCommandMessage ¶
type GameCommandMessage struct { GameCommand Player int Message string }
func (GameCommandMessage) Command ¶
func (gc GameCommandMessage) Command() Command
type GameCommandNickname ¶
type GameCommandNickname struct { GameCommand Player int Nickname string }
func (GameCommandNickname) Command ¶
func (gc GameCommandNickname) Command() Command
type GameCommandPing ¶
type GameCommandPing struct { GameCommand Message string }
func (GameCommandPing) Command ¶
func (gc GameCommandPing) Command() Command
type GameCommandPong ¶
type GameCommandPong struct { GameCommand Message string }
func (GameCommandPong) Command ¶
func (gc GameCommandPong) Command() Command
type GameCommandQuitGame ¶
type GameCommandQuitGame struct { GameCommand Player int }
func (GameCommandQuitGame) Command ¶
func (gc GameCommandQuitGame) Command() Command
type GameCommandReceiveGarbage ¶
type GameCommandReceiveGarbage struct { GameCommand Lines int }
func (GameCommandReceiveGarbage) Command ¶
func (gc GameCommandReceiveGarbage) Command() Command
type GameCommandSendGarbage ¶
type GameCommandSendGarbage struct { GameCommand Lines int }
func (GameCommandSendGarbage) Command ¶
func (gc GameCommandSendGarbage) Command() Command
type GameCommandStartGame ¶
type GameCommandStartGame struct { GameCommand Seed int64 Started bool }
func (GameCommandStartGame) Command ¶
func (gc GameCommandStartGame) Command() Command
type GameCommandTransport ¶
type GameCommandTransport struct { Command Command `json:"cmd"` Data json.RawMessage }
type GameCommandUpdateGame ¶
type GameCommandUpdateGame struct { GameCommand Players map[int]string }
func (GameCommandUpdateGame) Command ¶
func (gc GameCommandUpdateGame) Command() Command
type GameCommandUpdateMatrix ¶
type GameCommandUpdateMatrix struct { GameCommand Matrixes map[int]*mino.Matrix }
func (GameCommandUpdateMatrix) Command ¶
func (gc GameCommandUpdateMatrix) Command() Command
type IncomingPlayer ¶
type IncomingPlayer struct { Name string Conn *ServerConn }
type Player ¶
type Player struct { Name string *ServerConn Score int Preview *mino.Matrix Matrix *mino.Matrix // contains filtered or unexported fields }
func NewPlayer ¶
func NewPlayer(name string, conn *ServerConn) *Player
type Server ¶
type Server struct { I []ServerInterface In chan GameCommandInterface Out chan GameCommandInterface NewPlayers chan *IncomingPlayer Games map[int]*Game Logger chan string sync.RWMutex // contains filtered or unexported fields }
func NewServer ¶
func NewServer(si []ServerInterface) *Server
func (*Server) StopListening ¶
func (s *Server) StopListening()
type ServerConn ¶
type ServerConn struct { Conn net.Conn Player int In chan GameCommandInterface ForwardOut chan GameCommandInterface LastTransfer time.Time Terminated bool *sync.WaitGroup // contains filtered or unexported fields }
func Connect ¶
func Connect(address string) *ServerConn
func NewServerConn ¶
func NewServerConn(conn net.Conn, forwardOut chan GameCommandInterface) *ServerConn
func (*ServerConn) Close ¶
func (s *ServerConn) Close()
func (*ServerConn) JoinGame ¶
func (s *ServerConn) JoinGame(name string, gameID int, logger chan string, draw chan event.DrawObject) (*Game, error)
func (*ServerConn) Write ¶
func (s *ServerConn) Write(gc GameCommandInterface)
type ServerInterface ¶
type ServerInterface interface { // Load config Host(newPlayers chan<- *IncomingPlayer) Shutdown(reason string) }
Click to show internal directories.
Click to hide internal directories.