Main.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 libsecondlife;
  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 LLUUID m_lastCreatedUser = LLUUID.Random();
  47. [STAThread]
  48. public static void Main(string[] args)
  49. {
  50. XmlConfigurator.Configure();
  51. m_log.Info("Launching MessagingServer...");
  52. OpenMessage_Main messageserver = new OpenMessage_Main();
  53. messageserver.Startup();
  54. messageserver.Work();
  55. }
  56. private OpenMessage_Main()
  57. {
  58. m_console = new ConsoleBase("Messaging", this);
  59. MainConsole.Instance = m_console;
  60. }
  61. private void Work()
  62. {
  63. m_console.Notice("Enter help for a list of commands\n");
  64. while (true)
  65. {
  66. m_console.Prompt();
  67. }
  68. }
  69. public override void Startup()
  70. {
  71. base.Startup();
  72. Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml")));
  73. m_log.Info("[REGION]: Starting HTTP process");
  74. m_httpServer = new BaseHttpServer(Cfg.HttpPort);
  75. msgsvc = new MessageService(Cfg);
  76. if (msgsvc.registerWithUserServer())
  77. {
  78. m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn);
  79. m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff);
  80. //httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
  81. //httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
  82. //httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar);
  83. //httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend);
  84. //httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend);
  85. //httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms);
  86. //httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList);
  87. //httpServer.AddStreamHandler(
  88. //new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
  89. m_httpServer.Start();
  90. m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete");
  91. }
  92. else
  93. {
  94. m_log.Error("[STARTUP]: Unable to connect to User Server");
  95. }
  96. }
  97. public void do_create(string what)
  98. {
  99. switch (what)
  100. {
  101. case "user":
  102. try
  103. {
  104. //userID =
  105. //m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
  106. } catch (Exception ex)
  107. {
  108. m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString());
  109. }
  110. try
  111. {
  112. //RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
  113. //userID.UUID);
  114. }
  115. catch (Exception ex)
  116. {
  117. m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString());
  118. }
  119. // m_lastCreatedUser = userID;
  120. break;
  121. }
  122. }
  123. public override void RunCmd(string cmd, string[] cmdparams)
  124. {
  125. base.RunCmd(cmd, cmdparams);
  126. switch (cmd)
  127. {
  128. case "help":
  129. m_console.Notice("clear-cache - Clears region cache. Should be done when regions change position. The region cache gets stale after a while.");
  130. break;
  131. case "clear-cache":
  132. int entries = msgsvc.ClearRegionCache();
  133. m_console.Notice("Region cache cleared! Cleared " + entries.ToString() + " entries");
  134. break;
  135. }
  136. }
  137. public override void Shutdown()
  138. {
  139. msgsvc.deregisterWithUserServer();
  140. base.Shutdown();
  141. }
  142. }
  143. }