diff --git a/bomb.go b/bomb.go index 078f5e7..2de4859 100644 --- a/bomb.go +++ b/bomb.go @@ -56,7 +56,6 @@ func MakeBomb(s *System) ConnectionState { m.CommandSuite = CommandSet{ balCommand, BroadcastCommand(s), - helpCommand, NearbyCommand(s), playersCommand, } diff --git a/colony.go b/colony.go index 16af87a..407d4f0 100644 --- a/colony.go +++ b/colony.go @@ -17,7 +17,6 @@ func MakeColony(c *Connection, sys *System) { CommandSuite: CommandSet{ balCommand, BroadcastCommand(sys), - helpCommand, NearbyCommand(sys), playersCommand, }, diff --git a/commands.go b/commands.go index 1d29652..807f368 100644 --- a/commands.go +++ b/commands.go @@ -35,6 +35,12 @@ func (c Command) Commands() []Command { type CommandSet []Command func (c CommandSet) GetCommand(name string) *Command { + switch name { + case "help": + return &helpCommand + case "commands": + return &commandsCommand + } for _, cmd := range c { if cmd.name == name { return &cmd @@ -44,7 +50,7 @@ func (c CommandSet) GetCommand(name string) *Command { } func (c CommandSet) Commands() []Command { - return []Command(c) + return append([]Command(c), helpCommand, commandsCommand) } var helpCommand = Command{ @@ -73,10 +79,9 @@ attempting to communicate from one star system to another, it takes time for the light of your message to reach the other star systems. Star systems that are farther away take longer to communicate with. ` - msg = strings.TrimSpace(msg) - fmt.Fprintln(conn, msg) - if len(args) == 0 { + msg = strings.TrimSpace(msg) + fmt.Fprintln(conn, msg) fmt.Fprint(conn, "\n") conn.Line() fmt.Fprint(conn, "\n") @@ -85,8 +90,8 @@ are farther away take longer to communicate with. return } for _, cmdName := range args { - cmd, ok := commandRegistry[cmdName] - if !ok { + cmd := conn.GetCommand(cmdName) + if cmd == nil { conn.Printf("no such command: %v\n", cmdName) continue } diff --git a/idle.go b/idle.go index 91eac69..40d3fc0 100644 --- a/idle.go +++ b/idle.go @@ -15,7 +15,6 @@ func Idle(sys *System) ConnectionState { i := &IdleState{System: sys} i.CommandSuite = CommandSet{ balCommand, - helpCommand, playersCommand, BroadcastCommand(sys), NearbyCommand(sys), diff --git a/lobby.go b/lobby.go index 8767674..43df51c 100644 --- a/lobby.go +++ b/lobby.go @@ -44,8 +44,6 @@ type LobbyState struct { func EnterLobby() ConnectionState { return &LobbyState{ CommandSuite: CommandSet{ - commandsCommand, - helpCommand, newGameCommand, joinGameCommand, }, diff --git a/mining.go b/mining.go index 4f25201..be4c01b 100644 --- a/mining.go +++ b/mining.go @@ -14,7 +14,6 @@ func Mine(sys *System) ConnectionState { m := &MiningState{System: sys} m.CommandSuite = CommandSet{ balCommand, - helpCommand, playersCommand, BroadcastCommand(sys), NearbyCommand(sys), diff --git a/shield.go b/shield.go index a7268e5..460abff 100644 --- a/shield.go +++ b/shield.go @@ -10,7 +10,6 @@ func MakeShield(c *Connection, s *System) { CommandSuite: CommandSet{ balCommand, BroadcastCommand(s), - helpCommand, NearbyCommand(s), playersCommand, }, diff --git a/travel.go b/travel.go index b8d60e8..6ca5c27 100644 --- a/travel.go +++ b/travel.go @@ -20,7 +20,6 @@ func NewTravel(c *Connection, start, dest *System) ConnectionState { dist: start.DistanceTo(dest), } t.CommandSuite = CommandSet{ - helpCommand, playersCommand, balCommand, Command{