예제 #1
0
    def __updateData(self):
        if self.__lazyInitialization:
            arbiter = BigWorld.globalData.get('Arbiter', False)
            if arbiter:
                self.__lazyInitialization = False
                for dvKey, keyDescription in self.__dvKeyArray.iteritems():
                    arbiter.addNewKey(dvKey, wgPickle.dumps(wgPickle.FromServerToServer, keyDescription))

            else:
                return
        else:
            _buffer = {}
            for dvKey, dataObj in self.__storage.iteritems():
                for viewerId, mask in self.__filter.iteritems():
                    is_new_viewer = viewerId in self.__newViewers
                    in_mask = dvKey in mask
                    is_change = self.__storage[dvKey].is_change
                    if in_mask and (is_change or is_new_viewer):
                        _buffer.setdefault(viewerId, {})[dvKey] = dataObj.data

                self.__storage[dvKey].is_change = False

            _puck_buffer = dict(((ID, wgPickle.dumps(wgPickle.FromServerToClient, single_buffer)) for ID, single_buffer in _buffer.iteritems()))
            if len(_puck_buffer):
                if IS_CLIENT:
                    fromClient = _puck_buffer.get(-1, None)
                    if fromClient:
                        fromClient = wgPickle.loads(wgPickle.FromServerToClient, fromClient)
                        BigWorld.player().debugViewer_pushToView(wgPickle.dumps(wgPickle.FromServerToServer, fromClient))
                else:
                    BigWorld.globalData['Arbiter'].pushToView(wgPickle.dumps(wgPickle.FromServerToServer, _puck_buffer))
            self.__newViewers.clear()
        return
예제 #2
0
 def __pushToClientNewKey(self, dvKey, keyDescription):
     if IS_CLIENT:
         BigWorld.player().debugViewer_addNewKey(dvKey, wgPickle.dumps(wgPickle.FromServerToServer, keyDescription))
     else:
         arbiter = BigWorld.globalData.get('Arbiter', False)
         if arbiter:
             arbiter.addNewKey(dvKey, wgPickle.dumps(wgPickle.FromServerToServer, keyDescription))
         else:
             self.__lazyInitialization = True
예제 #3
0
    def __proccessSending(self, player):
        LOG_DEBUG('Send stats data', len(self.__pendingData),
                  self.__pendingData)
        lenToSend = 0
        if not self.__pendingData:
            self.__sendCallback = None
            return
        else:
            for i, sData in enumerate(self.__pendingData):
                lenToSend += len(str(sData[1]))
                if i > self.MAX_SEND_STATS_COUNT or lenToSend > self.MAX_SEND_STATS_LENGTH:
                    break

            data = wgPickle.dumps(wgPickle.FromClientToServer,
                                  self.__pendingData[:i + 1])
            if len(data) > MAX_SEND_DATA_SIZE:
                LOG_ERROR('wrong stats data is to long, ingorred', len(data))
                self.__sendCallback = None
                return
            try:
                player.base.updateClientStats(CLIENT_STATS_TYPE.CLIENT_CONTROL,
                                              data)
            except:
                pass

            self.__pendingData = self.__pendingData[i + 1:]
            if self.__pendingData:
                self.__sendCallback = BigWorld.callback(
                    0.25, partial(self.__proccessSending, player))
            else:
                self.__sendCallback = None
            return
