DbGridConfig.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using Db4objects.Db4o;
  30. using OpenSim.Framework.Configuration;
  31. using OpenSim.Framework.Console;
  32. using OpenSim.Framework.Interfaces;
  33. namespace OpenGrid.Config.GridConfigDb4o
  34. {
  35. /// <summary>
  36. /// A grid configuration interface for returning the DB4o Config Provider
  37. /// </summary>
  38. public class Db40ConfigPlugin: IGridConfig
  39. {
  40. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  41. /// <summary>
  42. /// Loads and returns a configuration objeect
  43. /// </summary>
  44. /// <returns>A grid configuration object</returns>
  45. public GridConfig GetConfigObject()
  46. {
  47. m_log.Info("[DBGRIDCONFIG]: Loading Db40Config dll");
  48. return new DbGridConfig();
  49. }
  50. }
  51. /// <summary>
  52. /// A DB4o based Gridserver configuration object
  53. /// </summary>
  54. public class DbGridConfig : GridConfig
  55. {
  56. /// <summary>
  57. /// The DB4o Database
  58. /// </summary>
  59. private IObjectContainer db;
  60. /// <summary>
  61. /// User configuration for the Grid Config interfaces
  62. /// </summary>
  63. public void LoadDefaults()
  64. {
  65. MainConsole.Instance.Info("DbGridConfig.cs:LoadDefaults() - Please press enter to retain default or enter new settings");
  66. // About the grid options
  67. this.GridOwner = MainConsole.Instance.CmdPrompt("Grid owner", "OGS development team");
  68. // Asset Options
  69. this.DefaultAssetServer = MainConsole.Instance.CmdPrompt("Default asset server","http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString() + "/");
  70. this.AssetSendKey = MainConsole.Instance.CmdPrompt("Key to send to asset server","null");
  71. this.AssetRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from asset server","null");
  72. // User Server Options
  73. this.DefaultUserServer = MainConsole.Instance.CmdPrompt("Default user server","http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString() + "/");
  74. this.UserSendKey = MainConsole.Instance.CmdPrompt("Key to send to user server","null");
  75. this.UserRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from user server","null");
  76. // Region Server Options
  77. this.SimSendKey = MainConsole.Instance.CmdPrompt("Key to send to sims","null");
  78. this.SimRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from sims","null");
  79. }
  80. /// <summary>
  81. /// Initialises a new configuration object
  82. /// </summary>
  83. public override void InitConfig()
  84. {
  85. try
  86. {
  87. // Perform Db4o initialisation
  88. db = Db4oFactory.OpenFile("opengrid.yap");
  89. // Locate the grid configuration object
  90. IObjectSet result = db.Get(typeof(DbGridConfig));
  91. // Found?
  92. if (result.Count==1)
  93. {
  94. m_log.Info("[DBGRIDCONFIG]: Found a GridConfig object in the local database, loading");
  95. foreach (DbGridConfig cfg in result)
  96. {
  97. // Import each setting into this class
  98. // Grid Settings
  99. this.GridOwner=cfg.GridOwner;
  100. // Asset Settings
  101. this.DefaultAssetServer=cfg.DefaultAssetServer;
  102. this.AssetSendKey=cfg.AssetSendKey;
  103. this.AssetRecvKey=cfg.AssetRecvKey;
  104. // User Settings
  105. this.DefaultUserServer=cfg.DefaultUserServer;
  106. this.UserSendKey=cfg.UserSendKey;
  107. this.UserRecvKey=cfg.UserRecvKey;
  108. // Region Settings
  109. this.SimSendKey=cfg.SimSendKey;
  110. this.SimRecvKey=cfg.SimRecvKey;
  111. }
  112. // Create a new configuration object from this class
  113. }
  114. else
  115. {
  116. m_log.Info("[DBGRIDCONFIG]: Could not find object in database, loading precompiled defaults");
  117. // Load default settings into this class
  118. LoadDefaults();
  119. // Saves to the database file...
  120. m_log.Info("[DBGRIDCONFIG]: Writing out default settings to local database");
  121. db.Set(this);
  122. // Closes file locks
  123. db.Close();
  124. }
  125. }
  126. catch(Exception e)
  127. {
  128. m_log.Warn("DbGridConfig.cs:InitConfig() - Exception occured");
  129. m_log.Warn(e.ToString());
  130. }
  131. // Grid Settings
  132. m_log.Info("[DBGRIDCONFIG]: Grid settings loaded:");
  133. m_log.Info("[DBGRIDCONFIG]: Grid owner: " + this.GridOwner);
  134. // Asset Settings
  135. m_log.Info("[DBGRIDCONFIG]: Default asset server: " + this.DefaultAssetServer);
  136. m_log.Info("[DBGRIDCONFIG]: Key to send to asset server: " + this.AssetSendKey);
  137. m_log.Info("[DBGRIDCONFIG]: Key to expect from asset server: " + this.AssetRecvKey);
  138. // User Settings
  139. m_log.Info("[DBGRIDCONFIG]: Default user server: " + this.DefaultUserServer);
  140. m_log.Info("[DBGRIDCONFIG]: Key to send to user server: " + this.UserSendKey);
  141. m_log.Info("[DBGRIDCONFIG]: Key to expect from user server: " + this.UserRecvKey);
  142. // Region Settings
  143. m_log.Info("[DBGRIDCONFIG]: Key to send to sims: " + this.SimSendKey);
  144. m_log.Info("[DBGRIDCONFIG]: Key to expect from sims: " + this.SimRecvKey);
  145. }
  146. /// <summary>
  147. /// Closes down the database and releases filesystem locks
  148. /// </summary>
  149. public void Shutdown()
  150. {
  151. db.Close();
  152. }
  153. }
  154. }