From 495f4c3fa21761f95dc622954dc9ee67b16ca787 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 6 Jun 2019 13:39:05 +0000 Subject: [PATCH] fix nil panic when lobby connections leave --- connection.go | 6 ++++-- lobby.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/connection.go b/connection.go index a338cab..ec94920 100644 --- a/connection.go +++ b/connection.go @@ -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()) - c.game.Quit(c) + if c.game != nil { + c.game.Quit(c) + } if c.Conn != nil { return c.Conn.Close() } diff --git a/lobby.go b/lobby.go index 6781890..e6e0788 100644 --- a/lobby.go +++ b/lobby.go @@ -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) },