1
2
3
4
5 """ provide partyline functionality .. manage dcc sockets """
6
7
8 __copyright__ = 'this file is in the public domain'
9 __credits__ = 'Aim'
10
11 from gozerbot.generic import rlog, handle_exception
12 from gozerbot.fleet import fleet
13 from gozerbot.thr import start_new_thread
14 import thread, pickle, socket
15
17
18 """ this is the partyline """
19
21
22 self.socks = []
23 self.lock = thread.allocate_lock()
24
26 for i in data['partyline']:
27 bot = fleet.byname(i['botname'])
28 sock = socket.fromfd(i['fileno'], socket.AF_INET, socket.SOCK_STREAM)
29 sock.setblocking(1)
30 nick = i['nick']
31 userhost = i['userhost']
32 channel = i['channel']
33 if not bot:
34 rlog(10, 'partyline', "can't find %s bot in fleet" % i['botname'])
35 continue
36 self.socks.append({'bot': bot, 'sock': sock, 'nick': nick, \
37 'userhost': userhost, 'channel': channel, 'silent': i['silent']})
38 bot._dccresume(sock, nick, userhost, channel)
39
41 result = []
42 for i in self.socks:
43 result.append({'botname': i['bot'].name, 'fileno': \
44 i['sock'].fileno(), 'nick': i['nick'], 'userhost': i['userhost'], \
45 'channel': i['channel'], 'silent': i['silent']})
46 return result
47
48 - def resume(self, sessionfile):
54
55 - def stop(self, bot):
56 """ stop all user on bot """
57 for i in self.socks:
58 if i['bot'] == bot:
59 try:
60 i['sock'].shutdown(2)
61 i['sock'].close()
62 except:
63 pass
64
66 """ stop every users on partyline """
67 for i in self.socks:
68 try:
69 i['sock'].shutdown(2)
70 i['sock'].close()
71 except:
72 pass
73
74 - def loud(self, nick):
75 """ enable broadcasting of txt for nick """
76 for i in self.socks:
77 if i['nick'] == nick:
78 i['silent'] = False
79
81 """ disable broadcasting txt from/to nick """
82 for i in self.socks:
83 if i['nick'] == nick:
84 i['silent'] = True
85
86 - def add_party(self, bot, sock, nick, userhost, channel):
87 ''' add a socket with nick to the list '''
88 for i in self.socks:
89 if i['sock'] == sock:
90 return
91 self.socks.append({'bot': bot, 'sock': sock, 'nick': nick, \
92 'userhost': userhost, 'channel': channel, 'silent': False})
93 rlog(1, 'partyline', 'added user %s on the partyline' % nick)
94
96 ''' remove a socket with nick from the list '''
97 nick = nick.lower()
98 self.lock.acquire()
99 try:
100 for socknr in range(len(self.socks)-1, -1, -1):
101 if self.socks[socknr]['nick'].lower() == nick:
102 del self.socks[socknr]
103 rlog(1, 'partyline', 'removed user %s from the partyline' % nick)
104 finally:
105 self.lock.release()
106
108 ''' list all connected nicks '''
109 result = []
110 for item in self.socks:
111 result.append(item['nick'])
112 return result
113
115 ''' broadcast a message to all ppl on partyline '''
116 for item in self.socks:
117 if not item['silent']:
118 item['sock'].send("%s\n" % txt)
119
121 ''' broadcast a message to all ppl on partyline '''
122 nick = nick.lower()
123 for item in self.socks:
124 if item['nick'] == nick:
125 continue
126 if not item['silent']:
127 item['sock'].send("%s\n" % txt)
128
130 ''' say a message on the partyline to an user '''
131 nickto = nickto.lower()
132 for item in self.socks:
133 if item['nick'].lower() == nickto:
134 if not '\n' in msg:
135 msg += "\n"
136 item['sock'].send("%s" % msg)
137 return
138
140 ''' checks if user an is on the partyline '''
141 nick = nick.lower()
142 for item in self.socks:
143 if item['nick'].lower() == nick:
144 return 1
145 return 0
146
147 partyline = Partyline()
148