|
|
@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var commandRegistry map[string]*Command
|
|
|
|
var commandRegistry map[string]*Command
|
|
|
@ -27,6 +28,71 @@ var infoCommand = &Command{
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var nearbyCommand = &Command{
|
|
|
|
|
|
|
|
name: "nearby",
|
|
|
|
|
|
|
|
help: "list objects nearby",
|
|
|
|
|
|
|
|
handler: func(conn *Connection, args ...string) {
|
|
|
|
|
|
|
|
system := conn.System()
|
|
|
|
|
|
|
|
neighbors, err := system.Nearby(25)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log_error("unable to get neighbors: %v", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, neighbor := range neighbors {
|
|
|
|
|
|
|
|
other := index[neighbor.id]
|
|
|
|
|
|
|
|
fmt.Fprintf(conn, "%s: %v\n", other.name, neighbor.distance)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var helpCommand = &Command{
|
|
|
|
|
|
|
|
name: "help",
|
|
|
|
|
|
|
|
help: "helpful things to help you",
|
|
|
|
|
|
|
|
handler: func(conn *Connection, args ...string) {
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
|
|
|
|
fmt.Fprintln(conn, `use the "commands" command for a list of commands.`)
|
|
|
|
|
|
|
|
fmt.Fprintln(conn, `use "help [command-name]" to get info for a specific command.`)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmdName := range args {
|
|
|
|
|
|
|
|
cmd, ok := commandRegistry[cmdName]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
fmt.Fprintf(conn, "no such command: %v\n", cmdName)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(conn, "%v: %v\n", cmdName, cmd.help)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var commandsCommand = &Command{
|
|
|
|
|
|
|
|
name: "commands",
|
|
|
|
|
|
|
|
help: "gives you a handy list of commands",
|
|
|
|
|
|
|
|
handler: func(conn *Connection, args ...string) {
|
|
|
|
|
|
|
|
names := make([]string, 0, len(commandRegistry))
|
|
|
|
|
|
|
|
for name, _ := range commandRegistry {
|
|
|
|
|
|
|
|
names = append(names, name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(names)
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
|
|
|
|
fmt.Fprintln(conn, name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var superscanCommand = &Command{
|
|
|
|
|
|
|
|
// name: "super-scan",
|
|
|
|
|
|
|
|
// help: "super duper scan",
|
|
|
|
|
|
|
|
// handler: func(conn *Connection, args ...string) {
|
|
|
|
|
|
|
|
// for id, _ := range index {
|
|
|
|
|
|
|
|
// if id == conn.System().id {
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
func isCommand(name string) bool {
|
|
|
|
func isCommand(name string) bool {
|
|
|
|
_, ok := commandRegistry[name]
|
|
|
|
_, ok := commandRegistry[name]
|
|
|
|
return ok
|
|
|
|
return ok
|
|
|
@ -47,5 +113,8 @@ func registerCommand(c *Command) {
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
commandRegistry = make(map[string]*Command, 16)
|
|
|
|
commandRegistry = make(map[string]*Command, 16)
|
|
|
|
|
|
|
|
registerCommand(commandsCommand)
|
|
|
|
|
|
|
|
registerCommand(helpCommand)
|
|
|
|
registerCommand(infoCommand)
|
|
|
|
registerCommand(infoCommand)
|
|
|
|
|
|
|
|
registerCommand(nearbyCommand)
|
|
|
|
}
|
|
|
|
}
|
|
|
|