1
0

GodNamesModule.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. foreach (string strl in conf_str.Split(',')) {
  63. string strlan = strl.Trim(" \t".ToCharArray());
  64. m_log.DebugFormat("[GODNAMES]: Adding {0} as a God name", strlan);
  65. m_fullNames.Add(strlan);
  66. }
  67. conf_str = moduleConfig.GetString("Surnames", String.Empty);
  68. foreach (string strl in conf_str.Split(',')) {
  69. string strlan = strl.Trim(" \t".ToCharArray());
  70. m_log.DebugFormat("[GODNAMES]: Adding {0} as a God last name", strlan);
  71. m_lastNames.Add(strlan);
  72. }
  73. }
  74. public void AddRegion(Scene scene) {
  75. /*no op*/
  76. }
  77. public void RemoveRegion(Scene scene) {
  78. /*no op*/
  79. }
  80. public void PostInitialise() {
  81. /*no op*/
  82. }
  83. public void Close() {
  84. /*no op*/
  85. }
  86. public Type ReplaceableInterface {
  87. get { return null; }
  88. }
  89. public string Name {
  90. get { return "Godnames"; }
  91. }
  92. public bool IsSharedModule {
  93. get { return true; }
  94. }
  95. public virtual void RegionLoaded(Scene scene)
  96. {
  97. if (!m_enabled)
  98. return;
  99. ISimulatorFeaturesModule featuresModule = scene.RequestModuleInterface<ISimulatorFeaturesModule>();
  100. if (featuresModule != null)
  101. featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest;
  102. }
  103. private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features)
  104. {
  105. OSD namesmap = new OSDMap();
  106. if (features.ContainsKey("god_names"))
  107. namesmap = features["god_names"];
  108. else
  109. features["god_names"] = namesmap;
  110. OSDArray fnames = new OSDArray();
  111. foreach (string name in m_fullNames) {
  112. fnames.Add(name);
  113. }
  114. ((OSDMap)namesmap)["full_names"] = fnames;
  115. OSDArray lnames = new OSDArray();
  116. foreach (string name in m_lastNames) {
  117. lnames.Add(name);
  118. }
  119. ((OSDMap)namesmap)["last_names"] = lnames;
  120. }
  121. }
  122. }