def alliance_appoint(p, req): ''' 公会任命 ''' cid, [other_cid, position] = req _m = g_UserMgr.getUser(cid) if not _m: defer.returnValue(CONNECTION_LOSE) if not _m.alliance or not _m.has_authority: defer.returnValue(ALLIANCE_NEED_VICE_LEADER) # 判断该玩家当前的公会状态 _other_m = yield g_UserMgr.get_offline_user(other_cid) if not _other_m or not _other_m.alliance or _other_m.alliance.aid != _m.alliance.aid: defer.returnValue(ALLIANCE_NOT_MEMBER_ERROR) if _other_m.position == position: defer.returnValue(ALLIANCE_HAD_IN_POSITION) if position == ALLIANCE_POSITION_LEADER: if _m.isLeader: _m.update_position(ALLIANCE_POSITION_NORMAL) res_err = _m.alliance.appoint_leader(_other_m, _m) defer.returnValue(res_err) else: defer.returnValue(ALLIANCE_NEED_LEADER) elif position == ALLIANCE_POSITION_VICE: if not _m.isLeader: defer.returnValue(ALLIANCE_NEED_LEADER) res_err = _m.alliance.appoint_vice(_other_m, _m) defer.returnValue(res_err) else: res_err = _m.alliance.appoint_normal(_other_m, _m) defer.returnValue(res_err)
def alliance_kick(p, req): ''' 将成员踢出公会 ''' cid, [kick_cid] = req _m = g_UserMgr.getUser(cid) if not _m: defer.returnValue(CONNECTION_LOSE) if not _m.alliance or not _m.has_authority: defer.returnValue(ALLIANCE_NEED_VICE_LEADER) _kick_m = yield g_UserMgr.get_offline_user(kick_cid) if not _kick_m: defer.returnValue(UNKNOWN_ERROR) # 判断该玩家当前的公会状态 if not _kick_m.alliance or _kick_m.alliance.aid != _m.alliance.aid: _m.alliance.del_invalid_member(_kick_m) defer.returnValue(NO_ERROR) if _kick_m.position and _m.position >= _kick_m.position: defer.returnValue(ALLIANCE_NEED_VICE_LEADER) yield _m.alliance.del_member(_kick_m, _m) defer.returnValue(NO_ERROR)
def reject_all(self): # 对方没有公会时发送邮件 for _cid, _r in self.__requests.iteritems(): _m = yield g_UserMgr.get_offline_user( _cid ) if _m and not _m.alliance: ms_send('write_mail', (_r.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_4, [self.__name])) # 删除所有的入会申请 yield self.del_all_requests() self.__requests = {} defer.returnValue( NO_ERROR )
def get_alliance_info(p, req): cid, = req alliance_info = 0, '', 0 user = yield g_UserMgr.get_offline_user(cid) if (not user) or (not user.alliance): defer.returnValue( alliance_info ) alliance_info = user.alliance.aid, user.alliance.name, user.position defer.returnValue( alliance_info )
def sync_alliance_rank(self): _alliances = [] for _a in Server.__alliances: _member_cids = _a.members _total_might = 0 for _cid in _member_cids: _m = yield g_UserMgr.get_offline_user(_cid) if not _m: continue _total_might += _m.might _a.set_might(_total_might) bisect.insort_right(_alliances, _a) Server.__alliances = _alliances _remain = get_reward_timestamp(23, 59, 59) - int(time()) reactor.callLater(_remain, self.sync_alliance_rank)
def sync_alliance_rank(self): _alliances = [] for _a in Server.__alliances: _member_cids = _a.members _total_might = 0 for _cid in _member_cids: _m = yield g_UserMgr.get_offline_user(_cid) if not _m: continue _total_might += _m.might _a.set_might(_total_might) bisect.insort_right( _alliances, _a ) Server.__alliances = _alliances _remain = get_reward_timestamp(23, 59, 59) - int(time()) reactor.callLater(_remain, self.sync_alliance_rank)
def del_request(self, cid, join_flag=False, action_member=None): ''' param join_flag: True-同意加入公会 False-拒绝加入公会 ''' _r = self.__requests.get(cid, None) if not _r: defer.returnValue( ALLIANCE_REQUEST_UNKNOWN ) _m = yield g_UserMgr.get_offline_user( cid ) if not _m: log.warn('Unknown member. cid: {0}.'.format( cid )) defer.returnValue( NO_ERROR ) # 对方没有公会且拒绝加入时发送邮件 if not join_flag and not _m.alliance: ms_send('write_mail', (cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_4, [self.__name])) # 同意加入公会时检查公会成员人数限制之后再删除请求 if join_flag: # 判断公会成员数量 _conf = get_alliance_level_conf(self.__level) if not _conf: log.error('Can not find the conf. alliance_level: {0}.'.format( self.__level )) defer.returnValue( ALLIANCE_MEMBERS_MAX_ERROR ) if len(self.__members) >= _conf['MembersCount']: defer.returnValue( ALLIANCE_MEMBERS_MAX_ERROR ) del self.__requests[cid] yield redis.lrem( TPL_LIST_ALLIANCE_REQUEST % self.__id, 0, dumps(_r.info) ) del_request_to_dict( [_r] ) # 同意加入公会 if join_flag: # 判断对方的公会状态 if _m.alliance: defer.returnValue( ALLIANCE_OTHER_HAD_IN ) yield _m.join_alliance( self ) # 维护公会的公共信息 self.__members.append( cid ) self.dirty() self.update_might( _r.might ) # 公会动态 self.new_action( (ALLIANCE_ACTION_1, int(time()), action_member.cid, \ action_member.lead_id, action_member.nick_name, action_member.level, [_m.lead_id, _m.nick_name]) ) # 给对方发送邮件 ms_send('write_mail', (cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_3, [self.__name])) defer.returnValue( NO_ERROR )