summaryrefslogtreecommitdiff
path: root/omegle.py
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-28 16:09:02 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-28 16:09:02 +0000
commited0a2c0c359e5ed87c378f533519d269022462ce (patch)
tree78bcf58fbb209a94a10a322c48c1c68ed17ec4db /omegle.py
parenteaa9de7bcc3dda4b86592bdab23ac5e97f71173e (diff)
downloadomegle-ed0a2c0c359e5ed87c378f533519d269022462ce.tar.gz
omegle-ed0a2c0c359e5ed87c378f533519d269022462ce.zip
blah
git-svn-id: http://xapek.org/svn/common/omegle@1032 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'omegle.py')
-rw-r--r--omegle.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/omegle.py b/omegle.py
index fd62d45..8c5fdce 100644
--- a/omegle.py
+++ b/omegle.py
@@ -62,9 +62,13 @@ class OmegleChat(RESTClient):
self.timer = Timer(self.events, poll_interval)
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__ + name)
- self.is_connected = False
+ self.is_confirmed = False #after getting a connection confirm
+ self.is_connected = False #after having self.id
def start(self):
+ if self.is_connected:
+ self.logger.error("Already connected")
+ raise Exception("Already connected")
resp = RESTClient.request(self, "POST", "/start", {})
body=resp.read()
id=body.split("\"")
@@ -73,22 +77,26 @@ class OmegleChat(RESTClient):
self.logger.info("Connected id=%s" % self.id)
#Poll events
self.timer.start()
+ self.is_connected = True
else:
self.logger.error("Bad response: %s" % body)
raise Exception("Bad response: %s" % body)
def disconnect(self):
- self.logger.debug("/disconnect")
+ self.logger.debug("disconnect()")
self.is_connected = False
self.timer.stop()
- r = RESTClient.request(self,"POST", "/disconnect", urllib.urlencode({'id': self.id}))
- body = r.read()
- self.logger.debug("/disconnect sent. Read: %s" % body)
- if body == "win":
- pass
- else:
- self.is_connected = True #disconnect failed
- raise Exception("/disconnect; Bad response: %s" % body)
+ if self.is_confirmed:
+ self.is_confirmed = False
+ r = RESTClient.request(self,"POST", "/disconnect", urllib.urlencode({'id': self.id}))
+ body = r.read()
+ self.logger.debug("/disconnect sent. Read: %s" % body)
+ if body == "win":
+ pass
+ else:
+ self.is_connected = True #disconnect failed
+ self.is_confirmed = True
+ raise Exception("/disconnect; Bad response: %s" % body)
def events(self):
"""does use its own "HTTPConnection" because its called async from a thread"""
@@ -141,9 +149,10 @@ class OmegleChat(RESTClient):
elif data[0] == "gotMessage" and data.__len__() == 2:
self.on_message(data[1])
elif data[0] == "connected":
- self.is_connected = True
+ self.is_confirmed = True
self.on_connect()
elif data[0] == "strangerDisconnected":
+ self.is_confirmed = False
self.is_connected = False
self.timer.stop()
self.on_disconnect()