def execute(self, user, name): if name.startswith('#'): channel = Channel.find_by_name(name) if user.is_operator: if channel is None: self.service.msg(user, '등록되지 않은 채널입니다.') return else: if channel is not None: if (channel.get_flags_by_user(user) & Flags.OWNER) == 0: self.service.msg(user, '권한이 없습니다.') return else: self.service.msg(user, '권한이 없습니다.') return self.service.msg(user, '\x02=== {} 채널 정보 ===\x02', channel.name) self.service.msg(user, '채널 등록일: {}', channel.created_on) else: account = Account.find_by_nick(name) if (not user.is_operator) and (account != user.account): self.service.msg(user, '권한이 없습니다. 오퍼레이터 인증을 해 주세요.') return if account is None: self.service.msg(user, '등록되지 않은 계정입니다.') return self.service.msg(user, '\x02=== {} 계정 정보 ===\x02', account.name.name) self.service.msg(user, '이메일: {}', account.email) self.service.msg(user, '대표 계정명: {}', account.name.name) self.service.msg(user, '보조 계정명: {}', (', '.join([nick.name for nick in account.aliases])) or '없음') self.service.msg(user, '가상 호스트: {}', account.vhost or '없음') self.service.msg(user, '계정 등록일: {}', account.created_on) self.service.msg(user, '마지막 로그인: {}', account.last_login)
def execute(self, user, nick): account = Account.find_by_nick(nick) if account is not user.account: self.service.msg(user, '해당 닉네임이 \x02{}\x02 계정에 속해 있지 않습니다.', user.account.name.name) return for target in self.service.server.users.values(): if target.nick == nick: self.service.writesvsuserline('KILL {} :{}!{}@{} 에 의한 고스트', target.uid, user.nick, user.ident, user.dhost) self.service.msg(user, '\x02{}\x02 닉네임을 사용중인 사용자의 연결을 종료시켰습니다.', target.nick) return
def execute(self, user, name, new_vhost): account = Account.find_by_nick(name) if account is None: self.service.msg(user, '등록되지 않은 계정입니다.') return session = Session() account.vhost = new_vhost session.commit() self.service.writesvsuserline('CHGHOST {} {}', user.uid, account.vhost or user.host) self.service.msg(user, '\x02{}\x02 계정의 가상 호스트가 \x02{}\x02 로 변경되었습니다.', user.account.name.name, new_vhost or '(없음)')
def execute(self, user, name): if name is None: account = user.account else: if user.is_operator: account = Account.find_by_nick(name) if account is None: self.service.msg(user, '등록되지 않은 계정입니다.') return else: self.service.msg(user, '권한이 없습니다. 오퍼레이터 인증을 해 주세요.') return self.service.msg(user, '\x02=== {} 계정 정보 ===\x02', account.name.name) self.service.msg(user, '이메일: {}', account.email) self.service.msg(user, '대표 계정명: {}', account.name.name) self.service.msg(user, '보조 계정명: {}', (', '.join([nick.name for nick in account.aliases])) or '없음') self.service.msg(user, '가상 호스트: {}', account.vhost or '없음') self.service.msg(user, '마지막 로그인: {}', account.last_login)
def connect(self): self.reader, self.writer = yield from asyncio.open_connection(self.link.host, self.link.port) logger.debug('Connected') self.writeline('SERVER {} {} 0 {} :{}', self.name, self.link.password, self.sid, self.description ) while 1: line = yield from self.readline() if not line: continue if RE_SERVER.match(line): server, command, *params = ircutils.parseline(line) sender = server if command == 'PING': self.writeserverline('PONG {} {}', params[1], params[0]) elif command == 'BURST': self._ev = self.ev self.ev = None elif command == 'ENDBURST': self.ev = self._ev self._ev = None params = [self.linked_once] if not self.linked_once: self.linked_once = True if settings.admin_channel in self.channels: timestamp = self.channels[settings.admin_channel].timestamp modes = self.channels[settings.admin_channel].modes else: timestamp = timeutils.unixtime() modes = '' self.writeserverline('FJOIN {} {} +{} :{}', settings.admin_channel, timestamp, modes, ' '.join(map(lambda x: 'a,{}'.format(x), self.services.keys()))) elif command == 'UID': self.users[params[0]] = User(*params) elif command == 'METADATA': if params[0] == '*': pass elif params[0].startswith('#'): self.channels[params[0].lower()].metadata[params[1]] = params[-1] else: if params[1] == 'accountname': account = Account.find_by_nick(params[-1]) if (account is not None) and (account.name.name == params[-1]): self.users[params[0]].metadata['accountname'] = account.name.name else: self.writeserverline('METADATA {} accountname :', params[0]) else: self.users[params[0]].metadata[params[1]] = params[-1] elif command == 'FJOIN': channel = params[0].lower() if channel in self.channels: self.channels[channel].fjoin(self.users, *params) else: self.channels[channel] = Channel(self.users, *params) elif RE_USER.match(line): uid, command, *params = ircutils.parseline(line) user = self.users[uid] sender = user if command == 'PRIVMSG': target = params[0] if target.startswith(self.sid): self.services[target].process_command(user, *params[1:]) elif command == 'OPERTYPE': user.opertype = params[0] elif command == 'IDLE': service = self.services[params[0]] self.writeuserline(service.uid, 'IDLE {} {} 0', uid, timeutils.unixtime()) elif command == 'NICK': user.nick = params[0] elif command == 'FHOST': user.dhost = params[0] elif command == 'KICK': channel = params[0].lower() target = self.users[params[1]] self.channels[channel].remove_user(target) if len(self.channels[channel].users) == 0: del self.channels[channel] elif command == 'PART': channel = params[0].lower() self.channels[channel].remove_user(user) if len(self.channels[channel].users) == 0: del self.channels[channel] elif command == 'QUIT': for channel in self.users[uid].channels: self.channels[channel].remove_user(user) if len(self.channels[channel].users) == 0: del self.channels[channel] del self.users[uid] else: command, *params = ircutils.parseline(line) sender = None if command == 'SERVER': try: assert params[0] == self.link.name assert params[1] == self.link.password except AssertionError: self.writeline('ERROR :Server information doesn\'t match.') break else: self.link.sid = params[3] self.writeserverline('BURST {}', timeutils.unixtime()) self.writeserverline('VERSION :{} {}', Versions.IKA, self.name) idx = 621937810 # int('AAAAAA', 36) for service in self.services_instances: service.id = ircutils.base36encode(idx) names = list(service.aliases) names.insert(0, service.name) for name in names: uid = '{}{}'.format(self.sid, ircutils.base36encode(idx)) self.writeserverline('UID {uid} {timestamp} {nick} {host} {host} {ident} 0.0.0.0 {timestamp} +Iiko :{gecos}', uid=uid, nick=name, ident=service.ident, host=self.name, gecos=service.gecos, timestamp=timeutils.unixtime(), ) self.writeuserline(uid, 'OPERTYPE Services') self.services[uid] = service idx += 1 self.writeserverline('ENDBURST') elif command == 'ERROR': raise RuntimeError('Remote server has returned an error: {}'.format(params[-1])) if hasattr(self.ev, command): getattr(self.ev, command).fire(sender, *params) # TODO: Implement each functions logger.debug('Disconnected')
def account(self): name = self.metadata.get('accountname') if name is not None: return Account.find_by_nick(name) return None