1
0

ConciergeModule.cs 25 KB

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