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

Move squitServer/spawnServer to ts6_common, add topicServer for Unreal

This commit is contained in:
James Lu 2015-11-15 09:12:21 -08:00
parent 5664218254
commit ac48c49591
3 changed files with 54 additions and 35 deletions

View File

@ -247,39 +247,6 @@ class TS6Protocol(TS6BaseProtocol):
else:
self._send(source, 'AWAY')
def spawnServer(self, name, sid=None, uplink=None, desc=None):
"""
Spawns a server off a PyLink server. desc (server description)
defaults to the one in the config. uplink defaults to the main PyLink
server, and sid (the server ID) is automatically generated if not
given.
"""
# -> :0AL SID test.server 1 0XY :some silly pseudoserver
uplink = uplink or self.irc.sid
name = name.lower()
desc = desc or self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']
if sid is None: # No sid given; generate one!
sid = self.sidgen.next_sid()
assert len(sid) == 3, "Incorrect SID length"
if sid in self.irc.servers:
raise ValueError('A server with SID %r already exists!' % sid)
for server in self.irc.servers.values():
if name == server.name:
raise ValueError('A server named %r already exists!' % name)
if not utils.isInternalServer(self.irc, uplink):
raise ValueError('Server %r is not a PyLink internal PseudoServer!' % uplink)
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, desc=desc)
return sid
def squitServer(self, source, target, text='No reason given'):
"""SQUITs a PyLink server."""
# -> SQUIT 9PZ :blah, blah
self._send(source, 'SQUIT %s :%s' % (target, text))
self.handle_squit(source, 'SQUIT', [target, text])
def connect(self):
"""Initializes a connection to a server."""
ts = self.irc.start_ts

View File

@ -25,6 +25,8 @@ class TS6BaseProtocol(Protocol):
for k, v in self.irc.servers.items():
if v.name.lower() == nick:
return k
else:
return sname # Fall back to given text instead of None
### OUTGOING COMMANDS
@ -103,6 +105,40 @@ class TS6BaseProtocol(Protocol):
self.irc.channels[target].topic = text
self.irc.channels[target].topicset = True
def spawnServer(self, name, sid=None, uplink=None, desc=None):
"""
Spawns a server off a PyLink server. desc (server description)
defaults to the one in the config. uplink defaults to the main PyLink
server, and sid (the server ID) is automatically generated if not
given.
"""
# -> :0AL SID test.server 1 0XY :some silly pseudoserver
uplink = uplink or self.irc.sid
name = name.lower()
desc = desc or self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']
if sid is None: # No sid given; generate one!
sid = self.sidgen.next_sid()
assert len(sid) == 3, "Incorrect SID length"
if sid in self.irc.servers:
raise ValueError('A server with SID %r already exists!' % sid)
for server in self.irc.servers.values():
if name == server.name:
raise ValueError('A server named %r already exists!' % name)
if not utils.isInternalServer(self.irc, uplink):
raise ValueError('Server %r is not a PyLink internal PseudoServer!' % uplink)
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, desc=desc)
return sid
def squitServer(self, source, target, text='No reason given'):
"""SQUITs a PyLink server."""
# -> SQUIT 9PZ :blah, blah
log.debug('source=%s, target=%s', source, target)
self._send(source, 'SQUIT %s :%s' % (target, text))
self.handle_squit(source, 'SQUIT', [target, text])
### HANDLERS
def handle_privmsg(self, source, command, args):
@ -172,6 +208,7 @@ class TS6BaseProtocol(Protocol):
def handle_squit(self, numeric, command, args):
"""Handles incoming SQUITs (netsplits)."""
# :70M SQUIT 1ML :Server quit by GL!gl@0::1
log.debug('handle_squit args: %s', args)
split_server = args[0]
affected_users = []
log.debug('(%s) Splitting server %s (reason: %s)', self.irc.name, split_server, args[-1])

View File

@ -22,6 +22,7 @@ class UnrealProtocol(TS6BaseProtocol):
self.hook_map = {'UMODE2': 'MODE', 'SVSKILL': 'KILL', 'SVSMODE': 'MODE',
'SVS2MODE': 'MODE'}
self.uidgen = {}
self.sidgen = utils.TS6SIDGenerator(self.irc)
self.caps = {}
self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
@ -36,6 +37,7 @@ class UnrealProtocol(TS6BaseProtocol):
'I': 'invex', 't': 'topiclock', 'f': 'flood_unreal'}
self._neededCaps = ["VL", "SID", "CHANMODES", "NOQUIT", "SJ3"]
# Some command aliases
self.handle_svskill = self.handle_kill
### OUTGOING COMMAND FUNCTIONS
@ -195,6 +197,14 @@ class UnrealProtocol(TS6BaseProtocol):
raise LookupError('No such PyLink server exists.')
self._sendModes(numeric, target, modes, ts=ts)
def topicServer(self, numeric, target, text):
"""Sends a TOPIC change from a PyLink server."""
if not utils.isInternalServer(self.irc, numeric):
raise LookupError('No such PyLink server exists.')
self._send(numeric, 'TOPIC %s :%s' % (target, text))
self.irc.channels[target].topic = text
self.irc.channels[target].topicset = True
### HANDLERS
def connect(self):
@ -375,8 +385,13 @@ class UnrealProtocol(TS6BaseProtocol):
args = args[2:]
# If the sender isn't in UID format, try to convert it automatically.
# Unreal's protocol isn't quite consistent with this yet!
numeric = self._getSid(sender) or utils.nickToUid(self.irc, sender) or \
sender
sender_server = self._getSid(sender)
if sender_server in self.irc.servers:
# Sender is a server when converted from name to SID.
numeric = sender_server
else:
# Sender is a user.
numeric = self._getNick(sender)
# parseTS6Args() will raise IndexError if the TS6 sender prefix is missing.
except IndexError:
# Raw command without an explicit sender; assume it's being sent by our uplink.