Browse Source

Update channel indexes when user changes nickname

master
Forest Belton 3 years ago
parent
commit
8824a465ce
4 changed files with 17 additions and 3 deletions
  1. +3
    -0
      paircd/channel.py
  2. +10
    -2
      paircd/handler/nick.py
  3. +1
    -1
      paircd/main.py
  4. +3
    -0
      paircd/server.py

+ 3
- 0
paircd/channel.py View File

@ -14,6 +14,9 @@ class Channel:
def add_client(self, client: Client) -> None: def add_client(self, client: Client) -> None:
self.clients_by_nick[client.nickname] = client self.clients_by_nick[client.nickname] = client
def remove_client_by_nick(self, nick: str) -> None:
del self.clients_by_nick[nick]
async def process(self) -> None: async def process(self) -> None:
while True: while True:
msg = await self.msg_queue.get() msg = await self.msg_queue.get()

+ 10
- 2
paircd/handler/nick.py View File

@ -12,12 +12,20 @@ class NickHandler(CommandHandler):
async def handle(self, server: Server, client: Client, msg: Message) -> None: async def handle(self, server: Server, client: Client, msg: Message) -> None:
nickname = msg.args[0] nickname = msg.args[0]
# Remove stale references if they exist
if client.nickname: if client.nickname:
del server.clients_by_nick[client.nickname]
# TODO: Update all channel references
server.remove_client_by_name(client.nickname)
for channel_name in client.channels:
channel = server.get_channel_by_name(channel_name)
channel.remove_client_by_nick(client.nickname)
client.nickname = nickname client.nickname = nickname
# Add references for client
server.add_client(client) server.add_client(client)
for channel_name in client.channels:
channel = server.get_channel_by_name(channel_name)
channel.remove_client_by_nick(client.nickname)
if client.username and client.realname: if client.username and client.realname:
client.registered = True client.registered = True

+ 1
- 1
paircd/main.py View File

@ -45,7 +45,7 @@ async def main() -> None:
reuse_port=True, reuse_port=True,
) )
logger.info(f"Listening on {bind_addr}:{port}...")
logger.info(f"Listening on {bind_addr}:{port}")
async with server: async with server:
await server.serve_forever() await server.serve_forever()

+ 3
- 0
paircd/server.py View File

@ -19,3 +19,6 @@ class Server:
self.channels_by_name[name] = Channel(name=name) self.channels_by_name[name] = Channel(name=name)
create_task(self.channels_by_name[name].process()) create_task(self.channels_by_name[name].process())
return self.channels_by_name[name] return self.channels_by_name[name]
def remove_client_by_name(self, name: str) -> None:
del self.clients_by_nick[name]

Loading…
Cancel
Save