Skip to content

Commit

Permalink
refactor SendExceptionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
SoprachevAK committed Mar 9, 2024
1 parent 9a5e420 commit 40edf74
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from Event import Event
from debug_utils import LOG_CURRENT_EXCEPTION
from serverLogger import send_current_exception


def with_exception_sending(f):
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except:
send_current_exception()
LOG_CURRENT_EXCEPTION()

return wrapper


class SendExceptionEvent(Event):
__slots__ = ()

def __init__(self, manager=None):
super(SendExceptionEvent, self).__init__(manager)

def __call__(self, *args, **kwargs):
for delegate in self[:]:
try:
delegate(*args, **kwargs)
except:
send_current_exception()
LOG_CURRENT_EXCEPTION()
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import BigWorld
import json
import os
import shutil
import json
import BigWorld

from helpers import getShortClientVersion
from asyncResponse import get_async
from helpers import getShortClientVersion
from ..utils import print_log
from .exceptionSending import with_exception_sending


def num_game_version():
return getShortClientVersion().split('v.')[1].strip()


@with_exception_sending
def update_game_version(full_mod_name):
gameVersion = num_game_version()
currentMod = os.path.join(os.path.abspath('./mods/'), gameVersion, full_mod_name)
Expand All @@ -36,6 +38,7 @@ def b(x, y):
'Accept': 'application/vnd.github+json'}


@with_exception_sending
def update_mod_version(url, mod_name, current_version, on_start_update=None, on_updated=None, on_success_check=None):
latest_version = ''

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding=utf-8
from gui import SystemMessages
from ..utils import print_log

import BigWorld
from notification.actions_handlers import NotificationsActionsHandlers
from gui import SystemMessages
from gui.DialogsInterface import showDialog
from gui.Scaleform.daapi.view.dialogs import DIALOG_BUTTON_ID
from gui.Scaleform.daapi.view.dialogs import SimpleDialogMeta
from notification.actions_handlers import NotificationsActionsHandlers
from .exceptionSending import with_exception_sending
from ..utils import print_log


OPEN_PERSONAL_WOTSTAT_EVENT = 'OPEN_PERSONAL_WOTSTAT_EVENT_'
Expand All @@ -20,11 +20,13 @@ def getLabels(self):
]


@with_exception_sending
def show_url_dialog(title=None, message=None, url=None):
meta = SimpleDialogMeta(title=title, message=message, buttons=UrlDialogButtons())
showDialog(meta, lambda proceed: BigWorld.wg_openWebBrowser(url) if proceed else None)


@with_exception_sending
def __wotstat_events_handleAction(self, model, typeID, entityID, actionName):
try:
if actionName.startswith(OPEN_PERSONAL_WOTSTAT_EVENT):
Expand All @@ -43,6 +45,7 @@ def __wotstat_events_handleAction(self, model, typeID, entityID, actionName):
NotificationsActionsHandlers.handleAction = __wotstat_events_handleAction


@with_exception_sending
def show_notification(msg, message_type=SystemMessages.SM_TYPE.Information):
print_log('show notification: %s. With type: %s' % (msg, message_type))
SystemMessages.pushMessage(msg, type=message_type)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from account_shared import readClientServerVersion
from constants import AUTH_REALM
from debug_utils import _addTagsToMsg, _makeMsgHeader, LOG_CURRENT_EXCEPTION, _src_file_trim_to, _g_logLock
from .common.asyncResponse import post_async
from .asyncResponse import post_async

logger = None # type: ServerLogger
modVersion = 'unknown'
Expand Down
5 changes: 2 additions & 3 deletions WOTSTAT/res/scripts/client/gui/mods/wot_stat/load_mod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import BigWorld
import json

import BigWorld
from .common.config import Config
configPath = './mods/configs/wot_stat/config.cfg'
config = Config(configPath) # type: Config
Expand All @@ -12,10 +12,9 @@
from .common.asyncResponse import get_async

