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[]"
25 def __init__(self
, num
, nick
, hostmask
, modes
, account
):
28 self
.hostmask
= hostmask
30 self
.account
= account
37 if self
.account
is not None:
47 self
.lastnum
= None # last numeric used, as [int,int,int]
48 self
.nicks
= {} # 'nick': Pseudo-object
49 self
.nums
= {} # 'num': Pseudo-objecta
50 self
.users
= {} # 'num': User-objects
51 self
.data
= "" # receive buffer
57 self
.sock
= socket
.socket()
58 self
.sock
.bind((config
.uplink
['vhost'], 0))
59 self
.sock
.connect((config
.uplink
['address'], config
.uplink
['port']))
61 self
._transmit
("PASS %s" % (config
.uplink
['password']))
62 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}
)
63 def send(self
, line
, source
=None, **kwargs
):
65 source
= config
.numeric
66 self
._transmit
(source
+" "+(line
% kwargs
))
67 def _transmit(self
, line
):
69 self
.sock
.sendall(line
+"\r\n")
71 self
.data
+= self
.sock
.recv(4096)
72 while "\n" in self
.data
:
73 pieces
= self
.data
.split("\n", 1)
74 line
= pieces
[0].strip()
82 if self
.bursting
and self
.bursted
>= modcount
:
84 keepgoing
= self
._receive
()
86 def _process(self
, line
):
88 extrapos
= line
.find(' :')
89 extra
= line
[extrapos
+2:]
90 line
= line
[0:extrapos
]
98 # words = ['ABACB', 'P', '#p10']; extra = 'Hi there!'
99 if words
[1] == "G" or words
[1] == "PING":
100 self
.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']}
)
101 elif words
[1] == "EB":
103 elif words
[1] == "P" or words
[1] == "PRIVMSG":
107 extra
= ' '.join(words
[3:])
109 tonick
= target
.split('@', 1)
110 self
.nicks
[tonick
].gotmsg(extra
, source
, target
)
116 self
.nums
[target
].gotmsg(extra
, source
, target
)
117 elif words
[1] == "N" or words
[1] == "NICK":
119 hostmask
= words
[5]+"@"+words
[6]
120 if words
[7][0] == '+':
122 if 'r' in modes
and 'h' in modes
:
123 rpos
= modes
.find('r')
124 hpos
= modes
.find('h')
134 print repr((num
, nick
, hostmask
, modes
, account
, extra
))
135 self
.users
[num
] = User(num
, nick
, hostmask
, modes
, account
)
136 def _newnum(self
): #FIXME increment only one value, not all!
137 if self
.lastnum
is None:
138 self
.lastnum
= [0,0,0]
140 self
.lastnum
= [i
+1 for i
in self
.lastnum
]
142 num
+= b64
[self
.lastnum
[2]]
143 num
+= b64
[self
.lastnum
[1]]
144 num
+= b64
[self
.lastnum
[0]]
147 def makenick(self
, obj
, nick
, ident
, realname
):
148 newnum
= self
._newnum
()
149 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
)
150 self
.nums
[newnum
] = obj
151 self
.nicks
[nick
] = obj
153 def getuser(self
, num
):
154 return self
.users
[num
]
155 def join(self
, chan
, source
, op
=False):
157 # if chan not in self.burstchans:
158 # self.burstchans[chan] = {'ops':[], 'regs':[]}
161 # self.burstchans[chan]['ops'].append(source)
163 # self.burtschans[chan]['regs'].append(source)
164 # else: # not bursting
165 self
.send("J %(chan)s %(time)s", source
, chan
=chan
, time
=time
.time()+3600)
167 self
.send("OM %(chan)s +nto %(num)s", source
, chan
=chan
, num
=source
)
168 def endburst(self
, module
):
170 print module
.num
, self
.bursted
, modcount
171 def _burstisdone(self
):
172 self
.bursting
= False
173 for chname
, chan
in self
.burstchans
.iteritems():
176 if len(chan
['ops']) != 0:
177 chan
['ops'][0] += ':o'
178 users
.extend(chan
['ops'])
180 mems
= ','.join(users
)
181 self
.send("B %(chan)s 780000001 +nt %(members)s", chan
=chname
, members
=mems
)
185 class Account(object):
188 class Client(object):
193 for modu
in config
.autoload
:
194 modules
[modu
] = (__import__('modules.'+str(modu
), globals(), locals(), ['Pseudo'], 0)).Pseudo(uplink
)