Exemplo n.º 1
0
def m_MONITOR(cli, ev_msg):
    command = ev_msg['params'][0].casefold()

    if command in valid_metadata_subcommands:
        info = {
            'client': cli,
            'command': command,
        }

        limit = cli.ctx.conf.monitor.get('limit', None)
        if command == '+' and limit is not None:
            if len([c for c in cli.monitoring if validate_nick(c)]) + len(
                    ev_msg['params'][1].split(',')) > limit:
                cli.dump_numeric(
                    '734',
                    [str(limit), ev_msg['params'][1], 'Monitor list is full'])
                return

        if command in '-+':
            targets = []
            for target in ev_msg['params'][1].split(','):
                if not validate_nick(target):
                    continue
                targets.append(target)

            info['targets'] = targets

        eventmgr_core.dispatch(' '.join(['monitor', command]), info)
    else:
        cli.dump_numeric('400', ['MONITOR', command, 'Unknown subcommand'])
Exemplo n.º 2
0
def m_MONITOR(cli, ev_msg):
    command = ev_msg['params'][0].casefold()

    if command in valid_metadata_subcommands:
        info = {
            'client': cli,
            'command': command,
        }

        limit = cli.ctx.conf.monitor.get('limit', None)
        if command == '+' and limit is not None:
            if len([c for c in cli.monitoring if validate_nick(c)]) + len(ev_msg['params'][1].split(',')) > limit:
                cli.dump_numeric('734', [cli.nickname, str(limit), ev_msg['params'][1], 'Monitor list is full'])
                return

        if command in '-+':
            targets = []
            for target in ev_msg['params'][1].split(','):
                if not validate_nick(target):
                    continue
                targets.append(target)

            info['targets'] = targets

        eventmgr_core.dispatch(' '.join(['monitor', command]), info)
    else:
        cli.dump_numeric(400, ['MONITOR', command, 'Unknown subcommand'])
Exemplo n.º 3
0
def m_monitor_status(info):
    ctx = get_context()
    client = info['client']

    online = []
    offline = []

    for target in client.monitoring:
        if validate_nick(target):
            if target in ctx.clients:
                online.append(target)
            else:
                offline.append(target)

    if online:
        client.dump_numeric('730', [info['client'].nickname, ','.join(online)])
    if offline:
        client.dump_numeric('731', [info['client'].nickname, ','.join(offline)])
Exemplo n.º 4
0
def m_monitor_status(info):
    ctx = get_context()
    cli = info['client']

    online = []
    offline = []

    for target in cli.monitoring:
        if validate_nick(target):
            if target in ctx.clients:
                online.append(target)
            else:
                offline.append(target)

    if online:
        cli.dump_numeric('730', [','.join(online)])
    if offline:
        cli.dump_numeric('731', [','.join(offline)])
Exemplo n.º 5
0
def m_NICK(cli, ev_msg):
    new_nickname = ev_msg["params"][0]
    nicklen = cli.ctx.conf.limits.get("nick", None)
    if nicklen and len(new_nickname) > nicklen:
        new_nickname = new_nickname[:nicklen]
    if not validate_nick(new_nickname):
        cli.dump_numeric("432", [new_nickname, "Erroneous nickname"])
        return
    if new_nickname in cli.ctx.clients:
        cli.dump_numeric("433", [new_nickname, "Nickname already in use"])
        return
    msg = RFC1459Message.from_data("NICK", source=cli.hostmask, params=[new_nickname])
    if cli.registered:
        if cli.nickname in cli.ctx.clients:
            cli.ctx.clients.pop(cli.nickname)
        cli.ctx.clients[new_nickname] = cli
        cli.sendto_common_peers(msg)
    cli.nickname = new_nickname
    cli.release_registration_lock("NICK")
Exemplo n.º 6
0
def m_NICK(cli, ev_msg):
    new_nickname = ev_msg['params'][0]
    nicklen = cli.ctx.conf.limits.get('nick', None)
    if nicklen and len(new_nickname) > nicklen:
        new_nickname = new_nickname[:nicklen]
    if not validate_nick(new_nickname):
        cli.dump_numeric('432', [new_nickname, 'Erroneous nickname'])
        return
    with cli.ctx.prereg_nicks_lock:
        if new_nickname in cli.ctx.clients or new_nickname in cli.ctx.prereg_nicks:
            cli.dump_numeric('433', [new_nickname, 'Nickname already in use'])
            return
        cli.ctx.prereg_nicks.append(new_nickname)
    msg = RFC1459Message.from_data('NICK', source=cli, params=[new_nickname])
    if cli.registered:
        if cli.nickname in cli.ctx.clients:
            cli.ctx.clients.pop(cli.nickname)
        cli.ctx.clients[new_nickname] = cli
        cli.sendto_common_peers(msg)
    cli.nickname = new_nickname
    cli.release_registration_lock('NICK')
Exemplo n.º 7
0
def m_monitor_clear(info):
    cli = info['client']
    for target in cli.monitoring:
        if validate_nick(target):
            monitored[target].remove(cli)
    cli.monitoring = [c for c in cli.monitoring if not validate_nick(c)]
Exemplo n.º 8
0
def m_monitor_list(info):
    cli = info['client']
    cli.dump_numeric(
        '732', [','.join([c for c in cli.monitoring if validate_nick(c)])])
    cli.dump_numeric('733', ['End of MONITOR list'])