def delay(inputs): days = int(inputs['days']) room = Room.find_one({'addrindex': session.addrindex}) if not room: return '找不到房间信息,已经删了?' delay = datetime.utcnow() + timedelta(days=days) Room.find_and_modify({'addrindex': session.addrindex}, {'$set':{'last_check': delay}}) return '到{0}前不会发送提醒邮件。'.format(delay)
def test_add_user(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) self.assertIn( user._id, Room(_id=room._id)._object['users'] )
def test_add_user_twice(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) room.add_user(user) self.assertEqual( Room(_id=room._id)._object['users'].count(user._id), 1 )
def cmd_create_room(self, args): print "creating room" blind = int(args["blind"]) max_stake = int(args["max_stake"]) min_stake = int(args["min_stake"]) max_player = int(args["max_player"]) routing_key = args['source'] roomType = int(args["roomType"]) newRoom = Room.new(self.exchange,blind,max_player, max_stake, min_stake,roomType) self.room_list[newRoom.id] = GameRoom( newRoom, args["user_id"], self, max_player,blind,min_stake,max_stake) print newRoom message = {"room_id":newRoom.id} self.channel.basic_publish( exchange = self.exchange, routing_key = routing_key, body = json.dumps(message)) self.info.rooms += 1
def edit_property(): from database import Property, Room informations = request.get_json() if 'id' in informations: property = Property.query.filter_by(id=informations['id'], owner_id=g.user.id).first() if not property: return jsonify({'error': 'Property not existing or not yours'}) else: if 'name' in informations: if informations[ 'name'] != property.name and Property.query.filter_by( name=informations['name']).count() == 0: property.name = informations['name'] if 'city' in informations: property.city = informations['city'] if 'type' in informations: property.type = informations['type'] if 'description' in informations: property.description = informations['description'] if 'address' in informations: property.address = informations['address'] if 'rooms' in informations: for room in informations['rooms']: if 'action' in room: if room['action'] == 'add': var = Room() var.property_id = property.id if 'area' in room: var.area = room['area'] else: var.area = None if 'description' in room: var.description = room['description'] else: var.description = "" db.session.add(var) elif room['action'] == 'delete' and 'id' in room: var = Room.query.filter_by(id=room['id']).first() db.session.delete(var) elif room['action'] == 'edit' and 'id' in room: var = Room.query.filter_by(id=room['id']).first() if 'area' in room: var.area = room['area'] if 'description' in room: var.description = room['description'] db.session.commit() final_property = Property.query.filter_by( id=informations['id']).first() return jsonify(final_property.serialize) else: return jsonify({'error': 'ID of property missing'})
def create_test_api(): room = Room.query.filter_by(id=request.args.get('room_id', -1)).first() if room is None: room = Room('', request.args.get('password', '')) DB.session.add(room) DB.session.commit() room.description = request.args.get('description', '') if request.args.get('password') is not None: session[str(room.id)] = request.args.get('password') for key, case in json.loads(request.args.get('cases', '{}')).items(): tests = case.get("tests", "") expects = case.get("expects", "") id = case.get("id", 0) testdata = TestData(id, room.id, tests, expects) DB.session.add(testdata) DB.session.commit() return json.dumps({"url": '/edit/{}'.format(room.id), "room_id": room.id})
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 test_remove_inexistent_user(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) room.remove_user(user) self.assertNotIn( user._id, Room(_id=room._id)._object['users'] )
def handle_init_file(self, fname, isDebug): info = Room.find_all(exchange=self.exchange) for room in info: room.remove() # if os.path.isfile(fname): print len(fname) print os.getcwd() with open(fname) as f: for line in f: if line[0] == '#': continue (roomType, blind, max_stake, min_stake, max_player) = (int(x) for x in line.strip().split(',')) newRoom = Room.new(self.exchange, blind, max_player, max_stake, min_stake, roomType) self.room_list[newRoom.id] = GameRoom(newRoom, 1, self, max_player, blind, min_stake, max_stake) self.info.rooms += 1 print newRoom
def handle_init_file(self,fname,isDebug): info = Room.find_all(exchange = self.exchange) for room in info: room.remove() # if os.path.isfile(fname): print len(fname) print os.getcwd() with open(fname) as f: for line in f: if line[0] == '#': continue (roomType,blind,max_stake,min_stake,max_player) = ( int(x) for x in line.strip().split(',')) newRoom = Room.new(self.exchange,blind,max_player, max_stake, min_stake,roomType) self.room_list[newRoom.id] = GameRoom( newRoom, 1, self, max_player, blind, min_stake, max_stake) self.info.rooms += 1 print newRoom
def test_draft(self): owner = User(name="joe") room = Room(owner=owner) for name in ['john','carl','james']: user = User(name=name) room.add_user(user) self.assertIn( room.draft(), Room(_id=room._id)._object['users'] )
def write_new_room(database, numMafia): targets = Targets("", "", "") new_room = Room( generateGameRoomKey(), int(numMafia), 0, [], targets, "pre-game", "pre-game", True, uuid.uuid4().hex, [], [Message("Waiting for players", "Waiting for players")], [Message("Waiting for players", "Waiting for players")] ) database.append(new_room) return database, new_room
def add_property(): from database import Property, Room informations = request.get_json() if 'name' in informations and 'city' in informations: if Property.query.filter_by(name=informations['name'], owner_id=g.user.id).first() is None: property = Property() property.name = informations['name'] property.city = informations['city'] property.owner_id = g.user.id if 'type' in informations: property.type = informations['type'] else: property.type = "" if 'description' in informations: property.description = informations['description'] else: property.description = "" if 'address' in informations: property.address = informations['address'] else: property.address = "" db.session.add(property) db.session.commit() if 'rooms' in informations: property_id = Property.query.filter_by( name=informations['name'], owner_id=g.user.id).first().id for room in informations['rooms']: var = Room() var.property_id = property_id if 'area' in room: var.area = room['area'] else: var.area = None if 'description' in room: var.description = room['description'] else: var.description = "" db.session.add(var) db.session.commit() final_property = Property.query.filter_by( name=informations['name'], owner_id=g.user.id).first() return jsonify(final_property.serialize) else: return jsonify({'error': 'Name already existing'}) else: return jsonify({'error': 'City or name is missing'})
def create_test_room(): players = [ Player('alan', '12354', 'mafia', 'alive', False), Player('noob1', '42314', 'civilian', 'alive', False), Player('noob2', '22222', 'civilian', 'alive', False), Player('noob3', '33333', 'civilian', 'alive', False), Player('noob4', '44444', 'civilian', 'alive', False) ] targets = Targets('', '', '') gameMessages = [Message('Pre-Game', 'Waiting for players...')] observerMessages = [ Message('Pre-Game', 'Waiting for players...'), Message('Observer Message', 'Testing...') ] room = Room('0001', 2, 0, players, targets, 'pre-game', 'pre-game', True, '55555', [], gameMessages, observerMessages) database.append(room) LOG.info('Test room created..')
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 cmd_create_room(self, args): print "creating room" blind = int(args["blind"]) max_stake = int(args["max_stake"]) min_stake = int(args["min_stake"]) max_player = int(args["max_player"]) routing_key = args['source'] roomType = int(args["roomType"]) newRoom = Room.new(self.exchange, blind, max_player, max_stake, min_stake, roomType) self.room_list[newRoom.id] = GameRoom(newRoom, args["user_id"], self, max_player, blind, min_stake, max_stake) print newRoom message = {"room_id": newRoom.id} self.channel.basic_publish(exchange=self.exchange, routing_key=routing_key, body=json.dumps(message)) self.info.rooms += 1
def create(): # Get player id stored in a cookie player_id = request.cookies.get('uuid') # List of all players on the website player = Player.query.filter_by(uuid=player_id).first() # If user doesnt have a name and id assigned, redirect them to create one if not player_id or not player: return redirect('/name/create') if request.method == 'POST': # User has not accepted the use of cookies if not request.cookies.get('cookies'): return render_template( 'create.html', settings=settings_values, error='You must accept the use of cookies before proceeding.') # Validate recaptcha if not recaptcha.verify(): return render_template('create.html', settings=settings_values, error='ReCaptcha failed.') difficulty = Difficulty.query.filter_by( name=request.form.get('difficulty')).first() goal = Goal.query.filter_by(name=request.form.get('goal')).first() logic = Logic.query.filter_by(name=request.form.get('logic')).first() mode = Mode.query.filter_by(name=request.form.get('mode')).first() variation = Variation.query.filter_by( name=request.form.get('variation')).first() weapons = Weapons.query.filter_by( name=request.form.get('weapons')).first() settings = Settings(difficulty, bool(request.form.get('enemizer')), goal, logic, mode, bool(request.form.get('spoilers')), bool(request.form.get('tournament')), variation, weapons) settings_validate, settings_error = validation.validate_settings( settings) # Make certain that all selected settings exist if not settings_validate: return render_template('create.html', settings=settings, error=settings_error) seed = alttpr_api.generate_seed(settings.to_dict()) hash_code = seed['hash'] chat_url = chat.get_chat_room(hash_code) # Create a game room room = Room(settings=settings, chat_url=chat_url, creator=player, hash_code=hash_code) #db.session.add(settings) db.session.add(room) db.session.commit() # generate response that redirects to the game room just created response = make_response(redirect(f'/room/{room.hash_code}')) return response else: return render_template('create.html', settings=settings_values, error=None)
addr='zeiozrez') session.add(ch1) session.add(ch2) session.add(ch3) session.add(ch4) print("Checkouts Done :)") ################################### r1 = Room( title='Junior Suit', description= 'body="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essenti', price='400', mode='CLOSED', home_img='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img1_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img2_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img3_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', capacity='5') r2 = Room( title='Sinior Suit', description= 'body="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essenti', price='700', mode='CLOSED', home_img='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img1_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img2_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img3_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg',
def post(self): roomType = int(self.get_argument('type', 0)) rooms = Room.find_all(roomType=roomType) rooms = [(r.id, r.blind, r.player, r.max_player, r.min_stake, r.max_stake) for r in rooms] self.write(json.dumps({"rooms": rooms}))
def post(self): roomType = int(self.get_argument('type',0)) rooms = Room.find_all(roomType=roomType) rooms = [(r.id,r.blind,r.player,r.max_player,r.min_stake,r.max_stake) for r in rooms] self.write(json.dumps({"rooms":rooms}))
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!"
def test_delete_room(self): owner = User(name="joe") room = Room(owner=owner) room.delete() self.assertRaises(Exception,Room(_id=room._id))
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!"