ConciergeModule.cs 25 KB

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