示例#1
0
文件: core.py 项目: kestred/sandbox
    def on_authenticate(self, data):
        core = Core.getInstance()

        # Check Public ID
        if not 'publicId' in data:
            util.socketError(self, 'Missing public key.')
            return
        publicId = data['publicId']
        if not util.validPublicId(publicId):
            util.socketError(self, 'Invalid public key.')
            return

        # Handle reconnection
        if publicId in core.clients:
            if not core.validIdPair(data):
                self.emit('authenticate', {'status': 'fail'})
                return
            client = core.clients[publicId]
            client.sockets['core'] = self
            self.socket.session['client'] = client
            self.emit('authenticate', {'status': 'success'})
            return

        # Distribute privateId
        secret = None
        if('privateId' in data
           and util.validPrivateId(data['privateId'])):
            secret = data['privateId']
        else:
            secret = util.randomKey(32)
        self.client = Client(publicId, secret)
        self.client.sockets['core'] = self
        core.clients[publicId] = self.client
        self.emit('authenticate', {'status': 'success'
                                 , 'privateId': secret})
示例#2
0
文件: core.py 项目: kestred/sandbox
 def stderr(self, message, client):
     socket = None  # TODO: Default to gamemaster
     if hasattr(client, 'sockets'):
         socket = client.sockets['core']
     else:
         socket = self.clients[client].sockets['core']
     util.socketError(socket, message)