1 import craw
, nil
.time
, utility
, threading
, packets
3 class player_information
:
4 def __init__(self
, name
):
6 player_data
= utility
.get_player_data_by_name(name
)
7 if player_data
== None:
8 self
.character_class_string
= '[Unknown]'
9 print 'Unable to extract player information for name %s' % name
11 self
.character_class_string
= utility
.get_character_string(player_data
)
15 return '%s (*%s) (%s)' % (self
.name
, self
.account
, self
.character_class_string
)
18 class player_kill_whois_request
:
19 def __init__(self
, victim_name
, killer_name
):
20 self
.victim
= player_information(victim_name
)
21 self
.killer
= player_information(killer_name
)
23 class player_kill_handler_class
:
25 self
.bncs_handler
= None
26 self
.request_lock
= threading
.Lock()
28 self
.pending_requests
= []
30 def victim_whois_handler(self
, account
):
31 self
.request_lock
.acquire()
32 self
.pending_requests
[0].victim
.account
= account
33 killer_name
= self
.pending_requests
[0].killer
.name
34 self
.request_lock
.release()
35 self
.bncs_handler
.whois(killer_name
, self
.killer_whois_handler
)
37 def killer_whois_handler(self
, account
):
38 self
.request_lock
.acquire()
39 request
= self
.pending_requests
[0]
40 self
.pending_requests
= self
.pending_requests
[1 : ]
41 request
.killer
.account
= account
42 print '%s %s was slain by %s' % (nil
.time
.timestamp(), request
.victim
.get_string(), request
.killer
.get_string())
43 self
.request_lock
.release()
45 def lame_print(self
, victim_name
, killer_name
):
46 victim
= utility
.get_player_data_by_name(victim_name
)
47 killer
= utility
.get_player_data_by_name(killer_name
)
49 if victim
== None or killer
== None:
50 print 'Somebody got killed but the program was unable to extract the victim/killer'
53 victim_string
= utility
.get_character_string(victim
)
54 killer_string
= utility
.get_character_string(killer
)
56 line
= '%s %s (%s) was slain by %s (%s) ' % (nil
.time
.timestamp(), victim_name
, victim_string
, killer_name
, killer_string
)
59 def process_bytes(self
, bytes
):
63 if bytes
[0 : 2] != [0x5a, 0x06]:
66 #print utility.get_packet_string(bytes)
68 victim_name
= utility
.read_name(bytes
, 8)
69 killer_name
= utility
.read_name(bytes
, 24)
71 #self.lame_print(victim_name, killer_name)
73 victim
= utility
.get_player_data_by_name(victim_name
)
74 killer
= utility
.get_player_data_by_name(killer_name
)
76 if victim
== None or killer
== None:
79 self
.request_lock
.acquire()
80 self
.pending_requests
.append(player_kill_whois_request(victim_name
, killer_name
))
81 self
.request_lock
.release()
83 self
.bncs_handler
.whois(victim_name
, self
.victim_whois_handler
)