/// <summary> /// Loads additional assets specified by assets.xml /// </summary> public void loadAdditionalAssets() { //Load up our assets config file ConfigSetting cfg = new Xmlconfig(@"../Global/assets.xml", false).Settings; foreach (ConfigSetting asset in cfg.GetNamedChildren("asset")) { //Insert it into the asset list AssetFile assetf = AssetFileFactory.CreateFromGlobalFile <AssetFile>(asset.Value); if (assetf != null) { addAssetData(assetf); } } }
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); }
/////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// <summary> /// Loads all game assets /// </summary> public bool load(CfgInfo zoneConf, string configFilename) { _singleton = this; _assetList = new List <AssetInfo>(); //Add the game config addAssetData(AssetFileFactory.CreateFromFile <AssetFile>(configFilename)); //Load shit up ItemFile itms = AssetFileFactory.CreateFromFile <ItemFile>(zoneConf.level.itmFile); LioFile lios = AssetFileFactory.CreateFromFile <LioFile>(zoneConf.level.lioFile); SkillFile rpgs = AssetFileFactory.CreateFromFile <SkillFile>(zoneConf.level.rpgFile); VehicleFile vehs = AssetFileFactory.CreateFromFile <VehicleFile>(zoneConf.level.vehFile); LevelFile lvl = AssetFileFactory.CreateFromFile <LevelFile>(zoneConf.level.lvlFile); if (itms == null || lios == null || rpgs == null || vehs == null || lvl == null) { //Missing a core file foreach (string missing in AssetFileFactory._missingFiles) { Log.write(TLog.Error, "Missing file: {0}", missing); } return(false); } Level = lvl.Data; //Save checksums to send to clients addAssetData(itms); addAssetData(lios); addAssetData(rpgs); addAssetData(vehs); addAssetData(lvl); //Make item maps _idToItem = new SortedDictionary <int, ItemInfo>(); _nameToItem = new SortedDictionary <string, ItemInfo>(); foreach (ItemInfo it in itms.Data) { _idToItem.Add(it.id, it); } foreach (ItemInfo it in itms.Data) { if (!_nameToItem.ContainsKey(it.name.ToLower())) { _nameToItem.Add(it.name.ToLower(), it); } } //Make skill maps _idToSkill = new SortedDictionary <int, SkillInfo>(); _nameToSkill = new SortedDictionary <string, SkillInfo>(); foreach (SkillInfo it in rpgs.Data) { _idToSkill.Add(it.SkillId, it); } foreach (SkillInfo it in rpgs.Data) { if (!_nameToSkill.ContainsKey(it.Name.ToLower())) { _nameToSkill.Add(it.Name.ToLower(), it); } } //Make lio map _idToLio = new SortedDictionary <int, LioInfo>(); foreach (LioInfo it in lios.Data) { _idToLio.Add(it.GeneralData.Id, it); } //Load blo files _bloList = new List <string>(); foreach (string file in ItemInfo.BlobsToLoad) { loadBloFile(file + ".blo"); } foreach (string file in CfgInfo.BlobsToLoad) { loadBloFile(file + ".blo"); } foreach (string file in LioInfo.BlobsToLoad) { loadBloFile(file + ".blo"); } foreach (string file in SkillInfo.BlobsToLoad) { loadBloFile(file + ".blo"); } foreach (LvlInfo.BlobReference blob in Level.ObjectBlobs) { loadBloFile(blob.FileName); } foreach (LvlInfo.BlobReference blob in Level.FloorBlobs) { loadBloFile(blob.FileName); } //Make vehicle map _idToVehicle = new SortedDictionary <int, VehInfo>(); foreach (VehInfo it in vehs.Data) { _idToVehicle.Add(it.Id, it); foreach (string blo in it.blofiles) { loadBloFile(blo + ".blo"); } } foreach (string blo in _bloList) { //Attempt to load it BloFile blof = AssetFileFactory.LoadBlobFromFile <BloFile>(blo); if (blof != null) { addAssetData(blof); } } //For debugging _bloList.Sort(); _bloListFileName = "bloList_" + configFilename + ".txt"; System.IO.File.WriteAllLines(string.Format("{0}/{1}", Environment.CurrentDirectory, _bloListFileName), _bloList); //Update our asset server sendDataToDirectory(); //Initialize our lio data Lios = new Lio(this); //Load news file AssetFile nws = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.level.nwsFile); if (nws != null) { addAssetData(nws); } //Load the helpMenu files for (int i = 0; i <= zoneConf.helpMenu.links.Count - 1; i++) { AssetFile helpMenu = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.helpMenu.links[i].name); if (helpMenu != null) { addAssetData(helpMenu); } } //Load everything else loadAdditionalAssets(); //Are we missing files? if (AssetFileFactory.IsIncomplete) { //Missing a core file foreach (string missing in AssetFileFactory._missingFiles) { Log.write(TLog.Error, "Missing file: {0}", missing); } return(false); } //Cache all our assets AssetCache = new Cache(this); AssetCache.prepareCache(_assetList); 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); }