game

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package game holds all of the code required to manage games

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyRunning = errors.New("game is already running")
	ErrGameNotRunning = errors.New("game is not running")
)

Sentinel errors

View Source
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

type Game struct {
	*log.Logger
	// contains filtered or unexported fields
}

Game represents a game server and its transport

func NewGame

func NewGame(conf *tomlconf.Game, manager *Manager) (*Game, error)

NewGame creates a new game from the given config

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

func (g *Game) GetComment() string

GetComment is a getter required by the interfaces.Game interface

func (*Game) GetName

func (g *Game) GetName() string

GetName is a getter required by the interfaces.Game interface

func (*Game) IsRunning

func (g *Game) IsRunning() bool

IsRunning returns whether or not the transport is currently running

func (*Game) OnJoin

func (g *Game) OnJoin(source, channel string)

OnJoin is a callback that is fired when a user joins any channel

func (*Game) OnKick

func (g *Game) OnKick(source, channel, kickee, message string)

OnKick is a callback that is fired when a user kicks another user from the channel

func (*Game) OnMessage

func (g *Game) OnMessage(source, target, msg string, isAction bool)

OnMessage is a callback that is fired when a PRIVMSG is received from IRC

func (*Game) OnNick

func (g *Game) OnNick(source, newnick string)

OnNick is a callback that is fired when a user changes their nickname

func (*Game) OnPart

func (g *Game) OnPart(source, target, message string)

OnPart is a callback that is fired when a user leaves a channel

func (*Game) OnQuit

func (g *Game) OnQuit(source, message string)

OnQuit is a callback that is fired when a user quits from IRC

func (*Game) Run

func (g *Game) Run() error

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

func (g *Game) SendFormattedLine(d interface{}, fmt *format.Format) error

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) Status

func (g *Game) Status() string

Status returns the status of the game's transport as a string

func (*Game) StopOrKill

func (g *Game) StopOrKill() error

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

func (g *Game) StopOrKillTimeout(timeout time.Duration) error

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

func (g *Game) StopOrKillWaitgroup(wg *sync.WaitGroup)

StopOrKillWaitgroup is exactly the same as StopOrKill but it takes a waitgroup that is marked as done after the game has exited

func (*Game) String

func (g *Game) String() string

func (*Game) UpdateFromConfig

func (g *Game) UpdateFromConfig(conf *tomlconf.Game) error

UpdateFromConfig updates the game object with the data from the config object.

func (*Game) Write

func (g *Game) Write(p []byte) (n int, err error)

Write writes the given data to the transport's STDIN, it it safe to use concurrently

func (*Game) WriteString

func (g *Game) WriteString(s string) (n int, err error)

WriteString is the same as Write but accepts a string instead of a byte slice

type Manager

type Manager struct {
	Cmd *command.Manager

	*log.Logger
	// contains filtered or unexported fields
}

Manager manages games, and communication between them, eachother, and an interfaces.Bot

func NewManager

func NewManager(conf *tomlconf.Config, bot interfaces.Bot, logger *log.Logger) (*Manager, error)

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

func (m *Manager) Error(err 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

func (m *Manager) GameExists(name string) bool

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

func (m *Manager) ReloadGames(configs []*tomlconf.Game)

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) Run

func (m *Manager) Run() (bool, error)

Run starts the manager, connects its bots

func (*Manager) StartAutoStartGames

func (m *Manager) StartAutoStartGames()

StartAutoStartGames starts any game marked as auto start

func (*Manager) StartGame

func (m *Manager) StartGame(name string) error

StartGame starts the game named if it exists on the manager and is not already running

func (*Manager) Stop

func (m *Manager) Stop(msg string, restart bool)

Stop stops all running games on the manager and disconnects the bot.

func (*Manager) StopAllGames

func (m *Manager) StopAllGames()

StopAllGames stops all the games on the manager, blocking until they all close or are killed

func (*Manager) StopGame

func (m *Manager) StopGame(name string) error

StopGame stops the named game on the manager if it exists and is already running

func (*Manager) String

func (m *Manager) String() string

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

func NewRegexp

func NewRegexp(conf tomlconf.Regexp, manager *RegexpManager, root *template.Template) (*Regexp, error)

NewRegexp instantiates a regexp object from a config.Regexp. the root may be nil, otherwise everything passed must exist

func (*Regexp) String

func (r *Regexp) String() string

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

type RegexpManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (r *RegexpManager) UpdateFromConf(res []tomlconf.Regexp, root *template.Template) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL