]> jfr.im git - z_archive/pyp10.git/commitdiff
Moved creation of pseudo-clients
authorJohn Runyon <redacted>
Sat, 17 Aug 2013 16:53:10 +0000 (11:53 -0500)
committerJohn Runyon <redacted>
Sat, 17 Aug 2013 16:53:10 +0000 (11:53 -0500)
modules/q.py
pyp10.py

index 6d353f36e95a945f909c5da668c40e022e05f77c..85c5b94b68a6f17c3eff28745f4e639cce83945d 100644 (file)
@@ -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)
index 2235f14d876735e37c941e6f6e88e258c2daada8..51ed06ffad0183ba13a842d1da4ce39c0284c500 100755 (executable)
--- 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()