diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-06-30 15:48:03 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-06-30 15:48:03 +0000 |
commit | ad621c29997aff0bda961718de44f536d13213cf (patch) | |
tree | 12f46c43d1fdd3b5204b199ff24eb3d2bcda9b57 | |
parent | d7c18eb91b752af0a617feb08151ba6ec73b7332 (diff) |
implemented messaging! woohoo!
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@223 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r-- | MySpace/common.h | 5 | ||||
-rw-r--r-- | MySpace/proto.cpp | 121 | ||||
-rw-r--r-- | MySpace/server_con.cpp | 26 |
3 files changed, 135 insertions, 17 deletions
diff --git a/MySpace/common.h b/MySpace/common.h index c74cb99..6ba2650 100644 --- a/MySpace/common.h +++ b/MySpace/common.h @@ -62,6 +62,11 @@ #define MODULE "MySpace"
+#define CLIENT_VER 673
+
+#define MAX_MESSAGE_SIZE 1024
+
+
extern HINSTANCE hInst;
extern PLUGINLINK *pluginLink;
extern HANDLE mainThread;
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) {
diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index 41aad7d..47bfbcb 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -5,6 +5,8 @@ #include "options.h"
#include "nick_dialog.h"
+#include <ctime>
+
#define SERVER_READ_BUFFER_SIZE (1024 * 32)
/* TODO: obtain IPs of network interfaces from user's machine, instead of @@ -190,7 +192,7 @@ void try_login(NetMessage &msg, HANDLE connection) { reply.add_int("login2", 196610);
reply.add_string("username", email);
reply.add_data("response", ch_resp, ch_resp_size);
- reply.add_int("clientver", 673);
+ reply.add_int("clientver", CLIENT_VER);
reply.add_int("reconn", 0);
reply.add_int("status", 100);
reply.add_int("id", 1);
@@ -347,6 +349,28 @@ void __cdecl ServerThreadFunc(void*) { DBWriteContactSettingWord(hContact, MODULE, "Status", stat_myspace_to_mir(smsg[3] - '0'));
}
}
+ } else if(msg.get_int("bm") == 1) { // instant message
+ int uid = msg.get_int("f");
+ if(uid) {
+ HANDLE hContact = FindContact(uid);
+ if(!hContact) {
+ hContact = CreateContact(uid, 0, 0);
+ }
+ char text[MAX_MESSAGE_SIZE];
+ if(msg.get_string("msg", text, MAX_MESSAGE_SIZE)) {
+ PROTORECVEVENT pre = {0};
+ pre.flags = PREF_UTF;
+ pre.szMessage = text;
+ pre.timestamp = (DWORD)time(0);
+
+ CCSDATA css = {0};
+ css.hContact = hContact;
+ css.lParam = (LPARAM)⪯
+ css.szProtoService = PSR_MESSAGE;
+
+ CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&css);
+ }
+ }
} else if(msg.exists(NMString("persistr"))) {
int cmd, dsn, lid, req;
cmd = msg.get_int("cmd") & 255;
|