DbGridConfig.cs 7.5 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. using System;
  28. using Db4objects.Db4o;
  29. using OpenSim.Framework.Configuration;
  30. using OpenSim.Framework.Console;
  31. using OpenSim.Framework.Interfaces;
  32. namespace OpenGrid.Config.GridConfigDb4o
  33. {
  34. /// <summary>
  35. /// A grid configuration interface for returning the DB4o Config Provider
  36. /// </summary>
  37. public class Db40ConfigPlugin: IGridConfig
  38. {
  39. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  40. /// <summary>
  41. /// Loads and returns a configuration objeect
  42. /// </summary>
  43. /// <returns>A grid configuration object</returns>
  44. public GridConfig GetConfigObject()
  45. {
  46. m_log.Info("[DBGRIDCONFIG]: Loading Db40Config dll");
  47. return new DbGridConfig();
  48. }
  49. }
  50. /// <summary>
  51. /// A DB4o based Gridserver configuration object
  52. /// </summary>
  53. public class DbGridConfig : GridConfig
  54. {
  55. /// <summary>
  56. /// The DB4o Database
  57. /// </summary>
  58. private IObjectContainer db;
  59. /// <summary>
  60. /// User configuration for the Grid Config interfaces
  61. /// </summary>
  62. public void LoadDefaults()
  63. {
  64. MainConsole.Instance.Info("DbGridConfig.cs:LoadDefaults() - Please press enter to retain default or enter new settings");
  65. // About the grid options
  66. this.GridOwner = MainConsole.Instance.CmdPrompt("Grid owner", "OGS development team");
  67. // Asset Options
  68. this.DefaultAssetServer = MainConsole.Instance.CmdPrompt("Default asset server","http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString() + "/");
  69. this.AssetSendKey = MainConsole.Instance.CmdPrompt("Key to send to asset server","null");
  70. this.AssetRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from asset server","null");
  71. // User Server Options
  72. this.DefaultUserServer = MainConsole.Instance.CmdPrompt("Default user server","http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString() + "/");
  73. this.UserSendKey = MainConsole.Instance.CmdPrompt("Key to send to user server","null");
  74. this.UserRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from user server","null");
  75. // Region Server Options
  76. this.SimSendKey = MainConsole.Instance.CmdPrompt("Key to send to sims","null");
  77. this.SimRecvKey = MainConsole.Instance.CmdPrompt("Key to expect from sims","null");
  78. }
  79. /// <summary>
  80. /// Initialises a new configuration object
  81. /// </summary>
  82. public override void InitConfig()
  83. {
  84. try
  85. {
  86. // Perform Db4o initialisation
  87. db = Db4oFactory.OpenFile("opengrid.yap");
  88. // Locate the grid configuration object
  89. IObjectSet result = db.Get(typeof(DbGridConfig));
  90. // Found?
  91. if (result.Count==1)
  92. {
  93. m_log.Info("[DBGRIDCONFIG]: Found a GridConfig object in the local database, loading");
  94. foreach (DbGridConfig cfg in result)
  95. {
  96. // Import each setting into this class
  97. // Grid Settings
  98. this.GridOwner=cfg.GridOwner;
  99. // Asset Settings
  100. this.DefaultAssetServer=cfg.DefaultAssetServer;
  101. this.AssetSendKey=cfg.AssetSendKey;
  102. this.AssetRecvKey=cfg.AssetRecvKey;
  103. // User Settings
  104. this.DefaultUserServer=cfg.DefaultUserServer;
  105. this.UserSendKey=cfg.UserSendKey;
  106. this.UserRecvKey=cfg.UserRecvKey;
  107. // Region Settings
  108. this.SimSendKey=cfg.SimSendKey;
  109. this.SimRecvKey=cfg.SimRecvKey;
  110. }
  111. // Create a new configuration object from this class
  112. }
  113. else
  114. {
  115. m_log.Info("[DBGRIDCONFIG]: Could not find object in database, loading precompiled defaults");
  116. // Load default settings into this class
  117. LoadDefaults();
  118. // Saves to the database file...
  119. m_log.Info("[DBGRIDCONFIG]: Writing out default settings to local database");
  120. db.Set(this);
  121. // Closes file locks
  122. db.Close();
  123. }
  124. }
  125. catch(Exception e)
  126. {
  127. m_log.Warn("DbGridConfig.cs:InitConfig() - Exception occured");
  128. m_log.Warn(e.ToString());
  129. }
  130. // Grid Settings
  131. m_log.Info("[DBGRIDCONFIG]: Grid settings loaded:");
  132. m_log.Info("[DBGRIDCONFIG]: Grid owner: " + this.GridOwner);
  133. // Asset Settings
  134. m_log.Info("[DBGRIDCONFIG]: Default asset server: " + this.DefaultAssetServer);
  135. m_log.Info("[DBGRIDCONFIG]: Key to send to asset server: " + this.AssetSendKey);
  136. m_log.Info("[DBGRIDCONFIG]: Key to expect from asset server: " + this.AssetRecvKey);
  137. // User Settings
  138. m_log.Info("[DBGRIDCONFIG]: Default user server: " + this.DefaultUserServer);
  139. m_log.Info("[DBGRIDCONFIG]: Key to send to user server: " + this.UserSendKey);
  140. m_log.Info("[DBGRIDCONFIG]: Key to expect from user server: " + this.UserRecvKey);
  141. // Region Settings
  142. m_log.Info("[DBGRIDCONFIG]: Key to send to sims: " + this.SimSendKey);
  143. m_log.Info("[DBGRIDCONFIG]: Key to expect from sims: " + this.SimRecvKey);
  144. }
  145. /// <summary>
  146. /// Closes down the database and releases filesystem locks
  147. /// </summary>
  148. public void Shutdown()
  149. {
  150. db.Close();
  151. }
  152. }
  153. }