1
0

GodNamesModule.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 OpenSimulator 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 System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Mono.Addins;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. namespace OpenSim.Region.OptionalModules.ViewerSupport
  39. {
  40. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodNamesModule")]
  41. public class GodNamesModule : ISharedRegionModule
  42. {
  43. // Infrastructure
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. // Configuration
  46. private static bool m_enabled = false;
  47. private static List<String> m_lastNames = new List<String>();
  48. private static List<String> m_fullNames = new List<String>();
  49. public void Initialise(IConfigSource config)
  50. {
  51. IConfig moduleConfig = config.Configs["GodNames"];
  52. if (moduleConfig == null) {
  53. return;
  54. }
  55. if (!moduleConfig.GetBoolean("Enabled", false)) {
  56. m_log.Info("[GODNAMES]: Addon is disabled");
  57. return;
  58. }
  59. m_log.Info("[GODNAMES]: Enabled");
  60. m_enabled = true;
  61. string conf_str = moduleConfig.GetString("FullNames", String.Empty);
  62. if (conf_str != String.Empty)
  63. {
  64. foreach (string strl in conf_str.Split(',')) {
  65. string strlan = strl.Trim(" \t".ToCharArray());
  66. m_log.DebugFormat("[GODNAMES]: Adding {0} as a God name", strlan);
  67. m_fullNames.Add(strlan);
  68. }
  69. }
  70. conf_str = moduleConfig.GetString("Surnames", String.Empty);
  71. if (conf_str != String.Empty)
  72. {
  73. foreach (string strl in conf_str.Split(',')) {
  74. string strlan = strl.Trim(" \t".ToCharArray());
  75. m_log.DebugFormat("[GODNAMES]: Adding {0} as a God last name", strlan);
  76. m_lastNames.Add(strlan);
  77. }
  78. }
  79. }
  80. public void AddRegion(Scene scene) {
  81. /*no op*/
  82. }
  83. public void RemoveRegion(Scene scene) {
  84. /*no op*/
  85. }
  86. public void PostInitialise() {
  87. /*no op*/
  88. }
  89. public void Close() {
  90. /*no op*/
  91. }
  92. public Type ReplaceableInterface {
  93. get { return null; }
  94. }
  95. public string Name {
  96. get { return "Godnames"; }
  97. }
  98. public bool IsSharedModule {
  99. get { return true; }
  100. }
  101. public virtual void RegionLoaded(Scene scene)
  102. {
  103. if (!m_enabled)
  104. return;
  105. ISimulatorFeaturesModule featuresModule = scene.RequestModuleInterface<ISimulatorFeaturesModule>();
  106. if (featuresModule != null)
  107. featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest;
  108. }
  109. private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features)
  110. {
  111. OSD namesmap = new OSDMap();
  112. if (features.ContainsKey("god_names"))
  113. namesmap = features["god_names"];
  114. else
  115. features["god_names"] = namesmap;
  116. OSDArray fnames = new OSDArray();
  117. foreach (string name in m_fullNames) {
  118. fnames.Add(name);
  119. }
  120. ((OSDMap)namesmap)["full_names"] = fnames;
  121. OSDArray lnames = new OSDArray();
  122. foreach (string name in m_lastNames) {
  123. lnames.Add(name);
  124. }
  125. ((OSDMap)namesmap)["last_names"] = lnames;
  126. }
  127. }
  128. }