CChatItem* CChatSelector::StartSession(CUpDownClient* client, bool show) { ::SetFocus(m_hwndMessageBox); if (GetTabByClient(client) != 0xFFFF){ 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 += 20; chatitem->log->Create(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL | ES_MULTILINE | ES_READONLY, 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(); CTime theTime = CTime::GetCurrentTime(); CString sessions = GetResString(IDS_CHAT_START) + client->GetUserName() + CString(_T(" - ")) + theTime.Format(_T("%c")) + _T("\n"); chatitem->log->AppendKeyWord(sessions, RGB(255,0,0)); 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; 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::EndSession(CUpDownClient* client) { int iCurSel; if (client) iCurSel = GetTabByClient(client); else iCurSel = GetCurSel(); if (iCurSel == -1) return; TCITEM item; item.mask = TCIF_PARAM; if (!GetItem(iCurSel, &item) || item.lParam == 0) return; CChatItem* ci = (CChatItem*)item.lParam; ci->client->SetChatState(MS_NONE); ci->client->SetChatCaptchaState(CA_NONE); DeleteItem(iCurSel); delete ci; int iTabItems = GetItemCount(); if (iTabItems > 0){ // select next tab if (iCurSel == CB_ERR) iCurSel = 0; else if (iCurSel >= iTabItems) iCurSel = iTabItems - 1; (void)SetCurSel(iCurSel); // returns CB_ERR if error or no prev. selection(!) iCurSel = GetCurSel(); // get the real current selection if (iCurSel == CB_ERR) // if still error iCurSel = SetCurSel(0); ShowChat(); } }
void CChatSelector::EndSession(CUpDownClient* client, bool bForceFocus /* true */) { if (!g_App.m_pMDlg->IsRunning()) return; int iCurSel; if (client != NULL) iCurSel = GetTabByClient(client); else iCurSel = GetCurSel(); if (iCurSel == -1) return; TCITEM tcitem; tcitem.mask = TCIF_PARAM; if (!GetItem(iCurSel, &tcitem) || tcitem.lParam == 0) return; CChatItem *pChatItem = (CChatItem*)tcitem.lParam; pChatItem->m_pClient->SetChatState(MS_NONE); DeleteItem(iCurSel); delete pChatItem; int iTabItems = GetItemCount(); if (iTabItems > 0) { // Select next tab if (iCurSel >= iTabItems) iCurSel = iTabItems - 1; SetCurSel(iCurSel); // Returns CB_ERR if error or no prev. selection(!) iCurSel = GetCurSel(); // get the real current selection if (iCurSel == CB_ERR) // if still error iCurSel = SetCurSel(0); if (bForceFocus) ShowChat(); } }
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; } }
CChatItem* CChatSelector::StartSession(CUpDownClient* pClient, bool bForceFocus /* true */) { if (pClient == NULL || !g_App.m_pMDlg->IsRunning()) return NULL; EMULE_TRY if (GetTabByClient(pClient) != (uint16)-1) { SetCurSel(GetTabByClient(pClient)); if (bForceFocus) ShowChat(); return NULL; } CChatItem *pChatItem = new CChatItem(); CRect rcRect; pChatItem->m_pClient = pClient; pChatItem->m_pLog = new CHTRichEditCtrl; GetClientRect(&rcRect); AdjustRect(false, rcRect); rcRect.left += 3; rcRect.top += 4; rcRect.right -= 3; rcRect.bottom -= 3; if (GetItemCount() == 0) rcRect.top += 20; pChatItem->m_pLog->Create(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL, rcRect, this, (UINT)-1); pChatItem->m_pLog->ModifyStyleEx(0, WS_EX_STATICEDGE, SWP_FRAMECHANGED); pChatItem->m_pLog->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(3, 3)); pChatItem->m_pLog->SetFont(&g_App.m_pMDlg->m_fontDefault); pChatItem->m_pLog->m_dwFlags |= HTC_ISWORDWRAP; pChatItem->m_pLog->SetTargetDevice(NULL, 0); COleDateTime timelog(COleDateTime::GetCurrentTime()); CString strName = pClient->GetUserName(), strCountry, strTemp; if (g_App.m_pIP2Country->IsIP2Country()) strCountry.Format(_T(" (%s)"), pClient->GetCountryName()); strTemp.Format(_T("*** %s: %s (%s: %s:%u%s) - %s\n"), GetResString(IDS_CHAT_START), strName, GetResString(IDS_IP), pClient->GetFullIP(), pClient->GetUserPort(), strCountry, timelog.Format(_T("%c"))); pChatItem->m_pLog->AppendText(strTemp, RGB(255, 0, 0)); pClient->SetChatState(MS_CHATTING); if (pClient->IsFriend()) pClient->m_pFriend->m_dwLastChatted = time(NULL); if (strName.GetLength() > 30) { strName.Truncate(30); strName += _T("..."); } else if (strName.IsEmpty()) strName.Format(_T("[%s]"), GetResString(IDS_UNKNOWN)); TCITEM tcitem; tcitem.mask = TCIF_PARAM | TCIF_TEXT | TCIF_IMAGE; tcitem.lParam = (LPARAM)pChatItem; tcitem.pszText = (TCHAR*)strName.GetString(); tcitem.iImage = 0; int iResult = InsertItem(GetItemCount(), &tcitem); g_App.m_pMDlg->m_wndChat.m_ctlCloseButton.EnableWindow(true); g_App.m_pMDlg->m_wndChat.m_ctlSendButton.EnableWindow(true); if (iResult != -1 && IsWindowVisible()) { SetCurSel(iResult); pChatItem->m_pLog->SetTitle(pClient->GetUserName()); if (bForceFocus) ShowChat(); } return pChatItem; EMULE_CATCH return NULL; }
void CChatSelector::ProcessMessage(CUpDownClient* pSender, const CString &strIncomingMessage) { CString strMessage = strIncomingMessage; int iCurPos = 0; strMessage.MakeLower(); // Ban spammers if ( g_App.m_pPrefs->IsCounterMeasures() && ( strMessage.Find(_T("di-emule")) >= 0 || strMessage.Find(_T("emule fx")) >= 0 || strMessage.Find(_T("zambor")) >= 0 || strMessage.Find(_T("fastest emule ever")) >= 0 || strMessage.Find(_T("robot from riaa")) >= 0 || strMessage.Find(_T("ketamine")) >= 0 || strMessage.Find(_T("http://www.chez.com/theworld/")) >= 0 || strMessage.Find(_T("http://fullspeed.to/mison")) >= 0 ) ) { AddDebugLogLine(RGB_LOG_DIMMED_TXT _T("Anti-leechermods: Client %s has been banned because of spamming"), pSender->GetClientNameWithSoftware()); pSender->Ban(BAN_CLIENT_SPAMMING); return; } CString strResToken, strFilter = g_App.m_pPrefs->GetMessageFilter(); strFilter.MakeLower(); for (;;) { strResToken = strFilter.Tokenize(_T("|"), iCurPos); if (strResToken.IsEmpty()) break; if (strMessage.Find(strResToken) >= 0) { AddDebugLogLine(RGB_LOG_DIMMED_TXT _T("Filtered message '%s' from client %s"), strIncomingMessage, pSender->GetClientNameWithSoftware()); return; } } CChatItem *pChatItem = GetItemByClient(pSender); bool bIsNewChatWindow = false; if (pChatItem == NULL) { if (GetItemCount() >= 50) { AddDebugLogLine(RGB_LOG_WARNING_TXT _T("Instant Messaging: Messages limit reached")); return; } if (g_App.m_pPrefs->GetAcceptMessagesFrom() == 4) //no messages return; if ((g_App.m_pPrefs->GetAcceptMessagesFrom() == 2) && !pSender->IsFriend()) //only friends return; if ((g_App.m_pPrefs->GetAcceptMessagesFrom() == 3) && !pSender->IsFriend()) //log non friends { AddLogLine(false, GetResString(IDS_IM_MSGFROMCHAT) + _T(" %s: %s"), pSender->GetUserName(), strIncomingMessage); pSender->SetChatState(MS_NONE); return; } pChatItem = StartSession(pSender); if (pChatItem == NULL) return; bIsNewChatWindow = true; } COleDateTime timelog(COleDateTime::GetCurrentTime()); strMessage.Format(_T("%s (%s): "), pSender->GetUserName(), timelog.Format(_T("%c"))); pChatItem->m_pLog->AppendText(strMessage, RGB(50, 200, 250)); pChatItem->m_pLog->AppendText(strIncomingMessage + _T('\n')); if (g_App.m_pPrefs->GetAwayState()) { if ((::GetTickCount() - pChatItem->m_pClient->GetAwayMessageResendCount()) > 3000) { //send again only if 3 secs from last away message SendAwayMessage(pChatItem); pChatItem->m_pClient->SetAwayMessageResendCount(::GetTickCount()); } } if ((iCurPos = GetTabByClient(pSender)) != GetCurSel()) SetItemState(iCurPos, TCIS_HIGHLIGHTED, TCIS_HIGHLIGHTED); if (!g_App.m_pPrefs->GetAwayState()) { BOOL bVisible = ::IsWindowVisible(::GetParent(m_hWnd)); // Show statusbar indicator if Messages window isn't active or our application isn't topmost one if (!bVisible || (g_App.m_pMDlg->m_hWnd != ::GetForegroundWindow())) { pChatItem->m_bNotify = true; // Send Notification is required if ( ( g_App.m_pPrefs->GetUseChatNotifier() && (bIsNewChatWindow || g_App.m_pPrefs->GetNotifierPopsEveryChatMsg()) ) ) { strMessage.Format(_T("%s %s:'%s'\n"), GetResString(IDS_TBN_NEWCHATMSG), pSender->GetUserName(), strIncomingMessage); g_App.m_pMDlg->SendMail(strMessage, true, g_App.m_pPrefs->IsSMTPInfoEnabled()); g_App.m_pMDlg->ShowNotifier(strMessage, TBN_CHAT, false, true); } } } }