28 using System.Collections.Generic;
29 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Servers;
36 using OpenSim.Framework.Client;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
43 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"OfflineIMConnectorModule")]
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private bool m_Enabled =
false;
49 private List<Scene> m_SceneList =
new List<Scene>();
51 private bool m_ForwardOfflineGroupMessages =
true;
57 IConfig cnf = config.Configs[
"Messaging"];
60 if (cnf != null && cnf.GetString(
"OfflineMessageModule",
string.Empty) != Name)
65 string serviceLocation = cnf.GetString(
"OfflineMessageURL", string.Empty);
66 if (serviceLocation ==
string.Empty)
71 m_ForwardOfflineGroupMessages = cnf.GetBoolean(
"ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages);
72 m_log.DebugFormat(
"[OfflineIM.V2]: Offline messages enabled by {0}", Name);
81 m_SceneList.Add(scene);
82 scene.EventManager.OnNewClient += OnNewClient;
90 if (m_TransferModule == null)
93 if (m_TransferModule == null)
95 scene.EventManager.OnNewClient -= OnNewClient;
99 m_log.Error(
"[OfflineIM.V2]: No message transfer module is enabled. Disabling offline messages");
110 m_SceneList.Remove(scene);
111 scene.EventManager.OnNewClient -= OnNewClient;
114 scene.ForEachClient(delegate(
IClientAPI client)
117 client.OnMuteListRequest -= OnMuteListRequest;
127 get {
return "Offline Message Module V2"; }
130 public Type ReplaceableInterface
140 private Scene FindScene(UUID agentID)
142 foreach (
Scene s
in m_SceneList)
153 foreach (
Scene s
in m_SceneList)
157 return presence.ControllingClient;
165 client.OnMuteListRequest += OnMuteListRequest;
170 m_log.DebugFormat(
"[OfflineIM.V2]: Retrieving stored messages for {0}", client.AgentId);
172 List<GridInstantMessage> msglist = m_OfflineIMService.GetMessages(client.AgentId);
175 m_log.DebugFormat(
"[OfflineIM.V2]: WARNING null message list.");
179 if (im.
dialog == (byte)InstantMessageDialog.InventoryOffered)
192 s.EventManager.TriggerIncomingInstantMessage(im);
198 private void OnMuteListRequest(
IClientAPI client, uint crc)
200 m_log.DebugFormat(
"[OfflineIM.V2] Got mute list request for crc {0}", crc);
201 string filename =
"mutes" + client.AgentId.ToString();
203 IXfer xfer = client.Scene.RequestModuleInterface<
IXfer>();
206 xfer.AddNewFile(filename,
new Byte[0]);
207 client.SendMuteListUpdate(filename);
213 if (im.
dialog != (byte)InstantMessageDialog.MessageFromObject &&
214 im.
dialog != (byte)InstantMessageDialog.MessageFromAgent &&
215 im.
dialog != (byte)InstantMessageDialog.GroupNotice &&
216 im.
dialog != (byte)InstantMessageDialog.GroupInvitation &&
217 im.
dialog != (byte)InstantMessageDialog.InventoryOffered)
222 if (!m_ForwardOfflineGroupMessages)
224 if (im.
dialog == (byte)InstantMessageDialog.GroupNotice ||
225 im.
dialog == (byte)InstantMessageDialog.GroupInvitation)
229 string reason = string.Empty;
230 bool success = m_OfflineIMService.StoreMessage(im, out reason);
232 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
239 null,
new UUID(im.toAgentID),
240 "System",
new UUID(im.fromAgentID),
241 (byte)InstantMessageDialog.MessageFromAgent,
242 "User is not logged in. " +
243 (success ?
"Message saved." :
"Message not saved: " + reason),
244 false,
new Vector3()));
252 return m_OfflineIMService.GetMessages(principalID);
257 return m_OfflineIMService.StoreMessage(im, out reason);
262 m_OfflineIMService.DeleteMessages(userID);
delegate void UndeliveredMessage(GridInstantMessage im)
void DeleteMessages(UUID userID)
Delete messages to or from this user (or group).
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
List< GridInstantMessage > GetMessages(UUID principalID)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
bool StoreMessage(GridInstantMessage im, out string reason)
Interactive OpenSim region server
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void SendInstantMessage(GridInstantMessage im)
delegate void RetrieveInstantMessages(IClientAPI client)