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