mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-12 21:22:36 +01:00
ngircd: implement nick changing
This commit is contained in:
parent
42a25300c4
commit
b780070ee6
@ -112,6 +112,18 @@ class NgIRCdProtocol(IRCS2SProtocol):
|
|||||||
self.channels[channel].users.add(client)
|
self.channels[channel].users.add(client)
|
||||||
self.users[client].channels.add(channel)
|
self.users[client].channels.add(channel)
|
||||||
|
|
||||||
|
def nick(self, source, newnick):
|
||||||
|
"""Changes the nick of a PyLink client."""
|
||||||
|
if not self.is_internal_client(source):
|
||||||
|
raise LookupError('No such PyLink client exists.')
|
||||||
|
|
||||||
|
self._send_with_prefix(source, 'NICK %s' % newnick)
|
||||||
|
|
||||||
|
self.users[source].nick = newnick
|
||||||
|
|
||||||
|
# Update the nick TS for consistency with other protocols (it isn't actually used in S2S)
|
||||||
|
self.users[source].ts = int(time.time())
|
||||||
|
|
||||||
### Handlers
|
### Handlers
|
||||||
|
|
||||||
def handle_pass(self, source, command, args):
|
def handle_pass(self, source, command, args):
|
||||||
@ -145,25 +157,36 @@ class NgIRCdProtocol(IRCS2SProtocol):
|
|||||||
return {'name': servername, 'sid': None, 'text': serverdesc}
|
return {'name': servername, 'sid': None, 'text': serverdesc}
|
||||||
|
|
||||||
def handle_nick(self, source, command, args):
|
def handle_nick(self, source, command, args):
|
||||||
# <- :ngircd.midnight.local NICK GL 1 ~gl localhost 1 +io :realname
|
"""
|
||||||
nick = args[0]
|
Handles the NICK command, used for server introductions and nick changes.
|
||||||
assert source in self.servers, "Server %r tried to introduce nick %r but isn't in the servers index?" % (source, nick)
|
"""
|
||||||
|
if len(args) >= 2:
|
||||||
|
# User introduction:
|
||||||
|
# <- :ngircd.midnight.local NICK GL 1 ~gl localhost 1 +io :realname
|
||||||
|
nick = args[0]
|
||||||
|
assert source in self.servers, "Server %r tried to introduce nick %r but isn't in the servers index?" % (source, nick)
|
||||||
|
|
||||||
ident = args[2]
|
ident = args[2]
|
||||||
host = args[3]
|
host = args[3]
|
||||||
uid = self.uidgen.next_uid(prefix=nick)
|
uid = self.uidgen.next_uid(prefix=nick)
|
||||||
realname = args[-1]
|
realname = args[-1]
|
||||||
|
|
||||||
ts = int(time.time())
|
ts = int(time.time())
|
||||||
self.users[uid] = User(nick, ts, uid, source, ident=ident, host=host, realname=realname)
|
self.users[uid] = User(nick, ts, uid, source, ident=ident, host=host, realname=realname)
|
||||||
parsedmodes = self.parse_modes(uid, [args[5]])
|
parsedmodes = self.parse_modes(uid, [args[5]])
|
||||||
self.apply_modes(uid, parsedmodes)
|
self.apply_modes(uid, parsedmodes)
|
||||||
|
|
||||||
# Add the nick to the list of users on its server; this is used for SQUIT tracking
|
# Add the nick to the list of users on its server; this is used for SQUIT tracking
|
||||||
self.servers[source].users.add(uid)
|
self.servers[source].users.add(uid)
|
||||||
|
|
||||||
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': host, 'host': host, 'ident': ident,
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': host, 'host': host, 'ident': ident,
|
||||||
'parse_as': 'UID', 'ip': '0.0.0.0'}
|
'parse_as': 'UID', 'ip': '0.0.0.0'}
|
||||||
|
else:
|
||||||
|
# Nick changes:
|
||||||
|
# <- :GL NICK :GL_
|
||||||
|
oldnick = self.users[source].nick
|
||||||
|
newnick = self.users[source].nick = args[0]
|
||||||
|
return {'newnick': newnick, 'oldnick': oldnick}
|
||||||
|
|
||||||
def handle_ping(self, source, command, args):
|
def handle_ping(self, source, command, args):
|
||||||
if source == self.uplink:
|
if source == self.uplink:
|
||||||
|
Loading…
Reference in New Issue
Block a user