void FacebookProto::SendChatMsgWorker(void *p) { if (p == NULL) return; send_chat *data = static_cast<send_chat*>(p); std::string err_message; // replace %% back to %, because chat automatically does this to sent messages utils::text::replace_all(&data->msg, "%%", "%"); MCONTACT hContact = ChatIDToHContact(data->chat_id); if (hContact) { ptrA tid_(getStringA(hContact, FACEBOOK_KEY_TID)); std::string tid; if (tid_ != NULL && mir_strcmp(tid_, "null")) { tid = tid_; } else { std::string post_data = "client=mercury"; post_data += "&__user="******"&__dyn=" + facy.__dyn(); post_data += "&__req=" + facy.__req(); post_data += "&fb_dtsg=" + facy.dtsg_; post_data += "&ttstamp=" + facy.ttstamp_; post_data += "&__rev=" + facy.__rev(); post_data += "&threads[thread_ids][0]=" + utils::url::encode(data->chat_id); http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data); // NOTE: Request revised 1.9.2015 tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\""); if (!tid.empty() && tid.compare("null")) setString(hContact, FACEBOOK_KEY_TID, tid.c_str()); debugLogA(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str()); } if (!tid.empty()) { if (facy.send_message(0, hContact, data->msg, &err_message) == SEND_MESSAGE_OK) UpdateChat(data->chat_id.c_str(), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str()); else { ptrA text(mir_utf8encode(err_message.c_str())); UpdateChat(data->chat_id.c_str(), NULL, NULL, text); } } } delete data; }
bool MinecraftDynmapProto::doSendMessage(const std::string &message_text) { handleEntry(__FUNCTION__); JSONNode json(JSON_NODE); json.push_back(JSONNode("name", m_nick.c_str())); json.push_back(JSONNode("message", message_text.c_str())); std::string data = json.write(); http::response resp = sendRequest(MINECRAFTDYNMAP_REQUEST_MESSAGE, &data); if (resp.code == HTTP_CODE_OK) { JSONNode root = JSONNode::parse(resp.data.c_str()); if (root) { const JSONNode &error_ = root["error"]; if (error_) { std::string error = error_.as_string(); if (error == "none") { return handleSuccess(__FUNCTION__); } else if (error == "not-allowed") { UpdateChat(NULL, Translate("Message was not sent. Probably you are sending them too fast or chat is disabled completely.")); } } } } return handleError(__FUNCTION__); }
void TwitterProto::UpdateStatuses(bool pre_read,bool popups) { try { ScopedLock s(twitter_lock_); twitter::status_list updates = twit_.get_statuses(200,since_id_); s.Unlock(); if(!updates.empty()) since_id_ = std::max(since_id_, updates[0].status.id); for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i) { if(!pre_read && in_chat_) UpdateChat(*i); if(i->username == twit_.get_username()) continue; HANDLE hContact = AddToClientList(i->username.c_str(),""); DBEVENTINFO dbei = {sizeof(dbei)}; dbei.pBlob = (BYTE*)(i->status.text.c_str()); dbei.cbBlob = i->status.text.size()+1; dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET; dbei.flags = DBEF_UTF; //dbei.flags = DBEF_READ; dbei.timestamp = static_cast<DWORD>(i->status.time); dbei.szModule = m_szModuleName; CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei); DBWriteContactSettingUTF8String(hContact,"CList","StatusMsg", i->status.text.c_str()); if(!pre_read && popups) ShowContactPopup(hContact,i->status.text); } db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_); LOG("***** Status messages updated"); } catch(const bad_response &) { LOG("***** Bad response from server, signing off"); SetStatus(ID_STATUS_OFFLINE); } catch(const std::exception &e) { ShowPopup( (std::string("While updating status messages, an error occurred: ") +e.what()).c_str() ); LOG("***** Error updating status messages: %s",e.what()); } }
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()) debugLogA("***** Disconnected from stranger %s", facy.chat_id_.c_str()); else debugLogA("***** 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); debugLogA("***** 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); debugLogA("***** Waiting for stranger %s", facy.chat_id_.c_str()); ForkThread(&OmegleProto::EventsLoop, this); } } }
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()) debugLogA("***** Disconnected from stranger %s", facy.chat_id_.c_str()); else debugLogA("***** 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 CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)GetChatHandle(), NULL); } else { // disconnecting or inactive return; } facy.state_ = STATE_INACTIVE; facy.chat_id_.clear(); }
bool MinecraftDynmapProto::doEvents() { handleEntry(__FUNCTION__); // Get update http::response resp = sendRequest(MINECRAFTDYNMAP_REQUEST_EVENTS); if (resp.code != HTTP_CODE_OK) return handleError(__FUNCTION__, "Response is not code 200"); JSONNode root = JSONNode::parse(resp.data.c_str()); if (!root) return handleError(__FUNCTION__, "Invalid JSON response"); const JSONNode ×tamp_ = root["timestamp"]; if (!timestamp_) return handleError(__FUNCTION__, "Received no timestamp node"); m_timestamp = timestamp_.as_string(); const JSONNode &updates_ = root["updates"]; if (!updates_) return handleError(__FUNCTION__, "Received no updates node"); for (auto it = updates_.begin(); it != updates_.end(); ++it) { const JSONNode &type_ = (*it)["type"]; if (type_ && type_.as_string() == "chat") { const JSONNode &time_ = (*it)["timestamp"]; // const JSONNode &source_ = (*it)["source"]; // e.g. "web" const JSONNode &playerName_ = (*it)["playerName"]; const JSONNode &message_ = (*it)["message"]; // TODO: there are also "channel" and "account" elements if (!time_ || !playerName_ || !message_) { debugLog(_T("Error: No player name, time or text for message")); continue; } time_t timestamp = utils::time::from_string(time_.as_string()); std::string name = playerName_.as_string(); std::string message = message_.as_string(); debugLog(_T("Received message: [%d] %s -> %s"), timestamp, name.c_str(), message.c_str()); UpdateChat(name.c_str(), message.c_str(), timestamp); } } return handleSuccess(__FUNCTION__); }
void OmegleProto::SendMsgWorker(void *p) { if (p == NULL) return; ScopedLock s(facy.send_message_lock_); std::string data = *(std::string*)p; delete (std::string*)p; data = utils::text::trim(data); if (facy.state_ == STATE_ACTIVE && data.length() && facy.send_message(data)) { TCHAR *msg = mir_a2t_cp(data.c_str(), CP_UTF8); UpdateChat(facy.nick_, msg); mir_free(msg); } }
void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg) { try { ScopedLock s(twitter_lock_); twitter::status_list updates = twit_.get_statuses(200,since_id_); s.Unlock(); if(!updates.empty()) { since_id_ = std::max(since_id_, updates[0].status.id); } for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i) { if(!pre_read && in_chat_) UpdateChat(*i); if(i->username == twit_.get_username()) continue; HANDLE hContact = AddToClientList(i->username.c_str(),""); UpdateAvatar(hContact,i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here // i think we maybe should just do that DBEF_READ line instead of stopping ALL this code. have to test. if (tweetToMsg) { DBEVENTINFO dbei = {sizeof(dbei)}; dbei.pBlob = (BYTE*)(i->status.text.c_str()); dbei.cbBlob = (int)i->status.text.size()+1; dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET; dbei.flags = DBEF_UTF | DBEF_READ; dbei.timestamp = static_cast<DWORD>(i->status.time); dbei.szModule = m_szModuleName; db_event_add(hContact, &dbei); } db_set_utf(hContact,"CList","StatusMsg",i->status.text.c_str()); if(!pre_read && popups) ShowContactPopup(hContact,i->status.text); } db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_); disconnectionCount = 0; debugLogA( _T("***** Status messages updated")); } catch(const bad_response &) { ++disconnectionCount; debugLogA( _T("***** UpdateStatuses - Bad response from server, this has happened %d time(s)"), disconnectionCount); if (disconnectionCount > 2) { debugLogA( _T("***** UpdateStatuses - Too many bad responses from the server, signing off")); SetStatus(ID_STATUS_OFFLINE); } } catch(const std::exception &e) { ShowPopup( (std::string("While updating status messages, an error occurred: ") +e.what()).c_str()); debugLogA( _T("***** Error updating status messages: %s"), e.what()); } }