// quit implements the 'QUIT' command. // // quit extracts a player from the world cleanly. If the player's location is // not crowded it also announces their departure - in a crowded location their // departure will go unnoticed. func (p *Player) quit(cmd *command.Command) (handled bool) { log.Printf("%s is quiting", p.Name()) p.quitting = true p.dropInventory(cmd) l := p.Locate() if !l.Crowded() { cmd.Broadcast([]thing.Interface{p}, "%s gives a strangled cry of 'Bye Bye', and then slowly fades away and is gone.", p.Name()) } cmd.Flush() l.Remove(p) PlayerList.Remove(p) return true }
// parseStage2 is called by Parse to take advantage of defer unwinding. By // splitting the parsing we can easily obtain the locks we want and defer the // unlocking. This makes both Parse and parseStage2 very simple. func (p *Player) parseStage2(cmd *command.Command) (retry bool) { for _, l := range cmd.Locks { l.Lock() defer l.Unlock() } // If player moved before we locked we need to retry if !cmd.CanLock(p.Locate()) { return true } handled := p.Process(cmd) retry = cmd.LocksModified() if !handled && !retry { cmd.Respond("[RED]Eh?") } if !retry { cmd.Flush() } return }