diff options
author | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-29 14:50:52 +0000 |
---|---|---|
committer | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-29 14:50:52 +0000 |
commit | 325c4f6b2ddc158ffec3d40a832b6535fd0e2f43 (patch) | |
tree | eec71e21af8712615659abdae05573aeb9e547b6 | |
parent | 6af8df1a442dcac86ba8d21c23c01677fb81121e (diff) | |
download | omegle-325c4f6b2ddc158ffec3d40a832b6535fd0e2f43.tar.gz omegle-325c4f6b2ddc158ffec3d40a832b6535fd0e2f43.zip |
better proxy
git-svn-id: http://xapek.org/svn/common/omegle@1039 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
-rw-r--r-- | proxy.py | 70 |
1 files changed, 39 insertions, 31 deletions
@@ -1,19 +1,26 @@ +import sys +import time +import logging +from threading import Event from omegle import OmegleChat -import sys, logging, time -from threading import Lock + + +__all__ = ['OmegleProxyChat'] + + colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33, - "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, - "black":39} #33[%colors%m -# color_string = "\033[%dm\033[1m" % colors[color] + "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, "black":39} + -chat_lock = Lock() class OmegleProxyChat(OmegleChat): - def __init__(self,name,color=0): + def __init__(self,disconnect_event,name,color=0): OmegleChat.__init__(self,name="(" + name + ")") + self.disconnect_event = disconnect_event self.name = name self.color = color + def c(self,str,bold=False): if bold: return "\033[1m\033[%sm%s\033[0m\033[0m" %(self.color, str) @@ -27,48 +34,49 @@ class OmegleProxyChat(OmegleChat): print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, message),bold=True) if self.partner.is_connected: self.partner.send(message) + def on_connect(self): print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name)) + def on_typing(self): print self.c("%s [EVT] %s is typing" % (time.strftime("%H:%M:%S"), self.name)) if self.partner.is_connected: self.partner.typing() + def on_stopped_typing(self): print self.c("%s [EVT] %s stopped typing" % (time.strftime("%H:%M:%S"), self.name)) if self.partner.is_connected: self.partner.stopped_typing() + def on_disconnect(self): print self.c("%s [EVT] %s disconnect" % (time.strftime("%H:%M:%S"), self.name)) if self.partner.is_connected: self.partner.disconnect() - chat_lock.release() - + self.disconnect_event.set() -logging.basicConfig(level=logging.DEBUG) -print "press ctrl-c to abort" -A=OmegleProxyChat("A",colors['red']) -B=OmegleProxyChat("B",colors['blue']) -A.set_partner(B) -B.set_partner(A) - -A.start() -B.start() - -chat_lock.acquire() -try: - while True: - if chat_lock.acquire(0): - print "One part disconnected, exiting" - break - else: - time.sleep(0.5) -except KeyboardInterrupt: - print "CTRL-C pressed, exiting" +if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) + print "press ctrl-c to abort" + + event = Event() + A=OmegleProxyChat(event,"A",colors['red']) + B=OmegleProxyChat(event,"B",colors['blue']) -if A.is_connected: A.disconnect() -if B.is_connected: B.disconnect() + A.set_partner(B) + B.set_partner(A) + A.start() + B.start() + try: + while True: + if disconnect_event.wait(0.5): + print "One part disconnected, exiting" + break + except KeyboardInterrupt: + print "CTRL-C pressed, exiting" + if A.is_connected: A.disconnect() + if B.is_connected: B.disconnect() |