ConciergeModule.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Net;
  32. using System.Net.Sockets;
  33. using System.Reflection;
  34. using System.Text;
  35. using System.Text.RegularExpressions;
  36. using System.Threading;
  37. using log4net;
  38. using Nini.Config;
  39. using Nwc.XmlRpc;
  40. using OpenMetaverse;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Region.CoreModules.Avatar.Chat;
  46. namespace OpenSim.Region.OptionalModules.Avatar.Concierge
  47. {
  48. public class ConciergeModule : ChatModule, ISharedRegionModule
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private const int DEBUG_CHANNEL = 2147483647;
  52. private List<IScene> m_scenes = new List<IScene>();
  53. private List<IScene> m_conciergedScenes = new List<IScene>();
  54. private bool m_replacingChatModule = false;
  55. private IConfig m_config;
  56. private string m_whoami = "conferencier";
  57. private Regex m_regions = null;
  58. private string m_welcomes = null;
  59. private int m_conciergeChannel = 42;
  60. private string m_announceEntering = "{0} enters {1} (now {2} visitors in this region)";
  61. private string m_announceLeaving = "{0} leaves {1} (back to {2} visitors in this region)";
  62. private string m_xmlRpcPassword = String.Empty;
  63. private string m_brokerURI = String.Empty;
  64. private int m_brokerUpdateTimeout = 300;
  65. internal object m_syncy = new object();
  66. internal bool m_enabled = false;
  67. #region ISharedRegionModule Members
  68. public override void Initialise(IConfigSource config)
  69. {
  70. m_config = config.Configs["Concierge"];
  71. if (null == m_config)
  72. {
  73. m_log.Info("[Concierge]: no config found, plugin disabled");
  74. return;
  75. }
  76. if (!m_config.GetBoolean("enabled", false))
  77. {
  78. m_log.Info("[Concierge]: plugin disabled by configuration");
  79. return;
  80. }
  81. m_enabled = true;
  82. // check whether ChatModule has been disabled: if yes,
  83. // then we'll "stand in"
  84. try
  85. {
  86. if (config.Configs["Chat"] == null)
  87. {
  88. // if Chat module has not been configured it's
  89. // enabled by default, so we are not going to
  90. // replace it.
  91. m_replacingChatModule = false;
  92. }
  93. else
  94. {
  95. m_replacingChatModule = !config.Configs["Chat"].GetBoolean("enabled", true);
  96. }
  97. }
  98. catch (Exception)
  99. {
  100. m_replacingChatModule = false;
  101. }
  102. m_log.InfoFormat("[Concierge] {0} ChatModule", m_replacingChatModule ? "replacing" : "not replacing");
  103. // take note of concierge channel and of identity
  104. m_conciergeChannel = config.Configs["Concierge"].GetInt("concierge_channel", m_conciergeChannel);
  105. m_whoami = m_config.GetString("whoami", "conferencier");
  106. m_welcomes = m_config.GetString("welcomes", m_welcomes);
  107. m_announceEntering = m_config.GetString("announce_entering", m_announceEntering);
  108. m_announceLeaving = m_config.GetString("announce_leaving", m_announceLeaving);
  109. m_xmlRpcPassword = m_config.GetString("password", m_xmlRpcPassword);
  110. m_brokerURI = m_config.GetString("broker", m_brokerURI);
  111. m_brokerUpdateTimeout = m_config.GetInt("broker_timeout", m_brokerUpdateTimeout);
  112. m_log.InfoFormat("[Concierge] reporting as \"{0}\" to our users", m_whoami);
  113. // calculate regions Regex
  114. if (m_regions == null)
  115. {
  116. string regions = m_config.GetString("regions", String.Empty);
  117. if (!String.IsNullOrEmpty(regions))
  118. {
  119. m_regions = new Regex(@regions, RegexOptions.Compiled | RegexOptions.IgnoreCase);
  120. }
  121. }
  122. }
  123. public override void AddRegion(Scene scene)
  124. {
  125. if (!m_enabled) return;
  126. MainServer.Instance.AddXmlRPCHandler("concierge_update_welcome", XmlRpcUpdateWelcomeMethod, false);
  127. lock (m_syncy)
  128. {
  129. if (!m_scenes.Contains(scene))
  130. {
  131. m_scenes.Add(scene);
  132. if (m_regions == null || m_regions.IsMatch(scene.RegionInfo.RegionName))
  133. m_conciergedScenes.Add(scene);
  134. // subscribe to NewClient events
  135. scene.EventManager.OnNewClient += OnNewClient;
  136. // subscribe to *Chat events
  137. scene.EventManager.OnChatFromWorld += OnChatFromWorld;
  138. if (!m_replacingChatModule)
  139. scene.EventManager.OnChatFromClient += OnChatFromClient;
  140. scene.EventManager.OnChatBroadcast += OnChatBroadcast;
  141. // subscribe to agent change events
  142. scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
  143. scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
  144. }
  145. }
  146. m_log.InfoFormat("[Concierge]: initialized for {0}", scene.RegionInfo.RegionName);
  147. }
  148. public override void RemoveRegion(Scene scene)
  149. {
  150. if (!m_enabled) return;
  151. MainServer.Instance.RemoveXmlRPCHandler("concierge_update_welcome");
  152. lock (m_syncy)
  153. {
  154. // unsubscribe from NewClient events
  155. scene.EventManager.OnNewClient -= OnNewClient;
  156. // unsubscribe from *Chat events
  157. scene.EventManager.OnChatFromWorld -= OnChatFromWorld;
  158. if (!m_replacingChatModule)
  159. scene.EventManager.OnChatFromClient -= OnChatFromClient;
  160. scene.EventManager.OnChatBroadcast -= OnChatBroadcast;
  161. // unsubscribe from agent change events
  162. scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent;
  163. scene.EventManager.OnMakeChildAgent -= OnMakeChildAgent;
  164. if (m_scenes.Contains(scene))
  165. {
  166. m_scenes.Remove(scene);
  167. }
  168. if (m_conciergedScenes.Contains(scene))
  169. {
  170. m_conciergedScenes.Remove(scene);
  171. }
  172. }
  173. m_log.InfoFormat("[Concierge]: removed {0}", scene.RegionInfo.RegionName);
  174. }
  175. public override void PostInitialise()
  176. {
  177. }
  178. public override void Close()
  179. {
  180. }
  181. new public Type ReplaceableInterface
  182. {
  183. get { return null; }
  184. }
  185. public override string Name
  186. {
  187. get { return "ConciergeModule"; }
  188. }
  189. #endregion
  190. #region ISimChat Members
  191. public override void OnChatBroadcast(Object sender, OSChatMessage c)
  192. {
  193. if (m_replacingChatModule)
  194. {
  195. // distribute chat message to each and every avatar in
  196. // the region
  197. base.OnChatBroadcast(sender, c);
  198. }
  199. // TODO: capture logic
  200. return;
  201. }
  202. public override void OnChatFromClient(Object sender, OSChatMessage c)
  203. {
  204. if (m_replacingChatModule)
  205. {
  206. // replacing ChatModule: need to redistribute
  207. // ChatFromClient to interested subscribers
  208. c = FixPositionOfChatMessage(c);
  209. Scene scene = (Scene)c.Scene;
  210. scene.EventManager.TriggerOnChatFromClient(sender, c);
  211. if (m_conciergedScenes.Contains(c.Scene))
  212. {
  213. // when we are replacing ChatModule, we treat
  214. // OnChatFromClient like OnChatBroadcast for
  215. // concierged regions, effectively extending the
  216. // range of chat to cover the whole
  217. // region. however, we don't do this for whisper
  218. // (got to have some privacy)
  219. if (c.Type != ChatTypeEnum.Whisper)
  220. {
  221. base.OnChatBroadcast(sender, c);
  222. return;
  223. }
  224. }
  225. // redistribution will be done by base class
  226. base.OnChatFromClient(sender, c);
  227. }
  228. // TODO: capture chat
  229. return;
  230. }
  231. public override void OnChatFromWorld(Object sender, OSChatMessage c)
  232. {
  233. if (m_replacingChatModule)
  234. {
  235. if (m_conciergedScenes.Contains(c.Scene))
  236. {
  237. // when we are replacing ChatModule, we treat
  238. // OnChatFromClient like OnChatBroadcast for
  239. // concierged regions, effectively extending the
  240. // range of chat to cover the whole
  241. // region. however, we don't do this for whisper
  242. // (got to have some privacy)
  243. if (c.Type != ChatTypeEnum.Whisper)
  244. {
  245. base.OnChatBroadcast(sender, c);
  246. return;
  247. }
  248. }
  249. base.OnChatFromWorld(sender, c);
  250. }
  251. return;
  252. }
  253. #endregion
  254. public override void OnNewClient(IClientAPI client)
  255. {
  256. client.OnLogout += OnClientLoggedOut;
  257. if (m_replacingChatModule)
  258. client.OnChatFromClient += OnChatFromClient;
  259. }
  260. public void OnClientLoggedOut(IClientAPI client)
  261. {
  262. client.OnLogout -= OnClientLoggedOut;
  263. client.OnConnectionClosed -= OnClientLoggedOut;
  264. if (m_conciergedScenes.Contains(client.Scene))
  265. {
  266. Scene scene = client.Scene as Scene;
  267. m_log.DebugFormat("[Concierge]: {0} logs off from {1}", client.Name, scene.RegionInfo.RegionName);
  268. List<ScenePresence> avs = scene.GetAvatars();
  269. AnnounceToAgentsRegion(scene, String.Format(m_announceLeaving, client.Name, scene.RegionInfo.RegionName, avs.Count));
  270. UpdateBroker(scene, avs);
  271. }
  272. }
  273. public void OnMakeRootAgent(ScenePresence agent)
  274. {
  275. if (m_conciergedScenes.Contains(agent.Scene))
  276. {
  277. Scene scene = agent.Scene;
  278. m_log.DebugFormat("[Concierge]: {0} enters {1}", agent.Name, scene.RegionInfo.RegionName);
  279. List<ScenePresence> avs = scene.GetAvatars();
  280. WelcomeAvatar(agent, scene);
  281. AnnounceToAgentsRegion(scene, String.Format(m_announceEntering, agent.Name,
  282. scene.RegionInfo.RegionName, avs.Count));
  283. UpdateBroker(scene, avs);
  284. }
  285. }
  286. public void OnMakeChildAgent(ScenePresence agent)
  287. {
  288. if (m_conciergedScenes.Contains(agent.Scene))
  289. {
  290. Scene scene = agent.Scene;
  291. m_log.DebugFormat("[Concierge]: {0} leaves {1}", agent.Name, scene.RegionInfo.RegionName);
  292. List<ScenePresence> avs = scene.GetAvatars();
  293. AnnounceToAgentsRegion(scene, String.Format(m_announceLeaving, agent.Name,
  294. scene.RegionInfo.RegionName, avs.Count));
  295. UpdateBroker(scene, avs);
  296. }
  297. }
  298. internal class BrokerState
  299. {
  300. public string Uri;
  301. public string Payload;
  302. public HttpWebRequest Poster;
  303. public Timer Timer;
  304. public BrokerState(string uri, string payload, HttpWebRequest poster)
  305. {
  306. Uri = uri;
  307. Payload = payload;
  308. Poster = poster;
  309. }
  310. }
  311. protected void UpdateBroker(IScene scene, List<ScenePresence> avatars)
  312. {
  313. if (String.IsNullOrEmpty(m_brokerURI))
  314. return;
  315. string uri = String.Format(m_brokerURI, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);
  316. // create XML sniplet
  317. StringBuilder list = new StringBuilder();
  318. if (0 == avatars.Count)
  319. {
  320. list.Append(String.Format("<avatars count=\"0\" region_name=\"{0}\" region_uuid=\"{1}\" timestamp=\"{2}\" />",
  321. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  322. DateTime.UtcNow.ToString("s")));
  323. }
  324. else
  325. {
  326. list.Append(String.Format("<avatars count=\"{0}\" region_name=\"{1}\" region_uuid=\"{2}\" timestamp=\"{3}\">\n",
  327. avatars.Count, scene.RegionInfo.RegionName,
  328. scene.RegionInfo.RegionID,
  329. DateTime.UtcNow.ToString("s")));
  330. foreach (ScenePresence av in avatars)
  331. {
  332. list.Append(String.Format(" <avatar name=\"{0}\" uuid=\"{1}\" />\n", av.Name, av.UUID));
  333. }
  334. list.Append("</avatars>");
  335. }
  336. string payload = list.ToString();
  337. // post via REST to broker
  338. HttpWebRequest updatePost = WebRequest.Create(uri) as HttpWebRequest;
  339. updatePost.Method = "POST";
  340. updatePost.ContentType = "text/xml";
  341. updatePost.ContentLength = payload.Length;
  342. updatePost.UserAgent = "OpenSim.Concierge";
  343. BrokerState bs = new BrokerState(uri, payload, updatePost);
  344. bs.Timer = new Timer(delegate(object state)
  345. {
  346. BrokerState b = state as BrokerState;
  347. b.Poster.Abort();
  348. b.Timer.Dispose();
  349. m_log.Debug("[Concierge]: async broker POST abort due to timeout");
  350. }, bs, m_brokerUpdateTimeout * 1000, Timeout.Infinite);
  351. try
  352. {
  353. updatePost.BeginGetRequestStream(UpdateBrokerSend, bs);
  354. m_log.DebugFormat("[Concierge] async broker POST to {0} started", uri);
  355. }
  356. catch (WebException we)
  357. {
  358. m_log.ErrorFormat("[Concierge] async broker POST to {0} failed: {1}", uri, we.Status);
  359. }
  360. }
  361. private void UpdateBrokerSend(IAsyncResult result)
  362. {
  363. BrokerState bs = null;
  364. try
  365. {
  366. bs = result.AsyncState as BrokerState;
  367. string payload = bs.Payload;
  368. HttpWebRequest updatePost = bs.Poster;
  369. using (StreamWriter payloadStream = new StreamWriter(updatePost.EndGetRequestStream(result)))
  370. {
  371. payloadStream.Write(payload);
  372. payloadStream.Close();
  373. }
  374. updatePost.BeginGetResponse(UpdateBrokerDone, bs);
  375. }
  376. catch (WebException we)
  377. {
  378. m_log.DebugFormat("[Concierge]: async broker POST to {0} failed: {1}", bs.Uri, we.Status);
  379. }
  380. catch (Exception)
  381. {
  382. m_log.DebugFormat("[Concierge]: async broker POST to {0} failed", bs.Uri);
  383. }
  384. }
  385. private void UpdateBrokerDone(IAsyncResult result)
  386. {
  387. BrokerState bs = null;
  388. try
  389. {
  390. bs = result.AsyncState as BrokerState;
  391. HttpWebRequest updatePost = bs.Poster;
  392. using (HttpWebResponse response = updatePost.EndGetResponse(result) as HttpWebResponse)
  393. {
  394. m_log.DebugFormat("[Concierge] broker update: status {0}", response.StatusCode);
  395. }
  396. bs.Timer.Dispose();
  397. }
  398. catch (WebException we)
  399. {
  400. m_log.ErrorFormat("[Concierge] broker update to {0} failed with status {1}", bs.Uri, we.Status);
  401. if (null != we.Response)
  402. {
  403. using (HttpWebResponse resp = we.Response as HttpWebResponse)
  404. {
  405. m_log.ErrorFormat("[Concierge] response from {0} status code: {1}", bs.Uri, resp.StatusCode);
  406. m_log.ErrorFormat("[Concierge] response from {0} status desc: {1}", bs.Uri, resp.StatusDescription);
  407. m_log.ErrorFormat("[Concierge] response from {0} server: {1}", bs.Uri, resp.Server);
  408. if (resp.ContentLength > 0)
  409. {
  410. StreamReader content = new StreamReader(resp.GetResponseStream());
  411. m_log.ErrorFormat("[Concierge] response from {0} content: {1}", bs.Uri, content.ReadToEnd());
  412. content.Close();
  413. }
  414. }
  415. }
  416. }
  417. }
  418. protected void WelcomeAvatar(ScenePresence agent, Scene scene)
  419. {
  420. // welcome mechanics: check whether we have a welcomes
  421. // directory set and wether there is a region specific
  422. // welcome file there: if yes, send it to the agent
  423. if (!String.IsNullOrEmpty(m_welcomes))
  424. {
  425. string[] welcomes = new string[] {
  426. Path.Combine(m_welcomes, agent.Scene.RegionInfo.RegionName),
  427. Path.Combine(m_welcomes, "DEFAULT")};
  428. foreach (string welcome in welcomes)
  429. {
  430. if (File.Exists(welcome))
  431. {
  432. try
  433. {
  434. string[] welcomeLines = File.ReadAllLines(welcome);
  435. foreach (string l in welcomeLines)
  436. {
  437. AnnounceToAgent(agent, String.Format(l, agent.Name, scene.RegionInfo.RegionName, m_whoami));
  438. }
  439. }
  440. catch (IOException ioe)
  441. {
  442. m_log.ErrorFormat("[Concierge]: run into trouble reading welcome file {0} for region {1} for avatar {2}: {3}",
  443. welcome, scene.RegionInfo.RegionName, agent.Name, ioe);
  444. }
  445. catch (FormatException fe)
  446. {
  447. m_log.ErrorFormat("[Concierge]: welcome file {0} is malformed: {1}", welcome, fe);
  448. }
  449. }
  450. return;
  451. }
  452. m_log.DebugFormat("[Concierge]: no welcome message for region {0}", scene.RegionInfo.RegionName);
  453. }
  454. }
  455. static private Vector3 PosOfGod = new Vector3(128, 128, 9999);
  456. // protected void AnnounceToAgentsRegion(Scene scene, string msg)
  457. // {
  458. // ScenePresence agent = null;
  459. // if ((client.Scene is Scene) && (client.Scene as Scene).TryGetAvatar(client.AgentId, out agent))
  460. // AnnounceToAgentsRegion(agent, msg);
  461. // else
  462. // m_log.DebugFormat("[Concierge]: could not find an agent for client {0}", client.Name);
  463. // }
  464. protected void AnnounceToAgentsRegion(IScene scene, string msg)
  465. {
  466. OSChatMessage c = new OSChatMessage();
  467. c.Message = msg;
  468. c.Type = ChatTypeEnum.Say;
  469. c.Channel = 0;
  470. c.Position = PosOfGod;
  471. c.From = m_whoami;
  472. c.Sender = null;
  473. c.SenderUUID = UUID.Zero;
  474. c.Scene = scene;
  475. if (scene is Scene)
  476. (scene as Scene).EventManager.TriggerOnChatBroadcast(this, c);
  477. }
  478. protected void AnnounceToAgent(ScenePresence agent, string msg)
  479. {
  480. OSChatMessage c = new OSChatMessage();
  481. c.Message = msg;
  482. c.Type = ChatTypeEnum.Say;
  483. c.Channel = 0;
  484. c.Position = PosOfGod;
  485. c.From = m_whoami;
  486. c.Sender = null;
  487. c.SenderUUID = UUID.Zero;
  488. c.Scene = agent.Scene;
  489. agent.ControllingClient.SendChatMessage(msg, (byte) ChatTypeEnum.Say, PosOfGod, m_whoami, UUID.Zero,
  490. (byte)ChatSourceType.Object, (byte)ChatAudibleLevel.Fully);
  491. }
  492. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  493. {
  494. Hashtable requestData = (Hashtable) request.Params[0];
  495. foreach (string p in param)
  496. {
  497. if (!requestData.Contains(p))
  498. throw new Exception(String.Format("missing string parameter {0}", p));
  499. if (String.IsNullOrEmpty((string)requestData[p]))
  500. throw new Exception(String.Format("parameter {0} is empty", p));
  501. }
  502. }
  503. public XmlRpcResponse XmlRpcUpdateWelcomeMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  504. {
  505. m_log.Info("[Concierge]: processing UpdateWelcome request");
  506. XmlRpcResponse response = new XmlRpcResponse();
  507. Hashtable responseData = new Hashtable();
  508. try
  509. {
  510. Hashtable requestData = (Hashtable)request.Params[0];
  511. checkStringParameters(request, new string[] { "password", "region", "welcome" });
  512. // check password
  513. if (!String.IsNullOrEmpty(m_xmlRpcPassword) &&
  514. (string)requestData["password"] != m_xmlRpcPassword) throw new Exception("wrong password");
  515. if (String.IsNullOrEmpty(m_welcomes))
  516. throw new Exception("welcome templates are not enabled, ask your OpenSim operator to set the \"welcomes\" option in the [Concierge] section of OpenSim.ini");
  517. string msg = (string)requestData["welcome"];
  518. if (String.IsNullOrEmpty(msg))
  519. throw new Exception("empty parameter \"welcome\"");
  520. string regionName = (string)requestData["region"];
  521. IScene scene = m_scenes.Find(delegate(IScene s) { return s.RegionInfo.RegionName == regionName; });
  522. if (scene == null)
  523. throw new Exception(String.Format("unknown region \"{0}\"", regionName));
  524. if (!m_conciergedScenes.Contains(scene))
  525. throw new Exception(String.Format("region \"{0}\" is not a concierged region.", regionName));
  526. string welcome = Path.Combine(m_welcomes, regionName);
  527. if (File.Exists(welcome))
  528. {
  529. m_log.InfoFormat("[Concierge]: UpdateWelcome: updating existing template \"{0}\"", welcome);
  530. string welcomeBackup = String.Format("{0}~", welcome);
  531. if (File.Exists(welcomeBackup))
  532. File.Delete(welcomeBackup);
  533. File.Move(welcome, welcomeBackup);
  534. }
  535. File.WriteAllText(welcome, msg);
  536. responseData["success"] = "true";
  537. response.Value = responseData;
  538. }
  539. catch (Exception e)
  540. {
  541. m_log.InfoFormat("[Concierge]: UpdateWelcome failed: {0}", e.Message);
  542. responseData["success"] = "false";
  543. responseData["error"] = e.Message;
  544. response.Value = responseData;
  545. }
  546. m_log.Debug("[Concierge]: done processing UpdateWelcome request");
  547. return response;
  548. }
  549. }
  550. }