diff --git a/commands.go b/commands.go index 4304ea8..d4f6c1b 100644 --- a/commands.go +++ b/commands.go @@ -14,6 +14,7 @@ type Command struct { help string handler func(*Connection, ...string) mobile bool + debug bool // marks command as a debug mode command } var infoCommand = &Command{ @@ -188,8 +189,9 @@ var colonizeCommand = &Command{ } var winCommand = &Command{ - name: "win", - help: "win the game.", + name: "win", + help: "win the game.", + debug: true, handler: func(conn *Connection, args ...string) { conn.Win("win-command") }, @@ -271,10 +273,18 @@ func runCommand(conn *Connection, name string, args ...string) { } func registerCommand(c *Command) { - commandRegistry[c.name] = c + if c.debug { + if options.debug { + commandRegistry[c.name] = c + log_info("registered debug command: %s", c.name) + } + } else { + commandRegistry[c.name] = c + log_info("registered command: %s", c.name) + } } -func init() { +func setupCommands() { commandRegistry = make(map[string]*Command, 16) registerCommand(bombCommand) registerCommand(broadcastCommand) diff --git a/main.go b/main.go index 1b4e436..9ef9287 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ var options struct { playerSpeed float64 bombSpeed float64 economic int + debug bool } var ( @@ -90,11 +91,13 @@ func handleConnection(conn *Connection) { func main() { flag.Parse() dbconnect() + rand.Seed(time.Now().UnixNano()) info_log = log.New(os.Stdout, "[INFO] ", 0) error_log = log.New(os.Stderr, "[ERROR] ", 0) setupDb() + setupCommands() listener, err := net.Listen("tcp", ":9220") if err != nil { bail(E_No_Port, "unable to start server: %v", err) @@ -121,4 +124,5 @@ func init() { flag.IntVar(&options.economic, "economic", 25000, "amount of money needed to win economic victory") flag.Float64Var(&options.moneyMean, "money-mean", 10000, "mean amount of money on a system") flag.Float64Var(&options.moneySigma, "money-sigma", 1500, "standard deviation in money per system") + flag.BoolVar(&options.debug, "debug", false, "puts the game in debug mode") }