28 using System.Collections.Generic;
29 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Client;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
40 namespace OpenSim.
Region.CoreModules.
Avatar.InstantMessage
42 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"InstantMessageModule")]
45 private static readonly ILog m_log = LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
49 private List<GridInstantMessage> m_logData =
new List<GridInstantMessage>();
50 private string m_restUrl;
55 private bool m_enabled =
false;
57 private readonly List<Scene> m_scenes =
new List<Scene>();
59 #region Region Module interface
65 if (config.Configs[
"Messaging"] != null)
67 if (config.Configs[
"Messaging"].GetString(
68 "InstantMessageModule",
"InstantMessageModule") !=
69 "InstantMessageModule")
71 m_restUrl = config.Configs[
"Messaging"].GetString(
"LogURL", String.Empty);
75 m_logTimer.AutoReset =
false;
76 m_logTimer.Elapsed += LogTimerElapsed;
86 if (!m_scenes.Contains(scene))
89 scene.EventManager.OnClientConnect += OnClientConnect;
90 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
100 if (m_TransferModule == null)
105 if (m_TransferModule == null)
107 m_log.Error(
"[INSTANT MESSAGE]: No message transfer module, IM will not work!");
108 scene.EventManager.OnClientConnect -= OnClientConnect;
109 scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
124 m_scenes.Remove(scene);
131 if (client.TryGet(out clientIM))
133 clientIM.OnInstantMessage += OnInstantMessage;
147 get {
return "InstantMessageModule"; }
150 public Type ReplaceableInterface
159 byte dialog = im.dialog;
161 if (client != null && dialog == (byte)InstantMessageDialog.MessageFromAgent)
162 LogInstantMesssage(im);
164 if (dialog != (byte)InstantMessageDialog.MessageFromAgent
165 && dialog != (byte)InstantMessageDialog.StartTyping
166 && dialog != (byte)InstantMessageDialog.StopTyping
167 && dialog != (byte)InstantMessageDialog.BusyAutoResponse
168 && dialog != (byte)InstantMessageDialog.MessageFromObject)
197 im.timestamp = (uint)Util.UnixTimeSinceEpoch();
199 if (m_TransferModule != null)
202 im.fromAgentName = client.FirstName +
" " + client.LastName;
203 m_TransferModule.SendInstantMessage(im,
204 delegate(
bool success)
206 if (dialog == (uint)InstantMessageDialog.StartTyping ||
207 dialog == (uint)InstantMessageDialog.StopTyping ||
208 dialog == (uint)InstantMessageDialog.MessageFromObject)
213 if ((client != null) && !success)
215 client.SendInstantMessage(
217 null,
new UUID(im.fromAgentID),
"System",
218 new UUID(im.toAgentID),
219 (byte)InstantMessageDialog.BusyAutoResponse,
220 "Unable to send instant message. "+
221 "User is not logged in.",
false,
240 OnInstantMessage(null, msg);
245 if (m_logData.Count < 20)
250 if (!m_logTimer.Enabled)
259 private void LogTimerElapsed(
object source, ElapsedEventArgs e)
263 if (m_restUrl !=
String.Empty && m_logData.Count > 0)
265 bool success = SynchronousRestObjectRequester.MakeRequest<List<GridInstantMessage>,
bool>(
"POST", m_restUrl +
"/LogMessages/", m_logData);
267 m_log.ErrorFormat(
"[INSTANT MESSAGE]: Failed to save log data");
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
System.Timers.Timer Timer
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void OnInstantMessage(IClientAPI client, GridInstantMessage im)
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...