From: John Runyon Date: Mon, 12 Aug 2013 06:54:00 +0000 (-0500) Subject: Madness. Starting code X-Git-Url: https://jfr.im/git/z_archive/pyp10.git/commitdiff_plain/5b0ca09795d5f2b48618b1b8650404c38c1000d4 Madness. Starting code --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/modules/q.py b/modules/q.py new file mode 100644 index 0000000..6d353f3 --- /dev/null +++ b/modules/q.py @@ -0,0 +1 @@ +class Pseudo(object): pass diff --git a/pyp10.py b/pyp10.py new file mode 100755 index 0000000..5b328e2 --- /dev/null +++ b/pyp10.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +import socket, time + + +uplink = None +modules = {} +modules['q'] = (__import__('modules.q', globals(), locals(), ['Pseudo'], 0)).Pseudo() + +class config(object): + name = 'services.p10' + numeric = ']S' + uplink = { + 'address': '127.0.0.1', + 'port': 4400, + 'name': 'test.p10', + 'password': 'password', + 'vhost': '', #bind to this ip - empty string '' for auto-select + } + +def process(line): + words = line.split() + print "process" + if words[1] == "G" or words[1] == "PING": + print "PING!", line + 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): + global uplink + super(Uplink, self).__init__(*args, **kwargs) + uplink = self + self.isuplink = True + self.data = "" + + self.sock = socket.socket() + self.sock.bind((config.uplink['vhost'], 0)) + self.sock.connect((config.uplink['address'], config.uplink['port'])) + + 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._transmit("]S G services.p10 test.p10") #todo + #def send - inherited + def _transmit(self, line): + print ">", line + self.sock.sendall(line+"\r\n") + def _receive(self): + self.data += self.sock.recv(4096) + while "\n" in self.data: + pieces = self.data.split("\n", 1) + line = pieces[0].strip() + print "<", line + process(line) + self.data = pieces[1] + return True + def loop(self): + keepgoing = True + while keepgoing: + keepgoing = self._receive() + + +class Account(object): + pass + +class Client(object): + pass + +uplink = Uplink(-1, '') +uplink.loop()