#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 int MraChatGcEventHook (WPARAM, LPARAM lParam); void MraChatSendPrivateMessage (LPWSTR lpwszEMail); void MraChatDllError() { MessageBoxW(NULL,TranslateW(L"CHAT plugin is required for conferences. Install it before chatting"),PROTOCOL_DISPLAY_NAMEW,(MB_OK|MB_ICONWARNING)); } BOOL MraChatRegister() { BOOL bRet=FALSE; if (ServiceExists(MS_GC_REGISTER)) { GCREGISTER gcr={0}; gcr.cbSize=sizeof(GCREGISTER); gcr.dwFlags=GC_UNICODE; gcr.iMaxText=MRA_MAXLENOFMESSAGE; gcr.nColors=0; //gcr.pColors=&crCols[0]; gcr.pszModuleDispName=PROTOCOL_DISPLAY_NAMEA; gcr.pszModule=PROTOCOL_NAMEA; CallServiceSync(MS_GC_REGISTER,NULL,(LPARAM)&gcr); HookEvent(ME_GC_EVENT,&MraChatGcEventHook); //HookEvent(ME_GC_BUILDMENU, &CJabberProto::JabberGcMenuHook ); bRet=TRUE; }else{ MraChatDllError(); } return(bRet); } INT_PTR MraChatSessionNew(HANDLE hContact) { INT_PTR iRet=1; if (masMraSettings.bChatExist) if (hContact) { GCSESSION gcw={0}; WCHAR wszEMail[MAX_EMAIL_LEN]={0}; gcw.cbSize=sizeof(GCSESSION); gcw.iType=GCW_CHATROOM; gcw.pszModule=PROTOCOL_NAMEA; gcw.ptszName=GetContactNameW(hContact); gcw.ptszID=(LPWSTR)wszEMail; gcw.ptszStatusbarText=L"status bar"; gcw.dwFlags=GC_UNICODE; gcw.dwItemData=(DWORD)hContact; DB_Mra_GetStaticStringW(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=PROTOCOL_NAMEA; 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,-1,PROTOCOL_NAMEA,PROTOCOL_NAME_LEN)==CSTR_EQUAL) { 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=DB_Mra_GetByte(NULL,"SlowSend",MRA_DEFAULT_SLOW_SEND); if (DB_Mra_GetByte(NULL,"RTFSendEnable",MRA_DEFAULT_RTF_SEND_ENABLE) && (MraContactCapabilitiesGet(hContact)&FEATURE_FLAG_RTF_MESSAGE)) { dwFlags|=MESSAGE_FLAG_RTF; } iSendRet=MraSendCommand_MessageW(bSlowSend,hContact,ACKTYPE_MESSAGE,dwFlags,szEMail,dwEMailSize,gch->ptszText,dwMessageSize,NULL,0); if (bSlowSend==FALSE) { ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,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 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); }