def user_list(self, uids): result = [] for uid in uids: player = Player.get(uid) if player: result.append({ "uid": str(uid), "name": player.name, "fbname": player.fbname, "avatar": player.avatar if player.avatar else "0", "banner": player.banner if player.banner else "0", "fb_id": player.fb_id, "stars": int(player.stars), "is_local": uid == self.uid, "level": int(player.level) }) else: result.append({ "uid": str(uid), "name": "", "fbname": "", "avatar": "0", "fb_id": "", "stars": 0, "is_local": uid == self.uid, "level": 0 }) return result
def friend_request(self): player = Player.get(self.uid) name = '' fbname = '' avatar = '' if player: name = player.name fbname = player.fbname avatar = player.avatar fid = self.request.get_argument("fid", "") if not fid: return {"status": 404, "content": []} friend = Friends.get(fid) if not friend: friend = Friends() friend.pkey = fid if fid in self.friends.friends: return {"status": 405, "content": []} if len(friend.friends) >= FRIEND_LIMIT: return {"status": 406, "content": []} if len(self.friends.friends) >= FRIEND_LIMIT: return {"status": 407, "content": []} message = { "mid": shortuuid.uuid()[:8], "local_mid": "", "opened": False, "time": int(time.time()), "type": 'friend_request', "num": 1, "name": name, "fbname": fbname, "avatar": avatar, "sender": self.uid } mail = Mail.get(fid) if not mail: mail = Mail() mail.pkey = fid mail.delete_old() for message in mail.mail: if message.get("type") == "friend_request" and message.get( "sender") == self.uid: return {"status": 408, "content": []} mail.mail.insert(0, message) mail.put() return {"status": 200, "content": []}
def do_request(self, method): if method == "list": playerid = self.get_argument("playerid", "") regcode = self.get_argument("playerinvitecode", "") playername = "" friends = "" rubys = [] payments = [] if regcode: from api.data.regcode import RegCode r = RegCode.get(regcode) if r: playerid = r.uid if playerid: from api.data.player import Player p = Player.get(playerid) if p: playername = p.name from api.data.friends import Friends f = Friends.get(playerid) if f: regcode = f.code friends = ",".join(f.friends) from api.data.player import Ruby r = Ruby.get(playerid) if r: rubys = r.list sbs_id = options.sbs_key password = options.sbs_pass device_id = "adminplatform" client = Sbs(sbs_id, playerid, device_id, password, url=options.sbs_url) try: payments = yield client.getPayments(playerid) except Exception as e: logging.exception(str(e)) self.render("playerids.html", datas={}, payments=payments, playerid=playerid, invitecode=regcode, playername=playername, friends=friends, rubys=[r for r in rubys if len(r) >= 6])
def friend_accept(self): player = Player.get(self.uid) name = '' fbname = '' avatar = '' if player: name = player.name fbname = player.fbname avatar = player.avatar fid = self.request.get_argument("fid", "") if not fid: return {"status": 404, "content": []} friend = Friends.get(fid) if not friend: friend = Friends() friend.pkey = fid if fid in self.friends.friends: return {"status": 405, "content": []} if len(friend.friends) >= FRIEND_LIMIT: return {"status": 406, "content": []} if len(self.friends.friends) >= FRIEND_LIMIT: return {"status": 407, "content": []} if fid not in self.friends.friends: self.friends.friends.append(fid) self.friends.put() if self.uid not in friend.friends: friend.friends.append(self.uid) friend.put() return {"status": 200, "content": self.friends.friends}
def friend_add(self): player = Player.get(self.uid) name = '' fbname = '' avatar = '' if player: name = player.name fbname = player.fbname avatar = player.avatar fid = self.request.get_argument("fid", "") code = self.request.get_argument("code", "") invite = False if code: invite = True regcode = RegCode.get(code) if regcode: fid = regcode.uid else: return {"status": 404, "first_invite": False, "content": []} if not fid: return {"status": 404, "first_invite": False, "content": []} if fid == self.uid: return {"status": 408, "first_invite": False, "content": []} friend = Friends.get(fid) if not friend: friend = Friends() friend.pkey = fid invite_ok = False if invite and (not self.friends.inviter ) and self.device_id not in friend.invited: invited_count = len(friend.invited) if invited_count < FRIEND_LIMIT: friend.invited.append(self.device_id) invited_count += 1 mail = Mail.get(fid) if not mail: mail = Mail() mail.pkey = fid count_set = (1, 3, 10, 20) if invited_count in count_set: msg = { "mid": shortuuid.uuid()[:8], "local_mid": "invite_success_%d" % (count_set.index(invited_count) + 1), "opened": False, "time": int(time.time()), "type": "reward", "num": 1, "name": "", "fbname": "", "avatar": "", "sender": "gmuser" } mail.delete_old() mail.mail.insert(0, msg) msg = { "mid": shortuuid.uuid()[:8], "local_mid": "invite_everytime_1", "opened": False, "time": int(time.time()), "type": "reward", "num": 1, "name": "", "fbname": "", "avatar": "", "sender": "gmuser" } mail.delete_old() mail.mail.insert(0, msg) msg = { "mid": shortuuid.uuid()[:8], "local_mid": "invite_everytime_2", "opened": False, "time": int(time.time()), "type": "reward", "num": 1, "name": "", "fbname": "", "avatar": "", "sender": "gmuser" } mail.delete_old() mail.mail.insert(0, msg) mail.put() invite_ok = True friend.put() else: return {"status": 409, "first_invite": False, "content": []} if len(friend.friends) >= FRIEND_LIMIT: return { "status": 205 if invite_ok else 407, "first_invite": False, "content": [] } if len(self.friends.friends) >= FRIEND_LIMIT: return { "status": 205 if invite_ok else 406, "first_invite": False, "content": [] } if self.uid not in friend.friends: friend.friends.append(self.uid) friend.put() message = { "mid": shortuuid.uuid()[:8], "local_mid": "", "opened": False, "time": int(time.time()), "type": 'friend', "num": 1, "name": name, "fbname": fbname, "avatar": avatar, "sender": self.uid, "gift": { "type": 4, "amount": 1 } } mail = Mail.get(fid) if not mail: mail = Mail() mail.pkey = fid mail.delete_old() mail.mail.insert(0, message) mail.put() first_invite = False if fid not in self.friends.friends: self.friends.friends.append(fid) if invite and not self.friends.inviter: self.friends.inviter = fid first_invite = True self.friends.put() else: return { "status": 205 if invite_ok else 405, "first_invite": False, "content": [] } return { "status": 200 if invite_ok else 206, "first_invite": first_invite, "content": self.friends.friends }
def mail_send(self): player = Player.get(self.uid) name = '' fbname = '' avatar = '' if player: name = player.name fbname = player.fbname avatar = player.avatar message = { "mid": shortuuid.uuid()[:8], "local_mid": "", "opened": False, "time": int(time.time()), "type": self.type, "num": self.num, "name": name, "fbname": fbname, "avatar": avatar, "sender": self.uid } if self.type == "heart": friends = Friends.get(self.uid) if not friends: friends = Friends() friends.pkey = self.uid for fid in self.fids.split(","): mail = Mail.get(fid) if not mail: mail = Mail() mail.pkey = fid if self.type == "heart": # 送体力检测 f_obj = Player.get(fid) if not f_obj: logging.info("[%s]赠送体力给好友[%s]时,好友不存在!" % (self.uid, fid)) continue #好友不存在 # 判断好友是关闭了接收体力 if int(f_obj.recieve_heart) == 0: logging.info("[%s]赠送体力给好友[%s]时,好友关闭了体力接收!" % (self.uid, fid)) continue message["mid"] = shortuuid.uuid()[:8] mail.delete_old() mail.mail.insert(0, message) mail.put() if self.type == "heart": friends.hearts[fid] = int(time.time()) #if self.type == "heart": # for key,value in copy.copy(friends.hearts.items()): # if (int(time.time()) - value) > SENDHEART_INTERVAL: # del friends.hearts[key] # friends.put() result = {"status": 200, "content": []} return result
def do_request(self): method = self.request.get_argument("method", u"") if not self.uid: raise gen.Return({"status": 404, "content": []}) self.player = Player.get(self.uid) result = {"status": 200, "content": []} if not self.player: self.player = Player() self.player.pkey = self.uid self.player.put() if method == "save": self.player.pkey = self.uid self.player.name = self.request.get_argument("name", u"nobody") self.player.fbname = self.request.get_argument("fbname", u"") self.player.avatar = self.request.get_argument("avatar", u"") self.player.banner = self.request.get_argument("banner", u"") self.player.stars = int(self.request.get_argument("stars", u"0")) self.player.fb_id = self.request.get_argument("fb_id", u"") self.player.level = int(self.request.get_argument("level", u"0")) self.player.recieve_heart = int( self.request.get_argument("recieve_heart", u"1")) maillist = self.system_mails m = Mail.get(self.uid) if not m: m = Mail() m.pkey = self.uid newmail = False for mail in self.system_mails: if mail.get("mid") and mail.get( "mid") not in self.player.system_mail: mail_send = copy.deepcopy(mail) mail_send["mid"] = shortuuid.uuid()[:8] self.player.system_mail.append(mail.get("mid")) m.append(mail_send) newmail = True if newmail: m.put() self.player.put() if self.sbs_uid and self.player.fb_id: sbs_bind = FBIdBind.get(self.player.fb_id) if not sbs_bind: sbs_bind = FBIdBind() sbs_bind.pkey = self.player.fb_id sbs_bind.sbs_user_id = self.sbs_uid sbs_bind.put() level = self.request.get_argument("cur_level", u"0") level_star = int(self.request.get_argument("level_star", u"0")) level_score = int(self.request.get_argument("level_score", u"0")) level_key = "%s_%s" % (self.uid, level) l = Level.get(level_key) if not l: l = Level() l.pkey = level_key l.stars = level_star l.score = level_score elif level_star > l.stars: l.stars = level_star elif level_score > l.score: l.score = level_score l.put() elif method == "del": self.player.delete() elif method == "finance": f = Finance.get(self.uid) if not f: f = Finance() f.pkey = self.uid f.source = self.request.get_argument("source", u"") f.total_gold = int(self.request.get_argument("total_gold", u"0")) f.total_free_gold = int( self.request.get_argument("total_free_gold", u"0")) f.total_pay_gold = int( self.request.get_argument("total_pay_gold", u"0")) f.total_ruby = int(self.request.get_argument("total_ruby", u"0")) f.total_free_ruby = int( self.request.get_argument("total_free_ruby", u"0")) f.total_pay_ruby = int( self.request.get_argument("total_pay_ruby", u"0")) f.gold = int(self.request.get_argument("gold", u"0")) f.free_gold = int(self.request.get_argument("free_gold", u"0")) f.pay_gold = int(self.request.get_argument("pay_gold", u"0")) old_ruby = f.ruby ruby_changed = False f.ruby = int(self.request.get_argument("ruby", u"0")) if old_ruby != f.ruby: ruby_changed = True f.free_ruby = int(self.request.get_argument("free_ruby", u"0")) f.pay_ruby = int(self.request.get_argument("pay_ruby", u"0")) delta_ruby = int(self.request.get_argument("delta_ruby", u"0")) delta_free_ruby = int( self.request.get_argument("delta_free_ruby", u"0")) f.put() if ruby_changed: r = Ruby.get(self.uid) if not r: r = Ruby() r.pkey = self.uid if len(r.list) > 500: r.list.pop() if ruby_changed: r.list.insert(0, [ f.source, f.ruby, f.pay_ruby, delta_ruby, delta_free_ruby, time.time() ]) r.put() elif method == "getbind": pid = self.request.get_argument("pid", u"") player = Player.get(pid) if player and player.fb_id: result["content"].append(player.fb_id) elif method == "getfbbind": pid = self.request.get_argument("pid", u"") sbs_bind = FBIdBind.get(pid) if sbs_bind and sbs_bind.sbs_user_id: result["content"].append(sbs_bind.sbs_user_id) result = {"status": 404, "content": []} elif method == "checkin": starttime = self.request.get_argument("start", "0000") endtime = self.request.get_argument("end", "9999") c = Checkin.get(self.uid) if not c: c = Checkin() c.pkey = self.uid now = (datetime.datetime.now() - datetime.timedelta(hours=3)).strftime("%Y%m%d") if c.data.get(now) == 1: result["status"] = 201 else: c.data[now] = 1 for key in c.data.keys(): if key < starttime or key > endtime: del c.data[key] c.put() l = len(c.data) if l in (1, 2, 3, 4, 5, 6, 7, 8): msgobj = Mail.get(self.uid) if not msgobj: msgobj = Mail() msgobj.pkey = self.uid msg = { "mid": shortuuid.uuid()[:8], "local_mid": "checkInActivity_%d" % (l), "opened": False, "time": int(time.time()), "type": "reward", "num": 1, "name": "", "fbname": "", "avatar": "", "sender": "gmuser" } msgobj.delete_old() msgobj.mail.insert(0, msg) msgobj.put() result["content"] = c.data.keys() # 签到事件2 elif method == "checkin_event": logging.info("checkin_event:%s" % self.uid) c = CheckinEvent.get(self.uid) if not c: c = CheckinEvent() c.pkey = self.uid now = (datetime.datetime.now() - datetime.timedelta(hours=3)).strftime("%Y%m%d") if c.data.get(now) == 1: result["status"] = 201 else: c.data[now] = 1 for key in c.data.keys(): if not key.startswith(now[:6]): del c.data[key] c.put() result["content"] = c.data.keys() elif method == "getservertime": result["content"] = int(time.time()) elif method == "checkinlist": starttime = self.request.get_argument("start", "0000") endtime = self.request.get_argument("end", "9999") c = Checkin.get(self.uid) if not c: c = Checkin() c.pkey = self.uid now = (datetime.datetime.now() - datetime.timedelta(hours=3)).strftime("%Y%m") for key in c.data.keys(): if key < starttime or key > endtime: del c.data[key] c.put() result["content"] = c.data.keys() raise gen.Return(result)