1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#!/usr/bin/python
# -*- vim: encoding: utf-8 -*-
import struct
import sys
import thread
from twisted.words.protocols import oscar
from twisted.internet import reactor, protocol
from twisted.internet.protocol import ClientFactory
from twisted.python import log
from omegle import OmegleChat
ICQ_UIN = '446323989'
ICQ_PASSWORD = 'gagaga'
class OmegleICQChat(OmegleChat):
def __init__(self,icqconn,user):
self.user = user
self.icqconn = icqconn
OmegleChat.__init__(self,name="omegle")
def on_message(self,message):
self.send_icqconn( message )
def send_icqconn(self,message):
#send stopped typing snac
reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x00")
#von omegle kommt immer unicode, icq sendet latin1/iso-8859-1
message = unicode(message)
message = message.encode("iso-8859-1","replace")
print "Omegle->%s: %s" % (self.user,message.__repr__())
reactor.callFromThread(self.icqconn.sendMessage, self.user, message )
def on_typing(self):
"""
0x02 begin
0x01 idle
0x00 finish
"""
reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x02")
print "Omegle->%s: (begin typing)" % self.user
def on_stopped_typing(self):
reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x01")
def on_connect(self):
print "Omegle->%s: (connected)" % self.user
self.send_icqconn( "== Sup dawg, we heard u need some stranger in ur chatroom, so we put a Stranger in ur chatroom so u can chat with him while u chat with others (until you type %disconnect% anywhere) ==" )
def on_disconnect(self):
print "Omegle->%s: (disconnected)" % self.user
self.send_icqconn( "==Stranger Disconnected ==" )
CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3'
# [4, 20, 0, 0, 2854066430L, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02']
class OmegleICQ( oscar.BOSConnection ):
capabilities = [oscar.CAP_CHAT,CAP_TYPING]
def __init__(self,s,p,**kwargs):
oscar.BOSConnection.__init__(self, s, p,**kwargs)
"""
handles typing SNAC
"""
def oscar_04_14(self,snac):
data = snac[3]
if len(data) == len("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02"):
user = data[11:20]
state = data[20:22]
if not self.omegleConns.has_key(user):
self.omegleConns[user] = OmegleICQChat(self,user)
if state == "\x00\x00": #finish
try:
self.omegleConns[user].stopped_typing()
except:
pass
elif state == "\x00\x01": #idle
pass
elif state == "\x00\x02": #begin
try:
self.omegleConns[user].typing()
except:
pass
else:
print "Unknown state in typing snac\nuser %s\ndata %s\nsnac %s\nstate %X%X" % (user,data,snac,state[0],sate[1])
else:
print "komisches tpying snac"
def initDone( self ):
self.requestSelfInfo()
self.requestSSI().addCallback(self.gotBuddyList)
self.omegleConns = {}
def shutdown( self ):
for conn in self.omegleConns:
if conn.is_connected:
conn.disconnect()
def updateBuddy(self, user):
print "icq: Update buddy %s" % user
def gotBuddyList( self, buddylist ):
self.activateSSI()
self.setProfile("Forget ICQ, MSN, Yahoo and the other shitty protocols! Use XMPP/Jabber!")
self.setIdleTime( 0 )
self.clientReady()
for user in buddylist[0][0].users:
print "icq: Authorize %s" % user.name
self.sendAuthorizationResponse(user.name, True, '')
def receiveMessage( self, user, multiparts, flags ):
print "icq: receiveMessage(%s,%s,%s)" % (user,multiparts,flags)
if "auto" in flags:
print "'auto' message, abort"
return
# because i cant receive the "budded added signal" i auth on every message
self.sendAuthorizationResponse(user.name, True, '')
if not self.omegleConns.has_key(user.name):
self.omegleConns[user.name] = OmegleICQChat(self,user.name)
try:
message = None
if len(multiparts[0]) == 2:
if multiparts[0][1] == "unicode":
message = unicode(multiparts[0][0])
else:
try:
message = multiparts[0][0].decode(multiparts[0][1])
except Exception,e:
self.sendMessage(user.name,str(e))
else:
try:
message = multiparts[0][0].decode('latin1')
except Exception,e:
self.sendMessage(user.name,str(e))
#filter qip \x00CHAR\x00CHAR - qip sucks at unicode?
message_neu = filter(lambda x: x!=u"\x00", message)
if len(message_neu) != len(message):
client_sucks = True
message = message_neu
if not self.omegleConns[user.name].is_connected:
if u"%connect%" in message:
self.omegleConns[user.name].start()
self.sendMessage(user.name, "Please stand by.....")
if client_sucks:
self.sendMessage(user.name, "Hey, dein ICQ-Client sendet scheiss")
else:
print "Not connected"
# self.sendMessage(user.name, "Not connected, type >connect<")
elif self.omegleConns[user.name].is_connected and u"%disconnect%" in message:
try:
self.omegleConns[user.name].disconnect()
except Exception,e:
self.sendMessage(user.name, str(e))
self.sendMessage(user.name, "Disconnecting")
elif self.omegleConns[user.name].is_connected and not self.omegleConns[user.name].is_confirmed:
self.sendMessage(user.name, "Wait for connection confirm from omegle")
else:
try:
print "%s->Omegle: %s" % (user.name, message.__repr__())
self.omegleConns[user.name].send(message)
except Exception,e:
print "icq(%s): Error %s" % (user.name,e)
self.sendMessage(user.name,str(e))
except Exception,e:
print "error: %s %s -> %s" % (user,multiparts,e)
def chatReceiveMessage( self, chat, user, message ):
self.receiveMessage( self, user, message, 0 )
def sendAuthorizationResponse(self, uin, success, responsString):
packet = struct.pack("b", len(uin)) + uin
if success:
packet += struct.pack("b", 1)
else:
packet += struct.pack("b", 0)
packet += struct.pack(">H", len(responsString)) + responsString
self.sendSNACnr(0x13, 0x1a, packet)
class Authenticator( oscar.OscarAuthenticator ):
BOSClass = OmegleICQ
def connectionLost(self,reason):
oscar.OscarAuthenticator.connectionLost(self,reason)
self.factory.connectionLost(reason)
class OscarFactory(ClientFactory):
OAClass=Authenticator
def __init__(self, uid, password,icq=1):
self.uid = uid
self.password = password
self.icq = icq
def buildProtocol(self, addr):
p = OscarFactory.OAClass(self.uid, self.password,icq=self.icq)
p.factory = self
return p
def startedConnecting(self, connector):
print 'Started to connect to oscar'
def connectionLost(self,reason):
print "CONECTION LOST - start njew factory"
reactor.callLater(4.0, reactor.connectTCP,
'login.icq.com', 5238, self)
# reactor.connectTCP('login.icq.com', 5238, OscarFactory(self.uin, self.password,icq=1))
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.INFO)
log.startLogging(sys.stdout)
reactor.connectTCP('login.icq.com', 5238,
OscarFactory(uin,password,icq=1))
reactor.run()
|