3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-11 20:52:42 +01:00

protocols: send outgoing hop counts for servers and users

Closes #527.
This commit is contained in:
James Lu 2017-09-23 22:36:16 -07:00
parent 663bfe462c
commit ad32ce20da
8 changed files with 37 additions and 30 deletions

View File

@ -115,10 +115,11 @@ class HybridProtocol(TS6Protocol):
realhost=realhost, ip=ip, manipulatable=manipulatable)
self.apply_modes(uid, modes)
self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
self._send_with_prefix(server, "UID {nick} {hopcount} {ts} {modes} {ident} {host} {ip} {uid} "
"* :{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=ip, realname=realname))
modes=raw_modes, ip=ip, realname=realname,
hopcount=self.servers[server].hopcount))
return u
def update_client(self, target, field, text):

View File

@ -56,17 +56,17 @@ class InspIRCdProtocol(TS6BaseProtocol):
realname = realname or conf.conf['bot']['realname']
realhost = realhost or host
raw_modes = self.join_modes(modes)
u = self.users[uid] = User(self, nick, ts, uid, server, ident=ident, host=host, realname=realname,
u = self.users[uid] = User(self, nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
self.apply_modes(uid, modes)
self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=ip, realname=realname,
realhost=realhost))
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=ip, realname=realname,
realhost=realhost))
if ('o', None) in modes or ('+o', None) in modes:
self._oper_up(uid, opertype)
return u
@ -355,8 +355,9 @@ class InspIRCdProtocol(TS6BaseProtocol):
raise ValueError('Server %r is not a PyLink server!' % uplink)
if not self.is_server_name(name):
raise ValueError('Invalid server name %r' % name)
self._send_with_prefix(uplink, 'SERVER %s * 1 %s :%s' % (name, sid, desc))
self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
self._send_with_prefix(uplink, 'SERVER %s * %s %s :%s' % (name, self.servers[sid].hopcount, sid, desc))
def endburstf():
# Delay ENDBURST by X seconds if requested.

View File

@ -97,7 +97,8 @@ class NgIRCdProtocol(IRCS2SProtocol):
# Grab our server token; this is used instead of server name to denote where the client is.
server_token = server.rsplit('@')[-1]
# <- :ngircd.midnight.local NICK GL 1 ~gl localhost 1 +io :realname
self._send_with_prefix(server, 'NICK %s 1 %s %s %s %s :%s' % (nick, ident, host, server_token, self.join_modes(modes), realname))
self._send_with_prefix(server, 'NICK %s %s %s %s %s %s :%s' % (nick, self.servers[server].hopcount,
ident, host, server_token, self.join_modes(modes), realname))
return userobj
def spawn_server(self, name, sid=None, uplink=None, desc=None, endburst_delay=0):
@ -130,8 +131,8 @@ class NgIRCdProtocol(IRCS2SProtocol):
# We need to store a server token to introduce clients on the right server. Since this is just
# a number, we can simply use the counter in our PSID generator for this.
server_token = sid.rsplit('@')[-1]
self._send_with_prefix(uplink, 'SERVER %s 1 %s :%s' % (name, server_token, desc))
self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
self._send_with_prefix(uplink, 'SERVER %s %s %s :%s' % (name, self.servers[sid].hopcount, server_token, desc))
return sid
def away(self, source, text):

View File

@ -319,10 +319,10 @@ class P10Protocol(IRCS2SProtocol):
else:
b64ip = 'AAAAAA'
self._send_with_prefix(server, "N {nick} 1 {ts} {ident} {host} {modes} {ip} {uid} "
":{realname}".format(ts=ts, host=host, nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=b64ip, realname=realname,
realhost=realhost))
self._send_with_prefix(server, "N {nick} {hopcount} {ts} {ident} {host} {modes} {ip} {uid} "
":{realname}".format(ts=ts, host=host, nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=b64ip, realname=realname,
realhost=realhost, hopcount=self.servers[server].hopcount))
return u
def away(self, source, text):
@ -696,10 +696,10 @@ class P10Protocol(IRCS2SProtocol):
if not self.is_server_name(name):
raise ValueError('Invalid server name %r' % name)
self._send_with_prefix(uplink, 'SERVER %s 1 %s %s P10 %s]]] +h6 :%s' % \
(name, self.start_ts, int(time.time()), sid, desc))
self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
self._send_with_prefix(uplink, 'SERVER %s %s %s %s P10 %s]]] +h6 :%s' % \
(name, self.servers[sid].hopcount, self.start_ts, int(time.time()), sid, desc))
return sid
def squit(self, source, target, text='No reason given'):

View File

@ -77,10 +77,11 @@ class RatboxProtocol(TS6Protocol):
self.apply_modes(uid, modes)
self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
self._send_with_prefix(server, "UID {nick} {hopcount} {ts} {modes} {ident} {host} {ip} {uid} "
":{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid,
modes=raw_modes, ip=ip, realname=realname))
modes=raw_modes, ip=ip, realname=realname,
hopcount=self.servers[server].hopcount))
if orig_realhost:
# If real host is specified, send it using ENCAP REALHOST

View File

@ -58,11 +58,11 @@ class TS6Protocol(TS6BaseProtocol):
self.apply_modes(uid, modes)
self.servers[server].users.add(uid)
self._send_with_prefix(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))
self._send_with_prefix(server, "EUID {nick} {hopcount} {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, hopcount=self.servers[server].hopcount))
return u

View File

@ -169,6 +169,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
uplink = uplink or self.sid
name = name.lower()
desc = desc or self.serverdata.get('serverdesc') or conf.conf['bot']['serverdesc']
if sid is None: # No sid given; generate one!
sid = self.sidgen.next_sid()
assert len(sid) == 3, "Incorrect SID length"
@ -181,8 +182,9 @@ class TS6BaseProtocol(IRCS2SProtocol):
raise ValueError('Server %r is not a PyLink server!' % uplink)
if not self.is_server_name(name):
raise ValueError('Invalid server name %r' % name)
self._send_with_prefix(uplink, 'SID %s 1 %s :%s' % (name, sid, desc))
self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
self._send_with_prefix(uplink, 'SID %s %s %s :%s' % (name, self.servers[sid].hopcount, sid, desc))
return sid
def away(self, source, text):

View File

@ -93,11 +93,12 @@ class UnrealProtocol(TS6BaseProtocol):
encoded_ip = encoded_ip.strip().decode()
# <- :001 UID GL 0 1441306929 gl localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
self._send_with_prefix(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))
self._send_with_prefix(server, "UID {nick} {hopcount} {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,
hopcount=self.servers[server].hopcount))
return u