public bool loadAssets(string zoneConfig) { string assetsPath = "assets\\"; //Load our zone config InfServer.Log.write(InfServer.TLog.Normal, "Loading Zone Configuration"); if (!System.IO.Directory.Exists(assetsPath)) { InfServer.Log.write(InfServer.TLog.Error, "Unable to find assets directory '" + assetsPath + "'."); return(false); } string filePath = AssetFileFactory.findAssetFile(zoneConfig, assetsPath); if (filePath == null) { InfServer.Log.write(InfServer.TLog.Error, "Unable to find config file '" + assetsPath + zoneConfig + "'."); return(false); } _zoneConfig = CfgInfo.Load(filePath); //Load assets from zone config and populate AssMan try { _assets = new AssetManager(); _assets.bUseBlobs = false; if (!_assets.load(_zoneConfig, zoneConfig)) { //We're unable to continue InfServer.Log.write(InfServer.TLog.Error, "Files missing, unable to continue."); return(false); } } catch (System.IO.FileNotFoundException ex) { //Report and abort InfServer.Log.write(InfServer.TLog.Error, "Unable to find file '{0}'", ex.FileName); return(false); } return(true); }
/// <summary> /// Allows the server to preload all assets. /// </summary> public bool init() { // Load configuration /////////////////////////////////////////////// //Load our server config _connections = new Dictionary <IPAddress, DateTime>(); Log.write(TLog.Normal, "Loading Server Configuration"); _config = new Xmlconfig("server.xml", false).Settings; string assetsPath = "assets\\"; //Load our zone config Log.write(TLog.Normal, "Loading Zone Configuration"); if (!System.IO.Directory.Exists(assetsPath)) { Log.write(TLog.Error, "Unable to find assets directory '" + assetsPath + "'."); return(false); } string filePath = AssetFileFactory.findAssetFile(_config["server/zoneConfig"].Value, assetsPath); if (filePath == null) { Log.write(TLog.Error, "Unable to find config file '" + assetsPath + _config["server/zoneConfig"].Value + "'."); return(false); } _zoneConfig = CfgInfo.Load(filePath); //Load assets from zone config and populate AssMan try { _assets = new AssetManager(); _assets.bUseBlobs = _config["server/loadBlobs"].boolValue; //Grab the latest global news if specified if (_config["server/updateGlobalNws"].Value.Length > 0) { Log.write(TLog.Normal, String.Format("Grabbing latest global news from {0}...", _config["server/updateGlobalNws"].Value)); if (!_assets.grabGlobalNews(_config["server/updateGlobalNws"].Value, "..\\Global\\global.nws")) { try { string global; if ((global = Assets.AssetFileFactory.findAssetFile("global.nws", _config["server/copyServerFrom"].Value)) != null) { System.IO.File.Copy(global, "..\\Global\\global.nws"); } } catch (System.UnauthorizedAccessException) { } } } if (!_assets.load(_zoneConfig, _config["server/zoneConfig"].Value)) { //We're unable to continue Log.write(TLog.Error, "Files missing, unable to continue."); return(false); } } catch (System.IO.FileNotFoundException ex) { //Report and abort Log.write(TLog.Error, "Unable to find file '{0}'", ex.FileName); return(false); } //Make sure our protocol helpers are aware Helpers._server = this; //Load protocol config settings base._bLogPackets = _config["server/logPackets"].boolValue; Client.udpMaxSize = _config["protocol/udpMaxSize"].intValue; Client.crcLength = _config["protocol/crcLength"].intValue; if (Client.crcLength > 4) { Log.write(TLog.Error, "Invalid protocol/crcLength, must be less than 4."); return(false); } Client.connectionTimeout = _config["protocol/connectionTimeout"].intValue; Client.bLogUnknowns = _config["protocol/logUnknownPackets"].boolValue; ClientConn <Database> .clientPingFreq = _config["protocol/clientPingFreq"].intValue; // Load scripts /////////////////////////////////////////////// Log.write("Loading scripts.."); //Obtain the bot and operation types ConfigSetting scriptConfig = new Xmlconfig("scripts.xml", false).Settings; IList <ConfigSetting> scripts = scriptConfig["scripts"].GetNamedChildren("type"); //Load the bot types List <Scripting.InvokerType> scriptingBotTypes = new List <Scripting.InvokerType>(); foreach (ConfigSetting cs in scripts) { //Convert the config entry to a bottype structure scriptingBotTypes.Add( new Scripting.InvokerType( cs.Value, cs["inheritDefaultScripts"].boolValue, cs["scriptDir"].Value) ); } //Load them into the scripting engine Scripting.Scripts.loadBotTypes(scriptingBotTypes); try { //Loads! bool bSuccess = Scripting.Scripts.compileScripts(); if (!bSuccess) { //Failed. Exit Log.write(TLog.Error, "Unable to load scripts."); return(false); } } catch (Exception ex) { //Error while compiling Log.write(TLog.Exception, "Exception while compiling scripts:\n" + ex.ToString()); return(false); } if (_config["server/pathFindingEnabled"].boolValue) { Log.write("Initializing pathfinder.."); _pathfinder = new Bots.Pathfinder(this); _pathfinder.beginThread(); } else { Log.write("Pathfinder disabled, skipping.."); } // Sets the zone settings ////////////////////////////////////////////// _name = _config["server/zoneName"].Value; _description = _config["server/zoneDescription"].Value; _isAdvanced = _config["server/zoneIsAdvanced"].boolValue; _bindIP = _config["server/bindIP"].Value; _bindPort = _config["server/bindPort"].intValue; _attemptDelay = _config["database/connectionDelay"].intValue; // Connect to the database /////////////////////////////////////////////// //Attempt to connect to our database //Are we connecting at all? if (_attemptDelay == 0) { //Skip the database! _bStandalone = true; Log.write(TLog.Warning, "Skipping database server connection, server is in stand-alone mode.."); } else { _bStandalone = false; _dbLogger = Log.createClient("Database"); _db = new Database(this, _config["database"], _dbLogger); _dbEP = new IPEndPoint(IPAddress.Parse(_config["database/ip"].Value), _config["database/port"].intValue); _db.connect(_dbEP, true); } //Initialize other parts of the zoneserver class if (!initPlayers()) { return(false); } if (!initArenas()) { return(false); } // Create the ping/player count responder ////////////////////////////////////////////// _pingResponder = new ClientPingResponder(_players); Log.write("Asset Checksum: " + _assets.checkSum()); //Create a new player silenced list _playerSilenced = new Dictionary <string, Dictionary <int, DateTime> >(); //Setup a new zoneserver recycling class _recycle = new Dictionary <ZoneServer, DateTime>(); _recycleAttempt = Environment.TickCount; //InitializeGameEventsDictionary(); return(true); }