Example #1
0
func specificSpawnerMenu(s *Session, spawner types.Spawner) {
	utils.ExecMenu(fmt.Sprintf("%s - %s", "Spawner", spawner.GetName()), s, func(menu *utils.Menu) {
		menu.AddAction("r", "Rename", func() bool {
			newName := s.getRawUserInput("New name: ")
			if newName != "" {
				spawner.SetName(newName)
			}
			return true
		})

		menu.AddAction("c", fmt.Sprintf("Count - %v", spawner.GetCount()), func() bool {
			count, valid := s.getInt("New count: ", 0, 1000)
			if valid {
				spawner.SetCount(count)
			}
			return true
		})

		menu.AddAction("h", fmt.Sprintf("Health - %v", spawner.GetHealth()), func() bool {
			health, valid := s.getInt("New hitpoint count: ", 0, 1000)
			if valid {
				spawner.SetHealth(health)
			}
			return true
		})
	})
}
Example #2
0
func templateMenu(s *Session, template types.Template) {
	utils.ExecMenu(template.GetName(), s, func(menu *utils.Menu) {
		menu.AddAction("c", "Create", func() bool {
			item := model.CreateItem(template.GetId())
			item.SetContainerId(s.pc.GetId(), nil)
			s.WriteLine("Item created")
			return true
		})

		menu.AddAction("d", "Delete", func() bool {
			items := model.GetTemplateItems(template.GetId())
			if len(items) > 0 {
				if !s.getConfirmation(fmt.Sprintf("%v associated items will also be deleted, proceed? ", len(items))) {
					return true
				}
			}

			model.DeleteTemplate(template.GetId())

			return false
		})

		menu.AddAction("v", fmt.Sprintf("Value - %v", template.GetValue()), func() bool {
			value, valid := s.getInt("New value: ", 0, math.MaxInt32)
			if valid {
				template.SetValue(value)
			}
			return true
		})

		menu.AddAction("n", "Name", func() bool {
			name := s.getRawUserInput("New name: ")
			if name != "" {
				template.SetName(name)
			}
			return true
		})

		menu.AddAction("w", fmt.Sprintf("Weight - %v", template.GetWeight()), func() bool {
			weight, valid := s.getInt("New weight: ", 0, math.MaxInt32)
			if valid {
				template.SetWeight(weight)
			}
			return true
		})

		menu.AddAction("a", fmt.Sprintf("Capacity - %v", template.GetCapacity()), func() bool {
			capacity, valid := s.getInt("New capacity: ", 0, math.MaxInt32)
			if valid {
				template.SetCapacity(capacity)
			}
			return true
		})
	})
}
Example #3
0
func (self *connectionHandler) adminMenu() {
	utils.ExecMenu(
		"Admin",
		self.user,
		func(menu *utils.Menu) {
			menu.AddAction("u", "Users", func() bool {
				self.userAdminMenu()
				return true
			})
		})
}
Example #4
0
func (self *connectionHandler) deleteMenu() {
	utils.ExecMenu(
		"Delete character",
		self.user,
		func(menu *utils.Menu) {
			// TODO: Sort character list
			chars := model.GetUserCharacters(self.user.GetId())
			for i, char := range chars {
				c := char
				menu.AddAction(strconv.Itoa(i+1), char.GetName(), func() bool {
					// TODO: Delete confirmation
					model.DeleteCharacter(c.GetId())
					return true
				})
			}
		})
}
Example #5
0
func (self *connectionHandler) userAdminMenu() {
	utils.ExecMenu("User Admin", self.user, func(menu *utils.Menu) {
		users := model.GetUsers()
		sort.Sort(users)

		for i, user := range users {
			online := ""
			if user.IsOnline() {
				online = "*"
			}

			u := user
			menu.AddAction(strconv.Itoa(i+1), user.GetName()+online, func() bool {
				self.specificUserMenu(u)
				return true
			})
		}
	})
}
Example #6
0
func specificNpcMenu(s *Session, npc types.NPC) {
	utils.ExecMenu(npc.GetName(), s, func(menu *utils.Menu) {
		menu.AddAction("r", "Rename", func() bool {
			name := getNpcName(s)
			if name != "" {
				npc.SetName(name)
			}
			return true
		})

		menu.AddAction("d", "Delete", func() bool {
			model.DeleteCharacter(npc.GetId())
			return false
		})

		menu.AddAction("c", "Conversation", func() bool {
			conversation := npc.GetConversation()

			if conversation == "" {
				conversation = "<empty>"
			}

			s.WriteLine("Conversation: %s", conversation)
			newConversation := s.getRawUserInput("New conversation text: ")

			if newConversation != "" {
				npc.SetConversation(newConversation)
			}
			return true
		})

		roamingState := "Off"
		if npc.GetRoaming() {
			roamingState = "On"
		}

		menu.AddAction("o", fmt.Sprintf("Roaming - %s", roamingState), func() bool {
			npc.SetRoaming(!npc.GetRoaming())
			return true
		})
	})
}
Example #7
0
func spawnerMenu(s *Session, area types.Area) {
	utils.ExecMenu("Spawners", s, func(menu *utils.Menu) {
		for i, spawner := range model.GetAreaSpawners(area.GetId()) {
			sp := spawner
			menu.AddActionI(i, spawner.GetName(), func() bool {
				specificSpawnerMenu(s, sp)
				return true
			})
		}

		menu.AddAction("n", "New", func() bool {
			name := s.getRawUserInput("Name of spawned NPC: ")

			if name != "" {
				model.CreateSpawner(name, area.GetId())
			}
			return true
		})
	})
}
Example #8
0
func (self *connectionHandler) userMenu() {
	utils.ExecMenu(
		self.user.GetName(),
		self.user,
		func(menu *utils.Menu) {
			menu.OnExit(func() {
				self.user.SetOnline(false)
				self.user = nil
			})

			if self.user.IsAdmin() {
				menu.AddAction("a", "Admin", func() bool {
					self.adminMenu()
					return true
				})
			}

			menu.AddAction("n", "New character", func() bool {
				self.pc = self.newPlayer()
				return true
			})

			// TODO: Sort character list
			chars := model.GetUserCharacters(self.user.GetId())

			if len(chars) > 0 {
				menu.AddAction("d", "Delete character", func() bool {
					self.deleteMenu()
					return true
				})
			}

			for i, char := range chars {
				c := char
				menu.AddAction(strconv.Itoa(i+1), char.GetName(), func() bool {
					self.pc = c
					return false
				})
			}
		})
}
Example #9
0
func (self *connectionHandler) mainMenu() {
	utils.ExecMenu(
		"MUD",
		self,
		func(menu *utils.Menu) {
			menu.AddAction("l", "Login", func() bool {
				self.user = login(self.conn)
				return false
			})

			menu.AddAction("n", "New user", func() bool {
				self.user = newUser(self.conn)
				return false
			})

			menu.OnExit(func() {
				utils.WriteLine(self.conn, "Take luck!", types.ColorModeNone)
				self.conn.Close()
			})
		})
}
Example #10
0
func specificSkillMenu(s *Session, skill types.Skill) {
	utils.ExecMenu(fmt.Sprintf("Skill - %s", skill.GetName()), s, func(menu *utils.Menu) {
		menu.AddAction("e", fmt.Sprintf("Effect - %v", skill.GetEffect()), func() bool {
			return true
		})
		menu.AddAction("p", fmt.Sprintf("Power - %v", skill.GetPower()), func() bool {
			dmg, valid := s.getInt("New power: ", 0, 1000)
			if valid {
				skill.SetPower(dmg)
			}
			return true
		})
		menu.AddAction("c", fmt.Sprintf("Cost - %v", skill.GetCost()), func() bool {
			cost, valid := s.getInt("New cost: ", 0, 1000)
			if valid {
				skill.SetCost(cost)
			}
			return true
		})
		menu.AddAction("v", fmt.Sprintf("Variance - %v", skill.GetVariance()), func() bool {
			variance, valid := s.getInt("New variance: ", 0, 1000)
			if valid {
				skill.SetVariance(variance)
			}
			return true
		})
		menu.AddAction("s", fmt.Sprintf("Speed - %v", skill.GetSpeed()), func() bool {
			speed, valid := s.getInt("New speed: ", 0, 1000)
			if valid {
				skill.SetSpeed(speed)
			}
			return true
		})
		menu.AddAction("d", "Delete", func() bool {
			model.DeleteSkill(skill.GetId())
			return false
		})
	})
}
Example #11
0
func (self *connectionHandler) specificUserMenu(user types.User) {
	suffix := ""
	if user.IsOnline() {
		suffix = "(Online)"
	} else {
		suffix = "(Offline)"
	}

	utils.ExecMenu(
		fmt.Sprintf("User: %s %s", user.GetName(), suffix),
		self.user,
		func(menu *utils.Menu) {
			menu.AddAction("d", "Delete", func() bool {
				model.DeleteUser(user.GetId())
				return false
			})

			menu.AddAction("a", fmt.Sprintf("Admin - %v", user.IsAdmin()), func() bool {
				u := model.GetUser(user.GetId())
				u.SetAdmin(!u.IsAdmin())
				return true
			})

			if user.IsOnline() {
				menu.AddAction("w", "Watch", func() bool {
					if user == self.user {
						self.user.WriteLine("You can't watch yourself!")
					} else {
						userConn := user.GetConnection().(*wrappedConnection)

						userConn.watcher.AddWatcher(self.conn)
						utils.GetRawUserInput(self.conn, "Type anything to stop watching\r\n", self.user.GetColorMode())
						userConn.watcher.RemoveWatcher(self.conn)
					}
					return true
				})
			}
		})
}
Example #12
0
func toggleExitMenu(s *Session) {
	onOrOff := func(direction types.Direction) string {
		text := "Off"
		if s.GetRoom().HasExit(direction) {
			text = "On"
		}
		return types.Colorize(types.ColorBlue, text)
	}

	toggleExit := func(direction types.Direction) func() bool {
		return func() bool {
			room := s.GetRoom()

			enable := !room.HasExit(direction)
			room.SetExitEnabled(direction, enable)

			loc := room.NextLocation(direction)
			otherRoom := model.GetRoomByLocation(loc, room.GetZoneId())
			if otherRoom != nil {
				otherRoom.SetExitEnabled(direction.Opposite(), enable)
			}
			return false
		}
	}

	utils.ExecMenu("Edit Exits", s, func(menu *utils.Menu) {
		menu.AddAction("n", "North: "+onOrOff(types.DirectionNorth), toggleExit(types.DirectionNorth))
		menu.AddAction("ne", "North East: "+onOrOff(types.DirectionNorthEast), toggleExit(types.DirectionNorthEast))
		menu.AddAction("e", "East: "+onOrOff(types.DirectionEast), toggleExit(types.DirectionEast))
		menu.AddAction("se", "South East: "+onOrOff(types.DirectionSouthEast), toggleExit(types.DirectionSouthEast))
		menu.AddAction("s", "South: "+onOrOff(types.DirectionSouth), toggleExit(types.DirectionSouth))
		menu.AddAction("sw", "South West: "+onOrOff(types.DirectionSouthWest), toggleExit(types.DirectionSouthWest))
		menu.AddAction("w", "West: "+onOrOff(types.DirectionWest), toggleExit(types.DirectionWest))
		menu.AddAction("nw", "North West: "+onOrOff(types.DirectionNorthWest), toggleExit(types.DirectionNorthWest))
		menu.AddAction("u", "Up: "+onOrOff(types.DirectionUp), toggleExit(types.DirectionUp))
		menu.AddAction("d", "Down: "+onOrOff(types.DirectionDown), toggleExit(types.DirectionDown))
	})
}
Example #13
0
func specificAreaMenu(s *Session, area types.Area) {
	utils.ExecMenu(area.GetName(), s, func(menu *utils.Menu) {
		menu.AddAction("r", "Rename", func() bool {
			newName := s.getRawUserInput("New name: ")

			if newName != "" {
				area.SetName(newName)
			}
			return true
		})
		menu.AddAction("d", "Delete", func() bool {
			answer := s.getRawUserInput("Are you sure? ")

			if strings.ToLower(answer) == "y" {
				model.DeleteArea(area.GetId())
			}
			return false
		})
		menu.AddAction("s", "Spawners", func() bool {
			spawnerMenu(s, area)
			return true
		})
	})
}
Example #14
0
	},
	"sb": aAlias("skillbook"),
	"skillbook": {
		exec: func(s *Session, arg string) {
			utils.ExecMenu("Skill Book", s, func(menu *utils.Menu) {
				menu.AddAction("a", "Add", func() bool {
					utils.ExecMenu("Select a skill to add", s, func(menu *utils.Menu) {
						for i, skill := range model.GetAllSkills() {
							sk := skill
							menu.AddActionI(i, skill.GetName(), func() bool {
								s.pc.AddSkill(sk.GetId())
								return true
							})
						}
					})
					return true
				})

				skills := model.GetSkills(s.pc.GetSkills())
				for i, skill := range skills {
					sk := skill
					menu.AddActionI(i, skill.GetName(), func() bool {
						s.WriteLine("Skill: %v", sk.GetName())
						s.WriteLine("  Damage: %v", sk.GetPower())
						return true
					})
				}
			})
		},
	},
	"talk": {
		exec: func(s *Session, arg string) {
Example #15
0
func init() {
	commands = map[string]*command{
		"help": {
			usage: "/help <command name>",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					s.WriteLine("List of commands:")
					var names []string
					for name, command := range commands {
						if command.alias == "" {
							names = append(names, name)
						}
					}
					sort.Strings(names)
					width, height := s.user.GetWindowSize()

					pages := utils.Paginate(names, width, height/2)

					for _, page := range pages {
						s.WriteLine(page)
					}
				} else {
					command, found := commands[arg]
					if found {
						command.Usage(s)
					} else {
						s.printError("Command not found")
					}
				}
			},
		},
		"store": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu("Store", s, func(menu *utils.Menu) {
					store := model.StoreIn(s.pc.GetRoomId())

					if store != nil {
						menu.AddAction("r", "Rename", func() bool {
							name := s.getCleanUserInput("New name: ")
							if name != "" {
								store.SetName("Name")
							}
							return true
						})
						menu.AddAction("d", "Delete", func() bool {
							model.DeleteStore(store.GetId())
							return true
						})
					} else {
						menu.AddAction("n", "New Store", func() bool {
							name := s.getCleanUserInput("Store name: ")
							if name != "" {
								model.CreateStore(name, s.pc.GetRoomId())
							}
							return true
						})
					}
				})
			},
		},
		"loc": cAlias("location"),
		"location": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				s.WriteLine("%v", s.GetRoom().GetLocation())
			},
		},
		"room": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu(
					"Room", s,
					func(menu *utils.Menu) {
						menu.AddAction("t", fmt.Sprintf("Title - %s", s.GetRoom().GetTitle()), func() bool {
							title := s.getRawUserInput("Enter new title: ")
							if title != "" {
								s.GetRoom().SetTitle(title)
							}
							return true
						})

						menu.AddAction("d", "Description", func() bool {
							description := s.getRawUserInput("Enter new description: ")
							if description != "" {
								s.GetRoom().SetDescription(description)
							}
							return true
						})

						menu.AddAction("e", "Exits", func() bool {
							toggleExitMenu(s)
							return true
						})

						areaId := s.GetRoom().GetAreaId()
						areaName := "(None)"
						if areaId != nil {
							area := model.GetArea(areaId)
							areaName = area.GetName()
						}

						menu.AddAction("a", fmt.Sprintf("Area - %s", areaName), func() bool {
							utils.ExecMenu("Change Area", s, func(menu *utils.Menu) {
								menu.AddAction("n", "None", func() bool {
									s.GetRoom().SetAreaId(nil)
									return true
								})

								for i, area := range model.GetAreas(s.currentZone()) {
									actionText := area.GetName()
									if area.GetId() == s.GetRoom().GetAreaId() {
										actionText += "*"
									}

									a := area
									menu.AddActionI(i, actionText, func() bool {
										s.GetRoom().SetAreaId(a.GetId())
										return true
									})
								}
							})
							return true
						})
					})

				s.PrintRoom()
			},
		},
		"map": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				zoneRooms := model.GetRoomsInZone(s.currentZone().GetId())
				roomsByLocation := map[types.Coordinate]types.Room{}

				for _, room := range zoneRooms {
					roomsByLocation[room.GetLocation()] = room
				}

				width, height := s.user.GetWindowSize()
				height /= 2
				width /= 2

				// width and height need to be odd numbers so that we keep the current location centered
				// and we don't go off the edge of the available space
				width += (width % 2) - 1
				height += (height % 2) - 1

				builder := newMapBuilder(width, height, 1)
				builder.setUserRoom(s.GetRoom())
				center := s.GetRoom().GetLocation()

				startX := center.X - (width / 2)
				endX := center.X + (width / 2)
				startY := center.Y - (height / 2)
				endY := center.Y + (height / 2)

				for y := startY; y <= endY; y++ {
					for x := startX; x <= endX; x++ {
						loc := types.Coordinate{X: x, Y: y, Z: center.Z}
						room := roomsByLocation[loc]

						if room != nil {
							// Translate to 0-based coordinates
							builder.addRoom(room, x-startX, y-startY, 0)
						}
					}
				}

				s.WriteLine(utils.TrimEmptyRows(builder.toString()))
			},
		},
		"zone": {
			admin: true,
			usage: "/zone [list|rename <name>|new <name>|delete <name>]",
			exec: func(self *command, s *Session, arg string) {
				subcommand, arg := utils.Argify(arg)
				if subcommand == "" {
					s.WriteLine("Current zone: " + types.Colorize(types.ColorBlue, s.currentZone().GetName()))
				} else if subcommand == "list" {
					s.WriteLineColor(types.ColorBlue, "Zones")
					s.WriteLineColor(types.ColorBlue, "-----")
					for _, zone := range model.GetZones() {
						s.WriteLine(zone.GetName())
					}
				} else if arg != "" {
					if subcommand == "rename" {
						zone := model.GetZoneByName(arg)

						if zone != nil {
							s.printError("A zone with that name already exists")
							return
						}

						s.currentZone().SetName(arg)
					} else if subcommand == "new" {
						newZone, err := model.CreateZone(arg)

						if err != nil {
							s.printError(err.Error())
							return
						}

						newRoom, err := model.CreateRoom(newZone, types.Coordinate{X: 0, Y: 0, Z: 0})
						utils.HandleError(err)

						model.MoveCharacterToRoom(s.pc, newRoom)

						s.PrintRoom()
					} else if subcommand == "delete" {
						zone := model.GetZoneByName(arg)

						if zone != nil {
							if zone == s.currentZone() {
								s.printError("You can't delete the zone you are in")
							} else {
								model.DeleteZone(zone.GetId())
								s.WriteLine("Zone deleted")
							}
						} else {
							s.printError("Zone not found")
						}
					} else {
						self.Usage(s)
					}
				} else {
					self.Usage(s)
				}
			},
		},
		"b": cAlias("broadcast"),
		"broadcast": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					s.printError("Nothing to say")
				} else {
					model.BroadcastMessage(s.pc, arg)
				}
			},
		},
		"s": cAlias("say"),
		"say": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					s.printError("Nothing to say")
				} else {
					model.Say(s.pc, arg)
				}
			},
		},
		"me": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				model.Emote(s.pc, arg)
			},
		},
		"w":    cAlias("whisper"),
		"tell": cAlias("whisper"),
		"whisper": {
			admin: false,
			usage: "/whisper <player> <message>",
			exec:  whisper,
		},
		"tp": cAlias("teleport"),
		"teleport": {
			admin: true,
			usage: "/teleport [<zone>|<X> <Y> <Z>]",
			exec: func(self *command, s *Session, arg string) {
				newZone := model.GetZoneByName(arg)
				var newRoom types.Room

				if newZone != nil {
					if newZone.GetId() == s.GetRoom().GetZoneId() {
						s.WriteLine("You're already in that zone")
					} else {
						zoneRooms := model.GetRoomsInZone(newZone.GetId())
						if len(zoneRooms) > 0 {
							newRoom = zoneRooms[0]
						}
					}
				} else {
					coords, err := utils.Atois(strings.Fields(arg))

					var x, y, z int

					if len(coords) != 3 || err != nil {
						s.printError("Zone not found: %s", arg)
						self.Usage(s)
					} else {
						x, y, z = coords[0], coords[1], coords[2]
					}

					newRoom = model.GetRoomByLocation(types.Coordinate{X: x, Y: y, Z: z}, s.currentZone().GetId())

					if newRoom == nil {
						s.printError("Invalid coordinates")
					}
				}

				if newRoom != nil {
					model.MoveCharacterToRoom(s.pc, newRoom)
					s.PrintRoom()
				}
			},
		},
		"who": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				chars := model.GetOnlinePlayerCharacters()

				s.WriteLine("")
				s.WriteLine("Online Players")
				s.WriteLine("--------------")

				for _, char := range chars {
					s.WriteLine(char.GetName())
				}
				s.WriteLine("")
			},
		},
		"colors": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				s.WriteLineColor(types.ColorNormal, "Normal")
				s.WriteLineColor(types.ColorRed, "Red")
				s.WriteLineColor(types.ColorDarkRed, "Dark Red")
				s.WriteLineColor(types.ColorGreen, "Green")
				s.WriteLineColor(types.ColorDarkGreen, "Dark Green")
				s.WriteLineColor(types.ColorBlue, "Blue")
				s.WriteLineColor(types.ColorDarkBlue, "Dark Blue")
				s.WriteLineColor(types.ColorYellow, "Yellow")
				s.WriteLineColor(types.ColorDarkYellow, "Dark Yellow")
				s.WriteLineColor(types.ColorMagenta, "Magenta")
				s.WriteLineColor(types.ColorDarkMagenta, "Dark Magenta")
				s.WriteLineColor(types.ColorCyan, "Cyan")
				s.WriteLineColor(types.ColorDarkCyan, "Dark Cyan")
				s.WriteLineColor(types.ColorBlack, "Black")
				s.WriteLineColor(types.ColorWhite, "White")
				s.WriteLineColor(types.ColorGray, "Gray")
			},
		},
		"cm": cAlias("colormode"),
		"colormode": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					message := "Current color mode is: "
					switch s.user.GetColorMode() {
					case types.ColorModeNone:
						message = message + "None"
					case types.ColorModeLight:
						message = message + "Light"
					case types.ColorModeDark:
						message = message + "Dark"
					}
					s.WriteLine(message)
				} else {
					switch strings.ToLower(arg) {
					case "none":
						s.user.SetColorMode(types.ColorModeNone)
						s.WriteLine("Color mode set to: None")
					case "light":
						s.user.SetColorMode(types.ColorModeLight)
						s.WriteLine("Color mode set to: Light")
					case "dark":
						s.user.SetColorMode(types.ColorModeDark)
						s.WriteLine("Color mode set to: Dark")
					default:
						s.WriteLine("Valid color modes are: None, Light, Dark")
					}
				}
			},
		},
		"dr": cAlias("destroyroom"),
		"destroyroom": {
			admin: true,
			usage: "/destroyroom <direction>",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					self.Usage(s)
				} else {
					direction := types.StringToDirection(arg)

					if direction == types.DirectionNone {
						s.printError("Not a valid direction")
					} else {
						loc := s.GetRoom().NextLocation(direction)
						roomToDelete := model.GetRoomByLocation(loc, s.GetRoom().GetZoneId())
						if roomToDelete != nil {
							model.DeleteRoom(roomToDelete)
							s.WriteLine("Room destroyed")
						} else {
							s.printError("No room in that direction")
						}
					}
				}
			},
		},
		"npc": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {

				utils.ExecMenu("NPCs", s, func(menu *utils.Menu) {
					var npcs types.NPCList
					npcs = model.GetNpcs()

					menu.AddAction("n", "New", func() bool {
						name := getNpcName(s)
						if name != "" {
							model.CreateNpc(name, s.pc.GetRoomId(), nil)
						}
						return true
					})

					for i, npc := range npcs {
						n := npc
						menu.AddActionI(i, npc.GetName(), func() bool {
							specificNpcMenu(s, n)
							return true
						})
					}
				})

				s.PrintRoom()
			},
		},
		"items": {
			admin: true,
			usage: "Usage: /items",
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu("Items", s, func(menu *utils.Menu) {
					menu.AddAction("n", "New", func() bool {
						name := s.getRawUserInput("Item name: ")
						if name != "" {
							template := model.CreateTemplate(name)
							templateMenu(s, template)
						}
						return true
					})

					for i, template := range model.GetAllTemplates() {
						t := template
						menu.AddActionI(i, template.GetName(), func() bool {
							templateMenu(s, t)
							return true
						})
					}
				})
			},
		},
		"destroyitem": {
			admin: true,
			usage: "/destroyitem <item name>",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					self.Usage(s)
					return
				} else {
					itemsInRoom := model.ItemsIn(s.GetRoom().GetId())
					name := strings.ToLower(arg)

					for _, item := range itemsInRoom {
						if strings.ToLower(item.GetName()) == name {
							model.DeleteItem(item.GetId())
							s.WriteLine("Item destroyed")
							return
						}
					}

					s.printError("Item not found")
				}
			},
		},
		"roomid": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				s.WriteLine("Room ID: %v", s.GetRoom().GetId())
			},
		},
		"cash": {
			admin: true,
			usage: "/cash give <amount>",
			exec: func(self *command, s *Session, arg string) {
				subcommand, arg := utils.Argify(arg)

				if subcommand == "give" {
					amount, err := utils.Atoir(arg, 1, math.MaxInt32)
					if err == nil {
						s.pc.AddCash(amount)
						s.WriteLine("Received: %v monies", amount)
					} else {
						s.printError(err.Error())
						self.Usage(s)
					}
				} else {
					self.Usage(s)
				}
			},
		},
		"ws": cAlias("windowsize"),
		"windowsize": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				width, height := s.user.GetWindowSize()

				header := fmt.Sprintf("Width: %v, Height: %v", width, height)

				topBar := header + " " + strings.Repeat("-", int(width)-2-len(header)) + "+"
				bottomBar := "+" + strings.Repeat("-", int(width)-2) + "+"
				outline := "|" + strings.Repeat(" ", int(width)-2) + "|"

				s.WriteLine(topBar)

				for i := 0; i < int(height)-3; i++ {
					s.WriteLine(outline)
				}

				s.WriteLine(bottomBar)
			},
		},
		"tt": cAlias("terminaltype"),
		"terminaltype": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				s.WriteLine("Terminal type: %s", s.user.GetTerminalType())
			},
		},
		"silent": {
			admin: false,
			usage: "/silent [on|off]",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					s.silentMode = !s.silentMode
				} else if arg == "on" {
					s.silentMode = true
				} else if arg == "off" {
					s.silentMode = false
				} else {
					self.Usage(s)
				}

				if s.silentMode {
					s.WriteLine("Silent mode on")
				} else {
					s.WriteLine("Silent mode off")
				}
			},
		},
		"r": cAlias("reply"),
		"reply": {
			admin: false,
			exec: func(self *command, s *Session, arg string) {
				targetChar := model.GetPlayerCharacter(s.replyId)

				if targetChar == nil {
					s.asyncMessage("No one to reply to")
				} else if arg == "" {
					prompt := "Reply to " + targetChar.GetName() + ": "
					input := s.getRawUserInput(prompt)

					if input != "" {
						newArg := fmt.Sprintf("%s %s", targetChar.GetName(), input)
						whisper(commands["whisper"], s, newArg)
					}
				} else {
					newArg := fmt.Sprintf("%s %s", targetChar.GetName(), arg)
					whisper(commands["whisper"], s, newArg)
				}
			},
		},
		"area": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu("Areas", s, func(menu *utils.Menu) {
					menu.AddAction("n", "New", func() bool {
						name := s.getRawUserInput("Area name: ")
						if name != "" {
							model.CreateArea(name, s.currentZone())
						}
						return true
					})

					for i, area := range model.GetAreas(s.currentZone()) {
						a := area
						menu.AddActionI(i, area.GetName(), func() bool {
							specificAreaMenu(s, a)
							return true
						})
					}
				})
			},
		},
		"link": {
			admin: true,
			usage: "Usage: /link <name> [single|double*] to start, /link to finish, /link remove <name> [single|double*], /link rename <old name> <new name>, /link cancel",
			exec: func(self *command, s *Session, arg string) {
				args := strings.Split(arg, " ")
				StateName := "Linking"

				linkName, linking := s.states[StateName]

				if linking {
					if len(args) == 1 && args[0] == "cancel" {
						linkData.source = nil
						delete(s.states, StateName)
					} else if len(args) != 0 {
						self.Usage(s)
					} else {
						sourceRoom := model.GetRoom(linkData.source)

						sourceRoom.SetLink(linkName, s.pc.GetRoomId())
						if linkData.mode == LinkDouble {
							s.GetRoom().SetLink(linkName, linkData.source)
						}

						linkData.source = nil
						delete(s.states, StateName)

						s.PrintRoom()
					}
				} else {
					if len(args) == 0 {
						self.Usage(s)
						return
					}

					if args[0] == "remove" {
						mode := "double"
						if len(args) == 3 {
							if args[2] == "single" || args[2] == "double" {
								mode = args[2]
							} else {
								self.Usage(s)
								return
							}
						}

						if len(args) != 2 {
							self.Usage(s)
							return
						}

						linkNames := s.GetRoom().LinkNames()
						index := utils.BestMatch(args[1], linkNames)

						if index == -2 {
							s.printError("Which one do you mean?")
						} else if index == -1 {
							s.printError("Link not found")
						} else {
							linkName := linkNames[index]

							if mode == "double" {
								links := s.GetRoom().GetLinks()
								linkedRoom := model.GetRoom(links[linkName])
								linkedRoom.RemoveLink(linkName)
							}

							s.GetRoom().RemoveLink(linkName)
							s.PrintRoom()
						}
					} else if args[0] == "rename" {
						// TODO
					} else {
						if len(args) == 2 {
							if args[1] == LinkSingle || args[1] == LinkDouble {
								linkData.mode = args[1]
							} else {
								self.Usage(s)
								return
							}
						} else {
							linkData.mode = LinkDouble
						}

						// New link
						s.states[StateName] = utils.FormatName(args[0])
						linkData.source = s.pc.GetRoomId()
					}
				}
			},
		},
		"kill": {
			admin: true,
			usage: "/kill [npc name]",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					self.Usage(s)
				} else {
					npcs := model.NpcsIn(s.pc.GetRoomId())
					index := utils.BestMatch(arg, npcs.Characters().Names())

					if index == -1 {
						s.printError("Not found")
					} else if index == -2 {
						s.printError("Which one do you mean?")
					} else {
						npc := npcs[index]
						combat.Kill(npc)
						s.WriteLine("Killed %s", npc.GetName())
					}
				}
			},
		},
		"inspect": {
			admin: true,
			usage: "/inspect [name]",
			exec: func(self *command, s *Session, arg string) {
				if arg == "" {
					self.Usage(s)
				} else {
					characters := model.CharactersIn(s.pc.GetRoomId())
					index := utils.BestMatch(arg, characters.Names())

					if index == -1 {
						s.printError("Not found")
					} else if index == -2 {
						s.printError("Which one do you mean?")
					} else {
						char := characters[index]

						s.WriteLine(char.GetName())
						s.WriteLine("Health: %v/%v", char.GetHitPoints(), char.GetHealth())
					}
				}
			},
		},
		"skills": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu("Skills", s, func(menu *utils.Menu) {
					menu.AddAction("n", "New", func() bool {
						for {
							name := s.getCleanUserInput("Skill name: ")

							if name == "" {
								break
							}

							skill := model.GetSkillByName(name)

							if skill != nil {
								s.printError("A skill with that name already exists")
							} else {
								model.CreateSkill(name)
								break
							}
						}
						return true
					})

					skills := model.GetAllSkills()
					for i, skill := range skills {
						sk := skill
						menu.AddActionI(i, skill.GetName(), func() bool {
							specificSkillMenu(s, sk)
							return true
						})
					}
				})
			},
		},
		"testmenu": {
			admin: true,
			exec: func(self *command, s *Session, arg string) {
				utils.ExecMenu("Menu Test", s, func(menu *utils.Menu) {
					for i := 0; i < 500; i++ {
						menu.AddActionI(i, "Test Item", func() bool {
							return false
						})
					}
				})
			},
		},
		"path": {
			admin: true,
			usage: "/path <coordinates>",
			exec: func(self *command, s *Session, arg string) {
				coords, err := utils.Atois(strings.Fields(arg))
				if err == nil {
					if len(coords) == 2 || len(coords) == 3 {
						x, y := coords[0], coords[1]

						z := s.GetRoom().GetLocation().Z
						if len(coords) == 3 {
							z = coords[2]
						}

						room := model.GetRoomByLocation(types.Coordinate{X: x, Y: y, Z: z}, s.GetRoom().GetZoneId())
						if room != nil {
							path := engine.FindPath(s.GetRoom(), room)
							/*
								s.WriteLine("Path:")
								for _, room := range path {
									s.WriteLine(fmt.Sprintf("%v", room.GetLocation()))
								}
							*/
							if len(path) > 0 {
								for _, room := range path {
									time.Sleep(200 * time.Millisecond)
									model.MoveCharacterToRoom(s.pc, room)
									s.PrintRoom()
									s.handleCommand("map", "")
								}
							} else {
								s.printError("No path found")
							}
						} else {
							s.printError("No room found at the given coordinates")
						}
					} else {
						self.Usage(s)
					}
				} else {
					self.Usage(s)
				}
			},
		},
		"time": {
			admin: false,
			usage: "/time",
			exec: func(self *command, s *Session, arg string) {
				s.WriteLine("%v", model.GetWorld().GetTime())
			},
		},
		"join": {
			admin: true,
			usage: "/join <player name>",
			exec: func(self *command, s *Session, arg string) {
				target := model.GetCharacterByName(arg)
				if target == nil {
					s.printError("Target not found")
				} else {
					model.MoveCharacterToRoom(s.pc, model.GetRoom(target.GetRoomId()))
					s.PrintRoom()
				}
			},
		},
		"bring": {
			admin: true,
			usage: "/bring <player name>",
			exec: func(self *command, s *Session, arg string) {
				// TODO - The target receives no indication that they've been moved
				target := model.GetCharacterByName(arg)
				if target == nil {
					s.printError("Target not found")
				} else {
					model.MoveCharacterToRoom(target, s.GetRoom())
				}
			},
		},
	}
}