MXPModule.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.Text;
  30. using System.Timers;
  31. using MXP;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Client.MXP.PacketHandler;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. namespace OpenSim.Client.MXP
  38. {
  39. public class MXPModule : IRegionModule
  40. {
  41. private int m_port = 1253;
  42. //private int m_ticks = 0;
  43. private bool m_shutdown = false;
  44. private IConfigSource m_config;
  45. private readonly Timer m_ticker = new Timer(100);
  46. private readonly Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
  47. private MXPPacketServer m_server;
  48. public void Initialise(Scene scene, IConfigSource source)
  49. {
  50. if (!m_scenes.ContainsKey(scene.RegionInfo.RegionID))
  51. m_scenes.Add(scene.RegionInfo.RegionID, scene);
  52. m_config = source;
  53. }
  54. public void PostInitialise()
  55. {
  56. if (m_config.Configs["MXP"] != null)
  57. {
  58. IConfig con = m_config.Configs["MXP"];
  59. if (!con.GetBoolean("Enabled", false))
  60. return;
  61. m_port = con.GetInt("Port", m_port);
  62. m_server = new MXPPacketServer(m_port, m_scenes);
  63. m_ticker.AutoReset = false;
  64. m_ticker.Elapsed += ticker_Elapsed;
  65. m_ticker.Start();
  66. }
  67. }
  68. void ticker_Elapsed(object sender, ElapsedEventArgs e)
  69. {
  70. m_server.Process();
  71. if (!m_shutdown)
  72. m_ticker.Start();
  73. // Commenting this at because of the excess flood to log.
  74. // TODO: Add ini file option.
  75. /*if (++ticks % 100 == 0)
  76. {
  77. server.PrintDebugInformation();
  78. }*/
  79. }
  80. public void Close()
  81. {
  82. m_shutdown = true;
  83. m_ticker.Stop();
  84. }
  85. public string Name
  86. {
  87. get { return "MXP ClientStack Module"; }
  88. }
  89. public bool IsSharedModule
  90. {
  91. get { return true; }
  92. }
  93. }
  94. }