From ed53a60bd110221ceeb12ce9ad531bce14b2cf46 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 8 Nov 2014 10:24:03 -0500 Subject: [PATCH] can now only scan once per minute --- commands.go | 5 +++++ session.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/commands.go b/commands.go index 813b124..40fdade 100644 --- a/commands.go +++ b/commands.go @@ -81,6 +81,11 @@ var scanCommand = &Command{ name: "scan", help: "super duper scan", 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() log_info("scan sent from %s", system.name) for id, _ := range index { diff --git a/session.go b/session.go index 756d8d9..b12e919 100644 --- a/session.go +++ b/session.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "strings" + "time" ) type Connection struct { @@ -12,6 +13,7 @@ type Connection struct { *bufio.Reader player *Player location *System + lastScan time.Time } func NewConnection(conn net.Conn) *Connection { @@ -76,3 +78,15 @@ func (c *Connection) PlayerName() string { func (c *Connection) InTransit() bool { 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)) +}