clean clean clean

slack
Jordan Orelli 10 years ago
parent a34c2bc64f
commit c5db5ce93d

@ -278,6 +278,11 @@ func runCommand(conn *Connection, name string, args ...string) {
fmt.Fprintf(conn, "command %s can not be used while in transit\n", name) fmt.Fprintf(conn, "command %s can not be used while in transit\n", name)
return return
} }
if conn.IsMining() {
conn.StopMining()
}
cmd.handler(conn, args...) cmd.handler(conn, args...)
} }

@ -3,6 +3,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"net" "net"
"strings" "strings"
"time" "time"
@ -137,6 +138,28 @@ func (c *Connection) SendBomb(target *System) {
fmt.Fprintf(c, "sending bomb to system %v\n", target.Label()) fmt.Fprintf(c, "sending bomb to system %v\n", target.Label())
} }
func (c *Connection) ReadLines(out chan []string) {
defer close(out)
for {
line, err := c.ReadString('\n')
switch err {
case io.EOF:
return
case nil:
break
default:
log_error("unable to read line on connection: %v", err)
return
}
line = strings.TrimSpace(line)
if line == "" {
continue
}
out <- strings.Split(line, " ")
}
}
func (c *Connection) land() { func (c *Connection) land() {
fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label()) fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label())
c.location = c.dest c.location = c.dest

@ -3,12 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io"
"log" "log"
"math/rand" "math/rand"
"net" "net"
"os" "os"
"strings"
"time" "time"
) )
@ -52,28 +50,11 @@ func handleConnection(conn *Connection) {
conn.Login() conn.Login()
conn.Respawn() conn.Respawn()
for {
line, err := conn.ReadString('\n')
switch err {
case io.EOF:
return
case nil:
break
default:
log_error("failed to read line from player %s: %v", conn.PlayerName(), err)
return
}
line = strings.TrimSpace(line)
if conn.IsMining() { c := make(chan []string)
conn.StopMining() go conn.ReadLines(c)
}
if line == "" {
continue
}
parts := strings.Split(line, " ")
for parts := range c {
if isCommand(parts[0]) { if isCommand(parts[0]) {
runCommand(conn, parts[0], parts[1:]...) runCommand(conn, parts[0], parts[1:]...)
continue continue
@ -85,6 +66,7 @@ func handleConnection(conn *Connection) {
default: default:
fmt.Fprintf(conn, "hmm I'm not sure I know that one.\n") fmt.Fprintf(conn, "hmm I'm not sure I know that one.\n")
} }
} }
} }

Loading…
Cancel
Save