players just disconnect at game end now

this is way easier than fixing the "you just can't mine" behavior
properly.  This is a shitty patch, I'll fix it right eventually but this
at least makes it playable.
slack
Jordan Orelli 10 years ago
parent 51409c4f56
commit 4158537894

@ -6,7 +6,6 @@ import (
)
type Bomb struct {
NopReset
player *Connection
origin *System
target *System

@ -6,7 +6,6 @@ import (
)
type broadcast struct {
NopReset
start time.Time
origin *System
dist float64

@ -44,16 +44,6 @@ func NewConnection(conn net.Conn) *Connection {
return c
}
func (conn *Connection) Reset() {
*conn = Connection{
Conn: conn.Conn,
Reader: bufio.NewReader(conn.Conn),
bombs: 1,
player: conn.player,
}
currentGame.Join(conn)
}
func (c *Connection) Login() {
for {
fmt.Fprintf(c, "what is your name, adventurer?\n")

@ -9,6 +9,7 @@ type Game struct {
id Id
start time.Time
end time.Time
done chan interface{}
winner string
winMethod string
connections map[*Connection]bool
@ -33,6 +34,7 @@ func NewGame() *Game {
game := &Game{
id: NewId(),
start: time.Now(),
done: make(chan interface{}),
connections: make(map[*Connection]bool, 32),
elems: make(map[GameElement]bool, 32),
}
@ -42,6 +44,14 @@ func NewGame() *Game {
for _, system := range index {
game.Register(system)
}
if currentGame != nil {
log_info("passing %d connections...", len(currentGame.connections))
for conn, _ := range currentGame.connections {
log_info("moving player %s to new game", conn.PlayerName())
currentGame.Quit(conn)
game.Join(conn)
}
}
return game
}
@ -76,28 +86,20 @@ func (g *Game) Quit(conn *Connection) {
}
func (g *Game) Win(winner *Connection, method string) {
defer close(g.done)
g.end = time.Now()
g.winner = winner.PlayerName()
g.winMethod = method
g.Store()
for conn, _ := range g.connections {
fmt.Fprintf(conn, "player %s has won by %s victory.\n", winner.PlayerName(), method)
fmt.Fprintf(conn, "starting new game ...\n")
conn.Reset()
}
g.Reset()
log_info("player %s has won by %s victory", winner.PlayerName(), method)
for conn, _ := range g.connections {
conn.Respawn()
fmt.Fprintf(conn, "player %s has won by %s victory.\n", winner.PlayerName(), method)
}
}
func (g *Game) Reset() {
for elem, _ := range g.elems {
elem.Reset()
}
connections := g.connections
fresh := NewGame()
*g = *fresh
@ -110,6 +112,11 @@ func (g *Game) Run() {
select {
case <-ticker:
g.tick()
case <-g.done:
for conn, _ := range g.connections {
conn.Close()
}
return
}
}
}
@ -134,11 +141,4 @@ func (g *Game) tick() {
type GameElement interface {
Tick(frame int64)
Dead() bool
Reset()
}
type NopReset struct {
}
func (n NopReset) Reset() {
}

@ -103,8 +103,13 @@ func main() {
bail(E_No_Port, "unable to start server: %v", err)
}
go func() {
for {
log_info("starting new game")
currentGame = NewGame()
go currentGame.Run()
currentGame.Run()
}
}()
for {
conn, err := listener.Accept()

@ -6,7 +6,6 @@ import (
)
type scan struct {
NopReset
start time.Time
origin *System
dist float64

Loading…
Cancel
Save