14 'address': '127.0.0.1',
17 'password': 'password',
18 'vhost': '', #bind to this ip - empty string '' for auto-select
20 autoload
= ['q', 'do']
22 b64
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]"
30 self
.lastnum
= None # last numeric used, as [int,int,int]
31 self
.nicks
= {} # 'nick': Pseudo-object
32 self
.nums
= {} # 'num': Pseudo-object
33 self
.data
= "" # receive buffer
39 self
.sock
= socket
.socket()
40 self
.sock
.bind((config
.uplink
['vhost'], 0))
41 self
.sock
.connect((config
.uplink
['address'], config
.uplink
['port']))
43 self
._transmit
("PASS %s" % (config
.uplink
['password']))
44 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}
)
45 def send(self
, line
, source
=None, **kwargs
):
47 source
= config
.numeric
48 self
._transmit
(source
+" "+(line
% kwargs
))
49 def _transmit(self
, line
):
51 self
.sock
.sendall(line
+"\r\n")
53 self
.data
+= self
.sock
.recv(4096)
54 while "\n" in self
.data
:
55 pieces
= self
.data
.split("\n", 1)
56 line
= pieces
[0].strip()
64 if self
.bursting
and self
.bursted
>= modcount
:
66 keepgoing
= self
._receive
()
68 def _process(self
, line
):
70 if words
[1] == "G" or words
[1] == "PING":
71 self
.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']}
)
72 elif words
[1] == "EB":
74 elif words
[1] == "P" or words
[1] == "PRIVMSG":
77 extra
= ' '.join(words
[3:])
81 tonick
= target
.split('@', 1)
82 self
.nicks
[tonick
].gotmsg(extra
, source
, target
)
88 self
.nums
[target
].gotmsg(extra
, source
, target
)
90 if self
.lastnum
is None:
91 self
.lastnum
= [0,0,0]
93 self
.lastnum
= [i
+1 for i
in self
.lastnum
]
95 num
+= b64
[self
.lastnum
[2]]
96 num
+= b64
[self
.lastnum
[1]]
97 num
+= b64
[self
.lastnum
[0]]
100 def makenick(self
, obj
, nick
, ident
, realname
):
101 newnum
= self
._newnum
()
102 self
.send("N %(nick)s 1 %(time)s %(ident)s %(host)s +doknXr pyp10 DAqAAB %(num)s :%(name)s", nick
=nick
, ident
=ident
, name
=realname
, time
=time
.time(), host
=config
.name
, num
=newnum
)
103 self
.nums
[newnum
] = obj
104 self
.nicks
[nick
] = obj
106 def join(self
, chan
, source
, op
=False):
108 # if chan not in self.burstchans:
109 # self.burstchans[chan] = {'ops':[], 'regs':[]}
112 # self.burstchans[chan]['ops'].append(source)
114 # self.burtschans[chan]['regs'].append(source)
115 # else: # not bursting
116 self
.send("J %(chan)s %(time)s", source
, chan
=chan
, time
=time
.time()+3600)
118 self
.send("OM %(chan)s +nto %(num)s", source
, chan
=chan
, num
=source
)
119 def endburst(self
, module
):
121 print module
.num
, self
.bursted
, modcount
122 def _burstisdone(self
):
123 self
.bursting
= False
124 for chname
, chan
in self
.burstchans
.iteritems():
127 if len(chan
['ops']) != 0:
128 chan
['ops'][0] += ':o'
129 users
.extend(chan
['ops'])
131 mems
= ','.join(users
)
132 self
.send("B %(chan)s 780000001 +nt %(members)s", chan
=chname
, members
=mems
)
136 class Account(object):
139 class Client(object):
144 for modu
in config
.autoload
:
145 modules
[modu
] = (__import__('modules.'+str(modu
), globals(), locals(), ['Pseudo'], 0)).Pseudo(uplink
)