diff --git a/connection.go b/connection.go index 8f894d8..a338cab 100644 --- a/connection.go +++ b/connection.go @@ -150,17 +150,17 @@ func (c *Connection) Name() string { } func (c *Connection) RecordScan() { - c.Printf("scanning known systems for signs of life\n") + c.Printf("Scanning known systems for signs of life\n") c.lastScan = time.Now() time.AfterFunc(options.scanTime, func() { - c.Printf("scanner ready\n") + c.Printf("Scanner ready\n") }) } func (c *Connection) RecordBomb() { c.lastBomb = time.Now() time.AfterFunc(15*time.Second, func() { - fmt.Fprintln(c, "bomb arsenal reloaded") + fmt.Fprintln(c, "Bomb arsenal reloaded") }) } @@ -206,27 +206,6 @@ func (c *Connection) Die(frame int64) { c.SetState(NewDeadState(frame)) } -type ConnectionState interface { - CommandSuite - String() string - FillStatus(*Connection, *status) - Enter(c *Connection) - Tick(c *Connection, frame int64) ConnectionState - Exit(c *Connection) -} - -// No-op enter struct, for composing connection states that have no interesitng -// Enter mechanic. -type NopEnter struct{} - -func (n NopEnter) Enter(c *Connection) {} - -// No-op exit struct, for composing connection states that have no interesting -// Exit mechanic. -type NopExit struct{} - -func (n NopExit) Exit(c *Connection) {} - func SpawnRandomly() ConnectionState { sys, err := randomSystem() if err != nil { diff --git a/connection_state.go b/connection_state.go new file mode 100644 index 0000000..d316678 --- /dev/null +++ b/connection_state.go @@ -0,0 +1,39 @@ +package main + +type ConnectionState interface { + // commands available while in this state + CommandSuite + + // human-readable description of the state + String() string + + // fills a status struct to be printed by the status command. The + // ConnectionState only needs to fill in things that are unique to the + // state itself, the common things on the connection are filled in + // automatically + FillStatus(*Connection, *status) + + // Triggered once when the state is entered + Enter(c *Connection) + + // Triggered every frame in which the state is the connection's current + // state. Returning a different ConnectionState transitions between states. + Tick(c *Connection, frame int64) ConnectionState + + // Triggered once when this state has finished for that connection + Exit(c *Connection) +} + +// No-op enter struct, for composing connection states that have no interesitng +// Enter mechanic. +type NopEnter struct{} + +func (n NopEnter) Enter(c *Connection) {} + +// No-op exit struct, for composing connection states that have no interesting +// Exit mechanic. +type NopExit struct{} + +func (n NopExit) Exit(c *Connection) {} + +