3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

hybrid: Implement suggested changes, remove comments

This commit is contained in:
Daniel Oaks 2015-12-27 09:18:06 +10:00
parent 1e79adc171
commit 7ec4962412

View File

@ -17,11 +17,13 @@ class HybridProtocol(TS6BaseProtocol):
self.casemapping = 'ascii' self.casemapping = 'ascii'
self.sidgen = utils.TS6SIDGenerator(self.irc) self.sidgen = utils.TS6SIDGenerator(self.irc)
self.uidgen = {} self.uidgen = {}
self.eob = False
self.caps = {} self.caps = {}
# halfops is mandatory on Hybrid
self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'} self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'}
self.hook_map = {'EOB': 'ENDBURST'}
def connect(self): def connect(self):
"""Initializes a connection to a server.""" """Initializes a connection to a server."""
ts = self.irc.start_ts ts = self.irc.start_ts
@ -44,17 +46,12 @@ class HybridProtocol(TS6BaseProtocol):
# hybrid-specific modes: # hybrid-specific modes:
'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C', 'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C',
'regmoderated': 'M', 'operonly': 'O', 'regonly': 'R', 'regmoderated': 'M', 'operonly': 'O', 'regonly': 'R',
'sslonly': 'S', 'banexception': 'e', 'sslonly': 'S', 'banexception': 'e', 'paranoia': 'p',
# # cannot handle? 'registered': 'r', 'inviteexempt': 'I',
# 'paranoia': 'p', 'registered': 'r', 'inviteexempt': 'I',
# Now, map all the ABCD type modes: # Now, map all the ABCD type modes:
'*A': 'beI', '*B': 'k', '*C': 'l', '*D': 'cimnprstCMORS' '*A': 'beI', '*B': 'k', '*C': 'l', '*D': 'cimnprstCMORS'
} }
if self.irc.serverdata.get('use_halfop'):
cmodes['halfop'] = 'h'
self.irc.prefixmodes['h'] = '%'
self.irc.cmodes.update(cmodes) self.irc.cmodes.update(cmodes)
# Same thing with umodes: # Same thing with umodes:
@ -63,14 +60,12 @@ class HybridProtocol(TS6BaseProtocol):
umodes = { umodes = {
'oper': 'o', 'invisible': 'i', 'wallops': 'w', 'chary_locops': 'l', 'oper': 'o', 'invisible': 'i', 'wallops': 'w', 'chary_locops': 'l',
'cloak': 'x', 'hidechans': 'p', 'regdeaf': 'R', 'deaf': 'D', 'cloak': 'x', 'hidechans': 'p', 'regdeaf': 'R', 'deaf': 'D',
'callerid': 'g', 'callerid': 'g', 'showadmin': 'a', 'softcallerid': 'G', 'hideops': 'H',
# # can't handle? 'webirc': 'W', 'client_connections': 'c', 'bad_client_connections': 'u',
# 'webirc': 'W', 'client_connections': 'c', 'bad_client_connections': 'u', 'rejected_clients': 'j', 'skill_notices': 'k', 'fullauthblock': 'f',
# 'rejected_clients': 'j', 'skill_notices': 'k', 'fullauthblock': 'f', 'remote_client_connections': 'F', 'admin_requests': 'y', 'debug': 'd',
# 'remote_client_connections': 'F', 'admin_requests': 'y', 'debug': 'd', 'nickchange_notices': 'n', 'hideidle': 'q', 'registered': 'r',
# 'nickchange_notices': 'n', 'hideidle': 'q', 'registered': 'r', 'smessages': 's', 'ssl': 'S', 'sjoins': 'e', 'botfloods': 'b',
# 'smessages': 's', 'ssl': 'S', 'sjoins': 'e', 'botfloods': 'b',
# 'showadmin': 'a', 'softcallerid': 'G', 'hideops': 'H',
# Now, map all the ABCD type modes: # Now, map all the ABCD type modes:
'*A': '', '*B': '', '*C': '', '*D': 'oiwlxpRDg' '*A': '', '*B': '', '*C': '', '*D': 'oiwlxpRDg'
} }
@ -102,6 +97,9 @@ class HybridProtocol(TS6BaseProtocol):
f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"], f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"],
self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']))
f(':%s EOB' % (self.irc.sid,))
print('SENT DSID')
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(), def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None, server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None,
manipulatable=False): manipulatable=False):
@ -130,21 +128,6 @@ class HybridProtocol(TS6BaseProtocol):
"* :{realname}".format(ts=ts, host=host, "* :{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid, nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=ip, realname=realname)) modes=raw_modes, ip=ip, realname=realname))
# self._send(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
# "{realhost} * :{realname}".format(ts=ts, host=host,
# nick=nick, ident=ident, uid=uid,
# modes=raw_modes, ip=ip, realname=realname,
# realhost=realhost))
# # <- :001 UID GL 0 1441306929 gl localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
# self._send(server, "UID {nick} 0 {ts} {ident} {realhost} {uid} 0 {modes} "
# "{host} * {ip} :{realname}".format(ts=ts, host=host,
# nick=nick, ident=ident, uid=uid,
# modes=raw_modes, realname=realname,
# realhost=realhost, ip=encoded_ip))
# # Force the virtual hostname to show correctly by running SETHOST on
# # the user. Otherwise, Unreal will show the real host of the person
# # instead, which is probably not what we want.
# self.updateClient(uid, 'HOST', host)
return u return u
def updateClient(self, numeric, field, text): def updateClient(self, numeric, field, text):
@ -211,6 +194,7 @@ class HybridProtocol(TS6BaseProtocol):
command = args[0] command = args[0]
args = args[1:] args = args[1:]
try: try:
command = self.hook_map.get(command.upper(), command).lower()
func = getattr(self, 'handle_'+command.lower()) func = getattr(self, 'handle_'+command.lower())
except AttributeError: # unhandled command except AttributeError: # unhandled command
# self._send(self.irc.sid, 'ERROR', 'Unknown Command') # self._send(self.irc.sid, 'ERROR', 'Unknown Command')
@ -265,10 +249,6 @@ class HybridProtocol(TS6BaseProtocol):
# when we get our uplink's SERVER command. # when we get our uplink's SERVER command.
self.irc.send('SVINFO 6 6 0 :%s' % int(time.time())) self.irc.send('SVINFO 6 6 0 :%s' % int(time.time()))
def handle_svinfo(self, numeric, command, args):
# TODO: do things here?
pass
def handle_uid(self, numeric, command, args): def handle_uid(self, numeric, command, args):
"""Handles incoming UID commands (user introduction).""" """Handles incoming UID commands (user introduction)."""
# <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname # <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname
@ -352,14 +332,13 @@ class HybridProtocol(TS6BaseProtocol):
destination = self.irc.sid destination = self.irc.sid
if utils.isInternalServer(self.irc, destination): if utils.isInternalServer(self.irc, destination):
self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source)) self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source))
if not self.eob:
self._send(destination, 'EOB')
def handle_eob(self, source, command, args): # empty handlers
"""Handles incoming EOB commands.""" # TODO: there's a better way to do this
self.irc.callHooks([source, 'ENDBURST', { def handle_svinfo(self, numeric, command, args):
'ts': int(time.time()), pass
}])
def handle_endburst(self, numeric, command, args):
pass
Class = HybridProtocol Class = HybridProtocol