summaryrefslogtreecommitdiff
path: root/protocols/Omegle/src/chat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Omegle/src/chat.cpp')
-rw-r--r--protocols/Omegle/src/chat.cpp244
1 files changed, 103 insertions, 141 deletions
diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp
index a65ac5b839..ad42a0601f 100644
--- a/protocols/Omegle/src/chat.cpp
+++ b/protocols/Omegle/src/chat.cpp
@@ -21,11 +21,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+const wchar_t msgChatModes[] =
+LPGENW("There are three different modes of chatting:\
+\n1) Standard mode\t - You chat with random stranger privately\
+\n2) Question mode\t - You ask two strangers a question and see how they discuss it (you can't join their conversation, only watch)\
+\n3) Spy mode\t - You and stranger got a question to discuss from third stranger (he can't join your conversation, only watch)\
+\n\nSend '/commands' for available commands.");
+
+const wchar_t msgChatCommands[] =
+LPGENW("You can use different commands:\
+\n/help\t - show info about chat modes\
+\n/new\t - start standard mode\
+\n/ask <question> - start question mode with your question\
+\n/ask\t - start question mode with your last asked question\
+\n/spy\t - start spy mode\
+\n/quit\t - disconnect from stranger or stop connecting\
+\n/asl\t - send your predefined ASL message\
+\n\nNote: You can reconnect to different stranger without disconnecting from current one.");
+
void OmegleProto::UpdateChat(const wchar_t *name, const wchar_t *message, bool addtolog)
{
+ if (message == nullptr)
+ return;
+
// replace % to %% to not interfere with chat color codes
- std::wstring smessage = message;
- utils::text::treplace_all(&smessage, L"%", L"%%");
+ CMStringW smessage(message);
+ smessage.Replace(L"%", L"%%");
GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE };
gce.time = ::time(0);
@@ -53,137 +74,106 @@ int OmegleProto::OnChatEvent(WPARAM, LPARAM lParam)
if (mir_strcmp(hook->pszModule, m_szModuleName))
return 0;
- switch (hook->iType)
- {
+ switch (hook->iType) {
case GC_USER_MESSAGE:
- {
- std::string text = mir_u2a_cp(hook->ptszText, CP_UTF8);
+ {
+ std::string text = mir_u2a_cp(hook->ptszText, CP_UTF8);
- // replace %% back to %, because chat automatically does this to sent messages
- utils::text::replace_all(&text, "%%", "%");
+ // replace %% back to %, because chat automatically does this to sent messages
+ utils::text::replace_all(&text, "%%", "%");
- if (text.empty())
- break;
+ if (text.empty())
+ break;
- if (text.substr(0, 1) == "/")
- { // Process commands
+ if (text.substr(0, 1) == "/") { // Process commands
- std::string command = "";
- std::string params = "";
+ std::string command = "";
+ std::string params = "";
- std::string::size_type pos = 0;
- if ((pos = text.find(" ")) != std::string::npos) {
- command = text.substr(1, pos - 1);
- params = text.substr(pos + 1);
- }
- else {
- command = text.substr(1);
- }
+ std::string::size_type pos = 0;
+ if ((pos = text.find(" ")) != std::string::npos) {
+ command = text.substr(1, pos - 1);
+ params = text.substr(pos + 1);
+ }
+ else command = text.substr(1);
- if (!mir_strcmpi(command.c_str(), "new"))
- {
- facy.spy_mode_ = false;
- facy.question_.clear();
+ if (!mir_strcmpi(command.c_str(), "new")) {
+ facy.spy_mode_ = false;
+ facy.question_.clear();
- ForkThread(&OmegleProto::NewChatWorker, nullptr);
- break;
- }
- else if (!mir_strcmpi(command.c_str(), "quit"))
- {
- ForkThread(&OmegleProto::StopChatWorker, nullptr);
- break;
- }
- else if (!mir_strcmpi(command.c_str(), "spy"))
- {
- facy.spy_mode_ = true;
- facy.question_.clear();
+ ForkThread(&OmegleProto::NewChatWorker, nullptr);
+ break;
+ }
+ else if (!mir_strcmpi(command.c_str(), "quit")) {
+ ForkThread(&OmegleProto::StopChatWorker, nullptr);
+ break;
+ }
+ else if (!mir_strcmpi(command.c_str(), "spy")) {
+ facy.spy_mode_ = true;
+ facy.question_.clear();
- ForkThread(&OmegleProto::NewChatWorker, nullptr);
- break;
- }
- else if (!mir_strcmpi(command.c_str(), "ask"))
- {
- if (params.empty()) {
- // Load last question
- DBVARIANT dbv;
- if (!getU8String(OMEGLE_KEY_LAST_QUESTION, &dbv)) {
- params = dbv.pszVal;
- db_free(&dbv);
+ ForkThread(&OmegleProto::NewChatWorker, nullptr);
+ break;
+ }
+ else if (!mir_strcmpi(command.c_str(), "ask")) {
+ if (params.empty()) {
+ // Load last question
+ DBVARIANT dbv;
+ if (!getU8String(OMEGLE_KEY_LAST_QUESTION, &dbv)) {
+ params = dbv.pszVal;
+ db_free(&dbv);
+ }
+
+ if (params.empty()) {
+ UpdateChat(nullptr, TranslateT("Last question is empty."), false);
+ break;
+ }
+ }
+ else {
+ // Save actual question as last question
+ if (params.length() >= OMEGLE_QUESTION_MIN_LENGTH)
+ setU8String(OMEGLE_KEY_LAST_QUESTION, params.c_str());
}
- if (params.empty()) {
- UpdateChat(nullptr, TranslateT("Last question is empty."), false);
+ if (params.length() < OMEGLE_QUESTION_MIN_LENGTH) {
+ UpdateChat(nullptr, TranslateT("Your question is too short."), false);
break;
}
- }
- else {
- // Save actual question as last question
- if (params.length() >= OMEGLE_QUESTION_MIN_LENGTH)
- {
- setU8String(OMEGLE_KEY_LAST_QUESTION, params.c_str());
- }
- }
- if (params.length() < OMEGLE_QUESTION_MIN_LENGTH)
- {
- UpdateChat(nullptr, TranslateT("Your question is too short."), false);
+ facy.spy_mode_ = true;
+ facy.question_ = params;
+ ForkThread(&OmegleProto::NewChatWorker, nullptr);
break;
}
+ else if (!mir_strcmpi(command.c_str(), "asl")) {
+ DBVARIANT dbv;
+ if (!getU8String(OMEGLE_KEY_ASL, &dbv)) {
+ text = dbv.pszVal;
+ db_free(&dbv);
- facy.spy_mode_ = true;
- facy.question_ = params;
- ForkThread(&OmegleProto::NewChatWorker, nullptr);
- break;
- }
- else if (!mir_strcmpi(command.c_str(), "asl"))
- {
- DBVARIANT dbv;
- if (!getU8String(OMEGLE_KEY_ASL, &dbv)) {
- text = dbv.pszVal;
- db_free(&dbv);
-
- SendChatMessage(text);
+ SendChatMessage(text);
+ }
+ else {
+ UpdateChat(nullptr, TranslateT("Your '/asl' setting is empty."), false);
+ break;
+ }
+ }
+ else if (!mir_strcmpi(command.c_str(), "help")) {
+ UpdateChat(nullptr, TranslateW(msgChatModes), false);
+ }
+ else if (!mir_strcmpi(command.c_str(), "commands")) {
+ UpdateChat(nullptr, TranslateW(msgChatCommands), false);
+ break;
}
else {
- UpdateChat(nullptr, TranslateT("Your '/asl' setting is empty."), false);
+ UpdateChat(nullptr, TranslateT("Unknown command. Send '/commands' for list."), false);
break;
}
}
- else if (!mir_strcmpi(command.c_str(), "help"))
- {
- UpdateChat(nullptr, TranslateT("There are three different modes of chatting:\
-\n1) Standard mode\t - You chat with random stranger privately\
-\n2) Question mode\t - You ask two strangers a question and see how they discuss it (you can't join their conversation, only watch)\
-\n3) Spy mode\t - You and stranger got a question to discuss from third stranger (he can't join your conversation, only watch)\
-\n\nSend '/commands' for available commands."), false);
- }
- else if (!mir_strcmpi(command.c_str(), "commands"))
- {
- UpdateChat(nullptr, TranslateT("You can use different commands:\
-\n/help\t - show info about chat modes\
-\n/new\t - start standard mode\
-\n/ask <question> - start question mode with your question\
-\n/ask\t - start question mode with your last asked question\
-\n/spy\t - start spy mode\
-\n/quit\t - disconnect from stranger or stop connecting\
-\n/asl\t - send your predefined ASL message\
-\n\nNote: You can reconnect to different stranger without disconnecting from current one."), false);
- break;
- }
- else
- {
- UpdateChat(nullptr, TranslateT("Unknown command. Send '/commands' for list."), false);
- break;
- }
-
+ else // Outgoing message
+ SendChatMessage(text);
}
- else {
- // Outgoing message
- SendChatMessage(text);
- }
-
break;
- }
case GC_USER_LEAVE:
case GC_SESSION_TERMINATE:
@@ -210,20 +200,9 @@ void OmegleProto::SendChatMessage(std::string text)
case STATE_SPY:
UpdateChat(nullptr, TranslateT("You can't send messages in question mode."), false);
break;
-
- //case STATE_WAITING:
- //case STATE_DISCONNECTING:
- default:
- break;
}
}
-/*void OmegleProto::SendChatEvent(int type)
-{
-GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL };
-Chat_Event(WINDOW_CLEARLOG,&gce);
-}*/
-
void OmegleProto::AddChatContact(const wchar_t *name)
{
GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN };
@@ -303,8 +282,7 @@ INT_PTR OmegleProto::OnLeaveChat(WPARAM, LPARAM)
void OmegleProto::SetChatStatus(int status)
{
- if (status == ID_STATUS_ONLINE)
- {
+ if (status == ID_STATUS_ONLINE) {
// Load actual name from database
facy.nick_ = db_get_wsa(NULL, m_szModuleName, OMEGLE_KEY_NAME);
if (facy.nick_ == NULL) {
@@ -318,10 +296,7 @@ void OmegleProto::SetChatStatus(int status)
Chat_Control(m_szModuleName, m_tszUserName, SESSION_INITDONE);
Chat_Control(m_szModuleName, m_tszUserName, SESSION_ONLINE);
}
- else
- {
- Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE);
- }
+ else Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE);
}
void OmegleProto::ClearChat()
@@ -333,24 +308,11 @@ void OmegleProto::ClearChat()
// TODO: Could this be done better?
MCONTACT OmegleProto::GetChatHandle()
{
- /*if (facy.chatHandle_ != NULL)
- return facy.chatHandle_;
-
- for (auto &hContact : AccContacts()) {
- if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0) {
- ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomId");
- if (id != NULL && !mir_strcmp(id, m_szModuleName))
- return hContact;
- }
- }
-
- return NULL;*/
-
- GC_INFO gci = { 0 };
+ GC_INFO gci = {};
gci.Flags = GCF_HCONTACT;
gci.pszModule = m_szModuleName;
gci.pszID = m_tszUserName;
Chat_GetInfo(&gci);
return gci.hContact;
-} \ No newline at end of file
+}