def initPenguinIglooRoom(self, penguin_id): penguin = ( yield Penguin.find(penguin_id) ) if penguin_id != self.penguin['id'] else self.penguin.dbpenguin if penguin is None: returnValue(None) iglooRoom = self.penguin.engine.iglooCrumbs.getPenguinIgloo(penguin_id) currentIgloo = int(penguin.igloo) igloo = yield Igloo.find(currentIgloo) if igloo is None: igloo = Igloo(penguin_id=penguin_id) yield igloo.save() currentIgloo = penguin.igloo = int(igloo.id) yield penguin.save() yield igloo.refresh() if iglooRoom is None: iglooRoom = IglooRoom(self.penguin.engine.roomHandler, (1000 + penguin_id), '{} igloo'.format(penguin_id), "{}'s Igloo".format(penguin.nickname), 100, False, False, None) self.penguin.engine.iglooCrumbs.penguinIgloos.append(iglooRoom) self.penguin.engine.roomHandler.rooms.append(iglooRoom) iglooRoom.owner = int(penguin_id) iglooRoom.opened = not bool(igloo.locked) iglooRoom._id = int(igloo.id) returnValue(iglooRoom)
def handleCanLike(client, data): igloo_id = client['room']._id igloo = yield Igloo.find(igloo_id) if igloo is None: returnValue( client.send( 'cli', int(igloo.id), 201, '{"canFuck": true, "periodicity": "Hourly", "nextFuck_msec": 0}' )) likes = yield igloo.iglooLikes.get() iglooLikes = {i.penguin_swid: i for i in likes} canLike = False nextLike = 0 if client['swid'] not in iglooLikes: canLike = True else: like_obj = iglooLikes[client['swid']] lastLike = like_obj.get_time() span = (lastLike + 24 * 60 * 60) - time() canLike = span < 0 nextLike = (lastLike + 24 * 60 * 60) - time() client.send( 'cli', int(igloo.id), 200, json.dumps({ 'canLike': canLike, 'periodicity': 'ScheduleDaily', 'nextLike_msecs': int(nextLike * 1000) })) returnValue(canLike)
def handleGetOpenIgloos(client, data): open_igloos = list() myLikes = yield client['currentIgloo'].get_likes_count() myPopl = len(client['igloo']) friends_by_id = map(lambda x: x.friend, client['data'].friends) igloos = list(client.engine.iglooCrumbs.penguinIgloos) for igloo in igloos: if not client['moderator'] and not igloo.opened \ and igloo.owner != client['id'] and igloo.owner not in friends_by_id: continue igloo_id = igloo._id owner = igloo.owner penguin = client.engine.getPenguinById(owner) iglooDB = yield Igloo.find(igloo_id) if (not client['moderator'] and penguin is None) or iglooDB is None: continue if penguin is None: nickname = (yield Penguin.find(where=['id=?', owner], limit=1)).nickname else: nickname = penguin['nickname'] iglooLikes = yield iglooDB.get_likes_count() open_igloos.append('|'.join( map(str, [owner, nickname, iglooLikes, len(igloo), 0]))) client.send('gr', myLikes, myPopl, *open_igloos)
def handleGetPlayerIgloo(client, _id): iglooRoom = yield client['RefreshHandler'].initPenguinIglooRoom(_id) if iglooRoom == None: return igloo = yield Igloo.find(iglooRoom._id) #player_id % igloo_type % music_id % floor_id % furniture_list(,) client.send('gm', _id, igloo.type, igloo.music, igloo.floor, (yield igloo.get_furnitures_string()))
def handleGetPlayerIgloo(client, _id): iglooRoom = yield client['RefreshHandler'].initPenguinIglooRoom(_id) if iglooRoom == None: return igloo = yield Igloo.find(iglooRoom._id) likes = yield igloo.get_likes_count() furnitures = yield igloo.get_furnitures_string() details = [igloo.id, 1, 0, int(bool(igloo.locked)), igloo.music, igloo.floor, igloo.location, igloo.type, likes, furnitures] client.send('gm', _id, ':'.join(map(str, details)))
def handleGetFriendIgloos(client, data): friends_by_id = map(lambda x: x.friend, client['data'].friends) friend_igloos = [i for i in client.engine.iglooCrumbs.penguinIgloos if i.owner in friends_by_id] availIgloos = list() for igloo in friend_igloos: _igloo = yield Igloo.find(igloo._id) if _igloo is None: continue likes = yield _igloo.get_likes_count() availIgloos.append('|'.join(map(str, [int(igloo.owner), likes]))) client.send('grf', *availIgloos) if len(availIgloos) > 0 else client.send('%xt%grf%-1%')
def handleLikeIgloo(client, data): igloo_id = client['room']._id igloo = yield Igloo.find(igloo_id) if igloo is None: return can_like = yield handleCanLike(client, []) if not can_like: returnValue(None) penguinIglooLike = yield igloo.iglooLikes.get(where = ['penguin_swid = ?', client['swid']], limit = 1) if penguinIglooLike is None: penguinIglooLike = yield IglooLike(penguin_swid=client['swid'], igloo_id=igloo_id, likes = 0).save() penguinIglooLike.likes = int(penguinIglooLike.likes) + 1 yield penguinIglooLike.save() client['room'].sendExcept(client['id'], 'lue', client['swid'], int(penguinIglooLike.likes))
def handleGetIglooLikes(client, start, end): igloo = yield Igloo.find(client['room']._id) if igloo is None: returnValue(client.send('gili', 0, 204, '{"about": "I don\' think you notice, I don\'t think you care.!"}')) likes = yield igloo.get_likes_count() likesList = yield igloo.iglooLikes.get(limit = (end, start)) like = { 'likedby': { 'counts': { 'count': int(likes), 'maxCount': 5000, 'accumCount': int(likes) }, 'IDs': map(lambda x: x.penguin_swid, likesList) } } client.send('gili', igloo.id, 200, json.dumps(like))