def run_in_transaction_custom_retries(retry, function, *args, **kwargs): MYSQL_WAIT_MAX = 3 count = retry start_time = OSAUtil.get_now() while True: try: return transaction_sub(function, *args, **kwargs) except AppError: # apperrorは意図的に出しているからスルー. raise except CabaretError: # apperrorは意図的に出しているからスルー. raise except TimeoutError: # db接続タイムアウト. raise except OperationalError: # mysqlの接続等のエラー. now = OSAUtil.get_now() dif = now - start_time if dif.seconds < MYSQL_WAIT_MAX: time.sleep(0.1) else: info = sys.exc_info() trace = CabaretError.makeErrorTraceString(info) raise CabaretError(trace, CabaretError.Code.TOO_MANY_TRANSACTION) except: if count <= 0: raise count -= 1 time.sleep(0.01)
def setUpEvent(self, eventmaster_kwargs=None, model_mgr=None, is_open=True, opening=True): # シナリオ. scenario = self.create_dummy(DummyType.EVENT_SCENARIO_MASTER) # イベントマスター. eventmaster_kwargs = eventmaster_kwargs or {} eventmaster_kwargs.update(op=scenario.number, ed=scenario.number) eventmaster = self.create_dummy(DummyType.BATTLE_EVENT_MASTER, **eventmaster_kwargs) self.__eventmaster = eventmaster # イベント発生中設定. model_mgr = model_mgr or ModelRequestMgr() if is_open: stime = OSAUtil.get_datetime_min() etime = OSAUtil.get_datetime_max() else: stime = OSAUtil.get_datetime_min() etime = stime config = BackendApi.get_current_battleeventconfig(model_mgr) self.__preconfig_mid = config.mid self.__preconfig_starttime = config.starttime self.__preconfig_endtime = config.endtime self.__preconfig_ependtime = config.epilogue_endtime BackendApi.update_battleeventconfig(eventmaster.id, stime, etime, OSAUtil.get_datetime_max()) return eventmaster
def process(self): v_player = self.getViewerPlayer() client = OSAUtil.get_cache_client() ctype = Defines.CharacterType.ALL rare = Defines.Rarity.ALL page = 0 if self.request.method == 'GET': namespacebase = 'albumlistargs:%s' ctype = client.get(v_player.id, namespace=namespacebase % 'ctype') or ctype rare = client.get(v_player.id, namespace=namespacebase % 'rare') or rare page = client.get(v_player.id, namespace=namespacebase % 'page') or page try: ctype = int(self.request.get(Defines.URLQUERY_CTYPE, ctype)) rare = int(self.request.get(Defines.URLQUERY_RARE, rare)) page = int(self.request.get(Defines.URLQUERY_PAGE, page)) except: ctype = Defines.CharacterType.ALL rare = Defines.Rarity.ALL page = 0 model_mgr = self.getModelMgr() # プレイヤー情報. v_player = self.getViewerPlayer() # アルバム情報取得. offset = page * Defines.ALBUM_PAGE_CONTENT_NUM limit = Defines.ALBUM_PAGE_CONTENT_NUM + 1 albumlist = BackendApi.get_album_list(self, v_player.id, ctype, rare, offset, limit, using=settings.DB_READONLY) has_nextpage = Defines.ALBUM_PAGE_CONTENT_NUM < len(albumlist) albumlist = albumlist[:Defines.ALBUM_PAGE_CONTENT_NUM] # アルバムリスト. self.html_param['album_list'] = albumlist self.html_param['cur_page'] = page + 1 self.html_param['page_max'] = self.getAlbumPageNumMax(model_mgr, ctype, rare) self.html_param['ctype'] = ctype self.html_param['rare'] = rare url_base = UrlMaker.album() self.html_param['url_post'] = self.makeAppLinkUrl(url_base) url_base = OSAUtil.addQuery(url_base, Defines.URLQUERY_CTYPE, ctype) url_base = OSAUtil.addQuery(url_base, Defines.URLQUERY_RARE, rare) if 0 < page: self.html_param['url_page_prev'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page-1)) if has_nextpage: self.html_param['url_page_next'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page+1)) namespacebase = 'albumlistargs:%s' client.set(v_player.id, ctype, namespace=namespacebase % 'ctype') client.set(v_player.id, rare, namespace=namespacebase % 'rare') client.set(v_player.id, page, namespace=namespacebase % 'page') self.writeAppHtml('album/album')
def procYesno(self, v_player, args): """申請確認. """ try: # 相手のID. fid = int(args.get(1)) except: raise CabaretError(u'引数が想定外です', CabaretError.Code.ILLEGAL_ARGS) playerlist = self.getObjPlayerList([fid]) if len(playerlist) == 0: raise CabaretError(u'存在しないプレイヤーです', CabaretError.Code.NOT_DATA) player = playerlist[0] url = UrlMaker.friendrequest_do() url = OSAUtil.addQuery(url, Defines.URLQUERY_USERID, fid) player['url_friendrequest_send'] = self.makeAppLinkUrl(url) self.html_param['player'] = player #フレンド検索URL. lvgrp = int(Defines.LevelGroup.LV01_09) url = OSAUtil.addQuery(UrlMaker.friendsearch(), Defines.URLQUERY_LEVELGROUP, lvgrp) self.html_param['url_search'] = self.makeAppLinkUrl(url) self.writeAppHtml('friend/sendyesno')
def handle(self, *args, **options): print '================================' print 'init_panelmission' print '================================' model_mgr = ModelRequestMgr() # メンテナンス確認. appconfig = BackendApi.get_appconfig(model_mgr) if not appconfig.is_maintenance(): print u'メンテナンスモードにしてください' return print 'check maintenance...OK' delete_target_model_cls_list = ( PlayerPanelMission, PanelMissionData, ) def tr(): for model_cls in delete_target_model_cls_list: tablename = model_cls.get_tablename() query_string = "truncate table `%s`;" % tablename Query.execute_update(query_string, [], False) print 'delete...%s' % tablename db_util.run_in_transaction(tr) # キャッシュを消す. OSAUtil.get_cache_client().flush() print '================================' print 'all done.'
def process(self): # 現在時刻. self.__now = OSAUtil.get_now() args = self.getUrlArgs('/cabaclubdeckselect/') # Retrieve the necessary arguments # mid : Cabaclubstore id # card_type : (全て、悪、知、癒) as defined in Defines.CharacterType.NAMES try: mid = args.getInt(0) card_type = int(self.request.get(Defines.URLQUERY_CTYPE, 0)) is_remove = self.request.get(Defines.URLQUERY_REM, '') == "rem" except: raise CabaretError(u'引数が想定外です', CabaretError.Code.ILLEGAL_ARGS) url = UrlMaker.cabaclubstore(mid=mid) # Automatically choose the casts and add them to the deck # for the Cabaclubstore of id `mid` if card_type: url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, card_type) # 一括編成 / 一括解除 self.processAuto(mid, card_type, is_remove=is_remove) if settings_sub.IS_BENCH: self.response.set_status(200) self.response.end() else: self.appRedirect(self.makeAppLinkUrlRedirect(url)) return
def __sendRequest(cls, api, args, query_params): host = "localhost:8080" # host = "ec2-46-51-225-216.ap-northeast-1.compute.amazonaws.com/nmh" url = cls.makeRequestUrl(api) print 'url:%s' % url method = "GET" data = None if args: method = "POST" for k, v in query_params.items(): args[k] = v # app_idはクエリに付加 url = OSAUtil.addQuery(url, OSAUtil.KEY_APP_ID, query_params[OSAUtil.KEY_APP_ID]) if args: data = '' for k, v in args.items(): data = OSAUtil.addQuery(data, k, v) data = data[1:] else: for k, v in query_params.items(): url = OSAUtil.addQuery(url, k, v) request_url = "http://" + host + url headers = {} req = urllib2.Request(request_url, data=data, headers=headers) req.get_method = lambda: method tmp = urllib2.urlopen(req) response = tmp.read() return response
def writeBoxHtml(self, name): """HTML書き出し. """ self.getViewerPlayer() _ctype = self.getCtypeOri() sortby = self.getSortby() page = self.getPage() self.html_param[Defines.URLQUERY_CTYPE] = _ctype self.html_param[Defines.URLQUERY_SORTBY] = sortby self.html_param[Defines.URLQUERY_PAGE] = page ctype_items = {'all': u'全て'} ctype_items.update(Defines.CharacterType.NAMES) self.html_param['ctype_items'] = ctype_items.items() self.html_param['sort_items'] = Defines.CardSortType.NAMES.items() # タブ切り替え用. url = UrlMaker.cardbox() url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, _ctype) url = OSAUtil.addQuery(url, Defines.URLQUERY_SORTBY, sortby) self.html_param['url_cardbox'] = self.makeAppLinkUrl(url) url = UrlMaker.sell() url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, _ctype) url = OSAUtil.addQuery(url, Defines.URLQUERY_SORTBY, sortby) self.html_param['url_sell'] = self.makeAppLinkUrl(url) self.saveSortParams() self.writeAppHtml(name)
def __proc_prizes(self, eventmaster, is_opened): """報酬. """ urlbase = UrlMaker.raidevent_explain(eventmaster.id, 'prizes') self.html_param['url_prizes_destroy'] = self.makeAppLinkUrl( OSAUtil.addQuery(urlbase, Defines.URLQUERY_CTYPE, 'destroy')) self.html_param['url_prizes_destroy_big'] = self.makeAppLinkUrl( OSAUtil.addQuery(urlbase, Defines.URLQUERY_CTYPE, 'destroy_big')) self.html_param['url_prizes_ranking'] = self.makeAppLinkUrl( OSAUtil.addQuery(urlbase, Defines.URLQUERY_CTYPE, 'ranking')) self.html_param['url_prizes_ranking_beginer'] = self.makeAppLinkUrl( OSAUtil.addQuery(urlbase, Defines.URLQUERY_CTYPE, 'ranking_beginer')) ctype = self.request.get(Defines.URLQUERY_CTYPE) self.html_param['current_prize'] = ctype if ctype == 'ranking': self.__proc_prizes_ranking(eventmaster, is_opened) elif ctype == 'destroy_big': self.__proc_prizes_destroy_big(eventmaster, is_opened) elif ctype == 'ranking_beginer': self.__proc_prizes_ranking_beginer(eventmaster, is_opened) else: self.html_param['current_prize'] = 'destroy' self.__proc_prizes_destroy(eventmaster, is_opened)
def procResult(self): """結果表示. """ presentidlist = self.__get_present_idlist(True) over = False try: over = bool(int(self.__args.get(1, 0))) except: pass model_mgr = self.getModelMgr() presentlist = BackendApi.get_presents(presentidlist, model_mgr, using=settings.DB_READONLY, received=True) self.html_param['presentreceivedlist'] = [Objects.present(self, presentset) for presentset in presentlist] self.html_param['overlimit'] = over url_reload = self.addIDQuesyParam(UrlMaker.presentresult(over), presentidlist) topic = self.request.get(Defines.URLQUERY_CTYPE) or "" topic = int(topic) if str(topic).isdigit() else Defines.PresentTopic.ALL url_reload = OSAUtil.addQuery(url_reload, Defines.URLQUERY_CTYPE, topic) client = OSAUtil.get_cache_client() v_player = self.getViewerPlayer() sort = client.get(v_player.id, namespace='present:sort') self.putPresentList(url_reload, topic, sort=sort, using=settings.DB_DEFAULT) if not self.response.isEnd: self.writeAppHtml('presentrecieve')
def create_loginbonus(self, maplist, is_open=True): """双六のログインボーナスを作成. """ map_id_list = [ map_id.id if isinstance(map_id, LoginBonusSugorokuMapMaster) else map_id for map_id in maplist ] loginbonusmaster = self.create_dummy( DummyType.LOGIN_BONUS_SUGOROKU_MASTER, map_id_list) if is_open: # ログインボーナスを設定. model_mgr = ModelRequestMgr() config = BackendApi.get_current_loginbonustimelimitedconfig( model_mgr) if self.__config_datalist is None: self.__config = config self.__config_datalist = config.datalist[:] config.datalist = [] config.setData(loginbonusmaster.id, OSAUtil.get_now(), OSAUtil.get_datetime_max(), sugoroku=True) config.save() model_mgr.save_models_to_cache([config]) return loginbonusmaster
def process(self): model_mgr = self.getModelMgr() v_player = self.getViewerPlayer() invitemaster = BackendApi.get_current_invitemaster( model_mgr, using=settings.DB_READONLY) if invitemaster is None: raise CabaretError(u'招待キャンペーンは開催していません', CabaretError.Code.ILLEGAL_ARGS) # 招待したフレンド. invite_member = self.request.get("invite_member") if invite_member: str_dmmidlist = str(invite_member).split(',') KpiOperator().set_increment_invite_count(len(str_dmmidlist), OSAUtil.get_now()).save() self.addlog(u'invite_member:%d:%s' % (len(str_dmmidlist), invite_member)) invite = BackendApi.get_invite(model_mgr, v_player.id, invitemaster.id, using=settings.DB_READONLY) self.html_param['invitecnt'] = invite.cnt url = OSAUtil.addQuery( 'invite:friends', 'callbackurl', self.makeAppLinkUrl(UrlMaker.invite(), add_frompage=False)) url = OSAUtil.addQuery(url, 'body', u'招待報酬をGET') self.html_param['url_dmm_invite'] = url self.writeAppHtml('invite/invite')
def process(self): model_mgr = self.getModelMgr() config = BackendApi.get_current_produce_event_config( model_mgr, using=settings.DB_READONLY) if config.mid == 0 or not config.is_open_epilogue(OSAUtil.get_now()): self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.mypage())) return produce_event_master = config.get_produce_event_master(model_mgr) if produce_event_master is None: self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.mypage())) return uid = self.getViewerPlayer().id if BackendApi.check_produceevent_lead_epilogue( model_mgr, uid, produce_event_master.id): flagrecord = BackendApi.update_produceevenflagrecord( produce_event_master.id, uid, epvtime=OSAUtil.get_now()) model_mgr.set_got_models([flagrecord]) url = UrlMaker.produceevent_top(produce_event_master.id) if produce_event_master.ed: # 演出のパラメータ. effectpath = UrlMaker.event_scenario() dataUrl = self.makeAppLinkUrlEffectParamGet( 'eventscenario/%d/last%s' % (produce_event_master.ed, url)) self.appRedirectToEffect2(effectpath, dataUrl) else: # 演出なし. self.appRedirect(self.makeAppLinkUrlRedirect(url))
def procList(self, args, raidid): page = 0 try: page = int(self.request.get(Defines.URLQUERY_PAGE) or 0) except: pass contentnum = Defines.RAIDFRIEND_LIST_CONTENT_NUM_PER_PAGE offset = contentnum * page limit = contentnum + 1 cardsetlist = self.getFriendLeaderCardList(limit, offset) has_next_page = contentnum < len(cardsetlist) cardsetlist = cardsetlist[:contentnum] if cardsetlist: cb = self.putPlayerListByLeaderList(raidid, cardsetlist) if cb: self.execute_api() cb() url_base = UrlMaker.raidfriendselect(raidid) if 0 < page: url = OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page - 1) self.html_param['url_page_prev'] = self.makeAppLinkUrl(url) if has_next_page: url = OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page + 1) self.html_param['url_page_next'] = self.makeAppLinkUrl(url) self.html_param['cur_page'] = page + 1 self.html_param['page_max'] = int( (self.getFriendLeaderCardNum() + contentnum - 1) / contentnum) self.writeAppHtml('raid/friendselect')
def setUp(self): model_mgr = ModelRequestMgr() # Player. self.__player0 = self.create_dummy(DummyType.PLAYER) # イベントマスター. scenario = self.create_dummy(DummyType.EVENT_SCENARIO_MASTER) eventmaster = self.create_dummy(DummyType.SCOUT_EVENT_MASTER, op=scenario.number, ed=scenario.number) self.__eventmaster = eventmaster # イベント設定. config = BackendApi.get_current_scouteventconfig(model_mgr) self.__preconfig_mid = config.mid self.__preconfig_starttime = config.starttime self.__preconfig_endtime = config.endtime self.__preconfig_epetime = config.epilogue_endtime now = OSAUtil.get_now() td = datetime.timedelta(days=1) BackendApi.update_scouteventconfig(self.__eventmaster.id, now-td, now-td, now+td) # OPを閲覧済みに. now = OSAUtil.get_now() flagrecord = self.create_dummy(DummyType.SCOUT_EVENT_FLAGS, self.__player0.id, self.__eventmaster.id, now) self.__flagrecord = flagrecord
def process(self): args = self.getUrlArgs('/lbsugorokuanim/') mid = args.getInt(0) page = int(self.request.get(Defines.URLQUERY_PAGE) or 0) loginbonus = args.getInt(1) model_mgr = self.getModelMgr() now = OSAUtil.get_now() # プレイヤー情報. v_player = self.getViewerPlayer() viewer_id = v_player.id if BackendApi.check_lead_loginbonus_sugoroku(model_mgr, viewer_id, now): # まだ受け取っていない. if settings_sub.IS_LOCAL: raise CabaretError(u'まだ受け取っていない') url = self.makeAppLinkUrlRedirect(UrlMaker.loginbonussugorokudo()) self.appRedirect(url) return logindata = BackendApi.get_loginbonus_sugoroku_playerdata( model_mgr, viewer_id, mid, using=settings.DB_DEFAULT) if logindata is None: url = self.makeAppLinkUrlRedirect(UrlMaker.mypage()) self.appRedirect(url) return squares_id_list = logindata.result.get('square_id_list') squares_master_list = BackendApi.get_loginbonus_sugoroku_map_squares_master_list_by_id( model_mgr, squares_id_list, using=settings.DB_READONLY) squares_master_list.sort(key=lambda x: squares_id_list.index(x.id)) mapidlist = [] mapid = None for squares_master in squares_master_list: if mapid is None or mapid != squares_master.mid: mapid = squares_master.mid mapidlist.append(mapid) page_max = len(mapidlist) mapmaster = BackendApi.get_loginbonus_sugoroku_map_master( model_mgr, mapidlist[page], using=settings.DB_READONLY) # 飛び先のURL. if page_max < 2 or page_max <= (page + 1): url = self.makeNextEffectUrl(loginbonus, timelimited=True, comeback=False, sugoroku=mid) url = self.makeAppLinkUrl(url) else: url = UrlMaker.loginbonussugorokuanim(mid, loginbonus) url = OSAUtil.addQuery(url, Defines.URLQUERY_PAGE, page + 1) url = self.makeAppLinkUrl(url) dataUrl = self.makeAppLinkUrlEffectParamGet('sugoroku/{}/{}'.format( mid, page)) self.appRedirectToEffect2('{}/effect2.html'.format( mapmaster.effectname), dataUrl, dataBody=urllib.urlencode(dict(backUrl=url)))
def setUp(self): model_mgr = ModelRequestMgr() now = OSAUtil.get_now() # Player. self.__player0 = self.create_dummy(DummyType.PLAYER) # アイテム. itemmaster = self.create_dummy(DummyType.ITEM_MASTER) data = ScoutDropItemData.create( Defines.ItemType.ITEM, itemmaster.id, filters={'ptype': Defines.CharacterType.TYPE_001}, rate=10000) items = [data.get_dropitem_dict()] # 報酬. prize = self.create_dummy(DummyType.PRIZE_MASTER, gold=100, gachapt=10, item=itemmaster) # レイドマスター. raidmaster = self.create_dummy(DummyType.RAID_MASTER, hp=1, prizes=[prize.id], helpprizes=[prize.id], cabaretking=100, demiworld=10) self.__raidmaster = raidmaster # ハプニング. happeningmaster = self.create_dummy(DummyType.HAPPENING_MASTER, raidmaster.id, items=items) self.__happeningmaster = happeningmaster # レイドイベント. data = ScoutHappeningData.create(happeningmaster.id, 10000) happenings = [data.get_dict()] eventmaster = self.create_dummy(DummyType.RAID_EVENT_MASTER, raidtable=happenings) self.__eventmaster = eventmaster # イベント発生中設定. config = BackendApi.get_current_raideventconfig(model_mgr) self.__preconfig_mid = config.mid self.__preconfig_starttime = config.starttime self.__preconfig_endtime = config.endtime self.__preconfig_timebonus = config.timebonus_time timebonus_time = [{ 'stime': now, 'etime': now + datetime.timedelta(days=1), }] now = OSAUtil.get_now() BackendApi.update_raideventconfig(self.__eventmaster.id, now, now + datetime.timedelta(days=1), timebonus_time=timebonus_time)
def makeCardObject(self, cardset, deck): data = Objects.card(self, cardset, deck=deck) url = UrlMaker.deckset(target=self.__target) url = OSAUtil.addQuery(url, Defines.URLQUERY_INDEX, self.__selected_index) url = OSAUtil.addQuery(url, Defines.URLQUERY_CARD, cardset.id) data['url_deck'] = self.makeAppLinkUrl(url) return data
def addFilterQuery(self, url): filters = self.request.get("filters") version = self.request.get("version") if filters: url = OSAUtil.addQuery(url, "filters", urllib2.quote(filters, "")) if version: url = OSAUtil.addQuery(url, "version", urllib2.quote(version, "")) return url
def process(self): args = self.getUrlArgs('/promotiontop/') appname = args.get(0) is_recipient = bool(int(self.request.get(Defines.URLQUERY_FLAG, '0'))) self.html_param['is_recipient'] = is_recipient model_mgr = self.getModelMgr() v_player = self.getViewerPlayer() if PlayerCrossPromotion.is_session(): self.html_param['is_pc'] = self.is_pc if self.is_pc: # self.html_param['url_goh'] = 'http://rcv.ixd.dmm.com/api/surl?urid=NmcO0Hxz' # self.html_param['url_harepai'] = 'http://rcv.ixd.dmm.com/api/surl?urid=XzIUBerr' # self.html_param['url_sengoku'] = 'http://www.dmm.co.jp/netgame/feature/sengokuaibu.html' self.html_param['url_avst'] = 'http://www.dmm.co.jp/netgame/social/-/gadgets/=/app_id=445699/' self.html_param['url_noahs_gate'] = 'http://www.dmm.co.jp/netgame/social/-/gadgets/=/app_id=223705/' else: # self.html_param['url_goh'] = 'http://rcv.ixd.dmm.com/api/surl?urid=t6vJmS4X' # self.html_param['url_harepai'] = 'http://rcv.ixd.dmm.com/api/surl?urid=j9mnDsZP' # self.html_param['url_sengoku'] = 'http://www.dmm.co.jp/netgame/feature/sengokuaibu.html' self.html_param['url_avst'] = 'http://www.dmm.co.jp/netgame_s/avstrikers/' self.html_param['url_noahs_gate'] = 'http://sp.dmm.co.jp/netgame/gadgets/index/app_id/223705/' url_base = UrlMaker.promotion_top(appname) if is_recipient: self.html_param['url_cabaret'] = self.makeAppLinkUrl(url_base) else: self.html_param['url_recipient'] = self.makeAppLinkUrl( OSAUtil.addQuery(url_base, Defines.URLQUERY_FLAG, '1')) # set display information for start time and end time of cross promotion start_date = '{d.month}/{d.day} {d.hour}:{d.minute:02}'.format(d=Defines.CROSS_PROMO_START_TIME) end_date = '{d.month}/{d.day} {d.hour}:{d.minute:02}'.format(d=Defines.CROSS_PROMO_END_TIME) self.html_param['cross_promo_time_limit'] = start_date + '〜' + end_date self.html_param['url_treasurelist'] = self.makeAppLinkUrl(UrlMaker.treasurelist()) self.html_param['url_cabaclubtop'] = self.makeAppLinkUrl(UrlMaker.cabaclubtop()) self.html_param['url_trade'] = self.makeAppLinkUrl(UrlMaker.trade()) self.html_param['url_scout'] = self.makeAppLinkUrl(UrlMaker.scout()) self.html_param['url_battle'] = self.makeAppLinkUrl(UrlMaker.battle()) self.html_param['url_gacha'] = self.makeAppLinkUrl( OSAUtil.addQuery( UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[Defines.GachaConsumeType.STEPUP2] ) ) player_cross_promotion = model_mgr.get_model(PlayerCrossPromotion, v_player.id) if player_cross_promotion: self.html_param['total_login_count'] = player_cross_promotion.total_login_count else: self.html_param['total_login_count'] = 0 self.writeAppHtml('promotion/{0}/top'.format(appname)) return else: # 開催期間外ならTopに飛ばす self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.mypage())) return
def reload(self): """マスターデータをリロード. """ now_diff = OSAUtil.get_now_diff() MasterData.incrementEditCacheVersion() rediscache.flush_all() OSAUtil.get_cache_client().flush() if settings_sub.IS_DEV: OSAUtil.set_now_diff(now_diff)
def procCard(self, filter_json, page): """カード画像確認. """ PAGE_CONTENT_NUM = 50 offset = page * PAGE_CONTENT_NUM nummax = CardMasterView.count(filters=filter_json, using=settings.DB_READONLY) pagemax = int((nummax + PAGE_CONTENT_NUM - 1) / PAGE_CONTENT_NUM) titles = ( u'ID', u'キャスト', u'thumbの値', u'Card_thumb_52_52.png', u'Card_thumb_60_75.png', u'Card_thumb_110_138.png', u'Card_thumb_320_400.png', u'Card_thumb_320_314.png', u'Card_thumb_70_88.png', ) cardmasterlist = CardMasterView.fetchValues(filters=filter_json, order_by='id', limit=PAGE_CONTENT_NUM, offset=offset, using=settings.DB_READONLY) datalist = [] for cardmaster in cardmasterlist: row = [ cardmaster.id, cardmaster.name, cardmaster.thumb, (self.makeAppImgUrl(CardUtil.makeThumbnailUrlIcon(cardmaster)), 52, 52), (self.makeAppImgUrl( CardUtil.makeThumbnailUrlSmall(cardmaster)), 60, 75), (self.makeAppImgUrl( CardUtil.makeThumbnailUrlMiddle(cardmaster)), 110, 138), (self.makeAppImgUrl( CardUtil.makeThumbnailUrlLarge(cardmaster)), 320, 400), (self.makeAppImgUrl( CardUtil.makeThumbnailUrlBustup(cardmaster)), 320, 314), ] if cardmaster.rare in Defines.Rarity.EVOLUTION_ABLES: row.append((self.makeAppImgUrl( CardUtil.makeThumbnailUrlMemory(cardmaster)), 70, 88)) else: row.append('') datalist.append(row) self.putData(titles, datalist) url = OSAUtil.addQuery(UrlMaker.view_images(), '_target', 'Card') url = OSAUtil.addQuery(url, '_filter', urllib.quote(self.html_param['_filter'], '')) self.putPagenationData(url, page, pagemax)
def _getJumpUrlPlayGacha(self, missionmaster): consumetype = missionmaster.condition_value1 url = UrlMaker.gacha() url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, Defines.GachaConsumeType.TO_TOPIC[consumetype]) url = OSAUtil.addQuery( url, Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[consumetype]) return url
def requestPromotionConditionGet(handler, appname, ridlist=None, do_execute=True): """プロモーション達成条件を問い合わせる. """ now = OSAUtil.get_now() namespace = 'PromotionCondition:%s' % appname sandbox = handler.appparam.sandbox not_found_ids = None cached_data = {} client = localcache.Client() if ridlist: cache_keys = [str(rid) for rid in ridlist] tmp = client.get_many(cache_keys, namespace=namespace) for k, v in tmp.items(): if v['date'] < now: continue cached_data[k] = v['data'] not_found_ids = list(set(cache_keys) - set(cached_data.keys())) if not not_found_ids: return cached_data if not_found_ids: conditionId = ','.join(not_found_ids) else: conditionId = 'all' endpoint_urlparams = dict(conditionId=conditionId) requet = PromotionUtil.__makePromotionApiRequest( handler, appname, 'conditionget', endpoint_urlparams, sandbox, None) reqkey = 'requestPromotionConditionGet:%s' % OSAUtil.makeSessionID() response = cached_data def cb(ret_data, reqkey, response, client, cache_limitdate): json_obj = ret_data[reqkey].get() for k, v in json_obj.items(): client.set(k, dict(data=v, date=cache_limitdate), namespace=namespace) response.update(json_obj) handler.addAppApiRequest(reqkey, requet, cb, reqkey, response, client, now + datetime.timedelta(seconds=3600 * 6)) if do_execute: handler.execute_api() return response
def setUp(self): model_mgr = ModelRequestMgr() # Player. self.__player0 = self.create_dummy(DummyType.PLAYER) # 報酬. prize = self.create_dummy(DummyType.PRIZE_MASTER, gold=100, gachapt=10) # イベントマスター. pointprizes = [ [1, [prize.id]], ] eventmaster = self.create_dummy(DummyType.SCOUT_EVENT_MASTER, pointprizes=pointprizes) self.__eventmaster = eventmaster # ステージマスター. stagemaster = self.create_dummy(DummyType.SCOUT_EVENT_STAGE_MASTER, eventid=eventmaster.id, stage=1) self.__stagemaster = stagemaster # OPを閲覧済みに. flagrecord = self.create_dummy(DummyType.SCOUT_EVENT_FLAGS, self.__player0.id, self.__eventmaster.id, OSAUtil.get_now()) self.__flagrecord = flagrecord # 項目作成. for number in xrange(3): self.create_dummy(DummyType.SCOUT_EVENT_PRESENT_PRIZE_MASTER, self.__eventmaster.id, number, pointprizes) # ハート数. self.create_dummy(DummyType.SCOUT_EVENT_PRESENT_NUM, self.__player0.id, self.__eventmaster.id, point=100, result_number=0, result_pointpre=0, result_pointpost=1) # イベント発生中設定. config = BackendApi.get_current_scouteventconfig(model_mgr) self.__preconfig_mid = config.mid self.__preconfig_starttime = config.starttime self.__preconfig_endtime = config.endtime self.__preconfig_present_endtime = config.present_endtime now = OSAUtil.get_now() BackendApi.update_scouteventconfig(self.__eventmaster.id, now, now + datetime.timedelta(days=1), present_endtime=now + datetime.timedelta(days=1))
def procGacha(self, uid, is_complete, stime, etime): """ガチャの課金情報. """ paymentlist = BackendApi.get_gachapaymententry_list(uid, is_complete, using=backup_db) if stime or etime: stime = stime or OSAUtil.get_datetime_min() etime = etime or OSAUtil.get_datetime_min() paymentlist = [payment for payment in paymentlist if stime <= payment.ctime < etime] obj_paymentlist = self.makePaymentObjList(paymentlist, GachaMaster) return obj_paymentlist
def process(self): args = self.getUrlArgs('/lbtlanim/') mid = args.getInt(0) loginbonus = args.getInt(1) model_mgr = self.getModelMgr() now = OSAUtil.get_now() # プレイヤー情報. v_player = self.getViewerPlayer() if BackendApi.check_lead_loginbonustimelimited(model_mgr, v_player.id, now): # まだ受け取っていない. if settings_sub.IS_LOCAL: raise CabaretError(u'まだ受け取っていない') url = self.makeAppLinkUrlRedirect( UrlMaker.loginbonustimelimiteddo()) self.appRedirect(url) return logindata = BackendApi.get_logintimelimited_data( model_mgr, v_player.id, mid, using=settings.DB_READONLY) if logindata is None: url = self.makeAppLinkUrlRedirect(UrlMaker.mypage()) self.appRedirect(url) return cur_day = logindata.days master = BackendApi.get_loginbonustimelimitedmaster( model_mgr, mid, using=settings.DB_READONLY) if master is None: url = self.makeAppLinkUrlRedirect(UrlMaker.mypage()) self.appRedirect(url) return #取得したアイテム(名前,日数). cur_bonusmaster = BackendApi.get_loginbonustimelimiteddaysmaster( model_mgr, master.id, cur_day, using=settings.DB_READONLY) if not cur_bonusmaster: # 演出いらない. url = self.makeAppLinkUrlRedirect(UrlMaker.mypage()) self.appRedirect(url) return str_midlist = self.request.get(Defines.URLQUERY_ID) or '' dataUrl = self.makeAppLinkUrlEffectParamGet( 'loginbonustimelimited/%s/%s' % (mid, loginbonus)) if str_midlist: dataUrl = OSAUtil.addQuery(dataUrl, Defines.URLQUERY_ID, str_midlist) self.appRedirectToEffect2('%s/effect2.html' % master.effectname, dataUrl)
def handle(self, *args, **options): starttime = OSAUtil.get_now() print '================================' print 'check_present_timeout' print '================================' now = OSAUtil.get_now() - datetime.timedelta(seconds=60) # 1分間猶予をもたせる. presentlist = list( Present.all(using=backup_db).filter(limittime__lt=now).values( 'id', 'toid', 'itype').fetch(100000)) print 'delete target num:%d' % len(presentlist) if len(presentlist) == 0: # 削除対象がない. print '---------------' print 'end...' return print 'delete...start' # redisから削除. redisdb = RedisModel.getDB() pipe = redisdb.pipeline() LIMIT = 500 presentidlist = [] for data in presentlist: BackendApi.remove_present(data['toid'], data['id'], data['itype'], pipe) presentidlist.append(data['id']) if LIMIT <= len(presentidlist): print 'delete...redis' pipe.execute() pipe = redisdb.pipeline() print 'delete...mysql' Present.all().filter(id__in=presentidlist).delete() presentidlist = [] print 'delete...restart' if presentidlist: print 'delete...redis' pipe.execute() print 'delete...mysql' Present.all().filter(id__in=presentidlist).delete() print 'delete...end' print '---------------' print 'all done.' diff = OSAUtil.get_now() - starttime sec = diff.days * 86400 + diff.seconds print 'time %d.%06d' % (sec, diff.microseconds)
def process(self): now = OSAUtil.get_now() model_mgr = self.getModelMgr() config = BackendApi.get_current_battleeventconfig(model_mgr, using=settings.DB_READONLY) cur_eventmaster = None if config.mid and config.starttime <= now < config.epilogue_endtime: cur_eventmaster = BackendApi.get_battleevent_master(model_mgr, config.mid, using=settings.DB_READONLY) if cur_eventmaster is None: self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.mypage())) return elif config.starttime <= now < config.endtime: self.checkBattleEventUser(do_check_battle_open=False, do_check_regist=False) if self.response.isEnd: return v_player = self.getViewerPlayer() uid = v_player.id # 現在の贈り物情報を確認. presentdata = BackendApi.get_battleeventpresent_pointdata(model_mgr, uid, cur_eventmaster.id, using=settings.DB_DEFAULT) pre_data = presentdata.getPreData() if pre_data is None: # 受け取り情報がない. self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.mypage())) return # 達成を一応確認. cur_data = presentdata.getData() presentmaster = BackendApi.get_battleeventpresent_master(model_mgr, cur_eventmaster.id, cur_data['number'], using=settings.DB_READONLY) if presentmaster.point <= presentdata.point: # 達成済みで受け取っていない. playerrequest = BackendApi.get_playerrequest(model_mgr, uid) url = UrlMaker.battleevent_presentreceive(playerrequest.req_confirmkey) self.appRedirect(self.makeAppLinkUrlRedirect(url)) return presentmaster = BackendApi.get_battleeventpresent_master(model_mgr, cur_eventmaster.id, pre_data['number'], using=settings.DB_READONLY) # 演出後のページ. url = OSAUtil.addQuery(UrlMaker.battleevent_present(), Defines.URLQUERY_FLAG, 1) params = { 'backUrl' : self.makeAppLinkUrl(url), 'logoPre' : self.url_static_img + 'event/btevent/%s/' % cur_eventmaster.codename, 'pre' : self.url_static_img, 'item' : presentmaster.thumb, } # 演出へリダイレクト. self.appRedirectToEffect('btevent/event_extra_alcohol/effect.html', params)
def putRanking(self, uid, eventid, view_myrank, url_battleevent_ranking, url_battleevent_myrank, view_beginer=False): model_mgr = self.getModelMgr() page = int(self.request.get(Defines.URLQUERY_PAGE) or 0) if view_myrank: score = BackendApi.get_battleevent_score(eventid, uid) if score: # 自分のランクのページヘ. index = BackendApi.get_battleevent_rankindex(eventid, uid, is_beginer=view_beginer) offset = max(0, index - int((self.CONTENT_NUM_MAX_PER_PAGE+1) / 2)) uidscoresetlist = BackendApi.fetch_uid_by_battleeventrank(eventid, self.CONTENT_NUM_MAX_PER_PAGE, offset, withrank=True, is_beginer=view_beginer) else: uidscoresetlist = [] else: uidscoresetlist = self.getUidScoreSetList(eventid, page, is_beginer=view_beginer) obj_playerlist = [] if uidscoresetlist: uidscoreset = dict(uidscoresetlist) playerlist = BackendApi.get_players(self, uidscoreset.keys(), [PlayerExp], using=settings.DB_READONLY) persons = BackendApi.get_dmmplayers(self, playerlist, using=settings.DB_READONLY, do_execute=False) leaders = BackendApi.get_leaders(uidscoreset.keys(), arg_model_mgr=model_mgr, using=settings.DB_READONLY) self.execute_api() for player in playerlist: obj_player = Objects.player(self, player, persons.get(player.dmmid), leaders.get(player.id)) score, rank = uidscoreset[player.id] obj_player['event_score'] = score obj_player['event_rank'] = rank obj_player['is_me'] = uid == player.id obj_playerlist.append(obj_player) obj_playerlist.sort(key=lambda x:x['event_score'], reverse=True) self.html_param['ranking_playerlist'] = obj_playerlist contentnum = BackendApi.get_battleevent_rankernum(eventid, is_beginer=view_beginer) self.html_param['is_view_myrank'] = view_myrank self.html_param['is_view_beginer'] = view_beginer self.html_param['url_battleevent_ranking'] = self.makeAppLinkUrl(url_battleevent_ranking) + "#ranking" self.html_param['url_battleevent_myrank'] = self.makeAppLinkUrl(url_battleevent_myrank) + "#ranking" self.html_param['url_battleevent_ranking_beginer'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_battleevent_ranking, Defines.URLQUERY_BEGINER, 1)) + "#ranking" self.html_param['url_battleevent_myrank_beginer'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_battleevent_myrank, Defines.URLQUERY_BEGINER, 1)) + "#ranking" url_base = OSAUtil.addQuery(url_battleevent_myrank if view_myrank else url_battleevent_ranking, Defines.URLQUERY_BEGINER, int(view_beginer)) if not view_myrank: self.putPagenation(url_base, page, contentnum, self.CONTENT_NUM_MAX_PER_PAGE, "ranking")