예제 #4
0
    def updateWaitingStats(self):
        if self._account is None or self._newPendingCount == 0:
            return
        else:
            waitData = {}
            for waitingType, info in self._pending.iteritems():
                infoLen = len(info)
                if infoLen > 1:
                    info.sort()
                    if len(info) % 2 == 0:
                        median = info[infoLen // 2]
                    else:
                        median = (info[(infoLen + 1) // 2] +
                                  info[(infoLen - 1) // 2]) / 2.0
                    waitData[waitingType] = [
                        infoLen, info[0], info[-1],
                        sum(info) / infoLen, median
                    ]
                elif infoLen == 1:
                    waitData[waitingType] = [
                        1, info[0], info[0], info[0], info[0]
                    ]

            if waitData:
                player = self.getPlayer()
                if player:
                    waitData = wgPickle.dumps(wgPickle.FromClientToServer,
                                              waitData.items())
                    player.base.updateClientStats(
                        CLIENT_STATS_TYPE.CLIENT_WAITING_TIME, waitData)
                    self._newPendingCount = 0
            return
예제 #5
0
 def sendCmd(self, commandID, callback, targetID, *args):
     """
     Double pickle args (cPickle+msgpack) and send them to server
     :param commandID: command id (QA_FUNCTIONS)
     :param callback: callback(requestID, result, response),
                      called in onCmdResponse
     :param targetID:
     :param args: command parameters (unpickled)
     """
     requestID = next(idGenerator)
     if callback is None:
         callback = self.__onCmdCallback
     if targetID == -1:
         targetID = self.client.id
     self.deferredRequests[requestID] = callback
     argstr = wgPickle.dumps(wgPickle.FromServerToServer, args)
     arg = wgPickle.dumps(wgPickle.FromClientToServer, argstr)
     self.server.doCommand(requestID, commandID, targetID, arg)
     return
 def _sendOperationResponse(self, operation, returnCode, *args):
     """
     @type operation: ReceivedOperation
     @param returnCode:
     @param args:
     """
     responseData = wgPickle.dumps(self.__dumpsTransferType, args)
     if self.__streamer:
         self.__streamer.toClientReceiveResponse(
             RESPONSE_TYPE.RESPONSE_TYPE_CMD, operation.invocationId,
             returnCode, responseData)
     else:
         self._sender.receiveOperationResponse(operation.invocationId,
                                               returnCode, responseData)
예제 #7
0
 def sendOperationTo(self, recipient, operationCode, timeout, timeoutClientNotification, *args):
     """
     Send operation to specific recipient
     @type recipient: MAILBOX
     @param operationCode:
     @param timeout:
     @param timeoutClientNotification:
     @param args:
     """
     if recipient is None:
         raise Exception, 'OperationSender::sendOperationTo: Trying to send operation to recipient which is None'
     if timeout is None or timeout <= 0:
         timeout = None
     operation = self._getNextOperation(operationCode, timeout, timeoutClientNotification)
     operationData = wgPickle.dumps(self.__dumpsTransferType, args)
     recipient.receiveOperation(operation.invocationId, operationCode, operationData)
     return operation
예제 #8
0
    def __init__(self):
        self.__newViewers = set()
        self.__storage = defaultdict(StorageData)
        self.__addSettingsStorage = {}
        self.__dvKeyArray = {}
        self.__filter = {}
        if IS_CLIENT:
            self.setFilter(-1, wgPickle.dumps(wgPickle.FromClientToServer, {}))
        else:
            globalData = BigWorld.globalData
            arbiterAllListener = globalData.get('ArbiterAllListener', [])
            for viewerId in arbiterAllListener:
                key = FILTER_KEY + str(viewerId)
                try:
                    self.setFilter(viewerId, globalData.get(key, None))
                except KeyError:
                    pass

        self.__lazyInitialization = False
        MultiUpdate.__init__(self, (0.1, self.__updateData))
        return
 def sendOperationTo(self, recipient, operationCode, timeout, timeoutClientNotification, *args):
     """
     Send operation to specific recipient
     @type recipient: MAILBOX
     @param operationCode:
     @param timeout:
     @param timeoutClientNotification:
     @param args:
     """
     if recipient is None:
         raise Exception, 'OperationSender::sendOperationTo: Trying to send operation to recipient which is None'
     if timeout is None or timeout <= 0:
         timeout = None
     operation = OperationSender._getNextOperation(self, operationCode, timeout, timeoutClientNotification)
     operationData = wgPickle.dumps(wgPickle.FromServerToClient, args)
     if self.__receiverBase:
         self.__receiverBase.toClientReceiveResponse(RESPONSE_TYPE.RESPONSE_TYPE_OPERATION, operation.invocationId, operationCode, operationData)
     else:
         if len(operationData) > STREAM_CLIENT.USE_PROXY_STREAM_FROM_SIZE:
             LOG_ERROR('Arguments is to log, define base for send by stream functionality op, size', operationCode, len(operationData))
         recipient.clientReceiveResponse(RESPONSE_TYPE.RESPONSE_TYPE_OPERATION, 0, operation.invocationId, operationCode, operationData)
     return operation
예제 #10
0
DB_NAME = 'cache.dat'
CACHE_TABLE_NAME = 'cache'
CHECK_TABLE_EXIST = 'SELECT count(*) FROM sqlite_master WHERE type="table" AND name="%s"' % CACHE_TABLE_NAME
CREATE_TABLE = 'CREATE table %s (id INT64 PRIMARY KEY, data BLOB, expiringTime FLOAT)' % CACHE_TABLE_NAME
GET_DATA = 'SELECT data, expiringTime FROM %s WHERE id = ?' % CACHE_TABLE_NAME
SET_DATA = 'INSERT OR REPLACE INTO %s VALUES (?, ?, ?)' % CACHE_TABLE_NAME
DELETE_DATA = 'DELETE FROM %s WHERE id = ?' % CACHE_TABLE_NAME
REINDEX = 'REINDEX'
VACUUM = 'VACUUM'
CLEAR_CACHE_TAG = 'clear-cache'
CLEAR_CACHE_DONE = False
SQL_CONNECTION = None
CACHE_PATH = None
ID_TYPE = int
encoder = lambda data: base64.b64encode(
    wgPickle.dumps(wgPickle.FromClientToClient, data, compress=False))
decoder = lambda data: wgPickle.loads(wgPickle.FromClientToClient,
                                      base64.b64decode(data))


def init(cachePath):
    global CACHE_PATH
    global CLEAR_CACHE_DONE
    CACHE_PATH = cachePath
    LOG_DEBUG('Init sql cache...')
    if CLEAR_CACHE_TAG in sys.argv and not CLEAR_CACHE_DONE:
        LOG_DEBUG('Delete sql cache from command line option...')
        deleteCache()
        CLEAR_CACHE_DONE = True
        LOG_DEBUG('Done')
    __createCacheStorage()
예제 #11
0
 def pushToView(self, dvKey, *args):
     self.__storage[dvKey].data = wgPickle.dumps(wgPickle.FromServerToClient, *args)
예제 #12
0
 def sendSystemMessage(msgType):
     import wgPickle
     account.sendSystemMessage(time.time(), '', wgPickle.dumps(wgPickle.FromServerToServer, {'memberID': memberID,
      'planeID': planeID,
      'specializationID': member[BARRACK_KEYS.SPECIALIZATION]}), msgType)