public void Start() { if (Running) throw new InvalidOperationException("Server already started."); Running = true; Client = new UdpClient(Port); Output.Write("Generating world... "); World = GameWorld.Generate(); Output.WriteLine("Done."); Output.Write("Starting command engine... "); List<Command> commands = new List<Command>(); commands.Add(new CommandHelp(World, null, commands, null)); commands.Add(new CommandSay(World, null, String.Empty)); commands.Add(new CommandStatus(World, null, null)); commands.Add(new CommandLook(World, null, null)); commands.Add(new CommandMove(World, null, null)); commands.Add(new CommandInventory(World, null, null)); commands.Add(new CommandTake(World, null, null)); commands.Add(new CommandDrop(World, null, null)); commands.Add(new CommandEquip(World, null, null)); commands.Add(new CommandUnequip(World, null, null)); commands.Add(new CommandUse(World, null, null)); commands.Add(new CommandEat(World, null, null)); commands.Add(new CommandAttack(World, null, null)); commands.Add(new CommandTruce(World, null)); commands.Add(new CommandLoot(World, null, null)); commands.Add(new CommandDie(World, null)); commands.Add(new CommandQuit(World, null)); CommandParser parser = new CommandParser(commands); CommandEngine = new CommandEngine(parser); RantEngine.RunPattern(""); // Run a blank pattern to initialize the rant engine. // This avoids a discernible delay during gameplay if the engine is initialized later. Output.WriteLine("Done."); LastUpdate = DateTime.Now; Task updateTask = new Task(BeginUpdate); updateTask.Start(); Task broadcastTask = new Task(Broadcast); broadcastTask.Start(); Task listenTask = new Task(Listen); listenTask.Start(); Output.WriteLine("Listening on port {0}...", Port); while (Running) { Output.Write(">"); CommandEngine.RunCommand(Console.ReadLine(), this); } }
public CommandEngine(CommandParser parser) { Parser = parser; }