def swap(self): data = { 'authToken': self.parent.authtoken, 'gameId': self.id, } print('swapping') url = "{}/game/swap".format(self.SERVER) post(url, data)
def invite_accept(self, pending): url = "{}/game/invitation".format(self.SERVER) key = 'id' if 'displayname' in pending else 'invId' print('accepting invite from ' + pending[key]) data = { 'gameInviteId': pending[key], 'action': 'accept', 'authToken': self.authtoken, 'tilesetId': 0, } post(url, data)
def submit_word(self, word, wait=3): assert isinstance(word, Word) if wait > 0: print('Waiting {}s'.format(wait)) #sleep(wait) print('playing {} for {} points against {}' .format(word.__str__(), word.value, self.gamedata['otherName'])) print('using ' + ','.join(x.__str__() for x in self.letters) + ' ' + word._grid.__str__()) data = { 'authToken': self.parent.authtoken, 'word': word.__str__(), 'bestWord': word.__str__().replace('!', ''), 'gameId': self.id, } url = "{}/game/play".format(self.SERVER) res = post(url, data) valid = 'game' in res if valid: self.instance = res['game'] else: print(res) return valid
def resume(self): self.logger.info('Resuming connection') data = { 'authToken': self.authtoken, 'timestamp': 0 } resp = post('{}/game/resume'.format(self.SERVER), data=data) if 'invitesPending' in resp: for invite in resp['invitesPending']: self.invite_accept(invite)
def login(email, password): data = { 'udId': _random_string(pool=ascii_letters.lower() + digits), 'deviceToken': _random_string(183, ascii_letters + digits + '-_'), 'password': md5((password + Session.SALT).encode('ascii')).hexdigest(), 'username': email, 'country': 'nl-NL', 'deviceId': 'Android Linux', 'version': '1.88', 'locale': 'nl', } resp = post('{}/account/login'.format(Session.SERVER), data=data) return Session(resp['user']['authToken'])
def __init__(self, parent, data): self.parent = parent self.gamedata = data data = { 'authToken': parent.authtoken, 'sid': 9, 'gid': self.id, 'cycle': int(self.gamedata['cycle']) + 1, 'newchats': 0, } resp = post(self.SERVER_LISTEN, data) self.instance = resp['game']
def listen(self, on_list=None, on_overview=None, on_invite=None): while True: data = { 'authToken': self.authtoken, 'overviewId': self.overview_id, 'sid': ScreenId.GAME_OVERVIEW, } self.overview_id += 1 #print('beep') resp = post(self.SERVER_LISTEN, data, timeout=None) #print(json.dumps(resp, indent=4)) if 'gameList' in resp: (on_list or self.parse_game_list)(resp['gameList']) if 'gameOverview' in resp: print('overview') (on_overview or self.handle_overview)(resp['gameOverview']) if 'invite' in resp: func = on_invite or self.invite_accept list(map(func, resp['invite']['invitesPending'])) for _, game in self.instances.items(): game.play()