Documentation
¶
Overview ¶
Package game holds all of the code required to manage games
Index ¶
- Variables
- type Game
- func (g *Game) AutoStart()
- func (g *Game) GetComment() string
- func (g *Game) GetName() string
- func (g *Game) IsRunning() bool
- func (g *Game) OnJoin(source, channel string)
- func (g *Game) OnKick(source, channel, kickee, message string)
- func (g *Game) OnMessage(source, target, msg string, isAction bool)
- func (g *Game) OnNick(source, newnick string)
- func (g *Game) OnPart(source, target, message string)
- func (g *Game) OnQuit(source, message string)
- func (g *Game) Run() error
- func (g *Game) SendFormattedLine(d interface{}, fmt *format.Format) error
- func (g *Game) SendLineFromOtherGame(msg string, source interfaces.Game)
- func (g *Game) Status() string
- func (g *Game) StopOrKill() error
- func (g *Game) StopOrKillTimeout(timeout time.Duration) error
- func (g *Game) StopOrKillWaitgroup(wg *sync.WaitGroup)
- func (g *Game) String() string
- func (g *Game) UpdateFromConfig(conf *tomlconf.Game) error
- func (g *Game) Write(p []byte) (n int, err error)
- func (g *Game) WriteString(s string) (n int, err error)
- type Manager
- func (m *Manager) AddGame(g interfaces.Game) error
- func (m *Manager) Error(err error)
- func (m *Manager) ForEachGame(gameFunc func(interfaces.Game), skip []interfaces.Game)
- func (m *Manager) GameExists(name string) bool
- func (m *Manager) GetGameFromName(name string) interfaces.Game
- func (m *Manager) ReloadGames(configs []*tomlconf.Game)
- func (m *Manager) Run() (bool, error)
- func (m *Manager) StartAutoStartGames()
- func (m *Manager) StartGame(name string) error
- func (m *Manager) Stop(msg string, restart bool)
- func (m *Manager) StopAllGames()
- func (m *Manager) StopGame(name string) error
- func (m *Manager) String() string
- type Regexp
- type RegexpList
- type RegexpManager
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyRunning = errors.New("game is already running") ErrGameNotRunning = errors.New("game is not running") )
Sentinel errors
var ( // ErrGameNotExist is returned by various methods when the game requested does not exist ErrGameNotExist = errors.New("requested game does not exist") )
Functions ¶
This section is empty.
Types ¶
type Game ¶
Game represents a game server and its transport
func (*Game) AutoStart ¶
func (g *Game) AutoStart()
AutoStart checks if the game is marked as auto-starting, and if so, starts the game by starting Game.Run in a goroutine
func (*Game) GetComment ¶
GetComment is a getter required by the interfaces.Game interface
func (*Game) OnKick ¶
OnKick is a callback that is fired when a user kicks another user from the channel
func (*Game) Run ¶
Run starts the given game if it is not already running. Note that this method blocks until the game exits, meaning you will probably want to use it in a goroutine
func (*Game) SendFormattedLine ¶
SendFormattedLine executes the given format with the given data and sends the result to the transport's STDIN
func (*Game) SendLineFromOtherGame ¶
func (g *Game) SendLineFromOtherGame(msg string, source interfaces.Game)
SendLineFromOtherGame Is a frontend for sending messages to a game from other games. If the game in source is the same as the current game, the name is switched to "LOCAL"
func (*Game) StopOrKill ¶
StopOrKill sends SIGINT to the running game, and after 30 seconds if the game has not closed on its own, it sends SIGKILL
func (*Game) StopOrKillTimeout ¶
StopOrKillTimeout sends SIGTERM to the running transport. If the game is still running after the timeout has passed, the transport is sent SIGKILL
func (*Game) StopOrKillWaitgroup ¶
StopOrKillWaitgroup is exactly the same as StopOrKill but it takes a waitgroup that is marked as done after the game has exited
func (*Game) UpdateFromConfig ¶
UpdateFromConfig updates the game object with the data from the config object.
type Manager ¶
Manager manages games, and communication between them, eachother, and an interfaces.Bot
func NewManager ¶
NewManager creates a Manager and configures it using the given data.
func (*Manager) AddGame ¶
func (m *Manager) AddGame(g interfaces.Game) error
AddGame adds the given game to the Manager's managed games. If the game already exists, AddGame returns an error
func (*Manager) Error ¶
Error is a helper function that returns the passed error to the manager's bot instance
func (*Manager) ForEachGame ¶
func (m *Manager) ForEachGame(gameFunc func(interfaces.Game), skip []interfaces.Game)
ForEachGame allows you to run a function on every game the Manager manages. Note that this read locks the mutex protecting the games list. Any panics that occur will be recovered and logged as an error on the bot
func (*Manager) GameExists ¶
GameExists returns whether or not the given name exists on any game found on this Manager
func (*Manager) GetGameFromName ¶
func (m *Manager) GetGameFromName(name string) interfaces.Game
GetGameFromName returns the game represented by the given name. If the game does not exist, it returns nil
func (*Manager) ReloadGames ¶
ReloadGames uses the passed config values to reload the games stored on it. Any new games found in the config are added, rather than reloaded
func (*Manager) StartAutoStartGames ¶
func (m *Manager) StartAutoStartGames()
StartAutoStartGames starts any game marked as auto start
func (*Manager) StartGame ¶
StartGame starts the game named if it exists on the manager and is not already running
func (*Manager) StopAllGames ¶
func (m *Manager) StopAllGames()
StopAllGames stops all the games on the manager, blocking until they all close or are killed
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp is a representation of a regex and a util.Format pair that is applied to stdout lines of a game
type RegexpList ¶
type RegexpList []*Regexp
RegexpList is a slice of pointers to regexps that exists simply to implement the sort interface
func (RegexpList) Len ¶
func (gl RegexpList) Len() int
func (RegexpList) Less ¶
func (gl RegexpList) Less(i, j int) bool
func (RegexpList) Swap ¶
func (gl RegexpList) Swap(i, j int)
type RegexpManager ¶
RegexpManager manages regexps for a game
func NewRegexpManager ¶
func NewRegexpManager(game *Game) *RegexpManager
NewRegexpManager creates a new RegexpManager with reference to the passed Game
func (*RegexpManager) String ¶
func (r *RegexpManager) String() string
func (*RegexpManager) UpdateFromConf ¶
UpdateFromConf updates the regexps on the RegexpManager. During the update, the Regexp list is sorted. UpdateFromConf only applies changes if none of the regexps failed to be created with NewRegexp. It is safe for concurrent use