move connection state to its own file

master
Jordan Orelli 6 years ago
parent 6cd419d013
commit 34a984a397

@ -150,17 +150,17 @@ func (c *Connection) Name() string {
} }
func (c *Connection) RecordScan() { 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() c.lastScan = time.Now()
time.AfterFunc(options.scanTime, func() { time.AfterFunc(options.scanTime, func() {
c.Printf("scanner ready\n") c.Printf("Scanner ready\n")
}) })
} }
func (c *Connection) RecordBomb() { func (c *Connection) RecordBomb() {
c.lastBomb = time.Now() c.lastBomb = time.Now()
time.AfterFunc(15*time.Second, func() { 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)) 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 { func SpawnRandomly() ConnectionState {
sys, err := randomSystem() sys, err := randomSystem()
if err != nil { if err != nil {

@ -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) {}
Loading…
Cancel
Save