MudEngine:
- Login command now supports Offline games. Skips various things that are server related only. - Added a constructor to SaveDataPaths for quickly being able to assign paths. - Game.Start is now Virtual so that scripts may override it. - Game.Start now supports single player games and initializes players within it. - Log now provides a Verbose mode so that Singleplayer games no longer gets flooded with Game startup messages. - BaseCharacter.Initialize() Initialize no longer crashes when called with IsMultiplayer set to false. - BaseCharacter.ReadInput() now supports IsMultiplayer being false. MudServer: - Now supports singleplayer and multiplayer games within a single application. - MudServer is now ready to be re-named to MudGame and will be used for both Offline and Online games.
This commit is contained in:
parent
ef7cc5d2c2
commit
aade5f797f
7 changed files with 188 additions and 55 deletions
|
@ -15,25 +15,35 @@ namespace MudServer
|
|||
{
|
||||
static class Program
|
||||
{
|
||||
const string SettingsFile = "Settings.ini";
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "false")
|
||||
Log.IsVerbose = true;
|
||||
else if (FileManager.GetData(SettingsFile, "ServerEnabled").ToLower() == "")
|
||||
Log.IsVerbose = false;
|
||||
else
|
||||
Log.IsVerbose = false;
|
||||
|
||||
Log.Write("Launching...");
|
||||
ScriptEngine scriptEngine;
|
||||
Game game;
|
||||
|
||||
//Re-create the settings file if it is missing
|
||||
if (!File.Exists("Settings.ini"))
|
||||
if (!File.Exists(SettingsFile))
|
||||
{
|
||||
Log.Write("Settings.ini missing!");
|
||||
FileManager.WriteLine("Settings.ini", "Scripts", "ScriptPath");
|
||||
FileManager.WriteLine("Settings.ini", ".cs", "ScriptExtension");
|
||||
FileManager.WriteLine(SettingsFile, "Scripts", "ScriptPath");
|
||||
FileManager.WriteLine(SettingsFile, ".cs", "ScriptExtension");
|
||||
FileManager.WriteLine(SettingsFile, "True", "ServerEnabled");
|
||||
Log.Write("Settings.ini re-created with default values");
|
||||
}
|
||||
|
||||
Log.Write("Loading settings...");
|
||||
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.SourceFiles);
|
||||
scriptEngine.ScriptPath = FileManager.GetData("Settings.ini", "ScriptPath");
|
||||
scriptEngine.ScriptExtension = FileManager.GetData("Settings.ini", "ScriptExtension");
|
||||
scriptEngine.ScriptPath = FileManager.GetData(SettingsFile, "ScriptPath");
|
||||
scriptEngine.ScriptExtension = FileManager.GetData(SettingsFile, "ScriptExtension");
|
||||
|
||||
//scriptEngine.CompileScripts();
|
||||
Log.Write("Initializing Script Engine for Script Compilation...");
|
||||
|
@ -68,13 +78,69 @@ namespace MudServer
|
|||
Console.WriteLine(Log.GetMessages());
|
||||
Log.FlushMessages();
|
||||
|
||||
game.Start();
|
||||
//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;
|
||||
|
||||
game.Start();
|
||||
|
||||
//Make sure the Game is in fact running.
|
||||
if (!game.IsRunning)
|
||||
{
|
||||
Console.WriteLine("Error starting game!\nReview Log file for details.");
|
||||
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.PlayerCollection[0] == null) || (game.PlayerCollection[0].Name == "New BaseCharacter"))
|
||||
{
|
||||
Console.WriteLine("Error! No player available for creation!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DateTime serverTime = new DateTime();
|
||||
DateTime systemTime = DateTime.Now;
|
||||
|
||||
int lastSaveGap = 0;
|
||||
|
||||
while (game.IsRunning)
|
||||
{
|
||||
Console.Write(Log.GetMessages());
|
||||
Log.FlushMessages();
|
||||
System.Threading.Thread.Sleep(1);
|
||||
if (lastSaveGap == 30)
|
||||
{
|
||||
game.Save();
|
||||
lastSaveGap = 0;
|
||||
}
|
||||
|
||||
if (serverTime.Minute != DateTime.Now.Minute)
|
||||
{
|
||||
serverTime = DateTime.Now;
|
||||
lastSaveGap++;
|
||||
}
|
||||
|
||||
if (game.IsMultiplayer)
|
||||
{
|
||||
Console.Write(Log.GetMessages());
|
||||
Log.FlushMessages();
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
game.PlayerCollection[0].ExecuteCommand(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue