mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Irc: introduce matchHost() wrapper around ircmatch
This makes the latter a core dependency. Refactor changehost and opercmds plugins to take advantage of this new core function.
This commit is contained in:
parent
37e1c7d538
commit
d3877b0194
@ -18,8 +18,8 @@ You can also find support via our IRC channels: `#PyLink @ irc.overdrivenetworks
|
||||
|
||||
* Python 3.4+
|
||||
* PyYAML (`pip install pyyaml`)
|
||||
* [ircmatch](https://github.com/mammon-ircd/ircmatch) (`pip install ircmatch`)
|
||||
* *For the servprotect plugin*: [expiringdict](https://github.com/mailgun/expiringdict) (note: unfortunately, installation is broken in pip due to [mailgun/expiringdict#13](https://github.com/mailgun/expiringdict/issues/13))
|
||||
* *For the changehost and opercmds plugins*: [ircmatch](https://github.com/mammon-ircd/ircmatch) (`pip install ircmatch`)
|
||||
|
||||
## Supported IRCds
|
||||
|
||||
|
33
classes.py
33
classes.py
@ -11,12 +11,13 @@ import threading
|
||||
from random import randint
|
||||
import time
|
||||
import socket
|
||||
import threading
|
||||
import ssl
|
||||
import hashlib
|
||||
from copy import deepcopy
|
||||
import inspect
|
||||
|
||||
import ircmatch
|
||||
|
||||
from . import world, utils, structures, __version__
|
||||
from .log import *
|
||||
|
||||
@ -908,6 +909,36 @@ class Irc():
|
||||
raise utils.NotAuthenticatedError("You are not authenticated!")
|
||||
return True
|
||||
|
||||
def matchHost(self, glob, target, ip=True, realhost=True):
|
||||
"""
|
||||
Checks whether the given host, or given UID's hostmask matches the given nick!user@host
|
||||
glob.
|
||||
|
||||
If the target given is a UID, and the ip or realhost options are True, this will also match
|
||||
against the target's IP address and real host, respectively.
|
||||
"""
|
||||
# Get the corresponding casemapping value used by ircmatch.
|
||||
casemapping = getattr(ircmatch, self.proto.casemapping)
|
||||
|
||||
# Prepare a list of hosts to check against.
|
||||
if target in self.users:
|
||||
hosts = {self.getHostmask(target)}
|
||||
|
||||
if ip:
|
||||
hosts.add(self.getHostmask(target, ip=True))
|
||||
|
||||
if realhost:
|
||||
hosts.add(self.getHostmask(target, ip=True))
|
||||
else: # We were given a host, use that.
|
||||
hosts = [target]
|
||||
|
||||
# Iterate over the hosts to match using ircmatch.
|
||||
for host in hosts:
|
||||
if ircmatch.match(casemapping, glob, host):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
class IrcUser():
|
||||
"""PyLink IRC user class."""
|
||||
def __init__(self, nick, ts, uid, ident='null', host='null',
|
||||
|
Loading…
Reference in New Issue
Block a user