- Added FileManager.GetDataSpan() method. This allows developers to start at a line and collect the next 'x' number of lines after that starting line. Example: GetDataSpan("MyFile.txt", 5, "DoorwayArrivalRoom", true); This seeks MyFile.txt until it finds "DoorwayArrivalRoom" and then it stores that line and the next 4 lines for a total of 5 lines and returns the collection. The last argument 'true' means that the method will scan the rest of the file after the initial 5 lines and add any other lines that match the "DoorwayArrivalRoom" string as well. - Deleted CommandResults class as it's no longer used by the script engine. - Singleplayer and Multiplayer save data paths are now the same paths by default. - Game.Update() method now checks for auto-saving (instead of MudGame performing this check) - Saving and restoring of Realms, Zones, Rooms and Doorways now fully implemented. - GameTime now supports auto-saving - GameWorld.Update() now calls BaseCharacter.Update() and is ready for future update code. - GameWorld.AddObject and GameWorld.RemoveObject() have been removed. - GameWorld.AddRealm() re-added for adding Realms pre-populated with zones/rooms. Note that Zones and Rooms can be added to a Realm even after it has been added to the GameWorld.RealmCollection - BaseObject now contains a OnStart() event method. - BaseObject.Save() now saves BaseObject.DetailedDescription collection content. - Updated BaseCharacter to retrieve Environments by Filename rather than Object name. - BaseStats.Experience property added. - Door.RoomTravelType enum added for determining if the room is Arrival or Departure - Door.SetRoom() method added for restoring a Rooms Doorway link during world restoration. - Renamed Room.InstallPath to Room.RoomLocation. Contains a MyRealm.Realm>MyZone.Zone>MyRoom.Room path - Added Room.RoomLocationWithoutExtension property for returning the Rooms location without file extensions. Ex: MyRealm>MyZone>MyRoom - Room now saves Doorways. - The GameWorld now restores the link between Rooms once all Environment objects have been instanced and restored from their saved state. MudGame: - Minor clean-up with MudGame loop and shutdown. - Updated scripts to reflect changes made to the engine.
134 lines
No EOL
5.1 KiB
C#
134 lines
No EOL
5.1 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)
|
|
{
|
|
dynamic 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);
|
|
ScriptEngine scriptEngine;
|
|
scriptEngine = new ScriptEngine(new Game(), ScriptEngine.ScriptTypes.Both);
|
|
|
|
//scriptEngine.CompileScripts();
|
|
Log.Write("Initializing Script Engine for Script Compilation...", true);
|
|
scriptEngine.Initialize();
|
|
|
|
GameObject obj = scriptEngine.GetObjectOf("Game");
|
|
//Console.WriteLine(Log.GetMessages());
|
|
//Log.FlushMessages();
|
|
|
|
if (obj == null)
|
|
{
|
|
game = new Game();
|
|
obj = new GameObject(game, "Game");
|
|
scriptEngine = new ScriptEngine((Game)obj.Instance, ScriptEngine.ScriptTypes.Both);
|
|
}
|
|
else
|
|
{
|
|
game = (Game)obj.Instance;
|
|
scriptEngine = new ScriptEngine(game, ScriptEngine.ScriptTypes.Both);
|
|
}
|
|
//Force TCP
|
|
game.ServerType = ProtocolType.Tcp;
|
|
|
|
//Setup the scripting engine and load our script library
|
|
//MUST be called before game.Start()
|
|
//scriptEngine.Initialize();
|
|
//game.scriptEngine = scriptEngine; //Pass this script engine off to the game to use now.
|
|
Log.Write("");
|
|
Log.Write("Starting " + obj.GetProperty().GameTitle + "...", true);
|
|
Log.Write("");
|
|
//Console.WriteLine(Log.GetMessages());
|
|
//Log.FlushMessages();
|
|
|
|
//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)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |