3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

classes/protocols: store server descriptions internally

Closes #106.
This commit is contained in:
James Lu 2015-09-12 10:39:05 -07:00
parent 7f526267ec
commit df42a81191
3 changed files with 12 additions and 7 deletions

View File

@ -26,7 +26,9 @@ class Irc():
self.lastping = time.time()
# Server, channel, and user indexes to be populated by our protocol module
self.servers = {self.sid: IrcServer(None, self.serverdata['hostname'], internal=True)}
self.servers = {self.sid: IrcServer(None, self.serverdata['hostname'],
internal=True, desc=self.serverdata.get('serverdesc')
or self.botdata['serverdesc'])}
self.users = {}
self.channels = defaultdict(IrcChannel)
# Sets flags such as whether to use halfops, etc. The default RFC1459
@ -307,11 +309,12 @@ class IrcServer():
name: The name of the server.
internal: Whether the server is an internal PyLink PseudoServer.
"""
def __init__(self, uplink, name, internal=False):
def __init__(self, uplink, name, internal=False, desc="(None given)"):
self.uplink = uplink
self.users = set()
self.internal = internal
self.name = name.lower()
self.desc = desc
def __repr__(self):
return repr(self.__dict__)

View File

@ -285,7 +285,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
if not utils.isServerName(name):
raise ValueError('Invalid server name %r' % name)
self._send(uplink, 'SERVER %s * 1 %s :%s' % (name, sid, desc))
self.irc.servers[sid] = IrcServer(uplink, name, internal=True)
self.irc.servers[sid] = IrcServer(uplink, name, internal=True, desc=desc)
self._send(sid, 'ENDBURST')
return sid
@ -329,7 +329,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
if args[2] != self.irc.serverdata['recvpass']:
# Check if recvpass is correct
raise ProtocolError('Error: recvpass from uplink server %s does not match configuration!' % servername)
self.irc.servers[numeric] = IrcServer(None, servername)
sdesc = ' '.join(args).split(':', 1)[1]
self.irc.servers[numeric] = IrcServer(None, servername, desc=sdesc)
self.irc.uplink = numeric
return
elif args[0] == 'CAPAB':
@ -459,7 +460,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
servername = args[0].lower()
sid = args[3]
sdesc = args[-1]
self.irc.servers[sid] = IrcServer(numeric, servername)
self.irc.servers[sid] = IrcServer(numeric, servername, desc=sdesc)
return {'name': servername, 'sid': args[3], 'text': sdesc}
def handle_fmode(self, numeric, command, args):

View File

@ -276,7 +276,7 @@ class TS6Protocol(TS6BaseProtocol):
if not utils.isServerName(name):
raise ValueError('Invalid server name %r' % name)
self._send(uplink, 'SID %s 1 %s :%s' % (name, sid, desc))
self.irc.servers[sid] = IrcServer(uplink, name, internal=True)
self.irc.servers[sid] = IrcServer(uplink, name, internal=True, desc=desc)
return sid
def squitServer(self, source, target, text='No reason given'):
@ -407,6 +407,7 @@ class TS6Protocol(TS6BaseProtocol):
sname = args[1].lower()
log.debug('(%s) Found uplink server name as %r', self.irc.name, sname)
self.irc.servers[self.irc.uplink].name = sname
self.irc.servers[self.irc.uplink].desc = ' '.join(args).split(':', 1)[1]
# According to the TS6 protocol documentation, we should send SVINFO
# when we get our uplink's SERVER command.
self.irc.send('SVINFO 6 6 0 :%s' % int(time.time()))
@ -593,7 +594,7 @@ class TS6Protocol(TS6BaseProtocol):
# XXX: don't just save these by their server names; that's ugly!
sid = servername
sdesc = args[-1]
self.irc.servers[sid] = IrcServer(numeric, servername)
self.irc.servers[sid] = IrcServer(numeric, servername, desc=sdesc)
return {'name': servername, 'sid': sid, 'text': sdesc}
handle_sid = handle_server