Permalink
Browse files

Added Jabber Gateway script

Extended Event Notifications to support sending notifications to jabber gateway endpoints
  • Loading branch information...
kg committed Dec 15, 2010
1 parent dc8b470 commit f9aa9e986be1e99ab9a270f6df3da4eb48604e38
Showing with 1,945 additions and 29 deletions.
  1. +0 −1 Common/common.eve.py
  2. +19 −7 Common/pythonexplorer.py
  3. +11 −5 DroneHelper/dronehelper.py
  4. +6 −1 EventNotifications/EventNotifications.cs
  5. +4 −0 EventNotifications/EventNotifications.csproj
  6. +15 −3 EventNotifications/EventNotificationsConfig.Designer.cs
  7. +24 −2 EventNotifications/EventNotificationsConfig.cs
  8. +3 −0 EventNotifications/EventNotificationsConfig.resx
  9. +2 −2 EventNotifications/Properties/AssemblyInfo.cs
  10. +47 −7 EventNotifications/eventnotifications.py
  11. BIN EventNotifications/notice.wav
  12. +365 −0 JabberGateway/AddEndpointDialog.Designer.cs
  13. +114 −0 JabberGateway/AddEndpointDialog.cs
  14. +120 −0 JabberGateway/AddEndpointDialog.resx
  15. +43 −0 JabberGateway/JabberExtensions.cs
  16. +290 −0 JabberGateway/JabberGateway.cs
  17. +119 −0 JabberGateway/JabberGateway.csproj
  18. +97 −0 JabberGateway/JabberGatewayConfig.Designer.cs
  19. +112 −0 JabberGateway/JabberGatewayConfig.cs
  20. +155 −0 JabberGateway/JabberGatewayConfig.resx
  21. +36 −0 JabberGateway/Properties/AssemblyInfo.cs
  22. +63 −0 JabberGateway/Properties/Resources.Designer.cs
  23. +120 −0 JabberGateway/Properties/Resources.resx
  24. +11 −0 JabberGateway/jabber.py
  25. +2 −1 Python/SessionTimer.Script.py
  26. +6 −0 ShootBluesScripts.sln
  27. BIN ext/soapbox/Coversant.SoapBox.Administration.dll
  28. BIN ext/soapbox/Coversant.SoapBox.dll
  29. BIN ext/soapbox/Coversant.Win32.dll
  30. BIN ext/soapbox/Microsoft.ApplicationBlocks.ConfigurationManagement.Interfaces.dll
  31. BIN ext/soapbox/Microsoft.ApplicationBlocks.ConfigurationManagement.dll
  32. BIN ext/soapbox/Microsoft.ApplicationBlocks.Data.dll
  33. +18 −0 ext/soapbox/SoapBox Studio - Samples - License Agreement.txt
  34. +143 −0 ext/soapbox/SoapBox Studio - Source Code - License Agreement.txt
  35. BIN ext/soapbox/coversant.corlib.dll
