Main.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 System.IO;
  29. using System.Reflection;
  30. using OpenMetaverse;
  31. using log4net;
  32. using log4net.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications.Cache;
  35. using OpenSim.Framework.Console;
  36. using OpenSim.Framework.Servers;
  37. namespace OpenSim.Grid.MessagingServer
  38. {
  39. /// <summary>
  40. /// </summary>
  41. public class OpenMessage_Main : BaseOpenSimServer, conscmd_callback
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private MessageServerConfig Cfg;
  45. private MessageService msgsvc;
  46. // private UUID m_lastCreatedUser = UUID.Random();
  47. public static void Main(string[] args)
  48. {
  49. XmlConfigurator.Configure();
  50. m_log.Info("[SERVER]: Launching MessagingServer...");
  51. OpenMessage_Main messageserver = new OpenMessage_Main();
  52. messageserver.Startup();
  53. messageserver.Work();
  54. }
  55. public OpenMessage_Main()
  56. {
  57. m_console = new ConsoleBase("Messaging", this);
  58. MainConsole.Instance = m_console;
  59. }
  60. private void Work()
  61. {
  62. m_console.Notice("Enter help for a list of commands\n");
  63. while (true)
  64. {
  65. m_console.Prompt();
  66. }
  67. }
  68. private void registerWithUserServer()
  69. {
  70. if (msgsvc.registerWithUserServer())
  71. {
  72. m_log.Info("[SERVER]: Starting HTTP process");
  73. m_httpServer = new BaseHttpServer(Cfg.HttpPort);
  74. m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn);
  75. m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff);
  76. m_httpServer.AddXmlRPCHandler("get_presence_info_bulk", msgsvc.GetPresenceInfoBulk);
  77. m_httpServer.AddXmlRPCHandler("region_startup", msgsvc.RegionStartup);
  78. m_httpServer.AddXmlRPCHandler("region_shutdown", msgsvc.RegionShutdown);
  79. m_httpServer.AddXmlRPCHandler("process_region_shutdown", msgsvc.ProcessRegionShutdown);
  80. m_httpServer.AddXmlRPCHandler("agent_location", msgsvc.AgentLocation);
  81. m_httpServer.AddXmlRPCHandler("agent_leaving", msgsvc.AgentLeaving);
  82. m_httpServer.Start();
  83. m_log.Info("[SERVER]: Userserver registration was successful");
  84. }
  85. else
  86. {
  87. m_log.Error("[STARTUP]: Unable to connect to User Server");
  88. }
  89. }
  90. private void deregisterFromUserServer()
  91. {
  92. msgsvc.deregisterWithUserServer();
  93. if (m_httpServer != null)
  94. {
  95. // try a completely fresh registration, with fresh handlers, too
  96. m_httpServer.Stop();
  97. m_httpServer = null;
  98. }
  99. m_console.Notice("[SERVER]: Deregistered from userserver.");
  100. }
  101. protected override void StartupSpecific()
  102. {
  103. Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml")));
  104. msgsvc = new MessageService(Cfg);
  105. registerWithUserServer();
  106. m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete");
  107. }
  108. public void do_create(string what)
  109. {
  110. switch (what)
  111. {
  112. case "user":
  113. try
  114. {
  115. //userID =
  116. //m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
  117. } catch (Exception ex)
  118. {
  119. m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString());
  120. }
  121. try
  122. {
  123. //RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
  124. //userID.Guid);
  125. }
  126. catch (Exception ex)
  127. {
  128. m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString());
  129. }
  130. // m_lastCreatedUser = userID;
  131. break;
  132. }
  133. }
  134. public override void RunCmd(string cmd, string[] cmdparams)
  135. {
  136. base.RunCmd(cmd, cmdparams);
  137. switch (cmd)
  138. {
  139. case "clear-cache":
  140. int entries = msgsvc.ClearRegionCache();
  141. m_console.Notice("Region cache cleared! Cleared " + entries.ToString() + " entries");
  142. break;
  143. case "register":
  144. deregisterFromUserServer();
  145. registerWithUserServer();
  146. break;
  147. }
  148. }
  149. protected override void ShowHelp(string[] helpArgs)
  150. {
  151. base.ShowHelp(helpArgs);
  152. m_console.Notice("clear-cache - Clears region cache. Should be done when regions change position. The region cache gets stale after a while.");
  153. m_console.Notice("register - (Re-)registers with user-server. This might be necessary if the userserver crashed/restarted");
  154. }
  155. public override void ShutdownSpecific()
  156. {
  157. msgsvc.deregisterWithUserServer();
  158. }
  159. }
  160. }