bool CChatSelector::SendMessage(const CString& rstrMessage) { CChatItem* ci = GetCurrentChatItem(); if (!ci) return false; if ((UINT)ci->history.GetCount() == thePrefs.GetMaxChatHistoryLines()) ci->history.RemoveAt(0); ci->history.Add(rstrMessage); ci->history_pos = ci->history.GetCount(); // advance spamfilter stuff ci->client->IncMessagesSent(); ci->client->SetSpammer(false); if (ci->client->GetChatState() == MS_CONNECTING) return false; if (ci->client->GetChatCaptchaState() == CA_CAPTCHARECV) ci->client->SetChatCaptchaState(CA_SOLUTIONSENT); else if (ci->client->GetChatCaptchaState() == CA_SOLUTIONSENT) ASSERT( false ); // we responsed to a captcha but didn't heard from the client afterwards - hopefully its just lag and this message will get through else ci->client->SetChatCaptchaState(CA_ACCEPTING); // there are three cases on connectiing/sending the message: if (ci->client->socket && ci->client->socket->IsConnected()) { // 1.) the client is connected already - this is simple, jsut send it ci->client->SendChatMessage(rstrMessage); if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(thePrefs.GetUserNick(), SENT_TARGET_MSG_COLOR); ci->log->AppendText(_T(": ")); ci->log->AppendText(rstrMessage + _T("\n")); } else if (ci->client->GetFriend() != NULL) { // We are not connected and this client is a friend - friends have additional ways to connect and additional checks // to make sure they are really friends, let the friend class is handling it ci->strMessagePending = rstrMessage; ci->client->SetChatState(MS_CONNECTING); ci->client->GetFriend()->TryToConnect(this); } else { // this is a normal client, who is not connected right now. just try to connect to the given IP, without any // additional checks or searchings. if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(_T("*** ") + GetResString(IDS_CONNECTING), STATUS_MSG_COLOR); ci->strMessagePending = rstrMessage; ci->client->SetChatState(MS_CONNECTING); ci->client->TryToConnect(true); } return true; }
void CChatSelector::ConnectingResult(CUpDownClient* sender, bool success) { CChatItem* ci = GetItemByClient(sender); if (!ci) return; ci->client->SetChatState(MS_CHATTING); if (!success){ if (!ci->strMessagePending.IsEmpty()){ ci->log->AppendKeyWord(_T(" ") + GetResString(IDS_FAILED) + _T("\n"), RGB(255,0,0)); ci->strMessagePending.Empty(); } else{ //==>timestamp in chatwindow [shadow2004] if (thePrefs.GetIRCAddTimestamp()) AddTimeStamp(ci); //<==timestamp in chatwindow [shadow2004] ci->log->AppendKeyWord(GetResString(IDS_CHATDISCONNECTED) + _T("\n"), RGB(255,0,0)); } } else if (!ci->strMessagePending.IsEmpty()){ ci->log->AppendKeyWord(_T(" ok\n"), RGB(255,0,0)); CSafeMemFile data; data.WriteString(ci->strMessagePending, ci->client->GetUnicodeSupport()); Packet* packet = new Packet(&data, OP_EDONKEYPROT, OP_MESSAGE); theStats.AddUpDataOverheadOther(packet->size); ci->client->socket->SendPacket(packet, true, true); //==>timestamp in chatwindow [shadow2004] if (thePrefs.GetIRCAddTimestamp()) AddTimeStamp(ci); //<==timestamp in chatwindow [shadow2004] ci->log->AppendKeyWord(thePrefs.GetUserNick(), RGB(1,180,20)); ci->log->AppendText(_T(": ")); ci->log->AppendText(ci->strMessagePending + _T("\n")); ci->strMessagePending.Empty(); } else{ //==>timestamp in chatwindow [shadow2004] if (thePrefs.GetIRCAddTimestamp()) AddTimeStamp(ci); //==>timestamp in chatwindow [shadow2004] ci->log->AppendKeyWord(_T("*** Connected\n"), RGB(255,0,0)); } }
void CChatSelector::ReportConnectionProgress(CUpDownClient* pClient, CString strProgressDesc, bool bNoTimeStamp) { CChatItem* ci = GetItemByClient(pClient); if (!ci) return; if (thePrefs.GetIRCAddTimeStamp() && !bNoTimeStamp) AddTimeStamp(ci); ci->log->AppendKeyWord(strProgressDesc, STATUS_MSG_COLOR); }
void CChatSelector::ShowCaptchaResult(CUpDownClient* sender, CString strResult) { CChatItem* ci = GetItemByClient(sender); if (ci != NULL) { if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(_T("*** ") + strResult + _T("\n"), STATUS_MSG_COLOR); } }
void CChatSelector::ShowCaptchaRequest(CUpDownClient* sender, HBITMAP bmpCaptcha) { CChatItem* ci = GetItemByClient(sender); if (ci != NULL) { if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(_T("*** ") + GetResString(IDS_CAPTCHAREQUEST), STATUS_MSG_COLOR); ci->log->AddCaptcha(bmpCaptcha); ci->log->AddLine(_T("\n")); } }
void CChatSelector::ConnectingResult(CUpDownClient* sender, bool success) { CChatItem* ci = GetItemByClient(sender); if (!ci) return; ci->client->SetChatState(MS_CHATTING); if (!success){ if (!ci->strMessagePending.IsEmpty()){ ci->log->AppendKeyWord(_T(" ...") + GetResString(IDS_FAILED) + _T("\n"), STATUS_MSG_COLOR); ci->strMessagePending.Empty(); } else{ if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(GetResString(IDS_CHATDISCONNECTED) + _T("\n"), STATUS_MSG_COLOR); } } else if (!ci->strMessagePending.IsEmpty()){ ci->log->AppendKeyWord(_T(" ...") + GetResString(IDS_TREEOPTIONS_OK) + _T("\n"), STATUS_MSG_COLOR); ci->client->SendChatMessage(ci->strMessagePending); if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(thePrefs.GetUserNick(), SENT_TARGET_MSG_COLOR); ci->log->AppendText(_T(": ")); ci->log->AppendText(ci->strMessagePending + _T("\n")); ci->strMessagePending.Empty(); } else{ if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(_T("*** Connected\n"), STATUS_MSG_COLOR); } }
bool CChatSelector::SendMessage(const CString& rstrMessage) { CChatItem* ci = GetCurrentChatItem(); if (!ci) return false; if (ci->history.GetCount() == thePrefs.GetMaxChatHistoryLines()) ci->history.RemoveAt(0); ci->history.Add(rstrMessage); ci->history_pos = ci->history.GetCount(); // advance spamfilter stuff ci->client->IncMessagesSent(); ci->client->SetSpammer(false); if (ci->client->GetChatState() == MS_CONNECTING) return false; //==>timestamp in chatwindow [shadow2004] if (thePrefs.GetIRCAddTimestamp()) AddTimeStamp(ci); //<==timestamp in chatwindow [shadow2004] if (ci->client->socket && ci->client->socket->IsConnected()) { CSafeMemFile data; data.WriteString(rstrMessage, ci->client->GetUnicodeSupport()); Packet* packet = new Packet(&data, OP_EDONKEYPROT, OP_MESSAGE); theStats.AddUpDataOverheadOther(packet->size); ci->client->socket->SendPacket(packet, true, true); ci->log->AppendKeyWord(thePrefs.GetUserNick(), RGB(1,180,20)); ci->log->AppendText(_T(": ")); ci->log->AppendText(rstrMessage + _T("\n")); } else { ci->log->AppendKeyWord(_T("*** ") + GetResString(IDS_CONNECTING), RGB(255,0,0)); ci->strMessagePending = rstrMessage; ci->client->SetChatState(MS_CONNECTING); //==>Fix for closed [cyrex2001] #ifdef FIX_CLOSED ci->client->TryToConnect(true); #else //Fix for closed ci->client->TryToConnect(); #endif //Fix for closed //<==Fix for closed [cyrex2001] } return true; }
void CChatSelector::ProcessMessage(CUpDownClient* sender, const CString& message) { sender->IncMessagesReceived(); CChatItem* ci = GetItemByClient(sender); AddLogLine(true, GetResString(IDS_NEWMSG), sender->GetUserName(), ipstr(sender->GetConnectIP())); bool isNewChatWindow = false; if (!ci) { if ((UINT)GetItemCount() >= thePrefs.GetMsgSessionsMax()) return; ci = StartSession(sender, false); isNewChatWindow = true; } if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(ci); ci->log->AppendKeyWord(sender->GetUserName(), RECV_SOURCE_MSG_COLOR); ci->log->AppendText(_T(": ")); ci->log->AppendText(message + _T("\n")); int iTabItem = GetTabByClient(sender); if (GetCurSel() == iTabItem && GetParent()->IsWindowVisible()) { // chat window is already visible ; } else if (GetCurSel() != iTabItem) { // chat window is already visible, but tab is not selected ci->notify = true; } else { ci->notify = true; if (isNewChatWindow || thePrefs.GetNotifierOnEveryChatMsg()) theApp.emuledlg->ShowNotifier(GetResString(IDS_TBN_NEWCHATMSG) + _T(" ") + CString(sender->GetUserName()) + _T(":'") + message + _T("'\n"), TBN_CHAT); isNewChatWindow = false; } }
CChatItem* CChatSelector::StartSession(CUpDownClient* client, bool show) { if (show) m_pParent->m_wndMessage.SetFocus(); if (GetTabByClient(client) != -1){ if (show){ SetCurSel(GetTabByClient(client)); ShowChat(); } return NULL; } CChatItem* chatitem = new CChatItem(); chatitem->client = client; chatitem->log = new CHTRichEditCtrl; CRect rcChat; GetChatSize(rcChat); if (GetItemCount() == 0) rcChat.top += 19; // add the height of the tab which is not yet there // using ES_NOHIDESEL is actually not needed, but it helps to get around a tricky window update problem! // If that style is not specified there are troubles with right clicking into the control for the very first time!? chatitem->log->Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL, rcChat, this, (UINT)-1); chatitem->log->ModifyStyleEx(0, WS_EX_STATICEDGE, SWP_FRAMECHANGED); chatitem->log->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(3, 3)); chatitem->log->SetEventMask(chatitem->log->GetEventMask() | ENM_LINK); chatitem->log->SetFont(&theApp.m_fontHyperText); chatitem->log->SetProfileSkinKey(_T("Chat")); chatitem->log->ApplySkin(); chatitem->log->EnableSmileys(thePrefs.GetMessageEnableSmileys()); PARAFORMAT pf = {0}; pf.cbSize = sizeof pf; pf.dwMask = PFM_OFFSET; pf.dxOffset = 150; chatitem->log->SetParaFormat(pf); if (thePrefs.GetIRCAddTimeStamp()) AddTimeStamp(chatitem); chatitem->log->AppendKeyWord(GetResString(IDS_CHAT_START) + client->GetUserName() + _T("\n"), STATUS_MSG_COLOR); client->SetChatState(MS_CHATTING); CString name; if (client->GetUserName() != NULL) name = client->GetUserName(); else name.Format(_T("(%s)"), GetResString(IDS_UNKNOWN)); chatitem->log->SetTitle(name); TCITEM newitem; newitem.mask = TCIF_PARAM | TCIF_TEXT | TCIF_IMAGE; newitem.lParam = (LPARAM)chatitem; name.Replace(_T("&"), _T("&&")); newitem.pszText = const_cast<LPTSTR>((LPCTSTR)name); newitem.iImage = 0; int iItemNr = InsertItem(GetItemCount(), &newitem); if (show || IsWindowVisible()){ SetCurSel(iItemNr); ShowChat(); } return chatitem; }
void CChatSelector::ProcessMessage(CUpDownClient* sender, const CString& message) { sender->IncMessagesReceived(); CString strMessage(message); strMessage.MakeLower(); CString resToken; int curPos = 0; resToken = thePrefs.GetMessageFilter().Tokenize(_T("|"), curPos); while (!resToken.IsEmpty()) { resToken.Trim(); if (strMessage.Find(resToken.MakeLower()) > -1) return; resToken = thePrefs.GetMessageFilter().Tokenize(_T("|"), curPos); } CChatItem* ci = GetItemByClient(sender); // advanced spamfilter check if (IsSpam(strMessage, sender)) { if (!sender->IsSpammer()){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("'%s' has been marked as spammer"), sender->GetUserName()); } sender->SetSpammer(true); if (ci) EndSession(sender); return; } bool isNewChatWindow = false; if (!ci) { if (GetItemCount() >= thePrefs.GetMsgSessionsMax()) return; ci = StartSession(sender, false); isNewChatWindow = true; } //==>timestamp in chatwindow [shadow2004] if (thePrefs.GetIRCAddTimestamp()) AddTimeStamp(ci); //<==timestamp in chatwindow [shadow2004] ci->log->AppendKeyWord(sender->GetUserName(), RGB(50,200,250)); ci->log->AppendText(_T(": ")); ci->log->AppendText(message + _T("\n")); int iTabItem = GetTabByClient(sender); if (GetCurSel() == iTabItem && GetParent()->IsWindowVisible()) { // chat window is already visible ; } else if (GetCurSel() != iTabItem) { // chat window is already visible, but tab is not selected ci->notify = true; } else { ci->notify = true; if (isNewChatWindow || thePrefs.GetNotifierPopsEveryChatMsg()) theApp.emuledlg->ShowNotifier(GetResString(IDS_TBN_NEWCHATMSG) + _T(" ") + CString(sender->GetUserName()) + _T(":'") + message + _T("'\n"), TBN_CHAT); isNewChatWindow = false; } }