mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
Handle SETHOST response to update the vhost of the user
This commit is contained in:
@@ -335,7 +335,7 @@ class IProtocol(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def parse_nick(self, server_msg: list[str]) -> dict[str, str]:
|
def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
|
||||||
"""Parse nick changes and return dictionary.
|
"""Parse nick changes and return dictionary.
|
||||||
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
|
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
|
||||||
|
|
||||||
@@ -343,7 +343,9 @@ class IProtocol(ABC):
|
|||||||
server_msg (list[str]): The server message to parse
|
server_msg (list[str]): The server message to parse
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: The response as dictionary.
|
tuple(MUser, newnickname(str), timestamp(str)): Tuple of the response.
|
||||||
|
|
||||||
|
>>> MUser, newnickname, timestamp
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -563,3 +565,12 @@ class IProtocol(ABC):
|
|||||||
Args:
|
Args:
|
||||||
server_msg (list[str]): The server message
|
server_msg (list[str]): The server message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def on_sethost(self, server_msg: list[str]) -> None:
|
||||||
|
"""On SETHOST command
|
||||||
|
>>> [':001DN7305', 'SETHOST', ':netadmin.example.org']
|
||||||
|
|
||||||
|
Args:
|
||||||
|
server_msg (list[str]): _description_
|
||||||
|
"""
|
||||||
@@ -1219,7 +1219,7 @@ class Inspircd(IProtocol):
|
|||||||
|
|
||||||
return user_obj, reason
|
return user_obj, reason
|
||||||
|
|
||||||
def parse_nick(self, server_msg: list[str]) -> dict[str, str]:
|
def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
|
||||||
"""Parse nick changes.
|
"""Parse nick changes.
|
||||||
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
|
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
|
||||||
|
|
||||||
@@ -1233,12 +1233,10 @@ class Inspircd(IProtocol):
|
|||||||
if scopy[0].startswith('@'):
|
if scopy[0].startswith('@'):
|
||||||
scopy.pop(0)
|
scopy.pop(0)
|
||||||
|
|
||||||
response = {
|
user_obj = self._User.get_user(self._User.clean_uid(scopy[0]))
|
||||||
"uid": scopy[0].replace(':', ''),
|
newnickname = scopy[2]
|
||||||
"newnickname": scopy[2],
|
timestamp = scopy[3]
|
||||||
"timestamp": scopy[3]
|
return user_obj, newnickname, timestamp
|
||||||
}
|
|
||||||
return response
|
|
||||||
|
|
||||||
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
||||||
"""Parse PRIVMSG message.
|
"""Parse PRIVMSG message.
|
||||||
@@ -1412,3 +1410,11 @@ class Inspircd(IProtocol):
|
|||||||
server_msg (list[str]): Original server message
|
server_msg (list[str]): Original server message
|
||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def on_sethost(self, server_msg: list[str]) -> None:
|
||||||
|
"""On SETHOST command
|
||||||
|
|
||||||
|
Args:
|
||||||
|
server_msg (list[str]): _description_
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ class Unrealircd6(IProtocol):
|
|||||||
'VERSION', 'REPUTATION', 'SVS2MODE',
|
'VERSION', 'REPUTATION', 'SVS2MODE',
|
||||||
'SLOG', 'NICK', 'PART', 'PONG', 'SASL', 'PING',
|
'SLOG', 'NICK', 'PART', 'PONG', 'SASL', 'PING',
|
||||||
'PROTOCTL', 'SERVER', 'SMOD', 'TKL', 'NETINFO',
|
'PROTOCTL', 'SERVER', 'SMOD', 'TKL', 'NETINFO',
|
||||||
'006', '007', '018'}
|
'SETHOST', '006', '007', '018'}
|
||||||
|
|
||||||
|
|
||||||
def get_ircd_protocol_poisition(self, cmd: list[str], log: bool = False) -> tuple[int, Optional[str]]:
|
def get_ircd_protocol_poisition(self, cmd: list[str], log: bool = False) -> tuple[int, Optional[str]]:
|
||||||
"""Get the position of known commands
|
"""Get the position of known commands
|
||||||
@@ -62,6 +61,7 @@ class Unrealircd6(IProtocol):
|
|||||||
self.Handler.register(m(command_name="MD", func=self.on_md))
|
self.Handler.register(m(command_name="MD", func=self.on_md))
|
||||||
self.Handler.register(m(command_name="PRIVMSG", func=self.on_privmsg))
|
self.Handler.register(m(command_name="PRIVMSG", func=self.on_privmsg))
|
||||||
self.Handler.register(m(command_name="KICK", func=self.on_kick))
|
self.Handler.register(m(command_name="KICK", func=self.on_kick))
|
||||||
|
self.Handler.register(m(command_name="SETHOST", func=self.on_sethost))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -663,7 +663,7 @@ class Unrealircd6(IProtocol):
|
|||||||
|
|
||||||
return user_obj, reason
|
return user_obj, reason
|
||||||
|
|
||||||
def parse_nick(self, server_msg: list[str]) -> dict[str, str]:
|
def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
|
||||||
"""Parse nick changes and return dictionary.
|
"""Parse nick changes and return dictionary.
|
||||||
>>> ['@unrealircd.org/geoip=FR;unrealircd.org/', ':001OOU2H3', 'NICK', 'WebIrc', '1703795844']
|
>>> ['@unrealircd.org/geoip=FR;unrealircd.org/', ':001OOU2H3', 'NICK', 'WebIrc', '1703795844']
|
||||||
|
|
||||||
@@ -671,20 +671,18 @@ class Unrealircd6(IProtocol):
|
|||||||
server_msg (list[str]): The server message to parse
|
server_msg (list[str]): The server message to parse
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: The response as dictionary.
|
tuple(MUser, newnickname(str), timestamp(str)): Tuple of the response.
|
||||||
|
|
||||||
>>> {"uid": "", "newnickname": "", "timestamp": ""}
|
>>> MUser, newnickname, timestamp
|
||||||
"""
|
"""
|
||||||
scopy = server_msg.copy()
|
scopy = server_msg.copy()
|
||||||
if scopy[0].startswith('@'):
|
if scopy[0].startswith('@'):
|
||||||
scopy.pop(0)
|
scopy.pop(0)
|
||||||
|
|
||||||
response = {
|
user_obj = self._User.get_user(self._User.clean_uid(scopy[0]))
|
||||||
"uid": scopy[0].replace(':', ''),
|
newnickname = scopy[2]
|
||||||
"newnickname": scopy[2],
|
timestamp = scopy[3]
|
||||||
"timestamp": scopy[3]
|
return user_obj, newnickname, timestamp
|
||||||
}
|
|
||||||
return response
|
|
||||||
|
|
||||||
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
||||||
"""Parse PRIVMSG message.
|
"""Parse PRIVMSG message.
|
||||||
@@ -772,7 +770,6 @@ class Unrealircd6(IProtocol):
|
|||||||
# TODO : User object should be able to update user modes
|
# TODO : User object should be able to update user modes
|
||||||
if self._Irc.User.update_mode(u.uid, user_mode):
|
if self._Irc.User.update_mode(u.uid, user_mode):
|
||||||
return None
|
return None
|
||||||
# self._Logs.debug(f"Updating user mode for [{userObj.nickname}] [{old_umodes}] => [{userObj.umodes}]")
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1573,7 +1570,6 @@ class Unrealircd6(IProtocol):
|
|||||||
case _:
|
case _:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
...
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._Logs.error(f"General Error: {e}")
|
self._Logs.error(f"General Error: {e}")
|
||||||
|
|
||||||
@@ -1590,4 +1586,17 @@ class Unrealircd6(IProtocol):
|
|||||||
|
|
||||||
# Delete the user from the channel.
|
# Delete the user from the channel.
|
||||||
self._Irc.Channel.delete_user_from_channel(channel, uid)
|
self._Irc.Channel.delete_user_from_channel(channel, uid)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def on_sethost(self, server_msg: list[str]) -> None:
|
||||||
|
"""On SETHOST command
|
||||||
|
>>> [':001DN7305', 'SETHOST', ':netadmin.example.org']
|
||||||
|
|
||||||
|
Args:
|
||||||
|
server_msg (list[str]): _description_
|
||||||
|
"""
|
||||||
|
scopy = server_msg.copy()
|
||||||
|
uid = self._User.clean_uid(scopy[0])
|
||||||
|
vhost = scopy[2].lstrip(':')
|
||||||
|
user = self._User.get_user(uid)
|
||||||
|
user.vhost = vhost
|
||||||
|
|||||||
Reference in New Issue
Block a user