Esempio n. 1
0
 def check_all(self, delay=12):
     cursor = Room.find()
     cursor = cursor.batch_size(5)
     for room in cursor:
         if room.has_key('last_check'):
             if time.utcnow() - room.last_check >= datetime.timedelta(hours=delay):
                 self.check_balance(room)
         else:
             self.check_balance(room)
    def post(self):
        self.mongodb = self.application.settings['_db']
        user = self.user
        seat = self.get_argument('seat')
        stake = self.get_argument('stake')

        if False and 'is_sit_down' in self.session and \
         self.session['is_sit_down'] == True and \
         self.session['seat'] == seat:
            self.write(json.dumps({'status': 'success'}))
            self.finish()
        else:
            messages = self.mongodb.board.find_one(
                {"id": self.session.session_id})
            room = Room.find(_id=messages["room_id"])
            if room is None:
                self.finish(json.dumps({'status': 'failed'}))
                return

            queue_name = str(user.username) + '_sit'
            exchange_name = self.session['exchange']

            user.room_id = room.id
            #exchange_name	= str(user.room.exchange)
            #source_key		= "%s_%s" % (exchange_name, queue_name)

            message = {
                'method': 'sit',
                'user_id': user.id,
                'seat': seat,
                #'source':source_key,
                'room_id': str(user.room_id),
                'private_key': self.session['private_key'],
                'stake': stake
            }

            arguments = {'routing_key': 'dealer', 'message': message}
            self.channel = Channel(self.application.channel, exchange_name)
            self.channel.add_ready_action(self.sit_call_back, arguments)
            self.channel.connect()
	def post(self):
		self.mongodb = self.application.settings['_db']
		user		= self.user
		seat		= self.get_argument('seat')
		stake		= self.get_argument('stake')

		if False and 'is_sit_down' in self.session and \
			self.session['is_sit_down'] == True and \
			self.session['seat'] == seat:
			self.write(json.dumps({'status':'success'}))
			self.finish()
		else:
			messages		= self.mongodb.board.find_one({"id":self.session.session_id})
			room			= Room.find(_id=messages["room_id"])
			if room is None:
				self.finish(json.dumps({'status':'failed'}))
				return

			queue_name		= str(user.username) + '_sit'
			exchange_name   = self.session['exchange']

			user.room_id	= room.id
			#exchange_name	= str(user.room.exchange)
			#source_key		= "%s_%s" % (exchange_name, queue_name)

			message			=	{
									'method':'sit',
									'user_id':user.id,
									'seat':seat,
									#'source':source_key,
									'room_id':str(user.room_id),
									'private_key':self.session['private_key'] ,
									'stake':stake
								}

			arguments		= {'routing_key': 'dealer', 'message':message}
			self.channel	= Channel(self.application.channel, exchange_name)
			self.channel.add_ready_action(self.sit_call_back, arguments)
			self.channel.connect()
	def post(self):
		message			= None
		user			= self.user
		room_id			= self.get_argument('room_id')
		room			= Room.find(_id = room_id)
		if not room:
			print Room.find_all()
			print "not a valid room",room_id
			self.finish()
			return

		self.mongodb	= self.application.settings['_db']
		msg = {"id":self.session.session_id, "room_id":room.id}

		BoardMessage.get_collection().remove({
						"id":self.session.session_id,
						},safe=True)

		# guarantee only one exist
		self.mongodb.board.update({"id":self.session.session_id},msg,upsert=True)

		exchange			= str(room.exchange)

		self.session['exchange'] = exchange

		public_key			= ('broadcast_%s_%s.testing')% (exchange, room._id)
		private_key			= ('direct.%s.%s.%s') % (exchange, room._id, user._id)
		binding_keys		= [public_key, private_key]
		if user.isBot:
			bot_key			= ('direct.%s.%s.bot') % (exchange, room._id)
			binding_keys.append(bot_key)
			self.session['bot_key'] = bot_key


		message				= {	'method'		: 'enter',
								'user_id'		: user.id,
								'room_id'		: room.id,
								'private_key'	: private_key}

		arguments			= {'routing_key': 'dealer', 'message': message}
		self.broadcast_channel = broadcast_channel	= PersistentChannel(
									self.application.channel,
									"%s%s" % (str(self.session.session_id),room.id[-10:]),
									exchange,
									binding_keys,
									declare_queue_only=True,
									arguments = {"x-expires":int(600000)}
									)

		self.callBackCount = 0
		broadcast_channel.add_ready_action(self.initial_call_back,
				arguments)
		broadcast_channel.connect()

		self.channel = Channel(self.application.channel,exchange)

		self.channel.add_ready_action(self.initial_call_back, arguments);
		self.channel.connect()
		self.session['public_key']	= public_key
		self.session['private_key']	= private_key
		#self.session['messages']	= list()
		print "ENTER!"
Esempio n. 5
0
 def check(self,addr):
     room = Room.find({"addrindex":addr}).next()
     self.check_balance(room)
    def post(self):
        message = None
        user = self.user
        room_id = self.get_argument('room_id')
        room = Room.find(_id=room_id)
        if not room:
            print Room.find_all()
            print "not a valid room", room_id
            self.finish()
            return

        self.mongodb = self.application.settings['_db']
        msg = {"id": self.session.session_id, "room_id": room.id}

        BoardMessage.get_collection().remove({
            "id": self.session.session_id,
        },
                                             safe=True)

        # guarantee only one exist
        self.mongodb.board.update({"id": self.session.session_id},
                                  msg,
                                  upsert=True)

        exchange = str(room.exchange)

        self.session['exchange'] = exchange

        public_key = ('broadcast_%s_%s.testing') % (exchange, room._id)
        private_key = ('direct.%s.%s.%s') % (exchange, room._id, user._id)
        binding_keys = [public_key, private_key]
        if user.isBot:
            bot_key = ('direct.%s.%s.bot') % (exchange, room._id)
            binding_keys.append(bot_key)
            self.session['bot_key'] = bot_key

        message = {
            'method': 'enter',
            'user_id': user.id,
            'room_id': room.id,
            'private_key': private_key
        }

        arguments = {'routing_key': 'dealer', 'message': message}
        self.broadcast_channel = broadcast_channel = PersistentChannel(
            self.application.channel,
            "%s%s" % (str(self.session.session_id), room.id[-10:]),
            exchange,
            binding_keys,
            declare_queue_only=True,
            arguments={"x-expires": int(600000)})

        self.callBackCount = 0
        broadcast_channel.add_ready_action(self.initial_call_back, arguments)
        broadcast_channel.connect()

        self.channel = Channel(self.application.channel, exchange)

        self.channel.add_ready_action(self.initial_call_back, arguments)
        self.channel.connect()
        self.session['public_key'] = public_key
        self.session['private_key'] = private_key
        #self.session['messages']	= list()
        print "ENTER!"