NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

disconnectNotice.py (3389B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\util\disconnectNotice.py
      2 import uthread2
      3 from carbon.client.script.sys import appUtils
      4 from carbon.common.script.net.ExceptionMappingGPCS import TRANSPORT_CLOSED_MESSAGES
      5 import carbonui.primitives as uiprimitives
      6 import localization
      7 import carbonui.const as uiconst
      8 import bluepy
      9 from carbonui.primitives.fill import Fill
     10 from eve.client.script.ui.shared.messagebox import MessageBox
     11 from carbonui.uicore import uicore
     12 from monolithsentry.geoip2_tags import get_geoip_tags, COUNTRY_KEY, ASN_KEY, IP_ADDRESS_KEY
     13 from clientevents.client.messenger import ClientEventsMessenger
     14 from player_messaging.client.ui_message import prompt_player
     15 
     16 class NoLog(object):
     17 
     18     def LogInfo(self):
     19         pass
     20 
     21     def LogError(self):
     22         pass
     23 
     24 
     25 class DisconnectNotice(object):
     26 
     27     def __init__(self, logProvider):
     28         if logProvider is None:
     29             logProvider = NoLog()
     30         self.logProvider = logProvider
     31         self._eventMessenger = ClientEventsMessenger(sm.GetService('publicGatewaySvc'))
     32 
     33     def OnDisconnect(self, reason = 0, msg = '', title = None, icon = None):
     34         if msg in TRANSPORT_CLOSED_MESSAGES:
     35             msg_type = msg
     36             msg = localization.GetByLabel(TRANSPORT_CLOSED_MESSAGES[msg])
     37         else:
     38             self.logProvider.LogError('GameUI::OnDisconnect - Unknown msg=', msg)
     39             msg_type = 'No reason given'
     40             msg = None
     41         self.logProvider.LogInfo('Received OnDisconnect with reason=', reason, ' and msg=', msg)
     42         user_id = session.userid if session else None
     43         geo_tags = get_geoip_tags()
     44         country_code = geo_tags.get(COUNTRY_KEY, '') if geo_tags else ''
     45         asn = geo_tags.get(ASN_KEY, 0) if geo_tags else 0
     46         ip_address = geo_tags.get(IP_ADDRESS_KEY, None) if geo_tags else None
     47         self._eventMessenger.connection_lost(user_id, msg_type, country_code, asn, ip_address)
     48         if reason in (0, 1):
     49             self.logProvider.LogError('GameUI::OnDisconnect', reason, msg)
     50             self.ShowDisconnectNotice(notice=msg, title=title, icon=icon)
     51 
     52     def ShowDisconnectNotice(self, notice = None, title = None, icon = None):
     53         notice = notice or localization.GetByLabel('UI/Shared/GenericConnectionLost')
     54         canReboot = appUtils.CanReboot()
     55         okLabel = localization.GetByLabel('UI/Commands/CmdRestart') if canReboot else localization.GetByLabel('UI/Commands/CmdQuit')
     56         buttons = uiconst.OKCANCEL if canReboot else uiconst.OK
     57         cancelLabel = localization.GetByLabel('UI/Commands/CmdQuit') if canReboot else None
     58         title = title or self._GetWindowTitle()
     59         uicore.layer.hint.display = False
     60         blackOut = Fill(parent=uicore.layer.modal, color=(0, 0, 0, 0), idx=1)
     61         uicore.animations.MorphScalar(blackOut, 'opacity', startVal=0, endVal=0.75, duration=1.0)
     62         result = prompt_player(text=notice, title=title, icon=icon, options=buttons, ok_label=okLabel, cancel_label=cancelLabel)
     63         if canReboot and result == uiconst.ID_OK:
     64             appUtils.Reboot('connection lost')
     65         else:
     66             bluepy.Terminate(0, 'User requesting close after client disconnect')
     67 
     68     def _GetWindowIcon(self):
     69         return uiconst.INFO
     70 
     71     def _GetWindowTitle(self):
     72         return localization.GetByLabel('UI/Shared/ConnectionLost')