eveSessions.py (21147B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\common\script\sys\eveSessions.py 2 import math 3 import blue 4 import localization 5 from carbon.common.script.net import machobase as macho 6 from carbon.common.script.sys.basesession import FindSessions 7 from carbon.common.script.sys.sessions import SessionMgr as SessionMgrBase 8 from carbon.common.script.sys import basesession 9 from carbon.common.script.sys.serviceConst import ROLE_ADMIN, ROLE_SERVICE, SERVICE_RUNNING 10 from cluster import SERVICE_BEYONCE, SERVICE_CHATX, SERVICE_STATION 11 from eve.common.lib import appConst as const 12 from eve.common.lib.appConst import locationCharacterGraveyard 13 from eve.common.script.sys.idCheckers import IsStation, IsCharacter 14 from inventorycommon.util import IsNPC 15 eveSessionsByAttribute = {'regionid': {}, 16 'constellationid': {}, 17 'corpid': {}, 18 'fleetid': {}, 19 'wingid': {}, 20 'squadid': {}, 21 'shipid': {}, 22 'stationid': {}, 23 'structureid': {}, 24 'locationid': {}, 25 'solarsystemid': {}, 26 'solarsystemid2': {}, 27 'allianceid': {}, 28 'warfactionid': {}} 29 basesession.sessionsByAttribute.update(eveSessionsByAttribute) 30 31 def GetCharInventoryLocation(charID): 32 locationID, locationGroupID, charLocationID = GetCharLocation2(charID) 33 if locationGroupID is None: 34 if charLocationID == locationCharacterGraveyard: 35 return (True, None, None) 36 raise RuntimeError('Bogus character item state', charID, locationID, charLocationID) 37 return (False, locationID, locationGroupID) 38 39 40 def GetCharLocation(charID, include_graveyard = False): 41 locationID, locationGroupID, charLocationID = GetCharLocation2(charID) 42 if locationGroupID is None: 43 raise RuntimeError('Bogus character item state', charID, locationID, charLocationID) 44 return (locationID, locationGroupID) 45 46 47 def GetCharLocation2(charID): 48 try: 49 locationID, locationGroupID, charLocationID = GetCharLocationEx(charID) 50 except RuntimeError: 51 locationGroupID = None 52 53 if locationGroupID is None: 54 sm.services['charUnboundMgr'].RecoverCharacter(charID) 55 locationID, locationGroupID, charLocationID = GetCharLocationEx(charID) 56 return (locationID, locationGroupID, charLocationID) 57 58 59 def IsLocationNode(session): 60 if not macho.mode == 'server': 61 return False 62 machoNet = sm.GetService('machoNet') 63 currentNodeID = machoNet.GetNodeID() 64 return any((session.solarsystemid and currentNodeID == machoNet.GetNodeFromAddress(SERVICE_BEYONCE, session.solarsystemid), session.stationid and currentNodeID == machoNet.GetNodeFromAddress(SERVICE_STATION, session.stationid))) 65 66 67 def GetCharLocationEx(charID): 68 sessions = FindSessions('charid', [charID]) 69 if len(sessions) and IsLocationNode(sessions[0]): 70 s = sessions[0] 71 if s.solarsystemid: 72 return (s.solarsystemid, const.groupSolarSystem, s.shipid) 73 if s.stationid and s.shipid: 74 return (s.stationid, const.groupStation, s.shipid) 75 if s.stationid: 76 return (s.stationid, const.groupStation, s.stationid) 77 else: 78 while sm.services['DB2'].state != SERVICE_RUNNING: 79 blue.pyos.synchro.SleepWallclock(100) 80 81 rs = sm.services['DB2'].GetSchema('character').Characters_LocationInfo(charID) 82 locationInfo = rs[0] 83 if locationInfo.locationID is None: 84 raise RuntimeError('No such locationID', locationInfo.locationID, 'for charID', charID) 85 if locationInfo.locationGroupID in (const.groupStation, const.groupSolarSystem): 86 return (locationInfo.locationID, locationInfo.locationGroupID, locationInfo.characterLocationID) 87 return (locationInfo.locationID, None, locationInfo.characterLocationID) 88 89 90 def IsUndockingSessionChange(session, change): 91 goingFromStation = 'stationid' in change and change.get('stationid')[0] 92 goingToSpace = 'solarsystemid' in change and change.get('solarsystemid')[1] 93 return goingFromStation and goingToSpace 94 95 96 class SessionMgr(SessionMgrBase): 97 __guid__ = 'svc.eveSessionMgr' 98 __displayname__ = 'Session manager' 99 __replaceservice__ = 'sessionMgr' 100 __exportedcalls__ = {'GetSessionStatistics': [ROLE_SERVICE], 101 'CloseUserSessions': [ROLE_SERVICE], 102 'GetProxyNodeFromID': [ROLE_SERVICE], 103 'GetClientIDsFromID': [ROLE_SERVICE], 104 'UpdateSessionAttributes': [ROLE_SERVICE], 105 'ConnectToClientService': [ROLE_SERVICE], 106 'PerformSessionChange': [ROLE_SERVICE], 107 'GetLocalClientIDs': [ROLE_SERVICE], 108 'EndAllGameSessions': [ROLE_ADMIN | ROLE_SERVICE], 109 'PerformHorridSessionAttributeUpdate': [ROLE_SERVICE], 110 'BatchedRemoteCall': [ROLE_SERVICE], 111 'GetSessionDetails': [ROLE_SERVICE], 112 'TerminateClientConnections': [ROLE_SERVICE | ROLE_ADMIN], 113 'GetInitialValuesFromCharID': [ROLE_SERVICE], 114 'RemoveSessionsFromServer': [ROLE_SERVICE], 115 'ResetClientConnection': [ROLE_SERVICE]} 116 __dependencies__ = [] 117 __notifyevents__ = ['ProcessInventoryChange', 'ProcessSessionReset'] + SessionMgrBase.__notifyevents__ 118 119 def __init__(self): 120 SessionMgrBase.__init__(self) 121 if macho.mode == 'server': 122 self.__dependencies__ += ['config', 123 'station', 124 'ship', 125 'corporationSvc', 126 'corpmgr', 127 'i2', 128 'stationSvc', 129 'cache'] 130 self.sessionChangeShortCircuitReasons = ['autopilot'] 131 self.additionalAttribsAllowedToUpdate = ['allianceid', 'corpid'] 132 self.additionalStatAttribs = ['solarsystemid', 'solarsystemid2', 'structureid'] 133 self.additionalSessionDetailsAttribs = ['allianceid', 134 'warfactionid', 135 'corpid', 136 'corprole', 137 'shipid', 138 'regionid', 139 'constellationid', 140 'solarsystemid2', 141 'locationid', 142 'solarsystemid', 143 'stationid', 144 'structureid', 145 'fleetid', 146 'wingid', 147 'squadid', 148 'fleetrole', 149 'corpAccountKey', 150 'inDetention'] 151 152 def AppRun(self, memstream = None): 153 if macho.mode == 'server': 154 self.dbcharacter = self.DB2.GetSchema('character') 155 156 def GetReason(self, oldReason, newReason, timeLeft): 157 if timeLeft: 158 seconds = int(math.ceil(max(1, timeLeft) / float(const.SEC))) 159 reason = localization.GetByLabel('UI/Sessions/BaseReason') 160 if oldReason == newReason or oldReason.startswith('fleet.') and newReason.startswith('fleet.') or oldReason.startswith('corp.') and newReason.startswith('corp.'): 161 if oldReason.startswith('fleet.'): 162 reason = localization.GetByLabel('UI/Sessions/FleetOperation') 163 if timeLeft: 164 reason = localization.GetByLabel('UI/Sessions/EstimatedTimeLeft', reason=reason, seconds=seconds) 165 elif oldReason.startswith('corp.'): 166 reason = localization.GetByLabel('UI/Sessions/CorpOperation') 167 if timeLeft: 168 reason = localization.GetByLabel('UI/Sessions/EstimatedTimeLeft', reason=reason, seconds=seconds) 169 elif oldReason == 'undock': 170 reason = localization.GetByLabel('UI/Sessions/Undocking') 171 if timeLeft: 172 reason = localization.GetByLabel('UI/Sessions/EstimatedTimeLeft', reason=reason, seconds=seconds) 173 elif oldReason == 'dock': 174 reason = localization.GetByLabel('UI/Sessions/Docking') 175 if timeLeft: 176 reason = localization.GetByLabel('UI/Sessions/EstimatedTimeLeft', reason=reason, seconds=seconds) 177 elif oldReason == 'jump' and newReason == 'jump': 178 reason = localization.GetByLabel('UI/Sessions/Jump') 179 if timeLeft: 180 reason = localization.GetByLabel('UI/Sessions/EstimatedTimeLeft', reason=reason, seconds=seconds) 181 elif oldReason == 'jump': 182 reason = localization.GetByLabel('UI/Sessions/StartgateJump') 183 if timeLeft: 184 reason = localization.GetByLabel('UI/Sessions/StartgateJumpEstimatedTime', reason=reason, seconds=seconds) 185 elif oldReason == 'eject': 186 reason = localization.GetByLabel('UI/Sessions/Ejecting') 187 if timeLeft: 188 reason = localization.GetByLabel('UI/Sessions/EjectingEstimatedTime', reason=reason, seconds=seconds) 189 elif oldReason == 'evacuate': 190 reason = localization.GetByLabel('UI/Sessions/Evacuation') 191 if timeLeft: 192 reason = localization.GetByLabel('UI/Sessions/EvacuationsEstimatedTime', reason=reason, seconds=seconds) 193 elif oldReason == 'board': 194 reason = localization.GetByLabel('UI/Sessions/Boarding') 195 if timeLeft: 196 reason = localization.GetByLabel('UI/Sessions/BoardingEstimatedTime', reason=reason, seconds=seconds) 197 elif oldReason == 'selfdestruct': 198 reason = localization.GetByLabel('UI/Sessions/SelfDestruct') 199 if timeLeft: 200 reason = localization.GetByLabel('UI/Sessions/SelfDestructEstimatedTime', reason=reason, seconds=seconds) 201 elif oldReason == 'charsel': 202 reason = localization.GetByLabel('UI/Sessions/CharacterSelection') 203 if timeLeft: 204 reason = localization.GetByLabel('UI/Sessions/CharacterSelectionEstimatedTime', reason=reason, seconds=seconds) 205 elif oldReason == 'storeVessel': 206 reason = localization.GetByLabel('UI/Sessions/Embarkation') 207 if timeLeft: 208 reason = localization.GetByLabel('UI/Sessions/EmbarkationEstimatedTime', reason=reason, seconds=seconds) 209 elif oldReason == 'autopilot': 210 reason = localization.GetByLabel('UI/Sessions/Autopilot') 211 if timeLeft: 212 reason = localization.GetByLabel('UI/Sessions/AutopilotEstimatedTime', reason=reason, seconds=seconds) 213 elif oldReason == 'undock': 214 reason = localization.GetByLabel('UI/Sessions/AreUndocking') 215 if timeLeft: 216 reason = localization.GetByLabel('UI/Sessions/AreUndockingEstimatedTime', reason=reason, seconds=seconds) 217 elif oldReason == 'dock': 218 reason = localization.GetByLabel('UI/Sessions/AreDocking') 219 if timeLeft: 220 reason = localization.GetByLabel('UI/Sessions/AreDockingEstimmatedTime', reason=reason, seconds=seconds) 221 elif oldReason == 'jump': 222 reason = localization.GetByLabel('UI/Sessions/AreJumping') 223 if timeLeft: 224 reason = localization.GetByLabel('UI/Sessions/AreJumpingEstimatedTime', reason=reason, seconds=seconds) 225 elif oldReason == 'eject': 226 reason = localization.GetByLabel('UI/Sessions/AreEjecting') 227 if timeLeft: 228 reason = localization.GetByLabel('UI/Sessions/AreEjectingEstimatedTime', reason=reason, seconds=seconds) 229 elif oldReason == 'evacuate': 230 reason = localization.GetByLabel('UI/Sessions/AreEvacuating') 231 if timeLeft: 232 reason = localization.GetByLabel('UI/Sessions/AreEvacuatingEstimatedTime', reason=reason, seconds=seconds) 233 elif oldReason == 'board': 234 reason = localization.GetByLabel('UI/Sessions/AreBoarding') 235 if timeLeft: 236 reason = localization.GetByLabel('UI/Sessions/AreBoardingEstimatedTime', reason=reason, seconds=seconds) 237 elif oldReason == 'selfdestruct': 238 reason = localization.GetByLabel('UI/Sessions/AreSelfDestructing') 239 if timeLeft: 240 reason = localization.GetByLabel('UI/Sessions/AreSelfDestructiongEstimateTime', reason=reason, seconds=seconds) 241 elif oldReason == 'charsel': 242 reason = localization.GetByLabel('UI/Sessions/AreSelectingCharacter') 243 if timeLeft: 244 reason = localization.GetByLabel('UI/Sessions/AreSelectingCharacterEstimatedTime', reason=reason, seconds=seconds) 245 elif oldReason == 'accelerationgate': 246 reason = localization.GetByLabel('UI/Sessions/AreUsingAccelerationGate') 247 if timeLeft: 248 reason = localization.GetByLabel('UI/Sessions/AreUsingAccelerationGateEstimatedTime', reason=reason, seconds=seconds) 249 elif oldReason.startswith('corp.'): 250 reason = localization.GetByLabel('UI/Sessions/CorpActivity') 251 if timeLeft: 252 reason = localization.GetByLabel('UI/Sessions/CorpActivityEstimatedTime', reason=reason, seconds=seconds) 253 elif oldReason.startswith('fleet.'): 254 reason = localization.GetByLabel('UI/Sessions/FleetOperations') 255 if timeLeft: 256 reason = localization.GetByLabel('UI/Sessions/FleetOperationsEstimatedTime', reason=reason, seconds=seconds) 257 elif oldReason == 'storeVessel': 258 reason = localization.GetByLabel('UI/Sessions/AreBoardingVessel') 259 if timeLeft: 260 reason = localization.GetByLabel('UI/Sessions/AreBoardingVesselEstimatedTime', reason=reason, seconds=seconds) 261 elif oldReason == 'bookmarking': 262 reason = localization.GetByLabel('UI/Sessions/Bookmarking') 263 return reason 264 265 def TypeAndNodeValidationHook(self, idType, id): 266 if macho.mode == 'server' and idType in ('allianceid', 'corpid'): 267 machoNet = sm.GetService('machoNet') 268 if machoNet.GetNodeID() != machoNet.GetNodeFromAddress(SERVICE_CHATX, id % 200): 269 raise RuntimeError('Horrid session change called on incorrect node. You must at very least perform this abomination on the right node.') 270 271 def ProcessSessionReset(self): 272 if macho.mode != 'client': 273 return 274 session.ClearCharacterDependantAttributes() 275 276 def ProcessInventoryChange(self, items, change, isRemote, inventory2): 277 if macho.mode != 'server': 278 return 279 if isRemote: 280 return 281 if const.ixLocationID not in change and const.ixFlag not in change: 282 return 283 chars = {} 284 for item in items: 285 if item.categoryID == const.categoryShip and item.singleton: 286 for sess in FindSessions('shipid', [item.itemID]): 287 locationToCompare = sess.structureid or sess.stationid or sess.solarsystemid 288 if sess.charid == item.ownerID and (locationToCompare == item.locationID or locationToCompare in change.get(const.ixLocationID, [None, None])): 289 chars[sess.charid] = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) 290 291 elif item.groupID == const.groupCharacter: 292 charValues = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) 293 if charValues['structureid'] and item.flagID == const.flagPilot and charValues['shipid'] is None: 294 charValues['shipid'] = charValues['structureid'] 295 chars[item.itemID] = charValues 296 297 if len(chars) == 0: 298 return 299 for charID, updateDict in chars.iteritems(): 300 for sess in FindSessions('charid', [charID]): 301 sess.LogSessionHistory('Transmogrifying OnInventoryChange to SetAttributes') 302 sess.SetAttributes(updateDict) 303 sess.LogSessionHistory('Transmogrified OnInventoryChange to SetAttributes') 304 305 def GetSessionValuesFromItemID(self, itemID, inventory2 = None, theItem = None): 306 if itemID == const.locationAbstract: 307 raise RuntimeError('Invalid argument, itemID cannot be 0') 308 309 def GetItem(id): 310 return sm.services['i2'].GetItemMx(id) 311 312 updateDict = {'shipid': None, 313 'stationid': None, 314 'structureid': None, 315 'solarsystemid': None, 316 'solarsystemid2': None, 317 'regionid': None, 318 'constellationid': None} 319 solsysID = None 320 while 1: 321 if inventory2 is None: 322 item = GetItem(itemID) 323 elif theItem and theItem.itemID == itemID: 324 item = theItem 325 elif itemID < const.minPlayerItem: 326 if IsStation(itemID): 327 station = self.stationSvc.GetStation(itemID) 328 updateDict['stationid'] = itemID 329 solsysID = station.solarSystemID 330 break 331 else: 332 item = inventory2.InvGetItem(itemID) 333 else: 334 item = inventory2.InvGetItem(itemID, 1) 335 if item.categoryID == const.categoryShip: 336 updateDict['shipid'] = itemID 337 elif item.groupID == const.groupStation: 338 updateDict['stationid'] = itemID 339 solsysID = item.locationID 340 break 341 elif item.categoryID == const.categoryStructure: 342 updateDict['structureid'] = itemID 343 elif item.typeID == const.typeSolarSystem: 344 solsysID = item.itemID 345 updateDict['solarsystemid'] = itemID 346 break 347 elif item.locationID == const.locationAbstract: 348 break 349 itemID = item.locationID 350 351 if solsysID is not None: 352 primeditems = sm.services['i2'].__primeditems__ 353 if solsysID in primeditems: 354 updateDict['solarsystemid2'] = solsysID 355 updateDict['constellationid'] = primeditems[solsysID].locationID 356 updateDict['regionid'] = primeditems[updateDict['constellationid']].locationID 357 return updateDict 358 359 def GetSessionValuesFromRowset(self, si): 360 sessValues = {'allianceid': si.allianceID, 361 'warfactionid': si.warFactionID, 362 'corpid': si.corporationID, 363 'hqID': si.hqID, 364 'baseID': si.baseID, 365 'rolesAtAll': si.roles, 366 'rolesAtHQ': si.rolesAtHQ, 367 'rolesAtBase': si.rolesAtBase, 368 'rolesAtOther': si.rolesAtOther, 369 'fleetid': None, 370 'fleetrole': None, 371 'wingid': None, 372 'squadid': None, 373 'shipid': si.shipID, 374 'stationid': None, 375 'structureid': si.structureID, 376 'solarsystemid': None, 377 'regionid': None, 378 'constellationid': None, 379 'genderID': si.genderID, 380 'bloodlineID': si.bloodlineID, 381 'raceID': si.raceID, 382 'corpAccountKey': si.corpAccountKey} 383 if si.stationID: 384 sessValues['stationid'] = si.stationID 385 station = self.stationSvc.GetStation(si.stationID) 386 sessValues['solarsystemid2'] = station.solarSystemID 387 elif si.solarSystemID: 388 sessValues['solarsystemid'] = si.solarSystemID 389 sessValues['solarsystemid2'] = si.solarSystemID 390 if 'solarsystemid2' in sessValues: 391 if sessValues['solarsystemid2'] is not None: 392 primeditems = sm.services['i2'].__primeditems__ 393 if sessValues['solarsystemid2'] in primeditems: 394 sessValues['constellationid'] = primeditems[sessValues['solarsystemid2']].locationID 395 sessValues['regionid'] = primeditems[sessValues['constellationid']].locationID 396 return sessValues 397 398 def GetInitialValuesFromCharID(self, characterID): 399 if macho.mode != 'server': 400 return {} 401 values = self.GetSessionValuesFromRowset(self.dbcharacter.Characters_Session2(characterID)[0]) 402 if not values.get('stationid') and not values.get('solarsystemid'): 403 sm.services['charUnboundMgr'].RecoverCharacter(characterID) 404 return self.GetSessionValuesFromRowset(self.dbcharacter.Characters_Session2(characterID)[0]) 405 return values 406 407 def IsPlayerCharacter(self, charID): 408 return IsCharacter(charID) and not IsNPC(charID) 409 410 def GetSession(self, charID): 411 s = FindSessions('charid', [charID]) 412 if not s: 413 return None 414 return s[0] 415 416 def GetUserSession(self, userid): 417 foundSessions = FindSessions('userid', [userid]) 418 if not foundSessions: 419 return 420 for foundSession in foundSessions: 421 if foundSession.charid is None: 422 return foundSession 423 424 def GetCharacterSession(self, charid): 425 s = FindSessions('charid', [charid]) 426 if not s: 427 return None 428 return s[0] 429 430 def _AddToSessionStatistics(self): 431 SessionMgrBase._AddToSessionStatistics(self) 432 eve_online = 0 433 for sess in basesession.sessionsBySID.itervalues(): 434 if sess.sessionType == const.session.SESSION_TYPE_GAME: 435 if sess.charid: 436 eve_online += 1 437 438 self.sessionStatistics['EVE:Online'] = (eve_online, {None: eve_online}) 439 self.sessionStatistics['EVE:Trial'] = (0, {None: 0}) 440 self.sessionStatistics['DUST:Online'] = (0, {None: 0}) 441 self.sessionStatistics['DUST:Battle'] = (0, {None: 0}) 442 self.sessionStatistics['DUST:User'] = (0, {None: 0})