DbGridConfig.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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.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. /// <summary>
  40. /// Loads and returns a configuration objeect
  41. /// </summary>
  42. /// <returns>A grid configuration object</returns>
  43. public GridConfig GetConfigObject()
  44. {
  45. MainLog.Instance.Verbose("Loading Db40Config dll");
  46. return ( new DbGridConfig());
  47. }
  48. }
  49. /// <summary>
  50. /// A DB4o based Gridserver configuration object
  51. /// </summary>
  52. public class DbGridConfig : GridConfig
  53. {
  54. /// <summary>
  55. /// The DB4o Database
  56. /// </summary>
  57. private IObjectContainer db;
  58. /// <summary>
  59. /// User configuration for the Grid Config interfaces
  60. /// </summary>
  61. public void LoadDefaults() {
  62. MainLog.Instance.Notice("Config.cs:LoadDefaults() - Please press enter to retain default or enter new settings");
  63. // About the grid options
  64. this.GridOwner = MainLog.Instance.CmdPrompt("Grid owner", "OGS development team");
  65. // Asset Options
  66. this.DefaultAssetServer = MainLog.Instance.CmdPrompt("Default asset server","http://127.0.0.1:8003/");
  67. this.AssetSendKey = MainLog.Instance.CmdPrompt("Key to send to asset server","null");
  68. this.AssetRecvKey = MainLog.Instance.CmdPrompt("Key to expect from asset server","null");
  69. // User Server Options
  70. this.DefaultUserServer = MainLog.Instance.CmdPrompt("Default user server","http://127.0.0.1:8002/");
  71. this.UserSendKey = MainLog.Instance.CmdPrompt("Key to send to user server","null");
  72. this.UserRecvKey = MainLog.Instance.CmdPrompt("Key to expect from user server","null");
  73. // Region Server Options
  74. this.SimSendKey = MainLog.Instance.CmdPrompt("Key to send to sims","null");
  75. this.SimRecvKey = MainLog.Instance.CmdPrompt("Key to expect from sims","null");
  76. }
  77. /// <summary>
  78. /// Initialises a new configuration object
  79. /// </summary>
  80. public override void InitConfig() {
  81. try {
  82. // Perform Db4o initialisation
  83. db = Db4oFactory.OpenFile("opengrid.yap");
  84. // Locate the grid configuration object
  85. IObjectSet result = db.Get(typeof(DbGridConfig));
  86. // Found?
  87. if(result.Count==1) {
  88. MainLog.Instance.Verbose("Config.cs:InitConfig() - Found a GridConfig object in the local database, loading");
  89. foreach (DbGridConfig cfg in result) {
  90. // Import each setting into this class
  91. // Grid Settings
  92. this.GridOwner=cfg.GridOwner;
  93. // Asset Settings
  94. this.DefaultAssetServer=cfg.DefaultAssetServer;
  95. this.AssetSendKey=cfg.AssetSendKey;
  96. this.AssetRecvKey=cfg.AssetRecvKey;
  97. // User Settings
  98. this.DefaultUserServer=cfg.DefaultUserServer;
  99. this.UserSendKey=cfg.UserSendKey;
  100. this.UserRecvKey=cfg.UserRecvKey;
  101. // Region Settings
  102. this.SimSendKey=cfg.SimSendKey;
  103. this.SimRecvKey=cfg.SimRecvKey;
  104. }
  105. // Create a new configuration object from this class
  106. } else {
  107. MainLog.Instance.Verbose("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults");
  108. // Load default settings into this class
  109. LoadDefaults();
  110. // Saves to the database file...
  111. MainLog.Instance.Verbose( "Writing out default settings to local database");
  112. db.Set(this);
  113. // Closes file locks
  114. db.Close();
  115. }
  116. } catch(Exception e) {
  117. MainLog.Instance.Warn("Config.cs:InitConfig() - Exception occured");
  118. MainLog.Instance.Warn(e.ToString());
  119. }
  120. // Grid Settings
  121. MainLog.Instance.Verbose("Grid settings loaded:");
  122. MainLog.Instance.Verbose("Grid owner: " + this.GridOwner);
  123. // Asset Settings
  124. MainLog.Instance.Verbose("Default asset server: " + this.DefaultAssetServer);
  125. MainLog.Instance.Verbose("Key to send to asset server: " + this.AssetSendKey);
  126. MainLog.Instance.Verbose("Key to expect from asset server: " + this.AssetRecvKey);
  127. // User Settings
  128. MainLog.Instance.Verbose("Default user server: " + this.DefaultUserServer);
  129. MainLog.Instance.Verbose("Key to send to user server: " + this.UserSendKey);
  130. MainLog.Instance.Verbose("Key to expect from user server: " + this.UserRecvKey);
  131. // Region Settings
  132. MainLog.Instance.Verbose("Key to send to sims: " + this.SimSendKey);
  133. MainLog.Instance.Verbose("Key to expect from sims: " + this.SimRecvKey);
  134. }
  135. /// <summary>
  136. /// Closes down the database and releases filesystem locks
  137. /// </summary>
  138. public void Shutdown() {
  139. db.Close();
  140. }
  141. }
  142. }