3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 11:42:51 +01:00

protocols: allow changing remote users' hosts in updateClient

Closes #142.
This commit is contained in:
James Lu 2015-12-30 15:54:09 -08:00
parent f3d8c35219
commit 741fed9acd
3 changed files with 90 additions and 29 deletions

View File

@ -231,20 +231,47 @@ class InspIRCdProtocol(TS6BaseProtocol):
raise LookupError('No such PyLink PseudoClient exists.')
self._send(numeric, 'ENCAP * KNOCK %s :%s' % (target, text))
def updateClient(self, numeric, field, text):
"""Updates the ident, host, or realname of a PyLink client."""
def updateClient(self, target, field, text):
"""Updates the ident, host, or realname of any connected client."""
field = field.upper()
if field == 'IDENT':
self.irc.users[numeric].ident = text
self._send(numeric, 'FIDENT %s' % text)
elif field == 'HOST':
self.irc.users[numeric].host = text
self._send(numeric, 'FHOST %s' % text)
elif field in ('REALNAME', 'GECOS'):
self.irc.users[numeric].realname = text
self._send(numeric, 'FNAME :%s' % text)
if field not in ('IDENT', 'HOST', 'REALNAME', 'GECOS'):
raise NotImplementedError("Changing field %r of a client is "
"unsupported by this protocol." % field)
if utils.isInternalClient(self.irc, target):
# It is one of our clients, use FIDENT/HOST/NAME.
if field == 'IDENT':
self.irc.users[target].ident = text
self._send(target, 'FIDENT %s' % text)
elif field == 'HOST':
self.irc.users[target].host = text
self._send(target, 'FHOST %s' % text)
elif field in ('REALNAME', 'GECOS'):
self.irc.users[target].realname = text
self._send(target, 'FNAME :%s' % text)
else:
raise NotImplementedError("Changing field %r of a client is unsupported by this protocol." % field)
# It is a client on another server, use CHGIDENT/HOST/NAME.
if field == 'IDENT':
self.irc.users[target].ident = text
self._send(self.irc.sid, 'CHGIDENT %s %s' % (target, text))
# Send hook payloads for other plugins to listen to.
self.irc.callHooks([self.irc.sid, 'CHGIDENT',
{'target': target, 'newident': text}])
elif field == 'HOST':
self.irc.users[target].host = text
self._send(self.irc.sid, 'CHGHOST %s %s' % (target, text))
self.irc.callHooks([self.irc.sid, 'CHGHOST',
{'target': target, 'newhost': text}])
elif field in ('REALNAME', 'GECOS'):
self.irc.users[target].realname = text
self._send(self.irc.sid, 'CHGNAME %s :%s' % (target, text))
self.irc.callHooks([self.irc.sid, 'CHGNAME',
{'target': target, 'newgecos': text}])
def pingServer(self, source=None, target=None):
"""Sends a PING to a target server. Periodic PINGs are sent to our uplink

View File

@ -223,14 +223,20 @@ class TS6Protocol(TS6BaseProtocol):
# No text value is supported here; drop it.
self._send(numeric, 'KNOCK %s' % target)
def updateClient(self, numeric, field, text):
"""Updates the hostname of a PyLink client."""
def updateClient(self, target, field, text):
"""Updates the hostname of any connected client."""
field = field.upper()
if field == 'HOST':
self.irc.users[numeric].host = text
self._send(self.irc.sid, 'CHGHOST %s :%s' % (numeric, text))
self.irc.users[target].host = text
self._send(self.irc.sid, 'CHGHOST %s :%s' % (target, text))
if not utils.isInternalClient(self.irc, target):
# If the target isn't one of our clients, send hook payload
# for other plugins to listen to.
self.irc.callHooks([self.irc.sid, 'CHGHOST',
{'target': target, 'newhost': text}])
else:
raise NotImplementedError("Changing field %r of a client is unsupported by this protocol." % field)
raise NotImplementedError("Changing field %r of a client is "
"unsupported by this protocol." % field)
def pingServer(self, source=None, target=None):
"""Sends a PING to a target server. Periodic PINGs are sent to our uplink

View File

@ -239,20 +239,48 @@ class UnrealProtocol(TS6BaseProtocol):
self.irc.channels[target].topic = text
self.irc.channels[target].topicset = True
def updateClient(self, numeric, field, text):
"""Updates the ident, host, or realname of a PyLink client."""
def updateClient(self, target, field, text):
"""Updates the ident, host, or realname of any connected client."""
field = field.upper()
if field == 'IDENT':
self.irc.users[numeric].ident = text
self._send(numeric, 'SETIDENT %s' % text)
elif field == 'HOST':
self.irc.users[numeric].host = text
self._send(numeric, 'SETHOST %s' % text)
elif field in ('REALNAME', 'GECOS'):
self.irc.users[numeric].realname = text
self._send(numeric, 'SETNAME :%s' % text)
if field not in ('IDENT', 'HOST', 'REALNAME', 'GECOS'):
raise NotImplementedError("Changing field %r of a client is "
"unsupported by this protocol." % field)
if utils.isInternalClient(self.irc, target):
# It is one of our clients, use SETIDENT/HOST/NAME.
if field == 'IDENT':
self.irc.users[target].ident = text
self._send(target, 'SETIDENT %s' % text)
elif field == 'HOST':
self.irc.users[target].host = text
self._send(target, 'SETHOST %s' % text)
elif field in ('REALNAME', 'GECOS'):
self.irc.users[target].realname = text
self._send(target, 'SETNAME :%s' % text)
else:
raise NotImplementedError("Changing field %r of a client is unsupported by this protocol." % field)
# It is a client on another server, use CHGIDENT/HOST/NAME.
if field == 'IDENT':
self.irc.users[target].ident = text
self._send(self.irc.sid, 'CHGIDENT %s %s' % (target, text))
# Send hook payloads for other plugins to listen to.
self.irc.callHooks([self.irc.sid, 'CHGIDENT',
{'target': target, 'newident': text}])
elif field == 'HOST':
self.irc.users[target].host = text
self._send(self.irc.sid, 'CHGHOST %s %s' % (target, text))
self.irc.callHooks([self.irc.sid, 'CHGHOST',
{'target': target, 'newhost': text}])
elif field in ('REALNAME', 'GECOS'):
self.irc.users[target].realname = text
self._send(self.irc.sid, 'CHGNAME %s :%s' % (target, text))
self.irc.callHooks([self.irc.sid, 'CHGNAME',
{'target': target, 'newgecos': text}])
def inviteClient(self, numeric, target, channel):
"""Sends an INVITE from a PyLink client.."""