from .utils import print_log
from .logger.eventLogger import eventLogger
from .logger.wotHookEvents import wotHookEvents
from .logger.sessionStorage import sessionStorage
from .serverLogger import setupLogger, send
from .common.serverLogger import setupLogger, send

is_success_check = None
api_server_time = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import BigWorld

import BigWorld
from events import Event, OnBattleStart, OnBattleResult
from ..common.asyncResponse import post_async
from ..common.exceptionSending import with_exception_sending
from ..utils import print_log, print_debug

try:
Expand Down Expand Up @@ -64,6 +65,7 @@ def __send_event_loop(self):
if self.enable:
BigWorld.callback(self.send_interval, self.__send_event_loop)

@with_exception_sending
def __post_events(self, events, callback=None):
if events and len(events) > 0:
data = {
Expand Down
16 changes: 5 additions & 11 deletions WOTSTAT/res/scripts/client/gui/mods/wot_stat/logger/eventLogger.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import Event as BigWorldEvent
from constants import ARENA_PERIOD

from battleEventSession import BattleEventSession
from ..load_mod import config
from ..utils import print_log, print_debug
from .utils import *
from constants import ARENA_PERIOD
from events import Event
from .utils import *
from ..common.exceptionSending import SendExceptionEvent
from ..utils import print_debug


class EventLogger:
old_battle_event_sessions = {}
battle_event_session = None # type: BattleEventSession
start_battle_time = 0
on_session_created = BigWorldEvent.Event()
on_session_created = SendExceptionEvent()

def __init__(self):
self.old_battle_event_sessions = {}
self.battle_event_session = None
self.start_battle_time = 0
self.on_session_created = BigWorldEvent.Event()
print_debug('INIT EVENT LOGGER')

def emit_event(self, event, arena_id=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from typing import Optional, Any

import BattleReplay
import BigWorld
from PlayerEvents import g_playerEvents
from items import vehicles as vehiclesWG
from ..eventLogger import eventLogger
from ..sessionStorage import sessionStorage
from ..events import OnBattleResult
from ...utils import print_log, print_debug
from items import vehicles as vehiclesWG
from ..sessionStorage import sessionStorage
from ..utils import short_tank_type, setup_dynamic_battle_info, setup_session_meta
from ...common.exceptionSending import with_exception_sending
from ...utils import print_log, print_debug


class OnBattleResultLogger:
Expand All @@ -30,11 +29,13 @@ def on_session_created(self, battleEventSession):
setup_dynamic_battle_info(event)
self.precreated_battle_result_event[battleEventSession.arenaID] = event

@with_exception_sending
def on_battle_results_received(self, isPlayerVehicle, results):
if not isPlayerVehicle or BattleReplay.isPlaying():
return
self.process_battle_result(results)

@with_exception_sending
def battle_result_cache_checker(self):
BigWorld.callback(3, self.battle_result_cache_checker)

Expand Down
2 changes: 2 additions & 0 deletions WOTSTAT/res/scripts/client/gui/mods/wot_stat/logger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from constants import ARENA_BONUS_TYPE, ARENA_GAMEPLAY_NAMES, AUTH_REALM
from gui.battle_control.battle_constants import FEEDBACK_EVENT_ID
from .sessionStorage import sessionStorage
from ..common.exceptionSending import with_exception_sending
from ..load_mod import config


Expand Down Expand Up @@ -43,6 +44,7 @@ def get_tank_type(vehicleTags):
return res


@with_exception_sending
def setup_dynamic_battle_info(dynamicBattleEvent):
"""
@type dynamicBattleEvent: DynamicBattleEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import BigWorld

from Avatar import PlayerAvatar
from Account import Account
from VehicleGunRotator import VehicleGunRotator
from gui.Scaleform.daapi.view.lobby.battle_queue import BattleQueue
from Avatar import PlayerAvatar
from ProjectileMover import ProjectileMover
from Vehicle import Vehicle
from VehicleGunRotator import VehicleGunRotator
from gui.Scaleform.daapi.view.lobby.battle_queue import BattleQueue
from helpers import dependency
from skeletons.connection_mgr import IConnectionManager
from Event import Event
from debug_utils import LOG_CURRENT_EXCEPTION

from ..common.exceptionSending import SendExceptionEvent
from ..common.hook import g_overrideLib
from ..serverLogger import send_current_exception


class SafeEvent(Event):
__slots__ = ()

def __init__(self, manager=None):
super(SafeEvent, self).__init__(manager)

def __call__(self, *args, **kwargs):
for delegate in self[:]:
try:
delegate(*args, **kwargs)
except:
send_current_exception()
LOG_CURRENT_EXCEPTION()


class WotHookEvents:
Expand All @@ -39,29 +19,29 @@ def __init__(self):

self.listeners = {}
# ------------------INIT------------------#
self.onConnected = SafeEvent()
self.Account_onBecomePlayer = SafeEvent()
self.BattleQueue_populate = SafeEvent()
self.PlayerAvatar_onEnterWorld = SafeEvent()
self.PlayerAvatar_updateTargetingInfo = SafeEvent()
self.PlayerAvatar_onArenaPeriodChange = SafeEvent()
self.onConnected = SendExceptionEvent()
self.Account_onBecomePlayer = SendExceptionEvent()
self.BattleQueue_populate = SendExceptionEvent()
self.PlayerAvatar_onEnterWorld = SendExceptionEvent()
self.PlayerAvatar_updateTargetingInfo = SendExceptionEvent()
self.PlayerAvatar_onArenaPeriodChange = SendExceptionEvent()
# -------------------MOVE------------------#
self.VehicleGunRotator_setShotPosition = SafeEvent()
self.VehicleGunRotator_updateGunMarker = SafeEvent()
self.PlayerAvatar_updateGunMarker = SafeEvent()
self.VehicleGunRotator_setShotPosition = SendExceptionEvent()
self.VehicleGunRotator_updateGunMarker = SendExceptionEvent()
self.PlayerAvatar_updateGunMarker = SendExceptionEvent()
# -------------------SHOT------------------#
self.PlayerAvatar_shoot = SafeEvent()
self.PlayerAvatar_showTracer = SafeEvent()
self.PlayerAvatar_showShotResults = SafeEvent()
self.Vehicle_onHealthChanged = SafeEvent()
self.PlayerAvatar_showOwnVehicleHitDirection = SafeEvent()
self.PlayerAvatar_shoot = SendExceptionEvent()
self.PlayerAvatar_showTracer = SendExceptionEvent()
self.PlayerAvatar_showShotResults = SendExceptionEvent()
self.Vehicle_onHealthChanged = SendExceptionEvent()
self.PlayerAvatar_showOwnVehicleHitDirection = SendExceptionEvent()
# -------------------EXPLOSION------------------#
self.PlayerAvatar_explodeProjectile = SafeEvent()
self.Vehicle_showDamageFromShot = SafeEvent()
self.PlayerAvatar_explodeProjectile = SendExceptionEvent()
self.Vehicle_showDamageFromShot = SendExceptionEvent()
# -------------------PROJECTILE-------------------#
self.ProjectileMover_killProjectile = SafeEvent()
self.ProjectileMover_killProjectile = SendExceptionEvent()
# -------------------HELP-------------------#
self.PlayerAvatar_enableServerAim = SafeEvent()
self.PlayerAvatar_enableServerAim = SendExceptionEvent()

def __onConnected(self):
self.onConnected()
Expand Down
2 changes: 1 addition & 1 deletion WOTSTAT/res/scripts/client/gui/mods/wot_stat/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BigWorld
from .serverLogger import send, LEVELS
from .common.serverLogger import send, LEVELS


def print_log(log):
Expand Down

0 comments on commit 40edf74

Please sign in to comment.