View
@@ -257,7 +257,6 @@ def activateModule(module, pulse=False, targetID=None, actionThreshold=ActionThr
return (False, "too soon to activate again (lag protection)")
setattr(module, "__last_action__", timestamp)
- log("Activating %s", moduleName)
oldautorepeat = getattr(module, "autorepeat", False)
if oldautorepeat:
View
@@ -1,19 +1,28 @@
import sys
import json
import types
+import weakref
+import inspect
def tupleize(i):
- if isinstance(i, types.ListType):
- return tuple(tupleize(x) for x in i)
- else:
- return i
+ if isinstance(i, types.ListType):
+ return tuple(tupleize(x) for x in i)
+ else:
+ return i
def resolveKey(obj, key):
- if key.startswith("["):
+ if key == "<Arguments>":
+ result = inspect.getargspec(obj)
+ elif key.startswith("["):
indexer = tupleize(json.loads(key)[0])
- return obj[indexer]
+ result = obj[indexer]
else:
- return getattr(obj, key)
+ result = getattr(obj, key)
+
+ if isinstance(result, weakref.ref):
+ result = result()
+
+ return result
def getModules():
return sorted(sys.modules.keys(), key=str.lower)
@@ -42,6 +51,9 @@ def getKeys(context, index):
for key in getattr(obj, "__keys__"):
result.append(json.dumps([key]))
+ if callable(obj):
+ result.append("<Arguments>")
+
result.sort(key=str.lower)
return result
View
@@ -132,7 +132,7 @@ def getDroneControlRange(self):
) * fighterRangeMultiplier)
return result
- def getCommonTarget(self, threshold, filtered=True):
+ def getCommonTarget(self, filtered=True):
ballpark = eve.LocalSvc("michelle").GetBallpark()
targetCounts = {}
@@ -144,7 +144,7 @@ def getCommonTarget(self, threshold, filtered=True):
sortedTargets = [st[1] for st in sorted(
[(count, targetID) for targetID, count in
- targetCounts.items() if count > threshold],
+ targetCounts.items() if count > 1],
cmp=lambda lhs, rhs: -cmp(lhs, rhs)
)]
@@ -232,7 +232,7 @@ def doAttack(self, idleOnly, targetID=None, dronesToAttack=[], oldTarget=None):
timestamp = blue.os.GetTime()
isCommonTarget = False
if not targetID:
- targetID = self.getCommonTarget(len(dronesToAttack))
+ targetID = self.getCommonTarget()
if targetID:
slimItem = ballpark.GetInvItem(targetID)
if slimItem:
@@ -256,7 +256,11 @@ def doAttack(self, idleOnly, targetID=None, dronesToAttack=[], oldTarget=None):
for id in list(drones):
droneObj = self.getDroneObject(id)
- if (droneObj.state == const.entityDeparting):
+ if ((droneObj.state == const.entityDeparting) or
+ (droneObj.state == const.entityDeparting2) or
+ (droneObj.state == const.entityFleeing) or
+ (droneObj.state == const.entityPursuit)):
+ log("drone state=%r, not attacking", droneObj.state)
drones.remove(id)
elif ((droneObj.target == targetID) or
abs(droneObj.actionTimestamp - timestamp) <= ActionThreshold):
@@ -302,8 +306,10 @@ def doRecall(self, *dronesToRecall):
if ((droneObj.state == const.entityDeparting) or
(droneObj.state == const.entityDeparting2) or
(droneObj.state == const.entityPursuit) or
+ (droneObj.state == const.entityFleeing) or
abs(droneObj.actionTimestamp - timestamp) <= ActionThreshold):
dronesToRecall.remove(droneID)
+ log("drone state=%r, not recalling", droneObj.state)
if len(dronesToRecall):
entity = moniker.GetEntityAccess()
@@ -378,7 +384,7 @@ def updateDrones(self):
if len(dronesToAttack):
self.doAttack(idleOnly=True, targetID=None, dronesToAttack=dronesToAttack)
elif getPref("WhenTargetLost", False):
- commonTarget = self.getCommonTarget(3, filtered=False)
+ commonTarget = self.getCommonTarget(filtered=False)
if commonTarget == eve.session.shipid:
return
@@ -21,6 +21,8 @@ public class EventEntry {
public bool BalloonTip = false;
[Column("messageBox")]
public bool MessageBox = false;
+ [Column("jabberEndpoints")]
+ public string JabberEndpoints = null;
public EventEntry () {
}
@@ -40,6 +42,7 @@ public EventNotifications (ScriptName name)
AddDependency("Common.script.dll");
AddDependency("eventnotifications.py");
+ AddDependency("JabberGateway.script.dll", true);
CustomMenu = new ToolStripMenuItem("Event Notifications");
CustomMenu.DropDownItems.Add("Configure", null, ConfigureEventNotifications);
@@ -63,7 +66,7 @@ public EventNotifications (ScriptName name)
public override IEnumerator<object> Initialize () {
yield return Program.CreateDBTable(
"eventNotifications",
- "( key TEXT PRIMARY KEY NOT NULL, sound TEXT, balloonTip BOOLEAN NOT NULL, messageBox BOOLEAN NOT NULL )"
+ "( key TEXT PRIMARY KEY NOT NULL, sound TEXT, balloonTip BOOLEAN NOT NULL, messageBox BOOLEAN NOT NULL, jabberEndpoints TEXT )"
);
}
@@ -92,6 +95,8 @@ public EventNotifications (ScriptName name)
dict["messageBox"] = true;
if (el.Sound != null)
dict["sound"] = el.Sound;
+ if (el.JabberEndpoints != null)
+ dict["jabberEndpoints"] = el.JabberEndpoints.Split(',');
}
cfgDict[eventName] = dict;
@@ -87,6 +87,10 @@
<Name>ShootBlues</Name>
<Private>False</Private>
</ProjectReference>
+ <ProjectReference Include="..\JabberGateway\JabberGateway.csproj">
+ <Project>{A0CB0C2D-8768-4E72-80E5-3857F3000AB8}</Project>
+ <Name>JabberGateway</Name>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -21,6 +21,9 @@ public EventNotificationsConfig (EventNotifications script)
public IEnumerator<object> LoadConfiguration () {
using (new ControlWaitCursor(this)) {
+ DataGrid.RowCount = 0;
+ JabberEndpoints.Items.Clear();
+
EventEntry[] dbEvents = null;
yield return Program.Database.ExecuteArray<EventEntry>(
"SELECT * FROM eventNotifications ORDER BY key ASC"
@@ -37,6 +40,19 @@ public EventNotificationsConfig (EventNotifications script)
var newEvents = dict.Values.ToArray();
Array.Sort(newEvents, (lhs, rhs) => lhs.Key.CompareTo(rhs.Key));
+ try {
+ var jg = Program.GetScriptInstance<JabberGateway>("JabberGateway.Script.dll");
+ if (jg != null) {
+ JabberEndpoints.Items.Add(DBNull.Value);
+ JabberEndpoints.Items.AddRange(jg.Endpoints.Keys.ToArray());
+ JabberEndpoints.Visible = true;
+ } else {
+ JabberEndpoints.Visible = false;
+ }
+ } catch {
+ JabberEndpoints.Visible = false;
+ }
+
EventData = newEvents;
DataGrid.RowCount = newEvents.Length;
}
@@ -64,6 +80,9 @@ public EventNotificationsConfig (EventNotifications script)
case 3:
e.Value = row.MessageBox;
break;
+ case 4:
+ e.Value = row.JabberEndpoints;
+ break;
}
}
@@ -82,14 +101,17 @@ public EventNotificationsConfig (EventNotifications script)
case 3:
row.MessageBox = (bool)e.Value;
break;
+ case 4:
+ row.JabberEndpoints = (string)e.Value;
+ break;
}
Start(FlushRow(row));
}
protected IEnumerator<object> FlushRow (EventEntry row) {
- using (var q = Program.Database.BuildQuery("REPLACE INTO eventNotifications (key, sound, balloonTip, messageBox) VALUES (?, ?, ?, ?)"))
- yield return q.ExecuteNonQuery(row.Key, row.Sound, row.BalloonTip, row.MessageBox);
+ using (var q = Program.Database.BuildQuery("REPLACE INTO eventNotifications (key, sound, balloonTip, messageBox, jabberEndpoints) VALUES (?, ?, ?, ?, ?)"))
+ yield return q.ExecuteNonQuery(row.Key, row.Sound, row.BalloonTip, row.MessageBox, row.JabberEndpoints);
Script.Preferences.Flush();
}
@@ -129,4 +129,7 @@
<metadata name="MessageBox.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
+ <metadata name="JabberEndpoints.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
</root>
@@ -8,9 +8,9 @@
[assembly: AssemblyTitle("EventNotifications")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EventNotifications")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -1,10 +1,17 @@
from shootblues.common import log, remoteCall, playSound, showBalloonTip, showMessageBox
from shootblues.common.service import forceStart, forceStop
-from shootblues.common.messaging import subscribe, unsubscribe, send
+from shootblues.common.messaging import subscribe, unsubscribe
+from shootblues.common.messaging import send as messageSend
+import types
import json
-notificationSettings = {}
+try:
+ from shootblues.jabber import send as jabberSend
+except:
+ def jabberSend(endpoint, text):
+ pass
+notificationSettings = {}
serviceRunning = False
def notifySettingsChanged(newSettingsJson):
@@ -15,20 +22,53 @@ def notifySettingsChanged(newSettingsJson):
def DefineEvent(eventName):
remoteCall("EventNotifications.Script.dll", "DefineEvent", eventName)
+def joinLines(text):
+ if isinstance(text, str) or isinstance(text, unicode):
+ return text
+ else:
+ try:
+ iterator = iter(text)
+ del iterator
+ return "\r\n".join(list(text))
+ except TypeError:
+ return repr(text)
+
+def getLines(text):
+ if isinstance(text, str) or isinstance(text, unicode):
+ return [text]
+ else:
+ try:
+ iterator = iter(text)
+ del iterator
+ return list(text)
+ except TypeError:
+ return [repr(text)]
+
def handleEvent(source, name, data):
global notificationSettings
settings = notificationSettings.get(name, None)
if settings:
- if settings.get("sound", None):
- playSound(settings["sound"])
+ sound = data.get("sound", settings.get("sound", None))
+
+ if sound:
+ playSound(str(sound))
+
+ text = joinLines(data.get("text", source))
+
if settings.get("balloonTip", False):
- showBalloonTip(name, str(data.get("text", source)))
+ showBalloonTip(str(data.get("title", name)), text)
if settings.get("messageBox", False):
- showMessageBox(name, str(data.get("text", source)))
+ showMessageBox(str(data.get("title", name)), text)
+
+ endpoints = settings.get("jabberEndpoints", [])
+ body = getLines(data.get("text", name))
+ for endpoint in endpoints:
+ for line in body:
+ jabberSend(endpoint, line)
def fireEvent(name, **extraData):
- send(name, **extraData)
+ messageSend(name, **extraData)
def initialize():
global serviceRunning
Binary file not shown.
Oops, something went wrong.

0 comments on commit f9aa9e9

Please sign in to comment.