From ad621c29997aff0bda961718de44f536d13213cf Mon Sep 17 00:00:00 2001 From: sje Date: Sat, 30 Jun 2007 15:48:03 +0000 Subject: implemented messaging! woohoo! git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@223 4f64403b-2f21-0410-a795-97e2b3489a10 --- MySpace/proto.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 16 deletions(-) (limited to 'MySpace/proto.cpp') diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp index 15bc91f..91fd26a 100644 --- a/MySpace/proto.cpp +++ b/MySpace/proto.cpp @@ -3,7 +3,9 @@ #include "server_con.h" #include "resource.h" -#define MAX_MESSAGE_SIZE 1024 +#define FAILED_MESSAGE_HANDLE 99998 + +int msg_id = 1; int GetCaps(WPARAM wParam,LPARAM lParam) { int ret = 0; @@ -79,19 +81,97 @@ int GetStatus(WPARAM wParam,LPARAM lParam) { return status; } +typedef struct tag_TFakeAckParams +{ + HANDLE hEvent; + HANDLE hContact; + LPARAM lParam; +} TFakeAckParams; + +static DWORD CALLBACK sttFakeAckMessageSuccess( LPVOID param ) +{ + TFakeAckParams *tParam = ( TFakeAckParams* )param; + WaitForSingleObject( tParam->hEvent, INFINITE ); + + Sleep( 100 ); + ProtoBroadcastAck(MODULE, tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, ( HANDLE )tParam->lParam, 0 ); + + CloseHandle( tParam->hEvent ); + delete tParam; + return 0; +} + +static DWORD CALLBACK sttFakeAckMessageFailed( LPVOID param ) +{ + TFakeAckParams *tParam = ( TFakeAckParams* )param; + WaitForSingleObject( tParam->hEvent, INFINITE ); + + Sleep( 100 ); + ProtoBroadcastAck(MODULE, tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)FAILED_MESSAGE_HANDLE, tParam->lParam); + + CloseHandle( tParam->hEvent ); + delete tParam; + return 0; +} + int ProtoSendMessage(WPARAM wParam, LPARAM lParam) { CCSDATA *ccs = (CCSDATA *) lParam; char *message = (char *)ccs->lParam; + char msg_utf[MAX_MESSAGE_SIZE]; + int uid; + + if((uid = DBGetContactSettingDword(ccs->hContact, MODULE, "UID", 0)) == 0 || status == ID_STATUS_OFFLINE) { + HANDLE hEvent; + TFakeAckParams *tfap; + + hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); + + tfap = new TFakeAckParams; + tfap->hContact = ccs->hContact; + tfap->hEvent = hEvent; + tfap->lParam = 0; + + CloseHandle( CreateThread( NULL, 0, sttFakeAckMessageFailed, tfap, 0, 0 )); + SetEvent( hEvent ); + return FAILED_MESSAGE_HANDLE; + } // TODO: process 'message' and/or 'messagew' below if(ccs->wParam & PREF_UNICODE) { wchar_t *messagew = (wchar_t *)&message[strlen(message)+1]; - } else if(ccs->wParam & PREF_UTF) { - // message is utf8 encoded - you can use mir_utf8decode (m_system.h) to make it wide + WideCharToMultiByte(CP_UTF8, 0, messagew, -1, msg_utf, MAX_MESSAGE_SIZE, 0, 0); } else { + //} else if(ccs->wParam & PREF_UTF) { + // message is utf8 encoded - you can use mir_utf8decode (m_system.h) to make it wide + strncpy(msg_utf, message, MAX_MESSAGE_SIZE); } + msg_utf[MAX_MESSAGE_SIZE-1] = 0; + + ClientNetMessage msg; + msg.add_int("bm", 1); + msg.add_int("sesskey", sesskey); + msg.add_int("t", uid); + msg.add_int("f", my_uid); + msg.add_int("cv", CLIENT_VER); + msg.add_string("msg", msg_utf); + SendMessage(msg); + + HANDLE hEvent; + TFakeAckParams *tfap; + + hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); + + int ret = msg_id++; + + tfap = new TFakeAckParams; + tfap->hContact = ccs->hContact; + tfap->hEvent = hEvent; + tfap->lParam = (LPARAM)ret; - return CallService(MS_PROTO_CHAINSEND, wParam, lParam); + CloseHandle( CreateThread( NULL, 0, sttFakeAckMessageSuccess, tfap, 0, 0 )); + SetEvent( hEvent ); + + return ret; } int ProtoSendMessageW(WPARAM wParam, LPARAM lParam) { @@ -102,19 +182,28 @@ int ProtoSendMessageW(WPARAM wParam, LPARAM lParam) { } int ProtoRecvMessage(WPARAM wParam, LPARAM lParam) { - CCSDATA *ccs = (CCSDATA *) lParam; - PROTORECVEVENT *pre = (PROTORECVEVENT *) ccs->lParam; - - char *message = pre->szMessage; + DBEVENTINFO dbei; + CCSDATA* ccs = (CCSDATA*)lParam; + PROTORECVEVENT* pre = (PROTORECVEVENT*)ccs->lParam; + + DBDeleteContactSetting(ccs->hContact, "CList", "Hidden"); + + ZeroMemory(&dbei, sizeof(dbei)); + dbei.cbSize = sizeof(dbei); + dbei.szModule = MODULE; + dbei.timestamp = pre->timestamp; + dbei.flags = (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0; + dbei.flags |= (pre->flags & PREF_RTL) ? DBEF_RTL : 0; + dbei.flags |= (pre->flags & PREF_UTF) ? DBEF_UTF : 0; + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.cbBlob = strlen(pre->szMessage) + 1; + if ( pre->flags & PREF_UNICODE ) + dbei.cbBlob *= ( sizeof( wchar_t )+1 ); + dbei.pBlob = (PBYTE)pre->szMessage; + + CallService(MS_DB_EVENT_ADD, (WPARAM)ccs->hContact, (LPARAM)&dbei); + return 0; - // TODO: process 'message' and/or 'messagew' below - if(pre->flags & PREF_UNICODE) { - wchar_t *messagew = (wchar_t *)&message[strlen(message)+1]; - } else if(pre->flags & PREF_UTF) { - // message is utf8 encoded - you can use mir_utf8decode (m_system.h) to make it wide - } - - return CallService(MS_PROTO_CHAINRECV, wParam, lParam); } int BasicSearch(WPARAM wParam, LPARAM lParam) { -- cgit v1.2.3