From: John Runyon Date: Sat, 17 Aug 2013 16:53:10 +0000 (-0500) Subject: Moved creation of pseudo-clients X-Git-Url: https://jfr.im/git/z_archive/pyp10.git/commitdiff_plain/94df133837400b33934136ec7dae0d97578dd0de Moved creation of pseudo-clients --- diff --git a/modules/q.py b/modules/q.py index 6d353f3..85c5b94 100644 --- a/modules/q.py +++ b/modules/q.py @@ -1 +1,7 @@ -class Pseudo(object): pass +class Pseudo(object): + def __init__(self, uplink): + self.uplink = uplink + self.num = self.uplink.makenick(self, 'Q','TheQBot','PyP10 Q') + self.send("J #p10 780000000") + def send(self, line, **kwargs): + self.uplink.send(line, self.num, **kwargs) diff --git a/pyp10.py b/pyp10.py index 2235f14..51ed06f 100755 --- a/pyp10.py +++ b/pyp10.py @@ -5,7 +5,6 @@ import socket, time uplink = None modules = {} -modules['q'] = (__import__('modules.q', globals(), locals(), ['Pseudo'], 0)).Pseudo() class config(object): name = 'services.p10' @@ -17,30 +16,23 @@ class config(object): 'password': 'password', 'vhost': '', #bind to this ip - empty string '' for auto-select } + autoload = ['q'] + +b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]" def process(line): words = line.split() if words[1] == "G" or words[1] == "PING": uplink.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']}) -class Server(object): - def __init__(self, numeric, name): - self.isuplink = False - self.numeric = numeric - self.name = name - self.clients = {} - def send(self, line, source=None, **kwargs): - if source is None: - source = config.numeric - uplink._transmit(source+" "+(line % kwargs)) - -class Uplink(Server): - def __init__(self, *args, **kwargs): +class Uplink(object): + def __init__(self): global uplink - super(Uplink, self).__init__(*args, **kwargs) uplink = self - self.isuplink = True - self.data = "" + + self.lastnum = None # last numeric used, as [int,int,int] + self.nicks = {} # 'nick': Pseudo-object + self.data = "" # receive buffer self.sock = socket.socket() self.sock.bind((config.uplink['vhost'], 0)) @@ -49,8 +41,10 @@ class Uplink(Server): self._transmit("PASS %s" % (config.uplink['password'])) self._transmit("SERVER %(name)s 1 %(time)s %(time)s J10 %(numeric)s]]] +s :PyP10 Services" % {'name': config.name, 'time': time.time(), 'numeric': config.numeric}) self.send("EB") - self.send("N Q 1 %(time)s q %(host)s +oknXr pyp10 DAqAAB ]SAAQ :Hax!", time=time.time(), host=config.name) - self.send("J #p10 780000000", ']SAAQ') + def send(self, line, source=None, **kwargs): + if source is None: + source = config.numeric + self._transmit(source+" "+(line % kwargs)) def _transmit(self, line): print ">", line self.sock.sendall(line+"\r\n") @@ -68,6 +62,23 @@ class Uplink(Server): while keepgoing: keepgoing = self._receive() + def _newnum(self): + if self.lastnum is None: + self.lastnum = [0,0,0] + else: + self.lastnum = [i+1 for i in lastnum] + num = config.numeric + num += b64[self.lastnum[2]] + num += b64[self.lastnum[1]] + num += b64[self.lastnum[0]] + return num + + def makenick(self, obj, nick, ident, realname): + newnum = self._newnum() + self.send("N %(nick)s 1 %(time)s %(ident)s %(host)s +oknXr pyp10 DAqAAB %(num)s :%(name)s", nick=nick, ident=ident, name=realname, time=time.time(), host=config.name, num=newnum) + self.nicks[nick] = obj + return newnum + class Account(object): pass @@ -75,5 +86,9 @@ class Account(object): class Client(object): pass -uplink = Uplink(-1, '') +uplink = Uplink() + +for modu in config.autoload: + modules[modu] = (__import__('modules.'+str(modu), globals(), locals(), ['Pseudo'], 0)).Pseudo(uplink) + uplink.loop()