]> jfr.im git - z_archive/pyp10.git/blob - pyp10.py
Madness. Starting code
[z_archive/pyp10.git] / pyp10.py
1 #!/usr/bin/python
2
3 import socket, time
4
5
6 uplink = None
7 modules = {}
8 modules['q'] = (__import__('modules.q', globals(), locals(), ['Pseudo'], 0)).Pseudo()
9
10 class config(object):
11 name = 'services.p10'
12 numeric = ']S'
13 uplink = {
14 'address': '127.0.0.1',
15 'port': 4400,
16 'name': 'test.p10',
17 'password': 'password',
18 'vhost': '', #bind to this ip - empty string '' for auto-select
19 }
20
21 def process(line):
22 words = line.split()
23 print "process"
24 if words[1] == "G" or words[1] == "PING":
25 print "PING!", line
26 uplink.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']})
27
28 class Server(object):
29 def __init__(self, numeric, name):
30 self.isuplink = False
31 self.numeric = numeric
32 self.name = name
33 self.clients = {}
34 def send(self, line, source=None, **kwargs):
35 if source is None:
36 source = config.numeric
37 uplink._transmit(source+" "+(line % kwargs))
38
39 class Uplink(Server):
40 def __init__(self, *args, **kwargs):
41 global uplink
42 super(Uplink, self).__init__(*args, **kwargs)
43 uplink = self
44 self.isuplink = True
45 self.data = ""
46
47 self.sock = socket.socket()
48 self.sock.bind((config.uplink['vhost'], 0))
49 self.sock.connect((config.uplink['address'], config.uplink['port']))
50
51 self._transmit("PASS %s" % (config.uplink['password']))
52 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})
53 self.send("EB")
54 self._transmit("]S G services.p10 test.p10") #todo
55 #def send - inherited
56 def _transmit(self, line):
57 print ">", line
58 self.sock.sendall(line+"\r\n")
59 def _receive(self):
60 self.data += self.sock.recv(4096)
61 while "\n" in self.data:
62 pieces = self.data.split("\n", 1)
63 line = pieces[0].strip()
64 print "<", line
65 process(line)
66 self.data = pieces[1]
67 return True
68 def loop(self):
69 keepgoing = True
70 while keepgoing:
71 keepgoing = self._receive()
72
73
74 class Account(object):
75 pass
76
77 class Client(object):
78 pass
79
80 uplink = Uplink(-1, '')
81 uplink.loop()