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",
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 {

@ -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))
}

Loading…
Cancel
Save