fix nil panic when lobby connections leave

master
Jordan Orelli 6 years ago
parent 34a984a397
commit 495f4c3fa2

@ -74,7 +74,7 @@ func (c *Connection) RunCommand(name string, args ...string) {
func (c *Connection) ListCommands() {
c.Printf("\n")
c.Line()
c.Printf("- Available Commands\n")
c.Printf("- Available Commands in state: %s\n", c.ConnectionState.String())
c.Line()
commands := c.Commands()
names := make([]string, len(commands))
@ -135,7 +135,9 @@ func (c *Connection) Printf(template string, args ...interface{}) (int, error) {
func (c *Connection) Close() error {
log_info("player disconnecting: %s", c.Name())
if c.game != nil {
c.game.Quit(c)
}
if c.Conn != nil {
return c.Conn.Close()
}

@ -108,7 +108,7 @@ var newGameCommand = Command{
handler: func(c *Connection, args ...string) {
c.Printf("Starting a new game...\n")
game := gm.NewGame()
log_info("Created game: %s", game.id)
log_info("%s Created game: %s", c.profile.name, game.id)
go game.Run()
c.game = game
c.Printf("Now playing in game: %s\n\n", game.id)
@ -136,6 +136,7 @@ Usage: join [game-code]`, " \n\t"))
}
id := args[0]
c.game = gm.Get(id)
log_info("%s Joining game: %s", c.profile.name, c.game.id)
c.SetState(SpawnRandomly())
c.game.Join(c)
},

Loading…
Cancel
Save