def send_notify(self): self.send_basic_notify() self.send_formation_notify() cg = ChampionshipGroup(self.server_id) cg.find_by_char_id(self.char_id) group_msg = cg.make_protomsg() MessagePipe(self.char_id).put(msg=group_msg) cl = ChampionshipLevel(self.server_id) level_msg = cl.make_protomsg() MessagePipe(self.char_id).put(msg=level_msg)
def _add(self, tp, args): doc = MongoNotification.db(self.server_id).find_one( {'_id': self.char_id}, {'notis': 1}) notis = [(k, v['tp'], v['args'], v['timestamp']) for k, v in doc['notis'].iteritems()] notis.sort(key=lambda item: item[3]) remove_ids = [] while len(notis) > NOTIFICATION_MAX_AMOUNT - 1: x = notis.pop(0) remove_ids.append(x[0]) noti_id = make_string_id() data = MongoNotification.document_notification() data['tp'] = tp data['args'] = args data['timestamp'] = arrow.utcnow().timestamp data['opened'] = False updater = {'$set': {'notis.{0}'.format(noti_id): data}} if remove_ids: updater['$unset'] = {'notis.{0}'.format(i): 1 for i in remove_ids} notify = NotificationRemoveNotify() notify.ids.extend(remove_ids) MessagePipe(self.char_id).put(msg=notify) MongoNotification.db(self.server_id).update_one({'_id': self.char_id}, updater) self.send_notify([noti_id]) return noti_id
def send_notify(self): notify = ChatNotify() notify.act = ACT_INIT values = [] value1 = CommonPublicChat(self.server_id).get() if value1: values.append(value1) union = Union(self.server_id, self.char_id) union_id = union.get_joined_union_id() if union_id: value2 = CommonUnionChat(self.server_id, union_id).get() if value2: values.append(value2) for value in values: for v in value: msg = ChatMessage() try: msg.MergeFromString(base64.b64decode(v)) except: continue notify_msg = notify.msgs.add() notify_msg.MergeFrom(msg) MessagePipe(self.char_id).put(msg=notify)
def broadcast(self, data): char_ids = OperationLog.get_recent_action_char_ids(self.server_id, recent_minutes=5) if self.char_id not in char_ids: char_ids.append(self.char_id) for _id in char_ids: MessagePipe(_id).put(data=data)
def send_notify(self, ids=None): if ids: act = ACT_UPDATE else: ids = ConfigInspire.INSTANCES.keys() act = ACT_INIT notify = InspireNotify() notify.act = act for i in ids: notify_slot = notify.slots.add() notify_slot.id = i staff_id = self.doc['slots'].get(str(i), None) if staff_id is None: notify_slot.status = INSPIRE_SLOT_LOCK else: if staff_id: notify_slot.status = INSPIRE_SLOT_USING notify_slot.staff_id = staff_id else: notify_slot.status = INSPIRE_SLOT_EMPTY MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): doc = MongoArena.db(self.server_id).find_one( {'_id': str(self.char_id)}) ti = TimesInfo(self.server_id, self.char_id) notify = ArenaNotify() notify.my_rank = self.get_current_rank() notify.remained_match_times = ti.remained_match_times notify.refresh_cd = self.get_refresh_cd() notify.remained_refresh_times = ti.remained_reset_times notify.refresh_cost = ti.reset_cost notify.remained_buy_times = ti.remained_buy_times notify.buy_cost = ti.buy_cost notify.point = doc['point'] notify.max_rank = self.get_max_rank() notify.my_score = ArenaScore(self.server_id, self.char_id).score if doc['rival']: rival_club = ArenaClub(self.server_id, doc['rival']) notify.rival.id = str(rival_club.id) notify.rival.name = rival_club.name notify.rival.club_flag = rival_club.flag notify.rival.level = rival_club.level notify.rival.power = rival_club.power notify.rival.rank = Arena(self.server_id, doc['rival']).get_current_rank() notify.rival.score = ArenaScore(self.server_id, doc['rival']).score MessagePipe(self.char_id).put(msg=notify)
def totally_reset(server_id, send_notify=False): MongoChampionship.db(server_id).update_many( {}, {'$set': { 'applied': False, 'bet': {}, 'has_bet': False, }}) MongoChampionshipGroup.db(server_id).drop() MongoChampionshipLevel.db(server_id).drop() if send_notify: basic_notify = make_common_basic_notify_msg(server_id) basic_data = MessageFactory.pack(basic_notify) group_notify = make_empty_group_notify_msg() group_data = MessageFactory.pack(group_notify) level_notify = ChampionshipLevel(server_id).make_protomsg() level_data = MessageFactory.pack(level_notify) char_ids = OperationLog.get_recent_action_char_ids(server_id) for cid in char_ids: mp = MessagePipe(cid) mp.put(data=basic_data) mp.put(data=group_data) mp.put(data=level_data)
def send_notify(self, ids=None): if arrow.utcnow().timestamp >= self.reward_end_at: return if ids: act = ACT_UPDATE else: act = ACT_INIT ids = ConfigActivityNewPlayer.INSTANCES.keys() notify = ActivityNewPlayerNotify() notify.act = act for i in ids: # 后面天数的情况不发 if ConfigActivityNewPlayer.get(i).day > self.create_day: continue value, status = self.get_activity_status(i) notify_items = notify.items.add() notify_items.id = i notify_items.current_value = value notify_items.status = status notify.activity_end_at = self.activity_end_at notify.reward_end_at = self.reward_end_at MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, ids=None): if ids is None: projection = {'staffs': 1, 'exp_pool': 1} act = ACT_INIT else: if not ids: projection = {'staffs': 0} else: projection = {'staffs.{0}'.format(i): 1 for i in ids} projection['exp_pool'] = 1 act = ACT_UPDATE doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, projection) staffs = doc.get('staffs', {}) notify = StaffNotify() notify.act = act notify.exp_pool = doc.get('exp_pool', 0) for k, _ in staffs.iteritems(): notify_staff = notify.staffs.add() staff = self.get_staff_object(k) notify_staff.MergeFrom(staff.make_protomsg()) MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): notify = UnitNotify() notify.act = ACT_UPDATE notify_unit = notify.units.add() notify_unit.MergeFrom(self.make_protomsg()) MessagePipe(self.char_id).put(msg=notify)
def __call__(self, request): if not request.path.startswith('/game/'): return self.get_response(request) request._game_error_id = 0 response = self.get_response(request) if response.status_code != 200: return response if request._operation_log: request._operation_log.record(request.path, request._game_error_id) request._operation_log = None char_id = request._game_session.char_id if char_id: all_msgs = MessagePipe(char_id).get() else: all_msgs = [] all_msgs.insert(0, response.content) # FOR DEBUG # _msg_names = [] # for _msg in all_msgs: # _msg_id = NUM_FILED.unpack(_msg[4:8])[0] # _msg_names.append(ID_TO_MESSAGE[_msg_id]) # # print _msg_names # END DEBUG return HttpResponse(''.join(all_msgs), content_type='text/plain')
def send_result_notify(self): notify = PlunderResultNotify() if self.doc['matching']['id']: notify.id = str(self.doc['matching']['id']) notify.result.extend(self.doc['matching']['result']) MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): notify = VIPNotify() notify.vip = self.doc['vip'] notify.exp = self.doc['exp'] notify.rewarded.extend(self.doc['rewards']) MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, ids=None): notify = FriendNotify() if ids: projection = {"friends.{0}".format(_id): 1 for _id in ids} act = ACT_UPDATE else: projection = {"friends": 1} act = ACT_INIT notify.act = act notify.max_amount = MAX_FRIEND_AMOUNT doc = MongoFriend.db(self.server_id).find_one({'_id': self.char_id}, projection) friend_ids = [int(i) for i in doc['friends'].keys()] online_char_ids = OperationLog.get_recent_action_char_ids( self.server_id) for f in friend_ids: notify_friend = notify.friends.add() notify_friend.status = FRIEND_STATUS_TABLE[doc['friends'][str(f)]] friend_club = Club(self.server_id, f) notify_friend.club.MergeFrom(friend_club.make_protomsg()) notify_friend.online = f in online_char_ids MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): notify = TalentNotify() notify.points = self.remained_points() notify.reset_cost = RESET_TALENT_TREE_COST notify.talent_id.extend(self.doc['talents']) MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, tp=None): if tp: act = ACT_UPDATE tps = [tp] else: act = ACT_INIT tps = ConfigStoreType.INSTANCES.keys() notify = StoreNotify() notify.act = act for _t in tps: ri = RefreshInfo(self.server_id, self.char_id, _t) notify_type = notify.store_types.add() notify_type.tp = _t notify_type.auto_refresh_at = self.next_auto_refresh_timestamp(_t) notify_type.remained_refresh_times = ri.remained_refresh_times notify_type.refresh_cost = ri.refresh_cost for _g in self.doc['tp'][str(_t)]['goods'].keys(): _g_data = self.doc['tp'][str(_t)]['goods'][str(_g)] notify_type_goods = notify_type.goods.add() notify_type_goods.id = int(_g) notify_type_goods.content_index = _g_data['index'] notify_type_goods.remained_times = ConfigStore.get( int(_g)).times_limit - _g_data['times'] MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, task_ids=None): # 日常任务的的时间范围肯定就是当天了 start_time = get_start_time_of_today() end_time = start_time.replace(days=1) start_at = start_time.timestamp end_at = end_time.timestamp if task_ids: act = ACT_UPDATE else: act = ACT_INIT task_ids = self.doc['tasks'] notify = TaskDailyNotify() notify.act = act for tid in task_ids: current_value, status = self.get_task_status(tid, start_at=start_at, end_at=end_at) notify_task = notify.tasks.add() notify_task.id = tid notify_task.value = current_value notify_task.status = status MessagePipe(self.char_id).put(msg=notify)
def send_my_applied_notify(self): docs = MongoUnion.db(self.server_id).find({'apply_list': self.char_id}, {'_id': 1}) ids = [d['_id'] for d in docs] notify = UnionMyAppliedNotify() notify.union_ids.extend(ids) MessagePipe(self.char_id).put(msg=notify)
def set_to_common(self, msg): data = msg.SerializeToString() value = base64.b64encode(data) self.COMMON(self.server_id).set(value) for _cid in OperationLog.get_recent_action_char_ids(self.server_id, recent_minutes=5): MessagePipe(_cid).put(data=data)
def send_formation_notify(self): notify = PlunderFormationNotify() for i in [1, 2, 3]: notify_way = notify.formation.add() w = self.get_way_object(i) notify_way.MergeFrom(w.make_protobuf()) MessagePipe(self.char_id).put(msg=notify)
def send_my_check_notify(self): notify = UnionMyCheckNotify() for cid in self.union_doc['apply_list']: m = _MemberClub(self.server_id, cid, 0, 0) notify_member = notify.members.add() notify_member.MergeFrom(m.make_member_protomsg()) MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): # 只有 gold 需要notify income, expense = self.get_gold_statistics() notify = FinanceStatisticsNotify() notify.income.extend(income) notify.expense.extend(expense) MessagePipe(self.char_id).put(msg=notify)
def send_goods_notify(self): notify = TowerGoodsNotify() goods = self.doc.get('goods', []) for _id, b in goods: notify_goods = notify.goods.add() notify_goods.id = _id notify_goods.has_bought = b MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, update=False): notify = TaskNotify() if update: notify.act = ACT_UPDATE else: notify.act = ACT_INIT notify.doing = self.doing MessagePipe(self.char_id).put(msg=notify)
def send_plunder_times_notify(self): ti = PlunderTimesBuyInfo(self.server_id, self.char_id) notify = PlunderTimesNotify() notify.max_times = PLUNDER_TIMES_RECOVER_LIMIT notify.remained_times = self.doc['plunder_remained_times'] notify.buy_cost = ti.buy_cost notify.remained_buy_times = ti.remained_buy_times notify.next_recover_at = get_plunder_times_next_recover_at() MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): notify = SpecialEquipmentGenerateNotify() notify.id = self.doc['item_id'] notify.finish_timestamp = self.doc['finish_at'] tp = self.doc['tp'] if not tp: tp = SPECIAL_EQUIPMENT_GENERATE_NORMAL notify.tp = tp MessagePipe(self.char_id).put(msg=notify)
def send_notify(self, staff_ids=None): if staff_ids: act = ACT_UPDATE else: act = ACT_INIT staff_ids = self.doc['staffs'] notify = CollectionNotify() notify.act = act notify.collected_ids.extend(staff_ids) MessagePipe(self.char_id).put(msg=notify)
def send_energy_reward_notify(self): notify = WelfareEnergyRewardNotify() for index, (start, end) in enumerate(ENERGY_TIME_RANGE): notify_range = notify.time_range.add() notify_range.start = start notify_range.end = end times = ValueLogWelfareEnergyRewardTimes(self.server_id, self.char_id).count_of_today(sub_id=index) notify_range.can_get = times == 0 MessagePipe(self.char_id).put(msg=notify)
def send_notify(self): notify = UnionNotify() notify.id = "" notify.name = "" notify.bulletin = "" notify.level = 0 notify.contribution = 0 notify.rank = 0 notify.my_contribution = 0 notify.signin_id = 0 MessagePipe(self.char_id).put(msg=notify)
def send_daily_buy_notify(self): if arrow.utcnow().timestamp >= self.reward_end_at: return notify = ActivityNewPlayerDailyBuyNotify() for i in range(1, self.create_day + 1): notify_status = notify.status.add() notify_status.day = i notify_status.has_bought = i in self.doc['daily_buy'] MessagePipe(self.char_id).put(msg=notify)