can now only scan once per minute

pull/5/head
Jordan Orelli 10 years ago
parent 47a54c939b
commit ed53a60bd1

@ -81,6 +81,11 @@ var scanCommand = &Command{
name: "scan", name: "scan",
help: "super duper scan", help: "super duper scan",
handler: func(conn *Connection, args ...string) { handler: func(conn *Connection, args ...string) {
if !conn.CanScan() {
fmt.Fprintf(conn, "scanners are still recharging. Can scan again in %v\n", conn.NextScan())
return
}
conn.RecordScan()
system := conn.System() system := conn.System()
log_info("scan sent from %s", system.name) log_info("scan sent from %s", system.name)
for id, _ := range index { for id, _ := range index {

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"strings" "strings"
"time"
) )
type Connection struct { type Connection struct {
@ -12,6 +13,7 @@ type Connection struct {
*bufio.Reader *bufio.Reader
player *Player player *Player
location *System location *System
lastScan time.Time
} }
func NewConnection(conn net.Conn) *Connection { func NewConnection(conn net.Conn) *Connection {
@ -76,3 +78,15 @@ func (c *Connection) PlayerName() string {
func (c *Connection) InTransit() bool { func (c *Connection) InTransit() bool {
return c.location == nil return c.location == nil
} }
func (c *Connection) RecordScan() {
c.lastScan = time.Now()
}
func (c *Connection) CanScan() bool {
return time.Since(c.lastScan) > 1*time.Minute
}
func (c *Connection) NextScan() time.Duration {
return -time.Since(c.lastScan.Add(time.Minute))
}

Loading…
Cancel
Save