-
Notifications
You must be signed in to change notification settings - Fork 9
/
ERA.pyw
executable file
·540 lines (433 loc) · 16.4 KB
/
ERA.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/usr/bin/env python
# ERA.py
# EVEOnline Ratting Assistant
#
# AFK away and listen for a ding.
#
# Written in python for you Alex....
#
# Copyright (c) 2015, QQHeresATissue <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
###############################################################################
from time import gmtime
import time
from threading import *
import sys
from datetime import datetime, timedelta, date
import re
import json
import os
import platform
import logging
from utils import EVEDir
# Do initial checks, code taken from Pyfa... cause that shit rocks
if sys.version_info < (2,6) or sys.version_info > (3,0):
print("ERA requires python 2.7\nExiting.")
time.sleep(10)
sys.exit(1)
try:
import wxversion
except ImportError:
print("Cannot find wxPython\nYou can download wxPython (2.8) from http://www.wxpython.org/")
time.sleep(10)
sys.exit(1)
try:
wxversion.select('2.8')
except wxversion.VersionError:
try:
wxversion.ensureMinimal('2.8')
except wxversion.VersionError:
print("Installed wxPython version doesn't meet requirements.\nYou can download wxPython (2.8) from http://www.wxpython.org/")
time.sleep(10)
sys.exit(1)
else:
print("wxPython 2.8 not found; attempting to use newer version, expect errors")
import wx
import wx.media
# set a version
ver = "1.0.8"
# supress errors (comment out for verbosity)
sys.tracebacklimit = 0
ID_HOSTILE_START = wx.NewId()
ID_LOOT_START = wx.NewId()
# Get current working direcroty
era_dir = os.path.dirname(__file__)
# Set wav names
hostile_sound = os.path.join( era_dir, "sounds", "hostile.wav")
done_sound = os.path.join( era_dir, "sounds", "sites_done.wav")
tags_and_ammo = os.path.join ( era_dir, "sounds", "cash_money.wav")
# Are we on windows or linux?
which_os = platform.system()
if which_os == "Windows":
import winsound
from winsound import PlaySound, SND_FILENAME
# Setup a class for text redirection
class RedirectText(object):
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
# Write string to wx window
def write(self,string):
wx.CallAfter(self.out.AppendText, string)
# Main form for graphical ERA
class era(wx.Frame):
def __init__(self,parent,id):
# Create the main window with the title ERA <version number>
wx.Frame.__init__(self,parent,id,'ERA %s' % ver, size=(800,365), style = wx.DEFAULT_FRAME_STYLE)
menubar = wx.MenuBar()
fileMenu = wx.Menu()
settingsMenu = wx.Menu()
fitem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit ERA')
self.debug = settingsMenu.Append(wx.ID_ANY, 'Enable Debugging',
'Enable Debugging', kind=wx.ITEM_CHECK)
settingsMenu.Check(self.debug.GetId(), False)
self.Bind(wx.EVT_MENU, self.Close, fitem)
self.Bind(wx.EVT_MENU, self.toggle_debug, self.debug)
menubar.Append(fileMenu, '&File')
menubar.Append(settingsMenu, '&Settings')
self.SetMenuBar(menubar)
# Event used to close the script
self.Bind(wx.EVT_CLOSE, self.Close)
# Create a panel in the windows
self.panel = wx.Panel(self)
# Setup logging early so we see it in the panel
logbox = wx.TextCtrl(self.panel, wx.ID_ANY, size = (780, 290), pos = (10,40), style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
# Redirect all printed messages to the panel
redir = RedirectText(logbox)
sys.stdout = redir
sys.stderr = redir
# Create a start and stop button
self.hostile_watch = wx.ToggleButton(self.panel, ID_HOSTILE_START, label="Hostile Watch", pos=(595,10), size=(95,25))
self.loot_watch = wx.ToggleButton(self.panel, ID_LOOT_START, label="Loot Watch", pos=(125, 10), size=(90,25))
# Create dropdown for update interval on the loot watcher
check_interval = [ '15', '30', '45', '60', '75', '90' ]
# Create text "Interval" before the dropdown
wx.StaticText(self.panel, -1, 'Interval', (10,15))
# Create the dropdown and populate with the list
era.check_interval = wx.ComboBox(self.panel, -1, '', pos=(65,10), size=(60,25), choices = check_interval, style=wx.CB_DROPDOWN)
# Set 60 seconds as the default (count starts from 0)
era.check_interval.SetSelection(3)
# Define regions we have systems for in a list
region_list = [ 'dek', 'brn', 'ftn', 'fade', 'tnl', 'tri', 'vnl', 'vale', 'cr' ]
# Create text "Region" before the dropdown box
wx.StaticText(self.panel, -1, 'Region', (225,15))
# Create the dropdown box
era.region_select = wx.ComboBox(self.panel, -1, pos=(280,10), size=(75,25), choices = region_list, style=wx.CB_DROPDOWN)
# Use DEK as a default selection
era.region_select.SetSelection(0)
# Load triggers from json courtesty of Orestus, Narex Vivari for adding auto complete.
self.load_region(era.region_select.GetValue());
era.region_select.Bind(wx.EVT_COMBOBOX, self.region_selection_changed, era.region_select)
#Create the system input box
wx.StaticText(self.panel, -1, 'System', (360, 15))
era.system_select = wx.TextCtrl(self.panel, -1, '', pos=(410,10), size=(75,-1))
era.system_select.Bind(wx.EVT_TEXT, self.system_text_changed, era.system_select)
# Create the range input box
range_list = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]
wx.StaticText(self.panel, -1, 'Range', (490, 15))
era.range_select = wx.ComboBox(self.panel, -1, '', pos=(535,10), size=(60,25), choices = range_list, style=wx.CB_DROPDOWN)
era.range_select.SetSelection(5)
# Bind button clicks to events (start|stop)
self.Bind(wx.EVT_TOGGLEBUTTON, self.hostile_run, id=ID_HOSTILE_START)
self.Bind(wx.EVT_TOGGLEBUTTON, self.loot_run, id=ID_LOOT_START)
# Set a watch variable to check later. If we want the process to stop, self.watch becomes 1
self.hostile_watcher = None
self.loot_watcher = None
self.timer = wx.Timer(self)
# Shameless self adversiting
print "EVEOnline Ratting Assistant v%s by QQHeresATissue" % ver
def region_selection_changed(self, event):
self.load_region(era.region_select.GetValue())
def system_text_changed(self, event):
if which_os == "Linux":
caret = era.system_select.GetInsertionPoint() + 1
else:
caret = era.system_select.GetInsertionPoint()
partial = era.system_select.GetValue()[:caret]
match = self.match_partial_system(partial)
if match != None and len(partial) > 0:
era.system_select.ChangeValue(match)
else:
era.system_select.ChangeValue(partial)
era.system_select.SetInsertionPoint(caret)
def match_partial_system(self, text):
for system in era.current_region:
if bool(re.match(text, system['name'], re.I)):
return system['name']
return None
def load_region(self, region):
json_data = open(os.path.join( era_dir, "regions", "%s.json" % str(region)))
era.current_region = json.load(json_data)
json_data.close()
# Setup a functions to start the watcher thread
def hostile_run(self, event):
if not self.hostile_watcher:
self.hostile_watch.SetLabel("Pause Hostile")
self.hostile_watcher = StartHOSTILE(self)
else:
self.hostile_watch.SetLabel("Hostile Watch")
# abort the thread
self.hostile_watcher.abort()
# set back to None so we can start it again
self.hostile_watcher = None
def loot_run(self, event):
if not self.loot_watcher:
self.loot_watch.SetLabel("Pause Loot")
self.loot_watcher = StartLOOT(self)
else:
self.loot_watch.SetLabel("Loot Watch")
# abort the thread
self.loot_watcher.abort()
# set back to None so we can start it again
self.loot_watcher = None
def Close(self, event):
self.Destroy()
# This is rather bad and probably doesnt work... fix me
def toggle_debug(self, event):
if self.debug.IsChecked():
print "Debugging enabled"
sys.tracebacklimit = 1
else:
sys.tracebacklimit = 0
# Define watcher thread
class StartHOSTILE(Thread):
def __init__(self, threadID):
Thread.__init__(self)
# Kill the thread when the main process is exited
self.daemon = True
self.threadID = threadID
self._want_abort = 0
self.start()
def abort(self):
print "Stopping the Hostile thread\n"
self._want_abort = 1
# setup our log file watcher, only open it once and update when a new line is written
def hostile_watch(self, logfile):
fp = open(logfile, 'r')
while self._want_abort == 0:
# remove null padding (lol ccp)
new = re.sub(r'[^\x20-\x7e]', '', fp.readline())
if new:
relevant_system = self.find_system_in_string(new)
if relevant_system:
yield (relevant_system, new)
else:
time.sleep(0.01)
# Start the main thread for alerting
def run(self):
print "Starting the Hostile Watcher"
hostile_logdir = EVEDir.chat_logs
# get region based on our dropdown box selection
region = era.region_select.GetValue()
# get the system based on our system input
system = era.system_select.GetValue()
# select identified logs and sort by date
hostile_tmp = sorted([ f for f in os.listdir(hostile_logdir) if f.startswith("%s.imperium" % str(region))])
# testing line so we shit up Corp chat not intel chans
# hostile_tmp = sorted([ f for f in os.listdir(hostile_logdir) if f.startswith('Corp')])
# grab the most recent file for each log, handle the error if it doesn't exist
try:
logfile = os.path.join( hostile_logdir, hostile_tmp[-1] )
except:
print "There don't appear to be any log files here at: %s" % hostile_logdir
self.abort()
exit()
# ignore status requests and clr reports
status_words = [ "status",
"Status",
"clear",
"Clear",
"stat",
"Stat",
"clr",
"Clr",
"EVE System" ]
# Print some initial info lines
print "parsing from - Intel: %s\n" % (hostile_tmp[-1])
# if the word matches a trigger, move on
for related_system, hostile_hit_sentence in self.hostile_watch(logfile):
#print "%r | %r | %r | %r" % (related_system, self.hostile_words, hostile_hit_sentence)
# if someone is just asking for status, ignore the hit
if not any(status_word in hostile_hit_sentence for status_word in status_words):
# find distance to the reported system
distance = self.find_system_distance(system, related_system, int(era.range_select.GetValue()))
if distance != None:
# get the current time for each event
hit_time = time.strftime('%H:%M:%S')
# get current date/time in UTC
utc = time.strftime('[ %Y.%m.%d %H:%M', gmtime())[:17]
# print the alert
if which_os == "Windows":
print "%s - HOSTILE ALERT!!\n" % (hit_time)
print "%r (%s jumps)\n" % (hostile_hit_sentence, distance)
wx.Yield()
else:
print "%s - HOSTILE ALERT!!" % (hit_time)
print "%r (%s jumps)\n" % (hostile_hit_sentence, distance)
wx.Yield()
# play a tone to get attention, only if its recent!
if utc in hostile_hit_sentence:
if which_os == "Linux":
os.system("aplay -q %r" % hostile_sound)
elif which_os == "Windows":
winsound.PlaySound("%s" % hostile_sound,SND_FILENAME)
elif which_os == "Darwin":
os.system("afplay %r" % hostile_sound)
def find_system_in_string(self, string):
for system in era.current_region:
if system['name'] in string:
return system['name']
return None
def find_system_distance(self, start_system, dest_system, range):
routes_found = []
# find the distance of all routes from start system to destination system
self.system_distance_recursive(start_system, dest_system, 0, range, [], routes_found)
# return shortest path
return min(routes_found) if len(routes_found) else None
def system_distance_recursive(self, cur_system, dest_system, distance, range, checked, routes_found):
# exit if out of range or system is already checked
if distance > range or cur_system in checked:
return
if cur_system == dest_system:
# destination found, so we don't need to check further connections
routes_found.append(distance)
return
for connected_system in self.get_connected_systems(cur_system):
# duplicate existing path and append this system
now_checked = list(checked)
now_checked.append(cur_system)
# recursively find distance, if a path exists
conn_dist = self.system_distance_recursive(connected_system, dest_system, distance + 1, range, now_checked, routes_found)
if conn_dist >= 0:
# this system is parth of a path to destination, so add the distance
routes_found.append(conn_dist)
def get_connected_systems(self, system):
# find the system and return its connections. can easily be optimized using a dict if performance is an issue (which it shouldn't be when only checking regions)
system_data = [x['connections'] for x in era.current_region if x['name'] == system]
# connections across regions exist in the data, but are currently not supported. but people probably don't report cross-region intel anyway
return system_data[0] if len(system_data) > 0 else []
# Define LOOT watcher thread
class StartLOOT(Thread):
def __init__(self, threadID):
Thread.__init__(self)
# Kill the thread when the main process is exited
self.daemon = True
self.threadID = threadID
self._want_abort = 0
self.start()
def abort(self):
print "Stopping the Loot watch thread\n"
self._want_abort = 1
# setup our log file watcher, only open it once and update when a new line is written
def loot_watch(self, fn, words):
done_count = 0
self.interval = int(era.check_interval.GetValue()) * 2
fp = open(fn, 'r')
while self._want_abort == 0:
new = fp.readline()
if new:
done_count = 0
for word in words:
if word in new:
yield (word, new)
else:
done_count = done_count + 1
if done_count > self.interval:
print "LOOT Notification"
print "%r - Sites done (or something is wrong)\n" % (time.strftime('%H:%M:%S'))
if which_os == "Linux":
os.system("aplay -q %r" % done_sound)
elif which_os == "Windows":
winsound.PlaySound("%s" % done_sound,SND_FILENAME)
elif which_os == "Darwin":
os.system("afplay %r" % done_sound)
done_count = 0
time.sleep(0.5)
def run(self):
count = 0
print "\nStarting the Loot Watcher"
logdir = EVEDir.game_logs
# sort by date
tmp = sorted([ f for f in os.listdir(logdir) if f.startswith('201')])
# grab the most recent file
try:
fn = os.path.join( logdir, tmp[-1] )
except:
print "There don't appear to be any log files here at: %s" % logdir
self.abort()
exit()
print "parsing from %s\n" % tmp[-1]
# triggers to look for in the log file
words = [ "Dread Guristas",
"Dark Blood",
"True Sansha",
"Shadow Serpentis",
"Sentient",
"Domination",
"Estamel Tharchon",
"Vepas Minimala",
"Thon Eney",
"Kaikka Peunato",
"Gotan Kreiss",
"Hakim Stormare",
"Mizuro Cybon",
"Tobias Kruzhor",
"Ahremen Arkah",
"Draclira Merlonne",
"Raysere Giant",
"Tairei Namazoth",
"Brokara Ryver",
"Chelm Soran",
"Selynne Mardakar",
"Vizan Ankonin",
"Brynn Jerdola",
"Cormack Vaaja",
"Setele Schellan",
"Tuvan Orth", ]
# Don't trigger if we are accepting or getting a contract
false_pos = [ "following items",
"question" ]
for hit_word, hit_sentence in self.loot_watch(fn, words):
if not any(false_word in hit_sentence for false_word in false_pos):
if count < 1:
count = count + 1
# log the combat lines involving the spawn
print "LOOT ALERT!!"
print "%r - %r\n" % (time.strftime('%H:%M:%S'), hit_word)
wx.Yield()
# debug statement
# print "%r" % (hit_sentence)
# get current date/time in UTC
utc = time.strftime('[ %Y.%m.%d %H:%M', gmtime())[:17]
if utc in hit_sentence:
# play a tone to get attention
if which_os == "Linux":
os.system("aplay -q %r" % tags_and_ammo)
elif which_os == "Windows":
winsound.PlaySound("%s" % tags_and_ammo,SND_FILENAME)
elif which_os == "Darwin":
os.system("afplay %r" % tags_and_ammo)
else:
print "What fucking system are you running?"
break
elif count == 30:
count = 0
continue
else:
count = count + 1
continue
if __name__ == '__main__':
app=wx.App()
frame=era(parent=None,id=-1)
frame.Show()
app.MainLoop()