ConciergeModule.cs 25 KB

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