MudGame:
- Create command script now writes to the Log file everytime a Admin creates an environment object. - Added a List command script that now lists all environment objects created. * Example: List Realms This will list all of the Realms in the game world. * Example: List MyRealm>Zones This will list all of the Zones within the MyRealm Realm object. * Example: List MyRealm>Rooms This will list all of the Rooms from every Zone within the MyRealm object. * Example: List MyRealm>MyZone>Rooms This will list all of the Rooms that are within the MyZone object contained within the MyRealm object. * Example: List Players This will list all created players, regardless if they are logged into the server or not.
This commit is contained in:
parent
de38cbf272
commit
5956c3d264
3 changed files with 149 additions and 0 deletions
142
MudEngine/Commands/CommandList.cs
Normal file
142
MudEngine/Commands/CommandList.cs
Normal file
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.GameObjects.Characters;
|
||||
using MudEngine.GameManagement;
|
||||
using MudEngine.Commands;
|
||||
using MudEngine.GameObjects.Environment;
|
||||
|
||||
namespace MudEngine.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// The List command is used to list filenames of a specified object type.
|
||||
/// </summary>
|
||||
public class CommandList : IGameCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by the Command Engine to allow for overriding any other commands that contain the same name.
|
||||
/// TODO: Does Overriding Commands still work? This is part of some old code I wrote several years back and might be broke.
|
||||
/// </summary>
|
||||
public Boolean Override { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the command.
|
||||
/// If Override is set to true, this command will override any other command that contains the same name.
|
||||
/// </summary>
|
||||
public String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A collection of strings that contains helpfull information for this Command.
|
||||
/// When the user enteres 'Help Exit' the game will print the content of this collection.
|
||||
/// This is treated like a virtual book, each entry in the collection is printed as a new line.
|
||||
/// </summary>
|
||||
public List<String> Help { get; set; }
|
||||
|
||||
public CommandList()
|
||||
{
|
||||
Help = new List<string>();
|
||||
Help.Add("Using the List command, you can view a generated list of filenames that pertain to a supplied object type.");
|
||||
Help.Add("Usage: List 'ItemType'");
|
||||
Help.Add(" Example: List Realms");
|
||||
Help.Add("This will list all of the Realms by Filename for you to review.");
|
||||
Help.Add("To view child objects of a Type, use the '>' separator.");
|
||||
Help.Add(" Example: List MyRealmName>Zones");
|
||||
}
|
||||
|
||||
public void Execute(String command, BaseCharacter player)
|
||||
{
|
||||
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
|
||||
{
|
||||
//Player must be a admin or GM to view all the objects on the server like this.
|
||||
|
||||
command = command.Substring("List".Length).Trim();
|
||||
String[] data = command.ToLower().Split('>');
|
||||
|
||||
if ((data.Length == 0) || (String.IsNullOrEmpty(data[0])))
|
||||
{
|
||||
player.Send("Invalid command usage. Enter 'help List' for usage examples.");
|
||||
return;
|
||||
}
|
||||
else if (data.Length == 1)
|
||||
{
|
||||
switch (data[0])
|
||||
{
|
||||
case "realms":
|
||||
player.Send("Currently loaded Realm files:");
|
||||
foreach (Realm r in player.ActiveGame.World.RealmCollection)
|
||||
player.Send(r.Filename + " | ", false);
|
||||
break;
|
||||
case "players":
|
||||
player.Send("Players with created characters:");
|
||||
BaseCharacter p = new BaseCharacter(player.ActiveGame);
|
||||
foreach (String file in Directory.GetFiles(player.ActiveGame.DataPaths.Players, "*.character"))
|
||||
{
|
||||
p.Load(file);
|
||||
player.Send(p.Name + " | ", false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
player.Send("Invalid token supplied. Enter 'Help List' for usage examples.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (data.Length == 2)
|
||||
{
|
||||
if (data[1] == "zones")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Zones.");
|
||||
return;
|
||||
}
|
||||
player.Send("Displaying Currently loaded Zones within Realm " + data[0]);
|
||||
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
|
||||
player.Send(z.Filename + " | ", false);
|
||||
}
|
||||
else if (data[1] == "rooms")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Send("Displaying currently loaded Rooms within Realm " + data[0] + ". These Rooms span multiple Zones.");
|
||||
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
|
||||
{
|
||||
foreach (Room r in z.RoomCollection)
|
||||
{
|
||||
player.Send(Path.GetFileNameWithoutExtension(z.Filename) + ">" + Path.GetFileNameWithoutExtension(r.Filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data.Length == 3)
|
||||
{
|
||||
if (data[2] == "rooms")
|
||||
{
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
|
||||
{
|
||||
player.Send("Invalid Realm, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0] == null)
|
||||
{
|
||||
player.Send("Invalid Zone, unable to list Rooms.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.Send("Displaying Currently loaded Rooms within " + data[0] + ">" + data[1]);
|
||||
foreach (Room r in player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0].RoomCollection)
|
||||
player.Send(r.Filename + " | ", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,7 @@
|
|||
<Compile Include="Commands\CommandRestart.cs" />
|
||||
<Compile Include="Commands\CommandLogin.cs" />
|
||||
<Compile Include="Commands\CommandSaveWorld.cs" />
|
||||
<Compile Include="Commands\CommandList.cs" />
|
||||
<Compile Include="FileSystem\SaveDataPaths.cs" />
|
||||
<Compile Include="GameManagement\CommandEngine.cs" />
|
||||
<Compile Include="GameManagement\GameTime.cs" />
|
||||
|
|
|
@ -82,6 +82,7 @@ public class CommandCreate : IGameCommand
|
|||
if (validRealm)
|
||||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
player.Send(env[0] + " created.");
|
||||
}
|
||||
//Add the 'realm' Field that was instanced via ValidateRealm
|
||||
|
@ -105,6 +106,7 @@ public class CommandCreate : IGameCommand
|
|||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
player.Send(env[0] + " created.");
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
}
|
||||
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||
|
||||
|
@ -112,6 +114,7 @@ public class CommandCreate : IGameCommand
|
|||
{
|
||||
realm.AddZone(zone);
|
||||
player.Send(env[1] + " created.");
|
||||
Log.Write(player.Name + " created a Zone called " + zone.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,6 +134,7 @@ public class CommandCreate : IGameCommand
|
|||
{
|
||||
player.ActiveGame.World.AddRealm(realm);
|
||||
player.Send(env[0] + " created.");
|
||||
Log.Write(player.Name + " created a Realm called " + realm.Filename);
|
||||
}
|
||||
|
||||
Boolean validZone = ValidateZone(env[0], env[1], player);
|
||||
|
@ -139,6 +143,7 @@ public class CommandCreate : IGameCommand
|
|||
{
|
||||
realm.AddZone(zone);
|
||||
player.Send(env[1] + " created.");
|
||||
Log.Write(player.Name + " created a Zone called " + zone.Filename);
|
||||
}
|
||||
|
||||
Boolean validRoom = ValidateRoom(env[0], env[1], env[2], player);
|
||||
|
@ -147,6 +152,7 @@ public class CommandCreate : IGameCommand
|
|||
{
|
||||
zone.AddRoom(room);
|
||||
player.Send(env[2] + " created.");
|
||||
Log.Write(player.Name + " created a Room called " + room.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue