diff --git a/commands.go b/commands.go index 785f229..5e96912 100644 --- a/commands.go +++ b/commands.go @@ -231,6 +231,14 @@ var colonizeCommand = &Command{ }, } +var winCommand = &Command{ + name: "win", + help: "win the game.", + handler: func(conn *Connection, args ...string) { + conn.Win() + }, +} + func move(conn *Connection, to *System) { start := conn.System() start.Leave(conn) @@ -344,4 +352,5 @@ func init() { registerCommand(nearbyCommand) registerCommand(scanCommand) registerCommand(mkBombCommand) + registerCommand(winCommand) } diff --git a/db.go b/db.go index f27f85a..19496d3 100644 --- a/db.go +++ b/db.go @@ -68,6 +68,7 @@ func setupDb() { planetsData() edgesTable() playersTable() + gamesTable() fillEdges() } diff --git a/game.go b/game.go new file mode 100644 index 0000000..8e3bd52 --- /dev/null +++ b/game.go @@ -0,0 +1,25 @@ +package main + +import ( + "time" +) + +type Game struct { + start time.Time + end time.Time + winner string + winMethod string +} + +func gamesTable() { + stmnt := `create table if not exists games ( + id integer not null primary key autoincrement, + start text, + end text, + winner text, + win_method text + );` + if _, err := db.Exec(stmnt); err != nil { + log_error("couldn't create games table: %v", err) + } +} diff --git a/main.go b/main.go index 94508b2..92096c5 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,6 @@ func handleConnection(conn *Connection) { } else { fmt.Fprintf(conn, "you are in the system %s. There are %d planets here.\n", system.name, system.planets) } -READING: for { line, err := conn.ReadString('\n') switch err { @@ -59,8 +58,7 @@ READING: break default: log_error("failed to read line from player %s: %v", conn.PlayerName(), err) - time.Sleep(time.Second) - continue READING + return } line = strings.TrimSpace(line)