def handleAddLayout(client, data): igloos = yield Igloo.find(where = ['owner = ?', client['id']]) if len(igloos) > 6: returnValue(None) if not client['member']: returnValue(client.send('e', 999)) igloo = yield Igloo(owner = client['id'], location = 1, furniture = '', likes = '[]').save() yield igloo.refresh() client['iglooHandler'].append(igloo) details = [igloo.id, len(igloos)+1, 0, int(bool(igloo.locked)), igloo.music, igloo.floor, igloo.location, igloo.type, 0, igloo.furniture] client.send('al', client['id'], ':'.join(map(str, details)))
def getIglooLayoutList(client, _id): if not isinstance(client['room'], IglooRoom) or not _id == (client['room'].ext_id - 1000): returnValue(None) iglooLayouts = list() igloos = yield Igloo.find(where=['owner = ?', _id]) total_likes = 0 igloo_likes = list() ix = 0 for i in igloos: locked = True ix += 1 if i.id == client['igloo']._id: locked = i.locked likes = 0 for j in json.loads(i.likes): likes += j['count'] total_likes += likes details = [ i.id, ix, 0, int(locked), i.music, i.floor, i.location, i.type, likes, i.furniture ] iglooLayouts.append(':'.join(map(str, details))) igloo_likes.append('|'.join(map(str, [i.id, likes]))) client.send('gail', _id, 0, *iglooLayouts) client.send('gaili', total_likes, ','.join(igloo_likes))
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) likes = json.loads(str(igloo.likes)) like_details = {'id': client['swid'], 'count': 0, 'time': int(time())} for i in likes: if i['id'] == client['swid']: like_details['count'] += i['count'] likes.remove(i) break like_details['count'] += 1 likes.insert(0, like_details) likes = json.dumps(likes) igloo.likes = likes yield igloo.save() client['room'].sendExcept(client['id'], 'lue', client['swid'], like_details['count']) peng = client.engine.getPenguinById(igloo.owner) if peng is not None: if peng['iglooHandler'] is not None: yield peng['iglooHandler'].currentIgloo.refresh()
def handleGetIglooLikes(client, start, end): igloo = yield Igloo.find(client['room']._id) if igloo is None: returnValue( client.send('gili', 0, 204, '{"about": "You are a pms and I know it!"}')) likes = str(igloo.likes) likes = json.loads(likes) count = 0 for i in likes: count += i['count'] like = { 'likedby': { 'counts': { 'count': count, 'maxCount': 5000, 'accumCount': count }, 'IDs': likes[start:end] } } client.send('gili', igloo.id, 200, json.dumps(like))
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 = json.loads(igloo.likes) like_str = { 'canLike': True, 'periodicity': 'ScheduleDaily', 'nextLike_msecs': 0 } now = int(time()) for i in likes: if i['id'] != client['swid']: continue last_like = int(i['time']) span = int((now - last_like) / (24 * 60 * 60)) if not span > 0: like_str['canLike'] = False like_str['nextLike_msecs'] = span * 1000 break client.send('cli', int(igloo.id), 200, json.dumps(like_str)) returnValue(like_str['canLike'])
def handleIsIglooOpen(client, _id): iglooRoom = yield client['iglooHandler'].createPenguinIgloo(_id) if iglooRoom == None: return igloo = yield Igloo.find(iglooRoom._id) client.send('pio', int(not bool(int(igloo.locked))))
def handleUpdateIglooSlotSummary(client, _id, summary): if not _id in client['iglooHandler']: returnValue(None) client['iglooHandler'].currentIgloo = client['iglooHandler'].find(_id) client['igloo']._id = _id client.dbpenguin.igloo = client['iglooHandler'].currentIgloo.id client.dbpenguin.save() likes = 0 for i in summary: _i = i[0] locked = int(bool(i[1])) if not locked and not client['member']: client.send('e', 999) locked = 1 igloo = yield Igloo.find(_i) igloo.locked = locked igloo.save() if _i == _id: client['igloo'].opened = not locked igloo = client['iglooHandler'].currentIgloo for i in json.loads(str(igloo.likes)): likes += i['count'] details = [igloo.id, 1, 0, int(bool(igloo.locked)), igloo.music, igloo.floor, igloo.location, igloo.type, likes, igloo.furniture] client['igloo'].send('uvi', client['id'], ':'.join(map(str, details)))
def handleGetPlayerIgloo(client, _id): iglooRoom = yield client['iglooHandler'].createPenguinIgloo(_id) if iglooRoom == None: return igloo = yield Igloo.find(iglooRoom._id) likes = 0 if igloo.likes != '' and igloo.likes != None: j = json.loads(igloo.likes) for i in j: likes += i['count'] details = [igloo.id, 1, 0, int(bool(igloo.locked)), igloo.music, igloo.floor, igloo.location, igloo.type, likes, igloo.furniture] client.send('gm', _id, ':'.join(map(str, details)))
def handleGetOpenIgloos(client, data): open_igloos = list() myLikes = 0 myPopl = 0 friends_by_id = [k[1] for k in client['friendsHandler'].friends] for igloo in client.engine.iglooCrumbs.penguinIgloos: if not igloo.opened and igloo.owner != client[ 'id'] and igloo.owner not in friends_by_id: continue _id = igloo._id owner = igloo.owner penguin = client.engine.getPenguinById(owner) if penguin is None: continue _igloo = yield Igloo.find(_id) if _igloo is None: continue likes = 0 like_json = json.loads(_igloo.likes) for _ in like_json: likes += _['count'] if igloo.owner != client['id']: open_igloos.append('|'.join( map(str, [ int(penguin['id']), penguin['nickname'], likes, len(igloo), int(not igloo.opened) ]))) else: myLikes = likes myPopl = len(igloo) client.send('gr', myLikes, myPopl, *open_igloos if len(open_igloos) > 0 else '')
def handleGetFriendIgloos(client, data): friends_by_id = [k[1] for k in client['friendsHandler'].friends] friend_igloos = [ igloo for igloo in client.engine.iglooCrumbs.penguinIgloos if igloo.owner in friends_by_id ] availIgloos = list() for igloo in friend_igloos: _igloo = yield Igloo.find(igloo._id) if _igloo is None: continue likes = 0 like_json = json.loads(_igloo.likes) for _ in like_json: likes += _['count'] availIgloos.append('|'.join(map(str, [int(igloo.owner), likes]))) client.send('grf', *availIgloos if len(availIgloos) > 0 else '')