MuteListService.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.Text;
  29. using OpenMetaverse;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenSim.Services.Base;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Data;
  35. using OpenSim.Framework;
  36. namespace OpenSim.Services.EstateService
  37. {
  38. public class MuteListService : ServiceBase, IMuteListService
  39. {
  40. // private static readonly ILog m_log =
  41. // LogManager.GetLogger(
  42. // MethodBase.GetCurrentMethod().DeclaringType);
  43. protected IMuteListData m_database;
  44. public MuteListService(IConfigSource config)
  45. : base(config)
  46. {
  47. string dllName = String.Empty;
  48. string connString = String.Empty;
  49. // Try reading the [DatabaseService] section, if it exists
  50. IConfig dbConfig = config.Configs["DatabaseService"];
  51. if (dbConfig != null)
  52. {
  53. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  54. connString = dbConfig.GetString("ConnectionString", String.Empty);
  55. connString = dbConfig.GetString("MuteConnectionString", connString);
  56. }
  57. // Try reading the [MuteListStore] section, if it exists
  58. IConfig muteConfig = config.Configs["MuteListStore"];
  59. if (muteConfig != null)
  60. {
  61. dllName = muteConfig.GetString("StorageProvider", dllName);
  62. connString = muteConfig.GetString("ConnectionString", connString);
  63. }
  64. // We tried, but this doesn't exist. We can't proceed
  65. if (dllName == String.Empty)
  66. throw new Exception("No StorageProvider configured");
  67. m_database = LoadPlugin<IMuteListData>(dllName, new Object[] { connString });
  68. if (m_database == null)
  69. throw new Exception("Could not find a storage interface in the given module");
  70. }
  71. public Byte[] MuteListRequest(UUID agentID, uint crc)
  72. {
  73. if(m_database == null)
  74. return null;
  75. MuteData[] data = m_database.Get(agentID);
  76. if (data == null || data.Length == 0)
  77. return new Byte[0];
  78. StringBuilder sb = new StringBuilder(16384);
  79. foreach (MuteData d in data)
  80. sb.AppendFormat("{0} {1} {2}|{3}\n",
  81. d.MuteType,
  82. d.MuteID.ToString(),
  83. d.MuteName,
  84. d.MuteFlags);
  85. Byte[] filedata = Util.UTF8.GetBytes(sb.ToString());
  86. uint dataCrc = Crc32.Compute(filedata);
  87. if (dataCrc == crc)
  88. {
  89. if(crc == 0)
  90. return new Byte[0];
  91. Byte[] ret = new Byte[1] {1};
  92. return ret;
  93. }
  94. return filedata;
  95. }
  96. public bool UpdateMute(MuteData mute)
  97. {
  98. if(m_database == null)
  99. return false;
  100. return m_database.Store(mute);
  101. }
  102. public bool RemoveMute(UUID agentID, UUID muteID, string muteName)
  103. {
  104. if(m_database == null)
  105. return false;
  106. return m_database.Delete(agentID, muteID, muteName);
  107. }
  108. }
  109. }