summaryrefslogtreecommitdiff
path: root/MySpace/proto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MySpace/proto.cpp')
-rw-r--r--MySpace/proto.cpp87
1 files changed, 85 insertions, 2 deletions
diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp
index b20727e..821b33e 100644
--- a/MySpace/proto.cpp
+++ b/MySpace/proto.cpp
@@ -4,6 +4,9 @@
#include "resource.h"
#include "formatting.h"
+#include <malloc.h>
+#include <ctime>
+
#define FAILED_MESSAGE_HANDLE 99998
int msg_id = 1;
@@ -12,12 +15,13 @@ int GetCaps(WPARAM wParam,LPARAM lParam) {
int ret = 0;
switch (wParam) {
case PFLAGNUM_1:
- ret = PF1_NUMERICUSERID | PF1_IM | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES | PF1_SERVERCLIST;
+ ret = PF1_NUMERICUSERID | PF1_IM | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES | PF1_SERVERCLIST | PF1_MODEMSG;
break;
case PFLAGNUM_2:
ret = PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE;
break;
case PFLAGNUM_3:
+ ret = PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE;
break;
case PFLAGNUM_4:
//ret = PF4_SUPPORTTYPING;
@@ -310,6 +314,81 @@ int AddToList(WPARAM wParam, LPARAM lParam) {
return (int)hContact;
}
+static DWORD CALLBACK sttRecvAway( LPVOID param )
+{
+ TFakeAckParams *tParam = ( TFakeAckParams* )param;
+ WaitForSingleObject( tParam->hEvent, INFINITE );
+
+ Sleep( 100 );
+
+ DBVARIANT dbv;
+ char buff[512];
+ buff[0] = 0;
+
+ if(!DBGetContactSettingStringUtf(tParam->hContact, MODULE, "StatusMsg", &dbv) && strlen(dbv.pszVal)) {
+ strncpy(buff, dbv.pszVal, 512);
+ buff[511] = 0;
+ DBFreeVariant(&dbv);
+ }
+
+ CCSDATA ccs = {0};
+ PROTORECVEVENT pre = {0};
+
+ ccs.hContact = tParam->hContact;
+ ccs.szProtoService = PSR_AWAYMSG;
+ ccs.wParam = 0;
+ ccs.lParam = (LPARAM)&pre;
+
+ pre.timestamp = (DWORD)time(0);
+ if(strlen(buff))
+ pre.szMessage = buff;
+ else
+ pre.szMessage = 0;
+
+ CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
+
+ CloseHandle( tParam->hEvent );
+ delete tParam;
+ return 0;
+}
+
+
+int GetAwayMsg(WPARAM wParam, LPARAM lParam) {
+ CCSDATA* ccs = (CCSDATA*)lParam;
+
+ HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
+
+ TFakeAckParams *tfap = new TFakeAckParams;
+ tfap->hContact = ccs->hContact;
+ tfap->hEvent = hEvent;
+ tfap->lParam = 0;
+
+ CloseHandle( CreateThread( NULL, 0, sttRecvAway, tfap, 0, 0 ));
+ SetEvent( hEvent );
+ return 1;
+}
+
+int RecvAwayMsg(WPARAM wParam, LPARAM lParam) {
+ CCSDATA* ccs = (CCSDATA*)lParam;
+ PROTORECVEVENT* pre = (PROTORECVEVENT*)ccs->lParam;
+
+ ProtoBroadcastAck(MODULE, ccs->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)pre->szMessage);
+
+ return 0;
+}
+
+
+
+int SetAwayMsg(WPARAM wParam, LPARAM lParam) {
+ int status = (int)wParam;
+ char *msg = (char *)lParam;
+
+ // called *just after* SetStatus :(
+ SetServerStatusMessage(msg);
+
+ return 0;
+}
+
int ContactDeleted(WPARAM wParam, LPARAM lParam) {
HANDLE hContact = (HANDLE)wParam;
int uid = DBGetContactSettingDword(hContact, MODULE, "UID", 0);
@@ -354,7 +433,7 @@ void RegisterProto() {
CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
}
-#define NUM_FILTER_SERVICES 13
+#define NUM_FILTER_SERVICES 16
HANDLE hServices[NUM_FILTER_SERVICES];
HANDLE hEventContactDeleted;
@@ -376,6 +455,10 @@ void CreateProtoServices() {
hServices[i++] = CreateProtoServiceFunction(MODULE, PS_SEARCHBYEMAIL, SearchByEmail);
hServices[i++] = CreateProtoServiceFunction(MODULE, PS_SEARCHBYNAME, SearchByName);
hServices[i++] = CreateProtoServiceFunction(MODULE, PS_ADDTOLIST, AddToList);
+
+ hServices[i++] = CreateProtoServiceFunction(MODULE, PSS_GETAWAYMSG, GetAwayMsg);
+ hServices[i++] = CreateProtoServiceFunction(MODULE, PSR_AWAYMSG, RecvAwayMsg);
+ hServices[i++] = CreateProtoServiceFunction(MODULE, PS_SETAWAYMSG, SetAwayMsg);
// remember to modify the NUM_FILTER_SERVICES #define above if you add more services!
hEventContactDeleted = HookEvent(ME_DB_CONTACT_DELETED, ContactDeleted);