- Removed External Script compilation support for now. I'll add it back once I provide SourceFile and SourceCode compiling support to the MudScriptCompiler. At the moment only Whole Directory compiling is supported. MudDesigner: - Removed all of the source code, with the exception of the designer generated source, from frmProjectManager. It will need to be re-wrote due to the removal of the MudScriptEngine. MudEngine: - Deleted Scripting.GameObject - Deleted Scripting.GameObjectCollection - Deleted Scripting.ScriptEngine - Deleted classes were replaced by the rScript engine. Only class needed now is the MudScriptCompiler, which handles all of the custom MudEngine script compiling, using the rScript Engine. - Removed old Scripting.ScriptEngine references from within GameManagement.Game - GameManagement.Game no longer checks to see if MudEngine.dll exists. If it didn't exist, the engine wouldn't be running to perform that check in the first place. - GameManagement.Game no longer adds MudEngine.dll as a referenced assembly. The MudScriptCompiler handles that during compilation. - MudScriptCompiler.Compile() always returns false when SourceFile or SourceCode is passed as an argument. Only Script Directories can be compiled at this time. MudGame: - Removed references to Scripting.ScriptEngine from MudGame.Program - Re-wrote how scripted Type's that inherit and replace MudEngine.GameManagement.Game. Scripts are compiled prior to Game.Start() being invoked, allowing GameManagement.Game to be replaced with an inherited class from a compiled script. TODO: Look at a way to prevent Game.Start() from compiling the scripts again, as they have already been compiled once. It's not a big hit on startup time, but it needs to be wrote the proper way.
127 lines
No EOL
4.9 KiB
C#
127 lines
No EOL
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
|
|
using MudEngine.FileSystem;
|
|
using MudEngine.GameManagement;
|
|
using MudEngine.GameObjects.Characters;
|
|
using MudEngine.Scripting;
|
|
|
|
namespace MudGame
|
|
{
|
|
static class Program
|
|
{
|
|
const String SettingsFile = "Settings.ini";
|
|
|
|
static void Main(String[] args)
|
|
{
|
|
Game game = new Game();
|
|
|
|
//Re-create the settings file if it is missing. Don't push any log messages until we know that this is
|
|
//verbose or not
|
|
Log.Write("Loading Settings...", false);
|
|
if (!File.Exists(SettingsFile))
|
|
{
|
|
Log.Write("Settings.ini missing!", false);
|
|
FileManager.WriteLine(SettingsFile, "Scripts", "ScriptPath");
|
|
FileManager.WriteLine(SettingsFile, ".cs", "ScriptExtension");
|
|
FileManager.WriteLine(SettingsFile, "True", "ServerEnabled");
|
|
Log.Write("Settings.ini re-created with default values", false);
|
|
}
|
|
|
|
if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "false")
|
|
Log.IsVerbose = true;
|
|
else if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "")
|
|
Log.IsVerbose = false;
|
|
else
|
|
Log.IsVerbose = false;
|
|
|
|
//Get are cached log messages and go forward from here.
|
|
Console.Write(Log.GetMessages());
|
|
Log.FlushMessages();
|
|
|
|
Log.Write("Launching...", true);
|
|
|
|
//Search for a custom Game Type before we launch our game.
|
|
//Compile the scripts
|
|
rScripting.CompileEngine compiler = new rScripting.CompileEngine(".cs");
|
|
compiler.Compiler = "MudScriptCompiler";
|
|
if (!compiler.Compile("Scripts"))
|
|
{
|
|
Log.Write("Failed compiling script files.");
|
|
Log.Write(compiler.Errors);
|
|
}
|
|
|
|
//If there were errors during compilation, then skip the custom scripts and use the default Game Type.
|
|
if (!compiler.HasErrors)
|
|
{
|
|
//Search the scripts for a Type inheriting from Game
|
|
rScripting.LateBinding.ScriptFactory factory = new rScripting.LateBinding.ScriptFactory(compiler.CompiledAssembly);
|
|
foreach (Type t in compiler.CompiledAssembly.GetTypes())
|
|
{
|
|
if (t.BaseType.Name == "Game")
|
|
{
|
|
rScripting.LateBinding.ScriptObject obj = factory.GetScript(t.Name);
|
|
game = (Game)obj.Instance;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Server is only enabled if the option is in the settings file
|
|
//Allows developers to remove the option from the settings file and letting
|
|
//people host multiplayer games with the singleplayer MUD.
|
|
//People won't know that it's an option if the option doesn't exist so if no
|
|
//option is found in the sttings file, then we assume offline play.
|
|
if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "false")
|
|
game.IsMultiplayer = false;
|
|
else if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "")
|
|
game.IsMultiplayer = false;
|
|
else
|
|
game.IsMultiplayer = true;
|
|
|
|
//Start the game.
|
|
game.Start();
|
|
|
|
//Make sure the Game is in fact running.
|
|
if (!game.IsRunning)
|
|
{
|
|
Log.Write("Error starting game!\nReview Log file for details.", true);
|
|
return;
|
|
}
|
|
|
|
//If the game isn't in multiplayer mode, then the server doesn't create an instance of the players
|
|
//We need to make sure that the Game created one. The default game handles this, but inherited Game
|
|
//scripts might miss this, so we check for it.
|
|
if (!game.IsMultiplayer)
|
|
{
|
|
if ((game.GetPlayerCollection()[0] == null) || (game.GetPlayerCollection()[0].Name == "New BaseCharacter"))
|
|
{
|
|
Log.Write("Error! No player available for creation!", true);
|
|
return;
|
|
}
|
|
}
|
|
|
|
Console.Title = game.GameTitle;
|
|
|
|
if (game.IsMultiplayer)
|
|
Console.Title += " server running.";
|
|
|
|
try
|
|
{
|
|
while (game.IsRunning)
|
|
{
|
|
game.Update();
|
|
System.Threading.Thread.Sleep(1);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Write("Critical Error! " + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |