added --debug flag

slack
Jordan Orelli 10 years ago
parent 957a6bfc7a
commit 8100e5e6df

@ -14,6 +14,7 @@ type Command struct {
help string help string
handler func(*Connection, ...string) handler func(*Connection, ...string)
mobile bool mobile bool
debug bool // marks command as a debug mode command
} }
var infoCommand = &Command{ var infoCommand = &Command{
@ -188,8 +189,9 @@ var colonizeCommand = &Command{
} }
var winCommand = &Command{ var winCommand = &Command{
name: "win", name: "win",
help: "win the game.", help: "win the game.",
debug: true,
handler: func(conn *Connection, args ...string) { handler: func(conn *Connection, args ...string) {
conn.Win("win-command") conn.Win("win-command")
}, },
@ -271,10 +273,18 @@ func runCommand(conn *Connection, name string, args ...string) {
} }
func registerCommand(c *Command) { 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) commandRegistry = make(map[string]*Command, 16)
registerCommand(bombCommand) registerCommand(bombCommand)
registerCommand(broadcastCommand) registerCommand(broadcastCommand)

@ -20,6 +20,7 @@ var options struct {
playerSpeed float64 playerSpeed float64
bombSpeed float64 bombSpeed float64
economic int economic int
debug bool
} }
var ( var (
@ -90,11 +91,13 @@ func handleConnection(conn *Connection) {
func main() { func main() {
flag.Parse() flag.Parse()
dbconnect() dbconnect()
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
info_log = log.New(os.Stdout, "[INFO] ", 0) info_log = log.New(os.Stdout, "[INFO] ", 0)
error_log = log.New(os.Stderr, "[ERROR] ", 0) error_log = log.New(os.Stderr, "[ERROR] ", 0)
setupDb() setupDb()
setupCommands()
listener, err := net.Listen("tcp", ":9220") listener, err := net.Listen("tcp", ":9220")
if err != nil { if err != nil {
bail(E_No_Port, "unable to start server: %v", err) 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.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.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.Float64Var(&options.moneySigma, "money-sigma", 1500, "standard deviation in money per system")
flag.BoolVar(&options.debug, "debug", false, "puts the game in debug mode")
} }

Loading…
Cancel
Save