Added improved logging through the engine for the server console.
This commit is contained in:
parent
43e93706ab
commit
bcd9f46b0a
10 changed files with 115 additions and 27 deletions
|
@ -143,9 +143,9 @@ namespace MudEngine.Core
|
|||
/// Loads all of the commands found within the assembly specified.
|
||||
/// </summary>
|
||||
/// <param name="commandLibrary"></param>
|
||||
public static void LoadCommandLibrary(Assembly commandLibrary)
|
||||
public static ICommand[] LoadCommandLibrary(Assembly commandLibrary)
|
||||
{
|
||||
LoadCommandLibrary(commandLibrary, true);
|
||||
return LoadCommandLibrary(commandLibrary, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -155,14 +155,20 @@ namespace MudEngine.Core
|
|||
/// </summary>
|
||||
/// <param name="commandLibrary"></param>
|
||||
/// <param name="purgeLoadedCommands"></param>
|
||||
public static void LoadCommandLibrary(Assembly commandLibrary, bool purgeLoadedCommands)
|
||||
public static ICommand[] LoadCommandLibrary(Assembly commandLibrary, bool purgeLoadedCommands)
|
||||
{
|
||||
//Check if we need to purge all of the commands.
|
||||
if (purgeLoadedCommands)
|
||||
PurgeCommands();
|
||||
|
||||
if (commandLibrary == null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
//Custom commands are temporarily stored here.
|
||||
//Since Commands are stored in the general Command collection
|
||||
//that can contain internal commands as well, we want to
|
||||
//return only what we just loaded.
|
||||
List<ICommand> commandsFound = new List<ICommand>();
|
||||
|
||||
//Loop through each Type in the assembly provided.
|
||||
foreach (Type type in commandLibrary.GetTypes())
|
||||
|
@ -192,8 +198,14 @@ namespace MudEngine.Core
|
|||
|
||||
//Everything checks out ok. Add the command to our collection.
|
||||
Commands.Add(cmd.Name, cmd);
|
||||
commandsFound.Add(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
if (commandsFound.Count > 0)
|
||||
return commandsFound.ToArray();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -49,7 +49,8 @@ namespace MudEngine.Core
|
|||
System.IO.File.Delete(LogFilename);
|
||||
|
||||
//Clear the cache.
|
||||
_Messages.Clear();
|
||||
if (_Messages != null)
|
||||
_Messages.Clear();
|
||||
}
|
||||
|
||||
public static void WriteLine(String message, Importance importance)
|
||||
|
|
|
@ -12,6 +12,7 @@ using MudEngine.Game.Characters;
|
|||
using MudEngine.DAL;
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.Scripting;
|
||||
using MudEngine.Core.Interfaces;
|
||||
|
||||
namespace MudEngine.Game
|
||||
{
|
||||
|
@ -105,7 +106,6 @@ namespace MudEngine.Game
|
|||
/// <param name="port"></param>
|
||||
public StandardGame(String name, Int32 port)
|
||||
{
|
||||
Logger.WriteLine("Initializing Mud Game");
|
||||
this.Name = name;
|
||||
this.Website = "http://scionwest.net";
|
||||
this.Description = "A sample Mud game created using the Mud Designer kit.";
|
||||
|
@ -118,19 +118,27 @@ namespace MudEngine.Game
|
|||
this.Server = new Server(this, port);
|
||||
|
||||
//Setup default save paths.
|
||||
DataPaths paths = new DataPaths();
|
||||
|
||||
this.SavePaths = paths;
|
||||
this.SavePaths = new DataPaths();
|
||||
|
||||
SetupPaths();
|
||||
|
||||
this.World = new World(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a script compiler and scans for custom scripts that
|
||||
/// inherit StandardGame and then returns them. This provides
|
||||
/// support for custom Game rules via Script.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StandardGame Initialize()
|
||||
{
|
||||
//Instance a new compiler
|
||||
CompileEngine compiler = new CompileEngine();
|
||||
Logger.WriteLine("Checking for custom Game scripts.");
|
||||
|
||||
compiler.AddAssemblyReference(Path.Combine(this.SavePaths.GetPath(DataTypes.Root), Assembly.GetExecutingAssembly().Location));
|
||||
|
||||
Boolean result = compiler.Compile(this.SavePaths.GetPath(DataTypes.Scripts));
|
||||
|
||||
if (result)
|
||||
|
@ -139,11 +147,18 @@ namespace MudEngine.Game
|
|||
StandardGame game = (StandardGame)factory.FindInheritedScripted("StandardGame", "Mud Game");
|
||||
|
||||
if (game == null)
|
||||
{
|
||||
Logger.WriteLine("No custom Game rules located. Defaulting to Standard setup.");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.WriteLine("Located " + game.GetType().Name + " ruleset.");
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
Logger.WriteLine("Failed to perform startup compilation! " + compiler.Errors);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
@ -158,13 +173,15 @@ namespace MudEngine.Game
|
|||
public virtual Boolean Start(Int32 maxPlayers, Int32 maxQueueSize)
|
||||
{
|
||||
Logger.WriteLine("Starting up " + this.Name);
|
||||
|
||||
|
||||
//Instance Script Engine
|
||||
Logger.WriteLine("Preparing script engine...");
|
||||
CompileEngine compiler = new CompileEngine("cs");
|
||||
//compiler.AddAssemblyReference(Assembly.GetExecutingAssembly().FullName);
|
||||
compiler.AddAssemblyReference(Path.Combine(this.SavePaths.GetPath(DataTypes.Root), Assembly.GetExecutingAssembly().Location));
|
||||
|
||||
//Compile any scripts
|
||||
Logger.WriteLine("Compiling game scripts.");
|
||||
Boolean result = compiler.Compile(this.SavePaths.GetPath(DataTypes.Scripts));
|
||||
if (!result)
|
||||
{
|
||||
|
@ -175,12 +192,32 @@ namespace MudEngine.Game
|
|||
}
|
||||
else
|
||||
{
|
||||
Logger.WriteLine("Compilation completed.");
|
||||
this.ScriptFactory = new ScriptFactory(compiler.CompiledAssembly);
|
||||
}
|
||||
|
||||
//Load the default engine Commands
|
||||
Logger.WriteLine("Loading internal game commands.");
|
||||
CommandSystem.LoadCommands();
|
||||
CommandSystem.LoadCommandLibrary(this.ScriptFactory.Assembly, false);
|
||||
if (CommandSystem.Commands.Count > 0)
|
||||
{
|
||||
foreach (ICommand command in CommandSystem.Commands.Values)
|
||||
Logger.WriteLine("Loaded Command: " + command.Name);
|
||||
}
|
||||
else
|
||||
Logger.WriteLine("No internal game commands located.");
|
||||
|
||||
Logger.WriteLine("Loading scripted game commands.");
|
||||
ICommand[] commands = CommandSystem.LoadCommandLibrary(this.ScriptFactory.Assembly, false);
|
||||
if (commands.Length > 0)
|
||||
{
|
||||
foreach (ICommand command in commands)
|
||||
{
|
||||
Logger.WriteLine("Loaded Command: " + command.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
Logger.WriteLine("No scripted game commands located.");
|
||||
|
||||
//Load World
|
||||
this.World.Initialize();
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Text;
|
|||
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Core;
|
||||
|
||||
namespace MudEngine.Game
|
||||
{
|
||||
|
@ -28,15 +29,22 @@ namespace MudEngine.Game
|
|||
|
||||
public void Initialize()
|
||||
{
|
||||
Logger.WriteLine("Initializing game world...");
|
||||
Realm realm = new Realm(this.Game, "Azeroth", "");
|
||||
realm.Initialize();
|
||||
|
||||
//Zone initialize method is called by Realm.
|
||||
Zone zone = realm.CreateZone("Bablo", "");
|
||||
|
||||
//Room initialize method is called by Zone
|
||||
zone.CreateRoom("Bedroom", "");
|
||||
zone.CreateRoom("Hallway", "");
|
||||
|
||||
zone.LinkRooms("Bedroom", "Hallway", AvailableTravelDirections.East);
|
||||
|
||||
this.StartLocation = zone.GetRoom("Bedroom");
|
||||
|
||||
Logger.WriteLine("Initialization completed.");
|
||||
}
|
||||
|
||||
public void Save()
|
||||
|
@ -45,6 +53,7 @@ namespace MudEngine.Game
|
|||
|
||||
public void Load()
|
||||
{
|
||||
Logger.WriteLine("World Loading has not been implemented as of yet!");
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
|
|||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
using MudEngine.Core;
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
|
@ -43,7 +44,7 @@ namespace MudEngine.GameScripts.Commands
|
|||
|
||||
//Don't allow anything other than the Login command to start the
|
||||
//character creation process.
|
||||
if (callingType != "CommandLogin")
|
||||
if (callingType != "Login")
|
||||
{
|
||||
character.SendMessage("Invalid Command Used.");
|
||||
return false;
|
||||
|
@ -80,11 +81,19 @@ namespace MudEngine.GameScripts.Commands
|
|||
}
|
||||
}
|
||||
|
||||
character.Move(game.World.StartLocation);
|
||||
try
|
||||
{
|
||||
|
||||
//TODO: Create a class and setup Stats.
|
||||
character.Save(character.Filename, false);
|
||||
character.Move(game.World.StartLocation);
|
||||
|
||||
//TODO: Create a class and setup Stats.
|
||||
character.Save(character.Filename, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine(ex.Message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace MudEngine.GameScripts.Commands
|
|||
names.Add(match.Value.ToLower());
|
||||
}
|
||||
|
||||
if (names.Count < 1)
|
||||
if (names.Count < 1 && character.Role == CharacterRoles.Admin)
|
||||
{
|
||||
character.SendMessage("You must provide a target character name.");
|
||||
ShowHelp(character);
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace MudEngine.Networking
|
|||
|
||||
public void Start(Int32 maxConnections, Int32 maxQueueSize)
|
||||
{
|
||||
Logger.WriteLine("Game Server System Starting...");
|
||||
if (this.Status != ServerStatus.Stopped)
|
||||
return;
|
||||
|
||||
|
@ -78,10 +79,14 @@ namespace MudEngine.Networking
|
|||
|
||||
this._ServerThread = new Thread(ServerLoop);
|
||||
this._ServerThread.Start();
|
||||
|
||||
Logger.WriteLine("Server status: Running");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.WriteLine("Failed to star the Engines Networking Server!");
|
||||
this.Status = ServerStatus.Stopped;
|
||||
Logger.WriteLine("Server status: Stopped");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ using System.IO;
|
|||
using Microsoft.CSharp;
|
||||
#endif
|
||||
|
||||
using MudEngine.Core;
|
||||
|
||||
namespace MudEngine.Scripting
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -51,14 +53,18 @@ namespace MudEngine.Scripting
|
|||
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||
|
||||
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||
|
||||
//if the compiler has errors, return false.
|
||||
if (Results.Errors.HasErrors)
|
||||
return false;
|
||||
if (scripts.Length > 0)
|
||||
{
|
||||
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||
//if the compiler has errors, return false.
|
||||
if (Results.Errors.HasErrors)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -7,6 +7,9 @@ using System.Text;
|
|||
#if WINDOWS_PC
|
||||
using Microsoft.CSharp;
|
||||
#endif
|
||||
|
||||
using MudEngine.Core;
|
||||
|
||||
namespace MudEngine.Scripting
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -170,7 +173,7 @@ namespace MudEngine.Scripting
|
|||
this._CompileMessages = new string[] { "Compilation Failed.", "Unable to locate the specified compiler of Type '" + Compiler + "'." };
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Get the compiler parameters.
|
||||
CompilerParameters param = GetParameters();
|
||||
|
||||
|
@ -407,7 +410,6 @@ namespace MudEngine.Scripting
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return compiler;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue