#include "Mra.h" #include "MraChat.h" #include "proto.h" //static COLORREF crCols[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; static LPWSTR lpwszStatuses[] = { L"Owners", L"Inviter", L"Visitors" }; #define MRA_CHAT_STATUS_OWNER 0 #define MRA_CHAT_STATUS_INVITER 1 #define MRA_CHAT_STATUS_VISITOR 2 void MraChatSendPrivateMessage (LPWSTR lpwszEMail); void CMraProto::MraChatDllError() { MessageBoxW(NULL, TranslateW(L"CHAT plugin is required for conferences. Install it before chatting"), m_tszUserName, (MB_OK|MB_ICONWARNING)); } BOOL CMraProto::MraChatRegister() { if ( !ServiceExists(MS_GC_REGISTER)) return FALSE; GCREGISTER gcr = {0}; gcr.cbSize = sizeof(GCREGISTER); gcr.dwFlags = GC_UNICODE; gcr.iMaxText = MRA_MAXLENOFMESSAGE; gcr.nColors = 0; gcr.ptszModuleDispName = m_tszUserName; gcr.pszModule = m_szModuleName; CallServiceSync(MS_GC_REGISTER, NULL, (LPARAM)&gcr); HookEvent(ME_GC_EVENT, &CMraProto::MraChatGcEventHook); return TRUE; } INT_PTR CMraProto::MraChatSessionNew(HANDLE hContact) { INT_PTR iRet = 1; if (bChatExists) if (hContact) { GCSESSION gcw = {0}; WCHAR wszEMail[MAX_EMAIL_LEN] = {0}; gcw.cbSize = sizeof(GCSESSION); gcw.iType = GCW_CHATROOM; gcw.pszModule = m_szModuleName; gcw.ptszName = GetContactNameW(hContact); gcw.ptszID = (LPWSTR)wszEMail; gcw.ptszStatusbarText = L"status bar"; gcw.dwFlags = GC_UNICODE; gcw.dwItemData = (DWORD)hContact; mraGetStaticStringW(hContact, "e-mail", wszEMail, SIZEOF(wszEMail), NULL); iRet = CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw); if (iRet == 0) { CHAR szEMail[MAX_EMAIL_LEN] = {0}; size_t dwEMailSize; GCDEST gcd = {0}; GCEVENT gce = {0}; gcd.pszModule = m_szModuleName; gcd.ptszID = (LPWSTR)wszEMail; gcd.iType = GC_EVENT_ADDGROUP; gce.cbSize = sizeof(GCEVENT); gce.pDest = &gcd; gce.dwFlags = GC_UNICODE; for (size_t i = 0;ipDest->pszModule, m_szModuleName)) { switch (gch->pDest->iType) { case GC_USER_MESSAGE: if (gch->ptszText && lstrlen(gch->ptszText)) { BOOL bSlowSend; CHAR szEMail[MAX_EMAIL_LEN] = {0}; DWORD dwFlags = 0; size_t dwEMailSize, dwMessageSize; INT_PTR iSendRet; HANDLE hContact; //rtrim(gch->ptszText); //TCHAR* buf = NEWTSTR_ALLOCA(gch->ptszText); //UnEscapeChatTags( buf ); dwMessageSize = lstrlenW(gch->ptszText); dwEMailSize = (WideCharToMultiByte(MRA_CODE_PAGE, 0, gch->pDest->ptszID, -1, szEMail, SIZEOF(szEMail), NULL, NULL)-1); hContact = MraHContactFromEmail(szEMail, dwEMailSize, FALSE, TRUE, NULL); bSlowSend = mraGetByte(NULL, "SlowSend", MRA_DEFAULT_SLOW_SEND); if (mraGetByte(NULL, "RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE) && (MraContactCapabilitiesGet(hContact)&FEATURE_FLAG_RTF_MESSAGE)) { dwFlags |= MESSAGE_FLAG_RTF; } iSendRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEMail, dwEMailSize, gch->ptszText, dwMessageSize, NULL, 0); if (bSlowSend == FALSE) { ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iSendRet, (LPARAM)NULL, 0); } MraChatSessionEventSendByHandle(hContact, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, NULL, 0, NULL, gch->ptszText, 0, (DWORD)_time32(NULL)); } break; case GC_USER_PRIVMESS: MraChatSendPrivateMessage(gch->ptszUID); break; case GC_USER_LOGMENU: //sttLogListHook( this, item, gch ); break; case GC_USER_NICKLISTMENU: //sttNickListHook( this, item, gch ); break; case GC_USER_CHANMGR: //int iqId = SerialNext(); //IqAdd( iqId, IQ_PROC_NONE, &CJabberProto::OnIqResultGetMuc ); //m_ThreadInfo->send( XmlNodeIq( _T("get"), iqId, item->jid ) << XQUERY( xmlnsOwner )); break; } } } return(iRet); } void CMraProto::MraChatSendPrivateMessage(LPWSTR lpwszEMail) { BOOL bAdded; HANDLE hContact; CHAR szEMail[MAX_EMAIL_LEN] = {0}; size_t dwEMailSize; dwEMailSize = (WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszEMail, -1, szEMail, SIZEOF(szEMail), NULL, NULL)-1); hContact = MraHContactFromEmail(szEMail, dwEMailSize, TRUE, TRUE, &bAdded); if (bAdded) DBWriteContactSettingByte(hContact, "CList", "Hidden", 1); CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, IGNOREEVENT_ALL); CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0); }