CRAW now runs on Windows 7 too - the problem was that Windows 7 has moved some functi...
[craw.git] / script / player_kill.py
blob02c84fc6a5027d152075c946382d223ce8ff18b3
1 import craw, nil.time, utility, threading, packets
3 class player_information:
4 def __init__(self, name):
5 self.name = 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
10 else:
11 self.character_class_string = utility.get_character_string(player_data)
12 self.account = None
14 def get_string(self):
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:
24 def __init__(self):
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'
51 return
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)
57 print line
59 def process_bytes(self, bytes):
60 if len(bytes) < 26:
61 return
63 if bytes[0 : 2] != [0x5a, 0x06]:
64 return
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:
77 return
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)