From 1680c6d262eb0525c1af95195b5b79839a5e2ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 22 May 2012 23:20:07 +0000 Subject: Added Omegle protocol. git-svn-id: http://svn.miranda-ng.org/main/trunk@136 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Omegle/connection.cpp | 179 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 protocols/Omegle/connection.cpp (limited to 'protocols/Omegle/connection.cpp') diff --git a/protocols/Omegle/connection.cpp b/protocols/Omegle/connection.cpp new file mode 100644 index 0000000000..f5c3b9d6b6 --- /dev/null +++ b/protocols/Omegle/connection.cpp @@ -0,0 +1,179 @@ +/* + +Omegle plugin for Miranda Instant Messenger +_____________________________________________ + +Copyright © 2011-12 Robert Pösel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#include "common.h" + +void OmegleProto::SignOn(void*) +{ + SYSTEMTIME t; + GetLocalTime( &t ); + Log("[%d.%d.%d] Using Omegle Protocol %s", t.wDay, t.wMonth, t.wYear, __VERSION_STRING); + + ScopedLock s(signon_lock_); + + int old_status = m_iStatus; + m_iStatus = m_iDesiredStatus; + ProtoBroadcastAck(m_szModuleName,0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus); + + setDword( "LogonTS", (DWORD)time(NULL) ); + ClearChat(); + OnJoinChat(0,false); + + //ToggleStatusMenuItems(true); +} + +void OmegleProto::SignOff(void*) +{ + ScopedLock s(signon_lock_); + + int old_status = m_iStatus; + m_iStatus = ID_STATUS_OFFLINE; + + Netlib_Shutdown(facy.hEventsConnection); + + OnLeaveChat(NULL, NULL); + + deleteSetting( "LogonTS" ); + + ProtoBroadcastAck(m_szModuleName,0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus); + + //SetAllContactStatuses( ID_STATUS_OFFLINE ); + //ToggleStatusMenuItems(false); + + if (facy.hEventsConnection) + Netlib_CloseHandle(facy.hEventsConnection); + facy.hEventsConnection = NULL; +} + +void OmegleProto::StopChat(bool disconnect) +{ + if (facy.state_ == STATE_WAITING) { + UpdateChat(NULL, TranslateT("Connecting canceled."), false); + } else if (facy.state_ == STATE_ACTIVE || facy.state_ == STATE_SPY) { + bool spy = facy.state_ == STATE_SPY; + + if (disconnect) + { + facy.state_ = STATE_DISCONNECTING; + UpdateChat(NULL, TranslateT("Disconnecting..."), true); + + if (facy.stop()) + LOG("***** Disconnected from stranger %s", facy.chat_id_.c_str()); + else + LOG("***** Error in disconnecting from stranger %s", facy.chat_id_.c_str()); + } + + if (spy) { + DeleteChatContact(TranslateT("Stranger 1")); + DeleteChatContact(TranslateT("Stranger 2")); + } else { + DeleteChatContact(TranslateT("Stranger")); + } + + SetTopic(); // reset topic content + } + else + { // disconnecting or inactive + return; + } + + facy.state_ = STATE_INACTIVE; + facy.chat_id_ = ""; +} + +void OmegleProto::NewChat() +{ + if (facy.state_ == STATE_WAITING) + { + UpdateChat(NULL, TranslateT("We are already waiting for new stranger..."), false); + return; + } + else if (facy.state_ == STATE_ACTIVE || facy.state_ == STATE_SPY) + { + UpdateChat(NULL, TranslateT("Disconnecting..."), true); + + if (facy.stop()) + LOG("***** Disconnected from stranger %s", facy.chat_id_.c_str()); + else + LOG("***** Error in disconnecting from stranger %s", facy.chat_id_.c_str()); + + if (facy.state_ == STATE_SPY) { + DeleteChatContact(TranslateT("Stranger 1")); + DeleteChatContact(TranslateT("Stranger 2")); + } else { + DeleteChatContact(TranslateT("Stranger")); + } + + SetTopic(); // reset topic content + + ClearChat(); + + UpdateChat(NULL, TranslateT("Connecting..."), true); + + facy.state_ = STATE_WAITING; + + if (facy.start()) + { + UpdateChat(NULL, TranslateT("Waiting for Stranger..."), true); + LOG("***** Waiting for stranger %s", facy.chat_id_.c_str()); + } + } + else if (facy.state_ == STATE_DISCONNECTING) + { + //UpdateChat(NULL, TranslateT("We are disconnecting now, wait..."), false); + return; + } + else + { + ClearChat(); + UpdateChat(NULL, TranslateT("Connecting..."), true); + + facy.state_ = STATE_WAITING; + + if (facy.start()) + { + UpdateChat(NULL, TranslateT("Waiting for Stranger..."), true); + LOG("***** Waiting for stranger %s", facy.chat_id_.c_str()); + + ForkThread( &OmegleProto::EventsLoop, this ); + } + } + +} + +void OmegleProto::EventsLoop(void *) +{ + ScopedLock s(events_loop_lock_); + + time_t tim = ::time(NULL); + LOG( ">>>>> Entering Omegle::EventsLoop[%d]", tim ); + + while ( facy.events() ) + { + if ( facy.state_ == STATE_INACTIVE || facy.state_ == STATE_DISCONNECTING || !isOnline() ) + break; + LOG( "***** OmegleProto::EventsLoop[%d] refreshing...", tim ); + } + + ResetEvent(events_loop_lock_); + LOG( "<<<<< Exiting OmegleProto::EventsLoop[%d]", tim ); +} -- cgit v1.2.3