From a3dcc20a0681641945ec6a60922493624f0d96d8 Mon Sep 17 00:00:00 2001 From: adator <85586985+adator85@users.noreply.github.com> Date: Sun, 16 Nov 2025 13:20:11 +0100 Subject: [PATCH] Handle SETHOST response to update the vhost of the user --- core/classes/interfaces/iprotocol.py | 15 +++++++++-- core/classes/protocols/inspircd.py | 20 +++++++++------ core/classes/protocols/unreal6.py | 37 +++++++++++++++++----------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/core/classes/interfaces/iprotocol.py b/core/classes/interfaces/iprotocol.py index 87b921f..704582b 100644 --- a/core/classes/interfaces/iprotocol.py +++ b/core/classes/interfaces/iprotocol.py @@ -335,7 +335,7 @@ class IProtocol(ABC): """ @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. >>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740'] @@ -343,7 +343,9 @@ class IProtocol(ABC): server_msg (list[str]): The server message to parse Returns: - dict[str, str]: The response as dictionary. + tuple(MUser, newnickname(str), timestamp(str)): Tuple of the response. + + >>> MUser, newnickname, timestamp """ @abstractmethod @@ -563,3 +565,12 @@ class IProtocol(ABC): Args: 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_ + """ \ No newline at end of file diff --git a/core/classes/protocols/inspircd.py b/core/classes/protocols/inspircd.py index 7ff0e54..52704af 100644 --- a/core/classes/protocols/inspircd.py +++ b/core/classes/protocols/inspircd.py @@ -1219,7 +1219,7 @@ class Inspircd(IProtocol): 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. >>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740'] @@ -1233,12 +1233,10 @@ class Inspircd(IProtocol): if scopy[0].startswith('@'): scopy.pop(0) - response = { - "uid": scopy[0].replace(':', ''), - "newnickname": scopy[2], - "timestamp": scopy[3] - } - return response + user_obj = self._User.get_user(self._User.clean_uid(scopy[0])) + newnickname = scopy[2] + timestamp = scopy[3] + return user_obj, newnickname, timestamp def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]: """Parse PRIVMSG message. @@ -1412,3 +1410,11 @@ class Inspircd(IProtocol): 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_ + """ + ... diff --git a/core/classes/protocols/unreal6.py b/core/classes/protocols/unreal6.py index 4886816..4f53a7e 100644 --- a/core/classes/protocols/unreal6.py +++ b/core/classes/protocols/unreal6.py @@ -19,8 +19,7 @@ class Unrealircd6(IProtocol): 'VERSION', 'REPUTATION', 'SVS2MODE', 'SLOG', 'NICK', 'PART', 'PONG', 'SASL', 'PING', '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]]: """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="PRIVMSG", func=self.on_privmsg)) self.Handler.register(m(command_name="KICK", func=self.on_kick)) + self.Handler.register(m(command_name="SETHOST", func=self.on_sethost)) return None @@ -663,7 +663,7 @@ class Unrealircd6(IProtocol): 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. >>> ['@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 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() if scopy[0].startswith('@'): scopy.pop(0) - response = { - "uid": scopy[0].replace(':', ''), - "newnickname": scopy[2], - "timestamp": scopy[3] - } - return response + user_obj = self._User.get_user(self._User.clean_uid(scopy[0])) + newnickname = scopy[2] + timestamp = scopy[3] + return user_obj, newnickname, timestamp def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]: """Parse PRIVMSG message. @@ -772,7 +770,6 @@ class Unrealircd6(IProtocol): # TODO : User object should be able to update user modes if self._Irc.User.update_mode(u.uid, user_mode): return None - # self._Logs.debug(f"Updating user mode for [{userObj.nickname}] [{old_umodes}] => [{userObj.umodes}]") return None @@ -1573,7 +1570,6 @@ class Unrealircd6(IProtocol): case _: return None - ... except Exception as e: self._Logs.error(f"General Error: {e}") @@ -1590,4 +1586,17 @@ class Unrealircd6(IProtocol): # Delete the user from the channel. self._Irc.Channel.delete_user_from_channel(channel, uid) - return None \ No newline at end of file + 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