|
|
@ -9,8 +9,6 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var connected = make(map[*Connection]bool, 32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
type Connection struct {
|
|
|
|
net.Conn
|
|
|
|
net.Conn
|
|
|
|
*bufio.Reader
|
|
|
|
*bufio.Reader
|
|
|
@ -32,10 +30,19 @@ func NewConnection(conn net.Conn) *Connection {
|
|
|
|
Reader: bufio.NewReader(conn),
|
|
|
|
Reader: bufio.NewReader(conn),
|
|
|
|
bombs: 1,
|
|
|
|
bombs: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
connected[c] = true
|
|
|
|
currentGame.Join(c)
|
|
|
|
return c
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (conn *Connection) Reset() {
|
|
|
|
|
|
|
|
*conn = Connection{
|
|
|
|
|
|
|
|
Conn: conn.Conn,
|
|
|
|
|
|
|
|
Reader: bufio.NewReader(conn.Conn),
|
|
|
|
|
|
|
|
bombs: 1,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentGame.Join(conn)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Connection) Login() {
|
|
|
|
func (c *Connection) Login() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
fmt.Fprintf(c, "what is your name, adventurer?\n")
|
|
|
|
fmt.Fprintf(c, "what is your name, adventurer?\n")
|
|
|
@ -79,8 +86,11 @@ func (c *Connection) System() *System {
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Connection) Close() error {
|
|
|
|
func (c *Connection) Close() error {
|
|
|
|
log_info("player disconnecting: %s", c.PlayerName())
|
|
|
|
log_info("player disconnecting: %s", c.PlayerName())
|
|
|
|
delete(connected, c)
|
|
|
|
currentGame.Quit(c)
|
|
|
|
return c.Conn.Close()
|
|
|
|
if c.Conn != nil {
|
|
|
|
|
|
|
|
return c.Conn.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Connection) PlayerName() string {
|
|
|
|
func (c *Connection) PlayerName() string {
|
|
|
@ -168,10 +178,7 @@ func (c *Connection) Deposit(n int64) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Connection) Win(method string) {
|
|
|
|
func (c *Connection) Win(method string) {
|
|
|
|
for conn, _ := range connected {
|
|
|
|
currentGame.Win(c, method)
|
|
|
|
fmt.Fprintf(conn, "player %s has won.\n", c.PlayerName())
|
|
|
|
|
|
|
|
conn.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Connection) Die() {
|
|
|
|
func (c *Connection) Die() {
|
|
|
|