_baseticker.py (3318B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\destiny\net\client\_baseticker.py 2 import abc 3 import logging 4 import sys 5 import blue 6 logger = logging.getLogger(__name__) 7 8 class BaseTicker(object): 9 __metaclass__ = abc.ABCMeta 10 11 def __init__(self, error_handler): 12 self._ballpark = None 13 self._history = [] 14 self._latest_set_state_time = 0 15 self._error_handler = error_handler 16 17 def set_ballpark(self, ballpark): 18 self._ballpark = ballpark 19 self._error_handler.set_ballpark(ballpark) 20 21 @abc.abstractmethod 22 def do_pre_tick(self): 23 raise NotImplemented 24 25 def update(self, state, wait_for_bubble): 26 if self._ballpark is None: 27 return 28 state = _expand_states(state) 29 self._report_update_if_bad(state) 30 self._flush_state(state, wait_for_bubble) 31 32 @abc.abstractmethod 33 def _flush_state(self, state, wait_for_bubble): 34 raise NotImplemented 35 36 @property 37 def _current_time(self): 38 return self._ballpark.currentTime 39 40 def _dump_history(self): 41 if logger.level > logging.INFO: 42 return 43 logger.info('------ %s History Dump %s -------', self.__class__.__name__, self._current_time) 44 rev = self._history[:] 45 rev.reverse() 46 for state, wait_for_bubble in rev: 47 logger.info('state waiting: %s', 'yes' if wait_for_bubble else 'no') 48 last_state = None 49 last_state_count = 0 50 for entry in state: 51 event_stamp, event = entry 52 func_name, args = event 53 next_state = ['[', 54 event_stamp, 55 ']', 56 func_name] 57 if next_state != last_state: 58 if last_state is not None: 59 if last_state_count != 1: 60 last_state.append('(x %d)' % last_state_count) 61 logger.info(' '.join([ str(s) for s in last_state ])) 62 last_state = next_state 63 last_state_count = 1 64 else: 65 last_state_count += 1 66 67 if last_state is not None: 68 if last_state_count != 1: 69 last_state.append('(x %d)' % last_state_count) 70 logger.info(' '.join([ str(s) for s in last_state ])) 71 logger.info(' ') 72 73 def _report_update_if_bad(self, state): 74 timestamps = {action[0] for action in state} 75 if len(timestamps) > 1: 76 logger.error('Found update batch with %s items and %s timestamps', len(state), len(timestamps)) 77 for action in state: 78 logger.error('Action: %s', action) 79 80 self._error_handler.on_fatal_desync() 81 82 83 def _expand_states(state): 84 expanded_states = [] 85 for action in state: 86 if action[1][0] == 'PackagedAction': 87 try: 88 unpackaged_actions = blue.marshal.Load(action[1][1]) 89 expanded_states.extend(unpackaged_actions) 90 except StandardError: 91 logger.exception('Exception whilst expanding a PackagedAction') 92 sys.exc_clear() 93 94 else: 95 expanded_states.append(action) 96 97 state = expanded_states 98 return state