From f98ef8ff5f7c6d2485d9e627a9af67d67e846d72 Mon Sep 17 00:00:00 2001 From: sje Date: Sun, 1 Jul 2007 15:27:08 +0000 Subject: implemented status messages added cool protol icons from Angeli-Ka (thankyou!) git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@234 4f64403b-2f21-0410-a795-97e2b3489a10 --- MySpace/MySpace.cpp | 8 ++++ MySpace/icons/proto_MySpace.dll | Bin 0 -> 11776 bytes MySpace/proto.cpp | 87 +++++++++++++++++++++++++++++++++++++++- MySpace/server_con.cpp | 48 ++++++++++++++++++---- MySpace/server_con.h | 1 + MySpace/version.h | 2 +- 6 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 MySpace/icons/proto_MySpace.dll diff --git a/MySpace/MySpace.cpp b/MySpace/MySpace.cpp index 6121fa3..c06690d 100644 --- a/MySpace/MySpace.cpp +++ b/MySpace/MySpace.cpp @@ -116,6 +116,14 @@ extern "C" __declspec (dllexport) int Load(PLUGINLINK *link) { code_page = (int)CallService(MS_LANGPACK_GETCODEPAGE, 0, 0); + if(ServiceExists(MS_DB_SETSETTINGRESIDENT)) { // 0.6+ + char buff[256]; + mir_snprintf(buff, 256, "%s/%s", MODULE, "Status"); + CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)buff); + mir_snprintf(buff, 256, "%s/%s", MODULE, "StatusMsg"); + CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)buff); + } + InitARC4Module(); InitOptions(); diff --git a/MySpace/icons/proto_MySpace.dll b/MySpace/icons/proto_MySpace.dll new file mode 100644 index 0000000..5ae95da Binary files /dev/null and b/MySpace/icons/proto_MySpace.dll differ 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 +#include + #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.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); diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index dbc7042..9f5a75d 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -6,6 +6,7 @@ #include "nick_dialog.h" #include "formatting.h" +#include #include #define SERVER_READ_BUFFER_SIZE (1024 * 32) @@ -30,6 +31,7 @@ bool myspace_server_running = false, server_stop = false; HANDLE server_connection = 0; int sesskey = 0, req_id = 1, my_uid = 0; int signon_status = ID_STATUS_ONLINE; +char signon_status_msg[512] = {0}; int stat_mir_to_myspace(int mir_status) { switch(mir_status) { @@ -329,7 +331,7 @@ void __cdecl ServerThreadFunc(void*) { char nick[256]; if(msg.get_string("uniquenick", nick, 256)) DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick); - QueueUserAPC(sttMainThreadStatusCallback, mainThread, ID_STATUS_ONLINE); + QueueUserAPC(sttMainThreadStatusCallback, mainThread, signon_status); if(my_uid == msg.get_int("uniquenick")) { // need to pick a nick @@ -370,7 +372,7 @@ void __cdecl ServerThreadFunc(void*) { ClientNetMessage msg_status; msg_status.add_int("status", stat_mir_to_myspace(signon_status)); msg_status.add_int("sesskey", sesskey); - msg_status.add_string("statstring", ""); + msg_status.add_string("statstring", signon_status_msg); msg_status.add_string("locstring", ""); SendMessage(msg_status); @@ -522,6 +524,7 @@ void __cdecl ServerThreadFunc(void*) { ClientNetMessage msg; msg.add_string("logout", ""); msg.add_int("sesskey", sesskey); + sesskey = 0; SendMessage(msg); Netlib_CloseHandle(server_connection); server_connection = 0; @@ -542,10 +545,17 @@ void StartThread() { void StopThread() { if(myspace_server_running) { - ClientNetMessage msg; - msg.add_string("logout", ""); - msg.add_int("sesskey", sesskey); - SendMessage(msg); + if(sesskey) { + ClientNetMessage msg; + msg.add_string("logout", ""); + msg.add_int("sesskey", sesskey); + SendMessage(msg); + } else { + if(server_connection) { + Netlib_CloseHandle(server_connection); + server_connection = 0; + } + } } } @@ -553,7 +563,7 @@ void SetServerStatus(int st) { if(st == ID_STATUS_OFFLINE) { StopThread(); } else { - if(myspace_server_running) { + if(myspace_server_running && sesskey) { // set status ClientNetMessage msg_status; msg_status.add_int("status", stat_mir_to_myspace(st)); @@ -569,3 +579,27 @@ void SetServerStatus(int st) { } } } + +void CALLBACK sttMainThreadStatusMessageCallback( ULONG dwParam ) { + char *msg = (char *)dwParam; + if(status != ID_STATUS_OFFLINE) { + if(myspace_server_running && sesskey) { + // set status + ClientNetMessage msg_status; + msg_status.add_int("status", stat_mir_to_myspace(status)); + msg_status.add_int("sesskey", sesskey); + msg_status.add_string("statstring", msg ? msg : ""); + msg_status.add_string("locstring", ""); + SendMessage(msg_status); + } else { + if(msg) strncpy(signon_status_msg, msg, 512); + else signon_status_msg[0] = 0; + } + } + if(msg) free(msg); +} + +void SetServerStatusMessage(char *msg) { + QueueUserAPC(sttMainThreadStatusMessageCallback, mainThread, (ULONG_PTR)(msg ? strdup(msg): 0)); +} + diff --git a/MySpace/server_con.h b/MySpace/server_con.h index 5d100c4..b247e00 100644 --- a/MySpace/server_con.h +++ b/MySpace/server_con.h @@ -11,6 +11,7 @@ extern bool myspace_server_running; extern int my_uid; void SetServerStatus(int st); +void SetServerStatusMessage(char *msg); HANDLE FindContact(int uid); HANDLE CreateContact(int uid, char *nick, char *email, bool add_buddy); diff --git a/MySpace/version.h b/MySpace/version.h index 2372d36..c34959c 100644 --- a/MySpace/version.h +++ b/MySpace/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 3 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM #define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM -- cgit v1.2.3